Subversion Repositories SmartDukaan

Rev

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

Rev 26420 Rev 27071
Line 59... Line 59...
59
import com.spice.profitmandi.service.transaction.TransactionService;
59
import com.spice.profitmandi.service.transaction.TransactionService;
60
import com.spice.profitmandi.service.wallet.WalletService;
60
import com.spice.profitmandi.service.wallet.WalletService;
61
import com.spice.profitmandi.web.util.MVCResponseSender;
61
import com.spice.profitmandi.web.util.MVCResponseSender;
62
 
62
 
63
@Controller
63
@Controller
64
@Transactional(rollbackFor=Throwable.class)
64
@Transactional(rollbackFor = Throwable.class)
65
public class PriceDropController {
65
public class PriceDropController {
66
 
66
 
67
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
67
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
68
 
68
 
69
	@Autowired
69
	@Autowired
Line 82... Line 82...
82
	@Autowired
82
	@Autowired
83
	private MVCResponseSender mvcResponseSender;
83
	private MVCResponseSender mvcResponseSender;
84
 
84
 
85
	@Autowired
85
	@Autowired
86
	private PriceDropService priceDropService;
86
	private PriceDropService priceDropService;
87
	
87
 
88
	@Autowired
88
	@Autowired
89
	private ItemPricingHistoryRepository itemPricingHistoryRepository;
89
	private ItemPricingHistoryRepository itemPricingHistoryRepository;
90
 
90
 
91
	@Autowired
91
	@Autowired
92
	private WalletService walletService;
92
	private WalletService walletService;
Line 153... Line 153...
153
	}
153
	}
154
 
154
 
155
	@RequestMapping(value = "/item", method = RequestMethod.GET)
155
	@RequestMapping(value = "/item", method = RequestMethod.GET)
156
	public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query) throws Throwable {
156
	public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query) throws Throwable {
157
		String query1 = query.toLowerCase();
157
		String query1 = query.toLowerCase();
158
		List<ItemDescriptionModel> partnersItemDescription = inventoryService.getAllPartnerItemStringDescription().parallelStream()
158
		List<ItemDescriptionModel> partnersItemDescription = inventoryService.getAllPartnerItemStringDescription()
159
				.filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
159
				.parallelStream().filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
160
				.collect(Collectors.toList());
160
				.collect(Collectors.toList());
161
 
161
 
162
		model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
162
		model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
163
		return "response";
163
		return "response";
164
	}
164
	}
Line 197... Line 197...
197
			throws Exception {
197
			throws Exception {
198
 
198
 
199
		PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
199
		PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
200
 
200
 
201
		// This call is used to persit imeis to pricedrop imeis in case its not there.
201
		// This call is used to persit imeis to pricedrop imeis in case its not there.
202
		//This should be called while creating price drop.
202
		// This should be called while creating price drop.
203
		//priceDropService.priceDropStatus(priceDropId);
203
		// priceDropService.priceDropStatus(priceDropId);
204
 
204
 
205
		List<String> pendingImeis = new ArrayList<>();
205
		List<String> pendingImeis = new ArrayList<>();
206
		List<String> approvedImeis = new ArrayList<>();
206
		List<String> approvedImeis = new ArrayList<>();
207
		List<String> rejectedImeis = new ArrayList<>();
207
		List<String> rejectedImeis = new ArrayList<>();
208
		List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
208
		List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
Line 223... Line 223...
223
		model.addAttribute("response", mvcResponseSender.createResponseString(priceDropImeisModel));
223
		model.addAttribute("response", mvcResponseSender.createResponseString(priceDropImeisModel));
224
		return "response";
224
		return "response";
225
	}
225
	}
226
 
226
 
227
	@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
227
	@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
228
	public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcess,
228
	public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
229
			Model model) throws Exception {
229
			Model model) throws Exception {
230
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcess.getPriceDropId());
230
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
231
		boolean response = false;
231
		boolean response = false;
232
		if (priceDrop.getProcessTimestamp() == null) {
232
		if(priceDrop.getPartnerPayout()==0) {
233
			priceDropService.processPriceDrop(priceDrop.getId());
233
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
234
			priceDrop.setProcessTimestamp(LocalDateTime.now());
-
 
235
			priceDropRepository.persist(priceDrop);
-
 
236
			response = true;
-
 
237
		}
234
		}
-
 
235
		priceDrop.setProcessTimestamp(LocalDateTime.now());
-
 
236
		priceDropRepository.persist(priceDrop);
-
 
237
		priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
-
 
238
			response = true;
238
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
239
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
239
		return "response";
240
		return "response";
240
	}
241
	}
241
 
242
 
242
	@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
