Subversion Repositories SmartDukaan

Rev

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

Rev 30015 Rev 30859
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import java.math.BigDecimal;
3
import java.time.LocalDateTime;
4
import java.time.LocalDateTime;
4
import java.util.Comparator;
5
import java.util.Comparator;
5
import java.util.List;
6
import java.util.List;
6
import java.util.stream.Collectors;
7
import java.util.stream.Collectors;
7
 
8
 
Line 23... Line 24...
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24
import com.spice.profitmandi.common.model.ProfitMandiConstants;
25
import com.spice.profitmandi.common.model.ProfitMandiConstants;
25
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
26
import com.spice.profitmandi.common.services.mandii.AccountStatusResponseOut;
26
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
27
import com.spice.profitmandi.common.services.mandii.EligibilityStatusEnum;
27
import com.spice.profitmandi.common.services.mandii.MandiiService;
28
import com.spice.profitmandi.common.services.mandii.MandiiService;
-
 
29
import com.spice.profitmandi.common.services.mandii.RepaymentDetails;
28
import com.spice.profitmandi.common.services.mandii.TransactionSummaryResponseOut;
30
import com.spice.profitmandi.common.services.mandii.TransactionSummaryResponseOut;
29
import com.spice.profitmandi.common.web.util.ResponseSender;
31
import com.spice.profitmandi.common.web.util.ResponseSender;
30
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
32
import com.spice.profitmandi.dao.entity.dtr.CreditAccount;
31
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
33
import com.spice.profitmandi.dao.entity.dtr.CreditStatus;
32
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
34
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
-
 
35
import com.spice.profitmandi.dao.entity.transaction.Loan;
-
 
36
import com.spice.profitmandi.dao.entity.transaction.LoanStatement;
-
 
37
import com.spice.profitmandi.dao.entity.transaction.SDCreditRequirement;
33
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
38
import com.spice.profitmandi.dao.enumuration.fofo.Gateway;
-
 
39
import com.spice.profitmandi.dao.model.SDCreditResponseOut;
34
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
40
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
35
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
41
import com.spice.profitmandi.dao.repository.dtr.CreditAccountRepository;
36
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
42
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
37
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
43
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
38
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
44
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
-
 
45
import com.spice.profitmandi.dao.repository.transaction.LoanRepository;
-
 
46
import com.spice.profitmandi.dao.repository.transaction.LoanStatementRepository;
39
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
47
import com.spice.profitmandi.dao.repository.transaction.PaymentRepository;
-
 
48
import com.spice.profitmandi.dao.repository.transaction.SDCreditRequirementRepository;
40
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
49
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
-
 
50
import com.spice.profitmandi.service.transaction.SDCreditService;
41
import com.spice.profitmandi.service.wallet.WalletService;
51
import com.spice.profitmandi.service.wallet.WalletService;
42
 
52
 
43
import io.swagger.annotations.ApiImplicitParam;
53
import io.swagger.annotations.ApiImplicitParam;
44
import io.swagger.annotations.ApiImplicitParams;
54
import io.swagger.annotations.ApiImplicitParams;
45
 
55
 
Line 81... Line 91...
81
	ResponseSender<?> responseSender;
91
	ResponseSender<?> responseSender;
82
 
92
 
83
	@Autowired
93
	@Autowired
84
	CreditAccountRepository creditAccountRepository;
94
	CreditAccountRepository creditAccountRepository;
85
 
95
 
-
 
96
	@Autowired
-
 
97
	SDCreditService sdCreditService;
-
 
98
 
-
 
99
	@Autowired
-
 
100
	SDCreditRequirementRepository sdCreditRequirementRepository;
-
 
101
 
-
 
102
	@Autowired
-
 
103
	LoanRepository loanRepository;
-
 
104
 
-
 
105
	@Autowired
-
 
106
	private LoanStatementRepository loanStatementRepository;
-
 
107
 
