Subversion Repositories SmartDukaan

Rev

Rev 26420 | Rev 27618 | 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)
156
	public String getItemPricing(HttpServletRequest request, Model model, @RequestParam String query) throws Throwable {
24383 amit.gupta 157
		String query1 = query.toLowerCase();
27071 amit.gupta 158
		List<ItemDescriptionModel> partnersItemDescription = inventoryService.getAllPartnerItemStringDescription()
159
				.parallelStream().filter(x -> x.getItemDescription().toLowerCase().matches(".*?" + query1 + ".*?"))
24564 amit.gupta 160
				.collect(Collectors.toList());
24168 amit.gupta 161
 
24191 amit.gupta 162
		model.addAttribute("response", mvcResponseSender.createResponseString(partnersItemDescription));
24168 amit.gupta 163
		return "response";
164
	}
165
 
23951 amit.gupta 166
	@RequestMapping(value = "/price-drop/imes/download")
167
	public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
168
			@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
169
		Item item = itemRepository.selectById(itemId);
26368 amit.gupta 170
		ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId(), null);
23951 amit.gupta 171
		final HttpHeaders headers = new HttpHeaders();
172
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
25408 amit.gupta 173
		headers.set("Content-disposition", "inline; filename=\"imei-" + item.getItemDescriptionNoColor() + ".csv\"");
23951 amit.gupta 174
		byte[] byteArray = baos.toByteArray();
175
		headers.setContentLength(byteArray.length);
176
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
177
	}
178
 
24083 amit.gupta 179
	@RequestMapping(value = "/price-drop/addPayout", method = RequestMethod.POST)
180
	public String updatePriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
181
			Model model) throws Exception {
182
		boolean response = false;
183
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
184
		if (priceDrop.getProcessTimestamp() == null) {
185
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
186
			priceDrop.setPriceDropIn(priceDropProcessModel.getPriceDropIn());
187
			// priceDrop.setProcessTimestamp(LocalDateTime.now());
188
			priceDropRepository.persist(priceDrop);
189
			response = true;
190
		}
191
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
192
		return "response";
193
	}
194
 
195
	@RequestMapping(value = "/priceDropImeis/{priceDropId}", method = RequestMethod.GET)
196
	public String priceDropStatus(HttpServletRequest request, @PathVariable int priceDropId, Model model)
197
			throws Exception {
198
 
199
		PriceDropImeisModel priceDropImeisModel = new PriceDropImeisModel();
24564 amit.gupta 200
 
201
		// This call is used to persit imeis to pricedrop imeis in case its not there.
27071 amit.gupta 202
		// This should be called while creating price drop.
203
		// priceDropService.priceDropStatus(priceDropId);
24564 amit.gupta 204
 
24083 amit.gupta 205
		List<String> pendingImeis = new ArrayList<>();
206
		List<String> approvedImeis = new ArrayList<>();
207
		List<String> rejectedImeis = new ArrayList<>();
208
		List<PriceDropIMEI> priceDropImeis = priceDropIMEIRepository.selectByPriceDropId(priceDropId);
209
		for (PriceDropIMEI priceDropIMEI : priceDropImeis) {
210
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.PENDING)) {
211
				pendingImeis.add(priceDropIMEI.getImei());
212
			} else if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.APPROVED)) {
213
				approvedImeis.add(priceDropIMEI.getImei());
214
			}
215
			if (priceDropIMEI.getStatus().equals(PriceDropImeiStatus.REJECTED)) {
216
				rejectedImeis.add(priceDropIMEI.getImei());
217
			}
218
		}
219
		priceDropImeisModel.setPendingImeis(pendingImeis);
220
		priceDropImeisModel.setPriceDropId(priceDropId);
221
		priceDropImeisModel.setApprovedImeis(approvedImeis);
222
		priceDropImeisModel.setRejectedImeis(rejectedImeis);
223
		model.addAttribute("response", mvcResponseSender.createResponseString(priceDropImeisModel));
224
		return "response";
225
	}
226
 
23968 amit.gupta 227
	@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