243
	@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
Line 276... Line 277...
276
						vip.setTp(priceDropModel.getTp());
277
						vip.setTp(priceDropModel.getTp());
277
						vendorItemPricingRepository.persist(vip);
278
						vendorItemPricingRepository.persist(vip);
278
					}
279
					}
279
					transactionService.updatePriceDrop(item.getId(), newDp);
280
					transactionService.updatePriceDrop(item.getId(), newDp);
280
				}
281
				}
281
				
282
 
282
				//Add to itemPricing history
283
				// Add to itemPricing history
283
				ItemPricingHistory iph = new ItemPricingHistory();
284
				ItemPricingHistory iph = new ItemPricingHistory();
284
				iph.setCatalogId(currentItem.getCatalogItemId());
285
				iph.setCatalogId(currentItem.getCatalogItemId());
285
				iph.setTp(priceDropModel.getTp());
286
				iph.setTp(priceDropModel.getTp());
286
				iph.setDp(priceDropModel.getDp());
287
				iph.setDp(priceDropModel.getDp());
287
				iph.setMop(priceDropModel.getMop());
288
				iph.setMop(priceDropModel.getMop());
288
				//TODO: changedBy
289
				// TODO: changedBy
289
				iph.setChangedBy("me");
290
				iph.setChangedBy("me");
290
				iph.setCreateTimestamp(LocalDateTime.now());
291
				iph.setCreateTimestamp(LocalDateTime.now());
291
				itemPricingHistoryRepository.persist(iph);
292
				itemPricingHistoryRepository.persist(iph);
292
				
-
 
293
				
293
 
294
				PriceDrop priceDrop = new PriceDrop();
294
				PriceDrop priceDrop = new PriceDrop();
295
				priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
295
				priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
296
				priceDrop.setTp(oldTp);
296
				priceDrop.setTp(oldTp);
297
				priceDrop.setNlc(oldTp);
297
				priceDrop.setNlc(oldTp);
298
				priceDrop.setMop(oldMop);
298
				priceDrop.setMop(oldMop);
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).
321
		Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
322
				stream().collect(Collectors.toMap(x->x.getImei(), x->x));
322
				.collect(Collectors.toMap(x -> x.getImei(), x -> x));
323
		
323
 
324
		if(priceDropIMEIsMap.size()==0 && priceDrop.getProcessTimestamp()==null) {
324
		if (priceDropIMEIsMap.size() == 0 && priceDrop.getProcessTimestamp() == null) {
325
			priceDrop.setProcessTimestamp(LocalDateTime.now());
325
			priceDrop.setProcessTimestamp(LocalDateTime.now());
326
		} else {
326
		} else {
327
			priceDropService.priceDropStatus(priceDrop.getId());
327
			priceDropService.priceDropStatus(priceDrop.getId());
328
		}
328
		}
329
		
329
 
330
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
330
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
331
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(), priceDropIMEIsMap);
331
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
-
 
332
				priceDropIMEIsMap);
332
		final HttpHeaders headers = new HttpHeaders();
333
		final HttpHeaders headers = new HttpHeaders();
333
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
334
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
334
		headers.set("Content-disposition",
335
		headers.set("Content-disposition",
335
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
336
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
336
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
337
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
Line 339... Line 340...
339
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
340
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
340
 
341
 
341
	}
342
	}
342
 
343
 
343
	@RequestMapping(value = "/updatePriceDropImeis-DNC", method = RequestMethod.POST)
344
	@RequestMapping(value = "/updatePriceDropImeis-DNC", method = RequestMethod.POST)
344
	public String updatePriceDropImeis(HttpServletRequest request,
345
	public String updatePriceDropImeis(HttpServletRequest request, @RequestBody PriceDropImeisModel priceDropImeisModel,
345
			@RequestBody PriceDropImeisModel priceDropImeisModel, Model model)
-
 
346
			throws ProfitMandiBusinessException, Exception {
346
			Model model) throws ProfitMandiBusinessException, Exception {
347
		PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
347
		PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
348
 
348
 
349
		switch (priceDropImeisModel.getUpdatedStatus()) {
349
		switch (priceDropImeisModel.getUpdatedStatus()) {
350
			case "approved": {
350
		case "approved": {
351
				status = PriceDropImeiStatus.APPROVED_OURS;
351
			status = PriceDropImeiStatus.APPROVED_OURS;
352
				break;
-
 
353
			}
-
 
354
			case "rejected": {
-
 
355
				status = PriceDropImeiStatus.REJECTED;
-
 
356
				break;
352
			break;
357
			}
-
 
358
		}
353
		}
359
		
354
		case "rejected": {
360
		if(PriceDropImeiStatus.PENDING.equals(status)) {
355
			status = PriceDropImeiStatus.REJECTED;
361
			throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING", "only approved and rejected is allowed");
-
 
-
 
356
			break;
362
		}
357
		}
363
		
358
		}
-
 
359
 
-
 
360
		if (PriceDropImeiStatus.PENDING.equals(status)) {
-
 
361
			throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING",
-
 
362
					"only approved and rejected is allowed");
-
 
363
		}
-
 
364
 
364
		//TODO:PD 
365
		// TODO:PD
365
		List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
366
		List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
366
				.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
367
				.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
367
 
368
 
368
		List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
369
		List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
369
		for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
370
		for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
370
			if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
371
			if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
371
					|| priceDropIMEI.getStatus().equals(status)) {
372
					|| priceDropIMEI.getStatus().equals(status)) {
372
				continue;
373
				continue;
373
			}
