Subversion Repositories SmartDukaan

Rev

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

Rev 29846 Rev 29926
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.Serializable;
-
 
4
import java.time.LocalDate;
-
 
5
import java.time.LocalDateTime;
-
 
6
import java.util.ArrayList;
-
 
7
import java.util.Arrays;
-
 
8
import java.util.List;
-
 
9
import java.util.Map;
-
 
10
import java.util.Set;
-
 
11
import java.util.stream.Collectors;
-
 
12
 
-
 
13
import javax.servlet.http.HttpServletRequest;
-
 
14
 
-
 
15
import org.apache.commons.io.output.ByteArrayOutputStream;
-
 
16
import org.apache.logging.log4j.LogManager;
-
 
17
import org.apache.logging.log4j.Logger;
-
 
18
import org.springframework.beans.factory.annotation.Autowired;
-
 
19
import org.springframework.beans.factory.annotation.Qualifier;
-
 
20
import org.springframework.core.io.ByteArrayResource;
-
 
21
import org.springframework.http.HttpHeaders;
-
 
22
import org.springframework.http.HttpStatus;
-
 
23
import org.springframework.http.ResponseEntity;
-
 
24
import org.springframework.stereotype.Controller;
-
 
25
import org.springframework.transaction.annotation.Transactional;
-
 
26
import org.springframework.ui.Model;
-
 
27
import org.springframework.web.bind.annotation.PathVariable;
-
 
28
import org.springframework.web.bind.annotation.RequestBody;
-
 
29
import org.springframework.web.bind.annotation.RequestMapping;
-
 
30
import org.springframework.web.bind.annotation.RequestMethod;
-
 
31
import org.springframework.web.bind.annotation.RequestParam;
-
 
32
 
-
 
33
import com.fasterxml.jackson.databind.ObjectMapper;
3
import com.fasterxml.jackson.databind.ObjectMapper;
-
 
4
import com.spice.profitmandi.common.enumuration.MessageType;
34
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
5
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
35
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
-
 
36
import com.spice.profitmandi.common.model.ItemDescriptionModel;
-
 
37
import com.spice.profitmandi.common.model.PriceDropImeisModel;
-
 
38
import com.spice.profitmandi.common.model.PriceDropModel;
6
import com.spice.profitmandi.common.model.*;
39
import com.spice.profitmandi.common.model.PriceDropProcessModel;
-
 
40
import com.spice.profitmandi.common.services.ReporticoService;
7
import com.spice.profitmandi.common.services.ReporticoService;
41
import com.spice.profitmandi.common.util.FileUtil;
8
import com.spice.profitmandi.common.util.FileUtil;
42
import com.spice.profitmandi.common.util.FormattingUtils;
9
import com.spice.profitmandi.common.util.FormattingUtils;
43
import com.spice.profitmandi.common.util.Utils;
10
import com.spice.profitmandi.common.util.Utils;
-
 
11
import com.spice.profitmandi.dao.entity.auth.AuthUser;
44
import com.spice.profitmandi.dao.entity.catalog.Item;
12
import com.spice.profitmandi.dao.entity.catalog.Item;
45
import com.spice.profitmandi.dao.entity.catalog.TagListing;
13
import com.spice.profitmandi.dao.entity.catalog.TagListing;
-
 
14
import com.spice.profitmandi.dao.entity.dtr.User;
46
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
15
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
47
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
16
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
48
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
17
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
49
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
18
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
50
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
19
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
51
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
20
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
52
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
21
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
53
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
22
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
54
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
23
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
-
 
24
import com.spice.profitmandi.dao.repository.cs.CsService;
55
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
25
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
56
import com.spice.profitmandi.dao.repository.dtr.Mongo;
26
import com.spice.profitmandi.dao.repository.dtr.Mongo;
-
 
27
import com.spice.profitmandi.dao.repository.dtr.UserRepository;
57
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
28
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
58
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
29
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
59
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
30
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
60
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
31
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
61
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
32
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
62
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
33
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
-
 
34
import com.spice.profitmandi.service.NotificationService;
63
import com.spice.profitmandi.service.inventory.InventoryService;
35
import com.spice.profitmandi.service.inventory.InventoryService;
64
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModel;
36
import com.spice.profitmandi.service.pricecircular.PriceCircularItemModel;
65
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
37
import com.spice.profitmandi.service.pricecircular.PriceCircularModel;
66
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
38
import com.spice.profitmandi.service.pricecircular.PriceCircularService;
67
import com.spice.profitmandi.service.pricing.PriceDropService;
39
import com.spice.profitmandi.service.pricing.PriceDropService;
Line 70... Line 42...
70
import com.spice.profitmandi.service.user.RetailerService;
42
import com.spice.profitmandi.service.user.RetailerService;
71
import com.spice.profitmandi.service.wallet.WalletService;
43
import com.spice.profitmandi.service.wallet.WalletService;
72
import com.spice.profitmandi.web.model.LoginDetails;
44
import com.spice.profitmandi.web.model.LoginDetails;
73
import com.spice.profitmandi.web.util.CookiesProcessor;
45
import com.spice.profitmandi.web.util.CookiesProcessor;
74
import com.spice.profitmandi.web.util.MVCResponseSender;
46
import com.spice.profitmandi.web.util.MVCResponseSender;
-
 
47
import org.apache.commons.io.output.ByteArrayOutputStream;
-
 
48
import org.apache.logging.log4j.LogManager;
-
 
49
import org.apache.logging.log4j.Logger;
-
 
50
import org.springframework.beans.factory.annotation.Autowired;
-
 
51
import org.springframework.beans.factory.annotation.Qualifier;
-
 
52
import org.springframework.core.io.ByteArrayResource;
-
 
53
import org.springframework.http.HttpHeaders;
-
 
54
import org.springframework.http.HttpStatus;
-
 
55
import org.springframework.http.ResponseEntity;
-
 
56
import org.springframework.stereotype.Controller;
-
 
57
import org.springframework.transaction.annotation.Transactional;
-
 
58
import org.springframework.ui.Model;
-
 
59
import org.springframework.web.bind.annotation.*;
-
 
60
 
-
 
61
import javax.servlet.http.HttpServletRequest;
-
 
62
import java.io.Serializable;
-
 
63
import java.time.LocalDate;
-
 
64
import java.time.LocalDateTime;
-
 
65
import java.util.*;
-
 
66
import java.util.stream.Collectors;
75
 
67
 
76
@Controller
68
@Controller
77
@Transactional(rollbackFor = Throwable.class)
69
@Transactional(rollbackFor = Throwable.class)
78
public class PriceDropController {
70
public class PriceDropController {
79
 
71
 
80
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
72
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
81
 
73
 
82
	@Autowired
74
	@Autowired
-
 
75
	private CsService csService;
-
 
76
 
-
 
77
	@Autowired
-
 
78
	private UserRepository dtrUserRepository;
-
 
79
 
-
 
80
	@Autowired
83
	private PriceDropRepository priceDropRepository;
81
	private PriceDropRepository priceDropRepository;
84
 
82
 
85
	@Autowired
83
	@Autowired
86
	private ObjectMapper objectMapper;
84
	private ObjectMapper objectMapper;
87
 
85
 
Line 137... Line 135...
137
 
135
 
138
	@Autowired
136
	@Autowired
139
	private RetailerService retailerService;
137
	private RetailerService retailerService;
140
 
138
 
141
	@Autowired
139
	@Autowired
-
 
140
	private NotificationService notificationService;
-
 
141
 
-
 
142
	@Autowired
142
	private FofoStoreRepository fofoStoreRepository;
143
	private FofoStoreRepository fofoStoreRepository;
143
 
144
 
144
	@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
145
	@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
145
	public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
146
	public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
146
		List<PriceDrop> priceDrops = priceDropRepository.selectAllIncomplete();
147
		List<PriceDrop> priceDrops = priceDropRepository.selectAllIncomplete();
Line 366... Line 367...
366
				priceDrop.setCreatedOn(LocalDateTime.now());
367
				priceDrop.setCreatedOn(LocalDateTime.now());
367
				priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
368
				priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
368
				priceDropRepository.persist(priceDrop);
369
				priceDropRepository.persist(priceDrop);
369
				priceDropService.priceDropStatus(priceDrop.getId());
370
				priceDropService.priceDropStatus(priceDrop.getId());
370
				response = true;
371
				response = true;
-
 
372
 
-
 
373
				this.sendPriceChangeNotification(priceDrop);
371
			} else {
374
			} else {
372
				throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
375
				throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
373
						"Price Drop Should be greater than 0");
376
						"Price Drop Should be greater than 0");
374
			}
377
			}
375
		}
378
		}
376
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
379
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
377
		return "response";
380
		return "response";
378
	}
381
	}
-
 
382
	private void sendPriceChangeNotification(PriceDrop priceDrop) throws ProfitMandiBusinessException {
-
 
383
		List<Item> items = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId());
-
 
384
		String title = "Price has been %s for %s";
-
 
385
 
-
 
386
 
-
 
387
		SendNotificationModel sendNotificationModel = new SendNotificationModel();
-
 
388
		sendNotificationModel.setCampaignName("pricechange");
-
 
389
		sendNotificationModel.setExpiresat(LocalDateTime.now().plusDays(1));
-
 
390
		sendNotificationModel.setTitle("");
-
 
391
		StringBuffer sb = new StringBuffer();
-
 
392
		String message = null;
-
 
393
		if(priceDrop.getDropAmount() > 0) {
-
 
394
			title = String.format(title, "dropped", items.get(0).getItemDescriptionNoColor());
-
 
395
			message = String.format("Price has been dropped from Rs.%d. Old DP - Rs.%d, New DP - Rs.%d", priceDrop.getDropAmount(),
-
 
396
					priceDrop.getOldDp(), priceDrop.getNewDp());
-
 
397
		} else {
-
 
398
			title = String.format(title, "increased", items.get(0).getItemDescriptionNoColor());
-
 
399
			message = String.format("Price has been increased from Rs.%d. Old DP - Rs.%d, New DP - Rs.%d", -priceDrop.getDropAmount(),
-
 
400
					priceDrop.getOldDp(), priceDrop.getNewDp());
-
 
401
		}
-
 
402
		sendNotificationModel.setTitle(title);
-
 
403
		sendNotificationModel.setMessage(message);
-
 
404
		sendNotificationModel.setMessageType(MessageType.pricechange);
-
 
405
		sendNotificationModel.setUserIds(fofoStoreRepository.selectAllDtrUserIds());
-
 
406
		Set<AuthUser> authUsers = new HashSet<>(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_RBM));
-
 
407
		authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_CATEGORY));
-
 
408
		authUsers.addAll(csService.getAuthUserByCategoryId(ProfitMandiConstants.TICKET_CATEGORY_SALES));
-
 
409
		List<String> emailIds = authUsers.stream().map(x->x.getEmailId()).collect(Collectors.toList());
-
 
410
		List<User> user = dtrUserRepository.selectAllByEmailIds(emailIds);
-
 
411
		sendNotificationModel.getUserIds().addAll(user.stream().map(x->x.getId()).collect(Collectors.toList()));
-
 
412
		notificationService.sendNotification(sendNotificationModel);
-
 
413
	}
379
 
414
 
380
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
415
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
381
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
416
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
382
			Model model) throws ProfitMandiBusinessException, Exception {
417
			Model model) throws ProfitMandiBusinessException, Exception {
383
 
418