27071 amit.gupta 228
	public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcessModel,
23968 amit.gupta 229
			Model model) throws Exception {
27071 amit.gupta 230
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcessModel.getPriceDropId());
23968 amit.gupta 231
		boolean response = false;
27071 amit.gupta 232
		if(priceDrop.getPartnerPayout()==0) {
233
			priceDrop.setPartnerPayout(priceDropProcessModel.getPartnerPayout());
234
		}
235
		priceDrop.setProcessTimestamp(LocalDateTime.now());
236
		priceDropRepository.persist(priceDrop);
237
		priceDropService.processPriceDrop(priceDrop.getId(), priceDropProcessModel.isActivatedOnly());
23968 amit.gupta 238
			response = true;
239
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
240
		return "response";
23819 govind 241
	}
24083 amit.gupta 242
 
23884 amit.gupta 243
	@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
23945 amit.gupta 244
	public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
245
			throws Exception {
23884 amit.gupta 246
		boolean response = false;
23968 amit.gupta 247
		priceDropModel.setAllColors(true);
23945 amit.gupta 248
		if (this.validatePriceDrop(priceDropModel)) {
23884 amit.gupta 249
			TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
24409 amit.gupta 250
			float oldDp = tagListing.getSellingPrice();
24410 amit.gupta 251
			float oldMop = tagListing.getMop();
252
			float oldTp = 0;
24409 amit.gupta 253
			float newDp = priceDropModel.getDp();
24564 amit.gupta 254
 
24410 amit.gupta 255
			if (newDp != oldDp) {
23884 amit.gupta 256
				List<Item> allItems = null;
257
				Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
23945 amit.gupta 258
				if (priceDropModel.isAllColors()) {
23884 amit.gupta 259
					allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
23945 amit.gupta 260
 
23884 amit.gupta 261
				} else {
23945 amit.gupta 262
					allItems = Arrays.asList(currentItem);
23884 amit.gupta 263
				}
23945 amit.gupta 264
				for (Item item : allItems) {
23884 amit.gupta 265
					TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
23945 amit.gupta 266
					if (itemTagListing == null)
267
						continue;
23884 amit.gupta 268
					itemTagListing.setSellingPrice(newDp);
269
					itemTagListing.setMop(priceDropModel.getMop());
270
					tagListingRepository.persist(tagListing);
271
					List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
23945 amit.gupta 272
					for (VendorItemPricing vip : vipList) {
24410 amit.gupta 273
						oldTp = vip.getNlc();
23884 amit.gupta 274
						vip.setDp(newDp);
275
						vip.setMop(priceDropModel.getMop());
24409 amit.gupta 276
						vip.setNlc(priceDropModel.getTp());
23884 amit.gupta 277
						vip.setTp(priceDropModel.getTp());
278
						vendorItemPricingRepository.persist(vip);
279
					}
280
					transactionService.updatePriceDrop(item.getId(), newDp);
281
				}
27071 amit.gupta 282
 
283
				// Add to itemPricing history
24822 amit.gupta 284
				ItemPricingHistory iph = new ItemPricingHistory();
285
				iph.setCatalogId(currentItem.getCatalogItemId());
286
				iph.setTp(priceDropModel.getTp());
287
				iph.setDp(priceDropModel.getDp());
288
				iph.setMop(priceDropModel.getMop());
27071 amit.gupta 289
				// TODO: changedBy
24822 amit.gupta 290
				iph.setChangedBy("me");
291
				iph.setCreateTimestamp(LocalDateTime.now());
292
				itemPricingHistoryRepository.persist(iph);
27071 amit.gupta 293
 
23951 amit.gupta 294
				PriceDrop priceDrop = new PriceDrop();
295
				priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
24410 amit.gupta 296
				priceDrop.setTp(oldTp);
297
				priceDrop.setNlc(oldTp);
298
				priceDrop.setMop(oldMop);
24409 amit.gupta 299
				priceDrop.setOldDp(oldDp);
300
				priceDrop.setAmount(oldDp - newDp);
23968 amit.gupta 301
				priceDrop.setNewDp(newDp);
23951 amit.gupta 302
				priceDrop.setCreatedOn(LocalDateTime.now());
303
				priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
304
				priceDropRepository.persist(priceDrop);
26116 amit.gupta 305
				priceDropService.priceDropStatus(priceDrop.getId());
23884 amit.gupta 306
				response = true;
307
			} else {
23945 amit.gupta 308
				throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
24409 amit.gupta 309
						"Price Drop Should be greater than 0");
23884 amit.gupta 310
			}
311
		}
