| 22551 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.ArrayList;
|
| 23936 |
tejbeer |
5 |
import java.util.Arrays;
|
|
|
6 |
import java.util.HashMap;
|
| 22551 |
ashik.ali |
7 |
import java.util.List;
|
| 23936 |
tejbeer |
8 |
import java.util.Map;
|
| 22551 |
ashik.ali |
9 |
|
|
|
10 |
import javax.servlet.http.HttpServletRequest;
|
|
|
11 |
|
| 23568 |
govind |
12 |
import org.apache.logging.log4j.Logger;
|
|
|
13 |
import org.apache.logging.log4j.LogManager;
|
| 22551 |
ashik.ali |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 23936 |
tejbeer |
15 |
import org.springframework.http.ResponseEntity;
|
| 22551 |
ashik.ali |
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.RequestMapping;
|
|
|
20 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
21 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
22 |
|
|
|
23 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23936 |
tejbeer |
24 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 22551 |
ashik.ali |
25 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 23936 |
tejbeer |
26 |
import com.spice.profitmandi.common.model.RechargeCredential;
|
| 22551 |
ashik.ali |
27 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 23936 |
tejbeer |
28 |
import com.spice.profitmandi.dao.entity.dtr.RechargeOperator;
|
|
|
29 |
import com.spice.profitmandi.dao.entity.transaction.AddWalletRequest;
|
|
|
30 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
|
|
31 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 22551 |
ashik.ali |
32 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
| 23936 |
tejbeer |
34 |
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
|
|
|
35 |
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
|
| 22551 |
ashik.ali |
36 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
| 23936 |
tejbeer |
37 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 22551 |
ashik.ali |
38 |
import com.spice.profitmandi.service.wallet.WalletService;
|
|
|
39 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
40 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 23936 |
tejbeer |
41 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 22551 |
ashik.ali |
42 |
|
| 23936 |
tejbeer |
43 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
44 |
|
| 22551 |
ashik.ali |
45 |
@Controller
|
|
|
46 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
47 |
public class WalletController {
|
|
|
48 |
|
|
|
49 |
@Autowired
|
| 22927 |
ashik.ali |
50 |
private CookiesProcessor cookiesProcessor;
|
| 22551 |
ashik.ali |
51 |
|
|
|
52 |
@Autowired
|
| 22927 |
ashik.ali |
53 |
private WalletService walletService;
|
| 22551 |
ashik.ali |
54 |
|
|
|
55 |
@Autowired
|
| 22927 |
ashik.ali |
56 |
private UserWalletRepository userWalletRepository;
|
| 22551 |
ashik.ali |
57 |
|
| 23936 |
tejbeer |
58 |
@Autowired
|
|
|
59 |
private MVCResponseSender mvcResponseSender;
|
|
|
60 |
|
|
|
61 |
@Autowired
|
|
|
62 |
private RetailerService retailerService;
|
|
|
63 |
|
|
|
64 |
|
|
|
65 |
@Autowired
|
|
|
66 |
AddWalletRequestRepository addWalletRequestRepository;
|
| 23568 |
govind |
67 |
private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
|
| 22551 |
ashik.ali |
68 |
|
|
|
69 |
@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
70 |
public String dashboard(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws ProfitMandiBusinessException{
|
|
|
71 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 22551 |
ashik.ali |
72 |
|
|
|
73 |
UserWallet userWallet = null;
|
|
|
74 |
try{
|
|
|
75 |
userWallet = userWalletRepository.selectByRetailerId(fofoDetails.getFofoId());
|
|
|
76 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
77 |
LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
|
|
|
78 |
//return "error";
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
82 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
83 |
|
|
|
84 |
List<UserWalletHistory> userWalletHistories = new ArrayList<>();
|
|
|
85 |
try{
|
|
|
86 |
userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
|
|
87 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
88 |
LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
|
|
|
89 |
}
|
|
|
90 |
|
|
|
91 |
long countItems = 0;
|
|
|
92 |
try{
|
|
|
93 |
countItems = walletService.getSizeByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime);
|
|
|
94 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
95 |
LOGGER.error("UserWallet not found : ",profitMandiBusinessException);
|
|
|
96 |
}
|
|
|
97 |
model.addAttribute("userWallet", userWallet);
|
|
|
98 |
model.addAttribute("walletHistories", userWalletHistories);
|
|
|
99 |
model.addAttribute("start", offset + 1);
|
|
|
100 |
model.addAttribute("size",countItems);
|
|
|
101 |
model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
|
|
|
102 |
model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
|
|
|
103 |
if (userWalletHistories.size() < limit){
|
|
|
104 |
model.addAttribute("end", offset + userWalletHistories.size());
|
|
|
105 |
}
|
|
|
106 |
else{
|
|
|
107 |
model.addAttribute("end", offset + limit);
|
|
|
108 |
}
|
|
|
109 |
return "wallet-details";
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
@RequestMapping(value = "/getPaginatedWalletHistory")
|
| 23505 |
ashik.ali |
113 |
public String getSaleHistoryPaginated(HttpServletRequest request, @RequestParam(name = ProfitMandiConstants.START_TIME, required = false) String startTimeString, @RequestParam(name = ProfitMandiConstants.END_TIME, required = false) String endTimeString, @RequestParam(name = "offset", defaultValue = "0") int offset, @RequestParam(name = "limit", defaultValue="10") int limit, Model model) throws ProfitMandiBusinessException{
|
| 22927 |
ashik.ali |
114 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
115 |
|
| 22551 |
ashik.ali |
116 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
117 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
118 |
|
|
|
119 |
List<UserWalletHistory> userWalletHistories = new ArrayList<>();
|
|
|
120 |
try{
|
|
|
121 |
userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
|
|
122 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
123 |
LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
|
|
|
124 |
}
|
|
|
125 |
|
|
|
126 |
model.addAttribute("walletHistories", userWalletHistories);
|
|
|
127 |
return "wallet-history-paginated";
|
|
|
128 |
}
|
|
|
129 |
|
| 23936 |
tejbeer |
130 |
@RequestMapping(value = "/getAddWalletRequest", method = RequestMethod.GET)
|
|
|
131 |
public String getAddwalletRequest(HttpServletRequest request,
|
|
|
132 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
133 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
134 |
throws ProfitMandiBusinessException {
|
|
|
135 |
List<AddWalletRequest> walletRequest = null;
|
|
|
136 |
long size = 0;
|
|
|
137 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.pending);
|
|
|
138 |
LOGGER .info("walletRequest" + walletRequest);
|
|
|
139 |
size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.pending);
|
|
|
140 |
|
|
|
141 |
List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
|
|
|
142 |
Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
|
|
|
143 |
|
|
|
144 |
model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
|
|
|
145 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
146 |
model.addAttribute("rStatus","pending");
|
|
|
147 |
model.addAttribute("start", offset + 1);
|
|
|
148 |
model.addAttribute("size", size);
|
|
|
149 |
model.addAttribute("url","/getPaginatedWalletRequest");
|
|
|
150 |
|
|
|
151 |
if (walletRequest.size() < limit) {
|
|
|
152 |
model.addAttribute("end", offset + walletRequest.size());
|
|
|
153 |
} else {
|
|
|
154 |
model.addAttribute("end", offset + limit);
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
return "add-wallet-request";
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
@RequestMapping(value = "/getPaginatedWalletRequest", method = RequestMethod.GET)
|
|
|
161 |
public String getPaginatedWalletRequest(HttpServletRequest request,
|
|
|
162 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
163 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
164 |
throws ProfitMandiBusinessException {
|
|
|
165 |
LOGGER .info("requested offset=[{}], limit = [{}]", offset, limit);
|
|
|
166 |
List<AddWalletRequest> walletRequest = null;
|
|
|
167 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.pending);
|
|
|
168 |
LOGGER.info("walletRequest" + walletRequest);
|
|
|
169 |
List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
|
|
|
170 |
Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
|
|
|
171 |
|
|
|
172 |
model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
|
|
|
173 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
174 |
model.addAttribute("rStatus","pending");
|
|
|
175 |
model.addAttribute("url","/getPaginatedWalletRequest");
|
|
|
176 |
|
|
|
177 |
return "add-wallet-request-paginated";
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
@RequestMapping(value = "/getAddWalletApproved", method = RequestMethod.GET)
|
|
|
181 |
public String getAddwalletRequestApproved(HttpServletRequest request,
|
|
|
182 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
183 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
184 |
throws ProfitMandiBusinessException {
|
|
|
185 |
List<AddWalletRequest> walletRequest = null;
|
|
|
186 |
|
|
|
187 |
long size = 0;
|
|
|
188 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.approved);
|
|
|
189 |
size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.approved);
|
|
|
190 |
LOGGER.info("walletRequest" + walletRequest);
|
|
|
191 |
List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
|
|
|
192 |
Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
|
|
|
193 |
|
|
|
194 |
model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
|
|
|
195 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
196 |
model.addAttribute("start", offset + 1);
|
|
|
197 |
model.addAttribute("size", size);
|
|
|
198 |
model.addAttribute("url","/getPaginatedWalletApproved");
|
|
|
199 |
|
|
|
200 |
if (walletRequest.size() < limit) {
|
|
|
201 |
model.addAttribute("end", offset + walletRequest.size());
|
|
|
202 |
} else {
|
|
|
203 |
model.addAttribute("end", offset + limit);
|
|
|
204 |
}
|
|
|
205 |
|
|
|
206 |
return "add-wallet-request";
|
|
|
207 |
}
|
|
|
208 |
|
|
|
209 |
@RequestMapping(value = "/getPaginatedWalletApproved", method = RequestMethod.GET)
|
|
|
210 |
public String getPaginatedWalletApproved(HttpServletRequest request,
|
|
|
211 |
@RequestParam(name = "offset", defaultValue = "0") int offset,
|
|
|
212 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
|
|
|
213 |
throws ProfitMandiBusinessException {
|
|
|
214 |
LOGGER .info("requested offset=[{}], limit = [{}]", offset, limit);
|
|
|
215 |
List<AddWalletRequest> walletRequest = null;
|
|
|
216 |
walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.approved);
|
|
|
217 |
LOGGER.info("walletRequest" + walletRequest);
|
|
|
218 |
List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
|
|
|
219 |
Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
|
|
|
220 |
|
|
|
221 |
model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
|
|
|
222 |
model.addAttribute("walletRequest", walletRequest);
|
|
|
223 |
model.addAttribute("url","/getPaginatedWalletApproved");
|
|
|
224 |
|
|
|
225 |
return "add-wallet-request-paginated";
|
|
|
226 |
}
|
|
|
227 |
|
|
|
228 |
@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
|
|
|
229 |
public String addAmountToWallet(HttpServletRequest request,@RequestParam(name = "id", defaultValue = "0")int id,Model model)
|
|
|
230 |
throws Exception {
|
|
|
231 |
|
|
|
232 |
AddWalletRequest addWalletRequest= addWalletRequestRepository.selectById(id);
|
|
|
233 |
walletService.addAmountToWallet(addWalletRequest.getRetailerId(), id,WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs",addWalletRequest.getAmount());
|
|
|
234 |
addWalletRequest.setStatus(AddWalletRequestStatus.approved);
|
|
|
235 |
addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
|
|
|
236 |
addWalletRequestRepository.persist(addWalletRequest);
|
|
|
237 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
238 |
return "response";
|
|
|
239 |
}
|
|
|
240 |
private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest)
|
|
|
241 |
{
|
|
|
242 |
List<Integer> fofoIds = new ArrayList<>();
|
|
|
243 |
for(AddWalletRequest walletdetail :walletRequest ) {
|
|
|
244 |
fofoIds.add(walletdetail.getRetailerId());
|
|
|
245 |
}
|
|
|
246 |
return fofoIds;
|
|
|
247 |
}
|
|
|
248 |
|
| 22551 |
ashik.ali |
249 |
}
|