| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
3 |
import java.io.ByteArrayInputStream;
|
| 4 |
import java.io.ByteArrayOutputStream;
|
4 |
import java.io.ByteArrayOutputStream;
|
| 5 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| - |
|
6 |
import java.time.LocalDate;
|
| 6 |
import java.time.LocalDateTime;
|
7 |
import java.time.LocalDateTime;
|
| - |
|
8 |
import java.time.LocalTime;
|
| - |
|
9 |
import java.util.ArrayList;
|
| 7 |
import java.util.Arrays;
|
10 |
import java.util.Arrays;
|
| 8 |
import java.util.HashMap;
|
11 |
import java.util.HashMap;
|
| 9 |
import java.util.HashSet;
|
12 |
import java.util.HashSet;
|
| - |
|
13 |
import java.util.LinkedHashSet;
|
| 10 |
import java.util.List;
|
14 |
import java.util.List;
|
| - |
|
15 |
import java.util.ListIterator;
|
| 11 |
import java.util.Map;
|
16 |
import java.util.Map;
|
| 12 |
import java.util.Set;
|
17 |
import java.util.Set;
|
| 13 |
import java.util.stream.Collectors;
|
18 |
import java.util.stream.Collectors;
|
| 14 |
|
19 |
|
| 15 |
import javax.servlet.http.HttpServletRequest;
|
20 |
import javax.servlet.http.HttpServletRequest;
|
| Line 39... |
Line 44... |
| 39 |
import com.spice.profitmandi.common.model.SchemeItems;
|
44 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 40 |
import com.spice.profitmandi.common.model.SchemeModel;
|
45 |
import com.spice.profitmandi.common.model.SchemeModel;
|
| 41 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
46 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 42 |
import com.spice.profitmandi.common.util.StringUtils;
|
47 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 43 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
48 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| - |
|
49 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 44 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
50 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| 45 |
import com.spice.profitmandi.dao.entity.catalog.OfferPartner;
|
51 |
import com.spice.profitmandi.dao.entity.catalog.OfferPartner;
|
| 46 |
import com.spice.profitmandi.dao.entity.catalog.Offermargin;
|
52 |
import com.spice.profitmandi.dao.entity.catalog.Offermargin;
|
| 47 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
53 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 48 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
54 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| - |
|
55 |
import com.spice.profitmandi.dao.entity.fofo.PrebookingListing;
|
| 49 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
56 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 50 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
57 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
| 51 |
import com.spice.profitmandi.dao.model.AmountMarginModel;
|
58 |
import com.spice.profitmandi.dao.model.AmountMarginModel;
|
| 52 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
59 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 53 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
60 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| 54 |
import com.spice.profitmandi.dao.model.ItemTypeParams;
|
61 |
import com.spice.profitmandi.dao.model.ItemTypeParams;
|
| 55 |
import com.spice.profitmandi.dao.model.SimpleItemType;
|
62 |
import com.spice.profitmandi.dao.model.SimpleItemType;
|
| - |
|
63 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 56 |
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
|
64 |
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
|
| 57 |
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
|
65 |
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
|
| 58 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
66 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
| 59 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
67 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 60 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
68 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 61 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
69 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 62 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
70 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 63 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
71 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| - |
|
72 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 64 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
73 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 65 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
74 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 66 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
75 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 67 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
76 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 68 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
77 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| Line 122... |
Line 131... |
| 122 |
|
131 |
|
| 123 |
@Autowired
|
132 |
@Autowired
|
| 124 |
private OfferPartnerRepository offerPartnerRepository;
|
133 |
private OfferPartnerRepository offerPartnerRepository;
|
| 125 |
|
134 |
|
| 126 |
@Autowired
|
135 |
@Autowired
|
| - |
|
136 |
private ItemRepository itemRepository;
|
| - |
|
137 |
|
| - |
|
138 |
@Autowired
|
| 127 |
private Gson gson;
|
139 |
private Gson gson;
|
| 128 |
|
140 |
|
| 129 |
@Autowired
|
141 |
@Autowired
|
| 130 |
private RetailerService retailerService;
|
142 |
private RetailerService retailerService;
|
| 131 |
|
143 |
|
| 132 |
@Autowired
|
144 |
@Autowired
|
| 133 |
private Mongo mongoClient;
|
145 |
private Mongo mongoClient;
|
| 134 |
|
146 |
|
| - |
|
147 |
@Autowired
|
| - |
|
148 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| - |
|
149 |
|
| 135 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
150 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 136 |
public String createScheme(HttpServletRequest request, Model model) {
|
151 |
public String createScheme(HttpServletRequest request, Model model) {
|
| 137 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
152 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
| 138 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
153 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
| 139 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
154 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| Line 538... |
Line 553... |
| 538 |
|
553 |
|
| 539 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
554 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
| 540 |
|
555 |
|
| 541 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
556 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
| 542 |
model.addAttribute("itemCriteriaType", ItemCriteriaType.values());
|
557 |
model.addAttribute("itemCriteriaType", ItemCriteriaType.values());
|
| - |
|
558 |
model.addAttribute("partnerType", PartnerType.values());
|
| 543 |
model.addAttribute("brands", brands);
|
559 |
model.addAttribute("brands", brands);
|
| 544 |
return "scheme_offer";
|
560 |
return "scheme_offer";
|
| 545 |
|
561 |
|
| 546 |
}
|
562 |
}
|
| 547 |
|
563 |
|
| Line 558... |
Line 574... |
| 558 |
offer.setAmountType(createOfferRequest.getAmountType());
|
574 |
offer.setAmountType(createOfferRequest.getAmountType());
|
| 559 |
offer.setStartDateTime(createOfferRequest.getStartDate());
|
575 |
offer.setStartDateTime(createOfferRequest.getStartDate());
|
| 560 |
offer.setEndDateTime(createOfferRequest.getEndDate());
|
576 |
offer.setEndDateTime(createOfferRequest.getEndDate());
|
| 561 |
offer.setPrice(createOfferRequest.getPrice());
|
577 |
offer.setPrice(createOfferRequest.getPrice());
|
| 562 |
offer.setCreatedTimestamp(LocalDateTime.now());
|
578 |
offer.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
579 |
offer.setCriteria(createOfferRequest.getCriteria());
|
| - |
|
580 |
offer.setPartnerType(createOfferRequest.getPartnerType());
|
| 563 |
|
581 |
|
| 564 |
if (createOfferRequest.getItemCriteria().equals(ItemCriteriaType.Item_Model)) {
|
582 |
if (createOfferRequest.getItemCriteria().equals(ItemCriteriaType.Item_Model)) {
|
| 565 |
ItemTypeParams itemTypeParams = new ItemTypeParams();
|
583 |
ItemTypeParams itemTypeParams = new ItemTypeParams();
|
| 566 |
itemTypeParams.setCatalogId(createOfferRequest.getCatalogIds());
|
584 |
itemTypeParams.setCatalogId(createOfferRequest.getCatalogIds());
|
| 567 |
SimpleItemType sit = new SimpleItemType(itemTypeParams);
|
585 |
SimpleItemType sit = new SimpleItemType(itemTypeParams);
|
| Line 574... |
Line 592... |
| 574 |
sit.setItemTypeParams(itemTypeParams);
|
592 |
sit.setItemTypeParams(itemTypeParams);
|
| 575 |
offer.setItemParam(gson.toJson(itemTypeParams));
|
593 |
offer.setItemParam(gson.toJson(itemTypeParams));
|
| 576 |
}
|
594 |
}
|
| 577 |
|
595 |
|
| 578 |
offerRepository.persist(offer);
|
596 |
offerRepository.persist(offer);
|
| - |
|
597 |
if (createOfferRequest.getFofoIds().isEmpty()) {
|
| - |
|
598 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
| - |
|
599 |
.collect(Collectors.toList());
|
| - |
|
600 |
for (Integer fofoId : fofoIds) {
|
| - |
|
601 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(fofoId,
|
| - |
|
602 |
offer.getStartDateTime().toLocalDate());
|
| - |
|
603 |
if (offer.getPartnerType().equals(partnerType)) {
|
| - |
|
604 |
LOGGER.info("partnerType" + partnerType);
|
| - |
|
605 |
LOGGER.info("fofoId" + fofoId);
|
| - |
|
606 |
|
| - |
|
607 |
|
| - |
|
608 |
OfferPartner op = new OfferPartner();
|
| - |
|
609 |
op.setFofoId(fofoId);
|
| - |
|
610 |
op.setOfferId(offer.getId());
|
| - |
|
611 |
offerPartnerRepository.persist(op);
|
| - |
|
612 |
}
|
| - |
|
613 |
|
| - |
|
614 |
}
|
| - |
|
615 |
}
|
| - |
|
616 |
|
| - |
|
617 |
else {
|
| - |
|
618 |
|
| 579 |
for (Integer fofoId : createOfferRequest.getFofoIds()) {
|
619 |
for (Integer fofoId : createOfferRequest.getFofoIds()) {
|
| 580 |
OfferPartner op = new OfferPartner();
|
620 |
OfferPartner op = new OfferPartner();
|
| 581 |
op.setFofoId(fofoId);
|
621 |
op.setFofoId(fofoId);
|
| 582 |
op.setOfferId(offer.getId());
|
622 |
op.setOfferId(offer.getId());
|
| 583 |
offerPartnerRepository.persist(op);
|
623 |
offerPartnerRepository.persist(op);
|
| - |
|
624 |
}
|
| 584 |
}
|
625 |
}
|
| 585 |
for (AmountMarginModel amm : createOfferRequest.getAmountOffer()) {
|
626 |
for (AmountMarginModel amm : createOfferRequest.getAmountOffer()) {
|
| 586 |
Offermargin om = new Offermargin();
|
627 |
Offermargin om = new Offermargin();
|
| 587 |
om.setValue(amm.getValue());
|
628 |
om.setValue(amm.getValue());
|
| 588 |
om.setMargin(amm.getMargin());
|
629 |
om.setMargin(amm.getMargin());
|
| Line 593... |
Line 634... |
| 593 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
634 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 594 |
return "response";
|
635 |
return "response";
|
| 595 |
|
636 |
|
| 596 |
}
|
637 |
}
|
| 597 |
|
638 |
|
| - |
|
639 |
@RequestMapping(value = "/getOffers", method = RequestMethod.GET)
|
| - |
|
640 |
public String createOffer(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
|
| - |
|
641 |
@RequestParam(name = "limit", defaultValue = "10") int limit, Model model) throws Exception {
|
| - |
|
642 |
|
| - |
|
643 |
List<Offer> offers = offerRepository.selectAll(offset, limit);
|
| - |
|
644 |
|
| - |
|
645 |
Map<Integer, String> statusMap = this.offerStatus(offers);
|
| - |
|
646 |
|
| - |
|
647 |
model.addAttribute("offers", offers);
|
| - |
|
648 |
model.addAttribute("statusMap", statusMap);
|
| - |
|
649 |
return "offer_history";
|
| - |
|
650 |
|
| - |
|
651 |
}
|
| - |
|
652 |
|
| - |
|
653 |
private Map<Integer, String> offerStatus(List<Offer> offers) {
|
| - |
|
654 |
Map<Integer, String> statusMap = new HashMap<>();
|
| - |
|
655 |
for (Offer offer : offers) {
|
| - |
|
656 |
LocalDateTime curDate = LocalDateTime.now();
|
| - |
|
657 |
if (offer.getStartDateTime().isAfter(curDate)) {
|
| - |
|
658 |
statusMap.put(offer.getId(), "Schedule");
|
| - |
|
659 |
|
| - |
|
660 |
} else if (offer.getEndDateTime().isBefore(curDate)) {
|
| - |
|
661 |
statusMap.put(offer.getId(), "Closed");
|
| - |
|
662 |
} else if (offer.getStartDateTime().isBefore(curDate) && offer.getEndDateTime().isAfter(curDate)) {
|
| - |
|
663 |
statusMap.put(offer.getId(), "Running");
|
| - |
|
664 |
}
|
| - |
|
665 |
}
|
| - |
|
666 |
|
| - |
|
667 |
return statusMap;
|
| - |
|
668 |
}
|
| - |
|
669 |
|
| - |
|
670 |
@RequestMapping(value = "/getOfferMargin", method = RequestMethod.GET)
|
| - |
|
671 |
public String getOfferMargin(HttpServletRequest request,
|
| - |
|
672 |
@RequestParam(name = "offerId", defaultValue = "0") int offerId, Model model) throws Exception {
|
| - |
|
673 |
Offer offer = offerRepository.selectById(offerId);
|
| - |
|
674 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
| - |
|
675 |
.collect(Collectors.toList());
|
| - |
|
676 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
| - |
|
677 |
List<OfferPartner> offerPartners = offerPartnerRepository.selectByOfferId(offerId);
|
| - |
|
678 |
|
| - |
|
679 |
LOGGER.info("offerId" + offer.getId());
|
| - |
|
680 |
|
| - |
|
681 |
Map<Integer, Double> value = offerRepository.selectSumOfferByRetailer(offer.getStartDateTime(),
|
| - |
|
682 |
offer.getEndDateTime(), 0, offer, true);
|
| - |
|
683 |
|
| - |
|
684 |
LOGGER.info("value" + value);
|
| - |
|
685 |
List<Offermargin> offerMargin = offerMarginRepository.selectByOfferId(offerId);
|
| - |
|
686 |
Map<Integer, Double> partnerValueMap = new HashMap<>();
|
| - |
|
687 |
Map<Integer, List<Integer>> partnerMarginMap = new HashMap<Integer, List<Integer>>();
|
| - |
|
688 |
Map<Integer, Integer> shortageAmount = new HashMap<>();
|
| - |
|
689 |
|
| - |
|
690 |
for (OfferPartner op : offerPartners) {
|
| - |
|
691 |
|
| - |
|
692 |
LOGGER.info("offerPartneer" + op.getFofoId());
|
| - |
|
693 |
if (value.containsKey(op.getFofoId())) {
|
| - |
|
694 |
partnerValueMap.put(op.getFofoId(), value.get(op.getFofoId()));
|
| - |
|
695 |
|
| - |
|
696 |
} else {
|
| - |
|
697 |
value.put(op.getFofoId(), 0d);
|
| - |
|
698 |
|
| - |
|
699 |
partnerValueMap.put(op.getFofoId(), 0d);
|
| - |
|
700 |
|
| - |
|
701 |
}
|
| - |
|
702 |
List<Integer> valSetOne = new ArrayList<Integer>();
|
| - |
|
703 |
|
| - |
|
704 |
for (Offermargin om : offerMargin) {
|
| - |
|
705 |
|
| - |
|
706 |
if (value.get(op.getFofoId()) <= om.getValue()) {
|
| - |
|
707 |
LOGGER.info("om1" + om.getMargin());
|
| - |
|
708 |
shortageAmount.put(op.getFofoId(), om.getValue() - value.get(op.getFofoId()).intValue());
|
| - |
|
709 |
valSetOne.add(om.getMargin());
|
| - |
|
710 |
partnerMarginMap.put(op.getFofoId(), valSetOne);
|
| - |
|
711 |
|
| - |
|
712 |
break;
|
| - |
|
713 |
} else {
|
| - |
|
714 |
LOGGER.info("om2" + om.getMargin());
|
| - |
|
715 |
valSetOne.add(om.getMargin());
|
| - |
|
716 |
|
| - |
|
717 |
int shortage = om.getValue() - value.get(op.getFofoId()).intValue();
|
| - |
|
718 |
|
| - |
|
719 |
if (shortage < 0) {
|
| - |
|
720 |
shortageAmount.put(op.getFofoId(), 0);
|
| - |
|
721 |
}
|
| - |
|
722 |
|
| - |
|
723 |
partnerMarginMap.put(op.getFofoId(), valSetOne);
|
| - |
|
724 |
|
| - |
|
725 |
}
|
| - |
|
726 |
}
|
| - |
|
727 |
|
| - |
|
728 |
}
|
| - |
|
729 |
|
| - |
|
730 |
LOGGER.info("partnerMarginMap" + partnerMarginMap);
|
| - |
|
731 |
LOGGER.info("partnerValueMap" + partnerValueMap);
|
| - |
|
732 |
LOGGER.info("shortageAmount" + shortageAmount);
|
| - |
|
733 |
|
| - |
|
734 |
ItemTypeParams scp = gson.fromJson(offer.getItemParam(), ItemTypeParams.class);
|
| - |
|
735 |
if (offer.getItemCriteria().equals(ItemCriteriaType.Multiple_Brand)) {
|
| - |
|
736 |
List<String> brands = scp.getBrands();
|
| - |
|
737 |
model.addAttribute("brands", brands);
|
| - |
|
738 |
}
|
| - |
|
739 |
if (offer.getItemCriteria().equals(ItemCriteriaType.Item_Model)) {
|
| - |
|
740 |
List<Integer> catalogIds = scp.getCatalogId();
|
| - |
|
741 |
List<Item> newList = new ArrayList<>();
|
| - |
|
742 |
Set<Integer> catalogId = new HashSet<>();
|
| - |
|
743 |
List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds.stream().collect(Collectors.toSet()));
|
| - |
|
744 |
for (Item item : items) {
|
| - |
|
745 |
if (catalogId.add(item.getCatalogItemId())) {
|
| - |
|
746 |
newList.add(item);
|
| - |
|
747 |
}
|
| - |
|
748 |
}
|
| - |
|
749 |
model.addAttribute("items", newList);
|
| - |
|
750 |
}
|
| - |
|
751 |
model.addAttribute("partnerMarginMap", partnerMarginMap);
|
| - |
|
752 |
model.addAttribute("partnerValueMap", partnerValueMap);
|
| - |
|
753 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
| - |
|
754 |
model.addAttribute("offerMargin", offerMargin);
|
| - |
|
755 |
model.addAttribute("offer", offer);
|
| - |
|
756 |
model.addAttribute("shortageAmount", shortageAmount);
|
| - |
|
757 |
|
| - |
|
758 |
return "offer_margin_detail";
|
| - |
|
759 |
|
| - |
|
760 |
}
|
| - |
|
761 |
|
| 598 |
}
|
762 |
}
|
| 599 |
|
763 |
|