Subversion Repositories SmartDukaan

Rev

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

Rev 23568 Rev 23936
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.time.LocalDateTime;
3
import java.time.LocalDateTime;
4
import java.util.ArrayList;
4
import java.util.ArrayList;
-
 
5
import java.util.Arrays;
-
 
6
import java.util.HashMap;
5
import java.util.List;
7
import java.util.List;
-
 
8
import java.util.Map;
6
 
9
 
7
import javax.servlet.http.HttpServletRequest;
10
import javax.servlet.http.HttpServletRequest;
8
 
11
 
9
import org.apache.logging.log4j.Logger;
12
import org.apache.logging.log4j.Logger;
10
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.LogManager;
11
import org.springframework.beans.factory.annotation.Autowired;
14
import org.springframework.beans.factory.annotation.Autowired;
-
 
15
import org.springframework.http.ResponseEntity;
12
import org.springframework.stereotype.Controller;
16
import org.springframework.stereotype.Controller;
13
import org.springframework.transaction.annotation.Transactional;
17
import org.springframework.transaction.annotation.Transactional;
14
import org.springframework.ui.Model;
18
import org.springframework.ui.Model;
15
import org.springframework.web.bind.annotation.RequestMapping;
19
import org.springframework.web.bind.annotation.RequestMapping;
16
import org.springframework.web.bind.annotation.RequestMethod;
20
import org.springframework.web.bind.annotation.RequestMethod;
17
import org.springframework.web.bind.annotation.RequestParam;
21
import org.springframework.web.bind.annotation.RequestParam;
18
 
22
 
19
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
-
 
24
import com.spice.profitmandi.common.model.CustomRetailer;
20
import com.spice.profitmandi.common.model.ProfitMandiConstants;
25
import com.spice.profitmandi.common.model.ProfitMandiConstants;
-
 
26
import com.spice.profitmandi.common.model.RechargeCredential;
21
import com.spice.profitmandi.common.util.StringUtils;
27
import com.spice.profitmandi.common.util.StringUtils;
-
 
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;
22
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
32
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
23
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
33
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
-
 
34
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
-
 
35
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
24
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
36
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
-
 
37
import com.spice.profitmandi.service.user.RetailerService;
25
import com.spice.profitmandi.service.wallet.WalletService;
38
import com.spice.profitmandi.service.wallet.WalletService;
26
import com.spice.profitmandi.web.model.LoginDetails;
39
import com.spice.profitmandi.web.model.LoginDetails;
27
import com.spice.profitmandi.web.util.CookiesProcessor;
40
import com.spice.profitmandi.web.util.CookiesProcessor;
-
 
41
import com.spice.profitmandi.web.util.MVCResponseSender;
-
 
42
 
-
 
43
import in.shop2020.model.v1.order.WalletReferenceType;
28
 
44
 
29
@Controller
45
@Controller
30
@Transactional(rollbackFor = Throwable.class)
46
@Transactional(rollbackFor = Throwable.class)
31
public class WalletController {
47
public class WalletController {
32
 
48
 
Line 37... Line 53...
37
	private WalletService walletService;
53
	private WalletService walletService;
38
	
54
	
39
	@Autowired
55
	@Autowired
40
	private UserWalletRepository userWalletRepository;
56
	private UserWalletRepository userWalletRepository;
41
	
57
	
-
 
58
	@Autowired
-
 
59
	private MVCResponseSender mvcResponseSender;
-
 
60
	
-
 
61
	@Autowired
-
 
62
	private RetailerService retailerService;
-
 
63
 
-
 
64
	
-
 
65
	@Autowired
-
 
66
	AddWalletRequestRepository addWalletRequestRepository;
42
	private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
67
	private static final Logger LOGGER = LogManager.getLogger(WalletController.class);
43
	
68
	
44
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
69
	@RequestMapping(value = "/walletDetails", method = RequestMethod.GET)
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{
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{
46
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
71
		LoginDetails fofoDetails = cookiesProcessor.getCookiesObject(request);
Line 100... Line 125...
100
		
125
		
101
		model.addAttribute("walletHistories", userWalletHistories);
126
		model.addAttribute("walletHistories", userWalletHistories);
102
		return "wallet-history-paginated";
127
		return "wallet-history-paginated";
103
	}
128
	}
104
	
129
	
-
 
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
 
105
}
249
}