| 21464 |
kshitij.so |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
| 21468 |
kshitij.so |
4 |
import java.util.ArrayList;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
import java.util.Map;
|
| 21464 |
kshitij.so |
7 |
|
|
|
8 |
import javax.servlet.http.HttpServletRequest;
|
|
|
9 |
|
| 21505 |
kshitij.so |
10 |
import org.apache.thrift.TException;
|
|
|
11 |
import org.apache.thrift.transport.TTransportException;
|
| 21464 |
kshitij.so |
12 |
import org.slf4j.Logger;
|
|
|
13 |
import org.slf4j.LoggerFactory;
|
| 21505 |
kshitij.so |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 21464 |
kshitij.so |
15 |
import org.springframework.http.HttpStatus;
|
|
|
16 |
import org.springframework.http.MediaType;
|
|
|
17 |
import org.springframework.http.ResponseEntity;
|
|
|
18 |
import org.springframework.stereotype.Controller;
|
|
|
19 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
22 |
|
| 21505 |
kshitij.so |
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 21464 |
kshitij.so |
24 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 21468 |
kshitij.so |
25 |
import com.spice.profitmandi.common.util.Utils;
|
| 21505 |
kshitij.so |
26 |
import com.spice.profitmandi.dao.entity.UserAccounts;
|
|
|
27 |
import com.spice.profitmandi.dao.enumuration.AccountType;
|
|
|
28 |
import com.spice.profitmandi.dao.repository.UserAccountRepository;
|
| 21464 |
kshitij.so |
29 |
import com.spice.profitmandi.thrift.clients.TransactionClient;
|
|
|
30 |
import com.spice.profitmandi.web.model.ProfitMandiResponse;
|
|
|
31 |
import com.spice.profitmandi.web.model.ResponseStatus;
|
| 21505 |
kshitij.so |
32 |
import com.spice.profitmandi.web.res.ConfirmRechargeResponse;
|
|
|
33 |
import com.spice.profitmandi.web.util.ResponseSender;
|
| 21464 |
kshitij.so |
34 |
|
| 21468 |
kshitij.so |
35 |
import in.shop2020.model.v1.order.DenominationType;
|
| 21464 |
kshitij.so |
36 |
import in.shop2020.model.v1.order.DeviceNumberInfo;
|
| 21468 |
kshitij.so |
37 |
import in.shop2020.model.v1.order.RechargeDenomination;
|
| 21464 |
kshitij.so |
38 |
import in.shop2020.model.v1.order.RechargeType;
|
| 21505 |
kshitij.so |
39 |
import in.shop2020.model.v1.order.UserWallet;
|
| 21464 |
kshitij.so |
40 |
import io.swagger.annotations.ApiImplicitParam;
|
|
|
41 |
import io.swagger.annotations.ApiImplicitParams;
|
|
|
42 |
import io.swagger.annotations.ApiOperation;
|
|
|
43 |
|
|
|
44 |
@Controller
|
|
|
45 |
public class RechargeController {
|
|
|
46 |
|
|
|
47 |
private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
|
|
|
48 |
|
| 21505 |
kshitij.so |
49 |
@Autowired
|
|
|
50 |
UserAccountRepository userAccountRepository;
|
|
|
51 |
|
| 21464 |
kshitij.so |
52 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
53 |
@ApiImplicitParams({
|
|
|
54 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
55 |
required = true, dataType = "string", paramType = "header")
|
|
|
56 |
})
|
|
|
57 |
@ApiOperation(value = "")
|
|
|
58 |
public ResponseEntity<?> getServiceProvider(HttpServletRequest request, @RequestParam(value="deviceNumber") String deviceNumber, @RequestParam(value="rechargeType") String rechargeType){
|
|
|
59 |
DeviceNumberInfo deviceInfo = null;
|
|
|
60 |
TransactionClient tcl;
|
|
|
61 |
try {
|
|
|
62 |
tcl = new TransactionClient();
|
|
|
63 |
deviceInfo = tcl.getClient().getServiceProviderForDevice(RechargeType.valueOf(rechargeType), deviceNumber.substring(0,4));
|
|
|
64 |
} catch (Exception e) {
|
|
|
65 |
log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " + rechargeType, e);
|
|
|
66 |
}
|
|
|
67 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, deviceInfo);
|
|
|
68 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
69 |
}
|
| 21505 |
kshitij.so |
70 |
|
| 21468 |
kshitij.so |
71 |
@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
72 |
@ApiImplicitParams({
|
|
|
73 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
74 |
required = true, dataType = "string", paramType = "header")
|
|
|
75 |
})
|
|
|
76 |
@ApiOperation(value = "")
|
|
|
77 |
public ResponseEntity<?> getAllDenominations(HttpServletRequest request, @RequestParam(value="operatorId") long operatorId, @RequestParam(value="circleCode") String circleCode, @RequestParam(value="denominationType") String denominationType){
|
|
|
78 |
List<RechargeDenomination> rechargeDenominations = new ArrayList<RechargeDenomination>();
|
|
|
79 |
TransactionClient tcl;
|
|
|
80 |
try {
|
|
|
81 |
tcl = new TransactionClient();
|
|
|
82 |
rechargeDenominations = tcl.getClient().getRechargeDenominations(operatorId, circleCode, DenominationType.valueOf(denominationType));
|
|
|
83 |
} catch (Exception e) {
|
|
|
84 |
log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " + circleCode + " and DenominationType : " + denominationType, e);
|
|
|
85 |
}
|
|
|
86 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, rechargeDenominations);
|
|
|
87 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
88 |
}
|
| 21505 |
kshitij.so |
89 |
|
| 21468 |
kshitij.so |
90 |
@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
91 |
@ApiImplicitParams({
|
|
|
92 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
93 |
required = true, dataType = "string", paramType = "header")
|
|
|
94 |
})
|
|
|
95 |
@ApiOperation(value = "")
|
|
|
96 |
public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request){
|
|
|
97 |
Map<Long, String> mobileProviderMap = Utils.getMobileProvidersMap();
|
|
|
98 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, mobileProviderMap);
|
|
|
99 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
100 |
}
|
| 21505 |
kshitij.so |
101 |
|
| 21468 |
kshitij.so |
102 |
@RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
103 |
@ApiImplicitParams({
|
|
|
104 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
105 |
required = true, dataType = "string", paramType = "header")
|
|
|
106 |
})
|
|
|
107 |
@ApiOperation(value = "")
|
|
|
108 |
public ResponseEntity<?> getAllDTHOperators(HttpServletRequest request){
|
|
|
109 |
Map<Long, String> dthProviderMap = Utils.getDthProvidersMap();
|
|
|
110 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dthProviderMap);
|
|
|
111 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
112 |
}
|
|
|
113 |
|
| 21505 |
kshitij.so |
114 |
@RequestMapping(value = ProfitMandiConstants.URL_RECHARGE_CONFIRM, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
115 |
@ApiImplicitParams({
|
|
|
116 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
117 |
required = true, dataType = "string", paramType = "header")
|
|
|
118 |
})
|
|
|
119 |
@ApiOperation(value = "")
|
| 21510 |
kshitij.so |
120 |
public ResponseEntity<?> confirmRecharge(HttpServletRequest request, @RequestParam(value="rechargeAmount") long rechargeAmount){
|
| 21505 |
kshitij.so |
121 |
int userId = (int)request.getAttribute("userId");
|
|
|
122 |
UserAccounts userAccount = null;
|
|
|
123 |
UserWallet wallet = null;
|
|
|
124 |
if (rechargeAmount <=0){
|
|
|
125 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.BAD_REQUEST.toString(), HttpStatus.BAD_REQUEST, ResponseStatus.SUCCESS, null);
|
|
|
126 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.BAD_REQUEST);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
try {
|
|
|
130 |
userAccount = userAccountRepository.getUserAccountByType(userId, AccountType.saholic);
|
|
|
131 |
} catch (ProfitMandiBusinessException e) {
|
|
|
132 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, null);
|
|
|
133 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
134 |
}
|
|
|
135 |
try {
|
|
|
136 |
TransactionClient tc = new TransactionClient();
|
|
|
137 |
wallet = tc.getClient().getUserWallet(Long.valueOf(userAccount.getAccount_key()));
|
|
|
138 |
} catch (NumberFormatException | TException e) {
|
|
|
139 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.INTERNAL_SERVER_ERROR.toString(), HttpStatus.INTERNAL_SERVER_ERROR, ResponseStatus.SUCCESS, null);
|
|
|
140 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.INTERNAL_SERVER_ERROR);
|
|
|
141 |
}
|
|
|
142 |
|
|
|
143 |
ConfirmRechargeResponse crr = new ConfirmRechargeResponse();
|
|
|
144 |
crr.setWalletAmount(wallet.getAmount());
|
|
|
145 |
crr.setWalletAmountLeft(wallet.getAmount() - rechargeAmount);
|
|
|
146 |
crr.setCanProceed(true);
|
|
|
147 |
if (crr.getWalletAmountLeft() < 0){
|
|
|
148 |
crr.setCanProceed(false);
|
|
|
149 |
crr.setReason("You don't have sufficient wallet balance");
|
|
|
150 |
}
|
|
|
151 |
final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, crr);
|
|
|
152 |
return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
|
|
|
153 |
}
|
|
|
154 |
|
|
|
155 |
@RequestMapping(value = ProfitMandiConstants.URL_CREATE_RECHARGE , method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
|
|
|
156 |
@ApiImplicitParams({
|
|
|
157 |
@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",
|
|
|
158 |
required = true, dataType = "string", paramType = "header")
|
|
|
159 |
})
|
|
|
160 |
public ResponseEntity<?> createRecharge(HttpServletRequest request){
|
|
|
161 |
return null;
|
|
|
162 |
}
|
|
|
163 |
|
| 21464 |
kshitij.so |
164 |
}
|
| 21505 |
kshitij.so |
165 |
|
|
|
166 |
|
|
|
167 |
|