| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.service;
|
1 |
package com.spice.profitmandi.service;
|
| 2 |
|
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.time.temporal.ChronoUnit;
|
| - |
|
11 |
import java.util.ArrayList;
|
| - |
|
12 |
import java.util.Arrays;
|
| - |
|
13 |
import java.util.Comparator;
|
| - |
|
14 |
import java.util.HashMap;
|
| - |
|
15 |
import java.util.HashSet;
|
| - |
|
16 |
import java.util.LinkedHashMap;
|
| - |
|
17 |
import java.util.LinkedHashSet;
|
| - |
|
18 |
import java.util.List;
|
| - |
|
19 |
import java.util.Map;
|
| - |
|
20 |
import java.util.Map.Entry;
|
| - |
|
21 |
import java.util.Optional;
|
| - |
|
22 |
import java.util.Set;
|
| - |
|
23 |
import java.util.TreeMap;
|
| - |
|
24 |
import java.util.stream.Collectors;
|
| - |
|
25 |
import java.util.stream.LongStream;
|
| - |
|
26 |
|
| - |
|
27 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
28 |
import org.apache.logging.log4j.Logger;
|
| - |
|
29 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
30 |
import org.springframework.stereotype.Component;
|
| - |
|
31 |
import org.springframework.ui.Model;
|
| - |
|
32 |
|
| 3 |
import com.google.gson.Gson;
|
33 |
import com.google.gson.Gson;
|
| 4 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
34 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
36 |
import com.spice.profitmandi.common.model.ChartInvestmentModel;
|
| - |
|
37 |
import com.spice.profitmandi.common.model.ChartModel;
|
| - |
|
38 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 6 |
import com.spice.profitmandi.common.model.*;
|
39 |
import com.spice.profitmandi.common.model.Data;
|
| - |
|
40 |
import com.spice.profitmandi.common.model.DataInvestmentModel;
|
| - |
|
41 |
import com.spice.profitmandi.common.model.Legend;
|
| - |
|
42 |
import com.spice.profitmandi.common.model.OptionModel;
|
| - |
|
43 |
import com.spice.profitmandi.common.model.PieLables;
|
| - |
|
44 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 7 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
45 |
import com.spice.profitmandi.dao.entity.auth.AuthUser;
|
| 8 |
import com.spice.profitmandi.dao.entity.auth.Menu;
|
46 |
import com.spice.profitmandi.dao.entity.auth.Menu;
|
| 9 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
47 |
import com.spice.profitmandi.dao.entity.cs.Position;
|
| 10 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
48 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| 11 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
49 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| Line 24... |
Line 62... |
| 24 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
62 |
import com.spice.profitmandi.dao.repository.fofo.ActivatedImeiRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
|
63 |
import com.spice.profitmandi.dao.repository.inventory.ReporticoCacheTableRepository;
|
| 26 |
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
|
64 |
import com.spice.profitmandi.dao.repository.inventory.SaholicInventoryCISRepository;
|
| 27 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
65 |
import com.spice.profitmandi.dao.repository.transaction.OrderRepository;
|
| 28 |
import com.spice.profitmandi.service.user.RetailerService;
|
66 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 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;
|
- |
|
| 34 |
|
- |
|
| 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.time.temporal.ChronoUnit;
|
- |
|
| 43 |
import java.util.*;
|
- |
|
| 44 |
import java.util.Map.Entry;
|
- |
|
| 45 |
import java.util.stream.Collectors;
|
- |
|
| 46 |
import java.util.stream.LongStream;
|
- |
|
| 47 |
|
67 |
|
| 48 |
@Component
|
68 |
@Component
|
| 49 |
public class AdminUser {
|
69 |
public class AdminUser {
|
| 50 |
@Autowired
|
70 |
@Autowired
|
| 51 |
private Gson gson;
|
71 |
private Gson gson;
|
| Line 104... |
Line 124... |
| 104 |
List<String> brands = Arrays.asList("Oppo", "Vivo", "Samsung", "Realme", "Xiaomi", "Tecno", "Itel", "Lava",
|
124 |
List<String> brands = Arrays.asList("Oppo", "Vivo", "Samsung", "Realme", "Xiaomi", "Tecno", "Itel", "Lava",
|
| 105 |
"Nokia");
|
125 |
"Nokia");
|
| 106 |
|
126 |
|
| 107 |
private static final Logger LOGGER = LogManager.getLogger(AdminUser.class);
|
127 |
private static final Logger LOGGER = LogManager.getLogger(AdminUser.class);
|
| 108 |
|
128 |
|
| 109 |
public ChartModel getBrandWiseLmp(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDateTime) {
|
129 |
public ChartModel getBrandWiseLmp(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
| - |
|
130 |
LocalDate endDate, String filterType) {
|
| 110 |
LOGGER.info("params" + warehouseIds + fofoIds + startDateTime);
|
131 |
LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
| 111 |
|
132 |
|
| 112 |
List<BrandWiseModel> brandWiseLms = orderRepository.selectGroupByBrandLmp(fofoIds, warehouseIds, startDateTime);
|
133 |
List<BrandWiseModel> brandWiseLms = orderRepository.selectGroupByBrandLmp(fofoIds, warehouseIds, startDate,
|
| - |
|
134 |
endDate, filterType);
|
| 113 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
135 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
| - |
|
136 |
ChartModel cm = null;
|
| 114 |
|
137 |
|
| - |
|
138 |
if (filterType.equals("dateWise")) {
|
| 115 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
139 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
| 116 |
|
140 |
|
| 117 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
141 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
| 118 |
for (BrandWiseModel bwl : brandWiseLms) {
|
142 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| 119 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
143 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
| 120 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
144 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
| - |
|
145 |
}
|
| - |
|
146 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
| - |
|
147 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
| 121 |
}
|
148 |
}
|
| 122 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
- |
|
| 123 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
- |
|
| 124 |
}
|
- |
|
| 125 |
|
149 |
|
| 126 |
long days = startDateTime.until(LocalDate.now(), ChronoUnit.DAYS);
|
150 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
| 127 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDateTime.plusDays(x)).collect(Collectors.toList());
|
151 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
| - |
|
152 |
.collect(Collectors.toList());
|
| 128 |
LOGGER.info("All dates between {}", allDatesBetween);
|
153 |
LOGGER.info("All dates between {}", allDatesBetween);
|
| 129 |
|
154 |
|
| 130 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
155 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| 131 |
|
156 |
|
| 132 |
for (String brand : brands) {
|
157 |
for (String brand : brands) {
|
| 133 |
if (!brandDateValue.containsKey(brand)) {
|
158 |
if (!brandDateValue.containsKey(brand)) {
|
| 134 |
brandDateValue.put(brand, new HashMap<>());
|
159 |
brandDateValue.put(brand, new HashMap<>());
|
| 135 |
}
|
160 |
}
|
| 136 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
161 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
| 137 |
for (LocalDate date : allDatesBetween) {
|
162 |
for (LocalDate date : allDatesBetween) {
|
| 138 |
if (dateWiseBrand.get(date) == null) {
|
163 |
if (dateWiseBrand.get(date) == null) {
|
| 139 |
dateWiseBrand.put(date, 0.0);
|
164 |
dateWiseBrand.put(date, 0.0);
|
| - |
|
165 |
}
|
| 140 |
}
|
166 |
}
|
| - |
|
167 |
|
| - |
|
168 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
| - |
|
169 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
| - |
|
170 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
| - |
|
171 |
}
|
| - |
|
172 |
|
| - |
|
173 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
| - |
|
174 |
|
| - |
|
175 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
| - |
|
176 |
cm = chartService.createChartWithLabels(
|
| - |
|
177 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
| - |
|
178 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
| - |
|
179 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Purchase");
|
| - |
|
180 |
|
| - |
|
181 |
} else {
|
| - |
|
182 |
|
| - |
|
183 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
| - |
|
184 |
|
| - |
|
185 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
| - |
|
186 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| - |
|
187 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
| - |
|
188 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
| - |
|
189 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
| - |
|
190 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| - |
|
191 |
(double) bwl.getAmount());
|
| - |
|
192 |
} else {
|
| - |
|
193 |
|
| - |
|
194 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| - |
|
195 |
(double) bwl.getAmount());
|
| - |
|
196 |
|
| - |
|
197 |
}
|
| - |
|
198 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
| - |
|
199 |
|
| 141 |
}
|
200 |
}
|
| - |
|
201 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 142 |
|
202 |
|
| - |
|
203 |
Period age = Period.between(startDate, endDate);
|
| - |
|
204 |
int months = age.getMonths();
|
| - |
|
205 |
LOGGER.info("months" + months);
|
| - |
|
206 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
| - |
|
207 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
| - |
|
208 |
|
| 143 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
209 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| - |
|
210 |
|
| - |
|
211 |
for (String brand : brands) {
|
| 144 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
212 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
| - |
|
213 |
for (int i = months; i >= 0; i--) {
|
| - |
|
214 |
|
| - |
|
215 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
| - |
|
216 |
|
| - |
|
217 |
if (yearMonthValue != null) {
|
| 145 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
218 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
| - |
|
219 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| - |
|
220 |
}
|
| - |
|
221 |
|
| - |
|
222 |
} else {
|
| - |
|
223 |
yearMonthValue = new HashMap<>();
|
| - |
|
224 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| - |
|
225 |
}
|
| 146 |
}
|
226 |
}
|
| - |
|
227 |
|
| - |
|
228 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
| - |
|
229 |
|
| - |
|
230 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
| - |
|
231 |
|
| - |
|
232 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
| 147 |
|
233 |
|
| 148 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
- |
|
| - |
|
234 |
}
|
| 149 |
|
235 |
|
| 150 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
236 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList,
|
| - |
|
237 |
"Brand Wise Monthly Purchase");
|
| 151 |
|
238 |
|
| 152 |
ChartModel cm = chartService.createChartWithLabels(
|
- |
|
| 153 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu")))).collect(Collectors.toCollection(LinkedHashSet::new))
|
- |
|
| 154 |
, sortedBrandValue, colorList, borderList,
|
- |
|
| 155 |
"Brand Wise Monthly Purchase");
|
239 |
}
|
| 156 |
|
240 |
|
| 157 |
return cm;
|
241 |
return cm;
|
| 158 |
}
|
242 |
}
|
| 159 |
|
243 |
|
| 160 |
public ChartInvestmentModel getAllStatePartnerType(Map<Integer, PartnerDetailModel> fofoIdAndallValues)
|
244 |
public ChartInvestmentModel getAllStatePartnerType(Map<Integer, PartnerDetailModel> fofoIdAndallValues)
|
| Line 237... |
Line 321... |
| 237 |
cm.setOptions(om);
|
321 |
cm.setOptions(om);
|
| 238 |
|
322 |
|
| 239 |
return cm;
|
323 |
return cm;
|
| 240 |
}
|
324 |
}
|
| 241 |
|
325 |
|
| 242 |
public Map<String, Object> getFilter(int warehouseId, String email, LocalDate date)
|
326 |
public Map<String, Object> getFilter(int warehouseId, String email, LocalDateTime date, LocalDateTime endDate)
|
| 243 |
throws ProfitMandiBusinessException {
|
327 |
throws ProfitMandiBusinessException {
|
| 244 |
Map<String, Object> map = new HashMap<>();
|
328 |
Map<String, Object> map = new HashMap<>();
|
| 245 |
|
329 |
|
| 246 |
Map<Integer, CustomRetailer> customRetailersMap = null;
|
330 |
Map<Integer, CustomRetailer> customRetailersMap = null;
|
| 247 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
331 |
Map<String, Set<Integer>> storeGuyMap = csService.getAuthUserPartnerIdMapping();
|
| Line 268... |
Line 352... |
| 268 |
|
352 |
|
| 269 |
fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
|
353 |
fofoIds = fofoStoreRepository.selectPartnerByfofoIdAndWarehouse(new ArrayList<>(fofoIds), warehouseId)
|
| 270 |
.stream().map(x -> x).collect(Collectors.toSet());
|
354 |
.stream().map(x -> x).collect(Collectors.toSet());
|
| 271 |
|
355 |
|
| 272 |
}
|
356 |
}
|
| 273 |
if (date == null) {
|
- |
|
| 274 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
- |
|
| 275 |
|
- |
|
| 276 |
LocalDateTime startOfMonth = curDate.withDayOfMonth(1).minusMonths(6);
|
- |
|
| 277 |
date = startOfMonth.toLocalDate();
|
- |
|
| 278 |
}
|
- |
|
| 279 |
|
357 |
|
| 280 |
if (fofoIds != null) {
|
358 |
if (fofoIds != null) {
|
| 281 |
customRetailersMap = retailerService
|
359 |
customRetailersMap = retailerService
|
| 282 |
.getFofoRetailers(fofoIds.stream().map(x -> x).collect(Collectors.toList()));
|
360 |
.getFofoRetailers(fofoIds.stream().map(x -> x).collect(Collectors.toList()));
|
| 283 |
|
361 |
|
| 284 |
}
|
362 |
}
|
| 285 |
|
363 |
|
| 286 |
map.put("date", date);
|
364 |
map.put("date", date);
|
| - |
|
365 |
map.put("endDate", endDate);
|
| 287 |
map.put("customRetailersMap", customRetailersMap);
|
366 |
map.put("customRetailersMap", customRetailersMap);
|
| 288 |
map.put("fofoIds", fofoIds);
|
367 |
map.put("fofoIds", fofoIds);
|
| 289 |
map.put("warehouseMap", warehouseMap);
|
368 |
map.put("warehouseMap", warehouseMap);
|
| 290 |
|
369 |
|
| 291 |
return map;
|
370 |
return map;
|
| 292 |
|
371 |
|
| 293 |
}
|
372 |
}
|
| 294 |
|
373 |
|
| 295 |
public ChartModel getBrandWiseLms(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDateTime) {
|
374 |
public ChartModel getBrandWiseLms(List<Integer> warehouseIds, List<Integer> fofoIds, LocalDate startDate,
|
| - |
|
375 |
LocalDate endDate, String filterType) {
|
| 296 |
LOGGER.info("params" + warehouseIds + fofoIds + startDateTime);
|
376 |
LOGGER.info("params" + warehouseIds + fofoIds + startDate);
|
| 297 |
|
377 |
|
| 298 |
List<BrandWiseModel> brandWiseLms = fofoStoreRepository.selectGroupByBrandLms(fofoIds, warehouseIds,
|
378 |
List<BrandWiseModel> brandWiseLms = fofoStoreRepository.selectGroupByBrandLms(fofoIds, warehouseIds, startDate,
|
| 299 |
startDateTime);
|
379 |
endDate, filterType);
|
| 300 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
380 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
| 301 |
|
381 |
|
| 302 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
382 |
ChartModel cm = null;
|
| 303 |
|
383 |
|
| 304 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
- |
|
| 305 |
for (BrandWiseModel bwl : brandWiseLms) {
|
384 |
if (filterType.equals("dateWise")) {
|
| 306 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
- |
|
| 307 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
- |
|
| 308 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
- |
|
| 309 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
- |
|
| 310 |
} else {
|
- |
|
| 311 |
|
- |
|
| 312 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
385 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
|
| 313 |
|
386 |
|
| - |
|
387 |
Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
|
| - |
|
388 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| - |
|
389 |
if (!brandDateValue.containsKey(bwl.getBrand())) {
|
| - |
|
390 |
brandDateValue.put(bwl.getBrand(), new HashMap<>());
|
| - |
|
391 |
}
|
| - |
|
392 |
Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
|
| - |
|
393 |
dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
|
| 314 |
}
|
394 |
}
|
| 315 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
- |
|
| 316 |
|
395 |
|
| 317 |
}
|
- |
|
| 318 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
396 |
long days = startDate.until(endDate, ChronoUnit.DAYS);
|
| - |
|
397 |
List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDate.plusDays(x))
|
| - |
|
398 |
.collect(Collectors.toList());
|
| - |
|
399 |
LOGGER.info("All dates between {}", allDatesBetween);
|
| 319 |
|
400 |
|
| - |
|
401 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| - |
|
402 |
|
| - |
|
403 |
for (String brand : brands) {
|
| - |
|
404 |
if (!brandDateValue.containsKey(brand)) {
|
| 320 |
Period age = Period.between(startDateTime, LocalDate.now());
|
405 |
brandDateValue.put(brand, new HashMap<>());
|
| - |
|
406 |
}
|
| - |
|
407 |
Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
|
| - |
|
408 |
for (LocalDate date : allDatesBetween) {
|
| - |
|
409 |
if (dateWiseBrand.get(date) == null) {
|
| 321 |
int months = age.getMonths();
|
410 |
dateWiseBrand.put(date, 0.0);
|
| - |
|
411 |
}
|
| - |
|
412 |
}
|
| - |
|
413 |
|
| - |
|
414 |
Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
|
| - |
|
415 |
sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
|
| - |
|
416 |
LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
|
| - |
|
417 |
}
|
| - |
|
418 |
|
| 322 |
LOGGER.info("months" + months);
|
419 |
LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
|
| - |
|
420 |
|
| - |
|
421 |
LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
|
| - |
|
422 |
cm = chartService.createChartWithLabels(
|
| - |
|
423 |
allDatesBetween.stream().map(x -> x.format((DateTimeFormatter.ofPattern("dd MMM''uu"))))
|
| - |
|
424 |
.collect(Collectors.toCollection(LinkedHashSet::new)),
|
| - |
|
425 |
sortedBrandValue, colorList, borderList, "Brand Wise Date Wise Sale");
|
| - |
|
426 |
|
| - |
|
427 |
} else {
|
| - |
|
428 |
|
| - |
|
429 |
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
|
| - |
|
430 |
|
| - |
|
431 |
Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
|
| 323 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
432 |
for (BrandWiseModel bwl : brandWiseLms) {
|
| - |
|
433 |
Map<YearMonth, Double> yearMonthValue = new HashMap<>();
|
| - |
|
434 |
if (brandMonthValue.containsKey(bwl.getBrand())) {
|
| 324 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
435 |
yearMonthValue = brandMonthValue.get(bwl.getBrand());
|
| - |
|
436 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| - |
|
437 |
(double) bwl.getAmount());
|
| - |
|
438 |
} else {
|
| 325 |
|
439 |
|
| 326 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
440 |
yearMonthValue.put(YearMonth.parse(bwl.getYearMonth(), dateTimeFormatter),
|
| - |
|
441 |
(double) bwl.getAmount());
|
| 327 |
|
442 |
|
| 328 |
for (String brand : brands) {
|
443 |
}
|
| 329 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
444 |
brandMonthValue.put(bwl.getBrand(), yearMonthValue);
|
| 330 |
for (int i = months; i >= 0; i--) {
|
- |
|
| 331 |
|
445 |
|
| - |
|
446 |
}
|
| 332 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
447 |
LocalDateTime curDate = LocalDate.now().atStartOfDay();
|
| 333 |
|
448 |
|
| - |
|
449 |
Period age = Period.between(startDate, endDate);
|
| - |
|
450 |
int months = age.getMonths();
|
| - |
|
451 |
LOGGER.info("months" + months);
|
| - |
|
452 |
LOGGER.info("brandWiseLms" + brandWiseLms);
|
| - |
|
453 |
LOGGER.info("brandMonthValue" + brandMonthValue);
|
| - |
|
454 |
|
| - |
|
455 |
Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
|
| - |
|
456 |
|
| - |
|
457 |
for (String brand : brands) {
|
| - |
|
458 |
Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
|
| - |
|
459 |
for (int i = months; i >= 0; i--) {
|
| - |
|
460 |
|
| - |
|
461 |
LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
|
| - |
|
462 |
|
| 334 |
if (yearMonthValue != null) {
|
463 |
if (yearMonthValue != null) {
|
| 335 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
464 |
if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
|
| - |
|
465 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| - |
|
466 |
}
|
| - |
|
467 |
|
| - |
|
468 |
} else {
|
| - |
|
469 |
yearMonthValue = new HashMap<>();
|
| 336 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
470 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
| 337 |
}
|
471 |
}
|
| 338 |
|
- |
|
| 339 |
} else {
|
- |
|
| 340 |
yearMonthValue = new HashMap<>();
|
- |
|
| 341 |
yearMonthValue.put(YearMonth.from(startMonth), 0.0);
|
- |
|
| 342 |
}
|
472 |
}
|
| 343 |
}
|
- |
|
| 344 |
|
473 |
|
| 345 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
474 |
Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
|
| 346 |
|
475 |
|
| 347 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
476 |
brandMonthValue.put(brand, sortedMonthBrandValue);
|
| 348 |
|
477 |
|
| 349 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
478 |
sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
|
| 350 |
|
479 |
|
| 351 |
}
|
480 |
}
|
| 352 |
|
481 |
|
| 353 |
ChartModel cm = chartService.createChart(months, sortedBrandValue, colorList, borderList,
|
482 |
cm = chartService.createChart(months, sortedBrandValue, colorList, borderList, "Brand Wise Monthly Sale");
|
| 354 |
"Brand Wise Monthly Sale");
|
483 |
}
|
| 355 |
|
484 |
|
| 356 |
return cm;
|
485 |
return cm;
|
| 357 |
}
|
486 |
}
|
| 358 |
|
487 |
|
| 359 |
public String adminPanel(int fofoId, String email, Model model) throws Exception {
|
488 |
public String adminPanel(int fofoId, String email, Model model) throws Exception {
|