Subversion Repositories SmartDukaan

Rev

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

Rev 26352 Rev 26368
Line 165... Line 165...
165
 
165
 
166
	@RequestMapping(value = "/price-drop/imes/download")
166
	@RequestMapping(value = "/price-drop/imes/download")
167
	public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
167
	public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
168
			@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
168
			@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
169
		Item item = itemRepository.selectById(itemId);
169
		Item item = itemRepository.selectById(itemId);
170
		ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId());
170
		ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null);
171
		final HttpHeaders headers = new HttpHeaders();
171
		final HttpHeaders headers = new HttpHeaders();
172
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
172
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
173
		headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
173
		headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
174
		byte[] byteArray = baos.toByteArray();
174
		byte[] byteArray = baos.toByteArray();
175
		headers.setContentLength(byteArray.length);
175
		headers.setContentLength(byteArray.length);
Line 316... Line 316...
316
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
316
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
317
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
317
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
318
			Model model) throws ProfitMandiBusinessException, Exception {
318
			Model model) throws ProfitMandiBusinessException, Exception {
319
 
319
 
320
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
320
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
-
 
321
		Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).
-
 
322
				stream().collect(Collectors.toMap(x->x.getImei(), x->x));
-
 
323
		
321
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
324
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
322
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId());
325
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(), priceDropIMEIsMap);
323
		final HttpHeaders headers = new HttpHeaders();
326
		final HttpHeaders headers = new HttpHeaders();
324
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
327
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
325
		headers.set("Content-disposition",
328
		headers.set("Content-disposition",
326
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
329
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
327
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
330
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
Line 359... Line 362...
359
		List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
362
		List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
360
		for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
363
		for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
361
			if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
364
			if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
362
					|| priceDropIMEI.getStatus().equals(status)) {
365
					|| priceDropIMEI.getStatus().equals(status)) {
363
				continue;
366
				continue;
364
			} else {
-
 
365
				priceDropIMEIsToProcess.add(priceDropIMEI);
-
 
366
				priceDropIMEI.setStatus(status);
-
 
367
				if(status.equals(PriceDropImeiStatus.REJECTED)) {
-
 
368
					priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
-
 
369
				}
-
 
370
				priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
-
 
371
				priceDropIMEIRepository.persist(priceDropIMEI);
-
 
372
			}
367
			}
-
 
368
			priceDropIMEIsToProcess.add(priceDropIMEI);
-
 
369
			if(status.equals(PriceDropImeiStatus.REJECTED)) {
-
 
370
				priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
-
 
371
			}
-
 
372
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
373
		}
373
		}
374
		if (priceDropIMEIsToProcess.size() > 0) {
374
		if (priceDropIMEIsToProcess.size() > 0) {
375
			priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(), priceDropIMEIsToProcess, status);
375
			priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(), priceDropIMEIsToProcess, status);
376
		}
376
		}
377
 
377
 
378
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
378
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
379
		return "response";
379
		return "response";
380
 
380
 
381
	}
381
	}
382
 
382
 
383
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId)
383
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId, Map<String, PriceDropIMEI> priceDropImeis)
384
			throws Exception {
384
			throws Exception {
385
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
385
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
386
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
386
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
387
		List<List<?>> rows = new ArrayList<>();
387
		List<List<?>> rows = new ArrayList<>();
388
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
388
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
-
 
389
			if(priceDropImeis == null) {
389
			rows.add(this.getRow(imeiDropSummaryModel));
390
				rows.add(this.getRow(imeiDropSummaryModel, null));
-
 
391
			} else if(priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
-
 
392
				rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
-
 
393
			}
390
		}
394
		}
391
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
395
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand", 
392
				"Model Name", "Model Number", "Color", "Last Scanned", "Vendor Name", "Activation Timestamp", "Activation Added On"), rows);
396
				"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Activated On", "Added On", "Last Scanned", "Vendor Name", "Activation Timestamp", "Activation Added On"), rows);
393
	}
397
	}
394
 
398
 
395
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel) {
399
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel, PriceDropIMEI priceDropIMEI) {
396
		List<Serializable> row = new ArrayList<>();
400
		List<Serializable> row = new ArrayList<>();
397
		row.add(imeiDropSummaryModel.getSerialNumber());
401
		row.add(imeiDropSummaryModel.getSerialNumber());
398
		row.add(imeiDropSummaryModel.getStoreName());
402
		row.add(imeiDropSummaryModel.getStoreName());
399
		row.add(imeiDropSummaryModel.getPartnerCode());
403
		row.add(imeiDropSummaryModel.getPartnerCode());
400
		row.add(imeiDropSummaryModel.getItemId());
404
		row.add(imeiDropSummaryModel.getItemId());
401
		row.add(imeiDropSummaryModel.getBrand());
405
		row.add(imeiDropSummaryModel.getBrand());
402
		row.add(imeiDropSummaryModel.getModelName());
406
		row.add(imeiDropSummaryModel.getModelName());
403
		row.add(imeiDropSummaryModel.getModelNumber());
407
		row.add(imeiDropSummaryModel.getModelNumber());
404
		row.add(imeiDropSummaryModel.getColor());
408
		row.add(imeiDropSummaryModel.getColor());
-
 
409
		if(priceDropIMEI != null) {
-
 
410
			row.add(priceDropIMEI.getStatus());
-
 
411
			row.add(priceDropIMEI.getRejectionReason());
-
 
412
		} else {
-
 
413
			row.add(PriceDropImeiStatus.PENDING);
-
 
414
			row.add("");
-
 
415
		}
-
 
416
		row.add(imeiDropSummaryModel.getActivationTimestamp());
-
 
417
		row.add(imeiDropSummaryModel.getActivationAddedOn());
405
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
418
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
406
		row.add(imeiDropSummaryModel.getVendorName());
419
		row.add(imeiDropSummaryModel.getVendorName());
407
		return row;
420
		return row;
408
	}
421
	}
409
 
422