Subversion Repositories SmartDukaan

Rev

Rev 34751 | Rev 34763 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 34751 Rev 34758
Line 6... Line 6...
6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
6
import com.spice.profitmandi.common.model.ProfitMandiConstants;
7
import com.spice.profitmandi.common.util.FormattingUtils;
7
import com.spice.profitmandi.common.util.FormattingUtils;
8
import com.spice.profitmandi.common.util.Utils;
8
import com.spice.profitmandi.common.util.Utils;
9
import com.spice.profitmandi.dao.cart.SmartCartService;
9
import com.spice.profitmandi.dao.cart.SmartCartService;
10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
10
import com.spice.profitmandi.dao.entity.auth.AuthUser;
-
 
11
import com.spice.profitmandi.dao.entity.catalog.TagListing;
11
import com.spice.profitmandi.dao.entity.fofo.*;
12
import com.spice.profitmandi.dao.entity.fofo.*;
12
import com.spice.profitmandi.dao.entity.logistics.AST;
13
import com.spice.profitmandi.dao.entity.logistics.AST;
13
import com.spice.profitmandi.dao.entity.logistics.ASTRepository;
14
import com.spice.profitmandi.dao.entity.logistics.ASTRepository;
14
import com.spice.profitmandi.dao.entity.transaction.*;
15
import com.spice.profitmandi.dao.entity.transaction.*;
15
import com.spice.profitmandi.dao.entity.user.User;
16
import com.spice.profitmandi.dao.entity.user.User;
16
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
17
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
17
import com.spice.profitmandi.dao.enumuration.transaction.LoanReferenceType;
18
import com.spice.profitmandi.dao.enumuration.transaction.LoanReferenceType;
18
import com.spice.profitmandi.dao.model.*;
19
import com.spice.profitmandi.dao.model.*;
19
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
20
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
-
 
21
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
20
import com.spice.profitmandi.dao.repository.cs.CsService;
22
import com.spice.profitmandi.dao.repository.cs.CsService;
21
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
23
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
22
import com.spice.profitmandi.dao.repository.fofo.*;
24
import com.spice.profitmandi.dao.repository.fofo.*;
23
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
25
import com.spice.profitmandi.dao.repository.inventory.StateRepository;
24
import com.spice.profitmandi.dao.repository.transaction.*;
26
import com.spice.profitmandi.dao.repository.transaction.*;
25
import com.spice.profitmandi.dao.repository.user.UserRepository;
27
import com.spice.profitmandi.dao.repository.user.UserRepository;
26
import com.spice.profitmandi.service.PartnerStatsService;
28
import com.spice.profitmandi.service.PartnerStatsService;
27
import com.spice.profitmandi.service.RbmTargetService;
29
import com.spice.profitmandi.service.RbmTargetService;
28
import com.spice.profitmandi.service.inventory.InventoryService;
30
import com.spice.profitmandi.service.inventory.*;
29
import com.spice.profitmandi.service.transaction.SDCreditService;
31
import com.spice.profitmandi.service.transaction.SDCreditService;
30
import com.spice.profitmandi.service.user.RetailerService;
32
import com.spice.profitmandi.service.user.RetailerService;
31
import com.spice.profitmandi.service.wallet.WalletService;
33
import com.spice.profitmandi.service.wallet.WalletService;
32
import in.shop2020.model.v1.order.OrderStatus;
34
import in.shop2020.model.v1.order.OrderStatus;
33
import in.shop2020.model.v1.order.WalletReferenceType;
35
import in.shop2020.model.v1.order.WalletReferenceType;
Line 137... Line 139...
137
 
139
 
138
    @Autowired
140
    @Autowired
139
    PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
141
    PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
140
 
142
 
141
    @Autowired
143
    @Autowired
-
 
144
    SaholicInventoryService saholicInventoryService;
-
 
145
 
-
 
146
    @Autowired
142
    WalletService walletService;
147
    WalletService walletService;
143
 
148
 
144
    @Autowired
149
    @Autowired
145
    RbmTargetService rbmTargetService;
150
    RbmTargetService rbmTargetService;
146
 
151
 
147
    @Autowired
152
    @Autowired
148
    PartnerStatsService partnerStatsService;
