Subversion Repositories SmartDukaan

Rev

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

Rev 23936 Rev 23985
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
-
 
3
import java.text.MessageFormat;
3
import java.time.LocalDateTime;
4
import java.time.LocalDateTime;
4
import java.util.ArrayList;
5
import java.util.ArrayList;
5
import java.util.Arrays;
-
 
6
import java.util.HashMap;
-
 
7
import java.util.List;
6
import java.util.List;
8
import java.util.Map;
7
import java.util.Map;
9
 
8
 
-
 
9
import javax.mail.internet.InternetAddress;
-
 
10
import javax.mail.internet.MimeMessage;
10
import javax.servlet.http.HttpServletRequest;
11
import javax.servlet.http.HttpServletRequest;
11
 
12
 
12
import org.apache.logging.log4j.Logger;
-
 
13
import org.apache.logging.log4j.LogManager;
13
import org.apache.logging.log4j.LogManager;
-
 
14
import org.apache.logging.log4j.Logger;
14
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.beans.factory.annotation.Autowired;
15
import org.springframework.http.ResponseEntity;
16
import org.springframework.mail.javamail.JavaMailSender;
-
 
17
import org.springframework.mail.javamail.MimeMessageHelper;
16
import org.springframework.stereotype.Controller;
18
import org.springframework.stereotype.Controller;
17
import org.springframework.transaction.annotation.Transactional;
19
import org.springframework.transaction.annotation.Transactional;
18
import org.springframework.ui.Model;
20
import org.springframework.ui.Model;
19
import org.springframework.web.bind.annotation.RequestMapping;
21
import org.springframework.web.bind.annotation.RequestMapping;
20
import org.springframework.web.bind.annotation.RequestMethod;
22
import org.springframework.web.bind.annotation.RequestMethod;
21
import org.springframework.web.bind.annotation.RequestParam;
23
import org.springframework.web.bind.annotation.RequestParam;
22
 
24
 
23
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
25
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
24
import com.spice.profitmandi.common.model.CustomRetailer;
26
import com.spice.profitmandi.common.model.CustomRetailer;
25
import com.spice.profitmandi.common.model.ProfitMandiConstants;
27
import com.spice.profitmandi.common.model.ProfitMandiConstants;
26
import com.spice.profitmandi.common.model.RechargeCredential;
-
 
27
import com.spice.profitmandi.common.util.StringUtils;
28
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;
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;
-
 
32
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
30
import com.spice.profitmandi.dao.entity.transaction.UserWallet;
33
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
31
import com.spice.profitmandi.dao.entity.transaction.UserWalletHistory;
34
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
32
import com.spice.profitmandi.dao.enumuration.transaction.AddWalletRequestStatus;
35
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
33
import com.spice.profitmandi.dao.repository.catalog.AddWalletRequestRepository;
-
 
34
import com.spice.profitmandi.dao.repository.dtr.UserAccountRepository;
36
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
35
import com.spice.profitmandi.dao.repository.transaction.UserWalletRepository;
37
import com.spice.profitmandi.service.user.RetailerService;
36
import com.spice.profitmandi.service.user.RetailerService;
38
import com.spice.profitmandi.service.wallet.WalletService;
37
import com.spice.profitmandi.service.wallet.WalletService;
39
import com.spice.profitmandi.web.model.LoginDetails;
38
import com.spice.profitmandi.web.model.LoginDetails;
40
import com.spice.profitmandi.web.util.CookiesProcessor;
39
import com.spice.profitmandi.web.util.CookiesProcessor;
Line 57... Line 56...
57
	
56
	
58
	@Autowired
57
	@Autowired
59
	private MVCResponseSender mvcResponseSender;
58
	private MVCResponseSender mvcResponseSender;
60
	
59
	
61
	@Autowired
60
	@Autowired
-
 
61
	private UserAccountRepository userAccountRepository;
-
 
62
 
-
 
63
	@Autowired
-
 
64
	JavaMailSender mailSender;
-
 
65
	
-
 
66
	
-
 
67
	@Autowired
62
	private RetailerService retailerService;
68
	private RetailerService retailerService;
63
 
69
 
64
	
70
	
65
	@Autowired
71
	@Autowired
66
	AddWalletRequestRepository addWalletRequestRepository;
72
	AddWalletRequestRepository addWalletRequestRepository;
