Subversion Repositories SmartDukaan

Rev

Rev 29165 | Rev 29198 | 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")) {
29168 manish 220
				backgroundColor.add("#CD7F32");
29165 manish 221
			}
222
			if (label.equals("SILVER")) {
223
				backgroundColor.add("silver");
224
			}
225
			if (label.equals("GOLD")) {
29168 manish 226
				backgroundColor.add("#FFD700");
29165 manish 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
 
239
		}
240
 
241
		LOGGER.info("valuesPartnerType" + values);
242
		LOGGER.info("partnerTypeCount" + partnerTypeCount);
243
 
244
		Data data = new Data();
245
		data.setData(values);
246
		data.setBackgroundColor(backgroundColor);
247
		data.setLabel("DataSet 1");
248
 
249
		PieLables label = new PieLables();
250
		label.setFontColor("black");
251
		label.setFontSize(22);
252
 
253
		Legend legend = new Legend();
254
		legend.setLabels(label);
255
		legend.setPosition("left");
256
 
257
		List<Data> dataList = new ArrayList<>();
258
		dataList.add(data);
259
 
260
		DataInvestmentModel datasets = new DataInvestmentModel();
261
		datasets.setDatasets(dataList);
262
		datasets.setLabels(labels);
263
 
264
		OptionModel om = new OptionModel();
265
		om.setLegend(legend);
266
		cm.setType("pie");
267
		cm.setData(datasets);
268
		cm.setOptions(om);
269
 
270
		return cm;
271
	}
272
 
28468 tejbeer 273
	public Map<String, Object> getFilter(int warehouseId, String email, LocalDate date)
274
			throws ProfitMandiBusinessException {
275
		Map<String, Object> map = new HashMap<>();
276
 
277
		Map<Integer, CustomRetailer> customRetailersMap = null;
278
		Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
279
		AuthUser authUser = authRepository.selectByEmailOrMobile(email);
280
		Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
281
 
282
		Set<Integer> fofoIds = null;
283
		fofoIds = storeGuyMap.get(authUser.getEmailId());
284
		if (emails.contains(authUser.getEmailId())) {
285
			fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
286
 
287
		}
288
 
289
		if (fofoIds == null) {
290
			List<Position> positions1 = positionRepository.selectAll(authUser.getId());
291
			if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
292
					.count() > 0) {
293
				fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream().flatMap(x -> x.stream())
294
						.map(x -> x.getPartnerId()).collect(Collectors.toSet());
295
			}
296
		}
297
 
298
		if (warehouseId != 0) {
299
 
300
			fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
301
					.stream().map(x -> x).collect(Collectors.toSet());
302
 
303
		}
304
		if (date == null) {
305
			LocalDateTime curDate = LocalDate.now().atStartOfDay();
306
 
307
			LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
308
			date = startOfMonth.toLocalDate();
309
		}
310
 
311
		if (fofoIds != null) {
312
			customRetailersMap = retailerService
313
					.getFofoRetailers(fofoIds.stream().map(x -> x).collect(Collectors.toList()));
314
 
315
		}
316
 
317
		map.put("date", date);
318
		map.put("customRetailersMap", customRetailersMap);
319
		map.put("fofoIds", fofoIds);
320
		map.put("warehouseMap", warehouseMap);
321
 
322
		return map;
323
 
324
	}
325
 
326
	public ChartModel getBrandWiseLms(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDateTime) {
327
		LOGGER.info("params" + warehouseIds + fofoIds + startDateTime);
328
 
329
		List<BrandWiseModel> brandWiseLms = fofoStoreRepository.selectGroupByBrandLms(fofoIds, warehouseIds,
330
				startDateTime);
331
		LOGGER.info("brandWiseLms" + brandWiseLms);
332
 
333
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
334
 
335
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
336
		for (BrandWiseModel bwl : brandWiseLms) {
337
			Map<YearMonth, Double> yearMonthValue = new HashMap<>();
338
			if (brandMonthValue.containsKey(bwl.getBrand())) {
339
				yearMonthValue = brandMonthValue.get(bwl.getBrand());
340
				yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
341
			} else {
342
 
343
				yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
344
 
345
			}
346
			brandMonthValue.put(bwl.getBrand(), yearMonthValue);
347
 
348
		}
349
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
350
 
351
		Period age = Period.between(startDateTime, LocalDate.now());
352
		int months = age.getMonths();
353
		LOGGER.info("months" + months);
354
		LOGGER.info("brandWiseLms" + brandWiseLms);
355
		LOGGER.info("brandMonthValue" + brandMonthValue);
356
 
357
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
358
 
359
		for (String brand : brands) {
360
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
361
			for (int i = months; i >= 0; i--) {
362
 
363
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
364
 
365
				if (yearMonthValue != null) {
366
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
367
						yearMonthValue.put(YearMonth.from(startMonth), 0.0);
368
					}
369
 
370
				} else {
371
					yearMonthValue = new HashMap<>();
372
					yearMonthValue.put(YearMonth.from(startMonth), 0.0);
373
				}
374
			}
375
 
376
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
377
 
378
			brandMonthValue.put(brand, sortedMonthBrandValue);
379
 
380
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
381
 
382
		}
