| 23506 |
amit.gupta |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
| 23618 |
amit.gupta |
4 |
import java.time.temporal.ChronoUnit;
|
|
|
5 |
import java.util.Arrays;
|
|
|
6 |
import java.util.HashMap;
|
| 23506 |
amit.gupta |
7 |
import java.util.List;
|
| 23618 |
amit.gupta |
8 |
import java.util.Map;
|
| 23506 |
amit.gupta |
9 |
|
|
|
10 |
import javax.servlet.http.HttpServletRequest;
|
| 23612 |
amit.gupta |
11 |
|
| 23568 |
govind |
12 |
import org.apache.logging.log4j.LogManager;
|
|
|
13 |
import org.apache.logging.log4j.Logger;
|
| 23506 |
amit.gupta |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
16 |
import org.springframework.scheduling.annotation.Scheduled;
|
|
|
17 |
import org.springframework.stereotype.Controller;
|
|
|
18 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
19 |
import org.springframework.ui.Model;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
22 |
|
| 23618 |
amit.gupta |
23 |
import com.spice.profitmandi.common.enumuration.RechargeStatus;
|
| 23506 |
amit.gupta |
24 |
import com.spice.profitmandi.common.enumuration.SchemeType;
|
| 23618 |
amit.gupta |
25 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 23506 |
amit.gupta |
26 |
import com.spice.profitmandi.common.web.client.RestClient;
|
| 23618 |
amit.gupta |
27 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 23511 |
amit.gupta |
28 |
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
|
| 23506 |
amit.gupta |
29 |
import com.spice.profitmandi.dao.entity.fofo.Purchase;
|
| 23612 |
amit.gupta |
30 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 23511 |
amit.gupta |
31 |
import com.spice.profitmandi.dao.repository.fofo.FofoOrderRepository;
|
| 23506 |
amit.gupta |
32 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 23612 |
amit.gupta |
33 |
import com.spice.profitmandi.service.recharge.provider.OxigenRechargeProviderService;
|
|
|
34 |
import com.spice.profitmandi.service.recharge.provider.ThinkWalnutDigitalRechargeProviderService;
|
| 23506 |
amit.gupta |
35 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
|
|
36 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
37 |
|
|
|
38 |
@Controller
|
| 23511 |
amit.gupta |
39 |
@Transactional(rollbackFor=Throwable.class)
|
| 23506 |
amit.gupta |
40 |
public class CronController {
|
| 23618 |
amit.gupta |
41 |
|
|
|
42 |
@Value("${oxigen.recharge.enquiry.url}")
|
|
|
43 |
private String oxigenRechargeEnquiryUrl;
|
|
|
44 |
|
|
|
45 |
@Value("${oxigen.recharge.auth.key}")
|
|
|
46 |
private String oxigenRechargeAuthKey;
|
|
|
47 |
|
|
|
48 |
@Value("${oxigen.recharge.validation.url}")
|
|
|
49 |
private String oxigenRechargeValidationUrl;
|
|
|
50 |
|
|
|
51 |
@Value("${oxigen.recharge.validation.auth.key}")
|
|
|
52 |
private String oxigenRechargeValidationAuthKey;
|
|
|
53 |
|
|
|
54 |
@Value("${think.walnut.digital.recharge.transaction.mobile.url}")
|
|
|
55 |
private String thinkWalnutDigitalRechargeTransactionMobileUrl;
|
|
|
56 |
|
|
|
57 |
@Value("${think.walnut.digital.recharge.transaction.mobile.username}")
|
|
|
58 |
private String thinkWalnutDigitalRechargeTransactionMobileUserName;
|
|
|
59 |
|
|
|
60 |
@Value("${think.walnut.digital.recharge.transaction.mobile.password}")
|
|
|
61 |
private String thinkWalnutDigitalRechargeTransactionMobilePassword;
|
|
|
62 |
|
|
|
63 |
@Value("${think.walnut.digital.recharge.transaction.dth.url}")
|
|
|
64 |
private String thinkWalnutDigitalRechargeTransactionDthUrl;
|
|
|
65 |
|
|
|
66 |
@Value("${think.walnut.digital.recharge.transaction.dth.username}")
|
|
|
67 |
private String thinkWalnutDigitalRechargeTransactionDthUserName;
|
|
|
68 |
|
|
|
69 |
@Value("${think.walnut.digital.recharge.transaction.dth.password}")
|
|
|
70 |
private String thinkWalnutDigitalRechargeTransactionDthPassword;
|
|
|
71 |
|
|
|
72 |
@Value("${think.walnut.digital.recharge.enquiry.url}")
|
|
|
73 |
private String thinkWalnutDigitalRechargeEnquiryUrl;
|
|
|
74 |
|
|
|
75 |
@Value("${think.walnut.digital.recharge.enquiry.username}")
|
|
|
76 |
private String thinkWalnutDigitalRechargeEnquiryUserName;
|
|
|
77 |
|
|
|
78 |
@Value("${think.walnut.digital.recharge.enquiry.password}")
|
|
|
79 |
private String thinkWalnutDigitalRechargeEnquiryPassword;
|
|
|
80 |
|
|
|
81 |
@Value("${think.walnut.digital.recharge.auth.key}")
|
|
|
82 |
private String thinkWalnutDigitalRechargeAuthKey;
|
| 23506 |
amit.gupta |
83 |
|
|
|
84 |
@Autowired
|
|
|
85 |
PurchaseRepository purchaseRepository;
|
|
|
86 |
|
|
|
87 |
@Autowired
|
|
|
88 |
SchemeService schemeService;
|
|
|
89 |
|
|
|
90 |
@Autowired
|
| 23612 |
amit.gupta |
91 |
RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
92 |
|
|
|
93 |
@Autowired
|
| 23511 |
amit.gupta |
94 |
FofoOrderRepository fofoOrderRepository;
|
| 23530 |
ashik.ali |
95 |
|
|
|
96 |
@Autowired
|
| 23612 |
amit.gupta |
97 |
ThinkWalnutDigitalRechargeProviderService thinkWalnutDigitalRechargeProviderService;
|
|
|
98 |
|
|
|
99 |
@Autowired
|
|
|
100 |
OxigenRechargeProviderService oxigenRechargeProviderService;
|
|
|
101 |
|
|
|
102 |
@Autowired
|
| 23530 |
ashik.ali |
103 |
private RestClient restClient;
|
| 23511 |
amit.gupta |
104 |
|
|
|
105 |
@Autowired
|
| 23506 |
amit.gupta |
106 |
private MVCResponseSender mvcResponseSender;
|
|
|
107 |
|
|
|
108 |
@Value("${prod}")
|
|
|
109 |
private boolean prod;
|
|
|
110 |
|
|
|
111 |
|
| 23612 |
amit.gupta |
112 |
private static final Logger LOGGER = LogManager.getLogger(CronController.class);
|
| 23506 |
amit.gupta |
113 |
|
|
|
114 |
@Scheduled(cron = "0 45 6 * * *")
|
|
|
115 |
public void executeJob() throws Exception {
|
|
|
116 |
if(prod) {
|
|
|
117 |
String uri = "/cron/process-schemes";
|
| 23530 |
ashik.ali |
118 |
restClient.get(SchemeType.HTTP, "localhost", 8080, uri, null);
|
| 23506 |
amit.gupta |
119 |
}
|
|
|
120 |
}
|
|
|
121 |
|
| 23618 |
amit.gupta |
122 |
@RequestMapping(value = "/cron/reconcile-recharge", method = RequestMethod.GET)
|
|
|
123 |
public String reconcileRecharge(Model model) throws Exception {
|
|
|
124 |
LocalDateTime fromDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS).minusDays(30);
|
|
|
125 |
LocalDateTime toDate = LocalDateTime.now().truncatedTo(ChronoUnit.DAYS);
|
| 23612 |
amit.gupta |
126 |
RechargeTransaction rt = new RechargeTransaction();
|
| 23618 |
amit.gupta |
127 |
List<RechargeStatus> nonSuccessRechargeStatuses = Arrays.asList(RechargeStatus.values());
|
|
|
128 |
nonSuccessRechargeStatuses.remove(RechargeStatus.SUCCESS);
|
|
|
129 |
nonSuccessRechargeStatuses.remove(RechargeStatus.FAILED);
|
|
|
130 |
RechargeCredential thinkWalnutDigitalRechargeEnquiryCredential = new RechargeCredential();
|
|
|
131 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUrl(thinkWalnutDigitalRechargeEnquiryUrl);
|
|
|
132 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeUserName(thinkWalnutDigitalRechargeEnquiryUserName);
|
|
|
133 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargePassword(thinkWalnutDigitalRechargeEnquiryPassword);
|
|
|
134 |
thinkWalnutDigitalRechargeEnquiryCredential.setRechargeAuthKey(thinkWalnutDigitalRechargeAuthKey);
|
|
|
135 |
Map<String, RechargeStatus> requestRechargeStatusChanged = new HashMap<>();
|
|
|
136 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository.selectAllBetweenTimestamp(nonSuccessRechargeStatuses,fromDate, toDate);
|
| 23612 |
amit.gupta |
137 |
for(RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
138 |
int providerId = rechargeTransaction.getProviderId();
|
|
|
139 |
if(providerId==1) {
|
| 23618 |
amit.gupta |
140 |
oxigenRechargeProviderService.doCheckStatusRequest(oxigenRechargeEnquiryUrl, oxigenRechargeAuthKey, rechargeTransaction);
|
|
|
141 |
} else if(providerId==2) {
|
|
|
142 |
thinkWalnutDigitalRechargeProviderService.doCheckStatusRequest(thinkWalnutDigitalRechargeEnquiryCredential, rechargeTransaction);
|
| 23612 |
amit.gupta |
143 |
}
|
| 23618 |
amit.gupta |
144 |
if(rechargeTransaction.getStatus().equals(RechargeStatus.SUCCESS) || rechargeTransaction.getStatus().equals(RechargeStatus.FAILED)) {
|
|
|
145 |
requestRechargeStatusChanged.put(rechargeTransaction.getRequestId(), rechargeTransaction.getStatus());
|
|
|
146 |
}
|
| 23612 |
amit.gupta |
147 |
}
|
| 23618 |
amit.gupta |
148 |
model.addAttribute("response", mvcResponseSender.createResponseString(requestRechargeStatusChanged));
|
|
|
149 |
return "response";
|
|
|
150 |
}
|
| 23612 |
amit.gupta |
151 |
|
| 23506 |
amit.gupta |
152 |
@RequestMapping(value = "/cron/process-schemes", method = RequestMethod.GET)
|
| 23558 |
amit.gupta |
153 |
public String createScheme(HttpServletRequest request, Model model) throws Exception {
|
| 23564 |
amit.gupta |
154 |
LocalDateTime fromDate = LocalDateTime.now().minusDays(15);
|
| 23506 |
amit.gupta |
155 |
LOGGER.info("Started execution at {}", LocalDateTime.now());
|
|
|
156 |
List<Purchase> purchases = purchaseRepository.selectFromPurchaseCompleteDate(fromDate);
|
|
|
157 |
for (Purchase purchase : purchases) {
|
|
|
158 |
try {
|
|
|
159 |
schemeService.processSchemeIn(purchase.getId(), purchase.getFofoId());
|
|
|
160 |
} catch (Exception e) {
|
|
|
161 |
LOGGER.error("Error while processing purchase {} for scheme In ", purchase.getId());
|
|
|
162 |
e.printStackTrace();
|
|
|
163 |
|
|
|
164 |
}
|
|
|
165 |
}
|
| 23511 |
amit.gupta |
166 |
List<FofoOrder> fofoOrders = fofoOrderRepository.selectFromSaleDate(fromDate);
|
|
|
167 |
for (FofoOrder fofoOrder: fofoOrders) {
|
|
|
168 |
try {
|
|
|
169 |
schemeService.processSchemeOut(fofoOrder.getId(), fofoOrder.getFofoId());
|
|
|
170 |
} catch (Exception e) {
|
|
|
171 |
LOGGER.error("Error while processing sale order {} for scheme Out", fofoOrder.getId());
|
|
|
172 |
}
|
|
|
173 |
}
|
| 23506 |
amit.gupta |
174 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
175 |
return "response";
|
|
|
176 |
}
|
|
|
177 |
|
|
|
178 |
}
|