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