153
    PartnerStatsService partnerStatsService;
149
 
154
 
150
    @Autowired
155
    @Autowired
-
 
156
    AgeingService ageingService;
-
 
157
 
-
 
158
    @Autowired
-
 
159
    TagListingRepository tagListingRepository;
-
 
160
 
-
 
161
    @Autowired
151
    UserWalletHistoryRepository userWalletHistoryRepository;
162
    UserWalletHistoryRepository userWalletHistoryRepository;
152
 
163
 
153
    public void test() throws Exception {
164
    public void test() throws Exception {
154
        System.out.println("test start");
165
        System.out.println("test start");
155
        //partnerStatsService.getAllPartnerStats();
166
        //partnerStatsService.getAllPartnerStats();
Line 464... Line 475...
464
        }
475
        }
465
 
476
 
466
        Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
477
        Map<Integer, CustomRetailer> customRetailers = retailerService.getAllFofoRetailersInternalFalse();
467
 
478
 
468
        List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());
479
        List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());
469
//
480
 
470
//        List<Integer> retailerIds = Arrays.asList(175139440,175139441);
481
/*        List<Integer> retailerIds = Arrays.asList(175130896);
471
//        Map<Integer,CustomRetailer> customRetailers = retailerService.getFofoRetailers(retailerIds);
482
        Map<Integer,CustomRetailer> customRetailers = retailerService.getFofoRetailers(retailerIds);*/
472
 
483
 
473
        //partner daily investment
484
        //partner daily investment
474
        List<Loan> defaultLoans = sdCreditService.getDefaultLoans();
485
        List<Loan> defaultLoans = sdCreditService.getDefaultLoans();
475
        Map<Integer,List<Loan>> defaultLoanMap = defaultLoans.stream().collect(Collectors.groupingBy(Loan::getFofoId));
486
        Map<Integer,List<Loan>> defaultLoanMap = defaultLoans.stream().collect(Collectors.groupingBy(Loan::getFofoId));
476
 
487
 
Line 780... Line 791...
780
 
791
 
781
            double totalMtdTertiaryAmount = brandMtdTertiaryAmount.values().stream().mapToDouble(Double::doubleValue).sum();
792
            double totalMtdTertiaryAmount = brandMtdTertiaryAmount.values().stream().mapToDouble(Double::doubleValue).sum();
782
 
793
 
783
            fofoTotalMtdTertiaryMap.put(fofoId,totalMtdTertiaryAmount);
794
            fofoTotalMtdTertiaryMap.put(fofoId,totalMtdTertiaryAmount);
784
 
795
 
785
            LOGGER.info("fofoBrandMtdTertiaryMap- {}",fofoBrandMtdTertiaryMap);
-
 
786
 
-
 
787
 
-
 
788
            List<BrandWiseModel> brandWiseMtdSecondary = orderRepository.selectAllBilledByCategoryOrderGroupByBrandFofoId(fofoId, currentMonthStartDate,Arrays.asList(10006,10001));
796
            List<BrandWiseModel> brandWiseMtdSecondary = orderRepository.selectAllBilledByCategoryOrderGroupByBrandFofoId(fofoId, currentMonthStartDate,Arrays.asList(10006,10001));
789
            Map<String,Long> brandWiseMtdSecondaryMap = brandWiseMtdSecondary.stream().collect(Collectors.toMap(BrandWiseModel::getBrand,BrandWiseModel::getAmount));
797
            Map<String,Long> brandWiseMtdSecondaryMap = brandWiseMtdSecondary.stream().collect(Collectors.toMap(BrandWiseModel::getBrand,BrandWiseModel::getAmount));
790
 
798
 
791
            //retrunInfo
799
            //retrunInfo
792
            List<BrandWiseReturnInfo> brandWiseReturnInfos = returnOrderInfoRepository.selectAllBrandWiseByBetweenDate(currentMonthStartDate,currentMonthEndDate.plusDays(1),fofoId);
800
            List<BrandWiseReturnInfo> brandWiseReturnInfos = returnOrderInfoRepository.selectAllBrandWiseByBetweenDate(currentMonthStartDate,currentMonthEndDate.plusDays(1),fofoId);