383
 
384
		ChartModel cm = chartService.createChart(months, sortedBrandValue, colorList, borderList,
385
				"Brand Wise Monthly Sale");
386
 
387
		return cm;
388
	}
389
 
390
	public String adminPanel(int fofoId, String email, Model model) throws Exception {
391
		List<Menu> menus = null;
392
		try {
393
			AuthUser authUser = authRepository.selectByEmailOrMobile(email);
394
			List<Position> positions = positionRepository.selectAll(authUser.getId());
395
			Map<Integer, PartnerDetailModel> warehousePartnerDetailMap = null;
396
			ReporticoCacheTable rctSaholic = null;
397
			ReporticoCacheTable rctPartneStat = null;
398
 
399
			Map<Integer, WarehouseWiseStockModel> warehouseStockMap = new HashMap<>();
400
			LinkedHashMap<Integer, WarehouseWiseStockModel> warehouseStockSortedMap = new LinkedHashMap<>();
401
 
402
			Map<Integer, String> warehouseMap = ProfitMandiConstants.WAREHOUSE_MAP;
403
			LinkedHashMap<Integer, String> wm = new LinkedHashMap<Integer, String>();
404
 
405
			Map<AuthUser, Long> authUserTicketCount = null;
406
 
407
			for (Map.Entry<Integer, String> entry : warehouseMap.entrySet()) {
408
				wm.put(entry.getKey(), entry.getValue());
409
			}
410
 
411
			wm.put(0, "Total Values");
412
			long stockValue = 0;
413
			long stockQty = 0;
414
			long pendingIndent = 0;
415
			long tertiary = 0;
416
 
417
			Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
418
 
419
			Set<Integer> fofoIds = storeGuyMap.get(authUser.getEmailId());
420
			if (emails.contains(authUser.getEmailId())) {
421
				fofoIds = storeGuyMap.get("tarun.verma@smartdukaan.com");
422
				LOGGER.info("fofoIds" + fofoIds);
423
			}
424
			if (fofoIds == null) {
425
				List<Position> positions1 = positionRepository.selectAll(authUser.getId());
426
				if (positions1.stream().filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_MASTER)
427
						.count() > 0) {
428
					fofoIds = csService.getPositionCustomRetailerMap(positions1).values().stream()
429
							.flatMap(x -> x.stream()).map(x -> x.getPartnerId()).collect(Collectors.toSet());
430
				}
431
			}
432
 
433
			if (fofoIds != null && fofoIds.size() > 0) {
434
				Map<Integer, List<Integer>> warehouseIdFofoIdMap = fofoStoreRepository
435
						.selectActivePartnersByRetailerIds(new ArrayList<>(fofoIds)).stream()
436
						.collect(Collectors.groupingBy(FofoStore::getWarehouseId,
437
								Collectors.mapping(FofoStore::getId, Collectors.toList())));
438
				// warehouseStock
439
				List<WarehouseWiseStockModel> warehouseStocks = saholicInventoryCISRepository
440
						.selectGroupByWarehouse(new ArrayList<>(warehouseIdFofoIdMap.keySet()));
441
 
442
				warehouseStockMap = warehouseStocks.stream().collect(Collectors.toMap(x -> x.getWarehouseId(), x -> x));
443
 
444
				if (!warehouseStockMap.isEmpty()) {
445
					for (Entry<Integer, WarehouseWiseStockModel> warehouseStock : warehouseStockMap.entrySet()) {
446
						stockValue += warehouseStock.getValue().getStockValue();
447
						stockQty += warehouseStock.getValue().getStockQty();
448
						pendingIndent += warehouseStock.getValue().getPendingIndent();
449
						tertiary += warehouseStock.getValue().getTertiary();
450
					}
451
					WarehouseWiseStockModel ws = new WarehouseWiseStockModel();
452
					ws.setStockQty(stockQty);
453
					ws.setStockValue(stockValue);
454
					ws.setPendingIndent(pendingIndent);
455
					ws.setTertiary(tertiary);
456
					ws.setWarehouseId(0);
457
					warehouseStockMap.put(0, ws);
458
 
459
				}
460
 
461
				warehouseStockMap.entrySet().stream().sorted(Map.Entry.comparingByKey(Comparator.reverseOrder()))
462
						.forEachOrdered(x -> warehouseStockSortedMap.put(x.getKey(), x.getValue()));
463
 
464
				rctSaholic = reporticoCacheTableRepository.selectByTableName("SaholicInventoryCIS");
465
 
466
				// warehouseStock
467
				warehousePartnerDetailMap = this.getWarehousePartnerDetail(warehouseIdFofoIdMap);
468
				rctPartneStat = reporticoCacheTableRepository.selectByTableName("partnerStat");
469
 
470
				Set<CustomRetailer> positionRetailers = fofoIds.stream()
471
						.map(x -> retailerService.getAllFofoRetailers().get(x)).filter(x -> x != null)
472
						.collect(Collectors.toSet());
473
				model.addAttribute("retailers", gson.toJson(positionRetailers));
474
				model.addAttribute("reporticoProjectMap", ReporticoProject.salesReporticoProjectMap);
475
				model.addAttribute("warehouses", getWarehouses(positionRetailers));
476
			} else {
477
				List<Position> warehousePositions = positions.stream()
478
						.filter(x -> x.getCategoryId() == ProfitMandiConstants.TICKET_CATEGORY_WAREHOUSE)
479
						.collect(Collectors.toList());
480
				if (warehousePositions.size() > 0) {
481
					Set<CustomRetailer> positionRetailers = new HashSet<>();
482
					csService.getPositionCustomRetailerMap(warehousePositions).values().forEach(customRetailers -> {
483
						positionRetailers.addAll(customRetailers);
484
					});
485
					model.addAttribute("reporticoProjectMap", ReporticoProject.warehouseReporticoMap);
486
					model.addAttribute("retailers", gson.toJson(positionRetailers));
487
					model.addAttribute("warehouses", getWarehouses(positionRetailers));
488
				}
489
			}
490
 
491
			if (positions.size() > 0) {
492
				if (positions.stream()
493
						.filter(x -> x.getEscalationType().equals(EscalationType.L3)
494
								|| x.getEscalationType().equals(EscalationType.L4)
495
								|| x.getEscalationType().equals(EscalationType.L5))
496
						.count() > 0) {
497
					authUserTicketCount = ticketRepository.selectAllAuthUserTicketCount(Optional.of(false));
498
				}
499
			}
500
 
501
			if (Arrays.asList("amit.gupta@shop2020.in", "tejbeer.kaur@shop2020.in", "manish.tiwari@smartdukaan.com")
502
					.contains(email)) {
503
				menus = menuRepository.selectAll();
504
			} else if (positions.size() > 0) {
505
				if (positions.stream().filter(x -> x.getEscalationType().equals(EscalationType.L5)).count() > 0) {
506
					menus = menuRepository.selectAll();
507
				} else {
508
					List<Integer> menuIds = menuCategoryRepository.selectAllByPositions(positions).stream()
509
							.map(x -> x.getMenuId()).collect(Collectors.toList());
510
					if (menuIds.size() > 0) {
511
						menus = menuRepository.selectAllByIds(menuIds);
512
					}
513
				}
514
			}
515
 
516
			model.addAttribute("authId", authUser.getId());
517
 
518
			model.addAttribute("rctPartneStat", rctPartneStat);
519
 
520
			model.addAttribute("reporticoDate", rctSaholic);
521
			model.addAttribute("warehousePartnerDetailMap", warehousePartnerDetailMap);
522
			model.addAttribute("warehouseMap", wm);
523
			model.addAttribute("authUserTicketCount", authUserTicketCount);
524
			model.addAttribute("warehouseStockMap", warehouseStockSortedMap);
525
			LocalDateTime curDate = LocalDate.now().atStartOfDay();
526
 
527
			model.addAttribute("date", curDate.withDayOfMonth(1).minusMonths(6).toLocalDate());
528
 
529
		} catch (ProfitMandiBusinessException e) {
530
		}
