Subversion Repositories SmartDukaan

Rev

Rev 33189 | Rev 33470 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 33189 Rev 33198
Line 205... Line 205...
205
 
205
 
206
    @RequestMapping(value = "/price-drop/imes/download")
206
    @RequestMapping(value = "/price-drop/imes/download")
207
    public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
207
    public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
208
                                                                    @RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
208
                                                                    @RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
209
        Item item = itemRepository.selectById(itemId);
209
        Item item = itemRepository.selectById(itemId);
210
        ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null);
210
        ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null, Optional.empty());
211
        final HttpHeaders headers = new HttpHeaders();
211
        final HttpHeaders headers = new HttpHeaders();
212
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
212
        headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
213
        headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
213
        headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
214
        byte[] byteArray = baos.toByteArray();
214
        byte[] byteArray = baos.toByteArray();
215
        headers.setContentLength(byteArray.length);
215
        headers.setContentLength(byteArray.length);
Line 411... Line 411...
411
                    "Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
411
                    "Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
412
                    "Grn On", "Activation Timestamp", "Activation Added On"), new ArrayList<>());
412
                    "Grn On", "Activation Timestamp", "Activation Added On"), new ArrayList<>());
413
        } else {
413
        } else {
414
 
414
 
415
            LOGGER.info("In else block");
415
            LOGGER.info("In else block");
416
            baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
416
            baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(), priceDropIMEIsMap, Optional.of(priceDrop.getCreatedOn()));
417
                    priceDropIMEIsMap);
-
 
418
        }
417
        }
419
        byte[] byteArray = baos.toByteArray();
418
        byte[] byteArray = baos.toByteArray();
420
        headers.setContentLength(byteArray.length);
419
        headers.setContentLength(byteArray.length);
421
        return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
420
        return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
422
 
421
 
Line 495... Line 494...
495
        return "response";
494
        return "response";
496
 
495
 
497
    }
496
    }
498
 
497
 
499
    private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
498
    private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
500
                                                           Map<String, PriceDropIMEI> priceDropImeis) throws Exception {
499
                                                           Map<String, PriceDropIMEI> priceDropImeis, Optional<LocalDateTime> createdOn) throws Exception {
-
 
500
 
501
        List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
501
        List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
502
                .getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId, Optional.empty());
502
                .getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId, createdOn);
503
        List<List<?>> rows = new ArrayList<>();
503
        List<List<?>> rows = new ArrayList<>();
504
        for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
504
        for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
505
            if (priceDropImeis == null) {
505
            if (priceDropImeis == null) {
506
                rows.add(this.getRow(imeiDropSummaryModel, null));
506
                rows.add(this.getRow(imeiDropSummaryModel, null));
507
            } else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
507
            } else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {