| 28468 |
tejbeer |
1 |
package com.spice.profitmandi.service;
|
|
|
2 |
|
|
|
3 |
import com.google.gson.Gson;
|
|
|
4 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
|
|
5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 30449 |
amit.gupta |
6 |
import com.spice.profitmandi.common.model.*;
|
| 28468 |
tejbeer |
7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
|
|
8 |
import com.spice.profitmandi.dao.entity.auth.Menu;
|
|
|
9 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
|
|
10 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 29165 |
manish |
11 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 28468 |
tejbeer |
12 |
import com.spice.profitmandi.dao.entity.inventory.ReporticoCacheTable;
|
|
|
13 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
|
|
14 |
import com.spice.profitmandi.dao.model.BrandWiseModel;
|
|
|
15 |
import com.spice.profitmandi.dao.model.PartnerDetailModel;
|
|
|
16 |
import com.spice.profitmandi.dao.model.WarehouseWiseStockModel;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.auth.AuthRepository;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.auth.MenuCategoryRepository;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.auth.MenuRepository;
|
|
|
20 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 31662 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.repository.cs.CsService1;
|
| 28468 |
tejbeer |
22 |
import com.spice.profitmandi.dao.repository.cs.PositionRepository;
|
|
|
23 |
import com.spice.profitmandi.dao.repository.cs.TicketRepository;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 28825 |
tejbeer |
25 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
| 28468 |
tejbeer |
26 |
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
|
|
|
27 |
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
|
|
|
28 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
|
|
29 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 30449 |
amit.gupta |
30 |
import org.apache.logging.log4j.LogManager;
|
|
|
31 |
import org.apache.logging.log4j.Logger;
|
|
|
32 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
33 |
import org.springframework.stereotype.Component;
|
|
|
34 |
import org.springframework.ui.Model;
|
| 28468 |
tejbeer |
35 |
|
| 30449 |
amit.gupta |
36 |
import java.io.FileInputStream;
|
|
|
37 |
import java.io.ObjectInputStream;
|
|
|
38 |
import java.time.LocalDate;
|
|
|
39 |
import java.time.LocalDateTime;
|
|
|
40 |
import java.time.Period;
|
|
|
41 |
import java.time.YearMonth;
|
|
|
42 |
import java.time.format.DateTimeFormatter;
|
|
|
43 |
import java.time.temporal.ChronoUnit;
|
|
|
44 |
import java.util.*;
|
|
|
45 |
import java.util.Map.Entry;
|
|
|
46 |
import java.util.stream.Collectors;
|
|
|
47 |
import java.util.stream.LongStream;
|
|
|
48 |
|
| 28468 |
tejbeer |
49 |
@Component
|
|
|
50 |
public class AdminUser {
|
|
|
51 |
@Autowired
|
|
|
52 |
private Gson gson;
|
|
|
53 |
|
|
|
54 |
@Autowired
|
|
|
55 |
private OrderRepository orderRepository;
|
|
|
56 |
|
|
|
57 |
@Autowired
|
|
|
58 |
TicketRepository ticketRepository;
|
|
|
59 |
|
|
|
60 |
@Autowired
|
|
|
61 |
private ChartService chartService;
|
|
|
62 |
|
|
|
63 |
@Autowired
|
|
|
64 |
RetailerService retailerService;
|
|
|
65 |
|
|
|
66 |
@Autowired
|
|
|
67 |
AuthRepository authRepository;
|
|
|
68 |
|
|
|
69 |
@Autowired
|
|
|
70 |
FofoStoreRepository fofoStoreRepository;
|
|
|
71 |
|
|
|
72 |
@Autowired
|
| 31662 |
amit.gupta |
73 |
CsService1 csService1;
|
|
|
74 |
|
|
|
75 |
@Autowired
|
| 28468 |
tejbeer |
76 |
CsService csService;
|
|
|
77 |
|
|
|
78 |
@Autowired
|
|
|
79 |
private MenuRepository menuRepository;
|
|
|
80 |
|
|
|
81 |
@Autowired
|
|
|
82 |
private PositionRepository positionRepository;
|
|
|
83 |
|
|
|
84 |
@Autowired
|
|
|
85 |
private MenuCategoryRepository menuCategoryRepository;
|
|
|
86 |
|
|
|
87 |
@Autowired
|
|
|
88 |
private SaholicInventoryCISRepository saholicInventoryCISRepository;
|
|
|
89 |
|
|
|
90 |
@Autowired
|
|
|
91 |
private ReporticoCacheTableRepository reporticoCacheTableRepository;
|
|
|
92 |
|
|
|
93 |
@Autowired
|
| 28825 |
tejbeer |
94 |
private ActivatedImeiRepository activatedImeiRepository;
|
|
|
95 |
|
|
|
96 |
@Autowired
|
| 28468 |
tejbeer |
97 |
private PartnerStatsService partnerStatsService;
|
|
|
98 |
List<String> emails = Arrays.asList("kamini.sharma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
|
| 31130 |
tejbeer |
99 |
"tejbeer.kaur@smartdukaan.com", "amit.gupta@smartdukaan.com", "kanan.choudhary@smartdukaan.com");
|
| 28468 |
tejbeer |
100 |
|
| 31259 |
tejbeer |
101 |
List<String> colorList = Arrays.asList("mediumseagreen", "dodgerblue", "darkblue", "gold", "#eb0029", "coral",
|
|
|
102 |
"#63C5DA", "red", "deeppink", "midnightblue", "cornsilk");
|
| 28468 |
tejbeer |
103 |
|
| 31259 |
tejbeer |
104 |
List<String> borderList = Arrays.asList("lawngreen", "lightblue", "#0000cd", "#f7e98e", "#eb0029", "lightcoral",
|
|
|
105 |
"#0000cd", "lightsalmon", "pink", "#0000cd", "cornsilk");
|
| 28468 |
tejbeer |
106 |
|
| 31259 |
tejbeer |
107 |
List<String> brands = Arrays.asList("Oppo", "Vivo", "Samsung", "Realme", "OnePlus", "Xiaomi", "Tecno", "Itel",
|
|
|
108 |
"Lava", "Nokia");
|
| 28468 |
tejbeer |
109 |
|
|
|
110 |
private static final Logger LOGGER = LogManager.getLogger(AdminUser.class);
|
|
|
111 |
|
| 30279 |
tejbeer |
112 |
public ChartModel getBrandWiseLmp(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
| 31259 |
tejbeer |
113 |
LocalDate endDate, String filterType) {
|
| 30279 |
tejbeer |
114 |
LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
| 28468 |
tejbeer |
115 |
|
| 30279 |
tejbeer |
116 |
List<BrandWiseModel> brandWiseLms = orderRepository.selectGroupByBrandLmp(fofoIds, warehouseIds, startDate,
|
|
|
117 |
endDate, filterType);
|
| 28468 |
tejbeer |
118 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
| 30279 |
tejbeer |
119 |
ChartModel cm = null;
|
| 28468 |
tejbeer |
120 |
|
| 30279 |
tejbeer |
121 |
if (filterType.equals("dateWise")) {
|
|
|
122 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
| 28468 |
tejbeer |
123 |
|
| 30279 |
tejbeer |
124 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
|
|
125 |
for (BrandWiseModel bwl : brandWiseLms) {
|
|
|
126 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
|
|
127 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
|
|
128 |
}
|
|
|
129 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
|
|
130 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
| 28468 |
tejbeer |
131 |
}
|
|
|
132 |
|
| 30279 |
tejbeer |
133 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
|
|
134 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
|
|
135 |
.collect(Collectors.toList());
|
|
|
136 |
LOGGER.info("All dates between {}", allDatesBetween);
|
| 28468 |
tejbeer |
137 |
|
| 30279 |
tejbeer |
138 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 28468 |
tejbeer |
139 |
|
| 30279 |
tejbeer |
140 |
for (String brand : brands) {
|
|
|
141 |
if (!brandDateValue.containsKey(brand)) {
|
|
|
142 |
brandDateValue.put(brand, new HashMap<>());
|
|
|
143 |
}
|
|
|
144 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
|
|
145 |
for (LocalDate date : allDatesBetween) {
|
|
|
146 |
if (dateWiseBrand.get(date) == null) {
|
|
|
147 |
dateWiseBrand.put(date, 0.0);
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
|
|
152 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
|
|
153 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
| 30220 |
amit.gupta |
154 |
}
|
| 30279 |
tejbeer |
155 |
|
|
|
156 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
|
|
157 |
|
|
|
158 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
|
|
159 |
cm = chartService.createChartWithLabels(
|
|
|
160 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
|
|
161 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
|
|
162 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Purchase");
|
|
|
163 |
|
|
|
164 |
} else {
|
|
|
165 |
|
|
|
166 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
|
|
167 |
|
|
|
168 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
|
|
169 |
for (BrandWiseModel bwl : brandWiseLms) {
|
|
|
170 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
|
|
171 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
|
|
172 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
|
|
173 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
|
|
174 |
(double) bwl.getAmount());
|
|
|
175 |
} else {
|
|
|
176 |
|
|
|
177 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
|
|
178 |
(double) bwl.getAmount());
|
|
|
179 |
|
| 28468 |
tejbeer |
180 |
}
|
| 30279 |
tejbeer |
181 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
|
|
182 |
|
| 28468 |
tejbeer |
183 |
}
|
| 30279 |
tejbeer |
184 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 28468 |
tejbeer |
185 |
|
| 30279 |
tejbeer |
186 |
Period age = Period.between(startDate, endDate);
|
|
|
187 |
int months = age.getMonths();
|
|
|
188 |
LOGGER.info("months" + months);
|
|
|
189 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
|
|
190 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
| 28468 |
tejbeer |
191 |
|
| 30279 |
tejbeer |
192 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 28468 |
tejbeer |
193 |
|
| 30279 |
tejbeer |
194 |
for (String brand : brands) {
|
|
|
195 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
|
|
196 |
for (int i = months; i >= 0; i--) {
|
| 28468 |
tejbeer |
197 |
|
| 30279 |
tejbeer |
198 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
| 28468 |
tejbeer |
199 |
|
| 30279 |
tejbeer |
200 |
if (yearMonthValue != null) {
|
|
|
201 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
|
|
202 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
|
|
203 |
}
|
|
|
204 |
|
|
|
205 |
} else {
|
|
|
206 |
yearMonthValue = new HashMap<>();
|
|
|
207 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
|
|
208 |
}
|
|
|
209 |
}
|
|
|
210 |
|
|
|
211 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
|
|
212 |
|
|
|
213 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
|
|
214 |
|
|
|
215 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
|
|
216 |
|
|
|
217 |
}
|
|
|
218 |
|
|
|
219 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList,
|
|
|
220 |
"Brand Wise Monthly Purchase");
|
|
|
221 |
|
|
|
222 |
}
|
|
|
223 |
|
| 28468 |
tejbeer |
224 |
return cm;
|
|
|
225 |
}
|
|
|
226 |
|
| 29165 |
manish |
227 |
public ChartInvestmentModel getAllStatePartnerType(Map<Integer, PartnerDetailModel> fofoIdAndallValues)
|
|
|
228 |
throws ProfitMandiBusinessException {
|
|
|
229 |
|
|
|
230 |
Map<String, Float> partnerTypeCount = new HashMap<>();
|
|
|
231 |
|
|
|
232 |
List<PartnerType> partnerTypes = Arrays.asList(PartnerType.values());
|
|
|
233 |
|
|
|
234 |
for (PartnerType partnerType : partnerTypes) {
|
|
|
235 |
|
|
|
236 |
float count = fofoIdAndallValues.entrySet().stream()
|
|
|
237 |
.filter(x -> x.getValue().getPartnerType().equals(partnerType)).count();
|
|
|
238 |
|
|
|
239 |
partnerTypeCount.put(partnerType.toString(), count);
|
|
|
240 |
|
|
|
241 |
}
|
|
|
242 |
|
|
|
243 |
ChartInvestmentModel cm = new ChartInvestmentModel();
|
|
|
244 |
|
|
|
245 |
HashSet<String> labels = new HashSet<String>();
|
|
|
246 |
labels.addAll(partnerTypes.stream().skip(1).map(x -> x.toString()).collect(Collectors.toList()));
|
|
|
247 |
List<String> labelList = new ArrayList<>(labels);
|
|
|
248 |
|
|
|
249 |
List<String> backgroundColor = new ArrayList<>();
|
|
|
250 |
|
|
|
251 |
List<Float> values = new ArrayList<>();
|
|
|
252 |
|
|
|
253 |
for (String label : labelList) {
|
|
|
254 |
values.add(partnerTypeCount.get(label));
|
|
|
255 |
if (label.equals("BRONZE")) {
|
| 29168 |
manish |
256 |
backgroundColor.add("#CD7F32");
|
| 29165 |
manish |
257 |
}
|
|
|
258 |
if (label.equals("SILVER")) {
|
|
|
259 |
backgroundColor.add("silver");
|
|
|
260 |
}
|
|
|
261 |
if (label.equals("GOLD")) {
|
| 29168 |
manish |
262 |
backgroundColor.add("#FFD700");
|
| 29165 |
manish |
263 |
}
|
|
|
264 |
if (label.equals("DIAMOND")) {
|
|
|
265 |
backgroundColor.add("#B9F2FF");
|
|
|
266 |
}
|
|
|
267 |
|
|
|
268 |
if (label.equals("PLATINUM")) {
|
| 29198 |
manish |
269 |
backgroundColor.add("#800080");
|
| 29165 |
manish |
270 |
}
|
|
|
271 |
if (label.equals("NEW")) {
|
|
|
272 |
backgroundColor.add("green");
|
|
|
273 |
}
|
|
|
274 |
|
|
|
275 |
}
|
|
|
276 |
|
|
|
277 |
LOGGER.info("valuesPartnerType" + values);
|
|
|
278 |
LOGGER.info("partnerTypeCount" + partnerTypeCount);
|
|
|
279 |
|
|
|
280 |
Data data = new Data();
|
|
|
281 |
data.setData(values);
|
|
|
282 |
data.setBackgroundColor(backgroundColor);
|
|
|
283 |
data.setLabel("DataSet 1");
|
|
|
284 |
|
|
|
285 |
PieLables label = new PieLables();
|
|
|
286 |
label.setFontColor("black");
|
|
|
287 |
label.setFontSize(22);
|
|
|
288 |
|
|
|
289 |
Legend legend = new Legend();
|
|
|
290 |
legend.setLabels(label);
|
|
|
291 |
legend.setPosition("left");
|
|
|
292 |
|
|
|
293 |
List<Data> dataList = new ArrayList<>();
|
|
|
294 |
dataList.add(data);
|
|
|
295 |
|
|
|
296 |
DataInvestmentModel datasets = new DataInvestmentModel();
|
|
|
297 |
datasets.setDatasets(dataList);
|
|
|
298 |
datasets.setLabels(labels);
|
|
|
299 |
|
|
|
300 |
OptionModel om = new OptionModel();
|
|
|
301 |
om.setLegend(legend);
|
|
|
302 |
cm.setType("pie");
|
|
|
303 |
cm.setData(datasets);
|
|
|
304 |
cm.setOptions(om);
|
|
|
305 |
|
|
|
306 |
return cm;
|
|
|
307 |
}
|
|
|
308 |
|
| 30279 |
tejbeer |
309 |
public Map<String, Object> getFilter(int warehouseId, String email, LocalDateTime date, LocalDateTime endDate)
|
| 28468 |
tejbeer |
310 |
throws ProfitMandiBusinessException {
|
|
|
311 |
Map<String, Object> map = new HashMap<>();
|
| 30426 |
tejbeer |
312 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
|
|
313 |
Map<Integer, CustomRetailer> crm = null;
|
| 28468 |
tejbeer |
314 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
|
|
315 |
|
| 31662 |
amit.gupta |
316 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
|
| 28468 |
tejbeer |
317 |
|
|
|
318 |
if (warehouseId != 0) {
|
|
|
319 |
|
|
|
320 |
fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
|
|
|
321 |
.stream().map(x -> x).collect(Collectors.toSet());
|
|
|
322 |
|
|
|
323 |
}
|
|
|
324 |
|
|
|
325 |
if (fofoIds != null) {
|
|
|
326 |
|
| 30426 |
tejbeer |
327 |
crm = fofoIds.stream().map(x -> customRetailerMap.get(x)).filter(x -> x != null)
|
|
|
328 |
.collect(Collectors.toList()).stream().collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
|
|
329 |
|
| 28468 |
tejbeer |
330 |
}
|
|
|
331 |
|
|
|
332 |
map.put("date", date);
|
| 30279 |
tejbeer |
333 |
map.put("endDate", endDate);
|
| 30426 |
tejbeer |
334 |
map.put("customRetailersMap", crm);
|
| 28468 |
tejbeer |
335 |
map.put("fofoIds", fofoIds);
|
|
|
336 |
map.put("warehouseMap", warehouseMap);
|
|
|
337 |
|
|
|
338 |
return map;
|
|
|
339 |
|
|
|
340 |
}
|
|
|
341 |
|
| 30279 |
tejbeer |
342 |
public ChartModel getBrandWiseLms(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
|
|
343 |
LocalDate endDate, String filterType) {
|
|
|
344 |
LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
| 28468 |
tejbeer |
345 |
|
| 30279 |
tejbeer |
346 |
List<BrandWiseModel> brandWiseLms = fofoStoreRepository.selectGroupByBrandLms(fofoIds, warehouseIds, startDate,
|
|
|
347 |
endDate, filterType);
|
| 28468 |
tejbeer |
348 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
|
|
349 |
|
| 30279 |
tejbeer |
350 |
ChartModel cm = null;
|
| 28468 |
tejbeer |
351 |
|
| 30279 |
tejbeer |
352 |
if (filterType.equals("dateWise")) {
|
|
|
353 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
| 28468 |
tejbeer |
354 |
|
| 30279 |
tejbeer |
355 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
|
|
356 |
for (BrandWiseModel bwl : brandWiseLms) {
|
|
|
357 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
|
|
358 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
|
|
359 |
}
|
|
|
360 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
|
|
361 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
|
|
362 |
}
|
| 28468 |
tejbeer |
363 |
|
| 30279 |
tejbeer |
364 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
|
|
365 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
|
|
366 |
.collect(Collectors.toList());
|
|
|
367 |
LOGGER.info("All dates between {}", allDatesBetween);
|
|
|
368 |
|
|
|
369 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
|
|
370 |
|
|
|
371 |
for (String brand : brands) {
|
|
|
372 |
if (!brandDateValue.containsKey(brand)) {
|
|
|
373 |
brandDateValue.put(brand, new HashMap<>());
|
|
|
374 |
}
|
|
|
375 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
|
|
376 |
for (LocalDate date : allDatesBetween) {
|
|
|
377 |
if (dateWiseBrand.get(date) == null) {
|
|
|
378 |
dateWiseBrand.put(date, 0.0);
|
|
|
379 |
}
|
|
|
380 |
}
|
|
|
381 |
|
|
|
382 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
|
|
383 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
|
|
384 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
| 28468 |
tejbeer |
385 |
}
|
|
|
386 |
|
| 30279 |
tejbeer |
387 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
| 28468 |
tejbeer |
388 |
|
| 30279 |
tejbeer |
389 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
|
|
390 |
cm = chartService.createChartWithLabels(
|
|
|
391 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
|
|
392 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
|
|
393 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Sale");
|
| 28468 |
tejbeer |
394 |
|
| 30279 |
tejbeer |
395 |
} else {
|
| 28468 |
tejbeer |
396 |
|
| 30279 |
tejbeer |
397 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
| 28468 |
tejbeer |
398 |
|
| 30279 |
tejbeer |
399 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
|
|
400 |
for (BrandWiseModel bwl : brandWiseLms) {
|
|
|
401 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
|
|
402 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
|
|
403 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
|
|
404 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
|
|
405 |
(double) bwl.getAmount());
|
|
|
406 |
} else {
|
| 28468 |
tejbeer |
407 |
|
| 30279 |
tejbeer |
408 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
|
|
409 |
(double) bwl.getAmount());
|
| 28468 |
tejbeer |
410 |
|
|
|
411 |
}
|
| 30279 |
tejbeer |
412 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
|
|
413 |
|
| 28468 |
tejbeer |
414 |
}
|
| 30279 |
tejbeer |
415 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 28468 |
tejbeer |
416 |
|
| 30279 |
tejbeer |
417 |
Period age = Period.between(startDate, endDate);
|
|
|
418 |
int months = age.getMonths();
|
|
|
419 |
LOGGER.info("months" + months);
|
|
|
420 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
|
|
421 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
| 28468 |
tejbeer |
422 |
|
| 30279 |
tejbeer |
423 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 28468 |
tejbeer |
424 |
|
| 30279 |
tejbeer |
425 |
for (String brand : brands) {
|
|
|
426 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
|
|
427 |
for (int i = months; i >= 0; i--) {
|
| 28468 |
tejbeer |
428 |
|
| 30279 |
tejbeer |
429 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
|
|
430 |
|
|
|
431 |
if (yearMonthValue != null) {
|
|
|
432 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
|
|
433 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
|
|
434 |
}
|
|
|
435 |
|
|
|
436 |
} else {
|
|
|
437 |
yearMonthValue = new HashMap<>();
|
|
|
438 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
|
|
439 |
}
|
|
|
440 |
}
|
|
|
441 |
|
|
|
442 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
|
|
443 |
|
|
|
444 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
|
|
445 |
|
|
|
446 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
|
|
447 |
|
|
|
448 |
}
|
|
|
449 |
|
|
|
450 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList, "Brand Wise Monthly Sale");
|
| 28468 |
tejbeer |
451 |
}
|
|
|
452 |
|
|
|
453 |
return cm;
|
|
|
454 |
}
|
|
|
455 |
|
|
|
456 |
public String adminPanel(int fofoId, String email, Model model) throws Exception {
|
|
|
457 |
List<Menu> menus = null;
|
|
|
458 |
try {
|
|
|
459 |
AuthUser authUser = authRepository.selectByEmailOrMobile(email);
|
|
|
460 |
List<Position> positions = positionRepository.selectAll(authUser.getId());
|
|
|
461 |
Map<Integer, PartnerDetailModel> warehousePartnerDetailMap = null;
|
|
|
462 |
|
|
|
463 |
Map<Integer, WarehouseWiseStockModel> warehouseStockMap = new HashMap<>();
|
|
|
464 |
LinkedHashMap<Integer, WarehouseWiseStockModel> warehouseStockSortedMap = new LinkedHashMap<>();
|
|
|
465 |
|
|
|
466 |
Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
|
| 30449 |
amit.gupta |
467 |
Map<Integer, String> wm = new LinkedHashMap<>();
|
| 28468 |
tejbeer |
468 |
|
|
|
469 |
Map<AuthUser, Long> authUserTicketCount = null;
|
|
|
470 |
|
|
|
471 |
for (Map.Entry<Integer, String> entry : warehouseMap.entrySet()) {
|
|
|
472 |
wm.put(entry.getKey(), entry.getValue());
|
|
|
473 |
}
|
|
|
474 |
|
|
|
475 |
wm.put(0, "Total Values");
|
|
|
476 |
long stockValue = 0;
|
|
|
477 |
long stockQty = 0;
|
|
|
478 |
long pendingIndent = 0;
|
|
|
479 |
long tertiary = 0;
|
|
|
480 |
|
| 31662 |
amit.gupta |
481 |
Set<Integer> fofoIds = csService1.getAuthFofoIds(email, true);
|
| 28468 |
tejbeer |
482 |
|
|
|
483 |
if (fofoIds != null && fofoIds.size() > 0) {
|
|
|
484 |
Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
|
|
|
485 |
.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream()
|
|
|
486 |
.collect(Collectors.groupingBy(FofoStore::getWarehouseId,
|
|
|
487 |
Collectors.mapping(FofoStore::getId, Collectors.toList())));
|
|
|
488 |
// warehouseStock
|
|
|
489 |
List<WarehouseWiseStockModel> warehouseStocks = saholicInventoryCISRepository
|
|
|
490 |
.selectGroupByWarehouse(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
|
|
|
491 |
|
|
|
492 |
warehouseStockMap = warehouseStocks.stream().collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
|
|
|
493 |
|
|
|
494 |
if (!warehouseStockMap.isEmpty()) {
|
|
|
495 |
for (Entry<Integer, WarehouseWiseStockModel> warehouseStock : warehouseStockMap.entrySet()) {
|
|
|
496 |
stockValue += warehouseStock.getValue().getStockValue();
|
|
|
497 |
stockQty += warehouseStock.getValue().getStockQty();
|
|
|
498 |
pendingIndent += warehouseStock.getValue().getPendingIndent();
|
|
|
499 |
tertiary += warehouseStock.getValue().getTertiary();
|
|
|
500 |
}
|
|
|
501 |
WarehouseWiseStockModel ws = new WarehouseWiseStockModel();
|
|
|
502 |
ws.setStockQty(stockQty);
|
|
|
503 |
ws.setStockValue(stockValue);
|
|
|
504 |
ws.setPendingIndent(pendingIndent);
|
|
|
505 |
ws.setTertiary(tertiary);
|
|
|
506 |
ws.setWarehouseId(0);
|
|
|
507 |
warehouseStockMap.put(0, ws);
|
|
|
508 |
|
|
|
509 |
}
|
|
|
510 |
|
|
|
511 |
warehouseStockMap.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
|
|
|
512 |
.forEachOrdered(x -> warehouseStockSortedMap.put(x.getKey(), x.getValue()));
|
|
|
513 |
|
| 30449 |
amit.gupta |
514 |
ReporticoCacheTable rctSaholic = reporticoCacheTableRepository.selectByTableName("SaholicInventoryCIS");
|
|
|
515 |
model.addAttribute("reporticoDate", rctSaholic);
|
| 28468 |
tejbeer |
516 |
|
|
|
517 |
// warehouseStock
|
|
|
518 |
warehousePartnerDetailMap = this.getWarehousePartnerDetail(warehouseIdFofoIdMap);
|
| 31259 |
tejbeer |
519 |
|
| 30449 |
amit.gupta |
520 |
ReporticoCacheTable rctPartneStat = reporticoCacheTableRepository.selectByTableName("partnerStat");
|
| 28468 |
tejbeer |
521 |
|
|
|
522 |
Set<CustomRetailer> positionRetailers = fofoIds.stream()
|
|
|
523 |
.map(x -> retailerService.getAllFofoRetailers().get(x)).filter(x -> x != null)
|
|
|
524 |
.collect(Collectors.toSet());
|
|
|
525 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
|
|
526 |
model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
|
|
|
527 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
| 30449 |
amit.gupta |
528 |
model.addAttribute("rctPartneStat", rctPartneStat);
|
| 28468 |
tejbeer |
529 |
} else {
|
|
|
530 |
List<Position> warehousePositions = positions.stream()
|
|
|
531 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
|
|
|
532 |
.collect(Collectors.toList());
|
|
|
533 |
if (warehousePositions.size() > 0) {
|
|
|
534 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
|
|
535 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
|
|
536 |
positionRetailers.addAll(customRetailers);
|
|
|
537 |
});
|
|
|
538 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
|
|
539 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
|
|
540 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
|
|
541 |
}
|
| 30056 |
amit.gupta |
542 |
List<Position> categoryPositions = positions.stream()
|
|
|
543 |
.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_CATEGORY)
|
|
|
544 |
.collect(Collectors.toList());
|
|
|
545 |
if (categoryPositions.size() > 0) {
|
|
|
546 |
Set<CustomRetailer> positionRetailers = new HashSet<>();
|
|
|
547 |
csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
|
|
|
548 |
positionRetailers.addAll(customRetailers);
|
|
|
549 |
});
|
|
|
550 |
model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
|
|
|
551 |
model.addAttribute("retailers", gson.toJson(positionRetailers));
|
|
|
552 |
model.addAttribute("warehouses", getWarehouses(positionRetailers));
|
|
|
553 |
}
|
| 28468 |
tejbeer |
554 |
}
|
|
|
555 |
|
|
|
556 |
if (positions.size() > 0) {
|
|
|
557 |
if (positions.stream()
|
|
|
558 |
.filter(x -> x.getEscalationType().equals(EscalationType.L3)
|
|
|
559 |
|| x.getEscalationType().equals(EscalationType.L4)
|
|
|
560 |
|| x.getEscalationType().equals(EscalationType.L5))
|
|
|
561 |
.count() > 0) {
|
|
|
562 |
authUserTicketCount = ticketRepository.selectAllAuthUserTicketCount(Optional.of(false));
|
|
|
563 |
}
|
|
|
564 |
}
|
|
|
565 |
|
| 31130 |
tejbeer |
566 |
if (Arrays.asList("amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com",
|
|
|
567 |
"kanan.choudhary@smartdukaan.com").contains(email)) {
|
| 28468 |
tejbeer |
568 |
menus = menuRepository.selectAll();
|
|
|
569 |
} else if (positions.size() > 0) {
|
|
|
570 |
if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
|
|
|
571 |
menus = menuRepository.selectAll();
|
|
|
572 |
} else {
|
|
|
573 |
List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
|
|
|
574 |
.map(x -> x.getMenuId()).collect(Collectors.toList());
|
|
|
575 |
if (menuIds.size() > 0) {
|
|
|
576 |
menus = menuRepository.selectAllByIds(menuIds);
|
|
|
577 |
}
|
|
|
578 |
}
|
|
|
579 |
}
|
|
|
580 |
|
|
|
581 |
model.addAttribute("authId", authUser.getId());
|
|
|
582 |
|
|
|
583 |
model.addAttribute("warehousePartnerDetailMap", warehousePartnerDetailMap);
|
|
|
584 |
model.addAttribute("warehouseMap", wm);
|
|
|
585 |
model.addAttribute("authUserTicketCount", authUserTicketCount);
|
|
|
586 |
model.addAttribute("warehouseStockMap", warehouseStockSortedMap);
|
|
|
587 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
|
|
588 |
|
|
|
589 |
model.addAttribute("date", curDate.withDayOfMonth(1).minusMonths(6).toLocalDate());
|
|
|
590 |
|
|
|
591 |
} catch (ProfitMandiBusinessException e) {
|
|
|
592 |
}
|
|
|
593 |
List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
|
|
|
594 |
LOGGER.info("menu" + menuList);
|
|
|
595 |
model.addAttribute("menu", menuList);
|
|
|
596 |
return "admin";
|
|
|
597 |
}
|
|
|
598 |
|
|
|
599 |
private List<Menu> prepareMenu(List<Menu> menus) {
|
|
|
600 |
List<Menu> returnMenu = new ArrayList<>();
|
| 30268 |
amit.gupta |
601 |
Map<Menu, List<Menu>> subMenuMap = new HashMap<>();
|
| 28468 |
tejbeer |
602 |
for (Menu menu : menus) {
|
|
|
603 |
if (menu.get_parent() == null) {
|
|
|
604 |
if (!subMenuMap.containsKey(menu)) {
|
|
|
605 |
subMenuMap.put(menu, new ArrayList<>());
|
|
|
606 |
}
|
|
|
607 |
} else {
|
|
|
608 |
Menu parentMenu = menu.get_parent();
|
|
|
609 |
if (!subMenuMap.containsKey(parentMenu)) {
|
|
|
610 |
subMenuMap.put(parentMenu, new ArrayList<>());
|
|
|
611 |
}
|
|
|
612 |
subMenuMap.get(parentMenu).add(menu);
|
|
|
613 |
}
|
|
|
614 |
}
|
|
|
615 |
subMenuMap.entrySet().stream().forEach(entry -> {
|
|
|
616 |
entry.getKey().setSubMenus(entry.getValue());
|
|
|
617 |
returnMenu.add(entry.getKey());
|
|
|
618 |
});
|
|
|
619 |
return returnMenu;
|
|
|
620 |
}
|
|
|
621 |
|
|
|
622 |
public Map<Integer, PartnerDetailModel> getWarehousePartnerDetail(Map<Integer, List<Integer>> warehousePartnerMap)
|
|
|
623 |
throws Exception {
|
|
|
624 |
|
|
|
625 |
Map<Integer, PartnerDetailModel> warehouseIdAndallValues = new LinkedHashMap<>();
|
|
|
626 |
// Map<Integer, List<FofoStore>> warehousePartnerMap =
|
|
|
627 |
// fofoStoreRepository.getWarehousePartnerMap();
|
|
|
628 |
Map<Integer, PartnerDetailModel> partnerStats = this.getPartnersStatDataFromFile();
|
|
|
629 |
List<Integer> allfofoIds = new ArrayList<>();
|
|
|
630 |
if (partnerStats != null) {
|
|
|
631 |
for (Entry<Integer, List<Integer>> warehouse : warehousePartnerMap.entrySet()) {
|
| 30246 |
amit.gupta |
632 |
List<Integer> fofoIds = warehouse.getValue().stream().collect(Collectors.toList());
|
| 28468 |
tejbeer |
633 |
allfofoIds.addAll(fofoIds);
|
|
|
634 |
List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
|
|
|
635 |
.collect(Collectors.toList());
|
|
|
636 |
if (partnerDetails != null && !partnerDetails.isEmpty()) {
|
|
|
637 |
PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
|
|
|
638 |
warehouseIdAndallValues.put(warehouse.getKey(), partnerDetailModel);
|
|
|
639 |
}
|
|
|
640 |
|
|
|
641 |
}
|
|
|
642 |
List<PartnerDetailModel> allPartnerDetails = allfofoIds.stream().map(x -> partnerStats.get(x))
|
|
|
643 |
.collect(Collectors.toList());
|
|
|
644 |
LOGGER.info("allPartnerDetails" + allPartnerDetails);
|
|
|
645 |
PartnerDetailModel partnerDetailModel = partnerStatsService
|
|
|
646 |
.getAggregateStats(new ArrayList<>(allPartnerDetails));
|
| 30268 |
amit.gupta |
647 |
warehouseIdAndallValues.put(0, partnerDetailModel);
|
| 28468 |
tejbeer |
648 |
}
|
|
|
649 |
return warehouseIdAndallValues;
|
|
|
650 |
}
|
|
|
651 |
|
|
|
652 |
public Map<Integer, PartnerDetailModel> getPartnersStatDataFromFile() throws Exception {
|
|
|
653 |
ObjectInputStream objectinputstream = null;
|
|
|
654 |
Map<Integer, PartnerDetailModel> partnerStat = null;
|
|
|
655 |
try {
|
|
|
656 |
FileInputStream streamIn = new FileInputStream("/tmp/partnerStat.tmp");
|
|
|
657 |
objectinputstream = new ObjectInputStream(streamIn);
|
|
|
658 |
partnerStat = (Map<Integer, PartnerDetailModel>) objectinputstream.readObject();
|
|
|
659 |
|
|
|
660 |
LOGGER.info("partnerStat" + partnerStat);
|
|
|
661 |
objectinputstream.close();
|
|
|
662 |
|
|
|
663 |
} catch (Exception e) {
|
|
|
664 |
LOGGER.info("exceptionddd" + e);
|
|
|
665 |
|
|
|
666 |
e.printStackTrace();
|
|
|
667 |
|
|
|
668 |
} finally {
|
|
|
669 |
if (objectinputstream != null) {
|
|
|
670 |
objectinputstream.close();
|
|
|
671 |
LOGGER.info("clofddd" + partnerStat);
|
|
|
672 |
|
|
|
673 |
}
|
|
|
674 |
}
|
|
|
675 |
return partnerStat;
|
|
|
676 |
|
|
|
677 |
}
|
|
|
678 |
|
|
|
679 |
private String getWarehouses(Set<CustomRetailer> positionRetailers) {
|
|
|
680 |
Map<Integer, String> warehouses = new HashMap<>();
|
|
|
681 |
positionRetailers.stream().forEach(x -> {
|
|
|
682 |
if (x.getWarehouseId() != 0) {
|
|
|
683 |
warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId()));
|
|
|
684 |
}
|
|
|
685 |
});
|
|
|
686 |
return gson.toJson(warehouses);
|
|
|
687 |
|
|
|
688 |
}
|
|
|
689 |
|
|
|
690 |
}
|