| 23505 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 23528 |
ashik.ali |
3 |
import java.util.ArrayList;
|
| 23505 |
ashik.ali |
4 |
import java.util.HashMap;
|
|
|
5 |
import java.util.HashSet;
|
|
|
6 |
import java.util.List;
|
|
|
7 |
import java.util.Map;
|
|
|
8 |
import java.util.Set;
|
|
|
9 |
|
|
|
10 |
import javax.servlet.http.HttpServletRequest;
|
|
|
11 |
|
| 23568 |
govind |
12 |
import org.apache.logging.log4j.Logger;
|
|
|
13 |
import org.apache.logging.log4j.LogManager;
|
| 23505 |
ashik.ali |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
15 |
import org.springframework.beans.factory.annotation.Value;
|
|
|
16 |
import org.springframework.stereotype.Controller;
|
|
|
17 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
18 |
import org.springframework.ui.Model;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
22 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
23 |
|
|
|
24 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
25 |
import com.spice.profitmandi.common.model.OperatorType;
|
|
|
26 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23528 |
ashik.ali |
27 |
import com.spice.profitmandi.common.model.RechargeCommissionRequest;
|
|
|
28 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 23505 |
ashik.ali |
29 |
import com.spice.profitmandi.common.model.RechargeRequest;
|
| 23528 |
ashik.ali |
30 |
import com.spice.profitmandi.dao.entity.dtr.RechargeCommission;
|
| 23505 |
ashik.ali |
31 |
import com.spice.profitmandi.dao.entity.dtr.RechargeOperator;
|
|
|
32 |
import com.spice.profitmandi.dao.entity.dtr.RechargeTransaction;
|
| 23548 |
ashik.ali |
33 |
import com.spice.profitmandi.dao.entity.fofo.PaymentOption;
|
| 23505 |
ashik.ali |
34 |
import com.spice.profitmandi.dao.enumuration.dtr.RechargeType;
|
| 23528 |
ashik.ali |
35 |
import com.spice.profitmandi.dao.repository.dtr.RechargeCommissionRepository;
|
| 23505 |
ashik.ali |
36 |
import com.spice.profitmandi.dao.repository.dtr.RechargeOperatorRepository;
|
|
|
37 |
import com.spice.profitmandi.dao.repository.dtr.RechargeTransactionRepository;
|
| 23548 |
ashik.ali |
38 |
import com.spice.profitmandi.dao.repository.fofo.FofoPartnerPaymentOptionRepository;
|
|
|
39 |
import com.spice.profitmandi.dao.repository.fofo.PaymentOptionRepository;
|
| 23505 |
ashik.ali |
40 |
import com.spice.profitmandi.service.recharge.RechargeService;
|
|
|
41 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
42 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
43 |
|
|
|
44 |
@Controller
|
|
|
45 |
@Transactional(rollbackFor=Throwable.class)
|
|
|
46 |
public class RechargeController {
|
|
|
47 |
|
| 23568 |
govind |
48 |
private static final Logger LOGGER = LogManager.getLogger(RechargeController.class);
|
| 23505 |
ashik.ali |
49 |
|
| 23559 |
ashik.ali |
50 |
@Value("${recharge.transaction.mobile.url}")
|
|
|
51 |
private String rechargeMobileUrl;
|
| 23528 |
ashik.ali |
52 |
|
| 23559 |
ashik.ali |
53 |
@Value("${recharge.transaction.mobile.username}")
|
|
|
54 |
private String rechargeMobileUserName;
|
| 23505 |
ashik.ali |
55 |
|
| 23559 |
ashik.ali |
56 |
@Value("${recharge.transaction.mobile.password}")
|
|
|
57 |
private String rechargeMobilePassword;
|
| 23528 |
ashik.ali |
58 |
|
| 23559 |
ashik.ali |
59 |
@Value("${recharge.transaction.dth.url}")
|
|
|
60 |
private String rechargeDthUrl;
|
| 23505 |
ashik.ali |
61 |
|
| 23559 |
ashik.ali |
62 |
@Value("${recharge.transaction.dth.username}")
|
|
|
63 |
private String rechargeDthUserName;
|
| 23528 |
ashik.ali |
64 |
|
| 23559 |
ashik.ali |
65 |
@Value("${recharge.transaction.dth.password}")
|
|
|
66 |
private String rechargeDthPassword;
|
| 23505 |
ashik.ali |
67 |
|
| 23559 |
ashik.ali |
68 |
@Value("${recharge.enquiry.url}")
|
|
|
69 |
private String rechargeEnquiryUrl;
|
| 23528 |
ashik.ali |
70 |
|
| 23559 |
ashik.ali |
71 |
@Value("${recharge.enquiry.username}")
|
|
|
72 |
private String rechargeEnquiryUserName;
|
| 23528 |
ashik.ali |
73 |
|
| 23559 |
ashik.ali |
74 |
@Value("${recharge.enquiry.password}")
|
|
|
75 |
private String rechargeEnquiryPassword;
|
| 23528 |
ashik.ali |
76 |
|
| 23559 |
ashik.ali |
77 |
@Value("${recharge.auth.key}")
|
|
|
78 |
private String rechargeAuthKey;
|
| 23528 |
ashik.ali |
79 |
|
| 23559 |
ashik.ali |
80 |
@Value("${recharge.validation.url}")
|
|
|
81 |
private String rechargeValidationUrl;
|
|
|
82 |
|
| 23505 |
ashik.ali |
83 |
@Value("${recharge.validation.auth.key}")
|
|
|
84 |
private String rechargeValidationAuthKey;
|
|
|
85 |
|
|
|
86 |
@Autowired
|
|
|
87 |
private RechargeService rechargeService;
|
|
|
88 |
|
|
|
89 |
@Autowired
|
|
|
90 |
private RechargeOperatorRepository rechargeOperatorRepository;
|
|
|
91 |
|
|
|
92 |
@Autowired
|
|
|
93 |
private RechargeTransactionRepository rechargeTransactionRepository;
|
|
|
94 |
|
|
|
95 |
@Autowired
|
| 23528 |
ashik.ali |
96 |
private RechargeCommissionRepository rechargeCommissionRepository;
|
|
|
97 |
|
|
|
98 |
@Autowired
|
| 23548 |
ashik.ali |
99 |
private PaymentOptionRepository paymentOptionRepository;
|
|
|
100 |
|
|
|
101 |
@Autowired
|
|
|
102 |
private FofoPartnerPaymentOptionRepository fofoPartnerPaymentOptionRepository;
|
|
|
103 |
|
|
|
104 |
@Autowired
|
| 23505 |
ashik.ali |
105 |
private CookiesProcessor cookiesProcessor;
|
|
|
106 |
|
|
|
107 |
@RequestMapping(value = "/createRecharge", method = RequestMethod.GET)
|
| 23548 |
ashik.ali |
108 |
public String createRecharge(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.RECHARGE_TYPE) String rechargeTypeString, Model model) throws ProfitMandiBusinessException{
|
| 23505 |
ashik.ali |
109 |
//model.addAttribute("rechargeOperators", rechargeOperatorRepository.selectAllByRechargeType(RechargeType.MOBILE));
|
|
|
110 |
//model.addAttribute("rechargeTypes", RechargeType.values());
|
| 23548 |
ashik.ali |
111 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23505 |
ashik.ali |
112 |
RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
113 |
List<RechargeOperator> rechargeOperators = null;
|
|
|
114 |
if(rechargeType == RechargeType.MOBILE) {
|
|
|
115 |
model.addAttribute("operatorTypes", OperatorType.values());
|
|
|
116 |
rechargeOperators = rechargeOperatorRepository.selectAllByOperatorType(OperatorType.PREPAID);
|
|
|
117 |
}else {
|
|
|
118 |
rechargeOperators = rechargeOperatorRepository.selectAllByRechargeType(rechargeType);
|
|
|
119 |
}
|
| 23548 |
ashik.ali |
120 |
|
|
|
121 |
List<Integer> paymentOptionIds = fofoPartnerPaymentOptionRepository.selectPaymentOptionIdsByFofoId(loginDetails.getFofoId());
|
|
|
122 |
List<PaymentOption> paymentOptions = paymentOptionRepository.selectByIds(new HashSet<>(paymentOptionIds));
|
|
|
123 |
model.addAttribute("paymentOptions", paymentOptions);
|
| 23505 |
ashik.ali |
124 |
model.addAttribute("rechargeOperators", rechargeOperators);
|
|
|
125 |
return "create-recharge";
|
|
|
126 |
}
|
|
|
127 |
|
| 23528 |
ashik.ali |
128 |
private Map<Integer, String> rechargeTransactionsToRechargeOperatorIdNameMap(List<RechargeTransaction> rechargeTransactions){
|
| 23505 |
ashik.ali |
129 |
Map<Integer, String> rechargeOperatorIdrechargeOperatorNameMap = new HashMap<>();
|
|
|
130 |
if(rechargeTransactions.isEmpty()) {
|
|
|
131 |
return rechargeOperatorIdrechargeOperatorNameMap;
|
|
|
132 |
}
|
|
|
133 |
Set<Integer> operatorIds = new HashSet<>();
|
|
|
134 |
for(RechargeTransaction rechargeTransaction : rechargeTransactions) {
|
|
|
135 |
operatorIds.add(rechargeTransaction.getOperatorId());
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByIds(operatorIds);
|
|
|
139 |
for(RechargeOperator rechargeOperator : rechargeOperators) {
|
|
|
140 |
rechargeOperatorIdrechargeOperatorNameMap.put(rechargeOperator.getId(), rechargeOperator.getName());
|
|
|
141 |
}
|
|
|
142 |
return rechargeOperatorIdrechargeOperatorNameMap;
|
|
|
143 |
}
|
|
|
144 |
|
| 23528 |
ashik.ali |
145 |
private Map<Integer, RechargeOperator> rechargeCommissionsOperatorIdRechargeOperatorMap(List<RechargeCommission> rechargeCommissions){
|
|
|
146 |
Map<Integer, RechargeOperator> rechargeOperatorIdNameMap = new HashMap<>();
|
|
|
147 |
if(rechargeCommissions.isEmpty()) {
|
|
|
148 |
return rechargeOperatorIdNameMap;
|
|
|
149 |
}
|
|
|
150 |
Set<Integer> operatorIds = new HashSet<>();
|
|
|
151 |
for(RechargeCommission rechargeCommission : rechargeCommissions) {
|
|
|
152 |
operatorIds.add(rechargeCommission.getOperatorId());
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByIds(operatorIds);
|
|
|
156 |
for(RechargeOperator rechargeOperator : rechargeOperators) {
|
|
|
157 |
rechargeOperatorIdNameMap.put(rechargeOperator.getId(), rechargeOperator);
|
|
|
158 |
}
|
|
|
159 |
return rechargeOperatorIdNameMap;
|
|
|
160 |
}
|
|
|
161 |
|
| 23505 |
ashik.ali |
162 |
@RequestMapping(value = "/createRecharge", method = RequestMethod.POST)
|
|
|
163 |
public String createRecharge(HttpServletRequest request, @RequestBody RechargeRequest rechargeRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 23528 |
ashik.ali |
164 |
LOGGER.info("Recharge request body {}", rechargeRequest);
|
| 23505 |
ashik.ali |
165 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23559 |
ashik.ali |
166 |
RechargeCredential rechargeTransactionMobileCredential = new RechargeCredential();
|
|
|
167 |
rechargeTransactionMobileCredential.setRechargeUrl(rechargeMobileUrl);
|
|
|
168 |
rechargeTransactionMobileCredential.setRechargeUserName(rechargeMobileUserName);
|
|
|
169 |
rechargeTransactionMobileCredential.setRechargePassword(rechargeMobilePassword);
|
|
|
170 |
rechargeTransactionMobileCredential.setRechargeAuthKey(rechargeAuthKey);
|
| 23528 |
ashik.ali |
171 |
|
| 23559 |
ashik.ali |
172 |
RechargeCredential rechargeTransactionDthCredential = new RechargeCredential();
|
|
|
173 |
rechargeTransactionDthCredential.setRechargeUrl(rechargeDthUrl);
|
|
|
174 |
rechargeTransactionDthCredential.setRechargeUserName(rechargeDthUserName);
|
|
|
175 |
rechargeTransactionDthCredential.setRechargePassword(rechargeDthPassword);
|
|
|
176 |
rechargeTransactionDthCredential.setRechargeAuthKey(rechargeAuthKey);
|
| 23528 |
ashik.ali |
177 |
|
| 23559 |
ashik.ali |
178 |
rechargeService.doRecharge(rechargeTransactionMobileCredential, rechargeTransactionDthCredential, rechargeValidationUrl, rechargeValidationAuthKey, loginDetails.getFofoId(), rechargeRequest);
|
| 23505 |
ashik.ali |
179 |
RechargeType rechargeType = RechargeType.valueOf(rechargeRequest.getRechargeType());
|
|
|
180 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository.selectAllByRetailerIdAndType(loginDetails.getFofoId(), rechargeType, offset, limit);
|
|
|
181 |
long size = rechargeTransactionRepository.selectCountByRetailerIdAndType(loginDetails.getFofoId(), rechargeType);
|
| 23528 |
ashik.ali |
182 |
Map<Integer, String> rechargeOperatorIdRechargeOperatorNameMap = this.rechargeTransactionsToRechargeOperatorIdNameMap(rechargeTransactions);
|
| 23505 |
ashik.ali |
183 |
model.addAttribute("rechargeTransactions", rechargeTransactions);
|
|
|
184 |
model.addAttribute("rechargeOperatorIdRechargeOperatorNameMap", rechargeOperatorIdRechargeOperatorNameMap);
|
|
|
185 |
model.addAttribute("start", offset + 1);
|
|
|
186 |
model.addAttribute("size", size);
|
|
|
187 |
if (rechargeTransactions.size() < limit){
|
|
|
188 |
model.addAttribute("end", offset + rechargeTransactions.size());
|
|
|
189 |
}else{
|
|
|
190 |
model.addAttribute("end", offset + limit);
|
|
|
191 |
}
|
|
|
192 |
if(RechargeType.valueOf(rechargeRequest.getRechargeType()) == RechargeType.MOBILE) {
|
|
|
193 |
return "mobile-recharges";
|
|
|
194 |
}else {
|
|
|
195 |
return "dth-recharges";
|
|
|
196 |
}
|
|
|
197 |
}
|
|
|
198 |
|
|
|
199 |
@RequestMapping(value = "/checkStatus", method = RequestMethod.GET)
|
|
|
200 |
public String checkStatus(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.REQUEST_ID) String requestId, @RequestParam(name = ProfitMandiConstants.RECHARGE_TYPE) String rechargeTypeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
201 |
LOGGER.info("RequestId [{}], rechargeType [{}]", requestId, rechargeTypeString);
|
|
|
202 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 23559 |
ashik.ali |
203 |
RechargeCredential rechargeTransactionEnquiryCredential = new RechargeCredential();
|
|
|
204 |
rechargeTransactionEnquiryCredential.setRechargeUrl(rechargeEnquiryUrl);
|
|
|
205 |
rechargeTransactionEnquiryCredential.setRechargeUserName(rechargeEnquiryUserName);
|
|
|
206 |
rechargeTransactionEnquiryCredential.setRechargePassword(rechargeEnquiryPassword);
|
|
|
207 |
rechargeTransactionEnquiryCredential.setRechargeAuthKey(rechargeAuthKey);
|
|
|
208 |
rechargeService.checkStatus(rechargeTransactionEnquiryCredential, loginDetails.getFofoId(), requestId);
|
| 23505 |
ashik.ali |
209 |
RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
210 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository.selectAllByRetailerIdAndType(loginDetails.getFofoId(), rechargeType, offset, limit);
|
|
|
211 |
//long size = rechargeTransactionRepository.selectCountByRetailerId(loginDetails.getFofoId());
|
| 23528 |
ashik.ali |
212 |
Map<Integer, String> rechargeOperatorIdRechargeOperatorNameMap = this.rechargeTransactionsToRechargeOperatorIdNameMap(rechargeTransactions);
|
| 23505 |
ashik.ali |
213 |
model.addAttribute("rechargeTransactions", rechargeTransactions);
|
|
|
214 |
model.addAttribute("rechargeOperatorIdRechargeOperatorNameMap", rechargeOperatorIdRechargeOperatorNameMap);
|
|
|
215 |
|
|
|
216 |
if(RechargeType.valueOf(rechargeTypeString) == RechargeType.MOBILE) {
|
|
|
217 |
return "mobile-recharges-paginated";
|
|
|
218 |
}else {
|
|
|
219 |
return "dth-recharges-paginated";
|
|
|
220 |
}
|
|
|
221 |
}
|
|
|
222 |
|
|
|
223 |
@RequestMapping(value = "/getRecharges", method = RequestMethod.GET)
|
|
|
224 |
public String getRecharges(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.RECHARGE_TYPE) String rechargeTypeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
225 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
226 |
RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
227 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository.selectAllByRetailerIdAndType(loginDetails.getFofoId(), rechargeType, offset, limit);
|
|
|
228 |
long size = rechargeTransactionRepository.selectCountByRetailerIdAndType(loginDetails.getFofoId(), rechargeType);
|
| 23528 |
ashik.ali |
229 |
Map<Integer, String> rechargeOperatorIdRechargeOperatorNameMap = this.rechargeTransactionsToRechargeOperatorIdNameMap(rechargeTransactions);
|
| 23505 |
ashik.ali |
230 |
model.addAttribute("rechargeTransactions", rechargeTransactions);
|
|
|
231 |
model.addAttribute("rechargeOperatorIdRechargeOperatorNameMap", rechargeOperatorIdRechargeOperatorNameMap);
|
|
|
232 |
model.addAttribute("start", offset + 1);
|
|
|
233 |
model.addAttribute("size", size);
|
|
|
234 |
if (rechargeTransactions.size() < limit){
|
|
|
235 |
model.addAttribute("end", offset + rechargeTransactions.size());
|
|
|
236 |
}else{
|
|
|
237 |
model.addAttribute("end", offset + limit);
|
|
|
238 |
}
|
|
|
239 |
if(RechargeType.valueOf(rechargeTypeString) == RechargeType.MOBILE) {
|
|
|
240 |
return "mobile-recharges";
|
|
|
241 |
}else {
|
|
|
242 |
return "dth-recharges";
|
|
|
243 |
}
|
|
|
244 |
}
|
|
|
245 |
|
|
|
246 |
@RequestMapping(value = "/getPaginatedRecharges", method = RequestMethod.GET)
|
|
|
247 |
public String getPaginatedRecharges(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.RECHARGE_TYPE) String rechargeTypeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
248 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
249 |
RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
250 |
List<RechargeTransaction> rechargeTransactions = rechargeTransactionRepository.selectAllByRetailerIdAndType(loginDetails.getFofoId(), rechargeType, offset, limit);
|
| 23528 |
ashik.ali |
251 |
Map<Integer, String> rechargeOperatorIdRechargeOperatorNameMap = this.rechargeTransactionsToRechargeOperatorIdNameMap(rechargeTransactions);
|
| 23505 |
ashik.ali |
252 |
model.addAttribute("rechargeTransactions", rechargeTransactions);
|
|
|
253 |
model.addAttribute("rechargeOperatorIdRechargeOperatorNameMap", rechargeOperatorIdRechargeOperatorNameMap);
|
|
|
254 |
if(RechargeType.valueOf(rechargeTypeString) == RechargeType.MOBILE) {
|
|
|
255 |
return "mobile-recharges-paginated";
|
|
|
256 |
}else {
|
|
|
257 |
return "dth-recharges-paginated";
|
|
|
258 |
}
|
|
|
259 |
}
|
|
|
260 |
|
| 23528 |
ashik.ali |
261 |
@RequestMapping(value = "/getRechargeOperators", method = RequestMethod.GET)
|
|
|
262 |
public String getRechargeOperators(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.OPERATOR_TYPE) String operatorTypeString, Model model){
|
| 23505 |
ashik.ali |
263 |
//model.addAttribute("rechargeOperators", rechargeOperatorRepository.selectAllByRechargeType(RechargeType.MOBILE));
|
|
|
264 |
//model.addAttribute("rechargeTypes", RechargeType.values());
|
|
|
265 |
OperatorType operatorType = OperatorType.valueOf(operatorTypeString);
|
|
|
266 |
List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByOperatorType(operatorType);
|
|
|
267 |
model.addAttribute("rechargeOperators", rechargeOperators);
|
|
|
268 |
return "recharge-operators";
|
|
|
269 |
}
|
|
|
270 |
|
| 23528 |
ashik.ali |
271 |
@RequestMapping(value = "/getRechargeCommissionOperators", method = RequestMethod.GET)
|
|
|
272 |
public String getRechargeCommissionOperators(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.OPERATOR_TYPE) String operatorTypeString, Model model) throws ProfitMandiBusinessException{
|
|
|
273 |
//model.addAttribute("rechargeOperators", rechargeOperatorRepository.selectAllByRechargeType(RechargeType.MOBILE));
|
|
|
274 |
//model.addAttribute("rechargeTypes", RechargeType.values());
|
|
|
275 |
OperatorType operatorType = OperatorType.valueOf(operatorTypeString);
|
|
|
276 |
List<RechargeOperator> rechargeOperators = rechargeOperatorRepository.selectAllByOperatorType(operatorType);
|
|
|
277 |
List<Integer> rechargeOperatorIds = rechargeCommissionRepository.selectAllOperatorIds();
|
|
|
278 |
if(!rechargeOperatorIds.isEmpty()) {
|
|
|
279 |
rechargeOperators = this.filterRechargeOperators(rechargeOperators, rechargeOperatorIds);
|
|
|
280 |
if(rechargeOperators.isEmpty()) {
|
|
|
281 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.OPERATOR_TYPE, operatorType, "RCHRG_1003");
|
|
|
282 |
}
|
|
|
283 |
}
|
|
|
284 |
model.addAttribute("rechargeOperators", rechargeOperators);
|
|
|
285 |
return "recharge-operators";
|
|
|
286 |
}
|
| 23505 |
ashik.ali |
287 |
|
| 23528 |
ashik.ali |
288 |
@RequestMapping(value = "/createRechargeCommission", method = RequestMethod.GET)
|
|
|
289 |
public String createRechargeCommission(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.RECHARGE_TYPE) String rechargeTypeString, Model model) throws ProfitMandiBusinessException{
|
|
|
290 |
//model.addAttribute("rechargeOperators", rechargeOperatorRepository.selectAllByRechargeType(RechargeType.MOBILE));
|
|
|
291 |
//model.addAttribute("rechargeTypes", RechargeType.values());
|
|
|
292 |
|
|
|
293 |
RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
294 |
List<RechargeOperator> rechargeOperators = null;
|
|
|
295 |
if(rechargeType == RechargeType.MOBILE) {
|
|
|
296 |
model.addAttribute("operatorTypes", OperatorType.values());
|
|
|
297 |
rechargeOperators = rechargeOperatorRepository.selectAllByOperatorType(OperatorType.PREPAID);
|
|
|
298 |
}else {
|
|
|
299 |
rechargeOperators = rechargeOperatorRepository.selectAllByRechargeType(rechargeType);
|
|
|
300 |
}
|
|
|
301 |
List<Integer> rechargeOperatorIds = rechargeCommissionRepository.selectAllOperatorIds();
|
|
|
302 |
if(!rechargeOperatorIds.isEmpty()) {
|
|
|
303 |
rechargeOperators = this.filterRechargeOperators(rechargeOperators, rechargeOperatorIds);
|
|
|
304 |
if(rechargeOperators.isEmpty()) {
|
|
|
305 |
throw new ProfitMandiBusinessException(ProfitMandiConstants.RECHARGE_TYPE, rechargeType, "RCHRG_1003");
|
|
|
306 |
}
|
|
|
307 |
}
|
|
|
308 |
model.addAttribute("rechargeOperators", rechargeOperators);
|
|
|
309 |
return "create-recharge-commission";
|
|
|
310 |
}
|
|
|
311 |
|
|
|
312 |
private List<RechargeOperator> filterRechargeOperators(List<RechargeOperator> rechargeOperators, List<Integer> rechargeOperatorIds){
|
|
|
313 |
List<RechargeOperator> filteredRechargeOperators = new ArrayList<>();
|
|
|
314 |
for(RechargeOperator rechargeOperator : rechargeOperators) {
|
|
|
315 |
if(!rechargeOperatorIds.contains(rechargeOperator.getId())) {
|
|
|
316 |
filteredRechargeOperators.add(rechargeOperator);
|
|
|
317 |
}
|
|
|
318 |
}
|
|
|
319 |
return filteredRechargeOperators;
|
|
|
320 |
}
|
|
|
321 |
|
|
|
322 |
@RequestMapping(value = "/createRechargeCommission", method = RequestMethod.POST)
|
|
|
323 |
public String createRechargeCommission(HttpServletRequest request, @RequestBody RechargeCommissionRequest rechargeCommissionRequest, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
324 |
rechargeService.createRechargeCommission(rechargeCommissionRequest);
|
|
|
325 |
List<RechargeCommission> rechargeCommissions = rechargeCommissionRepository.selectAllPaginated(offset, limit);
|
|
|
326 |
long size = rechargeCommissionRepository.selectAllCount();
|
|
|
327 |
Map<Integer, RechargeOperator> rechargeOperatorIdRechargeOperatorMap = this.rechargeCommissionsOperatorIdRechargeOperatorMap(rechargeCommissions);
|
|
|
328 |
model.addAttribute("rechargeCommissions", rechargeCommissions);
|
|
|
329 |
model.addAttribute("rechargeOperatorIdRechargeOperatorMap", rechargeOperatorIdRechargeOperatorMap);
|
|
|
330 |
model.addAttribute("start", offset + 1);
|
|
|
331 |
model.addAttribute("size", size);
|
|
|
332 |
if (rechargeCommissions.size() < limit){
|
|
|
333 |
model.addAttribute("end", offset + rechargeCommissions.size());
|
|
|
334 |
}else{
|
|
|
335 |
model.addAttribute("end", offset + limit);
|
|
|
336 |
}
|
|
|
337 |
return "recharge-commissions";
|
|
|
338 |
}
|
|
|
339 |
|
|
|
340 |
@RequestMapping(value = "/getRechargeCommissions", method = RequestMethod.GET)
|
|
|
341 |
public String getRechargeCommissions(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
342 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
343 |
//RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
344 |
List<RechargeCommission> rechargeCommissions = rechargeCommissionRepository.selectAllPaginated(offset, limit);
|
|
|
345 |
long size = rechargeCommissionRepository.selectAllCount();
|
|
|
346 |
Map<Integer, RechargeOperator> rechargeOperatorIdRechargeOperatorMap = this.rechargeCommissionsOperatorIdRechargeOperatorMap(rechargeCommissions);
|
|
|
347 |
model.addAttribute("rechargeCommissions", rechargeCommissions);
|
|
|
348 |
model.addAttribute("rechargeOperatorIdRechargeOperatorMap", rechargeOperatorIdRechargeOperatorMap);
|
|
|
349 |
model.addAttribute("start", offset + 1);
|
|
|
350 |
model.addAttribute("size", size);
|
|
|
351 |
if (rechargeCommissions.size() < limit){
|
|
|
352 |
model.addAttribute("end", offset + rechargeCommissions.size());
|
|
|
353 |
}else{
|
|
|
354 |
model.addAttribute("end", offset + limit);
|
|
|
355 |
}
|
|
|
356 |
return "recharge-commissions";
|
|
|
357 |
}
|
|
|
358 |
|
|
|
359 |
@RequestMapping(value = "/getPaginatedRechargeCommissions", method = RequestMethod.GET)
|
|
|
360 |
public String getPaginatedRechargeCommissions(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
361 |
//LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
362 |
//RechargeType rechargeType = RechargeType.valueOf(rechargeTypeString);
|
|
|
363 |
List<RechargeCommission> rechargeCommissions = rechargeCommissionRepository.selectAllPaginated(offset, limit);
|
|
|
364 |
Map<Integer, RechargeOperator> rechargeOperatorIdRechargeOperatorMap = this.rechargeCommissionsOperatorIdRechargeOperatorMap(rechargeCommissions);
|
|
|
365 |
model.addAttribute("rechargeCommissions", rechargeCommissions);
|
|
|
366 |
model.addAttribute("rechargeOperatorIdRechargeOperatorMap", rechargeOperatorIdRechargeOperatorMap);
|
|
|
367 |
return "recharge-commissions-paginated";
|
|
|
368 |
}
|
|
|
369 |
|
|
|
370 |
@RequestMapping(value = "/getRechargeCommissionByOperatorId", method = RequestMethod.GET)
|
|
|
371 |
public String getRechargeCommissionByOperatorId(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.OPERATOR_ID) int operatorId, Model model) throws ProfitMandiBusinessException{
|
|
|
372 |
RechargeOperator rechargeOperator = rechargeOperatorRepository.selectById(operatorId);
|
|
|
373 |
RechargeCommission rechargeCommission = rechargeCommissionRepository.selectByOperatorId(operatorId);
|
|
|
374 |
model.addAttribute("rechargeCommission", rechargeCommission);
|
|
|
375 |
model.addAttribute("rechargeOperator", rechargeOperator);
|
|
|
376 |
return "recharge-commission-details";
|
|
|
377 |
}
|
|
|
378 |
|
|
|
379 |
@RequestMapping(value = "/updateRechargeCommission", method = RequestMethod.PUT)
|
|
|
380 |
public String updateRechargeCommission(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.OPERATOR_ID) int operatorId, @RequestParam(name = ProfitMandiConstants.AMOUNT_TYPE) String amountTypeString, @RequestParam(name = ProfitMandiConstants.AMOUNT) float amount, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
381 |
rechargeService.updateRechargeCommission(operatorId, amountTypeString, amount);
|
|
|
382 |
List<RechargeCommission> rechargeCommissions = rechargeCommissionRepository.selectAllPaginated(offset, limit);
|
|
|
383 |
Map<Integer, RechargeOperator> rechargeOperatorIdRechargeOperatorMap = this.rechargeCommissionsOperatorIdRechargeOperatorMap(rechargeCommissions);
|
|
|
384 |
model.addAttribute("rechargeCommissions", rechargeCommissions);
|
|
|
385 |
model.addAttribute("rechargeOperatorIdRechargeOperatorMap", rechargeOperatorIdRechargeOperatorMap);
|
|
|
386 |
return "recharge-commissions-paginated";
|
|
|
387 |
}
|
|
|
388 |
|
|
|
389 |
|
| 23505 |
ashik.ali |
390 |
}
|