| Line 36... |
Line 36... |
| 36 |
public void payMonthlyInvestment() {
|
36 |
public void payMonthlyInvestment() {
|
| 37 |
LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
|
37 |
LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
|
| 38 |
LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
|
38 |
LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
|
| 39 |
LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
|
39 |
LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
|
| 40 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
|
40 |
List<PartnerDailyInvestment> partnerDailyInvestments = partnerDailyInvestmentRepository.selectAll(startOfPreviousMonth, lastOfPreviousMonth);
|
| 41 |
Map<Integer, Long> investmentShortDaysMap = partnerDailyInvestments.stream().filter(x->x.getShortPercentage() > 10).collect(Collectors.groupingBy(x->x.getFofoId(), Collectors.counting()));
|
41 |
Map<Integer, Long> investmentMaintainedDaysMap = partnerDailyInvestments.stream().filter(x->x.getShortPercentage() <= 10).collect(Collectors.groupingBy(x->x.getFofoId(), Collectors.counting()));
|
| 42 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT, startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
|
42 |
List<SchemeInOut> schemeInOuts = schemeInOutRepository.selectAllPending(SchemeType.INVESTMENT, startOfPreviousMonth.atStartOfDay(), firstDateOfCurrentMonth.atStartOfDay());
|
| 43 |
Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream().collect(Collectors.groupingBy(x->x.getInventoryItemId()));
|
43 |
Map<Integer, List<SchemeInOut>> inventoryItemIdSchemeMap = schemeInOuts.stream().collect(Collectors.groupingBy(x->x.getInventoryItemId()));
|
| 44 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
|
44 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
|
| 45 |
Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream()
|
45 |
Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream()
|
| 46 |
.collect(Collectors.groupingBy(x->x.getFofoId(), Collectors.mapping(x->x.getId(), Collectors.toList())));
|
46 |
.collect(Collectors.groupingBy(x->x.getFofoId(), Collectors.mapping(x->x.getId(), Collectors.toList())));
|
| 47 |
System.out.println("fofoId\tInvestment Short Days\tEligible payout");
|
47 |
System.out.println("fofoId\tInvestment Short Days\tEligible payout");
|
| 48 |
for(Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
|
48 |
for(Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
|
| 49 |
int fofoId = retailerEntry.getKey();
|
49 |
int fofoId = retailerEntry.getKey();
|
| 50 |
List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x->inventoryItemIdSchemeMap.get(x)).flatMap(List::stream).collect(Collectors.toList());
|
50 |
List<SchemeInOut> schemeInouts = retailerEntry.getValue().stream().map(x->inventoryItemIdSchemeMap.get(x)).flatMap(List::stream).collect(Collectors.toList());
|
| 51 |
double totalAmount = schemeInouts.stream().filter(x->x.getRolledBackTimestamp()!=null).collect(Collectors.summingDouble(x->x.getAmount()));
|
51 |
double totalAmount = schemeInouts.stream().filter(x->x.getRolledBackTimestamp()!=null).collect(Collectors.summingDouble(x->x.getAmount()));
|
| 52 |
long daysShort = investmentShortDaysMap.get(fofoId);
|
52 |
long investmentMaintainedDays = investmentMaintainedDaysMap.get(fofoId);
|
| 53 |
if(daysShort >= 12) {
|
53 |
if(investmentMaintainedDays < 12) {
|
| 54 |
totalAmount = 0;
|
- |
|
| 55 |
//do nothing
|
- |
|
| 56 |
} else if(daysShort >= 8) {
|
- |
|
| 57 |
totalAmount = totalAmount/2;
|
54 |
totalAmount = totalAmount/2;
|
| - |
|
55 |
} else if(investmentMaintainedDays < 8) {
|
| - |
|
56 |
totalAmount = 0;
|
| 58 |
}
|
57 |
}
|
| 59 |
System.out.printf("%d\t%d\t%f%n", fofoId, daysShort, totalAmount);
|
58 |
System.out.printf("%d\t%d\t%f%n", fofoId, investmentMaintainedDays, totalAmount);
|
| 60 |
}
|
59 |
}
|
| 61 |
}
|
60 |
}
|
| 62 |
}
|
61 |
}
|
| 63 |
|
62 |
|