| 27561 |
amit.gupta |
1 |
package com.smartdukaan.cron.scheduled;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDate;
|
|
|
4 |
import java.time.LocalDateTime;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Map;
|
|
|
7 |
import java.util.stream.Collectors;
|
|
|
8 |
|
|
|
9 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
10 |
import org.springframework.stereotype.Component;
|
|
|
11 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
12 |
|
|
|
13 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
|
|
14 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
|
|
15 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
|
|
16 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
|
|
17 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
|
|
18 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
|
|
19 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
|
|
20 |
import com.spice.profitmandi.service.user.RetailerService;;
|
|
|
21 |
|
|
|
22 |
@Component
|
|
|
23 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
24 |
public class InvestmentRelatedTasks {
|
|
|
25 |
@Autowired
|
|
|
26 |
RetailerService retailerService;
|
|
|
27 |
@Autowired
|
|
|
28 |
SchemeInOutRepository schemeInOutRepository;
|
|
|
29 |
|
|
|
30 |
@Autowired
|
|
|
31 |
InventoryItemRepository inventoryItemRepository;
|
|
|
32 |
|
|
|
33 |
@Autowired
|
|
|
34 |
PartnerDailyInvestmentRepository partnerDailyInvestmentRepository;
|
|
|
35 |
|
| 27565 |
amit.gupta |
36 |
public void payMonthlyInvestment() {
|
| 27561 |
amit.gupta |
37 |
LocalDate firstDateOfCurrentMonth = LocalDateTime.now().withDayOfMonth(1).toLocalDate();
|
|
|
38 |
LocalDate startOfPreviousMonth = firstDateOfCurrentMonth.minusMonths(1);
|
|
|
39 |
LocalDate lastOfPreviousMonth = firstDateOfCurrentMonth.minusDays(1);
|
|
|
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()));
|
|
|
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()));
|
|
|
44 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectByIds(inventoryItemIdSchemeMap.keySet());
|
|
|
45 |
Map<Integer, List<Integer>> retailerInventoryItemIdMap = inventoryItems.stream()
|
|
|
46 |
.collect(Collectors.groupingBy(x->x.getFofoId(), Collectors.mapping(x->x.getId(), Collectors.toList())));
|
|
|
47 |
for(Map.Entry<Integer, List<Integer>> retailerEntry : retailerInventoryItemIdMap.entrySet()) {
|
|
|
48 |
int fofoId = retailerEntry.getKey();
|
|
|
49 |
System.out.print("fofoId\tInvestment Short Days\tEligible payout");
|
|
|
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()));
|
|
|
52 |
long daysShort = investmentShortDaysMap.get(fofoId);
|
|
|
53 |
if(daysShort >= 12) {
|
|
|
54 |
//do nothing
|
|
|
55 |
} else if(daysShort >= 8) {
|
|
|
56 |
totalAmount = totalAmount/2;
|
|
|
57 |
} else {
|
|
|
58 |
totalAmount = 0;
|
|
|
59 |
}
|
|
|
60 |
System.out.printf("%d\t%d\t%f%n", fofoId, daysShort, totalAmount);
|
|
|
61 |
}
|
|
|
62 |
}
|
|
|
63 |
}
|