Line 223... Line 229...
223
		model.addAttribute("url","/getPaginatedWalletApproved");
229
		model.addAttribute("url","/getPaginatedWalletApproved");
224
 
230
 
225
		return "add-wallet-request-paginated";
231
		return "add-wallet-request-paginated";
226
	}
232
	}
227
	
233
	
-
 
234
	@RequestMapping(value = "/getAddWalletRequestRejected", method = RequestMethod.GET)
-
 
235
	public String getAddwalletRequestRejected(HttpServletRequest request,
-
 
236
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
237
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
-
 
238
			throws ProfitMandiBusinessException {
-
 
239
		List<AddWalletRequest> walletRequest = null;
-
 
240
		
-
 
241
		long size = 0;
-
 
242
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit,AddWalletRequestStatus.rejected);
-
 
243
		size = addWalletRequestRepository.selectCountByStatus(AddWalletRequestStatus.rejected);
-
 
244
		LOGGER.info("walletRequest" + walletRequest);
-
 
245
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
-
 
246
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
-
 
247
		
-
 
248
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
-
 
249
		model.addAttribute("walletRequest", walletRequest);
-
 
250
		model.addAttribute("start", offset + 1);
-
 
251
		model.addAttribute("size", size);
-
 
252
		model.addAttribute("url","/getPaginatedWalletRequestRejected");
-
 
253
 
-
 
254
		if (walletRequest.size() < limit) {
-
 
255
			model.addAttribute("end", offset + walletRequest.size());
-
 
256
		} else {
-
 
257
			model.addAttribute("end", offset + limit);
-
 
258
		}
-
 
259
 
-
 
260
		return "add-wallet-request";
-
 
261
	}
-
 
262
	
-
 
263
	
-
 
264
	@RequestMapping(value = "/getPaginatedWalletRequestRejected", method = RequestMethod.GET)
-
 
265
	public String getPaginatedWalletRequestRejected(HttpServletRequest request,
-
 
266
			@RequestParam(name = "offset", defaultValue = "0") int offset,
-
 
267
			@RequestParam(name = "limit", defaultValue = "10") int limit, Model model)
-
 
268
			throws ProfitMandiBusinessException {
-
 
269
		LOGGER .info("requested offset=[{}], limit = [{}]", offset, limit);
-
 
270
		List<AddWalletRequest> walletRequest = null;
-
 
271
		walletRequest = addWalletRequestRepository.selectAllByStatus(offset, limit, AddWalletRequestStatus.rejected);
-
 
272
		LOGGER.info("walletRequest" + walletRequest);
-
 
273
		List<Integer> fofoIds=this.getFofoIdsFromWalletRequest(walletRequest);
-
 
274
		Map<Integer,CustomRetailer> fofoIdsAndRetailerName=retailerService.getFofoRetailers(fofoIds);
-
 
275
		
-
 
276
		model.addAttribute("fofoIdsAndRetailerName",fofoIdsAndRetailerName);
-
 
277
		model.addAttribute("walletRequest", walletRequest);
-
 
278
		model.addAttribute("url","/getPaginatedWalletRequestRejected");
-
 
279
 
-
 
280
		return "add-wallet-request-paginated";
-
 
281
	}
228
	@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
282
	@RequestMapping(value = "/addAmountToWallet", method = RequestMethod.PUT)
229
	public String addAmountToWallet(HttpServletRequest request,@RequestParam(name = "id", defaultValue = "0")int id,Model model)
283
	public String addAmountToWallet(HttpServletRequest request,@RequestParam(name = "id", defaultValue = "0")int id,Model model)
