Subversion Repositories SmartDukaan

Rev

Rev 27071 | Rev 28102 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
23819 govind 1
package com.spice.profitmandi.web.controller;
2
 
24822 amit.gupta 3
import java.io.Serializable;
23819 govind 4
import java.time.LocalDateTime;
5
import java.util.ArrayList;
23884 amit.gupta 6
import java.util.Arrays;
23819 govind 7
import java.util.List;
8
import java.util.Map;
24063 amit.gupta 9
import java.util.Set;
23819 govind 10
import java.util.stream.Collectors;
11
 
12
import javax.servlet.http.HttpServletRequest;
13
 
23951 amit.gupta 14
import org.apache.commons.io.output.ByteArrayOutputStream;
23819 govind 15
import org.apache.logging.log4j.LogManager;
16
import org.apache.logging.log4j.Logger;
17
import org.springframework.beans.factory.annotation.Autowired;
18
import org.springframework.beans.factory.annotation.Qualifier;
23951 amit.gupta 19
import org.springframework.core.io.ByteArrayResource;
20
import org.springframework.http.HttpHeaders;
23819 govind 21
import org.springframework.http.HttpStatus;
22
import org.springframework.http.ResponseEntity;
23
import org.springframework.stereotype.Controller;
25161 amit.gupta 24
import org.springframework.transaction.annotation.Transactional;
23819 govind 25
import org.springframework.ui.Model;
26
import org.springframework.web.bind.annotation.PathVariable;
23884 amit.gupta 27
import org.springframework.web.bind.annotation.RequestBody;
23819 govind 28
import org.springframework.web.bind.annotation.RequestMapping;
29
import org.springframework.web.bind.annotation.RequestMethod;
23951 amit.gupta 30
import org.springframework.web.bind.annotation.RequestParam;
23819 govind 31
 
23945 amit.gupta 32
import com.fasterxml.jackson.databind.ObjectMapper;
23819 govind 33
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23951 amit.gupta 34
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
23884 amit.gupta 35
import com.spice.profitmandi.common.model.ItemDescriptionModel;
24083 amit.gupta 36
import com.spice.profitmandi.common.model.PriceDropImeisModel;
23884 amit.gupta 37
import com.spice.profitmandi.common.model.PriceDropModel;
23968 amit.gupta 38
import com.spice.profitmandi.common.model.PriceDropProcessModel;
23945 amit.gupta 39
import com.spice.profitmandi.common.services.ReporticoService;
23951 amit.gupta 40
import com.spice.profitmandi.common.util.FileUtil;
23945 amit.gupta 41
import com.spice.profitmandi.common.util.FormattingUtils;
23819 govind 42
import com.spice.profitmandi.dao.entity.catalog.Item;
23884 amit.gupta 43
import com.spice.profitmandi.dao.entity.catalog.TagListing;
24822 amit.gupta 44
import com.spice.profitmandi.dao.entity.inventory.ItemPricingHistory;
23884 amit.gupta 45
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
23819 govind 46
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
24083 amit.gupta 47
import com.spice.profitmandi.dao.entity.transaction.PriceDropIMEI;
48
import com.spice.profitmandi.dao.enumuration.transaction.PriceDropImeiStatus;
23819 govind 49
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23884 amit.gupta 50
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
24822 amit.gupta 51
import com.spice.profitmandi.dao.repository.inventory.ItemPricingHistoryRepository;
23884 amit.gupta 52
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
23983 amit.gupta 53
import com.spice.profitmandi.dao.repository.transaction.LineItemImeisRepository;
24083 amit.gupta 54
import com.spice.profitmandi.dao.repository.transaction.PriceDropIMEIRepository;
23819 govind 55
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
56
import com.spice.profitmandi.service.inventory.InventoryService;
23983 amit.gupta 57
import com.spice.profitmandi.service.pricing.PriceDropService;
23968 amit.gupta 58
import com.spice.profitmandi.service.scheme.SchemeService;
23884 amit.gupta 59
import com.spice.profitmandi.service.transaction.TransactionService;
23819 govind 60
import com.spice.profitmandi.service.wallet.WalletService;
61
import com.spice.profitmandi.web.util.MVCResponseSender;
62
 
