| Line 4... |
Line 4... |
| 4 |
import java.time.LocalDateTime;
|
4 |
import java.time.LocalDateTime;
|
| 5 |
import java.time.LocalTime;
|
5 |
import java.time.LocalTime;
|
| 6 |
import java.util.HashMap;
|
6 |
import java.util.HashMap;
|
| 7 |
import java.util.List;
|
7 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
8 |
import java.util.Map;
|
| - |
|
9 |
import java.util.Set;
|
| 9 |
import java.util.stream.Collectors;
|
10 |
import java.util.stream.Collectors;
|
| 10 |
|
11 |
|
| 11 |
import org.apache.logging.log4j.LogManager;
|
12 |
import org.apache.logging.log4j.LogManager;
|
| 12 |
import org.apache.logging.log4j.Logger;
|
13 |
import org.apache.logging.log4j.Logger;
|
| 13 |
import org.springframework.beans.factory.annotation.Autowired;
|
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| Line 15... |
Line 16... |
| 15 |
import org.springframework.stereotype.Component;
|
16 |
import org.springframework.stereotype.Component;
|
| 16 |
|
17 |
|
| 17 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
18 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 18 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
19 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 19 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
20 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| - |
|
21 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
| 20 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
22 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
| 21 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
23 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 22 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
24 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
| 23 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
25 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 24 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
26 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderItemRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
27 |
import com.spice.profitmandi.dao.repository.fofo.HygieneDataRepository;
|
| - |
|
28 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 26 |
import com.spice.profitmandi.service.user.RetailerService;
|
29 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 27 |
|
30 |
|
| 28 |
@Component
|
31 |
@Component
|
| 29 |
public class PartnerStatsServiceImpl implements PartnerStatsService {
|
32 |
public class PartnerStatsServiceImpl implements PartnerStatsService {
|
| 30 |
|
33 |
|
| 31 |
private static final Logger LOGGER = LogManager.getLogger(PartnerStatsServiceImpl.class);
|
34 |
private static final Logger LOGGER = LogManager.getLogger(PartnerStatsServiceImpl.class);
|
| 32 |
|
35 |
|
| 33 |
@Autowired
|
36 |
@Autowired
|
| 34 |
RetailerService retailerService;
|
37 |
RetailerService retailerService;
|
| 35 |
|
38 |
|
| 36 |
@Autowired
|
39 |
@Autowired
|
| 37 |
FofoStoreRepository fofoStoreRepository;
|
40 |
FofoStoreRepository fofoStoreRepository;
|
| Line 49... |
Line 52... |
| 49 |
PartnerInvestmentService partnerInvestmentService;
|
52 |
PartnerInvestmentService partnerInvestmentService;
|
| 50 |
|
53 |
|
| 51 |
@Autowired
|
54 |
@Autowired
|
| 52 |
HygieneDataRepository hygieneDataRepository;
|
55 |
HygieneDataRepository hygieneDataRepository;
|
| 53 |
|
56 |
|
| - |
|
57 |
@Autowired
|
| - |
|
58 |
UserWalletRepository userWalletRepository;
|
| - |
|
59 |
|
| 54 |
@Override
|
60 |
@Override
|
| 55 |
@Cacheable(value = "partnerStats", cacheManager = "thirtyMinsTimeOutCacheManager")
|
61 |
@Cacheable(value = "partnerStats", cacheManager = "thirtyMinsTimeOutCacheManager")
|
| 56 |
public Map<Integer, PartnerDetailModel> getAllPartnerStats() throws ProfitMandiBusinessException {
|
62 |
public Map<Integer, PartnerDetailModel> getAllPartnerStats() throws ProfitMandiBusinessException {
|
| 57 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
63 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 58 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
64 |
Map<Integer, Double> lmtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(
|
| 59 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
65 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.with(LocalTime.MAX).minusMonths(1), 0, false);
|
| 60 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1),
|
66 |
Map<Integer, Double> mtdSale = fofoOrderItemRepository.selectSumMopGroupByRetailer(curDate.withDayOfMonth(1),
|
| 61 |
curDate.with(LocalTime.MAX), 0, false);
|
67 |
curDate.with(LocalTime.MAX), 0, false);
|
| 62 |
|
68 |
|
| - |
|
69 |
Map<Integer, Long> last1daystertiary = fofoOrderItemRepository.selectQtyGroupByRetailer(curDate,
|
| - |
|
70 |
curDate.with(LocalTime.MAX), 0, false);
|
| - |
|
71 |
|
| - |
|
72 |
Map<Integer, Long> last3daystertiary = fofoOrderItemRepository.selectQtyGroupByRetailer(curDate.minusDays(4),
|
| - |
|
73 |
curDate.minusDays(1).with(LocalTime.MAX), 0, false);
|
| - |
|
74 |
|
| 63 |
Map<Integer, Long> ticketMap = ticketRepository.selectAllOpenTicketsGroupByRetailer();
|
75 |
Map<Integer, Long> ticketMap = ticketRepository.selectAllOpenTicketsGroupByRetailer();
|
| 64 |
|
76 |
|
| 65 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
77 |
List<FofoStore> fofoStores = fofoStoreRepository.selectActiveStores();
|
| - |
|
78 |
Set<Integer> fofoIds = fofoStores.stream().map(x -> x.getId()).collect(Collectors.toSet());
|
| - |
|
79 |
Map<Integer, UserWallet> userWallet = userWalletRepository.selectByRetailerIds(fofoIds).stream()
|
| - |
|
80 |
.collect(Collectors.toMap(x -> x.getUserId(), x -> x));
|
| - |
|
81 |
|
| 66 |
Map<Integer, PartnerDetailModel> allPartnerStats = new HashMap<>();
|
82 |
Map<Integer, PartnerDetailModel> allPartnerStats = new HashMap<>();
|
| 67 |
|
83 |
|
| 68 |
Map<Integer, PartnerDailyInvestment> investmentMap = fofoStores.stream()
|
84 |
Map<Integer, PartnerDailyInvestment> investmentMap = fofoStores.stream().map(x -> {
|
| 69 |
.map(x-> {
|
- |
|
| 70 |
PartnerDailyInvestment pdi = new PartnerDailyInvestment();
|
- |
|
| 71 |
pdi.setFofoId(x.getId());
|
- |
|
| 72 |
return pdi;
|
- |
|
| 73 |
})
|
- |
|
| 74 |
/*.map(x->{
|
- |
|
| 75 |
try {
|
85 |
try {
|
| 76 |
return partnerInvestmentService.getInvestment(x,0);
|
86 |
return partnerInvestmentService.getInvestment(x.getId(), 0);
|
| 77 |
}catch(Exception e) {
|
87 |
} catch (Exception e) {
|
| 78 |
LOGGER.info("Could not get invetment summary for {}", x);
|
88 |
LOGGER.info("Could not get invetment summary for {}", x);
|
| 79 |
return new PartnerDailyInvestment();
|
89 |
return new PartnerDailyInvestment();
|
| 80 |
}
|
90 |
}
|
| 81 |
})*/
|
- |
|
| 82 |
.collect(Collectors.toMap(x->x.getFofoId(), x->x));
|
91 |
}).collect(Collectors.toMap(x -> x.getFofoId(), x -> x));
|
| 83 |
|
92 |
|
| 84 |
for (FofoStore store: fofoStores) {
|
93 |
for (FofoStore store : fofoStores) {
|
| 85 |
int fofoId = store.getId();
|
94 |
int fofoId = store.getId();
|
| 86 |
int hygieneCount = (int) hygieneDataRepository.selectHygieneCount(fofoId, true,
|
95 |
int hygieneCount = (int) hygieneDataRepository.selectHygieneCount(fofoId, true,
|
| 87 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
96 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
| 88 |
int invalidHygieneCount = (int) hygieneDataRepository.selectHygieneCount(fofoId, true,
|
97 |
int invalidHygieneCount = (int) hygieneDataRepository.selectHygieneCount(fofoId, true,
|
| 89 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
98 |
curDate.withDayOfMonth(1).minusMonths(1), curDate.plusMonths(1).withDayOfMonth(1));
|
| 90 |
int totalHygieneCount = hygieneCount + invalidHygieneCount;
|
99 |
int totalHygieneCount = hygieneCount + invalidHygieneCount;
|
| 91 |
|
- |
|
| 92 |
PartnerDetailModel pm = new PartnerDetailModel();
|
100 |
PartnerDetailModel pm = new PartnerDetailModel();
|
| 93 |
pm.setLmtd(lmtdSale.get(fofoId) == null ? 0 : lmtdSale.get(fofoId));
|
101 |
pm.setLmtd(lmtdSale.get(fofoId) == null ? 0 : lmtdSale.get(fofoId));
|
| 94 |
pm.setMtd(mtdSale.get(fofoId) == null ? 0 : mtdSale.get(fofoId));
|
102 |
pm.setMtd(mtdSale.get(fofoId) == null ? 0 : mtdSale.get(fofoId));
|
| 95 |
|
- |
|
| - |
|
103 |
pm.setLastOneDayTertiary(last1daystertiary.get(fofoId) == null ? 0 : last1daystertiary.get(fofoId));
|
| - |
|
104 |
pm.setLastThreeDaytertiary(last3daystertiary.get(fofoId) == null ? 0 : last3daystertiary.get(fofoId));
|
| - |
|
105 |
pm.setWalletAmount(userWallet.get(fofoId).getAmount() == 0 ? 0 : userWallet.get(fofoId).getAmount());
|
| 96 |
pm.setInvestment(investmentMap.get(fofoId));
|
106 |
pm.setInvestment(investmentMap.get(fofoId));
|
| 97 |
pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
|
107 |
pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
|
| 98 |
pm.setHygiene(hygieneCount);
|
108 |
pm.setHygiene(hygieneCount);
|
| - |
|
109 |
|
| - |
|
110 |
pm.setAuthUser(csService.getAuthUserByPartnerId(fofoId).get(0) == null ? "not available"
|
| - |
|
111 |
: csService.getAuthUserByPartnerId(fofoId).get(0));
|
| 99 |
pm.setTotalHygiene(totalHygieneCount);
|
112 |
pm.setTotalHygiene(totalHygieneCount);
|
| 100 |
|
113 |
|
| 101 |
pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
|
114 |
pm.setTicket(ticketMap.get(fofoId) == null ? 0 : ticketMap.get(fofoId).intValue());
|
| 102 |
allPartnerStats.put(fofoId, pm);
|
115 |
allPartnerStats.put(fofoId, pm);
|
| 103 |
LOGGER.info("pm {}", pm);
|
116 |
LOGGER.info("pm {}", pm);
|
| 104 |
|
117 |
|
| 105 |
}
|
118 |
}
|
| 106 |
return allPartnerStats;
|
119 |
return allPartnerStats;
|
| 107 |
}
|
120 |
}
|
| 108 |
|
121 |
|
| 109 |
@Override
|
122 |
@Override
|
| 110 |
//@Cacheable(value = "partnerAggregateStats", cacheManager = "oneDayCacheManager")
|
123 |
// @Cacheable(value = "partnerAggregateStats", cacheManager =
|
| - |
|
124 |
// "oneDayCacheManager")
|
| 111 |
public PartnerDetailModel getAggregateStats(List<PartnerDetailModel> partnerDetailModels) throws ProfitMandiBusinessException {
|
125 |
public PartnerDetailModel getAggregateStats(List<PartnerDetailModel> partnerDetailModels)
|
| - |
|
126 |
throws ProfitMandiBusinessException {
|
| 112 |
PartnerDetailModel pdm = new PartnerDetailModel();
|
127 |
PartnerDetailModel pdm = new PartnerDetailModel();
|
| 113 |
PartnerDailyInvestment aggregateInvestment = new PartnerDailyInvestment();
|
128 |
PartnerDailyInvestment aggregateInvestment = new PartnerDailyInvestment();
|
| 114 |
pdm.setInvestment(aggregateInvestment);
|
129 |
pdm.setInvestment(aggregateInvestment);
|
| 115 |
double totallmtdAmount = 0;
|
130 |
double totallmtdAmount = 0;
|
| 116 |
double totalmtdAmount = 0;
|
131 |
double totalmtdAmount = 0;
|
| 117 |
int totalTicketCount = 0;
|
132 |
int totalTicketCount = 0;
|
| 118 |
|
133 |
|
| Line 123... |
Line 138... |
| 123 |
totallmtdAmount += partnerDetailModel.getLmtd();
|
138 |
totallmtdAmount += partnerDetailModel.getLmtd();
|
| 124 |
totalmtdAmount += partnerDetailModel.getMtd();
|
139 |
totalmtdAmount += partnerDetailModel.getMtd();
|
| 125 |
totalTicketCount += partnerDetailModel.getTicket();
|
140 |
totalTicketCount += partnerDetailModel.getTicket();
|
| 126 |
currentHygieneCount += partnerDetailModel.getHygiene();
|
141 |
currentHygieneCount += partnerDetailModel.getHygiene();
|
| 127 |
currentTotalHygieneCount += partnerDetailModel.getTotalHygiene();
|
142 |
currentTotalHygieneCount += partnerDetailModel.getTotalHygiene();
|
| - |
|
143 |
aggregateInvestment.setActivatedStockAmount(
|
| 128 |
aggregateInvestment.setActivatedStockAmount(aggregateInvestment.getActivatedStockAmount() + pdi.getActivatedStockAmount());
|
144 |
aggregateInvestment.getActivatedStockAmount() + pdi.getActivatedStockAmount());
|
| - |
|
145 |
aggregateInvestment
|
| 129 |
aggregateInvestment.setGrnPendingAmount(aggregateInvestment.getGrnPendingAmount() + pdi.getGrnPendingAmount());
|
146 |
.setGrnPendingAmount(aggregateInvestment.getGrnPendingAmount() + pdi.getGrnPendingAmount());
|
| 130 |
aggregateInvestment.setInStockAmount(aggregateInvestment.getInStockAmount() + pdi.getInStockAmount());
|
147 |
aggregateInvestment.setInStockAmount(aggregateInvestment.getInStockAmount() + pdi.getInStockAmount());
|
| - |
|
148 |
aggregateInvestment.setReturnInTransitAmount(
|
| 131 |
aggregateInvestment.setReturnInTransitAmount(aggregateInvestment.getReturnInTransitAmount() + pdi.getReturnInTransitAmount());
|
149 |
aggregateInvestment.getReturnInTransitAmount() + pdi.getReturnInTransitAmount());
|
| 132 |
aggregateInvestment.setSalesAmount(aggregateInvestment.getSalesAmount() + pdi.getSalesAmount());
|
150 |
aggregateInvestment.setSalesAmount(aggregateInvestment.getSalesAmount() + pdi.getSalesAmount());
|
| 133 |
aggregateInvestment.setUnbilledAmount(aggregateInvestment.getUnbilledAmount() + pdi.getUnbilledAmount());
|
151 |
aggregateInvestment.setUnbilledAmount(aggregateInvestment.getUnbilledAmount() + pdi.getUnbilledAmount());
|
| 134 |
aggregateInvestment.setWalletAmount(aggregateInvestment.getWalletAmount() + pdi.getWalletAmount());
|
152 |
aggregateInvestment.setWalletAmount(aggregateInvestment.getWalletAmount() + pdi.getWalletAmount());
|
| 135 |
}
|
153 |
}
|
| 136 |
pdm.setHygiene(currentHygieneCount);
|
154 |
pdm.setHygiene(currentHygieneCount);
|
| Line 139... |
Line 157... |
| 139 |
pdm.setMtd(totalmtdAmount);
|
157 |
pdm.setMtd(totalmtdAmount);
|
| 140 |
pdm.setTicket(totalTicketCount);
|
158 |
pdm.setTicket(totalTicketCount);
|
| 141 |
pdm.setCount(partnerDetailModels.size());
|
159 |
pdm.setCount(partnerDetailModels.size());
|
| 142 |
return pdm;
|
160 |
return pdm;
|
| 143 |
}
|
161 |
}
|
| 144 |
|
- |
|
| 145 |
|
162 |
|
| 146 |
}
|
163 |
}
|