| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.dao.repository.cs;
|
1 |
package com.spice.profitmandi.dao.repository.cs;
|
| 2 |
|
2 |
|
| - |
|
3 |
import java.time.LocalDate;
|
| 3 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| - |
|
5 |
import java.time.LocalTime;
|
| 4 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 5 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| 6 |
import java.util.Collection;
|
8 |
import java.util.Collection;
|
| 7 |
import java.util.HashMap;
|
9 |
import java.util.HashMap;
|
| 8 |
import java.util.HashSet;
|
10 |
import java.util.HashSet;
|
| - |
|
11 |
import java.util.LinkedHashMap;
|
| 9 |
import java.util.List;
|
12 |
import java.util.List;
|
| 10 |
import java.util.Map;
|
13 |
import java.util.Map;
|
| 11 |
import java.util.Map.Entry;
|
14 |
import java.util.Map.Entry;
|
| 12 |
import java.util.Set;
|
15 |
import java.util.Set;
|
| 13 |
import java.util.stream.Collectors;
|
16 |
import java.util.stream.Collectors;
|
| Line 35... |
Line 38... |
| 35 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
38 |
import com.spice.profitmandi.dao.entity.cs.Ticket;
|
| 36 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
39 |
import com.spice.profitmandi.dao.entity.cs.TicketAssigned;
|
| 37 |
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
|
40 |
import com.spice.profitmandi.dao.entity.cs.TicketCategory;
|
| 38 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
41 |
import com.spice.profitmandi.dao.entity.cs.TicketSubCategory;
|
| 39 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
42 |
import com.spice.profitmandi.dao.entity.fofo.ActivityType;
|
| - |
|
43 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| - |
|
44 |
import com.spice.profitmandi.dao.entity.user.Lead;
|
| 40 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
45 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| - |
|
46 |
import com.spice.profitmandi.dao.enumuration.dtr.LeadStatus;
|
| - |
|
47 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
| 41 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
48 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
| 42 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
49 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| - |
|
50 |
import com.spice.profitmandi.dao.repository.dtr.LeadRepository;
|
| - |
|
51 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| - |
|
52 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
| - |
|
53 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| - |
|
54 |
import com.spice.profitmandi.service.PartnerInvestmentService;
|
| 43 |
import com.spice.profitmandi.service.user.RetailerService;
|
55 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 44 |
|
56 |
|
| 45 |
@Component
|
57 |
@Component
|
| 46 |
public class CsServiceImpl implements CsService {
|
58 |
public class CsServiceImpl implements CsService {
|
| 47 |
|
59 |
|
| Line 87... |
Line 99... |
| 87 |
private PartnersPositionRepository partnersPositionRepository;
|
99 |
private PartnersPositionRepository partnersPositionRepository;
|
| 88 |
|
100 |
|
| 89 |
@Autowired
|
101 |
@Autowired
|
| 90 |
private FofoStoreRepository fofoStoreRepository;
|
102 |
private FofoStoreRepository fofoStoreRepository;
|
| 91 |
|
103 |
|
| - |
|
104 |
@Autowired
|
| - |
|
105 |
private FofoOrderItemRepository fofoOrderItemRepository;
|
| - |
|
106 |
|
| - |
|
107 |
@Autowired
|
| - |
|
108 |
private LeadRepository leadRepository;
|
| - |
|
109 |
|
| - |
|
110 |
@Autowired
|
| - |
|
111 |
private HygieneDataRepository hygieneDataRepository;
|
| - |
|
112 |
|
| - |
|
113 |
@Autowired
|
| - |
|
114 |
private PartnerInvestmentService partnerInvestmentService;
|
| - |
|
115 |
|
| - |
|
116 |
@Autowired
|
| - |
|
117 |
private PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
| - |
|
118 |
|
| 92 |
@Override
|
119 |
@Override
|
| 93 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
|
120 |
public void createTicket(int fofoId, int categoryId, int subcategoryId, String message)
|
| 94 |
throws ProfitMandiBusinessException {
|
121 |
throws ProfitMandiBusinessException {
|
| 95 |
|
122 |
|
| 96 |
ActivityType type = ActivityType.OPENED;
|
123 |
ActivityType type = ActivityType.OPENED;
|
| Line 651... |
Line 678... |
| 651 |
|
678 |
|
| 652 |
Map<Integer, List<Integer>> l2andl1Map = l1andl2Map.entrySet().stream().collect(
|
679 |
Map<Integer, List<Integer>> l2andl1Map = l1andl2Map.entrySet().stream().collect(
|
| 653 |
Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList())));
|
680 |
Collectors.groupingBy(Map.Entry::getValue, Collectors.mapping(Map.Entry::getKey, Collectors.toList())));
|
| 654 |
return l2andl1Map;
|
681 |
return l2andl1Map;
|
| 655 |
}
|
682 |
}
|
| - |
|
683 |
|
| - |
|
684 |
@Override
|
| - |
|
685 |
public Map<Integer, Object> getL2AuthUserPartnerDetail() throws Exception {
|
| - |
|
686 |
List<Position> pos = positionRepository.selectPositionbyCategoryIdAndEscalationType(
|
| - |
|
687 |
ProfitMandiConstants.TICKET_CATEGORY_SALES, EscalationType.L2);
|
| - |
|
688 |
|
| - |
|
689 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| - |
|
690 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(
|
| - |
|
691 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
| - |
|
692 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1),
|
| - |
|
693 |
curDate.with(LocalTime.MAX), 0, false);
|
| - |
|
694 |
|
| - |
|
695 |
Map<Integer, List<Integer>> pp = this.getAuthUserIdPartnerIdMapping();
|
| - |
|
696 |
Map<Integer, Long> ticketMap = ticketRepository.selectAllNotClosedTicketsGroupByRetailer();
|
| - |
|
697 |
Map<Integer, Integer> authIdAndleadsCountMap = new HashMap<>();
|
| - |
|
698 |
Map<Integer, List<Integer>> L2L1Mapping = this.getL1L2Mapping();
|
| - |
|
699 |
|
| - |
|
700 |
for (Entry<Integer, List<Integer>> l2l1 : L2L1Mapping.entrySet()) {
|
| - |
|
701 |
List<Integer> authIds = l2l1.getValue();
|
| - |
|
702 |
authIds.add(l2l1.getKey());
|
| - |
|
703 |
|
| - |
|
704 |
List<Lead> leads = leadRepository.selectByAssignAuthIdsAndStatus(authIds, LeadStatus.followUp);
|
| - |
|
705 |
|
| - |
|
706 |
AuthUser auth = authRepository.selectById(l2l1.getKey());
|
| - |
|
707 |
authIdAndleadsCountMap.put(auth.getId(), leads.size());
|
| - |
|
708 |
}
|
| - |
|
709 |
|
| - |
|
710 |
Map<Integer, Object> authIdAndallValues = new LinkedHashMap<>();
|
| - |
|
711 |
|
| - |
|
712 |
for (Position po : pos) {
|
| - |
|
713 |
|
| - |
|
714 |
double totallmtdAmount = 0;
|
| - |
|
715 |
double totalmtdAmount = 0;
|
| - |
|
716 |
int totalTicketCount = 0;
|
| - |
|
717 |
float totalTodayInvestment = 0;
|
| - |
|
718 |
float totalStockInInvestment = 0;
|
| - |
|
719 |
double currentMonthRatingAllPartners = 0;
|
| - |
|
720 |
|
| - |
|
721 |
AuthUser auth = authRepository.selectById(po.getAuthUserId());
|
| - |
|
722 |
|
| - |
|
723 |
List<Integer> fofoIds = pp.get(po.getAuthUserId());
|
| - |
|
724 |
|
| - |
|
725 |
for (Integer fId : fofoIds) {
|
| - |
|
726 |
Map<String, Object> investmentMap = this.getInvestments(fId);
|
| - |
|
727 |
|
| - |
|
728 |
double currentMonthRating = hygieneDataRepository.selectRatingAvg(fId,
|
| - |
|
729 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
| - |
|
730 |
|
| - |
|
731 |
currentMonthRatingAllPartners += currentMonthRating;
|
| - |
|
732 |
|
| - |
|
733 |
fofoIds.size();
|
| - |
|
734 |
|
| - |
|
735 |
Double lmtdAmount = lmtdSale.get(fId);
|
| - |
|
736 |
Double mtdAmount = mtdSale.get(fId);
|
| - |
|
737 |
Long ticketCount = ticketMap.get(fId);
|
| - |
|
738 |
|
| - |
|
739 |
if (!investmentMap.isEmpty()) {
|
| - |
|
740 |
totalTodayInvestment += (float) investmentMap.get("today");
|
| - |
|
741 |
totalStockInInvestment += (float) investmentMap.get("inStock");
|
| - |
|
742 |
|
| - |
|
743 |
}
|
| - |
|
744 |
LOGGER.info("totalTodayInvestment" + totalTodayInvestment);
|
| - |
|
745 |
LOGGER.info("totalStockInInvestment" + totalStockInInvestment);
|
| - |
|
746 |
if (ticketCount != null) {
|
| - |
|
747 |
totalTicketCount += ticketCount;
|
| - |
|
748 |
}
|
| - |
|
749 |
|
| - |
|
750 |
if (lmtdAmount != null) {
|
| - |
|
751 |
totallmtdAmount += lmtdAmount;
|
| - |
|
752 |
}
|
| - |
|
753 |
|
| - |
|
754 |
if (mtdAmount != null) {
|
| - |
|
755 |
totalmtdAmount += mtdAmount;
|
| - |
|
756 |
}
|
| - |
|
757 |
|
| - |
|
758 |
}
|
| - |
|
759 |
LOGGER.info("currentMonthRatingAllPartners" + currentMonthRatingAllPartners);
|
| - |
|
760 |
LOGGER.info("size" + fofoIds.size());
|
| - |
|
761 |
double totalHygieneRating = currentMonthRatingAllPartners / fofoIds.size();
|
| - |
|
762 |
|
| - |
|
763 |
LOGGER.info("totalHygieneRating" + totalHygieneRating);
|
| - |
|
764 |
|
| - |
|
765 |
PartnerDetailModel pm = new PartnerDetailModel();
|
| - |
|
766 |
pm.setLmtd(totallmtdAmount);
|
| - |
|
767 |
pm.setMtd(totalmtdAmount);
|
| - |
|
768 |
pm.setLeads(authIdAndleadsCountMap.get(po.getAuthUserId()));
|
| - |
|
769 |
pm.setInvestment(totalTodayInvestment);
|
| - |
|
770 |
pm.setStockInInvestment(totalStockInInvestment);
|
| - |
|
771 |
pm.setTicket(totalTicketCount);
|
| - |
|
772 |
pm.setHygiene((double) Math.round(totalHygieneRating));
|
| - |
|
773 |
authIdAndallValues.put(auth.getId(), pm);
|
| - |
|
774 |
|
| - |
|
775 |
}
|
| - |
|
776 |
return authIdAndallValues;
|
| - |
|
777 |
}
|
| - |
|
778 |
|
| - |
|
779 |
private Map<String, Object> getInvestments(int fofoId) throws Exception {
|
| - |
|
780 |
Map<String, Object> investments = new LinkedHashMap<>();
|
| - |
|
781 |
|
| - |
|
782 |
PartnerDailyInvestment investment = partnerInvestmentService.getInvestment(fofoId, 0);
|
| - |
|
783 |
LocalDate currentMonthStart = LocalDate.now().withDayOfMonth(1);
|
| - |
|
784 |
LocalDate yesterDate = LocalDate.now().minusDays(1);
|
| - |
|
785 |
PartnerDailyInvestment yesterdayInvestment = partnerDailyInvestmentRepository.select(fofoId, yesterDate);
|
| - |
|
786 |
if (yesterdayInvestment == null) {
|
| - |
|
787 |
yesterdayInvestment = new PartnerDailyInvestment();
|
| - |
|
788 |
}
|
| - |
|
789 |
|
| - |
|
790 |
List<PartnerDailyInvestment> currentMonthInvestments = partnerDailyInvestmentRepository.selectAll(fofoId,
|
| - |
|
791 |
currentMonthStart, currentMonthStart.withDayOfMonth(currentMonthStart.lengthOfMonth()));
|
| - |
|
792 |
|
| - |
|
793 |
long okInvestmentDays = currentMonthInvestments.stream().filter(x -> x.getShortPercentage() <= 10)
|
| - |
|
794 |
.collect(Collectors.counting());
|
| - |
|
795 |
investments.put("today", investment.getTotalInvestment());
|
| - |
|
796 |
investments.put("investment", investment);
|
| - |
|
797 |
investments.put("inStock", investment.getInStockAmount());
|
| - |
|
798 |
investments.put("minimum", investment.getMinInvestmentString());
|
| - |
|
799 |
investments.put("short", investment.getShortPercentage());
|
| - |
|
800 |
investments.put("activated_stock", investment.getActivatedStockAmount());
|
| - |
|
801 |
investments.put("okDays", okInvestmentDays);
|
| - |
|
802 |
|
| - |
|
803 |
return investments;
|
| - |
|
804 |
}
|
| 656 |
}
|
805 |
}
|