63
@Controller
27071 amit.gupta 64
@Transactional(rollbackFor = Throwable.class)
23819 govind 65
public class PriceDropController {
66
 
67
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
68
 
69
	@Autowired
70
	private PriceDropRepository priceDropRepository;
71
 
23951 amit.gupta 72
	@Autowired
73
	private ObjectMapper objectMapper;
23945 amit.gupta 74
 
23819 govind 75
	@Autowired
23884 amit.gupta 76
	private VendorItemPricingRepository vendorItemPricingRepository;
23819 govind 77
 
78
	@Autowired
23884 amit.gupta 79
	@Qualifier("fofoInventoryService")
80
	private InventoryService inventoryService;
23945 amit.gupta 81
 
23884 amit.gupta 82
	@Autowired
23819 govind 83
	private MVCResponseSender mvcResponseSender;
84
 
85
	@Autowired
23983 amit.gupta 86
	private PriceDropService priceDropService;
27071 amit.gupta 87
 
24822 amit.gupta 88
	@Autowired
89
	private ItemPricingHistoryRepository itemPricingHistoryRepository;
24083 amit.gupta 90
 
23983 amit.gupta 91
	@Autowired
23819 govind 92
	private WalletService walletService;
93
 
94
	@Autowired
23884 amit.gupta 95
	private TagListingRepository tagListingRepository;
23945 amit.gupta 96
 
23884 amit.gupta 97
	@Autowired
98
	private TransactionService transactionService;
23819 govind 99
 
100
	@Autowired
24083 amit.gupta 101
	private PriceDropIMEIRepository priceDropIMEIRepository;
102
 
103
	@Autowired
23819 govind 104
	@Qualifier("catalogItemRepository")
105
	private ItemRepository itemRepository;
106
 
23945 amit.gupta 107
	@Autowired
23968 amit.gupta 108
	private SchemeService schemeService;
24083 amit.gupta 109
 
23986 amit.gupta 110
	@Autowired
23945 amit.gupta 111
	ReporticoService reporticoService;
24083 amit.gupta 112
 
23983 amit.gupta 113
	@Autowired
114
	LineItemImeisRepository lineItemImeisRepository;
23945 amit.gupta 115
 
23819 govind 116
	@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
23945 amit.gupta 117
	public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
23819 govind 118
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
24191 amit.gupta 119
		Set<Integer> catalogIds = priceDrops.stream().map(x -> x.getCatalogItemId()).collect(Collectors.toSet());
24180 amit.gupta 120
		List<Item> items = itemRepository.selectAllByCatalogIds(catalogIds);
24191 amit.gupta 121
		Map<Integer, String> catalogDescription = items.stream().collect(Collectors.toMap(x -> x.getCatalogItemId(),
122
				x -> x.getItemDescriptionNoColor(), (description1, description2) -> description1));
23819 govind 123
		model.addAttribute("priceDrops", priceDrops);
23968 amit.gupta 124
		model.addAttribute("catalogDescription", catalogDescription);
23819 govind 125
		return "price-drop";
126
	}
24083 amit.gupta 127
 
24049 amit.gupta 128
	@RequestMapping(value = "/item-pricing/{itemId}", method = RequestMethod.GET)
129
	public String getItemPricing(HttpServletRequest request, Model model, @PathVariable int itemId) throws Throwable {
24083 amit.gupta 130
 
24063 amit.gupta 131
		TagListing tagListing;
24049 amit.gupta 132
		PriceDropModel pm = new PriceDropModel();
24063 amit.gupta 133
		try {
134
			tagListing = tagListingRepository.selectByItemId(itemId);
24083 amit.gupta 135
			if (tagListing != null) {
24063 amit.gupta 136
				pm.setMop(tagListing.getMop());
137
				pm.setDp(tagListing.getSellingPrice());
138
				pm.setMrp(tagListing.getMrp());
139
				List<VendorItemPricing> vips = vendorItemPricingRepository.selectAll(itemId);
24083 amit.gupta 140
				if (vips.size() > 0) {
24063 amit.gupta 141
					VendorItemPricing vip = vips.get(0);
142
					pm.setNlc(vip.getNlc());
143
					pm.setTp(vip.getTp());
144
				} else {
145
					throw new ProfitMandiBusinessException("Item Id", itemId, "Vendor item pricing does not exist");
146
				}
147
			}
24083 amit.gupta 148
		} catch (Exception e) {
24063 amit.gupta 149
			LOGGER.info("Chose item that doesn't exist");
24049 amit.gupta 150
		}
151
		model.addAttribute("response", mvcResponseSender.createResponseString(pm));
152
		return "response";
153
	}
24083 amit.gupta 154
 
24168 amit.gupta 155
	@RequestMapping(value = "/item", method = RequestMethod.GET)
