Subversion Repositories SmartDukaan

Rev

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

Rev 29662 Rev 29663
Line 275... Line 275...
275
		}
275
		}
276
 
276
 
277
	}
277
	}
278
 
278
 
279
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
279
	@RequestMapping(value = "/evaluateActualInvestmentPayout", method = RequestMethod.GET)
280
	   public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request,Model model) throws Exception {
280
	public ResponseEntity<?> evaluateActualInvestmentPayout(HttpServletRequest request, Model model) throws Exception {
281
			
281
 
282
			List<List<?>> rows = new ArrayList<>();
282
		List<List<?>> rows = new ArrayList<>();
283
			LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
283
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
284
			LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
284
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
285
			LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
285
		LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
286
			List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
286
		List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository
287
					.selectAll(firstDateOfCurrentMonth.atStartOfDay().toLocalDate(), LocalDateTime.now().minusDays(1).toLocalDate());
287
				.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
288
			
-
 
289
			Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
288
		Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream()
290
					.filter(x -> x.getShortPercentage() <= 10)
289
				.filter(x -> x.getShortPercentage() <= 10)
291
					.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
290
				.collect(Collectors.groupingBy(x -> x.getFofoId(), Collectors.counting()));
292
			LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
291
		LOGGER.info("investmentMaintainedDaysMap {}", investmentMaintainedDaysMap);
293
		
-
 
294
			List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
292
		List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT,
295
					firstDateOfCurrentMonth.atStartOfDay(),LocalDateTime.now().minusDays(1) );
293
				startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
296
			
-
 
297
			Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
294
		Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream()
298
					.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
295
				.collect(Collectors.groupingBy(x -> x.getInventoryItemId()));
299
			List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
296
		List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
300
			Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
297
		Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream().collect(
301
					Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
298
				Collectors.groupingBy(x -> x.getFofoId(), Collectors.mapping(x -> x.getId(), Collectors.toList())));
302
			System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
299
		System.out.println("Fofo Id\tInvestment Maintained Days\tEligible payout");
303
			for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
300
		for (Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
304
				int fofoId = retailerEntry.getKey();
301
			int fofoId = retailerEntry.getKey();
305
				List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
302
			List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x -> inventoryItemIdSchemeMap.get(x))
306
						.flatMap(List::stream).collect(Collectors.toList());
303
					.flatMap(List::stream).collect(Collectors.toList());
307
				double totalAmount = schemeInouts.stream().filter(x -> x.getRolledBackTimestamp() == null)
304
			double totalAmount = schemeInouts.stream().filter(x -> x.getRolledBackTimestamp() == null)
308
						.collect(Collectors.summingDouble(x -> x.getAmount()));
305
					.collect(Collectors.summingDouble(x -> x.getAmount()));
309
				long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
306
			long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId) == null ? 0
310
						: investmentMaintainedDaysMap.get(fofoId);
307
					: investmentMaintainedDaysMap.get(fofoId);
311
				if (investmentMaintainedDays < 8) {
308
			if (investmentMaintainedDays < 8) {
312
					totalAmount = 0;
309
				totalAmount = 0;
313
				} else if (investmentMaintainedDays < 12) {
310
			} else if (investmentMaintainedDays < 12) {
314
					totalAmount = totalAmount / 2;
311
				totalAmount = totalAmount / 2;
315
				}
-
 
316
				System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
-
 
317
				CustomRetailer customRetailer= retailerService.getFofoRetailer(fofoId);
-
 
318
				
-
 
319
				 rows.add(Arrays.asList(fofoId,customRetailer.getBusinessName(),customRetailer.getCode(),investmentMaintainedDays,totalAmount));
-
 
320
			}
312
			}
321
		
-
 
322
			
-
 
323
					org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
-
 
324
					.getCSVByteStream(Arrays.asList("fofoId","Name", "Code", "investmentMaintainedDays","totalAmount"), rows);
313
			System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
325
 
-
 
326
			final HttpHeaders headers = new HttpHeaders();
-
 
327
			headers.set("Content-Type", "text/csv");
-
 
328
			headers.set("Content-disposition", "inline; filename=investmentMaintainedDays.csv");
314
			CustomRetailer customRetailer = retailerService.getFofoRetailer(fofoId);
329
			headers.setContentLength(baos.toByteArray().length);
-
 
330
 
315
 
331
			final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
316
			rows.add(Arrays.asList(fofoId, customRetailer.getBusinessName(), customRetailer.getCode(),
332
			final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
317
					investmentMaintainedDays, totalAmount));
333
		
-
 
334
			return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
335
			
-
 
336
		}
318
		}
337
 
319
 
-
 
320
		org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
-
 
321
				Arrays.asList("fofoId", "Name", "Code", "investmentMaintainedDays", "totalAmount"), rows);
-
 
322
 
-
 
323
		final HttpHeaders headers = new HttpHeaders();
-
 
324
		headers.set("Content-Type", "text/csv");
-
 
325
		headers.set("Content-disposition", "inline; filename=investmentMaintainedDays.csv");
-
 
326
		headers.setContentLength(baos.toByteArray().length);
-
 
327
 
-
 
328
		final InputStream inputStream = new ByteArrayInputStream(baos.toByteArray());
-
 
329
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
-
 
330
 
-
 
331
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
-
 
332
 
-
 
333
	}
-
 
334
 
338
	@RequestMapping(value = "/processInvestmentDryRun", method = RequestMethod.GET)
335
	@RequestMapping(value = "/processInvestmentDryRun", method = RequestMethod.GET)
339
	public ResponseEntity<?> processInvestmentDryRun(HttpServletRequest request, Model model) throws Exception {
336
	public ResponseEntity<?> processInvestmentDryRun(HttpServletRequest request, Model model) throws Exception {
340
 
337
 
341
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
338
		LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
342
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
339
		LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);