| Line 29... |
Line 29... |
| 29 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
29 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
| 30 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
30 |
import com.spice.profitmandi.dao.repository.dtr.*;
|
| 31 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
31 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| 32 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
32 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 33 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
33 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| - |
|
34 |
import com.spice.profitmandi.service.PartnerCollectionService;
|
| 34 |
import com.spice.profitmandi.service.user.RetailerService;
|
35 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 35 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
36 |
import com.spice.profitmandi.service.user.StoreTimelineTatService;
|
| 36 |
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
|
37 |
import com.spice.profitmandi.web.req.CreateFranchiseeRequest;
|
| 37 |
import com.spice.profitmandi.web.res.Partner;
|
38 |
import com.spice.profitmandi.web.res.Partner;
|
| 38 |
import io.swagger.annotations.ApiImplicitParam;
|
39 |
import io.swagger.annotations.ApiImplicitParam;
|
| Line 102... |
Line 103... |
| 102 |
private FofoStoreRepository fofoStoreRepository;
|
103 |
private FofoStoreRepository fofoStoreRepository;
|
| 103 |
|
104 |
|
| 104 |
@Autowired
|
105 |
@Autowired
|
| 105 |
private StoreTimelineTatService storeTimelineTatService;
|
106 |
private StoreTimelineTatService storeTimelineTatService;
|
| 106 |
|
107 |
|
| - |
|
108 |
@Autowired
|
| - |
|
109 |
private PartnerCollectionService partnerCollectionService;
|
| - |
|
110 |
|
| 107 |
@RequestMapping(value = "/lead", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
111 |
@RequestMapping(value = "/lead", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
|
| 108 |
@ApiImplicitParams({
|
112 |
@ApiImplicitParams({
|
| 109 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
113 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", required = true, dataType = "string", paramType = "header") })
|
| 110 |
public ResponseEntity<?> LeadUser(HttpServletRequest request,
|
114 |
public ResponseEntity<?> LeadUser(HttpServletRequest request,
|
| 111 |
@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
|
115 |
@RequestBody CreateRefferalRequest createRefferalRequest) throws Exception {
|
| Line 566... |
Line 570... |
| 566 |
@RequestParam(name = "gmailId") String gmailId, @RequestParam String dayValue)
|
570 |
@RequestParam(name = "gmailId") String gmailId, @RequestParam String dayValue)
|
| 567 |
throws ProfitMandiBusinessException {
|
571 |
throws ProfitMandiBusinessException {
|
| 568 |
|
572 |
|
| 569 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
573 |
AuthUser authUser = authRepository.selectByGmailId(gmailId);
|
| 570 |
|
574 |
|
| 571 |
Set<Integer> fofoIds = authUserPartnerMappingRepository.selectByAuthId(authUser.getId()).stream()
|
- |
|
| 572 |
.map(x -> x.getFofoId()).collect(Collectors.toSet());
|
- |
|
| 573 |
|
- |
|
| 574 |
if (authUser.getEmailId().equals("tarun.verma@smartdukaan.com")
|
- |
|
| 575 |
|| authUser.getEmailId().equals("rakesh.sonawane@smartdukaan.com")) {
|
- |
|
| 576 |
|
- |
|
| 577 |
fofoIds = fofoStoreRepository.selectAll().stream().filter(x -> !x.isInternal() && x.isActive())
|
- |
|
| 578 |
.map(x -> x.getId()).collect(Collectors.toSet());
|
- |
|
| 579 |
|
- |
|
| 580 |
}
|
- |
|
| 581 |
|
- |
|
| 582 |
if (authUser.getEmailId().equals("mohit.gulati@smartdukaan.com")
|
- |
|
| 583 |
|| authUser.getEmailId().equals("manish.gupta@smartdukaan.com")) {
|
- |
|
| 584 |
|
- |
|
| 585 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
575 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| 586 |
|
576 |
|
| 587 |
fofoIds = storeGuyMap.get(authUser.getEmailId());
|
577 |
Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
|
| 588 |
|
- |
|
| 589 |
}
|
- |
|
| 590 |
|
578 |
|
| 591 |
List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Almost New", "Others");
|
579 |
List<String> brands = Arrays.asList("Vivo", "Samsung", "Oppo", "Itel", "Almost New", "Others");
|
| - |
|
580 |
|
| 592 |
float totalPartnerTargetSecondary = 0;
|
581 |
float totalPartnerTargetSecondary = 0;
|
| 593 |
float totalPartnerTargetCollection = 0;
|
582 |
float totalPartnerTargetCollection = 0;
|
| 594 |
float totalPartnerAchievementSecondary = 0;
|
583 |
float totalPartnerAchievementSecondary = 0;
|
| 595 |
float totalPartnerAchievementCollection = 0;
|
584 |
float totalPartnerAchievementCollection = 0;
|
| 596 |
TargetModel tm = new TargetModel();
|
585 |
TargetModel tm = new TargetModel();
|
| Line 627... |
Line 616... |
| 627 |
|
616 |
|
| 628 |
Map<Integer, PartnerCollectionAchievementModel> collectionAchievementMap = userWalletRepository
|
617 |
Map<Integer, PartnerCollectionAchievementModel> collectionAchievementMap = userWalletRepository
|
| 629 |
.getPartnerWiseCollectionAchievement(fofoIdList, startDate).stream()
|
618 |
.getPartnerWiseCollectionAchievement(fofoIdList, startDate).stream()
|
| 630 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
619 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 631 |
|
620 |
|
| 632 |
Set<Integer> maxCommitedIds = partnerCollectionPlanRepository.selectMaxCommitedDate(fofoIdList, startDate)
|
- |
|
| 633 |
.stream().map(x -> x.getId()).collect(Collectors.toSet());
|
- |
|
| 634 |
|
- |
|
| 635 |
List<PartnerCollectionPlanModel> foundCollections = partnerCollectionPlanRepository
|
- |
|
| 636 |
.getUntouchedPartner(new ArrayList<>(maxCommitedIds));
|
- |
|
| 637 |
|
- |
|
| 638 |
List<Integer> foundCollectionIds = foundCollections.stream().map(x -> x.getPcpId())
|
- |
|
| 639 |
.collect(Collectors.toList());
|
- |
|
| 640 |
|
- |
|
| 641 |
Set<Integer> foundCollectionFofoIds = foundCollections.stream().map(x -> x.getFofoId())
|
- |
|
| 642 |
.collect(Collectors.toSet());
|
- |
|
| 643 |
|
- |
|
| 644 |
List<Integer> unfoundCollectionIds = maxCommitedIds.stream().filter(x -> !foundCollectionIds.contains(x))
|
- |
|
| 645 |
.collect(Collectors.toList());
|
- |
|
| 646 |
|
- |
|
| 647 |
List<PartnerCollectionPlan> unfoundCollections = partnerCollectionPlanRepository
|
- |
|
| 648 |
.selectByIds(unfoundCollectionIds);
|
- |
|
| 649 |
|
- |
|
| 650 |
Set<Integer> unfoundCollectionFofoIds = unfoundCollections.stream().map(x -> x.getFofoId())
|
- |
|
| 651 |
.collect(Collectors.toSet());
|
- |
|
| 652 |
|
- |
|
| 653 |
List<Integer> untouchedCollectionFofoIds = fofoIdList.stream()
|
- |
|
| 654 |
.filter(x -> !foundCollectionFofoIds.contains(x) && !unfoundCollectionFofoIds.contains(x))
|
- |
|
| 655 |
.collect(Collectors.toList());
|
- |
|
| 656 |
|
- |
|
| 657 |
for (PartnerCollectionPlan unfoundCollection : unfoundCollections) {
|
- |
|
| 658 |
PartnerCollectionPlanModel pcpm = new PartnerCollectionPlanModel();
|
- |
|
| 659 |
|
- |
|
| 660 |
pcpm.setFofoId(unfoundCollection.getFofoId());
|
- |
|
| 661 |
pcpm.setTargetPlan((long) unfoundCollection.getCollectionPlan());
|
- |
|
| 662 |
pcpm.setAuthId(unfoundCollection.getAuthId());
|
- |
|
| 663 |
pcpm.setCommittedDate(unfoundCollection.getCommitedTimestamp());
|
- |
|
| 664 |
pcpm.setCreatedDate(unfoundCollection.getCreateTimestamp());
|
- |
|
| 665 |
pcpm.setPcpId(unfoundCollection.getId());
|
- |
|
| 666 |
|
- |
|
| 667 |
foundCollections.add(pcpm);
|
- |
|
| 668 |
|
- |
|
| 669 |
}
|
- |
|
| 670 |
for (Integer fofoId : untouchedCollectionFofoIds) {
|
- |
|
| 671 |
|
- |
|
| 672 |
PartnerCollectionPlanModel pcpm = new PartnerCollectionPlanModel();
|
- |
|
| 673 |
pcpm.setFofoId(fofoId);
|
- |
|
| 674 |
foundCollections.add(pcpm);
|
- |
|
| 675 |
}
|
- |
|
| 676 |
|
- |
|
| 677 |
Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = foundCollections.stream()
|
- |
|
| 678 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
- |
|
| 679 |
|
- |
|
| 680 |
Map<Integer, PartnerCollectionPlan> todayTarget = partnerCollectionPlanRepository
|
621 |
Map<Integer, PartnerCollectionPlan> todayTarget = partnerCollectionPlanRepository
|
| 681 |
.selectByLocalDateAndFofoIds(startDate.toLocalDate(), fofoIdList, true).stream()
|
622 |
.selectByLocalDateAndFofoIds(startDate.toLocalDate(), fofoIdList, true).stream()
|
| 682 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
623 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 683 |
|
624 |
|
| 684 |
LOGGER.info("todayTarget {}", todayTarget);
|
- |
|
| 685 |
|
- |
|
| 686 |
int todayCollectionCount = todayTarget.size();
|
625 |
int todayCollectionCount = todayTarget.size();
|
| - |
|
626 |
Map<Integer, PartnerCollectionPlanModel> foundCollectionMap = partnerCollectionService
|
| - |
|
627 |
.getCollectionMap(fofoIdList, startDate);
|
| 687 |
|
628 |
|
| 688 |
for (PartnerCollectionPlanModel collectionModel : foundCollections) {
|
- |
|
| 689 |
|
- |
|
| 690 |
if (collectionModel.getAchievementPlan() == null) {
|
- |
|
| 691 |
collectionModel.setAchievementPlan((long) 0);
|
- |
|
| 692 |
}
|
- |
|
| 693 |
if (collectionModel.getCommittedDate() == null) {
|
- |
|
| 694 |
collectionModel.setRank(3);
|
- |
|
| 695 |
} else if (collectionModel.getCommittedDate().toLocalDate().equals(LocalDate.now())
|
- |
|
| 696 |
&& collectionModel.getCreatedDate().toLocalDate().isBefore(LocalDate.now())) {
|
- |
|
| 697 |
collectionModel.setRank(1);
|
- |
|
| 698 |
} else if (collectionModel.getCommittedDate().toLocalDate().isAfter(LocalDate.now())) {
|
- |
|
| 699 |
collectionModel.setRank(4);
|
- |
|
| 700 |
} else if (collectionModel.getCommittedDate().toLocalDate().isBefore(LocalDate.now().minusDays(4))
|
- |
|
| 701 |
&& collectionModel.getAchievementPlan() >= 5000) {
|
- |
|
| 702 |
collectionModel.setRank(3);
|
- |
|
| 703 |
collectionModel.setTargetPlan((long) 0);
|
- |
|
| 704 |
collectionModel.setAuthId(0);
|
- |
|
| 705 |
collectionModel.setCommittedDate(null);
|
- |
|
| 706 |
|
- |
|
| 707 |
if (todayTarget.get(collectionModel.getFofoId()) != null) {
|
- |
|
| 708 |
if (todayTarget.get(collectionModel.getFofoId()).getCreateTimestamp().toLocalDate()
|
- |
|
| 709 |
.isEqual(LocalDate.now())) {
|
- |
|
| 710 |
collectionModel.setTargetPlan(
|
- |
|
| 711 |
(long) todayTarget.get(collectionModel.getFofoId()).getCollectionPlan());
|
- |
|
| 712 |
collectionModel.setCommittedDate(
|
- |
|
| 713 |
todayTarget.get(collectionModel.getFofoId()).getCommitedTimestamp());
|
- |
|
| 714 |
|
- |
|
| 715 |
collectionModel.setAuthId(todayTarget.get(collectionModel.getFofoId()).getAuthId());
|
- |
|
| 716 |
}
|
- |
|
| 717 |
}
|
- |
|
| 718 |
|
- |
|
| 719 |
} else if (collectionModel.getCommittedDate().toLocalDate().isBefore(LocalDate.now())
|
- |
|
| 720 |
&& collectionModel.getAchievementPlan() < 5000) {
|
- |
|
| 721 |
collectionModel.setRank(2);
|
- |
|
| 722 |
|
- |
|
| 723 |
} else {
|
- |
|
| 724 |
|
- |
|
| 725 |
collectionModel.setRank(5);
|
- |
|
| 726 |
if (!collectionModel.getCreatedDate().toLocalDate().equals(LocalDate.now())) {
|
- |
|
| 727 |
collectionModel.setTargetPlan((long) 0);
|
- |
|
| 728 |
}
|
- |
|
| 729 |
}
|
- |
|
| 730 |
|
- |
|
| 731 |
if (todayTarget.get(collectionModel.getFofoId()) != null) {
|
- |
|
| 732 |
if (todayTarget.get(collectionModel.getFofoId()).getCreateTimestamp().toLocalDate()
|
- |
|
| 733 |
.isEqual(LocalDate.now())) {
|
- |
|
| 734 |
collectionModel
|
- |
|
| 735 |
.setTargetPlan((long) todayTarget.get(collectionModel.getFofoId()).getCollectionPlan());
|
- |
|
| 736 |
collectionModel
|
- |
|
| 737 |
.setCommittedDate(todayTarget.get(collectionModel.getFofoId()).getCommitedTimestamp());
|
- |
|
| 738 |
|
- |
|
| 739 |
collectionModel.setAuthId(todayTarget.get(collectionModel.getFofoId()).getAuthId());
|
- |
|
| 740 |
}
|
- |
|
| 741 |
}
|
- |
|
| 742 |
|
- |
|
| 743 |
}
|
- |
|
| 744 |
LOGGER.info("updatedList {}", foundCollections);
|
- |
|
| 745 |
Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
|
629 |
Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
|
| 746 |
.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
|
630 |
.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
|
| 747 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
631 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 748 |
|
632 |
|
| 749 |
LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
|
633 |
LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
|