793
            Map<String,Double> brandWiseReturnInfoMap = brandWiseReturnInfos.stream().collect(Collectors.toMap(BrandWiseReturnInfo::getBrand, x->x.getReturnAmount()));
801
            Map<String,Double> brandWiseReturnInfoMap = brandWiseReturnInfos.stream().collect(Collectors.toMap(BrandWiseReturnInfo::getBrand, x->x.getReturnAmount()));
794
 
802
 
795
            LOGGER.info("brandWiseReturnInfos {}",brandWiseReturnInfos);
803
            LOGGER.info("brandWiseReturnInfos {}",brandWiseReturnInfos);
796
            LOGGER.info("brandWiseReturnInfoMap {}",brandWiseReturnInfoMap);
-
 
-
 
804
 
797
            //Rto retrunInfo
805
            //Rto retrunInfo
798
            List<BrandWiseReturnInfo> brandWiseRTOReturnInfos = returnOrderInfoRepository.selectAllBrandWiseRTORefundByBetweenDate(currentMonthStartDate,currentMonthEndDate.plusDays(1),fofoId);
806
            List<BrandWiseReturnInfo> brandWiseRTOReturnInfos = returnOrderInfoRepository.selectAllBrandWiseRTORefundByBetweenDate(currentMonthStartDate,currentMonthEndDate.plusDays(1),fofoId);
799
            Map<String,Double> brandWiseRTOReturnInfoMap = brandWiseRTOReturnInfos.stream().collect(Collectors.toMap(BrandWiseReturnInfo::getBrand, x->x.getReturnAmount()));
807
            Map<String,Double> brandWiseRTOReturnInfoMap = brandWiseRTOReturnInfos.stream().collect(Collectors.toMap(BrandWiseReturnInfo::getBrand, x->x.getReturnAmount()));
800
 
808
 
801
            // Step 1: Get union of all brand keys
809
            // Step 1: Get union of all brand keys
