| 22551 |
ashik.ali |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.time.LocalDateTime;
|
|
|
4 |
import java.util.ArrayList;
|
|
|
5 |
import java.util.List;
|
|
|
6 |
|
|
|
7 |
import javax.servlet.http.HttpServletRequest;
|
|
|
8 |
|
| 23568 |
govind |
9 |
import org.apache.logging.log4j.Logger;
|
|
|
10 |
import org.apache.logging.log4j.LogManager;
|
| 22551 |
ashik.ali |
11 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
12 |
import org.springframework.stereotype.Controller;
|
|
|
13 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
14 |
import org.springframework.ui.Model;
|
|
|
15 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
16 |
import org.springframework.web.bind.annotation.RequestMethod;
|
|
|
17 |
import org.springframework.web.bind.annotation.RequestParam;
|
|
|
18 |
|
|
|
19 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
|
|
20 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
|
|
21 |
import com.spice.profitmandi.common.util.StringUtils;
|
|
|
22 |
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
|
|
|
23 |
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
|
|
|
24 |
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
|
|
|
25 |
import com.spice.profitmandi.service.wallet.WalletService;
|
|
|
26 |
import com.spice.profitmandi.web.model.LoginDetails;
|
|
|
27 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
|
|
28 |
|
|
|
29 |
@Controller
|
|
|
30 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
31 |
public class WalletController {
|
|
|
32 |
|
|
|
33 |
@Autowired
|
| 22927 |
ashik.ali |
34 |
private CookiesProcessor cookiesProcessor;
|
| 22551 |
ashik.ali |
35 |
|
|
|
36 |
@Autowired
|
| 22927 |
ashik.ali |
37 |
private WalletService walletService;
|
| 22551 |
ashik.ali |
38 |
|
|
|
39 |
@Autowired
|
| 22927 |
ashik.ali |
40 |
private UserWalletRepository userWalletRepository;
|
| 22551 |
ashik.ali |
41 |
|
| 23568 |
govind |
42 |
private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
|
| 22551 |
ashik.ali |
43 |
|
|
|
44 |
@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
|
| 22927 |
ashik.ali |
45 |
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{
|
|
|
46 |
LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
|
| 22551 |
ashik.ali |
47 |
|
|
|
48 |
UserWallet userWallet = null;
|
|
|
49 |
try{
|
|
|
50 |
userWallet = userWalletRepository.selectByRetailerId(fofoDetails.getFofoId());
|
|
|
51 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
52 |
LOGGER.error("UserWallet not found : ", profitMandiBusinessException);
|
|
|
53 |
//return "error";
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
57 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
58 |
|
|
|
59 |
List<UserWalletHistory> userWalletHistories = new ArrayList<>();
|
|
|
60 |
try{
|
|
|
61 |
userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
|
|
62 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
63 |
LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
|
|
|
64 |
}
|
|
|
65 |
|
|
|
66 |
long countItems = 0;
|
|
|
67 |
try{
|
|
|
68 |
countItems = walletService.getSizeByRetailerId(fofoDetails.getFofoId(), startDateTime, endDateTime);
|
|
|
69 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
70 |
LOGGER.error("UserWallet not found : ",profitMandiBusinessException);
|
|
|
71 |
}
|
|
|
72 |
model.addAttribute("userWallet", userWallet);
|
|
|
73 |
model.addAttribute("walletHistories", userWalletHistories);
|
|
|
74 |
model.addAttribute("start", offset + 1);
|
|
|
75 |
model.addAttribute("size",countItems);
|
|
|
76 |
model.addAttribute(ProfitMandiConstants.START_TIME, startTimeString);
|
|
|
77 |
model.addAttribute(ProfitMandiConstants.END_TIME, endTimeString);
|
|
|
78 |
if (userWalletHistories.size() < limit){
|
|
|
79 |
model.addAttribute("end", offset + userWalletHistories.size());
|
|
|
80 |
}
|
|
|
81 |
else{
|
|
|
82 |
model.addAttribute("end", offset + limit);
|
|
|
83 |
}
|
|
|
84 |
return "wallet-details";
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
@RequestMapping(value = "/getPaginatedWalletHistory")
|
| 23505 |
ashik.ali |
88 |
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 |
89 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
|
|
90 |
|
| 22551 |
ashik.ali |
91 |
LocalDateTime startDateTime = StringUtils.toDateTime(startTimeString);
|
|
|
92 |
LocalDateTime endDateTime = StringUtils.toDateTime(endTimeString);
|
|
|
93 |
|
|
|
94 |
List<UserWalletHistory> userWalletHistories = new ArrayList<>();
|
|
|
95 |
try{
|
|
|
96 |
userWalletHistories = walletService.getPaginatedUserWalletHistoryByRetailerId(loginDetails.getFofoId(), startDateTime, endDateTime, offset, limit);
|
|
|
97 |
}catch(ProfitMandiBusinessException profitMandiBusinessException){
|
|
|
98 |
LOGGER.error("UserWallet History not found : ", profitMandiBusinessException);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
model.addAttribute("walletHistories", userWalletHistories);
|
|
|
102 |
return "wallet-history-paginated";
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
}
|