312
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
313
		return "response";
314
	}
23945 amit.gupta 315
 
23819 govind 316
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
317
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
23945 amit.gupta 318
			Model model) throws ProfitMandiBusinessException, Exception {
23819 govind 319
 
320
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
27071 amit.gupta 321
		Map<String, PriceDropIMEI> priceDropIMEIsMap = priceDropIMEIRepository.selectByPriceDropId(priceDropId).stream()
322
				.collect(Collectors.toMap(x -> x.getImei(), x -> x));
323
 
324
		if (priceDropIMEIsMap.size() == 0 && priceDrop.getProcessTimestamp() == null) {
26372 amit.gupta 325
			priceDrop.setProcessTimestamp(LocalDateTime.now());
326
		} else {
327
			priceDropService.priceDropStatus(priceDrop.getId());
328
		}
27071 amit.gupta 329
 
23968 amit.gupta 330
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
27071 amit.gupta 331
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId(),
332
				priceDropIMEIsMap);
23968 amit.gupta 333
		final HttpHeaders headers = new HttpHeaders();
334
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
23983 amit.gupta 335
		headers.set("Content-disposition",
336
				"inline; filename=pricedrop-" + item.getItemDescriptionNoColor().replaceAll("\\s?,\\s?", " ") + "-"
337
						+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
23968 amit.gupta 338
		byte[] byteArray = baos.toByteArray();
339
		headers.setContentLength(byteArray.length);
340
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
23951 amit.gupta 341
 
342
	}
343
 
26400 amit.gupta 344
	@RequestMapping(value = "/updatePriceDropImeis-DNC", method = RequestMethod.POST)
27071 amit.gupta 345
	public String updatePriceDropImeis(HttpServletRequest request, @RequestBody PriceDropImeisModel priceDropImeisModel,
346
			Model model) throws ProfitMandiBusinessException, Exception {
24168 amit.gupta 347
		PriceDropImeiStatus status = PriceDropImeiStatus.PENDING;
24083 amit.gupta 348
 
349
		switch (priceDropImeisModel.getUpdatedStatus()) {
27071 amit.gupta 350
		case "approved": {
351
			status = PriceDropImeiStatus.APPROVED_OURS;
352
			break;
24083 amit.gupta 353
		}
27071 amit.gupta 354
		case "rejected": {
355
			status = PriceDropImeiStatus.REJECTED;
356
			break;
24083 amit.gupta 357
		}
27071 amit.gupta 358
		}
359
 
360
		if (PriceDropImeiStatus.PENDING.equals(status)) {
361
			throw new ProfitMandiBusinessException("INVALID STATUS", "PENDING",
362
					"only approved and rejected is allowed");
363
		}
364
 
365
		// TODO:PD
24083 amit.gupta 366
		List<PriceDropIMEI> priceDropIMEIs = priceDropIMEIRepository
367
				.selectByPriceDropId(priceDropImeisModel.getPriceDropId());
368
 
369
		List<PriceDropIMEI> priceDropIMEIsToProcess = new ArrayList<>();
370
		for (PriceDropIMEI priceDropIMEI : priceDropIMEIs) {
371
			if (!priceDropImeisModel.getUpdatedImeis().contains(priceDropIMEI.getImei())
372
					|| priceDropIMEI.getStatus().equals(status)) {
373
				continue;
374
			}
26368 amit.gupta 375
			priceDropIMEIsToProcess.add(priceDropIMEI);
27071 amit.gupta 376
			if (status.equals(PriceDropImeiStatus.REJECTED)) {
26368 amit.gupta 377
				priceDropIMEI.setRejectionReason(priceDropImeisModel.getRejectionReason());
378
			}
379
			priceDropIMEI.setUpdateTimestamp(LocalDateTime.now());
24083 amit.gupta 380
		}
27071 amit.gupta 381
		/*
382
		 * if (priceDropIMEIsToProcess.size() > 0) {
383
		 * priceDropService.processManualPriceDrop(priceDropImeisModel.getPriceDropId(),
384
		 * priceDropIMEIsToProcess, status); }
385
		 */
24168 amit.gupta 386
 
24083 amit.gupta 387
		model.addAttribute("response", mvcResponseSender.createResponseString(true));
388
		return "response";
389
 
390
	}
