| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import com.google.gson.Gson;
|
3 |
import com.google.gson.Gson;
|
| - |
|
4 |
import com.spice.profitmandi.common.enumuration.OfferType;
|
| 4 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
5 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 5 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
6 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 6 |
import com.spice.profitmandi.common.model.*;
|
7 |
import com.spice.profitmandi.common.model.*;
|
| 7 |
import com.spice.profitmandi.common.services.ReporticoService;
|
8 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 8 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
9 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| Line 1442... |
Line 1443... |
| 1442 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
1443 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
| 1443 |
}
|
1444 |
}
|
| 1444 |
|
1445 |
|
| 1445 |
@RequestMapping(value = "/getCustomerOffer", method = RequestMethod.GET)
|
1446 |
@RequestMapping(value = "/getCustomerOffer", method = RequestMethod.GET)
|
| 1446 |
public String getCustomerOffer(HttpServletRequest request,
|
1447 |
public String getCustomerOffer(HttpServletRequest request,
|
| 1447 |
@RequestParam(name = "searchModel", required = false, defaultValue = "0") int searchModel, Model model)
|
1448 |
@RequestParam(name = "searchModel", required = false, defaultValue = "0") int searchModel, @RequestParam(name = "startDate", required = false) LocalDateTime startDate, @RequestParam(name = "endDate", required = false) LocalDateTime endDate, Model model)
|
| 1448 |
throws ProfitMandiBusinessException {
|
1449 |
throws ProfitMandiBusinessException {
|
| 1449 |
List<CustomerOffer> customerOffers = null;
|
1450 |
List<CustomerOffer> customerOffers = null;
|
| 1450 |
if (searchModel > 0) {
|
1451 |
if (searchModel > 0) {
|
| 1451 |
|
1452 |
|
| 1452 |
Item item = itemRepository.selectAllByCatalogItemId(searchModel).get(0);
|
1453 |
Item item = itemRepository.selectAllByCatalogItemId(searchModel).get(0);
|
| 1453 |
customerOffers = customerOfferRepository.selectActiveOfferByModel(searchModel, LocalDate.now());
|
1454 |
customerOffers = customerOfferRepository.selectActiveOfferByModel(searchModel, LocalDate.now());
|
| 1454 |
model.addAttribute("modelName", item.getItemDescriptionNoColor());
|
1455 |
model.addAttribute("modelName", item.getItemDescriptionNoColor());
|
| - |
|
1456 |
} else if (startDate != null && endDate != null) {
|
| - |
|
1457 |
customerOffers = customerOfferRepository.selectOffersByDates(startDate, endDate);
|
| 1455 |
} else {
|
1458 |
} else {
|
| - |
|
1459 |
if (startDate == null) {
|
| - |
|
1460 |
startDate = LocalDateTime.now().minusMonths(1); // One month ago from today
|
| - |
|
1461 |
}
|
| - |
|
1462 |
if (endDate == null) {
|
| - |
|
1463 |
endDate = LocalDateTime.now(); // Current date and time
|
| - |
|
1464 |
}
|
| 1456 |
customerOffers = customerOfferRepository.selectAll();
|
1465 |
customerOffers = customerOfferRepository.selectOffersByDates(startDate, endDate);
|
| 1457 |
}
|
1466 |
}
|
| 1458 |
|
1467 |
|
| 1459 |
LOGGER.info("customerOffers" + customerOffers);
|
1468 |
LOGGER.info("customerOffers" + customerOffers);
|
| 1460 |
|
1469 |
|
| 1461 |
for (CustomerOffer customerOffer : customerOffers) {
|
1470 |
for (CustomerOffer customerOffer : customerOffers) {
|
| Line 1509... |
Line 1518... |
| 1509 |
@RequestMapping(value = "/customerOffer/downloadTemplate", method = RequestMethod.GET)
|
1518 |
@RequestMapping(value = "/customerOffer/downloadTemplate", method = RequestMethod.GET)
|
| 1510 |
public ResponseEntity<?> downloadCustomerOfferTemplate(HttpServletRequest request) throws Exception {
|
1519 |
public ResponseEntity<?> downloadCustomerOfferTemplate(HttpServletRequest request) throws Exception {
|
| 1511 |
List<List<?>> rows = new ArrayList<>();
|
1520 |
List<List<?>> rows = new ArrayList<>();
|
| 1512 |
|
1521 |
|
| 1513 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("id",
|
1522 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("id",
|
| 1514 |
"Catalog Id", "Scheme Payout", "Dealer Payout", "Start Date (dd-mm-yyyy)", "End Date (dd-mm-yyyy)"),
|
1523 |
"Catalog Id", "Scheme Payout", "Dealer Payout", "Start Date (dd-mm-yyyy)", "End Date (dd-mm-yyyy)", "Offer Type"),
|
| 1515 |
rows);
|
1524 |
rows);
|
| 1516 |
|
1525 |
|
| 1517 |
final HttpHeaders headers = new HttpHeaders();
|
1526 |
final HttpHeaders headers = new HttpHeaders();
|
| 1518 |
headers.set("Content-Type", "text/csv");
|
1527 |
headers.set("Content-Type", "text/csv");
|
| 1519 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
1528 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
| Line 1541... |
Line 1550... |
| 1541 |
if (coi == null) {
|
1550 |
if (coi == null) {
|
| 1542 |
coi = new CustomerOfferItem();
|
1551 |
coi = new CustomerOfferItem();
|
| 1543 |
coi.setCatalogId(Integer.parseInt(record.get(1)));
|
1552 |
coi.setCatalogId(Integer.parseInt(record.get(1)));
|
| 1544 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
1553 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
| 1545 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
1554 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
| - |
|
1555 |
coi.setOfferType(OfferType.valueOf(record.get(6)));
|
| 1546 |
coi.setCustomerOfferId(offerId);
|
1556 |
coi.setCustomerOfferId(offerId);
|
| 1547 |
coi.setCreatedTimestamp(LocalDateTime.now());
|
1557 |
coi.setCreatedTimestamp(LocalDateTime.now());
|
| 1548 |
|
1558 |
|
| 1549 |
customerOfferItemRepository.persist(coi);
|
1559 |
customerOfferItemRepository.persist(coi);
|
| 1550 |
|
1560 |
|
| 1551 |
}
|
1561 |
}
|
| 1552 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
1562 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
| 1553 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
1563 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
| - |
|
1564 |
coi.setOfferType(OfferType.valueOf(record.get(6)));
|
| 1554 |
coi.setCustomerOfferId(offerId);
|
1565 |
coi.setCustomerOfferId(offerId);
|
| 1555 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
1566 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
| 1556 |
|
1567 |
|
| 1557 |
LOGGER.info(record.get(4));
|
1568 |
LOGGER.info(record.get(4));
|
| 1558 |
|
1569 |
|
| Line 1622... |
Line 1633... |
| 1622 |
LocalDate endDate = customerOfferItemModel.getEndDate().toLocalDate();
|
1633 |
LocalDate endDate = customerOfferItemModel.getEndDate().toLocalDate();
|
| 1623 |
CustomerOfferItem coi = new CustomerOfferItem();
|
1634 |
CustomerOfferItem coi = new CustomerOfferItem();
|
| 1624 |
coi.setCatalogId(customerOfferItemModel.getCatalogId());
|
1635 |
coi.setCatalogId(customerOfferItemModel.getCatalogId());
|
| 1625 |
coi.setSchemePayout(customerOfferItemModel.getSchemePayout());
|
1636 |
coi.setSchemePayout(customerOfferItemModel.getSchemePayout());
|
| 1626 |
coi.setDealerPayout(customerOfferItemModel.getDealerPayout());
|
1637 |
coi.setDealerPayout(customerOfferItemModel.getDealerPayout());
|
| - |
|
1638 |
coi.setOfferType(customerOfferItemModel.getOfferType());
|
| 1627 |
coi.setCustomerOfferId(customerOfferItemModel.getOfferId());
|
1639 |
coi.setCustomerOfferId(customerOfferItemModel.getOfferId());
|
| 1628 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
1640 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
| 1629 |
coi.setCreatedTimestamp(LocalDateTime.now());
|
1641 |
coi.setCreatedTimestamp(LocalDateTime.now());
|
| 1630 |
|
1642 |
|
| 1631 |
if ((startDate.equals(customerOffer.getStartDate().toLocalDate())
|
1643 |
if ((startDate.equals(customerOffer.getStartDate().toLocalDate())
|
| Line 1671... |
Line 1683... |
| 1671 |
List<List<?>> rows = new ArrayList<>();
|
1683 |
List<List<?>> rows = new ArrayList<>();
|
| 1672 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
1684 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
| 1673 |
|
1685 |
|
| 1674 |
for (CustomerOfferItem coi : cois) {
|
1686 |
for (CustomerOfferItem coi : cois) {
|
| 1675 |
rows.add(Arrays.asList(coi.getId(), coi.getCatalogId(), coi.getSchemePayout(), coi.getDealerPayout(),
|
1687 |
rows.add(Arrays.asList(coi.getId(), coi.getCatalogId(), coi.getSchemePayout(), coi.getDealerPayout(),
|
| 1676 |
coi.getStartDate().format(formatter), coi.getEndDate().format(formatter)));
|
1688 |
coi.getStartDate().format(formatter), coi.getEndDate().format(formatter), coi.getOfferType()));
|
| 1677 |
|
1689 |
|
| 1678 |
}
|
1690 |
}
|
| 1679 |
|
1691 |
|
| 1680 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
1692 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 1681 |
Arrays.asList("id", "Catalog Id", "Scheme Payout", "Dealer Payout", "Start Date", "End Date"), rows);
|
1693 |
Arrays.asList("id", "Catalog Id", "Scheme Payout", "Dealer Payout", "Start Date", "End Date", "Offer Type"), rows);
|
| 1682 |
|
1694 |
|
| 1683 |
final HttpHeaders headers = new HttpHeaders();
|
1695 |
final HttpHeaders headers = new HttpHeaders();
|
| 1684 |
headers.set("Content-Type", "text/csv");
|
1696 |
headers.set("Content-Type", "text/csv");
|
| 1685 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
1697 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
| 1686 |
headers.setContentLength(baos.toByteArray().length);
|
1698 |
headers.setContentLength(baos.toByteArray().length);
|
| Line 1699... |
Line 1711... |
| 1699 |
List<Integer> catalogIds = customerOfferItems.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
|
1711 |
List<Integer> catalogIds = customerOfferItems.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
|
| 1700 |
|
1712 |
|
| 1701 |
Map<Integer, List<Item>> catalogItemMap = itemRepository.selectAllByCatalogIds(new HashSet<>(catalogIds))
|
1713 |
Map<Integer, List<Item>> catalogItemMap = itemRepository.selectAllByCatalogIds(new HashSet<>(catalogIds))
|
| 1702 |
.stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
1714 |
.stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
| 1703 |
|
1715 |
|
| - |
|
1716 |
List<OfferType> offerTypes = Arrays.asList(OfferType.values());
|
| - |
|
1717 |
|
| 1704 |
model.addAttribute("catalogItemMap", catalogItemMap);
|
1718 |
model.addAttribute("catalogItemMap", catalogItemMap);
|
| 1705 |
|
1719 |
|
| 1706 |
model.addAttribute("offerId", offerId);
|
1720 |
model.addAttribute("offerId", offerId);
|
| 1707 |
|
1721 |
|
| 1708 |
model.addAttribute("customerOfferItems", customerOfferItems);
|
1722 |
model.addAttribute("customerOfferItems", customerOfferItems);
|
| - |
|
1723 |
|
| - |
|
1724 |
model.addAttribute("offerTypes", offerTypes);
|
| - |
|
1725 |
|
| 1709 |
return "customer-offer-item";
|
1726 |
return "customer-offer-item";
|
| 1710 |
|
1727 |
|
| 1711 |
}
|
1728 |
}
|
| 1712 |
|
1729 |
|
| 1713 |
@RequestMapping(value = "/expiredCustomerOfferItem", method = RequestMethod.POST)
|
1730 |
@RequestMapping(value = "/expiredCustomerOfferItem", method = RequestMethod.POST)
|