Subversion Repositories SmartDukaan

Rev

Rev 30220 | Rev 30268 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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