27618 tejbeer 156
	public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query,@RequestParam boolean anyColor) throws Throwable {
24383 amit.gupta 157
		String query1 = query.toLowerCase();
27618 tejbeer 158
 
159
		List<ItemDescriptionModel> partnersItemDescription = inventoryService.getAllPartnerItemStringDescription(anyColor)
27071 amit.gupta 160
				.parallelStream().filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
24564 amit.gupta 161
				.collect(Collectors.toList());
27618 tejbeer 162
		LOGGER.info("partnersItemDescription"+partnersItemDescription);
24168 amit.gupta 163
 
24191 amit.gupta 164
		model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
24168 amit.gupta 165
		return "response";
166
	}
167
 
23951 amit.gupta 168
	@RequestMapping(value = "/price-drop/imes/download")
169
	public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
170
			@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
171
		Item item = itemRepository.selectById(itemId);
26368 amit.gupta 172
		ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null);
23951 amit.gupta 173
		final HttpHeaders headers = new HttpHeaders();
174
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
25408 amit.gupta 175
		headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
23951 amit.gupta 176
		byte[] byteArray = baos.toByteArray();
177
		headers.setContentLength(byteArray.length);
178
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
179
	}
180
 
24083 amit.gupta 181
	@RequestMapping(value = "/price-drop/addPayout", method = RequestMethod.POST)
182
	public String updatePriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
183
			Model model) throws Exception {
184
		boolean response = false;
185
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
186
		if (priceDrop.getProcessTimestamp() == null) {
187
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
188
			priceDrop.setPriceDropIn(priceDropProcessModel.getPriceDropIn());
189
			// priceDrop.setProcessTimestamp(LocalDateTime.now());
190
			priceDropRepository.persist(priceDrop);
191
			response = true;
192
		}
193
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
194
		return "response";
195
	}
196
 
197
	@RequestMapping(value = "/priceDropImeis/{priceDropId}", method = RequestMethod.GET)
198
	public String priceDropStatus(HttpServletRequest request, @PathVariable int priceDropId, Model model)
199
			throws Exception {
200
 
201
		PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
24564 amit.gupta 202
 
203
		// This call is used to persit imeis to pricedrop imeis in case its not there.
27071 amit.gupta 204
		// This should be called while creating price drop.
205
		// priceDropService.priceDropStatus(priceDropId);
24564 amit.gupta 206
 
24083 amit.gupta 207
		List<String> pendingImeis = new ArrayList<>();
208
		List<String> approvedImeis = new ArrayList<>();
209
		List<String> rejectedImeis = new ArrayList<>();
210
		List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
211
		for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
212
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.PENDING)) {
213
				pendingImeis.add(priceDropIMEI.getImei());
214
			} else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)) {
215
				approvedImeis.add(priceDropIMEI.getImei());
216
			}
217
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.REJECTED)) {
218
				rejectedImeis.add(priceDropIMEI.getImei());
219
			}
220
		}
221
		priceDropImeisModel.setPendingImeis(pendingImeis);
222
		priceDropImeisModel.setPriceDropId(priceDropId);
223
		priceDropImeisModel.setApprovedImeis(approvedImeis);
224
		priceDropImeisModel.setRejectedImeis(rejectedImeis);
225
		model.addAttribute("response", mvcResponseSender.createResponseString(priceDropImeisModel));
226
		return "response";
227
	}
228
 
23968 amit.gupta 229
	@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
27071 amit.gupta 230
	public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
23968 amit.gupta 231
			Model model) throws Exception {
27071 amit.gupta 232
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
23968 amit.gupta 233
		boolean response = false;
27071 amit.gupta 234
		if(priceDrop.getPartnerPayout()==0) {
235
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
236
		}
237
		priceDrop.setProcessTimestamp(LocalDateTime.now());
238
		priceDropRepository.persist(priceDrop);
239
		priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
23968 amit.gupta 240
			response = true;
241
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
242
		return "response";
23819 govind 243
	}
24083 amit.gupta 244
 
23884 amit.gupta 245
	@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
23945 amit.gupta 246
	public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