531
		List<Menu> menuList = (menus != null) ? this.prepareMenu(menus) : new ArrayList<>();
532
		LOGGER.info("menu" + menuList);
533
		model.addAttribute("menu", menuList);
534
		return "admin";
535
	}
536
 
537
	private List<Menu> prepareMenu(List<Menu> menus) {
538
		List<Menu> returnMenu = new ArrayList<>();
539
		Map<Menu, List<Menu>> subMenuMap = new HashMap<Menu, List<Menu>>();
540
		for (Menu menu : menus) {
541
			if (menu.get_parent() == null) {
542
				if (!subMenuMap.containsKey(menu)) {
543
					subMenuMap.put(menu, new ArrayList<>());
544
				}
545
			} else {
546
				Menu parentMenu = menu.get_parent();
547
				if (!subMenuMap.containsKey(parentMenu)) {
548
					subMenuMap.put(parentMenu, new ArrayList<>());
549
				}
550
				subMenuMap.get(parentMenu).add(menu);
551
			}
552
		}
553
		subMenuMap.entrySet().stream().forEach(entry -> {
554
			entry.getKey().setSubMenus(entry.getValue());
555
			returnMenu.add(entry.getKey());
556
		});
557
		return returnMenu;
558
	}
559
 
560
	public Map<Integer, PartnerDetailModel> getWarehousePartnerDetail(Map<Integer, List<Integer>> warehousePartnerMap)