391
 
27071 amit.gupta 392
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId,
393
			Map<String, PriceDropIMEI> priceDropImeis) throws Exception {
24564 amit.gupta 394
		List<ImeiDropSummaryModel> imeiDropSummaryModelList = priceDropService
395
				.getAllSerialNumbersByAffectedDate(affectedOn, catalogItemId);
25852 amit.gupta 396
		List<List<?>> rows = new ArrayList<>();
23983 amit.gupta 397
		for (ImeiDropSummaryModel imeiDropSummaryModel : imeiDropSummaryModelList) {
27071 amit.gupta 398
			if (priceDropImeis == null) {
26368 amit.gupta 399
				rows.add(this.getRow(imeiDropSummaryModel, null));
27071 amit.gupta 400
			} else if (priceDropImeis.get(imeiDropSummaryModel.getSerialNumber()) != null) {
26368 amit.gupta 401
				rows.add(this.getRow(imeiDropSummaryModel, priceDropImeis.get(imeiDropSummaryModel.getSerialNumber())));
402
			}
23951 amit.gupta 403
		}
27071 amit.gupta 404
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
405
				"Model Name", "Model Number", "Color", "Status", "Rejection Reason", "Last Scanned", "Vendor Name",
406
				"Grn On", "Activation Timestamp", "Activation Added On"), rows);
23819 govind 407
	}
24083 amit.gupta 408
 
27071 amit.gupta 409
	private List<? extends Serializable> getRow(ImeiDropSummaryModel imeiDropSummaryModel,
410
			PriceDropIMEI priceDropIMEI) {
24822 amit.gupta 411
		List<Serializable> row = new ArrayList<>();
23986 amit.gupta 412
		row.add(imeiDropSummaryModel.getSerialNumber());
413
		row.add(imeiDropSummaryModel.getStoreName());
414
		row.add(imeiDropSummaryModel.getPartnerCode());
415
		row.add(imeiDropSummaryModel.getItemId());
416
		row.add(imeiDropSummaryModel.getBrand());
417
		row.add(imeiDropSummaryModel.getModelName());
418
		row.add(imeiDropSummaryModel.getModelNumber());
419
		row.add(imeiDropSummaryModel.getColor());
27071 amit.gupta 420
		if (priceDropIMEI != null) {
26368 amit.gupta 421
			row.add(priceDropIMEI.getStatus());
422
			row.add(priceDropIMEI.getRejectionReason());
423
		} else {
424
			row.add(PriceDropImeiStatus.PENDING);
425
			row.add("");
426
		}
26373 amit.gupta 427
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
428
		row.add(imeiDropSummaryModel.getVendorName());
26420 amit.gupta 429
		row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getGrnOn()));
26368 amit.gupta 430
		row.add(imeiDropSummaryModel.getActivationTimestamp());
431
		row.add(imeiDropSummaryModel.getActivationAddedOn());
23986 amit.gupta 432
		return row;
433
	}
23819 govind 434
 
23884 amit.gupta 435
	private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
24564 amit.gupta 436
		if (priceDropModel.getMop() > 0 && priceDropModel.getDp() > 0 && priceDropModel.getTp() > 0) {
23884 amit.gupta 437
			return true;
438
		}
439
		return false;
440
	}
23945 amit.gupta 441
 
23819 govind 442
}