| 34306 |
ranu |
1 |
package com.smartdukaan.cron.scheduled;
|
|
|
2 |
|
|
|
3 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
4 |
import com.spice.profitmandi.dao.entity.transaction.Loan;
|
|
|
5 |
import com.spice.profitmandi.dao.entity.transaction.Transaction;
|
|
|
6 |
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
|
|
|
7 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
|
|
8 |
import org.apache.logging.log4j.LogManager;
|
|
|
9 |
import org.apache.logging.log4j.Logger;
|
|
|
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
12 |
import org.springframework.stereotype.Component;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
|
|
|
15 |
import java.time.LocalDateTime;
|
|
|
16 |
import java.time.temporal.ChronoUnit;
|
|
|
17 |
import java.util.*;
|
|
|
18 |
|
|
|
19 |
@Component
|
|
|
20 |
@Transactional(rollbackFor = {Throwable.class, ProfitMandiBusinessException.class})
|
|
|
21 |
public class ScheduledTasksTest {
|
|
|
22 |
|
|
|
23 |
private static final Logger LOGGER = LogManager.getLogger(ScheduledTasksTest.class);
|
|
|
24 |
|
|
|
25 |
@Autowired
|
|
|
26 |
TransactionRepository transactionRepository;
|
|
|
27 |
|
|
|
28 |
@Autowired
|
|
|
29 |
LoanRepository loanRepository;
|
|
|
30 |
|
|
|
31 |
public void test() throws Exception {
|
|
|
32 |
System.out.println("test start");
|
|
|
33 |
this.findLoanTransactionMapingAccordingLoan();
|
|
|
34 |
System.out.println("test end");
|
|
|
35 |
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
public Map<Integer,Integer> findLoanTransactionMapingAccordingLoan() throws ProfitMandiBusinessException {
|
|
|
41 |
List<Integer> loanIds = new ArrayList<>(Arrays.asList(34833,36536,37151,37489,37502,37970,37997,38012));
|
|
|
42 |
|
|
|
43 |
Map<Integer, Integer> transactionLoanMap = new HashMap<>();
|
|
|
44 |
|
|
|
45 |
for(int loanId : loanIds){
|
|
|
46 |
Transaction transaction = null;
|
|
|
47 |
Loan loan = loanRepository.selectByLoanId(loanId);
|
|
|
48 |
List<Transaction> transactions = transactionRepository.selectByRetailerId(loan.getFofoId());
|
|
|
49 |
|
|
|
50 |
LocalDateTime nearestDateTime = transactions.stream().map(x -> x.getCreateTimestamp())
|
|
|
51 |
.min(Comparator.comparingLong(x -> Math.abs(ChronoUnit.MILLIS.between(x, loan.getCreatedOn()))))
|
|
|
52 |
.orElse(null);
|
|
|
53 |
|
|
|
54 |
if (nearestDateTime != null && loan.getCreatedOn().plusMinutes(2).isAfter(nearestDateTime) &&
|
|
|
55 |
loan.getCreatedOn().minusMinutes(1).isBefore(nearestDateTime)) {
|
|
|
56 |
// Here transaction is still null
|
|
|
57 |
transaction = transactions.stream()
|
|
|
58 |
.filter(x -> x.getCreateTimestamp().equals(nearestDateTime))
|
|
|
59 |
.findFirst().get();
|
|
|
60 |
transactionLoanMap.put(transaction.getId(), loanId);
|
|
|
61 |
}
|
|
|
62 |
|
|
|
63 |
}
|
|
|
64 |
LOGGER.info("transactionLoanMap {}",transactionLoanMap);
|
|
|
65 |
return transactionLoanMap;
|
|
|
66 |
}
|
|
|
67 |
}
|