Subversion Repositories SmartDukaan

Rev

Rev 21468 | Rev 21510 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 21468 Rev 21505
Line 5... Line 5...
5
import java.util.List;
5
import java.util.List;
6
import java.util.Map;
6
import java.util.Map;
7
 
7
 
8
import javax.servlet.http.HttpServletRequest;
8
import javax.servlet.http.HttpServletRequest;
9
 
9
 
-
 
10
import org.apache.thrift.TException;
-
 
11
import org.apache.thrift.transport.TTransportException;
10
import org.slf4j.Logger;
12
import org.slf4j.Logger;
11
import org.slf4j.LoggerFactory;
13
import org.slf4j.LoggerFactory;
-
 
14
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.http.HttpStatus;
15
import org.springframework.http.HttpStatus;
13
import org.springframework.http.MediaType;
16
import org.springframework.http.MediaType;
14
import org.springframework.http.ResponseEntity;
17
import org.springframework.http.ResponseEntity;
15
import org.springframework.stereotype.Controller;
18
import org.springframework.stereotype.Controller;
16
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMethod;
20
import org.springframework.web.bind.annotation.RequestMethod;
18
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RequestParam;
19
 
22
 
-
 
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
24
import com.spice.profitmandi.common.model.ProfitMandiConstants;
21
import com.spice.profitmandi.common.util.Utils;
25
import com.spice.profitmandi.common.util.Utils;
-
 
26
import com.spice.profitmandi.dao.entity.UserAccounts;
-
 
27
import com.spice.profitmandi.dao.enumuration.AccountType;
-
 
28
import com.spice.profitmandi.dao.repository.UserAccountRepository;
22
import com.spice.profitmandi.thrift.clients.TransactionClient;
29
import com.spice.profitmandi.thrift.clients.TransactionClient;
23
import com.spice.profitmandi.web.model.ProfitMandiResponse;
30
import com.spice.profitmandi.web.model.ProfitMandiResponse;
24
import com.spice.profitmandi.web.model.ResponseStatus;
31
import com.spice.profitmandi.web.model.ResponseStatus;
-
 
32
import com.spice.profitmandi.web.res.ConfirmRechargeResponse;
-
 
33
import com.spice.profitmandi.web.util.ResponseSender;
25
 
34
 
26
import in.shop2020.model.v1.order.DenominationType;
35
import in.shop2020.model.v1.order.DenominationType;
27
import in.shop2020.model.v1.order.DeviceNumberInfo;
36
import in.shop2020.model.v1.order.DeviceNumberInfo;
28
import in.shop2020.model.v1.order.RechargeDenomination;
37
import in.shop2020.model.v1.order.RechargeDenomination;
29
import in.shop2020.model.v1.order.RechargeType;
38
import in.shop2020.model.v1.order.RechargeType;
-
 
39
import in.shop2020.model.v1.order.UserWallet;
30
import io.swagger.annotations.ApiImplicitParam;
40
import io.swagger.annotations.ApiImplicitParam;
31
import io.swagger.annotations.ApiImplicitParams;
41
import io.swagger.annotations.ApiImplicitParams;
32
import io.swagger.annotations.ApiOperation;
42
import io.swagger.annotations.ApiOperation;
33
 
43
 
34
@Controller
44
@Controller
35
public class RechargeController {
45
public class RechargeController {
36
 
46
 
37
	private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
47
	private static final Logger log=LoggerFactory.getLogger(RechargeController.class);
38
 
48
 
-
 
49
	@Autowired
-
 
50
	UserAccountRepository userAccountRepository;
-
 
51
	
39
	@RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
52
	@RequestMapping(value = ProfitMandiConstants.URL_GET_SERVICE_PROVIDER, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
40
	@ApiImplicitParams({
53
	@ApiImplicitParams({
41
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
54
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
42
				required = true, dataType = "string", paramType = "header")
55
				required = true, dataType = "string", paramType = "header")
43
	})
56
	})
Line 52... Line 65...
52
			log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  rechargeType, e);
65
			log.error("Unable to get service provider for Device number " + deviceNumber + " and rechargeType : " +  rechargeType, e);
53
		}
66
		}
54
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, deviceInfo);
67
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, deviceInfo);
55
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
68
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
56
	}
69
	}
57
	
70
 
58
	@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
71
	@RequestMapping(value = ProfitMandiConstants.URL_GET_ALL_DENOMINATIONS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
59
	@ApiImplicitParams({
72
	@ApiImplicitParams({
60
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
73
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
61
				required = true, dataType = "string", paramType = "header")
74
				required = true, dataType = "string", paramType = "header")
62
	})
75
	})
Line 71... Line 84...
71
			log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
84
			log.error("Unable to get rechargeDenominations for operatorId " + operatorId + " and circleCode : " +  circleCode + " and DenominationType : " + denominationType, e);
72
		}
85
		}
73
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, rechargeDenominations);
86
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, rechargeDenominations);
74
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
87
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
75
	}
88
	}
76
	
89
 
77
	@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
90
	@RequestMapping(value = ProfitMandiConstants.URL_MOBILE_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
78
	@ApiImplicitParams({
91
	@ApiImplicitParams({
79
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
92
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
80
				required = true, dataType = "string", paramType = "header")
93
				required = true, dataType = "string", paramType = "header")
81
	})
94
	})
Line 83... Line 96...
83
	public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request){
96
	public ResponseEntity<?> getAllMobileOperators(HttpServletRequest request){
84
		Map<Long, String> mobileProviderMap = Utils.getMobileProvidersMap();
97
		Map<Long, String> mobileProviderMap = Utils.getMobileProvidersMap();
85
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, mobileProviderMap);
98
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, mobileProviderMap);
86
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
99
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
87
	}
100
	}
88
	
101
 
89
	@RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
102
	@RequestMapping(value = ProfitMandiConstants.URL_DTH_OPERATORS, method=RequestMethod.POST,produces = MediaType.APPLICATION_JSON_VALUE)
90
	@ApiImplicitParams({
103
	@ApiImplicitParams({
91
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
104
		@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token", 
92
				required = true, dataType = "string", paramType = "header")
105
				required = true, dataType = "string", paramType = "header")
93
	})
106
	})
Line 96... Line 109...
96
		Map<Long, String> dthProviderMap = Utils.getDthProvidersMap();
109
		Map<Long, String> dthProviderMap = Utils.getDthProvidersMap();
97
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dthProviderMap);
110
		final ProfitMandiResponse<?> profitMandiResponse=new ProfitMandiResponse<>(LocalDateTime.now(), request.getRequestURL().toString() , HttpStatus.OK.toString(), HttpStatus.OK, ResponseStatus.SUCCESS, dthProviderMap);
98
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
111
		return new ResponseEntity<>(profitMandiResponse,HttpStatus.OK);
99
	}
112
	}
100
 
113
 
-
 
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 = "")
-
 
120
	public ResponseEntity<?> confirmRecharge(HttpServletRequest request, long rechargeAmount){
-
 
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
	
101
}
164
}
-
 
165
 
-
 
166
 
-
 
167