374
			}
374
			priceDropIMEIsToProcess.add(priceDropIMEI);
375
			priceDropIMEIsToProcess.add(priceDropIMEI);
375
			if(status.equals(PriceDropImeiStatus.REJECTED)) {
376
			if (status.equals(PriceDropImeiStatus.REJECTED)) {
376
				priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
377
				priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
377
			}
378
			}
378
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
379
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
379
		}
380
		}
-
 
381
		/*
380
		/*if (priceDropIMEIsToProcess.size() > 0) {
382
		 * if (priceDropIMEIsToProcess.size() > 0) {
381
			priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(), priceDropIMEIsToProcess, status);
383
		 * priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(),
-
 
384
		 * priceDropIMEIsToProcess, status); }
382
		}*/
385
		 */
383
 
386
 
384
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
387
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
385
		return "response";
388
		return "response";
386
 
389
 
387
	}
390
	}
388
 
391
 
389
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId, Map<String, PriceDropIMEI> priceDropImeis)
392
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
390
			throws Exception {
393
			Map<String, PriceDropIMEI> priceDropImeis) throws Exception {
391
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
394
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
392
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
395
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
393
		List<List<?>> rows = new ArrayList<>();
396
		List<List<?>> rows = new ArrayList<>();
394
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
397
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
395
			if(priceDropImeis == null) {
398
			if (priceDropImeis == null) {
396
				rows.add(this.getRow(imeiDropSummaryModel, null));
399
				rows.add(this.getRow(imeiDropSummaryModel, null));
397
			} else if(priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
400
			} else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
398
				rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
401
				rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
399
			}
402
			}
400
		}
403
		}
401
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand", 
404
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
402
				"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name", "Grn On", "Activation Timestamp", "Activation Added On"), rows);
405
				"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
-
 
406
				"Grn On", "Activation Timestamp", "Activation Added On"), rows);
403
	}
407
	}
404
 
408
 
405
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel, PriceDropIMEI priceDropIMEI) {
409
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel,
-
 
410
			PriceDropIMEI priceDropIMEI) {
406
		List<Serializable> row = new ArrayList<>();
411
		List<Serializable> row = new ArrayList<>();
407
		row.add(imeiDropSummaryModel.getSerialNumber());
412
		row.add(imeiDropSummaryModel.getSerialNumber());
408
		row.add(imeiDropSummaryModel.getStoreName());
413
		row.add(imeiDropSummaryModel.getStoreName());
409
		row.add(imeiDropSummaryModel.getPartnerCode());
414
		row.add(imeiDropSummaryModel.getPartnerCode());
410
		row.add(imeiDropSummaryModel.getItemId());
415
		row.add(imeiDropSummaryModel.getItemId());
411
		row.add(imeiDropSummaryModel.getBrand());
416
		row.add(imeiDropSummaryModel.getBrand());
412
		row.add(imeiDropSummaryModel.getModelName());
417
		row.add(imeiDropSummaryModel.getModelName());
413
		row.add(imeiDropSummaryModel.getModelNumber());
418
		row.add(imeiDropSummaryModel.getModelNumber());
414
		row.add(imeiDropSummaryModel.getColor());
419
		row.add(imeiDropSummaryModel.getColor());
415
		if(priceDropIMEI != null) {
420
		if (priceDropIMEI != null) {
416
			row.add(priceDropIMEI.getStatus());
421
			row.add(priceDropIMEI.getStatus());
417
			row.add(priceDropIMEI.getRejectionReason());
422
			row.add(priceDropIMEI.getRejectionReason());
418
		} else {
423
		} else {
419
			row.add(PriceDropImeiStatus.PENDING);
424
			row.add(PriceDropImeiStatus.PENDING);
420
			row.add("");
425
			row.add("");