| 23506 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.List;
|
|
|
5 |
|
|
|
6 |
import javax.servlet.http.HttpServletRequest;
|
| 23612 |
amit.gupta |
7 |
|
| 23568 |
govind |
8 |
import org.apache.logging.log4j.LogManager;
|
|
|
9 |
import org.apache.logging.log4j.Logger;
|
| 23506 |
amit.gupta |
10 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
11 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
12 |
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
13 |
import org.springframework.stereotype.Controller;
|
|
|
14 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
15 |
import org.springframework.ui.Model;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
18 |
|
|
|
19 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
|
|
20 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 23511 |
amit.gupta |
21 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 23506 |
amit.gupta |
22 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 23612 |
amit.gupta |
23 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 23511 |
amit.gupta |
24 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 23506 |
amit.gupta |
25 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 23612 |
amit.gupta |
26 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
27 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
| 23506 |
amit.gupta |
28 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
|
|
29 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
30 |
|
|
|
31 |
@Controller
|
| 23511 |
amit.gupta |
32 |
@Transactional(rollbackFor=Throwable.class)
|
| 23506 |
amit.gupta |
33 |
public class CronController {
|
|
|
34 |
|
|
|
35 |
@Autowired
|
|
|
36 |
PurchaseRepository purchaseRepository;
|
|
|
37 |
|
|
|
38 |
@Autowired
|
|
|
39 |
SchemeService schemeService;
|
|
|
40 |
|
|
|
41 |
@Autowired
|
| 23612 |
amit.gupta |
42 |
RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
43 |
|
|
|
44 |
@Autowired
|
| 23511 |
amit.gupta |
45 |
FofoOrderRepository fofoOrderRepository;
|
| 23530 |
ashik.ali |
46 |
|
|
|
47 |
@Autowired
|
| 23612 |
amit.gupta |
48 |
ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
49 |
|
|
|
50 |
@Autowired
|
|
|
51 |
OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
52 |
|
|
|
53 |
@Autowired
|
| 23530 |
ashik.ali |
54 |
private RestClient restClient;
|
| 23511 |
amit.gupta |
55 |
|
|
|
56 |
@Autowired
|
| 23506 |
amit.gupta |
57 |
private MVCResponseSender mvcResponseSender;
|
|
|
58 |
|
|
|
59 |
@Value("${prod}")
|
|
|
60 |
private boolean prod;
|
|
|
61 |
|
|
|
62 |
|
| 23612 |
amit.gupta |
63 |
private static final Logger LOGGER = LogManager.getLogger(CronController.class);
|
| 23506 |
amit.gupta |
64 |
|
|
|
65 |
@Scheduled(cron = "0 45 6 * * *")
|
|
|
66 |
public void executeJob() throws Exception {
|
|
|
67 |
if(prod) {
|
|
|
68 |
String uri = "/cron/process-schemes";
|
| 23530 |
ashik.ali |
69 |
restClient.get(SchemeType.HTTP, "localhost", 8080, uri, null);
|
| 23506 |
amit.gupta |
70 |
}
|
|
|
71 |
}
|
|
|
72 |
|
| 23612 |
amit.gupta |
73 |
/* @RequestMapping(value = "/cron/reconcile-recharge", method = RequestMethod.GET)
|
|
|
74 |
public String reconcileRecharge() {
|
|
|
75 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(18);
|
|
|
76 |
LocalDateTime toDate = LocalDateTime.now();
|
|
|
77 |
RechargeTransaction rt = new RechargeTransaction();
|
|
|
78 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository.selectAllBetweenTimestamp(fromDate, toDate);
|
|
|
79 |
for(RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
80 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
81 |
if(providerId==1) {
|
|
|
82 |
oxigenRechargeProviderService.doCheckStatusRequest(rechargeTransaction)
|
|
|
83 |
}
|
|
|
84 |
}
|
|
|
85 |
}*/
|
|
|
86 |
|
| 23506 |
amit.gupta |
87 |
@RequestMapping(value = "/cron/process-schemes", method = RequestMethod.GET)
|
| 23558 |
amit.gupta |
88 |
public String createScheme(HttpServletRequest request, Model model) throws Exception {
|
| 23564 |
amit.gupta |
89 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(15);
|
| 23506 |
amit.gupta |
90 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
|
|
91 |
List<Purchase> purchases = purchaseRepository.selectFromPurchaseCompleteDate(fromDate);
|
|
|
92 |
for (Purchase purchase : purchases) {
|
|
|
93 |
try {
|
|
|
94 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
95 |
} catch (Exception e) {
|
|
|
96 |
LOGGER.error("Error while processing purchase {} for scheme In ", purchase.getId());
|
|
|
97 |
e.printStackTrace();
|
|
|
98 |
|
|
|
99 |
}
|
|
|
100 |
}
|
| 23511 |
amit.gupta |
101 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(fromDate);
|
|
|
102 |
for (FofoOrder fofoOrder: fofoOrders) {
|
|
|
103 |
try {
|
|
|
104 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
105 |
} catch (Exception e) {
|
|
|
106 |
LOGGER.error("Error while processing sale order {} for scheme Out", fofoOrder.getId());
|
|
|
107 |
}
|
|
|
108 |
}
|
| 23506 |
amit.gupta |
109 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
110 |
return "response";
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
}
|