Subversion Repositories SmartDukaan

Rev

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