230
			throws Exception {
284
			throws Exception {
231
		
285
		
232
		AddWalletRequest addWalletRequest= addWalletRequestRepository.selectById(id);
286
		AddWalletRequest addWalletRequest= addWalletRequestRepository.selectById(id);
233
	    walletService.addAmountToWallet(addWalletRequest.getRetailerId(), id,WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs",addWalletRequest.getAmount());		
287
	    walletService.addAmountToWallet(addWalletRequest.getRetailerId(), id,WalletReferenceType.ADVANCE_AMOUNT, "ntfs/rgfs",addWalletRequest.getAmount());		
234
        addWalletRequest.setStatus(AddWalletRequestStatus.approved);
288
        addWalletRequest.setStatus(AddWalletRequestStatus.approved);
235
        addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
289
        addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
236
	    addWalletRequestRepository.persist(addWalletRequest);
290
	    addWalletRequestRepository.persist(addWalletRequest);
237
	    model.addAttribute("response", mvcResponseSender.createResponseString(true));
291
	    model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
292
		CustomRetailer customRetailer=retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
-
 
293
	    String subject = "Request Approved for "+customRetailer.getBusinessName()+" of Rs."+ addWalletRequest.getAmount();
-
 
294
		String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
-
 
295
				new Integer(addWalletRequest.getRetailerId()),customRetailer.getBusinessName(),customRetailer.getEmail(),customRetailer.getMobileNumber(),addWalletRequest.getTransaction_reference(),
-
 
296
				new Float(addWalletRequest.getAmount()));
-
 
297
		
-
 
298
		this.sendMailWithAttachments(subject, messageText);
238
	    return "response";
299
	    return "response";
239
	}
300
	}
-
 
301
	
-
 
302
	@RequestMapping(value = "/addAmountToWalletRequestRejected", method = RequestMethod.PUT)
-
 
303
	public String addAmountToWalletRequestRejected(HttpServletRequest request,@RequestParam(name = "id", defaultValue = "0")int id,Model model)
-
 
304
			throws Exception {
-
 
305
		
-
 
306
		AddWalletRequest addWalletRequest= addWalletRequestRepository.selectById(id);
-
 
307
        addWalletRequest.setStatus(AddWalletRequestStatus.rejected);
-
 
308
        addWalletRequest.setUpdateTimestamp(LocalDateTime.now());
-
 
309
	    addWalletRequestRepository.persist(addWalletRequest);
-
 
310
	    model.addAttribute("response", mvcResponseSender.createResponseString(true));
-
 
311
		CustomRetailer customRetailer=retailerService.getFofoRetailer(addWalletRequest.getRetailerId());
-
 
312
	    String subject = "Request Rejected for "+customRetailer.getBusinessName()+" of Rs."+ addWalletRequest.getAmount();
-
 
313
		String messageText = MessageFormat.format("User Id - {0}\n Name -{1}\n Email -{2}\n mobile -{3}\n Reference - {4}\n Amount - Rs.{5}",
-
 
314
				new Integer(addWalletRequest.getRetailerId()),customRetailer.getBusinessName(),customRetailer.getEmail(),customRetailer.getMobileNumber(),addWalletRequest.getTransaction_reference(),
-
 
315
				new Float(addWalletRequest.getAmount()));
-
 
316
		
-
 
317
		this.sendMailWithAttachments(subject, messageText);
-
 
318
	    return "response";
-
 
319
	}
-
 
320
	
-
 
321
	private void sendMailWithAttachments(String subject, String messageText) throws Exception {
-
 
322
		MimeMessage message = mailSender.createMimeMessage();
-
 
323
		MimeMessageHelper helper = new MimeMessageHelper(message, true);
-
 
324
		String[] email = {"adeel.yazdani@smartdukaan.com","kamini.sharma@smartdukaan.com","care@smartdukaan.com","mohinder.mutreja@smartdukaan.com"};
-
 
325
		helper.setSubject(subject);
-
 
326
		helper.setText(messageText);
-
 
327
		helper.setTo(email);
-
 
328
		InternetAddress senderAddress = new InternetAddress("noreply@smartdukaan.com", "ProfitMandi Admin");
-
 
329
		helper.setFrom(senderAddress);
-
 
330
		mailSender.send(message);
-
 
331
 
-
 
332
	}
240
	private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest)
333
	private List<Integer> getFofoIdsFromWalletRequest(List<AddWalletRequest> walletRequest)
241
	{
334
	{
242
		List<Integer> fofoIds = new ArrayList<>();
335
		List<Integer> fofoIds = new ArrayList<>();
243
		for(AddWalletRequest  walletdetail :walletRequest ) {
336
		for(AddWalletRequest  walletdetail :walletRequest ) {
244
			fofoIds.add(walletdetail.getRetailerId());
337
			fofoIds.add(walletdetail.getRetailerId());
245
		}
338
		}
246
		return fofoIds;
339
		return fofoIds;
247
	}
340
	}	
-
 
341
 
248
 
342
 
249
}
343
}