247
			throws Exception {
23884 amit.gupta 248
		boolean response = false;
23968 amit.gupta 249
		priceDropModel.setAllColors(true);
23945 amit.gupta 250
		if (this.validatePriceDrop(priceDropModel)) {
23884 amit.gupta 251
			TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
24409 amit.gupta 252
			float oldDp = tagListing.getSellingPrice();
24410 amit.gupta 253
			float oldMop = tagListing.getMop();
254
			float oldTp = 0;
24409 amit.gupta 255
			float newDp = priceDropModel.getDp();
24564 amit.gupta 256
 
24410 amit.gupta 257
			if (newDp != oldDp) {
23884 amit.gupta 258
				List<Item> allItems = null;
259
				Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
23945 amit.gupta 260
				if (priceDropModel.isAllColors()) {
23884 amit.gupta 261
					allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
23945 amit.gupta 262
 
23884 amit.gupta 263
				} else {
23945 amit.gupta 264
					allItems = Arrays.asList(currentItem);
23884 amit.gupta 265
				}
23945 amit.gupta 266
				for (Item item : allItems) {
23884 amit.gupta 267
					TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
23945 amit.gupta 268
					if (itemTagListing == null)
269
						continue;
23884 amit.gupta 270
					itemTagListing.setSellingPrice(newDp);
271
					itemTagListing.setMop(priceDropModel.getMop());
272
					tagListingRepository.persist(tagListing);
273
					List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
23945 amit.gupta 274
					for (VendorItemPricing vip : vipList) {
24410 amit.gupta 275
						oldTp = vip.getNlc();
23884 amit.gupta 276
						vip.setDp(newDp);
277
						vip.setMop(priceDropModel.getMop());
24409 amit.gupta 278
						vip.setNlc(priceDropModel.getTp());
23884 amit.gupta 279
						vip.setTp(priceDropModel.getTp());
280
						vendorItemPricingRepository.persist(vip);
281
					}
282
					transactionService.updatePriceDrop(item.getId(), newDp);
283
				}
27071 amit.gupta 284
 
285
				// Add to itemPricing history
24822 amit.gupta 286
				ItemPricingHistory iph = new ItemPricingHistory();
287
				iph.setCatalogId(currentItem.getCatalogItemId());
288
				iph.setTp(priceDropModel.getTp());
289
				iph.setDp(priceDropModel.getDp());
290
				iph.setMop(priceDropModel.getMop());
27071 amit.gupta 291
				// TODO: changedBy
24822 amit.gupta 292
				iph.setChangedBy("me");
293
				iph.setCreateTimestamp(LocalDateTime.now());
294
				itemPricingHistoryRepository.persist(iph);
27071 amit.gupta 295
 
23951 amit.gupta 296
				PriceDrop priceDrop = new PriceDrop();
297
				priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
24410 amit.gupta 298
				priceDrop.setTp(oldTp);
299
				priceDrop.setNlc(oldTp);
300
				priceDrop.setMop(oldMop);
24409 amit.gupta 301
				priceDrop.setOldDp(oldDp);
302
				priceDrop.setAmount(oldDp - newDp);
23968 amit.gupta 303
				priceDrop.setNewDp(newDp);
23951 amit.gupta 304
				priceDrop.setCreatedOn(LocalDateTime.now());
305
				priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
306
				priceDropRepository.persist(priceDrop);
26116 amit.gupta 307
				priceDropService.priceDropStatus(priceDrop.getId());
23884 amit.gupta 308
				response = true;
309
			} else {
23945 amit.gupta 310
				throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
24409 amit.gupta 311
						"Price Drop Should be greater than 0");
23884 amit.gupta 312
			}
313
		}
314
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
315
		return "response";
316
	}
23945 amit.gupta 317
 
23819 govind 318
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
319
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
23945 amit.gupta 320
			Model model) throws ProfitMandiBusinessException, Exception {
23819 govind 321
 
322
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
27071 amit.gupta 323
		Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
324
				.collect(Collectors.toMap(x -> x.getImei(), x -> x));
325
 
326
		if (priceDropIMEIsMap.size() == 0 && priceDrop.getProcessTimestamp() == null) {
26372 amit.gupta 327
			priceDrop.setProcessTimestamp(LocalDateTime.now());
328
		} else {
329
			priceDropService.priceDropStatus(priceDrop.getId());
330
		}
27071 amit.gupta 331
 
23968 amit.gupta 332
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
27071 amit.gupta 333
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
334
				priceDropIMEIsMap);
23968 amit.gupta 335
		final HttpHeaders headers = new HttpHeaders();
336
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
23983 amit.gupta 337
		headers.set("Content-disposition",
338
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
339
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
23968 amit.gupta 340
		byte[] byteArray = baos.toByteArray();
341
		headers.setContentLength(byteArray.length);
342
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
23951 amit.gupta 343
 
344
	}
345
 
