Subversion Repositories SmartDukaan

Rev

Rev 30056 | Rev 30246 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 30056 Rev 30220
Line 37... Line 37...
37
import java.time.LocalDate;
37
import java.time.LocalDate;
38
import java.time.LocalDateTime;
38
import java.time.LocalDateTime;
39
import java.time.Period;
39
import java.time.Period;
40
import java.time.YearMonth;
40
import java.time.YearMonth;
41
import java.time.format.DateTimeFormatter;
41
import java.time.format.DateTimeFormatter;
-
 
42
import java.time.temporal.ChronoUnit;
42
import java.util.*;
43
import java.util.*;
43
import java.util.Map.Entry;
44
import java.util.Map.Entry;
44
import java.util.stream.Collectors;
45
import java.util.stream.Collectors;
-
 
46
import java.util.stream.LongStream;
45
 
47
 
46
@Component
48
@Component
47
public class AdminUser {
49
public class AdminUser {
48
	@Autowired
50
	@Autowired
49
	private Gson gson;
51
	private Gson gson;
Line 108... Line 110...
108
		LOGGER.info("params" + warehouseIds + fofoIds + startDateTime);
110
		LOGGER.info("params" + warehouseIds + fofoIds + startDateTime);
109
 
111
 
110
		List<BrandWiseModel> brandWiseLms = orderRepository.selectGroupByBrandLmp(fofoIds, warehouseIds, startDateTime);
112
		List<BrandWiseModel> brandWiseLms = orderRepository.selectGroupByBrandLmp(fofoIds, warehouseIds, startDateTime);
111
		LOGGER.info("brandWiseLms" + brandWiseLms);
113
		LOGGER.info("brandWiseLms" + brandWiseLms);
112
 
114
 
113
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-yyyy");
115
		DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("MM-dd-yyyy");
114
 
116
 
115
		Map<String, Map<YearMonth, Double>> brandMonthValue = new HashMap<>();
117
		Map<String, Map<LocalDate, Double>> brandDateValue = new HashMap<>();
116
		for (BrandWiseModel bwl : brandWiseLms) {
118
		for (BrandWiseModel bwl : brandWiseLms) {
117
			Map<YearMonth, Double> yearMonthValue = new HashMap<>();
-
 
118
			if (brandMonthValue.containsKey(bwl.getBrand())) {
119
			if (!brandDateValue.containsKey(bwl.getBrand())) {
119
				yearMonthValue = brandMonthValue.get(bwl.getBrand());
120
				brandDateValue.put(bwl.getBrand(), new HashMap<>());
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
			}
121
			}
-
 
122
			Map<LocalDate, Double> dateWiseSalesMap = brandDateValue.get(bwl.getBrand());
126
			brandMonthValue.put(bwl.getBrand(), yearMonthValue);
123
			dateWiseSalesMap.put(LocalDate.parse(bwl.getYearMonth(), dateTimeFormatter), (double) bwl.getAmount());
127
 
-
 
128
		}
124
		}
129
		LocalDateTime curDate = LocalDate.now().atStartOfDay();
-
 
130
 
125
 
131
		Period age = Period.between(startDateTime, LocalDate.now());
126
		long days = startDateTime.until(LocalDate.now(), ChronoUnit.DAYS);
-
 
127
		List<LocalDate> allDatesBetween = LongStream.range(0, days).mapToObj(x -> startDateTime.plusDays(x)).collect(Collectors.toList());
132
		int months = age.getMonths();
128
		LOGGER.info("All dates between {}", allDatesBetween);
133
 
129
 
134
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
130
		Map<String, List<Double>> sortedBrandValue = new LinkedHashMap<>();
135
 
131
 
136
		for (String brand : brands) {
132
		for (String brand : brands) {
137
			Map<YearMonth, Double> yearMonthValue = brandMonthValue.get(brand);
133
			if (!brandDateValue.containsKey(brand)) {
138
			for (int i = months; i >= 0; i--) {
134
				brandDateValue.put(brand, new HashMap<>());
139
 
135
			}
140
				LocalDateTime startMonth = curDate.withDayOfMonth(1).minusMonths(i);
136
			Map<LocalDate, Double> dateWiseBrand = brandDateValue.get(brand);
141
 
-
 
142
				if (yearMonthValue != null) {
137
			for (LocalDate date : allDatesBetween) {
143
					if (yearMonthValue.get(YearMonth.from(startMonth)) == null) {
138
				if (dateWiseBrand.get(date) == 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);
139
					dateWiseBrand.put(date, 0.0);
150
				}
140
				}
151
			}
141
			}
152
 
142
 
153
			Map<YearMonth, Double> sortedMonthBrandValue = new TreeMap<>(yearMonthValue);
143
			Map<LocalDate, Double> sortedMonthBrandValue = new TreeMap<>(dateWiseBrand);
154
 
-
 
155
			brandMonthValue.put(brand, sortedMonthBrandValue);
144
			sortedBrandValue.put(brand, new ArrayList<>(sortedMonthBrandValue.values()));
156
 
-
 
157
			sortedBrandValue.put(brand, sortedMonthBrandValue.values().stream().collect(Collectors.toList()));
145
			LOGGER.info("Sorted Brandwise values count {}", sortedMonthBrandValue.size());
158
 
-
 
159
		}
146
		}
160
 
147
 
161
		LOGGER.info("brandMonthValue" + brandMonthValue);
148
		LOGGER.info("brandMonthValueCount {}", brandDateValue.size());
162
 
149
 
163
		LOGGER.info("sortedBrandValue" + sortedBrandValue);
150
		LOGGER.info("sortedBrandValueCount {}", sortedBrandValue.size());
164
 
151
 
165
		ChartModel cm = chartService.createChart(months, sortedBrandValue, colorList, borderList,
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,
166
				"Brand Wise Monthly Purchase");
155
				"Brand Wise Monthly Purchase");
167
 
156
 
168
		return cm;
157
		return cm;
169
	}
158
	}
170
 
159