| 23819 |
govind |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
| 24822 |
amit.gupta |
3 |
import java.io.Serializable;
|
| 23968 |
amit.gupta |
4 |
import java.text.MessageFormat;
|
| 23819 |
govind |
5 |
import java.time.LocalDateTime;
|
|
|
6 |
import java.util.ArrayList;
|
| 23884 |
amit.gupta |
7 |
import java.util.Arrays;
|
| 23819 |
govind |
8 |
import java.util.List;
|
|
|
9 |
import java.util.Map;
|
| 24063 |
amit.gupta |
10 |
import java.util.Set;
|
| 23819 |
govind |
11 |
import java.util.stream.Collectors;
|
|
|
12 |
|
|
|
13 |
import javax.servlet.http.HttpServletRequest;
|
|
|
14 |
|
| 23951 |
amit.gupta |
15 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 23819 |
govind |
16 |
import org.apache.logging.log4j.LogManager;
|
|
|
17 |
import org.apache.logging.log4j.Logger;
|
|
|
18 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
19 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 24191 |
amit.gupta |
20 |
import org.springframework.cache.annotation.Cacheable;
|
| 23951 |
amit.gupta |
21 |
import org.springframework.core.io.ByteArrayResource;
|
|
|
22 |
import org.springframework.http.HttpHeaders;
|
| 23819 |
govind |
23 |
import org.springframework.http.HttpStatus;
|
|
|
24 |
import org.springframework.http.ResponseEntity;
|
|
|
25 |
import org.springframework.stereotype.Controller;
|
| 25161 |
amit.gupta |
26 |
import org.springframework.transaction.annotation.Transactional;
|
| 23819 |
govind |
27 |
import org.springframework.ui.Model;
|
|
|
28 |
import org.springframework.web.bind.annotation.PathVariable;
|
| 23884 |
amit.gupta |
29 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 23819 |
govind |
30 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
31 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 23951 |
amit.gupta |
32 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 23819 |
govind |
33 |
|
| 23945 |
amit.gupta |
34 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 23819 |
govind |
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 23951 |
amit.gupta |
36 |
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
|
| 23884 |
amit.gupta |
37 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
| 24083 |
amit.gupta |
38 |
import com.spice.profitmandi.common.model.PriceDropImeisModel;
|
| 23884 |
amit.gupta |
39 |
import com.spice.profitmandi.common.model.PriceDropModel;
|
| 23968 |
amit.gupta |
40 |
import com.spice.profitmandi.common.model.PriceDropProcessModel;
|
| 23945 |
amit.gupta |
41 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 23951 |
amit.gupta |
42 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 23945 |
amit.gupta |
43 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 23819 |
govind |
44 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 23884 |
amit.gupta |
45 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 23968 |
amit.gupta |
46 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| 24822 |
amit.gupta |
47 |
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
|
| 23884 |
amit.gupta |
48 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
| 23819 |
govind |
49 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 24083 |
amit.gupta |
50 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
|
|
51 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 23819 |
govind |
52 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 23884 |
amit.gupta |
53 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 24822 |
amit.gupta |
54 |
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
|
| 23884 |
amit.gupta |
55 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
| 23983 |
amit.gupta |
56 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
| 24083 |
amit.gupta |
57 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
| 23819 |
govind |
58 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
|
|
59 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| 23983 |
amit.gupta |
60 |
import com.spice.profitmandi.service.pricing.PriceDropService;
|
| 23968 |
amit.gupta |
61 |
import com.spice.profitmandi.service.scheme.SchemeService;
|
| 23884 |
amit.gupta |
62 |
import com.spice.profitmandi.service.transaction.TransactionService;
|
| 23819 |
govind |
63 |
import com.spice.profitmandi.service.wallet.WalletService;
|
|
|
64 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
65 |
|
| 23968 |
amit.gupta |
66 |
import in.shop2020.model.v1.order.WalletReferenceType;
|
|
|
67 |
|
| 23819 |
govind |
68 |
@Controller
|
| 25161 |
amit.gupta |
69 |
@Transactional(rollbackFor=Throwable.class)
|
| 23819 |
govind |
70 |
public class PriceDropController {
|
|
|
71 |
|
|
|
72 |
private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
|
|
|
73 |
|
|
|
74 |
@Autowired
|
|
|
75 |
private PriceDropRepository priceDropRepository;
|
|
|
76 |
|
| 23951 |
amit.gupta |
77 |
@Autowired
|
|
|
78 |
private ObjectMapper objectMapper;
|
| 23945 |
amit.gupta |
79 |
|
| 23819 |
govind |
80 |
@Autowired
|
| 23884 |
amit.gupta |
81 |
private VendorItemPricingRepository vendorItemPricingRepository;
|
| 23819 |
govind |
82 |
|
|
|
83 |
@Autowired
|
| 23884 |
amit.gupta |
84 |
@Qualifier("fofoInventoryService")
|
|
|
85 |
private InventoryService inventoryService;
|
| 23945 |
amit.gupta |
86 |
|
| 23884 |
amit.gupta |
87 |
@Autowired
|
| 23819 |
govind |
88 |
private MVCResponseSender mvcResponseSender;
|
|
|
89 |
|
|
|
90 |
@Autowired
|
| 23983 |
amit.gupta |
91 |
private PriceDropService priceDropService;
|
| 24822 |
amit.gupta |
92 |
|
|
|
93 |
@Autowired
|
|
|
94 |
private ItemPricingHistoryRepository itemPricingHistoryRepository;
|
| 24083 |
amit.gupta |
95 |
|
| 23983 |
amit.gupta |
96 |
@Autowired
|
| 23819 |
govind |
97 |
private WalletService walletService;
|
|
|
98 |
|
|
|
99 |
@Autowired
|
| 23884 |
amit.gupta |
100 |
private TagListingRepository tagListingRepository;
|
| 23945 |
amit.gupta |
101 |
|
| 23884 |
amit.gupta |
102 |
@Autowired
|
|
|
103 |
private TransactionService transactionService;
|
| 23819 |
govind |
104 |
|
|
|
105 |
@Autowired
|
| 24083 |
amit.gupta |
106 |
private PriceDropIMEIRepository priceDropIMEIRepository;
|
|
|
107 |
|
|
|
108 |
@Autowired
|
| 23819 |
govind |
109 |
@Qualifier("catalogItemRepository")
|
|
|
110 |
private ItemRepository itemRepository;
|
|
|
111 |
|
| 23945 |
amit.gupta |
112 |
@Autowired
|
| 23968 |
amit.gupta |
113 |
private SchemeService schemeService;
|
| 24083 |
amit.gupta |
114 |
|
| 23986 |
amit.gupta |
115 |
@Autowired
|
| 23945 |
amit.gupta |
116 |
ReporticoService reporticoService;
|
| 24083 |
amit.gupta |
117 |
|
| 23983 |
amit.gupta |
118 |
@Autowired
|
|
|
119 |
LineItemImeisRepository lineItemImeisRepository;
|
| 23945 |
amit.gupta |
120 |
|
| 23819 |
govind |
121 |
@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
|
| 23945 |
amit.gupta |
122 |
public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
|
| 23819 |
govind |
123 |
List<PriceDrop> priceDrops = priceDropRepository.selectAll();
|
| 24191 |
amit.gupta |
124 |
Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
|
| 24180 |
amit.gupta |
125 |
List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
|
| 24191 |
amit.gupta |
126 |
Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
|
|
|
127 |
x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
|
| 23819 |
govind |
128 |
model.addAttribute("priceDrops", priceDrops);
|
| 23968 |
amit.gupta |
129 |
model.addAttribute("catalogDescription", catalogDescription);
|
| 23819 |
govind |
130 |
return "price-drop";
|
|
|
131 |
}
|
| 24083 |
amit.gupta |
132 |
|
| 24049 |
amit.gupta |
133 |
@RequestMapping(value = "/item-pricing/{itemId}", method = RequestMethod.GET)
|
|
|
134 |
public String getItemPricing(HttpServletRequest request, Model model, @PathVariable int itemId) throws Throwable {
|
| 24083 |
amit.gupta |
135 |
|
| 24063 |
amit.gupta |
136 |
TagListing tagListing;
|
| 24049 |
amit.gupta |
137 |
PriceDropModel pm = new PriceDropModel();
|
| 24063 |
amit.gupta |
138 |
try {
|
|
|
139 |
tagListing = tagListingRepository.selectByItemId(itemId);
|
| 24083 |
amit.gupta |
140 |
if (tagListing != null) {
|
| 24063 |
amit.gupta |
141 |
pm.setMop(tagListing.getMop());
|
|
|
142 |
pm.setDp(tagListing.getSellingPrice());
|
|
|
143 |
pm.setMrp(tagListing.getMrp());
|
|
|
144 |
List<VendorItemPricing> vips = vendorItemPricingRepository.selectAll(itemId);
|
| 24083 |
amit.gupta |
145 |
if (vips.size() > 0) {
|
| 24063 |
amit.gupta |
146 |
VendorItemPricing vip = vips.get(0);
|
|
|
147 |
pm.setNlc(vip.getNlc());
|
|
|
148 |
pm.setTp(vip.getTp());
|
|
|
149 |
} else {
|
|
|
150 |
throw new ProfitMandiBusinessException("Item Id", itemId, "Vendor item pricing does not exist");
|
|
|
151 |
}
|
|
|
152 |
}
|
| 24083 |
amit.gupta |
153 |
} catch (Exception e) {
|
| 24063 |
amit.gupta |
154 |
LOGGER.info("Chose item that doesn't exist");
|
| 24049 |
amit.gupta |
155 |
}
|
|
|
156 |
model.addAttribute("response", mvcResponseSender.createResponseString(pm));
|
|
|
157 |
return "response";
|
|
|
158 |
}
|
| 24083 |
amit.gupta |
159 |
|
| 24168 |
amit.gupta |
160 |
@RequestMapping(value = "/item", method = RequestMethod.GET)
|
|
|
161 |
public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query) throws Throwable {
|
| 24383 |
amit.gupta |
162 |
String query1 = query.toLowerCase();
|
| 26299 |
amit.gupta |
163 |
List<ItemDescriptionModel> partnersItemDescription = inventoryService.getAllPartnerItemStringDescription().parallelStream()
|
| 24564 |
amit.gupta |
164 |
.filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
|
|
|
165 |
.collect(Collectors.toList());
|
| 24168 |
amit.gupta |
166 |
|
| 24191 |
amit.gupta |
167 |
model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
|
| 24168 |
amit.gupta |
168 |
return "response";
|
|
|
169 |
}
|
|
|
170 |
|
| 23951 |
amit.gupta |
171 |
@RequestMapping(value = "/price-drop/imes/download")
|
|
|
172 |
public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
|
|
|
173 |
@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
|
|
|
174 |
Item item = itemRepository.selectById(itemId);
|
| 23968 |
amit.gupta |
175 |
ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId());
|
| 23951 |
amit.gupta |
176 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
177 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 25408 |
amit.gupta |
178 |
headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
|
| 23951 |
amit.gupta |
179 |
byte[] byteArray = baos.toByteArray();
|
|
|
180 |
headers.setContentLength(byteArray.length);
|
|
|
181 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
|
|
182 |
}
|
|
|
183 |
|
| 24083 |
amit.gupta |
184 |
@RequestMapping(value = "/price-drop/addPayout", method = RequestMethod.POST)
|
|
|
185 |
public String updatePriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
|
|
|
186 |
Model model) throws Exception {
|
|
|
187 |
boolean response = false;
|
|
|
188 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
|
|
|
189 |
if (priceDrop.getProcessTimestamp() == null) {
|
|
|
190 |
priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
|
|
|
191 |
priceDrop.setPriceDropIn(priceDropProcessModel.getPriceDropIn());
|
|
|
192 |
// priceDrop.setProcessTimestamp(LocalDateTime.now());
|
|
|
193 |
priceDropRepository.persist(priceDrop);
|
|
|
194 |
response = true;
|
|
|
195 |
}
|
|
|
196 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
|
|
197 |
return "response";
|
|
|
198 |
}
|
|
|
199 |
|
|
|
200 |
@RequestMapping(value = "/priceDropImeis/{priceDropId}", method = RequestMethod.GET)
|
|
|
201 |
public String priceDropStatus(HttpServletRequest request, @PathVariable int priceDropId, Model model)
|
|
|
202 |
throws Exception {
|
|
|
203 |
|
|
|
204 |
PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
|
| 24564 |
amit.gupta |
205 |
|
|
|
206 |
// This call is used to persit imeis to pricedrop imeis in case its not there.
|
| 26116 |
amit.gupta |
207 |
//This should be called while creating price drop.
|
|
|
208 |
//priceDropService.priceDropStatus(priceDropId);
|
| 24564 |
amit.gupta |
209 |
|
| 24083 |
amit.gupta |
210 |
List<String> pendingImeis = new ArrayList<>();
|
|
|
211 |
List<String> approvedImeis = new ArrayList<>();
|
|
|
212 |
List<String> rejectedImeis = new ArrayList<>();
|
|
|
213 |
List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
|
|
|
214 |
for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
|
|
|
215 |
if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.PENDING)) {
|
|
|
216 |
pendingImeis.add(priceDropIMEI.getImei());
|
|
|
217 |
} else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)) {
|
|
|
218 |
approvedImeis.add(priceDropIMEI.getImei());
|
|
|
219 |
}
|
|
|
220 |
if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.REJECTED)) {
|
|
|
221 |
rejectedImeis.add(priceDropIMEI.getImei());
|
|
|
222 |
}
|
|
|
223 |
}
|
|
|
224 |
priceDropImeisModel.setPendingImeis(pendingImeis);
|
|
|
225 |
priceDropImeisModel.setPriceDropId(priceDropId);
|
|
|
226 |
priceDropImeisModel.setApprovedImeis(approvedImeis);
|
|
|
227 |
priceDropImeisModel.setRejectedImeis(rejectedImeis);
|
|
|
228 |
model.addAttribute("response", mvcResponseSender.createResponseString(priceDropImeisModel));
|
|
|
229 |
return "response";
|
|
|
230 |
}
|
|
|
231 |
|
| 23968 |
amit.gupta |
232 |
@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
|
|
|
233 |
public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcess,
|
|
|
234 |
Model model) throws Exception {
|
|
|
235 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcess.getPriceDropId());
|
|
|
236 |
boolean response = false;
|
|
|
237 |
if (priceDrop.getProcessTimestamp() == null) {
|
|
|
238 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
|
|
239 |
priceDropRepository.persist(priceDrop);
|
|
|
240 |
response = true;
|
| 23819 |
govind |
241 |
}
|
| 23968 |
amit.gupta |
242 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
|
|
243 |
return "response";
|
| 23819 |
govind |
244 |
}
|
| 24083 |
amit.gupta |
245 |
|
| 23884 |
amit.gupta |
246 |
@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
|
| 23945 |
amit.gupta |
247 |
public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
|
|
|
248 |
throws Exception {
|
| 23884 |
amit.gupta |
249 |
boolean response = false;
|
| 23968 |
amit.gupta |
250 |
priceDropModel.setAllColors(true);
|
| 23945 |
amit.gupta |
251 |
if (this.validatePriceDrop(priceDropModel)) {
|
| 23884 |
amit.gupta |
252 |
TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
|
| 24409 |
amit.gupta |
253 |
float oldDp = tagListing.getSellingPrice();
|
| 24410 |
amit.gupta |
254 |
float oldMop = tagListing.getMop();
|
|
|
255 |
float oldTp = 0;
|
| 24409 |
amit.gupta |
256 |
float newDp = priceDropModel.getDp();
|
| 24564 |
amit.gupta |
257 |
|
| 24410 |
amit.gupta |
258 |
if (newDp != oldDp) {
|
| 23884 |
amit.gupta |
259 |
List<Item> allItems = null;
|
|
|
260 |
Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
|
| 23945 |
amit.gupta |
261 |
if (priceDropModel.isAllColors()) {
|
| 23884 |
amit.gupta |
262 |
allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
|
| 23945 |
amit.gupta |
263 |
|
| 23884 |
amit.gupta |
264 |
} else {
|
| 23945 |
amit.gupta |
265 |
allItems = Arrays.asList(currentItem);
|
| 23884 |
amit.gupta |
266 |
}
|
| 23945 |
amit.gupta |
267 |
for (Item item : allItems) {
|
| 23884 |
amit.gupta |
268 |
TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
|
| 23945 |
amit.gupta |
269 |
if (itemTagListing == null)
|
|
|
270 |
continue;
|
| 23884 |
amit.gupta |
271 |
itemTagListing.setSellingPrice(newDp);
|
|
|
272 |
itemTagListing.setMop(priceDropModel.getMop());
|
|
|
273 |
tagListingRepository.persist(tagListing);
|
|
|
274 |
List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
|
| 23945 |
amit.gupta |
275 |
for (VendorItemPricing vip : vipList) {
|
| 24410 |
amit.gupta |
276 |
oldTp = vip.getNlc();
|
| 23884 |
amit.gupta |
277 |
vip.setDp(newDp);
|
|
|
278 |
vip.setMop(priceDropModel.getMop());
|
| 24409 |
amit.gupta |
279 |
vip.setNlc(priceDropModel.getTp());
|
| 23884 |
amit.gupta |
280 |
vip.setTp(priceDropModel.getTp());
|
|
|
281 |
vendorItemPricingRepository.persist(vip);
|
|
|
282 |
}
|
|
|
283 |
transactionService.updatePriceDrop(item.getId(), newDp);
|
|
|
284 |
}
|
| 24822 |
amit.gupta |
285 |
|
|
|
286 |
//Add to itemPricing history
|
|
|
287 |
ItemPricingHistory iph = new ItemPricingHistory();
|
|
|
288 |
iph.setCatalogId(currentItem.getCatalogItemId());
|
|
|
289 |
iph.setTp(priceDropModel.getTp());
|
|
|
290 |
iph.setDp(priceDropModel.getDp());
|
|
|
291 |
iph.setMop(priceDropModel.getMop());
|
|
|
292 |
//TODO: changedBy
|
|
|
293 |
iph.setChangedBy("me");
|
|
|
294 |
iph.setCreateTimestamp(LocalDateTime.now());
|
|
|
295 |
itemPricingHistoryRepository.persist(iph);
|
|
|
296 |
|
|
|
297 |
|
| 23951 |
amit.gupta |
298 |
PriceDrop priceDrop = new PriceDrop();
|
|
|
299 |
priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
|
| 24410 |
amit.gupta |
300 |
priceDrop.setTp(oldTp);
|
|
|
301 |
priceDrop.setNlc(oldTp);
|
|
|
302 |
priceDrop.setMop(oldMop);
|
| 24409 |
amit.gupta |
303 |
priceDrop.setOldDp(oldDp);
|
|
|
304 |
priceDrop.setAmount(oldDp - newDp);
|
| 23968 |
amit.gupta |
305 |
priceDrop.setNewDp(newDp);
|
| 23951 |
amit.gupta |
306 |
priceDrop.setCreatedOn(LocalDateTime.now());
|
|
|
307 |
priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
|
|
|
308 |
priceDropRepository.persist(priceDrop);
|
| 26116 |
amit.gupta |
309 |
priceDropService.priceDropStatus(priceDrop.getId());
|
| 23884 |
amit.gupta |
310 |
response = true;
|
|
|
311 |
} else {
|
| 23945 |
amit.gupta |
312 |
throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
|
| 24409 |
amit.gupta |
313 |
"Price Drop Should be greater than 0");
|
| 23884 |
amit.gupta |
314 |
}
|
|
|
315 |
}
|
|
|
316 |
model.addAttribute("response", mvcResponseSender.createResponseString(response));
|
|
|
317 |
return "response";
|
|
|
318 |
}
|
| 23945 |
amit.gupta |
319 |
|
| 23819 |
govind |
320 |
@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
|
|
|
321 |
public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
|
| 23945 |
amit.gupta |
322 |
Model model) throws ProfitMandiBusinessException, Exception {
|
| 23819 |
govind |
323 |
|
|
|
324 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
| 23968 |
amit.gupta |
325 |
Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
|
|
|
326 |
ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId());
|
|
|
327 |
final HttpHeaders headers = new HttpHeaders();
|
|
|
328 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 23983 |
amit.gupta |
329 |
headers.set("Content-disposition",
|
|
|
330 |
"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
|
|
|
331 |
+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
|
| 23968 |
amit.gupta |
332 |
byte[] byteArray = baos.toByteArray();
|
|
|
333 |
headers.setContentLength(byteArray.length);
|
|
|
334 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
| 23951 |
amit.gupta |
335 |
|
|
|
336 |
}
|
|
|
337 |
|
| 24083 |
amit.gupta |
338 |
@RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
|
| 24822 |
amit.gupta |
339 |
public String updatePriceDropImeis(HttpServletRequest request,
|
| 24083 |
amit.gupta |
340 |
@RequestBody PriceDropImeisModel priceDropImeisModel, Model model)
|
|
|
341 |
throws ProfitMandiBusinessException, Exception {
|
| 24168 |
amit.gupta |
342 |
PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
|
| 24083 |
amit.gupta |
343 |
|
|
|
344 |
switch (priceDropImeisModel.getUpdatedStatus()) {
|
| 26332 |
amit.gupta |
345 |
case "approved": {
|
|
|
346 |
status = PriceDropImeiStatus.APPROVED;
|
|
|
347 |
break;
|
|
|
348 |
}
|
|
|
349 |
case "rejected": {
|
|
|
350 |
status = PriceDropImeiStatus.REJECTED;
|
|
|
351 |
break;
|
|
|
352 |
}
|
| 24083 |
amit.gupta |
353 |
}
|
| 26332 |
amit.gupta |
354 |
|
|
|
355 |
if(PriceDropImeiStatus.PENDING.equals(status)) {
|
|
|
356 |
throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING", "only approved and rejected is allowed");
|
| 24083 |
amit.gupta |
357 |
}
|
| 26332 |
amit.gupta |
358 |
|
|
|
359 |
//TODO:PD
|
| 24083 |
amit.gupta |
360 |
List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
|
|
|
361 |
.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
|
|
|
362 |
|
|
|
363 |
List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
|
|
|
364 |
for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
|
|
|
365 |
if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
|
|
|
366 |
|| priceDropIMEI.getStatus().equals(status)) {
|
|
|
367 |
continue;
|
|
|
368 |
} else {
|
| 26332 |
amit.gupta |
369 |
priceDropIMEIsToProcess.add(priceDropIMEI);
|
|
|
370 |
priceDropIMEI.setStatus(status);
|
|
|
371 |
if(status.equals(PriceDropImeiStatus.REJECTED)) {
|
|
|
372 |
priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
|
| 24083 |
amit.gupta |
373 |
}
|
|
|
374 |
priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
|
|
|
375 |
priceDropIMEIRepository.persist(priceDropIMEI);
|
|
|
376 |
}
|
|
|
377 |
}
|
|
|
378 |
if (priceDropIMEIsToProcess.size() > 0) {
|
| 26332 |
amit.gupta |
379 |
priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(), priceDropIMEIsToProcess, status);
|
| 24083 |
amit.gupta |
380 |
}
|
| 24168 |
amit.gupta |
381 |
|
| 24083 |
amit.gupta |
382 |
model.addAttribute("response", mvcResponseSender.createResponseString(true));
|
|
|
383 |
return "response";
|
|
|
384 |
|
|
|
385 |
}
|
|
|
386 |
|
| 23983 |
amit.gupta |
387 |
private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId)
|
|
|
388 |
throws Exception {
|
| 24564 |
amit.gupta |
389 |
List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
|
|
|
390 |
.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
|
| 25852 |
amit.gupta |
391 |
List<List<?>> rows = new ArrayList<>();
|
| 23983 |
amit.gupta |
392 |
for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
|
| 23986 |
amit.gupta |
393 |
rows.add(this.getRow(imeiDropSummaryModel));
|
| 23951 |
amit.gupta |
394 |
}
|
|
|
395 |
return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
|
| 26311 |
amit.gupta |
396 |
"Model Name", "Model Number", "Color", "Last Scanned", "Vendor Name", "Activation Timestamp", "Activation Added On"), rows);
|
| 23819 |
govind |
397 |
}
|
| 24083 |
amit.gupta |
398 |
|
| 24822 |
amit.gupta |
399 |
private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel) {
|
|
|
400 |
List<Serializable> row = new ArrayList<>();
|
| 23986 |
amit.gupta |
401 |
row.add(imeiDropSummaryModel.getSerialNumber());
|
|
|
402 |
row.add(imeiDropSummaryModel.getStoreName());
|
|
|
403 |
row.add(imeiDropSummaryModel.getPartnerCode());
|
|
|
404 |
row.add(imeiDropSummaryModel.getItemId());
|
|
|
405 |
row.add(imeiDropSummaryModel.getBrand());
|
|
|
406 |
row.add(imeiDropSummaryModel.getModelName());
|
|
|
407 |
row.add(imeiDropSummaryModel.getModelNumber());
|
|
|
408 |
row.add(imeiDropSummaryModel.getColor());
|
|
|
409 |
row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
|
| 25629 |
amit.gupta |
410 |
row.add(imeiDropSummaryModel.getVendorName());
|
| 23986 |
amit.gupta |
411 |
return row;
|
|
|
412 |
}
|
| 23819 |
govind |
413 |
|
| 23884 |
amit.gupta |
414 |
private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
|
| 24564 |
amit.gupta |
415 |
if (priceDropModel.getMop() > 0 && priceDropModel.getDp() > 0 && priceDropModel.getTp() > 0) {
|
| 23884 |
amit.gupta |
416 |
return true;
|
|
|
417 |
}
|
|
|
418 |
return false;
|
|
|
419 |
}
|
| 23945 |
amit.gupta |
420 |
|
| 23819 |
govind |
421 |
}
|