| Line 617... |
Line 617... |
| 617 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
617 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 618 |
}
|
618 |
}
|
| 619 |
|
619 |
|
| 620 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
|
620 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(fofoIdList);
|
| 621 |
|
621 |
|
| - |
|
622 |
/*
|
| - |
|
623 |
* Map<Integer, PartnerCollectionPlanModel> collectionPlans =
|
| - |
|
624 |
* userWalletRepository .getPartnerWiseTargetCollections(fofoIdList,
|
| - |
|
625 |
* startDate).stream() .collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
626 |
*/
|
| - |
|
627 |
|
| 622 |
Map<Integer, PartnerCollectionPlanModel> collectionPlans = userWalletRepository
|
628 |
Map<Integer, PartnerCollectionAchievementModel> collectionAchievementMap = userWalletRepository
|
| 623 |
.getPartnerWiseTargetCollections(fofoIdList, startDate).stream()
|
629 |
.getPartnerWiseCollectionAchievement(fofoIdList, startDate).stream()
|
| 624 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
630 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 625 |
|
631 |
|
| - |
|
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
|
| - |
|
681 |
.selectByLocalDateAndFofoIds(startDate.toLocalDate(), fofoIdList, true).stream()
|
| - |
|
682 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| - |
|
683 |
|
| 626 |
LOGGER.info("collectionPlans {}", collectionPlans);
|
684 |
LOGGER.info("todayTarget {}", todayTarget);
|
| - |
|
685 |
|
| - |
|
686 |
int todayCollectionCount = todayTarget.size();
|
| - |
|
687 |
|
| - |
|
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 |
}
|
| - |
|
713 |
}
|
| - |
|
714 |
|
| - |
|
715 |
} else if (collectionModel.getCommittedDate().toLocalDate().isBefore(LocalDate.now())
|
| - |
|
716 |
&& collectionModel.getAchievementPlan() < 5000) {
|
| - |
|
717 |
collectionModel.setRank(2);
|
| - |
|
718 |
} else {
|
| - |
|
719 |
|
| - |
|
720 |
collectionModel.setRank(5);
|
| - |
|
721 |
if (!collectionModel.getCreatedDate().toLocalDate().equals(LocalDate.now())) {
|
| - |
|
722 |
collectionModel.setTargetPlan((long) 0);
|
| - |
|
723 |
}
|
| - |
|
724 |
}
|
| 627 |
|
725 |
|
| - |
|
726 |
}
|
| - |
|
727 |
LOGGER.info("updatedList {}", foundCollections);
|
| 628 |
Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
|
728 |
Map<Integer, List<PartnerSecondaryPlanModel>> partnerSecondayPlans = orderRepository
|
| 629 |
.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
|
729 |
.selectPartnerSecondaryGroupByBrand(fofoIdList, startDate.toLocalDate()).stream()
|
| 630 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
730 |
.collect(Collectors.groupingBy(x -> x.getFofoId()));
|
| 631 |
|
731 |
|
| 632 |
LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
|
732 |
LOGGER.info("partnerSecondayPlans {}", partnerSecondayPlans);
|
| Line 643... |
Line 743... |
| 643 |
if (partnerDailyInvestmentMap.get(fofoId) != null) {
|
743 |
if (partnerDailyInvestmentMap.get(fofoId) != null) {
|
| 644 |
ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
|
744 |
ptam.setWalletAmount(partnerDailyInvestmentMap.get(fofoId).getWalletAmount());
|
| 645 |
ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
|
745 |
ptam.setShortInvestment(partnerDailyInvestmentMap.get(fofoId).getShortInvestment());
|
| 646 |
}
|
746 |
}
|
| 647 |
|
747 |
|
| 648 |
if (collectionPlans.get(fofoId) != null) {
|
748 |
if (foundCollectionMap.get(fofoId) != null) {
|
| 649 |
PartnerCollectionPlanModel collectionPlan = collectionPlans.get(fofoId);
|
749 |
PartnerCollectionPlanModel collectionPlan = foundCollectionMap.get(fofoId);
|
| - |
|
750 |
PartnerCollectionAchievementModel collectionAchievement = collectionAchievementMap.get(fofoId);
|
| 650 |
|
751 |
|
| - |
|
752 |
ptam.setRank(collectionPlan.getRank());
|
| 651 |
Integer authId = collectionPlan.getAuthId();
|
753 |
Integer authId = collectionPlan.getAuthId();
|
| - |
|
754 |
|
| - |
|
755 |
if (collectionPlan.getRank() == 1) {
|
| - |
|
756 |
ptam.setCollectionColor("#007bff");
|
| - |
|
757 |
} else if (collectionPlan.getRank() == 2) {
|
| - |
|
758 |
ptam.setCollectionColor("#ffc107");
|
| - |
|
759 |
} else if (collectionPlan.getRank() == 3) {
|
| - |
|
760 |
ptam.setCollectionColor("#dc3545");
|
| - |
|
761 |
} else if (collectionPlan.getRank() == 4) {
|
| - |
|
762 |
ptam.setCollectionColor("#6c757d");
|
| - |
|
763 |
} else {
|
| - |
|
764 |
ptam.setCollectionColor("White");
|
| - |
|
765 |
}
|
| - |
|
766 |
|
| 652 |
LOGGER.info("authId" + authId);
|
767 |
LOGGER.info("authId" + authId);
|
| 653 |
if (authId != null && authId == authUser.getId()) {
|
- |
|
| 654 |
|
768 |
|
| 655 |
if (collectionPlan.getTargetPlan() != null && collectionPlan.getCommittedDate() != null) {
|
769 |
if (collectionPlan.getTargetPlan() != null && collectionPlan.getCommittedDate() != null) {
|
| - |
|
770 |
float targetCollection = 0;
|
| 656 |
|
771 |
|
| 657 |
if (collectionPlan.getCommittedDate().isEqual(startDate)) {
|
772 |
if (collectionPlan.getRank() == 2) {
|
| 658 |
totalPartnerTargetCollection += collectionPlan.getTargetPlan();
|
773 |
targetCollection = collectionPlan.getTargetPlan() - collectionPlan.getAchievementPlan();
|
| 659 |
}
|
774 |
} else {
|
| - |
|
775 |
targetCollection = collectionPlan.getTargetPlan();
|
| 660 |
}
|
776 |
}
|
| - |
|
777 |
|
| 661 |
if (collectionPlan.getAchievementPlan() != null) {
|
778 |
if (!collectionPlan.getCommittedDate().isAfter(startDate)) {
|
| 662 |
totalPartnerAchievementCollection += collectionPlan.getAchievementPlan();
|
779 |
totalPartnerTargetCollection += targetCollection;
|
| 663 |
}
|
780 |
}
|
| - |
|
781 |
ptam.setCollectionTarget(targetCollection);
|
| - |
|
782 |
}
|
| - |
|
783 |
if (collectionAchievement.getAmount() != null) {
|
| - |
|
784 |
totalPartnerAchievementCollection += collectionAchievement.getAmount();
|
| 664 |
|
785 |
|
| - |
|
786 |
ptam.setCollectionAchievement(collectionAchievement.getAmount());
|
| 665 |
}
|
787 |
}
|
| 666 |
|
788 |
|
| 667 |
if (authId != null && authId != authUser.getId()) {
|
789 |
if (authId != null && authId != authUser.getId()) {
|
| 668 |
ptam.setAuthUser(authRepository.selectById(authId));
|
790 |
ptam.setAuthUser(authRepository.selectById(authId));
|
| 669 |
ptam.setCollectionColor("red");
|
- |
|
| 670 |
}
|
- |
|
| 671 |
if (collectionPlans.get(fofoId).getTargetPlan() != null) {
|
- |
|
| 672 |
|
791 |
|
| 673 |
ptam.setCollectionTarget(collectionPlan.getTargetPlan());
|
- |
|
| 674 |
}
|
- |
|
| 675 |
|
- |
|
| 676 |
if (collectionPlans.get(fofoId).getAchievementPlan() != null) {
|
- |
|
| 677 |
ptam.setCollectionAchievement(collectionPlan.getAchievementPlan());
|
- |
|
| 678 |
}
|
792 |
}
|
| 679 |
|
793 |
|
| 680 |
if (collectionPlan.getCommittedDate() != null) {
|
794 |
if (collectionPlan.getCommittedDate() != null) {
|
| 681 |
|
795 |
|
| 682 |
ptam.setCollectionCommitmentDate(collectionPlan.getCommittedDate().toLocalDate());
|
796 |
ptam.setCollectionCommitmentDate(collectionPlan.getCommittedDate().toLocalDate());
|
| 683 |
}
|
797 |
}
|
| 684 |
}
|
798 |
}
|
| 685 |
|
799 |
|
| - |
|
800 |
// Secondary
|
| - |
|
801 |
|
| 686 |
PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
|
802 |
PartnerSecondaryPlanModel otherPartnerSecondaryPlanModel = null;
|
| 687 |
Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
|
803 |
Map<String, PartnerSecondaryPlanModel> secondaryModelMap = new HashMap<>();
|
| 688 |
if (partnerSecondayPlans.get(fofoId) != null) {
|
804 |
if (partnerSecondayPlans.get(fofoId) != null) {
|
| 689 |
|
- |
|
| 690 |
long otherBrandSecondary = 0;
|
805 |
long otherBrandSecondary = 0;
|
| 691 |
for (PartnerSecondaryPlanModel pspm : partnerSecondayPlans.get(fofoId)) {
|
806 |
for (PartnerSecondaryPlanModel pspm : partnerSecondayPlans.get(fofoId)) {
|
| 692 |
Integer authId = pspm.getAuthId();
|
807 |
Integer authId = pspm.getAuthId();
|
| 693 |
if (!brands.contains(pspm.getBrand())) {
|
808 |
if (!brands.contains(pspm.getBrand())) {
|
| 694 |
if (pspm.getAchievementPlan() != null) {
|
809 |
if (pspm.getAchievementPlan() != null) {
|
| 695 |
otherBrandSecondary += pspm.getAchievementPlan();
|
810 |
otherBrandSecondary += pspm.getAchievementPlan();
|
| 696 |
}
|
811 |
}
|
| 697 |
} else {
|
812 |
} else {
|
| 698 |
otherPartnerSecondaryPlanModel = pspm;
|
813 |
otherPartnerSecondaryPlanModel = pspm;
|
| 699 |
}
|
814 |
}
|
| 700 |
|
- |
|
| 701 |
if (pspm.getTargetPlan() != null) {
|
815 |
if (pspm.getTargetPlan() != null) {
|
| 702 |
totalSecondaryPlan += pspm.getTargetPlan();
|
816 |
totalSecondaryPlan += pspm.getTargetPlan();
|
| 703 |
}
|
817 |
}
|
| 704 |
|
818 |
|
| 705 |
if (pspm.getAchievementPlan() != null) {
|
819 |
if (pspm.getAchievementPlan() != null) {
|
| Line 756... |
Line 870... |
| 756 |
}
|
870 |
}
|
| 757 |
|
871 |
|
| 758 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
872 |
ptam.setPartnerSecondaryModel(secondaryModelMap);
|
| 759 |
ptam.setTotalSecondaryPlan(totalSecondaryPlan);
|
873 |
ptam.setTotalSecondaryPlan(totalSecondaryPlan);
|
| 760 |
ptam.setTotalSecondaryAchievement(totalSecondaryAchivement);
|
874 |
ptam.setTotalSecondaryAchievement(totalSecondaryAchivement);
|
| - |
|
875 |
// Secondary
|
| 761 |
|
876 |
|
| 762 |
} else {
|
877 |
} else {
|
| 763 |
for (String brand : brands) {
|
878 |
for (String brand : brands) {
|
| 764 |
PartnerSecondaryPlanModel pspm = new PartnerSecondaryPlanModel();
|
879 |
PartnerSecondaryPlanModel pspm = new PartnerSecondaryPlanModel();
|
| 765 |
pspm.setAchievementPlan((long) 0);
|
880 |
pspm.setAchievementPlan((long) 0);
|
| Line 777... |
Line 892... |
| 777 |
|
892 |
|
| 778 |
tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
|
893 |
tm.setTotalPartnerTargetCollection(totalPartnerTargetCollection);
|
| 779 |
tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
|
894 |
tm.setTotalPartnerTargetSecondary(totalPartnerTargetSecondary);
|
| 780 |
tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
|
895 |
tm.setTotalPartnerSecondary(totalPartnerAchievementSecondary);
|
| 781 |
tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
|
896 |
tm.setTotalPartnerCollection(totalPartnerAchievementCollection);
|
| - |
|
897 |
tm.setTodayCollectionCount(todayCollectionCount);
|
| 782 |
|
898 |
|
| 783 |
tm.setTargetAchievement(ptams.stream()
|
- |
|
| 784 |
.sorted(Comparator.comparing(PartnerTargetAchievementModel::getShortInvestment).reversed())
|
899 |
tm.setTargetAchievement(ptams.stream().sorted(Comparator.comparing(PartnerTargetAchievementModel::getRank))
|
| 785 |
.collect(Collectors.toList()));
|
900 |
.collect(Collectors.toList()));
|
| 786 |
|
901 |
|
| 787 |
}
|
902 |
}
|
| 788 |
|
903 |
|
| 789 |
return responseSender.ok(tm);
|
904 |
return responseSender.ok(tm);
|