Line 1011... Line 1019...
1011
        for (Map.Entry<Integer, BIRetailerModel> entry : biRetailerModelMap.entrySet()) {
1019
        for (Map.Entry<Integer, BIRetailerModel> entry : biRetailerModelMap.entrySet()) {
1012
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
1020
            DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
1013
            Integer fofoId = entry.getKey();
1021
            Integer fofoId = entry.getKey();
1014
            User user = userRepository.selectById(fofoId);
1022
            User user = userRepository.selectById(fofoId);
1015
            LocalDateTime walletCreationDate = userWalletHistoryRepository.selectFirstCreatedDate(fofoId);
1023
            LocalDateTime walletCreationDate = userWalletHistoryRepository.selectFirstCreatedDate(fofoId);
-
 
1024
            if(walletCreationDate == null){
-
 
1025
                walletCreationDate = user.getCreateTimestamp();
-
 
1026
            }
1016
            BIRetailerModel retailer = entry.getValue();
1027
            BIRetailerModel retailer = entry.getValue();
1017
 
1028
 
1018
            Map<YearMonth, BiSecondaryModel> monthlyData = allRetailerMonthlyData.get(fofoId);
1029
            Map<YearMonth, BiSecondaryModel> monthlyData = allRetailerMonthlyData.get(fofoId);
1019
 
1030
 
1020
            BiSecondaryModel current = monthlyData.getOrDefault(currentMonth, new BiSecondaryModel(0,0,0,0,0,0,0));
1031
            BiSecondaryModel current = monthlyData.getOrDefault(currentMonth, new BiSecondaryModel(0,0,0,0,0,0,0));
1021
            BiSecondaryModel last = monthlyData.getOrDefault(currentMonth.minusMonths(1), new BiSecondaryModel(0,0,0,0,0,0,0));
1032
            BiSecondaryModel last = monthlyData.getOrDefault(currentMonth.minusMonths(1), new BiSecondaryModel(0,0,0,0,0,0,0));
1022
            BiSecondaryModel twoAgo = monthlyData.getOrDefault(currentMonth.minusMonths(2), new BiSecondaryModel(0,0,0,0,0,0,0));
1033
            BiSecondaryModel twoAgo = monthlyData.getOrDefault(currentMonth.minusMonths(2), new BiSecondaryModel(0,0,0,0,0,0,0));
1023
 
1034
 
1024
            List<Object> row = new ArrayList<>();
1035
            List<Object> row = new ArrayList<>();
-
 
1036
            LOGGER.info("fofoId-11 {}",fofoId);
-
 
1037
 
1025
            row.addAll(Arrays.asList(
1038
            row.addAll(Arrays.asList(
-
 
1039
                    assessmentMap.get(fofoId),
-
 
1040
                    zeroBillingMap.get(fofoId),
-
 
1041
                    billingNeededMap.get(fofoId),
-
 
1042
                    countAMap.get(fofoId),
-
 
1043
                    retailer.getBmName(),
-
 
1044
                    fofoId ,
-
 
1045
                    "https://partners.smartdukaan.com/partnerPerformance?fofoId="+fofoId,
-
 
1046
                    walletCreationDate.format(formatter),
1026
                    assessmentMap.get(fofoId),zeroBillingMap.get(fofoId),billingNeededMap.get(fofoId),countAMap.get(fofoId),
1047
                    user.getCreateTimestamp() != null ? (user.getCreateTimestamp()).format(formatter) : "-",
-
 
1048
                    retailer.getCode(),
-
 
1049
                    retailer.getArea(),
-
 
1050
                    retailer.getCity(),
1027
                    retailer.getBmName(),fofoId ,"https://partners.smartdukaan.com/partnerPerformance?fofoId="+fofoId,walletCreationDate.format(formatter),(user.getCreateTimestamp()).format(formatter), retailer.getCode(), retailer.getArea(), retailer.getCity(),  retailer.getStoreName(), retailer.getStatus(),
1051
                    retailer.getStoreName(),
-
 
1052
                    retailer.getStatus(),
-
 
1053
                    retailer.getCategory(),
1028
                    retailer.getCategory(),  retailer.getSalesManager(), retailer.getRbm()
1054
                    retailer.getSalesManager(),
-
 
1055
                    retailer.getRbm()
1029
 
1056
 
1030
            ));
1057
            ));
1031
 
1058
 
1032
 
1059
 
1033
            // Two Months Ago
1060
            // Two Months Ago
Line 1150... Line 1177...
1150
 
1177
 
1151
        // Send to email
1178
        // Send to email
1152
//        ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
1179
//        ByteArrayOutputStream csvStream = FileUtil.getCSVByteStreamWithMultiHeaders(headerGroup, rows);
1153
        ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
1180
        ByteArrayOutputStream csvStream = getExcelStreamWithMultiHeaders(headerGroup, rows);
1154
        String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
1181
        String fileName = "BI-Retailer-Monthly-Report-" + FormattingUtils.formatDate(LocalDateTime.now()) + ".xlsx";
1155
//        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com","ashutosh.verma@smartdukaan.com","sm@smartdukaan.com","raj.singh@smartdukaan.com"};
1182
        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com","ashutosh.verma@smartdukaan.com","sm@smartdukaan.com","raj.singh@smartdukaan.com"};
1156
        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com"};
1183
//        String[] sendToArray = new String[]{"ranu.rajput@smartdukaan.com"};
1157
 
1184
 
1158
        Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{}, "BI Retailer Monthly Report", "Please find attached the BI retailer secondary/tertiary monthly report.", fileName, new ByteArrayResource(csvStream.toByteArray()));
1185
        Utils.sendMailWithAttachment(googleMailSender, sendToArray, new String[]{}, "BI Retailer Monthly Report", "Please find attached the BI retailer secondary/tertiary monthly report.", fileName, new ByteArrayResource(csvStream.toByteArray()));
1159
 
1186
 
1160
 
1187
 
1161
    }
1188
    }
Line 1370... Line 1397...
1370
        style.setFont(font);
1397
        style.setFont(font);
1371
        return style;
1398
        return style;
1372
    }
1399
    }
1373
 
1400
 
1374
 
1401
 
-
 