561
			throws Exception {
562
 
563
		Map<Integer, PartnerDetailModel> warehouseIdAndallValues = new LinkedHashMap<>();
564
		// Map<Integer, List<FofoStore>> warehousePartnerMap =
565
		// fofoStoreRepository.getWarehousePartnerMap();
566
		Map<Integer, PartnerDetailModel> partnerStats = this.getPartnersStatDataFromFile();
567
		List<Integer> allfofoIds = new ArrayList<>();
568
		if (partnerStats != null) {
569
			for (Entry<Integer, List<Integer>> warehouse : warehousePartnerMap.entrySet()) {
570
				List<Integer> fofoIds = warehouse.getValue().stream().map(x -> x).collect(Collectors.toList());
571
				allfofoIds.addAll(fofoIds);
572
				List<PartnerDetailModel> partnerDetails = fofoIds.stream().map(x -> partnerStats.get(x))
573
						.collect(Collectors.toList());
574
				if (partnerDetails != null && !partnerDetails.isEmpty()) {
575
					PartnerDetailModel partnerDetailModel = partnerStatsService.getAggregateStats(partnerDetails);
576
					warehouseIdAndallValues.put(warehouse.getKey(), partnerDetailModel);
577
				}
578
 
579
			}
580
			List<PartnerDetailModel> allPartnerDetails = allfofoIds.stream().map(x -> partnerStats.get(x))
581
					.collect(Collectors.toList());
582
			LOGGER.info("allPartnerDetails" + allPartnerDetails);
583
			PartnerDetailModel partnerDetailModel = partnerStatsService
584
					.getAggregateStats(new ArrayList<>(allPartnerDetails));
585
			warehouseIdAndallValues.put(0, partnerDetailModel);
586
		}
587
		return warehouseIdAndallValues;
588
	}
589
 
590
	public Map<Integer, PartnerDetailModel> getPartnersStatDataFromFile() throws Exception {
591
		ObjectInputStream objectinputstream = null;
592
		Map<Integer, PartnerDetailModel> partnerStat = null;
593
		try {
594
			FileInputStream streamIn = new FileInputStream("/tmp/partnerStat.tmp");
595
			objectinputstream = new ObjectInputStream(streamIn);
596
			partnerStat = (Map<Integer, PartnerDetailModel>) objectinputstream.readObject();
597
 
598
			LOGGER.info("partnerStat" + partnerStat);
599
			objectinputstream.close();
600
 
601
		} catch (Exception e) {
602
			LOGGER.info("exceptionddd" + e);
603
 
604
			e.printStackTrace();
605
 
606
		} finally {
607
			if (objectinputstream != null) {
608
				objectinputstream.close();
609
				LOGGER.info("clofddd" + partnerStat);
610
 
611
			}
612
		}
613
		return partnerStat;
614
 
615
	}
616
 
617
	private String getWarehouses(Set<CustomRetailer> positionRetailers) {
618
		Map<Integer, String> warehouses = new HashMap<>();
619
		positionRetailers.stream().forEach(x -> {
620
			if (x.getWarehouseId() != 0) {
621
				warehouses.put(x.getWarehouseId(), ProfitMandiConstants.WAREHOUSE_MAP.get(x.getWarehouseId()));
622
			}
623
		});
624
		return gson.toJson(warehouses);
625
 
626
	}
627
 
628
}