26400 amit.gupta 346
	@RequestMapping(value = "/updatePriceDropImeis-DNC", method = RequestMethod.POST)
27071 amit.gupta 347
	public String updatePriceDropImeis(HttpServletRequest request, @RequestBody PriceDropImeisModel priceDropImeisModel,
348
			Model model) throws ProfitMandiBusinessException, Exception {
24168 amit.gupta 349
		PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
24083 amit.gupta 350
 
351
		switch (priceDropImeisModel.getUpdatedStatus()) {
27071 amit.gupta 352
		case "approved": {
353
			status = PriceDropImeiStatus.APPROVED_OURS;
354
			break;
24083 amit.gupta 355
		}
27071 amit.gupta 356
		case "rejected": {
357
			status = PriceDropImeiStatus.REJECTED;
358
			break;
24083 amit.gupta 359
		}
27071 amit.gupta 360
		}
361
 
362
		if (PriceDropImeiStatus.PENDING.equals(status)) {
363
			throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING",
364
					"only approved and rejected is allowed");
365
		}
366
 
367
		// TODO:PD
24083 amit.gupta 368
		List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
369
				.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
370
 
371
		List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
372
		for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
373
			if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
374
					|| priceDropIMEI.getStatus().equals(status)) {
375
				continue;
376
			}
26368 amit.gupta 377
			priceDropIMEIsToProcess.add(priceDropIMEI);
27071 amit.gupta 378
			if (status.equals(PriceDropImeiStatus.REJECTED)) {
26368 amit.gupta 379
				priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
380
			}
381
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
24083 amit.gupta 382
		}
27071 amit.gupta 383
		/*
384
		 * if (priceDropIMEIsToProcess.size() > 0) {
385
		 * priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(),
386
		 * priceDropIMEIsToProcess, status); }
387
		 */
24168 amit.gupta 388
 
24083 amit.gupta 389
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
390
		return "response";
391
 
392
	}
393
 
27071 amit.gupta 394
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
395
			Map<String, PriceDropIMEI> priceDropImeis) throws Exception {
24564 amit.gupta 396
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
397
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
25852 amit.gupta 398
		List<List<?>> rows = new ArrayList<>();
23983 amit.gupta 399
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
27071 amit.gupta 400
			if (priceDropImeis == null) {
26368 amit.gupta 401
				rows.add(this.getRow(imeiDropSummaryModel, null));
27071 amit.gupta 402
			} else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
26368 amit.gupta 403
				rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
404
			}
23951 amit.gupta 405
		}
27071 amit.gupta 406
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
407
				"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
408
				"Grn On", "Activation Timestamp", "Activation Added On"), rows);
23819 govind 409
	}
24083 amit.gupta 410
 
27071 amit.gupta 411
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel,
412
			PriceDropIMEI priceDropIMEI) {
24822 amit.gupta 413
		List<Serializable> row = new ArrayList<>();
23986 amit.gupta 414
		row.add(imeiDropSummaryModel.getSerialNumber());
415
		row.add(imeiDropSummaryModel.getStoreName());
416
		row.add(imeiDropSummaryModel.getPartnerCode());
417
		row.add(imeiDropSummaryModel.getItemId());
418
		row.add(imeiDropSummaryModel.getBrand());
419
		row.add(imeiDropSummaryModel.getModelName());
420
		row.add(imeiDropSummaryModel.getModelNumber());
421
		row.add(imeiDropSummaryModel.getColor());
27071 amit.gupta 422
		if (priceDropIMEI != null) {
26368 amit.gupta 423
			row.add(priceDropIMEI.getStatus());
424
			row.add(priceDropIMEI.getRejectionReason());
425
		} else {
426
			row.add(PriceDropImeiStatus.PENDING);
427
			row.add("");
428
		}
26373 amit.gupta 429
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
430
		row.add(imeiDropSummaryModel.getVendorName());
26420 amit.gupta 431
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getGrnOn()));
26368 amit.gupta 432
		row.add(imeiDropSummaryModel.getActivationTimestamp());
433
		row.add(imeiDropSummaryModel.getActivationAddedOn());
23986 amit.gupta 434
		return row;
435
	}
23819 govind 436
 
23884 amit.gupta 437
	private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
24564 amit.gupta 438
		if (priceDropModel.getMop() > 0 && priceDropModel.getDp() > 0 && priceDropModel.getTp() > 0) {
23884 amit.gupta 439
			return true;
440
		}
441
		return false;
442
	}
23945 amit.gupta 443
 
23819 govind 444
}