86
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
108
	@RequestMapping(value = "payment/gateway/status/{gateway}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
87
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
109
	public ResponseEntity<?> getLoanStatus(HttpServletRequest request, @PathVariable Gateway gateway)
88
			throws ProfitMandiBusinessException {
110
			throws ProfitMandiBusinessException {
89
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
111
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
90
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
112
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
Line 131... Line 153...
131
				return responseSender.ok(accountStatusResponseOut);
153
				return responseSender.ok(accountStatusResponseOut);
132
			} catch (Exception e) {
154
			} catch (Exception e) {
133
				log.info("Trace {}\n{}", e.getMessage(), e);
155
				log.info("Trace {}\n{}", e.getMessage(), e);
134
				throw new ProfitMandiBusinessException("Loan Provider", gateway, "Can't fetch details for provider");
156
				throw new ProfitMandiBusinessException("Loan Provider", gateway, "Can't fetch details for provider");
135
			}
157
			}
-
 
158
		} else if (gateway != null && gateway.equals(Gateway.SDDIRECT)) {
-
 
159
			CreditAccount creditAccount = creditAccountRepository.selectByFofoIdAndGateway(retailerId,
-
 
160
					Gateway.SDDIRECT);
-
 
161
 
-
 
162
			SDCreditRequirement sdCreditRequirement = sdCreditRequirementRepository.selectByFofoId(retailerId);
-
 
163
 
-
 
164
			AccountStatusResponseOut accountStatusResponseOut = new AccountStatusResponseOut();
-
 
165
 
-
 
166
			BigDecimal availability = sdCreditService.getAvailableAmount(retailerId);
-
 
167
 
-
 
168
			creditAccount.setAvailableAmount(availability.floatValue());
-
 
169
 
-
 
170
			log.info("availability {}", availability);
-
 
171
			accountStatusResponseOut.setBalanceAmount(availability);
-
 
172
			if (availability.floatValue() > 0 && creditAccount.isActive()) {
-
 
173
				accountStatusResponseOut.setStatus(EligibilityStatusEnum.SANCTION_AVAILABLE);
-
 
174
				accountStatusResponseOut.setRateOfInterest(creditAccount.getInterestRate());
-
 
175
				accountStatusResponseOut.setCreditDays(sdCreditRequirement.getCreditDays());
-
 
176
			} else {
-
 
177
				accountStatusResponseOut.setStatus(EligibilityStatusEnum.IN_ELIGIBLE);
-
 
178
 
-
 
179
			}
-
 
180
			return responseSender.ok(accountStatusResponseOut);
136
		}
181
		}
137
 
182
 
138
		else {
183
		else {
139
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");
184
			throw new ProfitMandiBusinessException("Provider", "Empty", "Provider can't be empty");
140
		}
185
		}
Line 153... Line 198...
153
				.collect(Collectors.toList());
198
				.collect(Collectors.toList());
154
		log.info("tranactionSummary" + tranactionSummary);
199
		log.info("tranactionSummary" + tranactionSummary);
155
 
200
 
156
		return responseSender.ok(tranactionSummary.stream().limit(10).collect(Collectors.toList()));
201
		return responseSender.ok(tranactionSummary.stream().limit(10).collect(Collectors.toList()));
157
	}
202
	}
-
 
203
 
-
 
204
	@RequestMapping(value = "payment/gateway/sddirect/summary", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
-
 
205
	public ResponseEntity<?> getSdDirectLoan(HttpServletRequest request) throws ProfitMandiBusinessException {
-
 
206
		int userId = (int) request.getAttribute(ProfitMandiConstants.USER_ID);
-
 
207
		int retailerId = userAccountRepository.selectRetailerIdByUserId(userId);
-
 
208
		FofoStore fs = fofoStoreRepository.selectByRetailerId(retailerId);
-
 
209
		SDCreditResponseOut sdCreditResponseOut = sdCreditService.sdDirectService(retailerId);
-
 
210
		return responseSender.ok(sdCreditResponseOut);
-
 
211
	}
-
 
212
 
158
}
213
}
159
214