Subversion Repositories SmartDukaan

Rev

Rev 35853 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35853 Rev 35920
Line 1254... Line 1254...
1254
        LOGGER.info("PERF: Total getPartnerTarget took {} ms", System.currentTimeMillis() - startTime);
1254
        LOGGER.info("PERF: Total getPartnerTarget took {} ms", System.currentTimeMillis() - startTime);
1255
        return responseSender.ok(tm);
1255
        return responseSender.ok(tm);
1256
 
1256
 
1257
    }
1257
    }
1258
 
1258
 
-
 
1259
    @RequestMapping(value = "/getInactivePartnerTarget", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
1260
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
-
 
1261
    public ResponseEntity<?> getInactivePartnerTarget(HttpServletRequest request, @RequestParam String
-
 
1262
            gmailId, @RequestParam String dayValue, @RequestParam ActivationType activationType) throws
-
 
1263
            ProfitMandiBusinessException {
-
 
1264
 
-
 
1265
        long startTime = System.currentTimeMillis();
-
 
1266
        long lapTime = startTime;
-
 
1267
 
-
 
1268
        AuthUser authUser = authRepository.selectByGmailId(gmailId);
-
 
1269
 
-
 
1270
        Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserInactivePartnerIdMapping();
-
 
1271
        Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
-
 
1272
        List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Almost New", "Others");
-
 
1273
 
-
 
1274
        float totalPartnerTargetSecondary = 0;
-
 
1275
        float totalPartnerTargetCollection = 0;
-
 
1276
        float totalPartnerAchievementSecondary = 0;
-
 
1277
        float totalPartnerAchievementCollection = 0;
-
 
1278
        TargetModel tm = new TargetModel();
-
 
1279
        Map<Integer, PartnerDailyInvestment> partnerDailyInvestmentMap = new HashMap<>();
-
 
1280
        Map<Integer, Long> partnerTicketCount = new HashMap<>();
-
 
1281
 
-
 
1282
        List<PartnerTargetAchievementModel> ptams = new ArrayList<>();
-
 
1283
 
-
 
1284
        if (fofoIds != null && fofoIds.size() > 0) {
-
 
1285
            LOGGER.info("fofoIds {}", fofoIds);
-
 
1286
            // Get inactive stores for the given retailer IDs
-
 
1287
            List<Integer> fofoIdList = fofoStoreRepository.selectByRetailerIds(new ArrayList<>(fofoIds)).stream()
-
 
1288
                    .filter(x -> (!x.isInternal()))
-
 
1289
                    .map(x -> x.getId()).collect(Collectors.toList());
-
 
1290
            LOGGER.info("PERF: selectInActiveStore took {} ms", System.currentTimeMillis() - lapTime);
-
 
1291
            lapTime = System.currentTimeMillis();
-
 
1292
            LOGGER.info("inactive fofoIdList size: {}", fofoIdList.size());
-
 
1293
 
-
 
1294
            if (!fofoIdList.isEmpty()) {
-
 
1295
                partnerTicketCount = ticketRepository.selectOpenTicketsCountByFofoIds(fofoIdList);
-
 
1296
            }
-
 
1297
            LOGGER.info("PERF: selectOpenTicketsCountByFofoIds took {} ms", System.currentTimeMillis() - lapTime);
-
 
1298
            lapTime = System.currentTimeMillis();
-
 
1299
            LocalDateTime startDate = LocalDate.now().atStartOfDay();
-
 
1300
 
-
 
1301
            if (dayValue.equals("previous")) {
-
 
1302
                startDate = LocalDate.now().minusDays(1).atStartOfDay();
-
 
1303
            }
-
 
1304
 
-
 
1305
            if (fofoIdList.size() > 0) {
-
 
1306
 
-
 
1307
                LocalDateTime fifteenDaysAgo = LocalDate.now().minusDays(15).atStartOfDay();
-
 
1308
                Set<Integer> fofoIdsWithOverdueLoans = loanRepository.selectFofoIdsWithOverdueLoans(fofoIdList, fifteenDaysAgo);
-
 
1309
                LOGGER.info("PERF: selectFofoIdsWithOverdueLoans took {} ms", System.currentTimeMillis() - lapTime);
-
 
1310
                lapTime = System.currentTimeMillis();
-
 
1311
 
-
 
1312
                LocalDateTime mtdStartDate = LocalDate.now().withDayOfMonth(1).atStartOfDay();
-
 
1313
                LocalDateTime mtdEndDate = LocalDate.now().plusDays(1).atStartOfDay();
-
 
1314
                long billingThreshold = 1000L;
-
 
1315
                Set<Integer> allMtdBilledFofoIds = orderRepository.selectFofoIdsWithMtdBillingAboveThreshold(
-
 
1316
                        fofoIdList, mtdStartDate, mtdEndDate, billingThreshold);
-
 
1317
                LOGGER.info("PERF: selectFofoIdsWithMtdBillingAboveThreshold took {} ms", System.currentTimeMillis() - lapTime);
-
 
1318
                lapTime = System.currentTimeMillis();
-
 
1319
 
-
 
1320
                List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository.selectAll(fofoIdList, startDate.toLocalDate().minusDays(1));
-
 
1321
                LOGGER.info("PERF: partnerDailyInvestmentRepository.selectAll took {} ms", System.currentTimeMillis() - lapTime);
-
 
1322
                lapTime = System.currentTimeMillis();
-
 
1323
 
-
 
1324
                if (!partnerDailyInvestments.isEmpty()) {
-
 
1325
                    partnerDailyInvestmentMap = partnerDailyInvestments.stream().collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
-
 
1326
                }
-
 
1327
 
-
 
1328
                Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
-
 
1329
                LOGGER.info("PERF: getFofoRetailers took {} ms", System.currentTimeMillis() - lapTime);
-
 
1330
                lapTime = System.currentTimeMillis();
-
 
1331
 
-
 
1332
                List<Integer> remarkIds = partnerCollectionRemarkRepository.selectMaxRemarkId(fofoIdList);
-
 
1333
                LOGGER.info("PERF: selectMaxRemarkId took {} ms", System.currentTimeMillis() - lapTime);
-
 
1334
                lapTime = System.currentTimeMillis();
-
 
1335
 
-
 
1336
                long todayCollectionCount = 0;
-
 
1337
                if (!remarkIds.isEmpty()) {
-
 
1338
                    todayCollectionCount = partnerCollectionRemarkRepository
-
 
1339
                            .selectByAuthIdAndIds(authUser.getId(), remarkIds).stream()
-
 
1340
                            .filter(x -> x.getCreateTimestamp().toLocalDate().equals(LocalDate.now()))
-
 
1341
                            .collect(Collectors.counting());
-
 
1342
                }
-
 
1343
                LOGGER.info("PERF: selectByAuthIdAndIds took {} ms", System.currentTimeMillis() - lapTime);
-
 
1344
                lapTime = System.currentTimeMillis();
-
 
1345
 
-
 
1346
                Map<Integer, PartnerCollectionPlanModel> collectionMap = partnerCollectionService.getCollectionMap(fofoIdList, startDate);
-
 
1347
                LOGGER.info("PERF: getCollectionMap took {} ms", System.currentTimeMillis() - lapTime);
-
 
1348
                lapTime = System.currentTimeMillis();
-
 
1349
 
-
 
1350
                Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondaryPlans = orderRepository
-
 
1351
                        .selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
-
 
1352
                        .collect(Collectors.groupingBy(x -> x.getFofoId()));
-
 
1353
                LOGGER.info("PERF: selectPartnerSecondaryGroupByBrand took {} ms", System.currentTimeMillis() - lapTime);
-
 
1354
                lapTime = System.currentTimeMillis();
-
 
1355
 
-
 
1356
                Set<Integer> allAuthIds = new HashSet<>();
-
 
1357
                collectionMap.values().stream()
-
 
1358
                        .map(PartnerCollectionPlanModel::getAuthId)
-
 
1359
                        .filter(id -> id != null && id != authUser.getId())
-
 
1360
                        .forEach(allAuthIds::add);
-
 
1361
                partnerSecondaryPlans.values().stream()
-
 
1362
                        .flatMap(List::stream)
-
 
1363
                        .map(PartnerSecondaryPlanModel::getAuthId)
-
 
1364
                        .filter(id -> id != null && id != authUser.getId())
-
 
1365
                        .forEach(allAuthIds::add);
-
 
1366
                Map<Integer, AuthUser> authUserMap = new HashMap<>();
-
 
1367
                if (!allAuthIds.isEmpty()) {
-
 
1368
                    authUserMap = authRepository.selectByIds(new ArrayList<>(allAuthIds)).stream()
-
 
1369
                            .collect(Collectors.toMap(AuthUser::getId, x -> x));
-
 
1370
                }
-
 
1371
 
-
 
1372
                LOGGER.info("partnerSecondayPlans {}", partnerSecondaryPlans);
-
 
1373
                for (Entry<Integer, CustomRetailer> customRetailerEntry : customRetailers.entrySet()) {
-
 
1374
                    int fofoId = customRetailerEntry.getKey();
-
 
1375
                    CustomRetailer customRetailer = customRetailerEntry.getValue();
-
 
1376
                    float totalSecondaryPlan = 0;
-
 
1377
                    float totalSecondaryAchivement = 0;
-
 
1378
 
-
 
1379
                    PartnerTargetAchievementModel ptam = new PartnerTargetAchievementModel();
-
 
1380
                    ptam.setFofoId(fofoId);
-
 
1381
                    ptam.setBusinessName(customRetailer.getBusinessName());
-
 
1382
                    ptam.setMobile(customRetailer.getMobileNumber());
-
 
1383
 
-
 
1384
                    if (partnerDailyInvestmentMap.get(fofoId) != null) {
-
 
1385
                        ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
-
 
1386
                        ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
-
 
1387
                    }
-
 
1388
 
-
 
1389
                    if (collectionMap.get(fofoId) != null) {
-
 
1390
                        PartnerCollectionPlanModel collectionPlan = collectionMap.get(fofoId);
-
 
1391
 
-
 
1392
                        ptam.setRemark(collectionPlan.getRemark());
-
 
1393
                        ptam.setMessage(collectionPlan.getMessage());
-
 
1394
                        ptam.setRemarkTimestamp(collectionPlan.getRemarkTimestamp());
-
 
1395
                        ptam.setRecordingUrl(collectionPlan.getRecordingUrl());
-
 
1396
                        ptam.setScheduledCallTime(collectionPlan.getScheduledCallTime());
-
 
1397
                        ptam.setRank(collectionPlan.getRank());
-
 
1398
                        Integer authId = collectionPlan.getAuthId();
-
 
1399
 
-
 
1400
                        Map<Integer, String> rankColorMap = ProfitMandiConstants.Rank_Color_Map;
-
 
1401
                        ptam.setCollectionColor(rankColorMap.get(collectionPlan.getRank()));
-
 
1402
 
-
 
1403
                        LOGGER.info("authId" + authId);
-
 
1404
 
-
 
1405
                        if (collectionPlan.getTargetPlan() != null && collectionPlan.getCommittedDate() != null) {
-
 
1406
                            float targetCollection = 0;
-
 
1407
 
-
 
1408
                            if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null) {
-
 
1409
                                targetCollection = collectionPlan.getTargetPlan() - collectionPlan.getAchievementPlan();
-
 
1410
                            } else {
-
 
1411
                                targetCollection = collectionPlan.getTargetPlan();
-
 
1412
                            }
-
 
1413
 
-
 
1414
                            if (authId != null && authId == authUser.getId()) {
-
 
1415
                                if (!collectionPlan.getCommittedDate().isAfter(startDate)) {
-
 
1416
                                    totalPartnerTargetCollection += targetCollection;
-
 
1417
                                }
-
 
1418
                            }
-
 
1419
                            ptam.setCollectionTarget(targetCollection);
-
 
1420
                            if (collectionPlan.getRank() == 2 && collectionPlan.getAchievementPlan() != null
-
 
1421
                                    && collectionPlan.getWalletTimestamp() != null
-
 
1422
                                    && collectionPlan.getWalletTimestamp().toLocalDate().equals(startDate.toLocalDate())) {
-
 
1423
                                if (authId != null && authId == authUser.getId()) {
-
 
1424
                                    totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
-
 
1425
                                }
-
 
1426
                                ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
-
 
1427
                            } else if (collectionPlan.getCommittedDate().toLocalDate().isEqual(startDate.toLocalDate())
-
 
1428
                                    && collectionPlan.getAchievementPlan() != null) {
-
 
1429
                                if (authId != null && authId == authUser.getId()) {
-
 
1430
                                    totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
-
 
1431
                                }
-
 
1432
                                ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
-
 
1433
                            }
-
 
1434
                        }
-
 
1435
 
-
 
1436
                        if (authId != null && authId != authUser.getId()) {
-
 
1437
                            ptam.setAuthUser(authUserMap.get(authId));
-
 
1438
                        }
-
 
1439
 
-
 
1440
                        if (collectionPlan.getCommittedDate() != null) {
-
 
1441
                            ptam.setCollectionCommitmentDate(collectionPlan.getCommittedDate().toLocalDate());
-
 
1442
                        }
-
 
1443
                    }
-
 
1444
 
-
 
1445
                    PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
-
 
1446
                    Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
-
 
1447
                    if (partnerSecondaryPlans.get(fofoId) != null) {
-
 
1448
                        long otherBrandSecondary = 0;
-
 
1449
                        for (PartnerSecondaryPlanModel pspm : partnerSecondaryPlans.get(fofoId)) {
-
 
1450
                            Integer authId = pspm.getAuthId();
-
 
1451
                            if (!brands.contains(pspm.getBrand())) {
-
 
1452
                                if (pspm.getAchievementPlan() != null) {
-
 
1453
                                    otherBrandSecondary += pspm.getAchievementPlan();
-
 
1454
                                }
-
 
1455
                            } else {
-
 
1456
                                otherPartnerSecondaryPlanModel = pspm;
-
 
1457
                            }
-
 
1458
                            if (pspm.getTargetPlan() != null) {
-
 
1459
                                totalSecondaryPlan += pspm.getTargetPlan();
-
 
1460
                            }
-
 
1461
 
-
 
1462
                            if (pspm.getAchievementPlan() != null) {
-
 
1463
                                totalSecondaryAchivement += pspm.getAchievementPlan();
-
 
1464
                            }
-
 
1465
 
-
 
1466
                            if (pspm.getCommittedDate() != null) {
-
 
1467
                                ptam.setSecondaryCommitmentDate(pspm.getCommittedDate().toLocalDate());
-
 
1468
                            }
-
 
1469
                            if (authId != null && authId == authUser.getId()) {
-
 
1470
                                if (pspm.getTargetPlan() != null && pspm.getCommittedDate() != null) {
-
 
1471
                                    if (pspm.getCommittedDate().isEqual(startDate)) {
-
 
1472
                                        totalPartnerTargetSecondary += pspm.getTargetPlan();
-
 
1473
                                    }
-
 
1474
                                }
-
 
1475
 
-
 
1476
                                if (pspm.getAchievementPlan() != null) {
-
 
1477
                                    totalPartnerAchievementSecondary += pspm.getAchievementPlan();
-
 
1478
                                }
-
 
1479
                            }
-
 
1480
                        }
-
 
1481
                        if (otherPartnerSecondaryPlanModel != null) {
-
 
1482
                            otherPartnerSecondaryPlanModel.setAchievementPlan(otherBrandSecondary);
-
 
1483
                        }
-
 
1484
                        secondaryModelMap = partnerSecondaryPlans.get(fofoId).stream()
-
 
1485
                                .filter(x -> brands.contains(x.getBrand()))
-
 
1486
                                .collect(Collectors.toMap(x -> x.getBrand(), x -> x));
-
 
1487
 
-
 
1488
                        if (secondaryModelMap.containsKey("Others")) {
-
 
1489
                            PartnerSecondaryPlanModel psp = secondaryModelMap.get("Others");
-
 
1490
                            psp.setAchievementPlan(otherBrandSecondary);
-
 
1491
                        } else {
-
 
1492
                            secondaryModelMap.put("Others", new PartnerSecondaryPlanModel(fofoId, "Others", (long) 0, otherBrandSecondary, authUser.getId(), null));
-
 
1493
                        }
-
 
1494
                        for (String brand : brands) {
-
 
1495
                            if (!secondaryModelMap.containsKey(brand)) {
-
 
1496
                                secondaryModelMap.put(brand, new PartnerSecondaryPlanModel(fofoId, brand, (long) 0, (long) 0, authUser.getId(), null));
-
 
1497
                            }
-
 
1498
                        }
-
 
1499
 
-
 
1500
                        for (Entry<String, PartnerSecondaryPlanModel> secondaryModelEntry : secondaryModelMap.entrySet()) {
-
 
1501
                            Integer authId = secondaryModelEntry.getValue().getAuthId();
-
 
1502
                            if (authId != null && authId != authUser.getId()) {
-
 
1503
                                secondaryModelEntry.getValue().setAuthUser(authUserMap.get(authId));
-
 
1504
                                ptam.setSecondaryColor("red");
-
 
1505
                            }
-
 
1506
                        }
-
 
1507
 
-
 
1508
                        ptam.setPartnerSecondaryModel(secondaryModelMap);
-
 
1509
                        ptam.setTotalSecondaryPlan(totalSecondaryPlan);
-
 
1510
                        ptam.setTotalSecondaryAchievement(totalSecondaryAchivement);
-
 
1511
 
-
 
1512
                    } else {
-
 
1513
                        for (String brand : brands) {
-
 
1514
                            PartnerSecondaryPlanModel pspm = new PartnerSecondaryPlanModel();
-
 
1515
                            pspm.setAchievementPlan((long) 0);
-
 
1516
                            pspm.setTargetPlan((long) 0);
-
 
1517
                            pspm.setBrand(brand);
-
 
1518
                            pspm.setFofoId(fofoId);
-
 
1519
                            secondaryModelMap.put(brand, pspm);
-
 
1520
                        }
-
 
1521
                        ptam.setPartnerSecondaryModel(secondaryModelMap);
-
 
1522
                    }
-
 
1523
 
-
 
1524
                    if (!partnerTicketCount.isEmpty()) {
-
 
1525
                        if (partnerTicketCount.get(fofoId) != null) {
-
 
1526
                            ptam.setTicketCount(partnerTicketCount.get(fofoId));
-
 
1527
                        } else {
-
 
1528
                            ptam.setTicketCount(0);
-
 
1529
                        }
-
 
1530
                    }
-
 
1531
 
-
 
1532
                    boolean hasCreditDue = fofoIdsWithOverdueLoans.contains(fofoId);
-
 
1533
                    ptam.setHasOverdue(hasCreditDue);
-
 
1534
 
-
 
1535
                    int rank = ptam.getRank() > 0 ? ptam.getRank() : 5;
-
 
1536
                    boolean hasZeroBilling = !allMtdBilledFofoIds.contains(fofoId);
-
 
1537
 
-
 
1538
                    if (rank == 1) {
-
 
1539
                        ptam.setCategory("PLAN_TODAY");
-
 
1540
                        ptam.setCategoryPriority(1);
-
 
1541
                    } else if (rank == 2) {
-
 
1542
                        ptam.setCategory("CARRY_FORWARD");
-
 
1543
                        ptam.setCategoryPriority(2);
-
 
1544
                    } else if (hasZeroBilling && rank < 5) {
-
 
1545
                        ptam.setCategory("ZERO_BILLED");
-
 
1546
                        ptam.setCategoryPriority(3);
-
 
1547
                    } else if (rank == 3) {
-
 
1548
                        ptam.setCategory("UNTOUCHED");
-
 
1549
                        ptam.setCategoryPriority(4);
-
 
1550
                    } else {
-
 
1551
                        ptam.setCategory("NORMAL");
-
 
1552
                        ptam.setCategoryPriority(5);
-
 
1553
                    }
-
 
1554
 
-
 
1555
                    ptams.add(ptam);
-
 
1556
                }
-
 
1557
 
-
 
1558
                List<Position> positions = positionRepository.selectPositionByAuthId(authUser.getId()).stream().collect(Collectors.toList());
-
 
1559
                LOGGER.info("positions {}", positions);
-
 
1560
 
-
 
1561
                boolean isRBMAndL1 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && EscalationType.L1.equals(position.getEscalationType()));
-
 
1562
                boolean isRBMAndNotL1 = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_RBM == position.getCategoryId() && !EscalationType.L1.equals(position.getEscalationType()));
-
 
1563
                LOGGER.info("isRBMAndL1{}", isRBMAndL1);
-
 
1564
 
-
 
1565
                boolean isSales = positions.stream().anyMatch(position -> ProfitMandiConstants.TICKET_CATEGORY_SALES == position.getCategoryId());
-
 
1566
 
-
 
1567
                tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
-
 
1568
                tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
-
 
1569
                tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
-
 
1570
                tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
-
 
1571
                tm.setTodayCollectionCount((int) todayCollectionCount);
-
 
1572
                List<PartnerTargetAchievementModel> filteredPtams;
-
 
1573
 
-
 
1574
                if (isRBMAndL1) {
-
 
1575
                    filteredPtams = ptams;
-
 
1576
                } else if (isRBMAndNotL1) {
-
 
1577
                    filteredPtams = ptams;
-
 
1578
                } else if (isSales) {
-
 
1579
                    filteredPtams = ptams.stream()
-
 
1580
                            .filter(ptam -> !(CollectionRemark.RBM_L2_ESCALATION.equals(ptam.getRemark())))
-
 
1581
                            .collect(Collectors.toList());
-
 
1582
                } else {
-
 
1583
                    filteredPtams = ptams;
-
 
1584
                }
-
 
1585
                tm.setRBMAndL1(isRBMAndL1);
-
 
1586
                tm.setRBMAndNotL1(isRBMAndNotL1);
-
 
1587
                tm.setSales(isSales);
-
 
1588
 
-
 
1589
                Map<String, Long> categoryCounts = filteredPtams.stream()
-
 
1590
                        .collect(Collectors.groupingBy(
-
 
1591
                                p -> p.getCategory() != null ? p.getCategory() : "NORMAL",
-
 
1592
                                Collectors.counting()));
-
 
1593
                tm.setOverdueCount((int) filteredPtams.stream().filter(PartnerTargetAchievementModel::isHasOverdue).count());
-
 
1594
                tm.setPlanTodayCount(categoryCounts.getOrDefault("PLAN_TODAY", 0L).intValue());
-
 
1595
                tm.setCarryForwardCount(categoryCounts.getOrDefault("CARRY_FORWARD", 0L).intValue());
-
 
1596
                tm.setZeroBilledCount(categoryCounts.getOrDefault("ZERO_BILLED", 0L).intValue());
-
 
1597
                tm.setUntouchedCount(categoryCounts.getOrDefault("UNTOUCHED", 0L).intValue());
-
 
1598
                tm.setNormalCount(categoryCounts.getOrDefault("NORMAL", 0L).intValue());
-
 
1599
 
-
 
1600
                LocalDateTime now = LocalDateTime.now();
-
 
1601
                LocalDateTime fourHoursAgo = now.minusHours(4);
-
 
1602
                tm.setTargetAchievement(filteredPtams.stream()
-
 
1603
                        .sorted(Comparator
-
 
1604
                                .comparing((PartnerTargetAchievementModel p) -> {
-
 
1605
                                    if (p.getRemarkTimestamp() == null) {
-
 
1606
                                        return false;
-
 
1607
                                    }
-
 
1608
                                    LocalDate remarkDate = p.getRemarkTimestamp().toLocalDate();
-
 
1609
                                    if (!remarkDate.equals(LocalDate.now())) {
-
 
1610
                                        return false;
-
 
1611
                                    }
-
 
1612
                                    if (CollectionRemark.SCHEDULE_CALL.equals(p.getRemark()) || CollectionRemark.NO_ANSWER.equals(p.getRemark())) {
-
 
1613
                                        if (p.getScheduledCallTime() != null) {
-
 
1614
                                            if (!p.getScheduledCallTime().isAfter(now)) {
-
 
1615
                                                return false;
-
 
1616
                                            }
-
 
1617
                                            return true;
-
 
1618
                                        }
-
 
1619
                                        if (CollectionRemark.NO_ANSWER.equals(p.getRemark())
-
 
1620
                                                && p.getRemarkTimestamp().isBefore(fourHoursAgo)) {
-
 
1621
                                            return false;
-
 
1622
                                        }
-
 
1623
                                    }
-
 
1624
                                    return true;
-
 
1625
                                })
-
 
1626
                                .thenComparing(PartnerTargetAchievementModel::getCategoryPriority)
-
 
1627
                                .thenComparing(PartnerTargetAchievementModel::getRank)
-
 
1628
                        )
-
 
1629
                        .collect(Collectors.toList()));
-
 
1630
            }
-
 
1631
        }
-
 
1632
        LOGGER.info("PERF: Total getInactivePartnerTarget took {} ms", System.currentTimeMillis() - startTime);
-
 
1633
        return responseSender.ok(tm);
-
 
1634
 
-
 
1635
    }
-
 
1636
 
1259
    //TODO:Amit
1637
    //TODO:Amit
1260
    @RequestMapping(value = "/target", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
1638
    @RequestMapping(value = "/target", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
1261
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
1639
    @ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header")})
1262
    public ResponseEntity<?> createPartnerTarget(HttpServletRequest request,
1640
    public ResponseEntity<?> createPartnerTarget(HttpServletRequest request,
1263
                                                 @RequestBody PartnerTargetAchievementModel ptam) throws ProfitMandiBusinessException {
1641
                                                 @RequestBody PartnerTargetAchievementModel ptam) throws ProfitMandiBusinessException {