| Line 8... |
Line 8... |
| 8 |
import java.util.HashMap;
|
8 |
import java.util.HashMap;
|
| 9 |
import java.util.HashSet;
|
9 |
import java.util.HashSet;
|
| 10 |
import java.util.List;
|
10 |
import java.util.List;
|
| 11 |
import java.util.Map;
|
11 |
import java.util.Map;
|
| 12 |
import java.util.Set;
|
12 |
import java.util.Set;
|
| - |
|
13 |
import java.util.stream.Collectors;
|
| 13 |
|
14 |
|
| 14 |
import javax.servlet.http.HttpServletRequest;
|
15 |
import javax.servlet.http.HttpServletRequest;
|
| 15 |
import javax.transaction.Transactional;
|
16 |
import javax.transaction.Transactional;
|
| 16 |
|
17 |
|
| 17 |
import org.apache.logging.log4j.LogManager;
|
18 |
import org.apache.logging.log4j.LogManager;
|
| Line 27... |
Line 28... |
| 27 |
import org.springframework.web.bind.annotation.RequestBody;
|
28 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 28 |
import org.springframework.web.bind.annotation.RequestMapping;
|
29 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 29 |
import org.springframework.web.bind.annotation.RequestMethod;
|
30 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 30 |
import org.springframework.web.bind.annotation.RequestParam;
|
31 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 31 |
|
32 |
|
| - |
|
33 |
import com.google.gson.Gson;
|
| 32 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
34 |
import com.spice.profitmandi.common.enumuration.DateTimePattern;
|
| 33 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
36 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 34 |
import com.spice.profitmandi.common.model.MapWrapper;
|
37 |
import com.spice.profitmandi.common.model.MapWrapper;
|
| 35 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
38 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 36 |
import com.spice.profitmandi.common.model.SchemeItems;
|
39 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 37 |
import com.spice.profitmandi.common.model.SchemeModel;
|
40 |
import com.spice.profitmandi.common.model.SchemeModel;
|
| 38 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
41 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 39 |
import com.spice.profitmandi.common.util.StringUtils;
|
42 |
import com.spice.profitmandi.common.util.StringUtils;
|
| 40 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
43 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| - |
|
44 |
import com.spice.profitmandi.dao.entity.catalog.Offer;
|
| - |
|
45 |
import com.spice.profitmandi.dao.entity.catalog.OfferPartner;
|
| - |
|
46 |
import com.spice.profitmandi.dao.entity.catalog.Offermargin;
|
| 41 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
47 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| 42 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
48 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 43 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
49 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| - |
|
50 |
import com.spice.profitmandi.dao.enumuration.catalog.ItemCriteriaType;
|
| - |
|
51 |
import com.spice.profitmandi.dao.model.AmountMarginModel;
|
| - |
|
52 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| 44 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
53 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| - |
|
54 |
import com.spice.profitmandi.dao.model.ItemTypeParams;
|
| - |
|
55 |
import com.spice.profitmandi.dao.model.SimpleItemType;
|
| - |
|
56 |
import com.spice.profitmandi.dao.repository.catalog.OfferMarginRepository;
|
| - |
|
57 |
import com.spice.profitmandi.dao.repository.catalog.OfferPartnerRepository;
|
| - |
|
58 |
import com.spice.profitmandi.dao.repository.catalog.OfferRepository;
|
| 45 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
59 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| 46 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
60 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| - |
|
61 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| - |
|
62 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| 47 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
63 |
import com.spice.profitmandi.dao.repository.dtr.RoleRepository;
|
| 48 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
64 |
import com.spice.profitmandi.dao.repository.fofo.PurchaseRepository;
|
| 49 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
65 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 50 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
66 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 51 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
67 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 52 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
68 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| - |
|
69 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 53 |
import com.spice.profitmandi.web.model.LoginDetails;
|
70 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 54 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
71 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 55 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
72 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 56 |
|
73 |
|
| 57 |
@Controller
|
74 |
@Controller
|
| Line 84... |
Line 101... |
| 84 |
|
101 |
|
| 85 |
@Autowired
|
102 |
@Autowired
|
| 86 |
private RoleManager roleManager;
|
103 |
private RoleManager roleManager;
|
| 87 |
|
104 |
|
| 88 |
@Autowired
|
105 |
@Autowired
|
| 89 |
PurchaseRepository purchaseRepository;
|
106 |
private PurchaseRepository purchaseRepository;
|
| 90 |
|
107 |
|
| 91 |
@Autowired
|
108 |
@Autowired
|
| 92 |
private RoleRepository roleRepository;
|
109 |
private RoleRepository roleRepository;
|
| 93 |
|
110 |
|
| 94 |
@Autowired
|
111 |
@Autowired
|
| 95 |
private ResponseSender<?> responseSender;
|
112 |
private ResponseSender<?> responseSender;
|
| 96 |
|
113 |
|
| - |
|
114 |
@Autowired
|
| - |
|
115 |
private OfferRepository offerRepository;
|
| - |
|
116 |
|
| - |
|
117 |
@Autowired
|
| - |
|
118 |
private OfferMarginRepository offerMarginRepository;
|
| - |
|
119 |
|
| - |
|
120 |
@Autowired
|
| - |
|
121 |
private FofoStoreRepository fofoStoreRepository;
|
| - |
|
122 |
|
| - |
|
123 |
@Autowired
|
| - |
|
124 |
private OfferPartnerRepository offerPartnerRepository;
|
| - |
|
125 |
|
| - |
|
126 |
@Autowired
|
| - |
|
127 |
private Gson gson;
|
| - |
|
128 |
|
| - |
|
129 |
@Autowired
|
| - |
|
130 |
private RetailerService retailerService;
|
| - |
|
131 |
|
| - |
|
132 |
@Autowired
|
| - |
|
133 |
private Mongo mongoClient;
|
| - |
|
134 |
|
| 97 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
135 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 98 |
public String createScheme(HttpServletRequest request, Model model) {
|
136 |
public String createScheme(HttpServletRequest request, Model model) {
|
| 99 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
137 |
// Map<Integer, String> itemIdItemDescriptionMap =
|
| 100 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
138 |
// inventoryService.getAllItemIdItemDescriptionMap();
|
| 101 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
139 |
// model.addAttribute("itemIdItemDescriptionMap", itemIdItemDescriptionMap);
|
| Line 487... |
Line 525... |
| 487 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
525 |
model.addAttribute("roleType", roleManager.isAdmin(loginDetails.getRoleIds()));
|
| 488 |
return "schemes-paginated";
|
526 |
return "schemes-paginated";
|
| 489 |
|
527 |
|
| 490 |
}
|
528 |
}
|
| 491 |
|
529 |
|
| - |
|
530 |
@RequestMapping(value = "/getCreateOffer", method = RequestMethod.GET)
|
| - |
|
531 |
public String getCreateOffer(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| - |
|
532 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
533 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
| - |
|
534 |
.collect(Collectors.toList());
|
| - |
|
535 |
|
| - |
|
536 |
List<String> brands = mongoClient.getMongoBrands(loginDetails.getFofoId(), null, 3).stream()
|
| - |
|
537 |
.map(x -> (String) x.get("name")).collect(Collectors.toList());
|
| - |
|
538 |
|
| - |
|
539 |
Map<Integer, CustomRetailer> customRetailersMap = retailerService.getFofoRetailers(fofoIds);
|
| - |
|
540 |
|
| - |
|
541 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
| - |
|
542 |
model.addAttribute("itemCriteriaType", ItemCriteriaType.values());
|
| - |
|
543 |
model.addAttribute("brands", brands);
|
| - |
|
544 |
return "scheme_offer";
|
| - |
|
545 |
|
| - |
|
546 |
}
|
| - |
|
547 |
|
| - |
|
548 |
@RequestMapping(value = "/createOffer", method = RequestMethod.POST)
|
| - |
|
549 |
public String createOffer(HttpServletRequest request, @RequestBody CreateOfferRequest createOfferRequest,
|
| - |
|
550 |
Model model) throws Exception {
|
| - |
|
551 |
LOGGER.info("createOfferRequest" + createOfferRequest.getAmountOffer());
|
| - |
|
552 |
|
| - |
|
553 |
Offer offer = new Offer();
|
| - |
|
554 |
offer.setName(createOfferRequest.getName());
|
| - |
|
555 |
offer.setDescription(createOfferRequest.getDescription());
|
| - |
|
556 |
offer.setItemCreteria(createOfferRequest.getItemCriteria());
|
| - |
|
557 |
offer.setTargetType(createOfferRequest.getTargetType());
|
| - |
|
558 |
offer.setAmountType(createOfferRequest.getAmountType());
|
| - |
|
559 |
offer.setStartDateTime(createOfferRequest.getStartDate());
|
| - |
|
560 |
offer.setEndDateTime(createOfferRequest.getEndDate());
|
| - |
|
561 |
offer.setPrice(createOfferRequest.getPrice());
|
| - |
|
562 |
offer.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
563 |
|
| - |
|
564 |
if (createOfferRequest.getItemCriteria().equals(ItemCriteriaType.Item_Model)) {
|
| - |
|
565 |
ItemTypeParams itemTypeParams = new ItemTypeParams();
|
| - |
|
566 |
itemTypeParams.setCatalogId(createOfferRequest.getCatalogIds());
|
| - |
|
567 |
SimpleItemType sit = new SimpleItemType(itemTypeParams);
|
| - |
|
568 |
sit.setItemTypeParams(itemTypeParams);
|
| - |
|
569 |
offer.setItemParam(gson.toJson(itemTypeParams));
|
| - |
|
570 |
} else if (createOfferRequest.getItemCriteria().equals(ItemCriteriaType.Multiple_Brand)) {
|
| - |
|
571 |
ItemTypeParams itemTypeParams = new ItemTypeParams();
|
| - |
|
572 |
itemTypeParams.setBrands(createOfferRequest.getBrands());
|
| - |
|
573 |
SimpleItemType sit = new SimpleItemType(itemTypeParams);
|
| - |
|
574 |
sit.setItemTypeParams(itemTypeParams);
|
| - |
|
575 |
offer.setItemParam(gson.toJson(itemTypeParams));
|
| - |
|
576 |
}
|
| - |
|
577 |
|
| - |
|
578 |
offerRepository.persist(offer);
|
| - |
|
579 |
for (Integer fofoId : createOfferRequest.getFofoIds()) {
|
| - |
|
580 |
OfferPartner op = new OfferPartner();
|
| - |
|
581 |
op.setFofoId(fofoId);
|
| - |
|
582 |
op.setOfferId(offer.getId());
|
| - |
|
583 |
offerPartnerRepository.persist(op);
|
| - |
|
584 |
}
|
| - |
|
585 |
for (AmountMarginModel amm : createOfferRequest.getAmountOffer()) {
|
| - |
|
586 |
Offermargin om = new Offermargin();
|
| - |
|
587 |
om.setValue(amm.getValue());
|
| - |
|
588 |
om.setMargin(amm.getMargin());
|
| - |
|
589 |
om.setOfferId(offer.getId());
|
| - |
|
590 |
offerMarginRepository.persist(om);
|
| - |
|
591 |
}
|
| - |
|
592 |
|
| - |
|
593 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| - |
|
594 |
return "response";
|
| - |
|
595 |
|
| - |
|
596 |
}
|
| - |
|
597 |
|
| 492 |
}
|
598 |
}
|
| 493 |
|
599 |
|