| 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;
|
| - |
|
4 |
import java.io.ByteArrayOutputStream;
|
| - |
|
5 |
import java.io.InputStream;
|
| - |
|
6 |
import java.time.LocalDate;
|
| - |
|
7 |
import java.time.LocalDateTime;
|
| - |
|
8 |
import java.time.LocalTime;
|
| - |
|
9 |
import java.time.Month;
|
| - |
|
10 |
import java.time.YearMonth;
|
| - |
|
11 |
import java.time.format.DateTimeFormatter;
|
| - |
|
12 |
import java.util.ArrayList;
|
| - |
|
13 |
import java.util.Arrays;
|
| - |
|
14 |
import java.util.Comparator;
|
| - |
|
15 |
import java.util.HashMap;
|
| - |
|
16 |
import java.util.HashSet;
|
| - |
|
17 |
import java.util.LinkedHashSet;
|
| - |
|
18 |
import java.util.List;
|
| - |
|
19 |
import java.util.Map;
|
| - |
|
20 |
import java.util.Set;
|
| - |
|
21 |
import java.util.stream.Collectors;
|
| - |
|
22 |
|
| - |
|
23 |
import javax.servlet.http.HttpServletRequest;
|
| - |
|
24 |
import javax.servlet.http.HttpServletResponse;
|
| - |
|
25 |
import javax.transaction.Transactional;
|
| - |
|
26 |
|
| - |
|
27 |
import org.apache.commons.csv.CSVRecord;
|
| - |
|
28 |
import org.apache.logging.log4j.LogManager;
|
| - |
|
29 |
import org.apache.logging.log4j.Logger;
|
| - |
|
30 |
import org.springframework.beans.factory.annotation.Autowired;
|
| - |
|
31 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| - |
|
32 |
import org.springframework.core.io.InputStreamResource;
|
| - |
|
33 |
import org.springframework.http.HttpHeaders;
|
| - |
|
34 |
import org.springframework.http.HttpStatus;
|
| - |
|
35 |
import org.springframework.http.ResponseEntity;
|
| - |
|
36 |
import org.springframework.stereotype.Controller;
|
| - |
|
37 |
import org.springframework.ui.Model;
|
| - |
|
38 |
import org.springframework.web.bind.annotation.PathVariable;
|
| - |
|
39 |
import org.springframework.web.bind.annotation.RequestBody;
|
| - |
|
40 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| - |
|
41 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| - |
|
42 |
import org.springframework.web.bind.annotation.RequestParam;
|
| - |
|
43 |
import org.springframework.web.bind.annotation.RequestPart;
|
| - |
|
44 |
import org.springframework.web.multipart.MultipartFile;
|
| - |
|
45 |
|
| - |
|
46 |
import com.google.gson.Gson;
|
| 3 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
47 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
| 4 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
48 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 5 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
49 |
import com.spice.profitmandi.common.model.CustomRetailer;
|
| 6 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
50 |
import com.spice.profitmandi.common.model.ProfitMandiConstants;
|
| 7 |
import com.spice.profitmandi.common.model.SchemeItems;
|
51 |
import com.spice.profitmandi.common.model.SchemeItems;
|
| 8 |
import com.spice.profitmandi.common.model.SchemeModel;
|
52 |
import com.spice.profitmandi.common.model.SchemeModel;
|
| 9 |
import com.spice.profitmandi.common.services.ReporticoService;
|
53 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 10 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
54 |
import com.spice.profitmandi.common.util.ExcelUtils;
|
| 11 |
import com.spice.profitmandi.common.util.FileUtil;
|
55 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 12 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
56 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| - |
|
57 |
|
| 13 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
58 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
| - |
|
59 |
import com.spice.profitmandi.dao.entity.catalog.Category;
|
| - |
|
60 |
import com.spice.profitmandi.dao.entity.catalog.CustomerOffer;
|
| - |
|
61 |
import com.spice.profitmandi.dao.entity.catalog.CustomerOfferItem;
|
| - |
|
62 |
import com.spice.profitmandi.dao.entity.catalog.EvaluateSchemeInvestmentPayoutModel;
|
| 14 |
import com.spice.profitmandi.dao.entity.catalog.*;
|
63 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| - |
|
64 |
import com.spice.profitmandi.dao.entity.catalog.SamsungUpgradeOffer;
|
| - |
|
65 |
import com.spice.profitmandi.dao.entity.catalog.Scheme;
|
| - |
|
66 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 15 |
import com.spice.profitmandi.dao.entity.fofo.*;
|
67 |
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
|
| - |
|
68 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| - |
|
69 |
import com.spice.profitmandi.dao.entity.fofo.OfferPayout;
|
| - |
|
70 |
import com.spice.profitmandi.dao.entity.fofo.PartnerDailyInvestment;
|
| - |
|
71 |
import com.spice.profitmandi.dao.entity.fofo.PartnerType;
|
| - |
|
72 |
import com.spice.profitmandi.dao.entity.fofo.SchemeInOut;
|
| - |
|
73 |
import com.spice.profitmandi.dao.entity.fofo.SchemeItem;
|
| 16 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
74 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 17 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
75 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 18 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
76 |
import com.spice.profitmandi.dao.enumuration.catalog.AmountType;
|
| 19 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
77 |
import com.spice.profitmandi.dao.enumuration.catalog.SchemeType;
|
| 20 |
import com.spice.profitmandi.dao.enumuration.catalog.UpgradeOfferStatus;
|
78 |
import com.spice.profitmandi.dao.enumuration.catalog.UpgradeOfferStatus;
|
| 21 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
79 |
import com.spice.profitmandi.dao.enumuration.cs.EscalationType;
|
| 22 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
80 |
import com.spice.profitmandi.dao.enumuration.transaction.SchemePayoutStatus;
|
| - |
|
81 |
import com.spice.profitmandi.dao.model.CustomerOfferModel;
|
| - |
|
82 |
import com.spice.profitmandi.dao.model.CreateOfferRequest;
|
| - |
|
83 |
import com.spice.profitmandi.dao.model.CreateSchemeRequest;
|
| - |
|
84 |
import com.spice.profitmandi.dao.model.CustomerOfferItemModel;
|
| - |
|
85 |
import com.spice.profitmandi.dao.model.ImeiWiseIncomePairAndMapModel;
|
| 23 |
import com.spice.profitmandi.dao.model.*;
|
86 |
import com.spice.profitmandi.dao.model.IncomeImeiDate;
|
| - |
|
87 |
import com.spice.profitmandi.dao.model.LastMonthBrandWiseIncomeModel;
|
| - |
|
88 |
import com.spice.profitmandi.dao.model.LastMonthCreditedIncomeModel;
|
| - |
|
89 |
import com.spice.profitmandi.dao.model.LastMonthFrontEndBrandWiseIncome;
|
| - |
|
90 |
import com.spice.profitmandi.dao.model.LastMonthFrontEndImeiModel;
|
| - |
|
91 |
import com.spice.profitmandi.dao.model.LastMonthImeiModel;
|
| - |
|
92 |
import com.spice.profitmandi.dao.repository.catalog.CategoryRepository;
|
| - |
|
93 |
import com.spice.profitmandi.dao.repository.catalog.CustomerOfferItemRepository;
|
| - |
|
94 |
import com.spice.profitmandi.dao.repository.catalog.CustomerOfferRepository;
|
| 24 |
import com.spice.profitmandi.dao.repository.catalog.*;
|
95 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| - |
|
96 |
import com.spice.profitmandi.dao.repository.catalog.SamsungUpgradeOfferRepository;
|
| - |
|
97 |
import com.spice.profitmandi.dao.repository.catalog.SchemeRepository;
|
| - |
|
98 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
| - |
|
99 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 25 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
100 |
import com.spice.profitmandi.dao.repository.cs.CsService;
|
| 26 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
101 |
import com.spice.profitmandi.dao.repository.dtr.FofoStoreRepository;
|
| 27 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
102 |
import com.spice.profitmandi.dao.repository.dtr.Mongo;
|
| - |
|
103 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
| - |
|
104 |
import com.spice.profitmandi.dao.repository.fofo.OfferPayoutRepository;
|
| - |
|
105 |
import com.spice.profitmandi.dao.repository.fofo.PartnerDailyInvestmentRepository;
|
| - |
|
106 |
import com.spice.profitmandi.dao.repository.fofo.PartnerTypeChangeService;
|
| - |
|
107 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
| 28 |
import com.spice.profitmandi.dao.repository.fofo.*;
|
108 |
import com.spice.profitmandi.dao.repository.fofo.SchemeItemRepository;
|
| 29 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
109 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
| 30 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
110 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 31 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
111 |
import com.spice.profitmandi.dao.repository.transaction.TransactionRepository;
|
| 32 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
112 |
import com.spice.profitmandi.service.authentication.RoleManager;
|
| 33 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
113 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 34 |
import com.spice.profitmandi.service.offers.OfferService;
|
114 |
import com.spice.profitmandi.service.offers.OfferService;
|
| - |
|
115 |
import com.spice.profitmandi.service.offers.PartnerCriteria;
|
| 35 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
116 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 36 |
import com.spice.profitmandi.service.user.RetailerService;
|
117 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 37 |
import com.spice.profitmandi.service.wallet.WalletService;
|
118 |
import com.spice.profitmandi.service.wallet.WalletService;
|
| 38 |
import com.spice.profitmandi.web.model.LoginDetails;
|
119 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 39 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
120 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 40 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
121 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 41 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
- |
|
| 42 |
import org.apache.commons.csv.CSVRecord;
|
- |
|
| 43 |
import org.apache.logging.log4j.LogManager;
|
- |
|
| 44 |
import org.apache.logging.log4j.Logger;
|
- |
|
| 45 |
import org.springframework.beans.factory.annotation.Autowired;
|
- |
|
| 46 |
import org.springframework.beans.factory.annotation.Qualifier;
|
- |
|
| 47 |
import org.springframework.core.io.InputStreamResource;
|
- |
|
| 48 |
import org.springframework.http.HttpHeaders;
|
- |
|
| 49 |
import org.springframework.http.HttpStatus;
|
122 |
import org.springframework.util.StringUtils;
|
| 50 |
import org.springframework.http.ResponseEntity;
|
- |
|
| 51 |
import org.springframework.stereotype.Controller;
|
- |
|
| 52 |
import org.springframework.ui.Model;
|
- |
|
| 53 |
import org.springframework.web.bind.annotation.*;
|
- |
|
| 54 |
import org.springframework.web.multipart.MultipartFile;
|
- |
|
| 55 |
|
123 |
|
| 56 |
import javax.servlet.http.HttpServletRequest;
|
- |
|
| 57 |
import javax.servlet.http.HttpServletResponse;
|
124 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
| 58 |
import javax.transaction.Transactional;
|
- |
|
| 59 |
import java.io.ByteArrayInputStream;
|
- |
|
| 60 |
import java.io.ByteArrayOutputStream;
|
- |
|
| 61 |
import java.io.InputStream;
|
- |
|
| 62 |
import java.time.*;
|
- |
|
| 63 |
import java.time.format.DateTimeFormatter;
|
- |
|
| 64 |
import java.util.*;
|
- |
|
| 65 |
import java.util.stream.Collectors;
|
- |
|
| 66 |
|
125 |
|
| 67 |
@Controller
|
126 |
@Controller
|
| 68 |
@Transactional(rollbackOn = Throwable.class)
|
127 |
@Transactional(rollbackOn = Throwable.class)
|
| 69 |
public class SchemeController {
|
128 |
public class SchemeController {
|
| 70 |
// LED TV
|
129 |
// LED TV
|
| Line 159... |
Line 218... |
| 159 |
private CsService csService;
|
218 |
private CsService csService;
|
| 160 |
|
219 |
|
| 161 |
@Autowired
|
220 |
@Autowired
|
| 162 |
private CategoryRepository categoryRepository;
|
221 |
private CategoryRepository categoryRepository;
|
| 163 |
|
222 |
|
| - |
|
223 |
@Autowired
|
| - |
|
224 |
private Gson gson;
|
| - |
|
225 |
|
| 164 |
List<String> adminEmail = Arrays.asList("tarun.verma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
|
226 |
List<String> adminEmail = Arrays.asList("tarun.verma@smartdukaan.com", "neeraj.gupta@smartdukaan.com",
|
| 165 |
"amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com", "raksha.vyas@smartdukaan.com");
|
227 |
"amit.gupta@smartdukaan.com", "tejbeer.kaur@smartdukaan.com", "raksha.vyas@smartdukaan.com");
|
| 166 |
|
228 |
|
| 167 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
229 |
@RequestMapping(value = "/createScheme", method = RequestMethod.GET)
|
| 168 |
public String createScheme(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
230 |
public String createScheme(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
| Line 1344... |
Line 1406... |
| 1344 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
1406 |
LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
|
| 1345 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
1407 |
return responseSender.ok(schemeService.getSchemes(loginDetails.getRoleIds(), offset, limit));
|
| 1346 |
}
|
1408 |
}
|
| 1347 |
|
1409 |
|
| 1348 |
@RequestMapping(value = "/getCustomerOffer", method = RequestMethod.GET)
|
1410 |
@RequestMapping(value = "/getCustomerOffer", method = RequestMethod.GET)
|
| 1349 |
public String getCustomerOffer(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
|
1411 |
public String getCustomerOffer(HttpServletRequest request,
|
| - |
|
1412 |
@RequestParam(name = "searchModel", required = false, defaultValue = "0") int searchModel, Model model)
|
| - |
|
1413 |
throws ProfitMandiBusinessException {
|
| - |
|
1414 |
List<CustomerOffer> customerOffers = new ArrayList<>();
|
| - |
|
1415 |
if (searchModel > 0) {
|
| 1350 |
|
1416 |
|
| - |
|
1417 |
Item item = itemRepository.selectAllByCatalogItemId(searchModel).get(0);
|
| - |
|
1418 |
customerOffers = customerOfferRepository.selectActiveOfferByModel(searchModel, LocalDate.now());
|
| - |
|
1419 |
model.addAttribute("modelName", item.getItemDescriptionNoColor());
|
| - |
|
1420 |
} else {
|
| 1351 |
List<CustomerOffer> customerOffers = customerOfferRepository.selectAll();
|
1421 |
customerOffers = customerOfferRepository.selectAll();
|
| - |
|
1422 |
}
|
| - |
|
1423 |
|
| - |
|
1424 |
LOGGER.info("customerOffers" + customerOffers);
|
| - |
|
1425 |
|
| - |
|
1426 |
for (CustomerOffer customerOffer : customerOffers) {
|
| - |
|
1427 |
|
| - |
|
1428 |
LOGGER.info("ss" + searchModel);
|
| - |
|
1429 |
|
| - |
|
1430 |
if (!StringUtils.isEmpty(customerOffer.getPartnerCriteria())) {
|
| - |
|
1431 |
String partnerCriteria = retailerService.getPartnerCriteriaString(
|
| - |
|
1432 |
gson.fromJson(customerOffer.getPartnerCriteria(), PartnerCriteria.class));
|
| - |
|
1433 |
customerOffer.setPartnerCriteriaString(partnerCriteria);
|
| - |
|
1434 |
}
|
| - |
|
1435 |
|
| - |
|
1436 |
}
|
| - |
|
1437 |
|
| - |
|
1438 |
List<Integer> fofoIds = fofoStoreRepository.selectActiveStores().stream().map(x -> x.getId())
|
| - |
|
1439 |
.collect(Collectors.toList());
|
| - |
|
1440 |
|
| - |
|
1441 |
Map<Integer, CustomRetailer> customRetailerMap = retailerService.getAllFofoRetailers();
|
| - |
|
1442 |
|
| - |
|
1443 |
Map<Integer, CustomRetailer> customRetailersMap = fofoIds.stream().map(x -> customRetailerMap.get(x))
|
| - |
|
1444 |
.filter(x -> x != null).collect(Collectors.toList()).stream()
|
| - |
|
1445 |
.collect(Collectors.toMap(x -> x.getPartnerId(), x -> x));
|
| - |
|
1446 |
|
| - |
|
1447 |
model.addAttribute("customRetailersMap", customRetailersMap);
|
| - |
|
1448 |
model.addAttribute("warehouseRegion", ProfitMandiConstants.WAREHOUSE_MAP);
|
| - |
|
1449 |
model.addAttribute("searchModel", searchModel);
|
| 1352 |
|
1450 |
|
| 1353 |
model.addAttribute("customerOffers", customerOffers);
|
1451 |
model.addAttribute("customerOffers", customerOffers);
|
| 1354 |
return "customer-offer";
|
1452 |
return "customer-offer";
|
| 1355 |
|
1453 |
|
| 1356 |
}
|
1454 |
}
|
| 1357 |
|
1455 |
|
| 1358 |
@RequestMapping(value = "/createCustomerOffer", method = RequestMethod.POST)
|
1456 |
@RequestMapping(value = "/createCustomerOffer", method = RequestMethod.POST)
|
| 1359 |
public String createCustomerOffer(HttpServletRequest request, @RequestParam String offerName,
|
1457 |
public String createCustomerOffer(HttpServletRequest request, @RequestBody CustomerOfferModel customerOfferModel,
|
| 1360 |
@RequestParam LocalDateTime startDate, @RequestParam LocalDateTime endDate, Model model) throws Exception {
|
1458 |
Model model) throws Exception {
|
| 1361 |
|
1459 |
|
| 1362 |
CustomerOffer co = new CustomerOffer();
|
1460 |
CustomerOffer co = new CustomerOffer();
|
| 1363 |
co.setOfferName(offerName);
|
1461 |
co.setOfferName(customerOfferModel.getOfferName());
|
| 1364 |
co.setStartDate(startDate);
|
1462 |
co.setStartDate(customerOfferModel.getStartDate());
|
| 1365 |
co.setEndDate(endDate);
|
1463 |
co.setEndDate(customerOfferModel.getEndDate());
|
| - |
|
1464 |
co.setPartnerCriteria(gson.toJson(customerOfferModel.getPartnerCriteria()));
|
| 1366 |
co.setCreatedTimestamp(LocalDateTime.now());
|
1465 |
co.setCreatedTimestamp(LocalDateTime.now());
|
| 1367 |
co.setUpdatedTimestamp(LocalDateTime.now());
|
1466 |
co.setUpdatedTimestamp(LocalDateTime.now());
|
| 1368 |
customerOfferRepository.persist(co);
|
1467 |
customerOfferRepository.persist(co);
|
| 1369 |
|
1468 |
|
| 1370 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
1469 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| Line 1375... |
Line 1474... |
| 1375 |
|
1474 |
|
| 1376 |
@RequestMapping(value = "/customerOffer/downloadTemplate", method = RequestMethod.GET)
|
1475 |
@RequestMapping(value = "/customerOffer/downloadTemplate", method = RequestMethod.GET)
|
| 1377 |
public ResponseEntity<?> downloadCustomerOfferTemplate(HttpServletRequest request) throws Exception {
|
1476 |
public ResponseEntity<?> downloadCustomerOfferTemplate(HttpServletRequest request) throws Exception {
|
| 1378 |
List<List<?>> rows = new ArrayList<>();
|
1477 |
List<List<?>> rows = new ArrayList<>();
|
| 1379 |
|
1478 |
|
| 1380 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
1479 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(Arrays.asList("id",
|
| 1381 |
.getCSVByteStream(Arrays.asList("id", "Catalog Id", "Scheme Payout", "Dealer Payout"), rows);
|
1480 |
"Catalog Id", "Scheme Payout", "Dealer Payout", "Start Date (dd-mm-yyyy)", "End Date (dd-mm-yyyy)"),
|
| - |
|
1481 |
rows);
|
| 1382 |
|
1482 |
|
| 1383 |
final HttpHeaders headers = new HttpHeaders();
|
1483 |
final HttpHeaders headers = new HttpHeaders();
|
| 1384 |
headers.set("Content-Type", "text/csv");
|
1484 |
headers.set("Content-Type", "text/csv");
|
| 1385 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
1485 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
| 1386 |
headers.setContentLength(baos.toByteArray().length);
|
1486 |
headers.setContentLength(baos.toByteArray().length);
|
| Line 1394... |
Line 1494... |
| 1394 |
@RequestMapping(value = "/customerOfferItem/upload", method = RequestMethod.POST)
|
1494 |
@RequestMapping(value = "/customerOfferItem/upload", method = RequestMethod.POST)
|
| 1395 |
public String uploadCustomerOfferItem(HttpServletRequest request, Model model, @RequestParam int offerId,
|
1495 |
public String uploadCustomerOfferItem(HttpServletRequest request, Model model, @RequestParam int offerId,
|
| 1396 |
HttpServletResponse response, @RequestPart MultipartFile file) throws Throwable {
|
1496 |
HttpServletResponse response, @RequestPart MultipartFile file) throws Throwable {
|
| 1397 |
|
1497 |
|
| 1398 |
List<CSVRecord> records = FileUtil.readFile(file);
|
1498 |
List<CSVRecord> records = FileUtil.readFile(file);
|
| - |
|
1499 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
| 1399 |
|
1500 |
|
| - |
|
1501 |
CustomerOffer customerOffer = customerOfferRepository.selectById(offerId);
|
| - |
|
1502 |
List<Integer> catalogIds = new ArrayList<>();
|
| 1400 |
for (CSVRecord record : records) {
|
1503 |
for (CSVRecord record : records) {
|
| - |
|
1504 |
|
| 1401 |
if (Integer.parseInt(record.get(0)) == 0) {
|
1505 |
CustomerOfferItem coi = customerOfferItemRepository.selectById(Integer.parseInt(record.get(0)));
|
| - |
|
1506 |
|
| - |
|
1507 |
if (coi == null) {
|
| 1402 |
CustomerOfferItem coi = new CustomerOfferItem();
|
1508 |
coi = new CustomerOfferItem();
|
| 1403 |
coi.setCatalogId(Integer.parseInt(record.get(1)));
|
1509 |
coi.setCatalogId(Integer.parseInt(record.get(1)));
|
| 1404 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
1510 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
| 1405 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
1511 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
| 1406 |
coi.setCustomerOfferId(offerId);
|
1512 |
coi.setCustomerOfferId(offerId);
|
| 1407 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
- |
|
| 1408 |
coi.setCreatedTimestamp(LocalDateTime.now());
|
1513 |
coi.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
1514 |
|
| 1409 |
customerOfferItemRepository.persist(coi);
|
1515 |
customerOfferItemRepository.persist(coi);
|
| 1410 |
|
1516 |
|
| - |
|
1517 |
}
|
| - |
|
1518 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
| - |
|
1519 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
| - |
|
1520 |
coi.setCustomerOfferId(offerId);
|
| - |
|
1521 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
| - |
|
1522 |
|
| - |
|
1523 |
LOGGER.info(record.get(4));
|
| - |
|
1524 |
|
| - |
|
1525 |
LocalDate startDate = LocalDate.parse(record.get(4), formatter);
|
| - |
|
1526 |
LocalDate endDate = LocalDate.parse(record.get(5), formatter);
|
| - |
|
1527 |
|
| - |
|
1528 |
if ((startDate.equals(customerOffer.getStartDate().toLocalDate())
|
| - |
|
1529 |
|| startDate.isAfter(customerOffer.getStartDate().toLocalDate()))
|
| - |
|
1530 |
&& (startDate.isEqual(customerOffer.getEndDate().toLocalDate())
|
| - |
|
1531 |
|| startDate.isBefore(customerOffer.getEndDate().toLocalDate()))) {
|
| - |
|
1532 |
coi.setStartDate(startDate);
|
| - |
|
1533 |
|
| 1411 |
} else {
|
1534 |
} else {
|
| - |
|
1535 |
|
| - |
|
1536 |
catalogIds.add(coi.getCatalogId());
|
| - |
|
1537 |
}
|
| - |
|
1538 |
|
| - |
|
1539 |
if ((endDate.equals(customerOffer.getStartDate().toLocalDate())
|
| 1412 |
CustomerOfferItem coi = customerOfferItemRepository.selectById(Integer.parseInt(record.get(0)));
|
1540 |
|| endDate.isAfter(customerOffer.getStartDate().toLocalDate()))
|
| 1413 |
coi.setSchemePayout(Integer.parseInt(record.get(2)));
|
1541 |
&& (endDate.isEqual(customerOffer.getEndDate().toLocalDate())
|
| 1414 |
coi.setDealerPayout(Integer.parseInt(record.get(3)));
|
1542 |
|| endDate.isBefore(customerOffer.getEndDate().toLocalDate()))) {
|
| - |
|
1543 |
|
| 1415 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
1544 |
coi.setEndDate(endDate);
|
| - |
|
1545 |
|
| - |
|
1546 |
} else {
|
| - |
|
1547 |
catalogIds.add(coi.getCatalogId());
|
| 1416 |
}
|
1548 |
}
|
| 1417 |
|
1549 |
|
| 1418 |
}
|
1550 |
}
|
| 1419 |
|
1551 |
|
| - |
|
1552 |
if (!catalogIds.isEmpty()) {
|
| - |
|
1553 |
throw new ProfitMandiBusinessException("Please set accurate start and end date", catalogIds,
|
| - |
|
1554 |
"Please set accurate start and end date");
|
| - |
|
1555 |
}
|
| - |
|
1556 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| - |
|
1557 |
|
| - |
|
1558 |
return "response";
|
| - |
|
1559 |
|
| - |
|
1560 |
}
|
| - |
|
1561 |
|
| - |
|
1562 |
@RequestMapping(value = "/addCustomerOfferItem", method = RequestMethod.POST)
|
| - |
|
1563 |
public String addCustomerOfferItem(HttpServletRequest request,
|
| - |
|
1564 |
@RequestBody CustomerOfferItemModel customerOfferItemModel, Model model) throws Throwable {
|
| - |
|
1565 |
|
| - |
|
1566 |
CustomerOffer customerOffer = customerOfferRepository.selectById(customerOfferItemModel.getOfferId());
|
| - |
|
1567 |
|
| - |
|
1568 |
if (!(customerOffer.getEndDate().toLocalDate().equals(LocalDate.now()))
|
| - |
|
1569 |
&& customerOffer.getEndDate().isBefore(LocalDateTime.now())) {
|
| - |
|
1570 |
throw new ProfitMandiBusinessException("Catalog Id", customerOffer.getOfferName(), "Offer is Expired");
|
| - |
|
1571 |
|
| - |
|
1572 |
}
|
| - |
|
1573 |
|
| - |
|
1574 |
List<CustomerOfferItem> customerOfferItems = customerOfferItemRepository
|
| - |
|
1575 |
.selectByOfferAndCatalogId(customerOfferItemModel.getOfferId(), customerOfferItemModel.getCatalogId());
|
| - |
|
1576 |
|
| - |
|
1577 |
if (!customerOfferItems.isEmpty()) {
|
| - |
|
1578 |
|
| - |
|
1579 |
for (CustomerOfferItem coi : customerOfferItems) {
|
| - |
|
1580 |
if (!(coi.getEndDate().equals(LocalDate.now())) && coi.getEndDate().isAfter(LocalDate.now())) {
|
| - |
|
1581 |
throw new ProfitMandiBusinessException("Catalog Id", coi.getCatalogId(), "Item is already exist.");
|
| - |
|
1582 |
}
|
| - |
|
1583 |
}
|
| - |
|
1584 |
|
| - |
|
1585 |
}
|
| - |
|
1586 |
|
| - |
|
1587 |
LocalDate startDate = customerOfferItemModel.getStartDate().toLocalDate();
|
| - |
|
1588 |
LocalDate endDate = customerOfferItemModel.getEndDate().toLocalDate();
|
| - |
|
1589 |
CustomerOfferItem coi = new CustomerOfferItem();
|
| - |
|
1590 |
coi.setCatalogId(customerOfferItemModel.getCatalogId());
|
| - |
|
1591 |
coi.setSchemePayout(customerOfferItemModel.getSchemePayout());
|
| - |
|
1592 |
coi.setDealerPayout(customerOfferItemModel.getDealerPayout());
|
| - |
|
1593 |
coi.setCustomerOfferId(customerOfferItemModel.getOfferId());
|
| - |
|
1594 |
coi.setUpdatedTimestamp(LocalDateTime.now());
|
| - |
|
1595 |
coi.setCreatedTimestamp(LocalDateTime.now());
|
| - |
|
1596 |
|
| - |
|
1597 |
if ((startDate.equals(customerOffer.getStartDate().toLocalDate())
|
| - |
|
1598 |
|| startDate.isAfter(customerOffer.getStartDate().toLocalDate()))
|
| - |
|
1599 |
&& (startDate.isEqual(customerOffer.getEndDate().toLocalDate())
|
| - |
|
1600 |
|| startDate.isBefore(customerOffer.getEndDate().toLocalDate()))) {
|
| - |
|
1601 |
|
| - |
|
1602 |
coi.setStartDate(startDate);
|
| - |
|
1603 |
|
| - |
|
1604 |
} else {
|
| - |
|
1605 |
|
| - |
|
1606 |
throw new ProfitMandiBusinessException("Catalog Id", customerOffer.getOfferName(),
|
| - |
|
1607 |
"Please select accurate duration between " + customerOffer.getStartDate().toLocalDate() + " - "
|
| - |
|
1608 |
+ customerOffer.getEndDate());
|
| - |
|
1609 |
|
| - |
|
1610 |
}
|
| - |
|
1611 |
|
| - |
|
1612 |
if ((endDate.equals(customerOffer.getStartDate().toLocalDate())
|
| - |
|
1613 |
|| endDate.isAfter(customerOffer.getStartDate().toLocalDate()))
|
| - |
|
1614 |
&& (endDate.isEqual(customerOffer.getEndDate().toLocalDate())
|
| - |
|
1615 |
|| endDate.isBefore(customerOffer.getEndDate().toLocalDate()))) {
|
| - |
|
1616 |
|
| - |
|
1617 |
coi.setEndDate(endDate);
|
| - |
|
1618 |
|
| - |
|
1619 |
} else {
|
| - |
|
1620 |
throw new ProfitMandiBusinessException("Catalog Id", customerOffer.getOfferName(),
|
| - |
|
1621 |
"Please select accurate duration between " + customerOffer.getStartDate().toLocalDate() + " - "
|
| - |
|
1622 |
+ customerOffer.getEndDate());
|
| - |
|
1623 |
}
|
| - |
|
1624 |
|
| - |
|
1625 |
customerOfferItemRepository.persist(coi);
|
| - |
|
1626 |
|
| 1420 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
1627 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
| 1421 |
|
1628 |
|
| 1422 |
return "response";
|
1629 |
return "response";
|
| 1423 |
|
1630 |
|
| 1424 |
}
|
1631 |
}
|
| Line 1426... |
Line 1633... |
| 1426 |
@RequestMapping(value = "/customerOfferItem/download", method = RequestMethod.GET)
|
1633 |
@RequestMapping(value = "/customerOfferItem/download", method = RequestMethod.GET)
|
| 1427 |
public ResponseEntity<?> downloadOfferItem(HttpServletRequest request, @RequestParam int offerId) throws Exception {
|
1634 |
public ResponseEntity<?> downloadOfferItem(HttpServletRequest request, @RequestParam int offerId) throws Exception {
|
| 1428 |
|
1635 |
|
| 1429 |
List<CustomerOfferItem> cois = customerOfferItemRepository.selectByOfferId(offerId);
|
1636 |
List<CustomerOfferItem> cois = customerOfferItemRepository.selectByOfferId(offerId);
|
| 1430 |
List<List<?>> rows = new ArrayList<>();
|
1637 |
List<List<?>> rows = new ArrayList<>();
|
| - |
|
1638 |
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
|
| 1431 |
|
1639 |
|
| 1432 |
for (CustomerOfferItem coi : cois) {
|
1640 |
for (CustomerOfferItem coi : cois) {
|
| 1433 |
rows.add(Arrays.asList(coi.getId(), coi.getCatalogId(), coi.getSchemePayout(), coi.getDealerPayout()));
|
1641 |
rows.add(Arrays.asList(coi.getId(), coi.getCatalogId(), coi.getSchemePayout(), coi.getDealerPayout(),
|
| - |
|
1642 |
coi.getStartDate().format(formatter), coi.getEndDate().format(formatter)));
|
| 1434 |
|
1643 |
|
| 1435 |
}
|
1644 |
}
|
| 1436 |
|
1645 |
|
| 1437 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil
|
1646 |
org.apache.commons.io.output.ByteArrayOutputStream baos = FileUtil.getCSVByteStream(
|
| 1438 |
.getCSVByteStream(Arrays.asList("id", "Catalog Id", "Scheme Payout", "Dealer Payout"), rows);
|
1647 |
Arrays.asList("id", "Catalog Id", "Scheme Payout", "Dealer Payout", "Start Date", "End Date"), rows);
|
| 1439 |
|
1648 |
|
| 1440 |
final HttpHeaders headers = new HttpHeaders();
|
1649 |
final HttpHeaders headers = new HttpHeaders();
|
| 1441 |
headers.set("Content-Type", "text/csv");
|
1650 |
headers.set("Content-Type", "text/csv");
|
| 1442 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
1651 |
headers.set("Content-disposition", "inline; filename=customer-offer-template.csv");
|
| 1443 |
headers.setContentLength(baos.toByteArray().length);
|
1652 |
headers.setContentLength(baos.toByteArray().length);
|
| Line 1446... |
Line 1655... |
| 1446 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
1655 |
final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
|
| 1447 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
1656 |
return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
|
| 1448 |
|
1657 |
|
| 1449 |
}
|
1658 |
}
|
| 1450 |
|
1659 |
|
| - |
|
1660 |
@RequestMapping(value = "/getCustomerOfferItem", method = RequestMethod.GET)
|
| - |
|
1661 |
public String getCustomerOfferItem(HttpServletRequest request, @RequestParam int offerId, Model model)
|
| - |
|
1662 |
throws Exception {
|
| - |
|
1663 |
|
| - |
|
1664 |
List<CustomerOfferItem> customerOfferItems = customerOfferItemRepository.selectByOfferId(offerId);
|
| - |
|
1665 |
List<Integer> catalogIds = customerOfferItems.stream().map(x -> x.getCatalogId()).collect(Collectors.toList());
|
| - |
|
1666 |
|
| - |
|
1667 |
Map<Integer, List<Item>> catalogItemMap = itemRepository.selectAllByCatalogIds(new HashSet<>(catalogIds))
|
| - |
|
1668 |
.stream().collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
| - |
|
1669 |
|
| - |
|
1670 |
model.addAttribute("catalogItemMap", catalogItemMap);
|
| - |
|
1671 |
|
| - |
|
1672 |
model.addAttribute("offerId", offerId);
|
| - |
|
1673 |
|
| - |
|
1674 |
model.addAttribute("customerOfferItems", customerOfferItems);
|
| - |
|
1675 |
return "customer-offer-item";
|
| - |
|
1676 |
|
| - |
|
1677 |
}
|
| - |
|
1678 |
|
| - |
|
1679 |
@RequestMapping(value = "/expiredCustomerOfferItem", method = RequestMethod.POST)
|
| - |
|
1680 |
public String expiredCustomerOfferItem(HttpServletRequest request, @RequestParam int id,
|
| - |
|
1681 |
@RequestParam LocalDateTime endDate, Model model) throws Exception {
|
| - |
|
1682 |
|
| - |
|
1683 |
CustomerOfferItem customerOfferItem = customerOfferItemRepository.selectById(id);
|
| - |
|
1684 |
|
| - |
|
1685 |
CustomerOffer customerOffer = customerOfferRepository.selectById(customerOfferItem.getCustomerOfferId());
|
| - |
|
1686 |
|
| - |
|
1687 |
if ((endDate.toLocalDate().equals(customerOffer.getStartDate().toLocalDate())
|
| - |
|
1688 |
|| endDate.toLocalDate().isAfter(customerOffer.getStartDate().toLocalDate()))
|
| - |
|
1689 |
&& (endDate.toLocalDate().isEqual(customerOffer.getEndDate().toLocalDate())
|
| - |
|
1690 |
|| endDate.toLocalDate().isBefore(customerOffer.getEndDate().toLocalDate()))) {
|
| - |
|
1691 |
|
| - |
|
1692 |
customerOfferItem.setEndDate(endDate.toLocalDate());
|
| - |
|
1693 |
|
| - |
|
1694 |
} else {
|
| - |
|
1695 |
throw new ProfitMandiBusinessException("Date", customerOffer.getOfferName(),
|
| - |
|
1696 |
"customer offer expired on " + customerOffer.getEndDate());
|
| - |
|
1697 |
}
|
| - |
|
1698 |
Map<Integer, List<Item>> catalogItemMap = itemRepository
|
| - |
|
1699 |
.selectAllByCatalogItemId(customerOfferItem.getCatalogId()).stream()
|
| - |
|
1700 |
.collect(Collectors.groupingBy(x -> x.getCatalogItemId()));
|
| - |
|
1701 |
model.addAttribute("catalogItemMap", catalogItemMap);
|
| - |
|
1702 |
|
| - |
|
1703 |
model.addAttribute("coi", customerOfferItem);
|
| - |
|
1704 |
|
| - |
|
1705 |
return "customer-offer-item-index";
|
| - |
|
1706 |
|
| - |
|
1707 |
}
|
| - |
|
1708 |
|
| 1451 |
@RequestMapping(value = "/extendCustomerOffer", method = RequestMethod.POST)
|
1709 |
@RequestMapping(value = "/extendCustomerOffer", method = RequestMethod.POST)
|
| 1452 |
public String extendCustomerOffer(HttpServletRequest request, @RequestParam int id,
|
1710 |
public String extendCustomerOffer(HttpServletRequest request, @RequestParam int id,
|
| 1453 |
@RequestParam LocalDateTime endDate, Model model) throws ProfitMandiBusinessException {
|
1711 |
@RequestParam LocalDateTime endDate, Model model) throws ProfitMandiBusinessException {
|
| 1454 |
|
1712 |
|
| 1455 |
CustomerOffer co = customerOfferRepository.selectById(id);
|
1713 |
CustomerOffer co = customerOfferRepository.selectById(id);
|