Subversion Repositories SmartDukaan

Rev

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

Rev 24244 Rev 24246
Line 328... Line 328...
328
	}
328
	}
329
 
329
 
330
	// Temporary Method
330
	// Temporary Method
331
	public void evaluateExcessSchemeOut() {
331
	public void evaluateExcessSchemeOut() {
332
		Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
332
		Map<Integer, String> userNameMap = retailerService.getAllFofoRetailerIdNameMap();
333
		Map<Integer, String> userEmailMap = retailerService.getAllFofoRetailerIdEmailIdMap();
-
 
334
		Map<Integer, Float> userAmountMap = new HashMap<>();
333
		Map<Integer, Float> userAmountMap = new HashMap<>();
335
		schemeRepository.selectAll().stream().forEach(x -> {
334
		schemeRepository.selectAll().stream().forEach(x -> {
336
			if (x.getAmountType().equals(AmountType.FIXED)) {
-
 
337
				List<SchemeInOut> sioList = schemeInOutRepository
335
			List<SchemeInOut> sioList = schemeInOutRepository
338
						.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
336
					.selectBySchemeIds(new HashSet<>(Arrays.asList(x.getId())));
339
				if (x.getActiveTimestamp() != null) {
337
			if (x.getActiveTimestamp() != null) {
340
					LocalDateTime endDateTime = x.getEndDateTime();
338
				LocalDateTime endDateTime = x.getEndDateTime();
341
					if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
339
				if (x.getExpireTimestamp() != null && x.getExpireTimestamp().isBefore(x.getEndDateTime())) {
342
						endDateTime = x.getExpireTimestamp();
340
					endDateTime = x.getExpireTimestamp();
343
					}
341
				}
344
					for (SchemeInOut sio : sioList) {
342
				for (SchemeInOut sio : sioList) {
345
						Optional<ScanRecord> record = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId()).stream().filter(y->y.getType().equals(ScanType.SALE)).findFirst();
343
					Optional<ScanRecord> record = scanRecordRepository.selectByInventoryItemId(sio.getInventoryItemId())
-
 
344
							.stream().filter(y -> y.getType().equals(ScanType.SALE)).findFirst();
346
						if(record.isPresent()) {
345
					if (record.isPresent()) {
347
							int fofoId = record.get().getFofoId();
346
						int fofoId = record.get().getFofoId();
348
							if (record.get().getCreateTimestamp().isAfter(endDateTime)
347
						if (record.get().getCreateTimestamp().isAfter(endDateTime)
349
									|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
348
								|| record.get().getCreateTimestamp().isBefore(x.getStartDateTime())) {
350
									if(!userAmountMap.containsKey(fofoId)) {
349
							if (!userAmountMap.containsKey(fofoId)) {
351
										userAmountMap.put(fofoId, 0f);
350
								userAmountMap.put(fofoId, 0f);
352
									}
-
 
353
								userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
-
 
354
								LOGGER.info("Scheme disbursed to user {}({}) for inventoryItem {} and scheme {} for amount {}", userNameMap.get(fofoId), userEmailMap.get(fofoId), 
-
 
355
										sio.getInventoryItemId(),
-
 
356
										sio.getSchemeId(), sio.getAmount());
-
 
357
							}
351
							}
-
 
352
							userAmountMap.put(fofoId, sio.getAmount() + userAmountMap.get(fofoId));
-
 
353
							LOGGER.info("Scheme disbursed to user {} for inventoryItem {} and scheme {} for amount {}",
-
 
354
									userNameMap.get(fofoId), sio.getInventoryItemId(), sio.getSchemeId(),
-
 
355
									sio.getAmount());
358
						}
356
						}
359
					}
357
					}
360
				}
358
				}
361
			}
359
			}
362
		});
360
		});
-
 
361
		userAmountMap.entrySet().stream()
363
		userAmountMap.entrySet().stream().forEach(x->LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.", 
362
				.forEach(x -> LOGGER.info("{} to be deducted from {}({}) for wrongly disbursed due to technical error.",
364
				x.getValue(), userNameMap.get(x.getKey()), userEmailMap.get(x.getKey())));
363
						x.getValue(), userNameMap.get(x.getKey())));
365
 
364
 
366
	}
365
	}
367
 
366
 
368
	public void processScheme() throws Exception {
367
	public void processScheme() throws Exception {
369
		LocalDateTime fromDate = LocalDateTime.now().minusDays(15);
368
		LocalDateTime fromDate = LocalDateTime.now().minusDays(35);
370
		LOGGER.info("Started execution at {}", LocalDateTime.now());
369
		LOGGER.info("Started execution at {}", LocalDateTime.now());
371
		List<Purchase> purchases = purchaseRepository.selectFromPurchaseCompleteDate(fromDate);
370
		List<Purchase> purchases = purchaseRepository.selectFromPurchaseCompleteDate(fromDate);
372
		for (Purchase purchase : purchases) {
371
		for (Purchase purchase : purchases) {
373
			try {
372
			try {
374
				schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
373
				schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());