| 26460 |
amit.gupta |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDate;
|
|
|
4 |
import java.time.LocalDateTime;
|
|
|
5 |
import java.time.LocalTime;
|
|
|
6 |
import java.util.ArrayList;
|
|
|
7 |
import java.util.HashMap;
|
|
|
8 |
import java.util.List;
|
|
|
9 |
import java.util.Map;
|
|
|
10 |
import java.util.stream.Collectors;
|
|
|
11 |
|
|
|
12 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 26461 |
amit.gupta |
13 |
import org.springframework.cache.annotation.Cacheable;
|
|
|
14 |
import org.springframework.stereotype.Component;
|
| 26460 |
amit.gupta |
15 |
import org.springframework.stereotype.Service;
|
|
|
16 |
|
|
|
17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
18 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
|
|
19 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
|
|
21 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
|
|
22 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
|
|
24 |
import com.spice.profitmandi.service.user.RetailerService;
|
|
|
25 |
|
| 26461 |
amit.gupta |
26 |
@Component
|
| 26460 |
amit.gupta |
27 |
public class PartnerStatsServiceImpl implements PartnerStatsService {
|
|
|
28 |
|
|
|
29 |
@Autowired
|
|
|
30 |
RetailerService retailerService;
|
|
|
31 |
|
|
|
32 |
@Autowired
|
|
|
33 |
FofoOrderItemRepository fofoOrderItemRepository;
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
CsService csService;
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
TicketRepository ticketRepository;
|
|
|
40 |
|
|
|
41 |
@Autowired
|
|
|
42 |
PartnerInvestmentService partnerInvestmentService;
|
|
|
43 |
|
|
|
44 |
@Autowired
|
|
|
45 |
HygieneDataRepository hygieneDataRepository;
|
|
|
46 |
|
|
|
47 |
@Override
|
| 26461 |
amit.gupta |
48 |
@Cacheable(value = "partnerStats", cacheManager = "oneDayCacheManager")
|
| 26460 |
amit.gupta |
49 |
public Map<Integer, PartnerDetailModel> getAllPartnerStats() throws ProfitMandiBusinessException {
|
|
|
50 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
51 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(
|
|
|
52 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
|
|
53 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumAmountGroupByRetailer(curDate.withDayOfMonth(1),
|
|
|
54 |
curDate.with(LocalTime.MAX), 0, false);
|
|
|
55 |
|
|
|
56 |
Map<Integer, List<Integer>> pp = csService.getAuthUserIdPartnerIdMapping();
|
|
|
57 |
Map<Integer, Long> ticketMap = ticketRepository.selectAllOpenTicketsGroupByRetailer();
|
|
|
58 |
|
|
|
59 |
Map<Integer, String> fofoRetailerMap = retailerService.getAllFofoRetailerIdNameMap();
|
|
|
60 |
Map<Integer, PartnerDetailModel> allPartnerStats = new HashMap<>();
|
|
|
61 |
|
|
|
62 |
Map<Integer, PartnerDailyInvestment> investmentMap = partnerInvestmentService
|
|
|
63 |
.getInvestment(new ArrayList<>(fofoRetailerMap.keySet()), 0).stream()
|
|
|
64 |
.collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
|
|
65 |
|
|
|
66 |
for (int fofoId : fofoRetailerMap.keySet()) {
|
|
|
67 |
int hygieneCount = (int) hygieneDataRepository.selectHygieneCount(fofoId, true,
|
|
|
68 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
|
|
69 |
int invalidHygieneCount = (int) hygieneDataRepository.selectHygieneCount(fofoId, true,
|
|
|
70 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
|
|
71 |
int totalHygieneCount = hygieneCount + invalidHygieneCount;
|
|
|
72 |
|
|
|
73 |
PartnerDetailModel pm = new PartnerDetailModel();
|
|
|
74 |
pm.setLmtd(lmtdSale.get(fofoId) == null ? 0 : lmtdSale.get(fofoId));
|
|
|
75 |
pm.setMtd(mtdSale.get(fofoId) == null ? 0 : mtdSale.get(fofoId));
|
|
|
76 |
|
|
|
77 |
pm.setInvestment(investmentMap.get(fofoId));
|
|
|
78 |
pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
|
|
|
79 |
pm.setHygiene(hygieneCount);
|
|
|
80 |
pm.setTotalHygiene(totalHygieneCount);
|
|
|
81 |
|
|
|
82 |
pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
|
|
|
83 |
allPartnerStats.put(fofoId, pm);
|
|
|
84 |
|
|
|
85 |
}
|
|
|
86 |
return allPartnerStats;
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
@Override
|
| 26461 |
amit.gupta |
90 |
@Cacheable(value = "partnerAggregateStats", cacheManager = "oneDayCacheManager")
|
| 26460 |
amit.gupta |
91 |
public PartnerDetailModel getAggregateStats(List<PartnerDetailModel> partnerDetailModels) throws ProfitMandiBusinessException {
|
|
|
92 |
PartnerDetailModel pdm = new PartnerDetailModel();
|
|
|
93 |
PartnerDailyInvestment aggregateInvestment = new PartnerDailyInvestment();
|
|
|
94 |
pdm.setInvestment(aggregateInvestment);
|
|
|
95 |
double totallmtdAmount = 0;
|
|
|
96 |
double totalmtdAmount = 0;
|
|
|
97 |
int totalTicketCount = 0;
|
|
|
98 |
|
|
|
99 |
int currentHygieneCount = 0;
|
|
|
100 |
int currentTotalHygieneCount = 0;
|
|
|
101 |
for (PartnerDetailModel partnerDetailModel : partnerDetailModels) {
|
|
|
102 |
PartnerDailyInvestment pdi = partnerDetailModel.getInvestment();
|
|
|
103 |
totallmtdAmount += partnerDetailModel.getLmtd();
|
|
|
104 |
totalmtdAmount += partnerDetailModel.getMtd();
|
|
|
105 |
totalTicketCount += partnerDetailModel.getTicket();
|
|
|
106 |
currentHygieneCount += partnerDetailModel.getHygiene();
|
|
|
107 |
currentTotalHygieneCount += partnerDetailModel.getTotalHygiene();
|
|
|
108 |
aggregateInvestment.setActivatedStockAmount(aggregateInvestment.getActivatedStockAmount() + pdi.getActivatedStockAmount());
|
|
|
109 |
aggregateInvestment.setGrnPendingAmount(aggregateInvestment.getGrnPendingAmount() + pdi.getGrnPendingAmount());
|
|
|
110 |
aggregateInvestment.setInStockAmount(aggregateInvestment.getInStockAmount() + pdi.getInStockAmount());
|
|
|
111 |
aggregateInvestment.setReturnInTransitAmount(aggregateInvestment.getReturnInTransitAmount() + pdi.getReturnInTransitAmount());
|
|
|
112 |
aggregateInvestment.setSalesAmount(aggregateInvestment.getSalesAmount() + pdi.getSalesAmount());
|
|
|
113 |
aggregateInvestment.setUnbilledAmount(aggregateInvestment.getUnbilledAmount() + pdi.getUnbilledAmount());
|
|
|
114 |
aggregateInvestment.setWalletAmount(aggregateInvestment.getWalletAmount() + pdi.getWalletAmount());
|
|
|
115 |
}
|
|
|
116 |
pdm.setHygiene(currentHygieneCount);
|
|
|
117 |
pdm.setTotalHygiene(currentTotalHygieneCount);
|
|
|
118 |
pdm.setLmtd(totallmtdAmount);
|
|
|
119 |
pdm.setMtd(totalmtdAmount);
|
|
|
120 |
pdm.setTicket(totalTicketCount);
|
|
|
121 |
return pdm;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
}
|