| 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.text.MessageFormat;
|
4 |
import java.text.MessageFormat;
|
| 4 |
import java.time.LocalDate;
|
- |
|
| 5 |
import java.time.LocalDateTime;
|
5 |
import java.time.LocalDateTime;
|
| 6 |
import java.time.LocalTime;
|
- |
|
| 7 |
import java.util.ArrayList;
|
6 |
import java.util.ArrayList;
|
| 8 |
import java.util.Arrays;
|
7 |
import java.util.Arrays;
|
| 9 |
import java.util.HashMap;
|
- |
|
| 10 |
import java.util.List;
|
8 |
import java.util.List;
|
| 11 |
import java.util.Map;
|
9 |
import java.util.Map;
|
| 12 |
import java.util.Set;
|
10 |
import java.util.Set;
|
| 13 |
import java.util.stream.Collectors;
|
11 |
import java.util.stream.Collectors;
|
| 14 |
|
12 |
|
| 15 |
import javax.servlet.http.HttpServletRequest;
|
13 |
import javax.servlet.http.HttpServletRequest;
|
| 16 |
import javax.transaction.Transactional;
|
14 |
import javax.transaction.Transactional;
|
| 17 |
|
15 |
|
| 18 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
16 |
import org.apache.commons.io.output.ByteArrayOutputStream;
|
| 19 |
import org.apache.commons.lang.StringUtils;
|
- |
|
| 20 |
import org.apache.http.HttpResponse;
|
- |
|
| 21 |
import org.apache.logging.log4j.LogManager;
|
17 |
import org.apache.logging.log4j.LogManager;
|
| 22 |
import org.apache.logging.log4j.Logger;
|
18 |
import org.apache.logging.log4j.Logger;
|
| 23 |
import org.springframework.beans.factory.annotation.Autowired;
|
19 |
import org.springframework.beans.factory.annotation.Autowired;
|
| 24 |
import org.springframework.beans.factory.annotation.Qualifier;
|
20 |
import org.springframework.beans.factory.annotation.Qualifier;
|
| 25 |
import org.springframework.cache.annotation.Cacheable;
|
21 |
import org.springframework.cache.annotation.Cacheable;
|
| Line 33... |
Line 29... |
| 33 |
import org.springframework.web.bind.annotation.RequestBody;
|
29 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 34 |
import org.springframework.web.bind.annotation.RequestMapping;
|
30 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 35 |
import org.springframework.web.bind.annotation.RequestMethod;
|
31 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 36 |
import org.springframework.web.bind.annotation.RequestParam;
|
32 |
import org.springframework.web.bind.annotation.RequestParam;
|
| 37 |
|
33 |
|
| 38 |
import com.fasterxml.jackson.databind.JavaType;
|
- |
|
| 39 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
34 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
| 40 |
import com.fasterxml.jackson.databind.ObjectReader;
|
- |
|
| 41 |
import com.spice.profitmandi.common.enumuration.ReporticoProject;
|
- |
|
| 42 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
35 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 43 |
import com.spice.profitmandi.common.model.ClosingStockOnDate;
|
- |
|
| 44 |
import com.spice.profitmandi.common.model.GrnPendingDataModel;
|
- |
|
| 45 |
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
|
36 |
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
|
| 46 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
37 |
import com.spice.profitmandi.common.model.ItemDescriptionModel;
|
| 47 |
import com.spice.profitmandi.common.model.PartnerImeiNotSold;
|
- |
|
| 48 |
import com.spice.profitmandi.common.model.PriceDropImeisModel;
|
38 |
import com.spice.profitmandi.common.model.PriceDropImeisModel;
|
| 49 |
import com.spice.profitmandi.common.model.PriceDropModel;
|
39 |
import com.spice.profitmandi.common.model.PriceDropModel;
|
| 50 |
import com.spice.profitmandi.common.model.PriceDropProcessModel;
|
40 |
import com.spice.profitmandi.common.model.PriceDropProcessModel;
|
| 51 |
import com.spice.profitmandi.common.model.ReporticoResponseModel;
|
- |
|
| 52 |
import com.spice.profitmandi.common.services.ReporticoService;
|
41 |
import com.spice.profitmandi.common.services.ReporticoService;
|
| 53 |
import com.spice.profitmandi.common.util.FileUtil;
|
42 |
import com.spice.profitmandi.common.util.FileUtil;
|
| 54 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
43 |
import com.spice.profitmandi.common.util.FormattingUtils;
|
| 55 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
44 |
import com.spice.profitmandi.dao.entity.catalog.Item;
|
| 56 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
45 |
import com.spice.profitmandi.dao.entity.catalog.TagListing;
|
| 57 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
46 |
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
|
| - |
|
47 |
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
|
| 58 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
48 |
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
|
| 59 |
import com.spice.profitmandi.dao.entity.transaction.LineItemImei;
|
- |
|
| 60 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
49 |
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
|
| 61 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
50 |
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
|
| 62 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
51 |
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
|
| 63 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
52 |
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
|
| 64 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
53 |
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
|
| 65 |
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
|
54 |
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
|
| 66 |
import com.spice.profitmandi.dao.repository.fofo.SchemeInOutRepository;
|
- |
|
| 67 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
55 |
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
|
| 68 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
56 |
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
|
| 69 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
57 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
|
| 70 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
58 |
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
|
| 71 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
59 |
import com.spice.profitmandi.service.inventory.InventoryService;
|
| Line 99... |
Line 87... |
| 99 |
@Autowired
|
87 |
@Autowired
|
| 100 |
private MVCResponseSender mvcResponseSender;
|
88 |
private MVCResponseSender mvcResponseSender;
|
| 101 |
|
89 |
|
| 102 |
@Autowired
|
90 |
@Autowired
|
| 103 |
private PriceDropService priceDropService;
|
91 |
private PriceDropService priceDropService;
|
| - |
|
92 |
|
| - |
|
93 |
@Autowired
|
| - |
|
94 |
private ItemPricingHistoryRepository itemPricingHistoryRepository;
|
| 104 |
|
95 |
|
| 105 |
@Autowired
|
96 |
@Autowired
|
| 106 |
private WalletService walletService;
|
97 |
private WalletService walletService;
|
| 107 |
|
98 |
|
| 108 |
@Autowired
|
99 |
@Autowired
|
| Line 186... |
Line 177... |
| 186 |
itemDescriptionModel.setItemId(x.getId());
|
177 |
itemDescriptionModel.setItemId(x.getId());
|
| 187 |
itemDescriptionModel.setCatalogId(x.getCatalogItemId());
|
178 |
itemDescriptionModel.setCatalogId(x.getCatalogItemId());
|
| 188 |
return itemDescriptionModel;
|
179 |
return itemDescriptionModel;
|
| 189 |
}).collect(Collectors.toList());
|
180 |
}).collect(Collectors.toList());
|
| 190 |
}
|
181 |
}
|
| 191 |
|
- |
|
| 192 |
/*
|
- |
|
| 193 |
* IN-Request-20181101-0125
|
- |
|
| 194 |
*
|
- |
|
| 195 |
* @RequestMapping(value = "/price-drop/imes1/download") public
|
- |
|
| 196 |
* ResponseEntity<ByteArrayResource> downloadPriceDropImeis1(HttpServletRequest
|
- |
|
| 197 |
* request,
|
- |
|
| 198 |
*
|
- |
|
| 199 |
* @RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws
|
- |
|
| 200 |
* Exception { Item item = itemRepository.selectById(itemId);
|
- |
|
| 201 |
* List<ImeiDropSummaryModel> imeiDropSummaryModelList =
|
- |
|
| 202 |
* this.getAllSerialNumbersByAffectedDate(affectedDate,
|
- |
|
| 203 |
* item.getCatalogItemId()); List<String> imeis =
|
- |
|
| 204 |
* imeiDropSummaryModelList.stream().map(x->x.getSerialNumber()).collect(
|
- |
|
| 205 |
* Collectors.toList()); Map<String, ImeiDropSummaryModel> imeisDropMap =
|
- |
|
| 206 |
* imeiDropSummaryModelList.stream().collect(Collectors.toMap(
|
- |
|
| 207 |
* ImeiDropSummaryModel::getSerialNumber, x->x)); List<InventoryItem>
|
- |
|
| 208 |
* inventoryItems = inventoryItemRepository.selectBySerialNumbers(new
|
- |
|
| 209 |
* HashSet<>(imeis)); List<Integer> inventoryItemIds =
|
- |
|
| 210 |
* inventoryItems.stream().map(InventoryItem::getId).collect(Collectors.toList()
|
- |
|
| 211 |
* );
|
- |
|
| 212 |
*
|
- |
|
| 213 |
* List<SchemeInOut> schemeInOuts =
|
- |
|
| 214 |
* schemeInOutRepository.selectByInventoryItemIds(new
|
- |
|
| 215 |
* HashSet<>(inventoryItemIds));
|
- |
|
| 216 |
*
|
- |
|
| 217 |
* Set<ItemQuantity> itemSchemes = new HashSet<>(); Map<ItemQuantity,
|
- |
|
| 218 |
* SchemeInOut> itemSchemeInOutMap = new HashMap<>(); for(SchemeInOut
|
- |
|
| 219 |
* schemeInOut : schemeInOuts) { } List<List<Object>> rows = new ArrayList<>();
|
- |
|
| 220 |
* for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
|
- |
|
| 221 |
* List<Object> row = this.getRow(imeiDropSummaryModel);
|
- |
|
| 222 |
*
|
- |
|
| 223 |
* rows.add(this.getRow(imeiDropSummaryModel)); }
|
- |
|
| 224 |
*
|
- |
|
| 225 |
* FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name",
|
- |
|
| 226 |
* "Store Code", "Item ID", "Brand", "Model Name", "Model Number", "Color",
|
- |
|
| 227 |
* "Last Scanned"), rows); final HttpHeaders headers = new HttpHeaders();
|
- |
|
| 228 |
* headers.set("Content-Type",
|
- |
|
| 229 |
* "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
- |
|
| 230 |
* headers.set("Content-disposition", "inline; filename=imei-" +
|
- |
|
| 231 |
* item.getItemDescriptionNoColor() + ".csv"); return new
|
- |
|
| 232 |
* ResponseEntity<ByteArrayResource>(null, headers, HttpStatus.OK);
|
- |
|
| 233 |
*
|
- |
|
| 234 |
* }
|
- |
|
| 235 |
*/
|
- |
|
| 236 |
@RequestMapping(value = "/price-drop/imes/download")
|
182 |
@RequestMapping(value = "/price-drop/imes/download")
|
| 237 |
public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
|
183 |
public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
|
| 238 |
@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
|
184 |
@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
|
| 239 |
Item item = itemRepository.selectById(itemId);
|
185 |
Item item = itemRepository.selectById(itemId);
|
| 240 |
ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId());
|
186 |
ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId());
|
| Line 344... |
Line 290... |
| 344 |
vip.setTp(priceDropModel.getTp());
|
290 |
vip.setTp(priceDropModel.getTp());
|
| 345 |
vendorItemPricingRepository.persist(vip);
|
291 |
vendorItemPricingRepository.persist(vip);
|
| 346 |
}
|
292 |
}
|
| 347 |
transactionService.updatePriceDrop(item.getId(), newDp);
|
293 |
transactionService.updatePriceDrop(item.getId(), newDp);
|
| 348 |
}
|
294 |
}
|
| - |
|
295 |
|
| - |
|
296 |
//Add to itemPricing history
|
| - |
|
297 |
ItemPricingHistory iph = new ItemPricingHistory();
|
| - |
|
298 |
iph.setCatalogId(currentItem.getCatalogItemId());
|
| - |
|
299 |
iph.setTp(priceDropModel.getTp());
|
| - |
|
300 |
iph.setDp(priceDropModel.getDp());
|
| - |
|
301 |
iph.setMop(priceDropModel.getMop());
|
| - |
|
302 |
//TODO: changedBy
|
| - |
|
303 |
iph.setChangedBy("me");
|
| - |
|
304 |
iph.setCreateTimestamp(LocalDateTime.now());
|
| - |
|
305 |
itemPricingHistoryRepository.persist(iph);
|
| - |
|
306 |
|
| - |
|
307 |
|
| 349 |
PriceDrop priceDrop = new PriceDrop();
|
308 |
PriceDrop priceDrop = new PriceDrop();
|
| 350 |
priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
|
309 |
priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
|
| 351 |
priceDrop.setTp(oldTp);
|
310 |
priceDrop.setTp(oldTp);
|
| 352 |
priceDrop.setNlc(oldTp);
|
311 |
priceDrop.setNlc(oldTp);
|
| 353 |
priceDrop.setMop(oldMop);
|
312 |
priceDrop.setMop(oldMop);
|
| Line 384... |
Line 343... |
| 384 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
343 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
| 385 |
|
344 |
|
| 386 |
}
|
345 |
}
|
| 387 |
|
346 |
|
| 388 |
@RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
|
347 |
@RequestMapping(value = "/updatePriceDropImeis", method = RequestMethod.POST)
|
| 389 |
public String downloadTotalPriceDropIMEI(HttpServletRequest request,
|
348 |
public String updatePriceDropImeis(HttpServletRequest request,
|
| 390 |
@RequestBody PriceDropImeisModel priceDropImeisModel, Model model)
|
349 |
@RequestBody PriceDropImeisModel priceDropImeisModel, Model model)
|
| 391 |
throws ProfitMandiBusinessException, Exception {
|
350 |
throws ProfitMandiBusinessException, Exception {
|
| 392 |
PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
|
351 |
PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
|
| 393 |
;
|
352 |
;
|
| 394 |
|
353 |
|
| Line 464... |
Line 423... |
| 464 |
|
423 |
|
| 465 |
private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId)
|
424 |
private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId)
|
| 466 |
throws Exception {
|
425 |
throws Exception {
|
| 467 |
List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
|
426 |
List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
|
| 468 |
.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
|
427 |
.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
|
| 469 |
List<List<?>> rows = new ArrayList<>();
|
428 |
List<List<? extends Serializable>> rows = new ArrayList<>();
|
| 470 |
for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
|
429 |
for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
|
| 471 |
rows.add(this.getRow(imeiDropSummaryModel));
|
430 |
rows.add(this.getRow(imeiDropSummaryModel));
|
| 472 |
}
|
431 |
}
|
| 473 |
return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
|
432 |
return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
|
| 474 |
"Model Name", "Model Number", "Color", "Last Scanned"), rows);
|
433 |
"Model Name", "Model Number", "Color", "Last Scanned"), rows);
|
| 475 |
}
|
434 |
}
|
| 476 |
|
435 |
|
| 477 |
private List<Object> getRow(ImeiDropSummaryModel imeiDropSummaryModel) {
|
436 |
private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel) {
|
| 478 |
List<Object> row = new ArrayList<>();
|
437 |
List<Serializable> row = new ArrayList<>();
|
| 479 |
row.add(imeiDropSummaryModel.getSerialNumber());
|
438 |
row.add(imeiDropSummaryModel.getSerialNumber());
|
| 480 |
row.add(imeiDropSummaryModel.getStoreName());
|
439 |
row.add(imeiDropSummaryModel.getStoreName());
|
| 481 |
row.add(imeiDropSummaryModel.getPartnerCode());
|
440 |
row.add(imeiDropSummaryModel.getPartnerCode());
|
| 482 |
row.add(imeiDropSummaryModel.getItemId());
|
441 |
row.add(imeiDropSummaryModel.getItemId());
|
| 483 |
row.add(imeiDropSummaryModel.getBrand());
|
442 |
row.add(imeiDropSummaryModel.getBrand());
|