1402
    public void stockAlertMailToRetailer() throws Exception {
-
 
1403
 
-
 
1404
        Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
-
 
1405
 
-
 
1406
        List<Integer> retailerIds = customRetailers.values().stream().map(CustomRetailer::getPartnerId).collect(Collectors.toList());
-
 
1407
 
-
 
1408
        for(Integer fofoId : retailerIds){
-
 
1409
            List<String> statusOrder = Arrays.asList("HID", "FASTMOVING", "RUNNING", "SLOWMOVING", "OTHER");
-
 
1410
            FofoStore fofoStore = fofoStoreRepository.selectByRetailerId(fofoId);
-
 
1411
            List<PartnerWarehouseStockSummaryModel> partnerWarehouseStockSummaryModels = saholicInventoryService.getSaholicAndPartnerStock(fofoId, fofoStore.getWarehouseId());
-
 
1412
 
-
 
1413
            List<PartnerWarehouseStockAgingSummaryModel> partnerWarehouseStockAgingSummaryModelList = new ArrayList<>();
-
 
1414
 
-
 
1415
            Set<Integer> catalogIds = partnerWarehouseStockSummaryModels.stream().map(x -> x.getCatalogId()).collect(Collectors.toSet());
-
 
1416
 
-
 
1417
            List<Integer> catalogsList = new ArrayList<>(catalogIds);
-
 
1418
 
-
 
1419
            Map<Integer, TagListing> tagListingsMap = tagListingRepository.selectAllByCatalogIds(catalogsList);
-
 
1420
 
-
 
1421
            List<CatalogAgingModel> catalogAgingModels = ageingService.getCatalogsAgingByWarehouse(catalogIds, fofoStore.getWarehouseId());
-
 
1422
 
-
 
1423
            Map<Integer, CatalogAgingModel> catalogAgingModelMap = catalogAgingModels.stream().collect(Collectors.toMap(x -> x.getCatalogId(), x -> x));
-
 
1424
 
-
 
1425
            for (PartnerWarehouseStockSummaryModel stockSummary : partnerWarehouseStockSummaryModels) {
-
 
1426
 
-
 
1427
                PartnerWarehouseStockAgingSummaryModel partnerWarehouseStockAgingSummaryModel = new PartnerWarehouseStockAgingSummaryModel();
-
 
1428
                partnerWarehouseStockAgingSummaryModel.setCatalogId(stockSummary.getCatalogId());
-
 
1429
                partnerWarehouseStockAgingSummaryModel.setBrand(stockSummary.getBrand());
-
 
1430
                partnerWarehouseStockAgingSummaryModel.setModelNumber(stockSummary.getModelNumber());
-
 
1431
                partnerWarehouseStockAgingSummaryModel.setNetAvailability(stockSummary.getShaholicNetAvailability());
-
 
1432
                partnerWarehouseStockAgingSummaryModel.setPartnerStockAvailability(stockSummary.getPartnerFullFilledQty());
-
 
1433
                partnerWarehouseStockAgingSummaryModel.setPartnerCurrentAvailability(stockSummary.getPartnerCurrentQty());
-
 
1434
                partnerWarehouseStockAgingSummaryModel.setPartnerShortageStock(stockSummary.getPartnerShortageQty());
-
 
1435
                if (catalogAgingModelMap.get(stockSummary.getCatalogId()) != null) {
-
 
1436
                    partnerWarehouseStockAgingSummaryModel.setExceedDays(catalogAgingModelMap.get(stockSummary.getCatalogId()).getExceedDays());
-
 
1437
                } else {
-
 
1438
                    partnerWarehouseStockAgingSummaryModel.setExceedDays(0);
-
 
1439
 
-
 
1440
                }
-
 
1441
                partnerWarehouseStockAgingSummaryModel.setStatus(stockSummary.getStatus());
-
 
1442
 
-
 
1443
                partnerWarehouseStockAgingSummaryModelList.add(partnerWarehouseStockAgingSummaryModel);
-
 
1444
            }
-
 
1445
 
-
 
1446
            Set<Integer> existingCatalogIdsInAgingSummaryList = partnerWarehouseStockAgingSummaryModelList.stream()
-
 
1447
                    .map(PartnerWarehouseStockAgingSummaryModel::getCatalogId)
-
 
1448
                    .collect(Collectors.toSet());
-
 
1449
        }
-
 
1450
 
-
 
1451
    }
-
 
1452
 
-
 
1453
 
1375
}
1454
}