Subversion Repositories SmartDukaan

Rev

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