| Line 413... |
Line 413... |
| 413 |
|
413 |
|
| 414 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
414 |
PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
|
| 415 |
Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
|
415 |
Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
|
| 416 |
.collect(Collectors.toMap(x -> x.getImei(), x -> x));
|
416 |
.collect(Collectors.toMap(x -> x.getImei(), x -> x));
|
| 417 |
|
417 |
|
| 418 |
if (priceDropIMEIsMap.size() == 0 && priceDrop.getProcessTimestamp() == null) {
|
- |
|
| 419 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
- |
|
| 420 |
} else {
|
- |
|
| 421 |
priceDropService.priceDropStatus(priceDrop.getId());
|
- |
|
| 422 |
}
|
- |
|
| 423 |
|
- |
|
| 424 |
Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
|
418 |
Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
|
| 425 |
ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
|
- |
|
| 426 |
priceDropIMEIsMap);
|
- |
|
| 427 |
final HttpHeaders headers = new HttpHeaders();
|
419 |
final HttpHeaders headers = new HttpHeaders();
|
| 428 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
420 |
headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
|
| 429 |
headers.set("Content-disposition",
|
421 |
headers.set("Content-disposition",
|
| 430 |
"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
|
422 |
"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
|
| 431 |
+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
|
423 |
+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
|
| - |
|
424 |
ByteArrayOutputStream baos = null;
|
| - |
|
425 |
if (priceDropIMEIsMap.size() == 0 && priceDrop.getProcessTimestamp() == null) {
|
| - |
|
426 |
priceDrop.setProcessTimestamp(LocalDateTime.now());
|
| - |
|
427 |
} else if (priceDropIMEIsMap.size() == 0) {
|
| - |
|
428 |
priceDropService.priceDropStatus(priceDrop.getId());
|
| - |
|
429 |
baos = FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
|
| - |
|
430 |
"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
|
| - |
|
431 |
"Grn On", "Activation Timestamp", "Activation Added On"), new ArrayList<>());
|
| - |
|
432 |
} else {
|
| - |
|
433 |
baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
|
| - |
|
434 |
priceDropIMEIsMap);
|
| - |
|
435 |
}
|
| 432 |
byte[] byteArray = baos.toByteArray();
|
436 |
byte[] byteArray = baos.toByteArray();
|
| 433 |
headers.setContentLength(byteArray.length);
|
437 |
headers.setContentLength(byteArray.length);
|
| 434 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
438 |
return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
|
| 435 |
|
439 |
|
| 436 |
}
|
440 |
}
|