| 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;
|
3 |
import java.io.Serializable;
|
| - |
|
4 |
import java.time.LocalDate;
|
| 4 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 5 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 6 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| - |
|
8 |
import java.util.HashMap;
|
| 7 |
import java.util.List;
|
9 |
import java.util.List;
|
| 8 |
import java.util.Map;
|
10 |
import java.util.Map;
|
| - |
|
11 |
import java.util.Map.Entry;
|
| 9 |
import java.util.Set;
|
12 |
import java.util.Set;
|
| 10 |
import java.util.stream.Collectors;
|
13 |
import java.util.stream.Collectors;
|
| 11 |
|
14 |
|
| 12 |
import javax.servlet.http.HttpServletRequest;
|
15 |
import javax.servlet.http.HttpServletRequest;
|
| 13 |
|
16 |
|
| Line 29... |
Line 32... |
| 29 |
import org.springframework.web.bind.annotation.RequestMethod;
|
32 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 30 |
import org.springframework.web.bind.annotation.RequestParam;
|
33 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 31 |
|
34 |
|
| 32 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
35 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 33 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
36 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| - |
|
37 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 34 |
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
|
38 |
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
|
| 35 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
39 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
| 36 |
import com.spice.profitmandi.common.model.PriceDropImeisModel;
|
40 |
import com.spice.profitmandi.common.model.PriceDropImeisModel;
|
| 37 |
import com.spice.profitmandi.common.model.PriceDropModel;
|
41 |
import com.spice.profitmandi.common.model.PriceDropModel;
|
| 38 |
import com.spice.profitmandi.common.model.PriceDropProcessModel;
|
42 |
import com.spice.profitmandi.common.model.PriceDropProcessModel;
|
| 39 |
import com.spice.profitmandi.common.services.ReporticoService;
|
43 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 40 |
import com.spice.profitmandi.common.util.FileUtil;
|
44 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 41 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
45 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| - |
|
46 |
import com.spice.profitmandi.common.util.Utils;
|
| 42 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
47 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 43 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
48 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| - |
|
49 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| 44 |
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
|
50 |
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
|
| 45 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
51 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
| 46 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
52 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 47 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
53 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 48 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
54 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| - |
|
55 |
import com.spice.profitmandi.dao.model.PriceCircularModel;
|
| 49 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
56 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 50 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
57 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| - |
|
58 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| - |
|
59 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| 51 |
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
|
60 |
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
|
| 52 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
61 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
| 53 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
62 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
| 54 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
63 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
| 55 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
64 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 56 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
65 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 57 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
66 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 58 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
67 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 59 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
68 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| - |
|
69 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 60 |
import com.spice.profitmandi.service.wallet.WalletService;
|
70 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| - |
|
71 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| - |
|
72 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 61 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
73 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 62 |
|
74 |
|
| 63 |
@Controller
|
75 |
@Controller
|
| 64 |
@Transactional(rollbackFor = Throwable.class)
|
76 |
@Transactional(rollbackFor = Throwable.class)
|
| 65 |
public class PriceDropController {
|
77 |
public class PriceDropController {
|
| Line 111... |
Line 123... |
| 111 |
ReporticoService reporticoService;
|
123 |
ReporticoService reporticoService;
|
| 112 |
|
124 |
|
| 113 |
@Autowired
|
125 |
@Autowired
|
| 114 |
LineItemImeisRepository lineItemImeisRepository;
|
126 |
LineItemImeisRepository lineItemImeisRepository;
|
| 115 |
|
127 |
|
| - |
|
128 |
@Autowired
|
| - |
|
129 |
private Mongo mongoClient;
|
| - |
|
130 |
|
| - |
|
131 |
@Autowired
|
| - |
|
132 |
private CookiesProcessor cookiesProcessor;
|
| - |
|
133 |
|
| - |
|
134 |
@Autowired
|
| - |
|
135 |
private PartnerTypeChangeService partnerTypeChangeService;
|
| - |
|
136 |
|
| - |
|
137 |
@Autowired
|
| - |
|
138 |
private RetailerService retailerService;
|
| - |
|
139 |
|
| 116 |
@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
|
140 |
@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
|
| 117 |
public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
|
141 |
public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
|
| 118 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
142 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 119 |
Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
143 |
Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 120 |
List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
|
144 |
List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
|
| Line 151... |
Line 175... |
| 151 |
model.addAttribute("response", mvcResponseSender.createResponseString(pm));
|
175 |
model.addAttribute("response", mvcResponseSender.createResponseString(pm));
|
| 152 |
return "response";
|
176 |
return "response";
|
| 153 |
}
|
177 |
}
|
| 154 |
|
178 |
|
| 155 |
@RequestMapping(value = "/item", method = RequestMethod.GET)
|
179 |
@RequestMapping(value = "/item", method = RequestMethod.GET)
|
| 156 |
public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query,@RequestParam boolean anyColor) throws Throwable {
|
180 |
public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query,
|
| - |
|
181 |
@RequestParam boolean anyColor) throws Throwable {
|
| 157 |
String query1 = query.toLowerCase();
|
182 |
String query1 = query.toLowerCase();
|
| 158 |
|
183 |
|
| 159 |
List<ItemDescriptionModel> partnersItemDescription = inventoryService.getAllPartnerItemStringDescription(anyColor)
|
184 |
List<ItemDescriptionModel> partnersItemDescription = inventoryService
|
| - |
|
185 |
.getAllPartnerItemStringDescription(anyColor).parallelStream()
|
| 160 |
.parallelStream().filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
|
186 |
.filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
|
| 161 |
.collect(Collectors.toList());
|
187 |
.collect(Collectors.toList());
|
| 162 |
LOGGER.info("partnersItemDescription"+partnersItemDescription);
|
188 |
LOGGER.info("partnersItemDescription" + partnersItemDescription);
|
| 163 |
|
189 |
|
| 164 |
model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
|
190 |
model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
|
| 165 |
return "response";
|
191 |
return "response";
|
| 166 |
}
|
192 |
}
|
| 167 |
|
193 |
|
| Line 229... |
Line 255... |
| 229 |
@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
|
255 |
@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
|
| 230 |
public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
|
256 |
public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
|
| 231 |
Model model) throws Exception {
|
257 |
Model model) throws Exception {
|
| 232 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
|
258 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
|
| 233 |
boolean response = false;
|
259 |
boolean response = false;
|
| 234 |
if(priceDrop.getPartnerPayout()==0) {
|
260 |
if (priceDrop.getPartnerPayout() == 0) {
|
| 235 |
priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
|
261 |
priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
|
| 236 |
}
|
262 |
}
|
| 237 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
263 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
| 238 |
priceDropRepository.persist(priceDrop);
|
264 |
priceDropRepository.persist(priceDrop);
|
| 239 |
priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
|
265 |
priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
|
| 240 |
response = true;
|
266 |
response = true;
|
| 241 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
267 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
| 242 |
return "response";
|
268 |
return "response";
|
| 243 |
}
|
269 |
}
|
| 244 |
|
270 |
|
| 245 |
@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
|
271 |
@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
|
| Line 439... |
Line 465... |
| 439 |
return true;
|
465 |
return true;
|
| 440 |
}
|
466 |
}
|
| 441 |
return false;
|
467 |
return false;
|
| 442 |
}
|
468 |
}
|
| 443 |
|
469 |
|
| - |
|
470 |
@RequestMapping(value = "/priceCircular")
|
| - |
|
471 |
public String priceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| - |
|
472 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
| - |
|
473 |
Set<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
| - |
|
474 |
.collect(Collectors.toSet());
|
| - |
|
475 |
Map<Integer, CustomRetailer> customRetailers = retailerService.getFofoRetailers(true);
|
| - |
|
476 |
Map<Integer, PartnerType> fofoIdPartnerTypeMap = new HashMap<>();
|
| - |
|
477 |
|
| - |
|
478 |
for (Entry<Integer, CustomRetailer> customRetailer : customRetailers.entrySet()) {
|
| - |
|
479 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(customRetailer.getKey(), LocalDate.now());
|
| - |
|
480 |
fofoIdPartnerTypeMap.put(customRetailer.getKey(), partnerType);
|
| - |
|
481 |
}
|
| - |
|
482 |
|
| - |
|
483 |
Map<PartnerType, List<Integer>> partnerTypePartnersMap = fofoIdPartnerTypeMap.entrySet().stream().collect(
|
| - |
|
484 |
Collectors.groupingBy(x -> x.getValue(), Collectors.mapping(x -> x.getKey(), Collectors.toList())));
|
| - |
|
485 |
model.addAttribute("brands", brands);
|
| - |
|
486 |
|
| - |
|
487 |
return "price-circular";
|
| - |
|
488 |
}
|
| - |
|
489 |
|
| - |
|
490 |
@RequestMapping(value = "/partnerPriceCircular")
|
| - |
|
491 |
public String partnerPriceCircular(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| - |
|
492 |
int fofoId = Utils.SYSTEM_PARTNER_ID;
|
| - |
|
493 |
Set<String> brands = mongoClient.getMongoBrands(fofoId, null, 3).stream().map(x -> (String) x.get("name"))
|
| - |
|
494 |
.collect(Collectors.toSet());
|
| - |
|
495 |
brands.addAll(mongoClient.getMongoBrands(fofoId, null, 6).stream().map(x -> (String) x.get("name"))
|
| - |
|
496 |
.collect(Collectors.toSet()));
|
| - |
|
497 |
model.addAttribute("brands", brands);
|
| - |
|
498 |
model.addAttribute("date", LocalDate.now());
|
| - |
|
499 |
|
| - |
|
500 |
return "partner-price-circular";
|
| - |
|
501 |
}
|
| - |
|
502 |
|
| - |
|
503 |
@RequestMapping(value = "/priceCircularByBrand")
|
| - |
|
504 |
public String priceCircularByBrand(HttpServletRequest request, @RequestParam String brand, Model model)
|
| - |
|
505 |
throws ProfitMandiBusinessException {
|
| - |
|
506 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| - |
|
507 |
|
| - |
|
508 |
PartnerType partnerType = partnerTypeChangeService.getTypeOnDate(loginDetails.getFofoId(), LocalDate.now());
|
| - |
|
509 |
List<PartnerType> partnerTypes = new ArrayList<>();
|
| - |
|
510 |
partnerTypes.add(partnerType);
|
| - |
|
511 |
partnerTypes.add(PartnerType.ALL);
|
| - |
|
512 |
List<PriceCircularModel> priceCircular = tagListingRepository.getPriceCircularByBrandAndType(partnerTypes,
|
| - |
|
513 |
brand, LocalDateTime.now(), LocalDateTime.now().plusDays(1).toLocalDate().atStartOfDay());
|
| - |
|
514 |
|
| - |
|
515 |
for (PriceCircularModel pc : priceCircular) {
|
| - |
|
516 |
|
| - |
|
517 |
Long totalScheme = pc.getBasePayout() + pc.getCashDiscount() + pc.getTertiaryPayout()
|
| - |
|
518 |
+ pc.getHygienePayout() + pc.getCategoryPayout() + pc.getInvestmentPayout() + pc.getModelSpecfic();
|
| - |
|
519 |
pc.setTotalScheme(totalScheme);
|
| - |
|
520 |
long netprice = pc.getSellingPrice() - pc.getTotalScheme();
|
| - |
|
521 |
pc.setNetPrice(netprice);
|
| - |
|
522 |
int mopdpdiff = pc.getMop() - pc.getSellingPrice();
|
| - |
|
523 |
pc.setMopdp(mopdpdiff);
|
| - |
|
524 |
pc.setNetPrice2((int) pc.getNetPrice() - pc.getMopdp());
|
| - |
|
525 |
long totalProfit = totalScheme + mopdpdiff;
|
| - |
|
526 |
double rouoff = totalProfit / (pc.getSellingPrice() / 1.18) * 100;
|
| - |
|
527 |
double roundOff = Math.round(rouoff * 100.0) / 100.0;
|
| - |
|
528 |
pc.setNetMargin(roundOff);
|
| - |
|
529 |
|
| - |
|
530 |
}
|
| - |
|
531 |
LOGGER.info("priceCircular" + priceCircular);
|
| - |
|
532 |
model.addAttribute("priceCircular", priceCircular);
|
| - |
|
533 |
return "price-circular-detail";
|
| - |
|
534 |
}
|
| - |
|
535 |
|
| 444 |
}
|
536 |
}
|