Subversion Repositories SmartDukaan

Rev

Rev 23979 | Rev 23982 | 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
 
23968 amit.gupta 3
import java.text.MessageFormat;
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.HashMap;
8
import java.util.List;
9
import java.util.Map;
10
import java.util.stream.Collectors;
11
 
12
import javax.servlet.http.HttpServletRequest;
13
import javax.transaction.Transactional;
14
 
23951 amit.gupta 15
import org.apache.commons.io.output.ByteArrayOutputStream;
16
import org.apache.commons.lang.StringUtils;
23945 amit.gupta 17
import org.apache.http.HttpResponse;
23819 govind 18
import org.apache.logging.log4j.LogManager;
19
import org.apache.logging.log4j.Logger;
23884 amit.gupta 20
import org.json.JSONArray;
23819 govind 21
import org.springframework.beans.factory.annotation.Autowired;
22
import org.springframework.beans.factory.annotation.Qualifier;
23951 amit.gupta 23
import org.springframework.core.io.ByteArrayResource;
24
import org.springframework.http.HttpHeaders;
23819 govind 25
import org.springframework.http.HttpStatus;
26
import org.springframework.http.ResponseEntity;
27
import org.springframework.stereotype.Controller;
28
import org.springframework.ui.Model;
29
import org.springframework.web.bind.annotation.PathVariable;
23884 amit.gupta 30
import org.springframework.web.bind.annotation.RequestBody;
23819 govind 31
import org.springframework.web.bind.annotation.RequestMapping;
32
import org.springframework.web.bind.annotation.RequestMethod;
23951 amit.gupta 33
import org.springframework.web.bind.annotation.RequestParam;
23819 govind 34
 
23951 amit.gupta 35
import com.fasterxml.jackson.databind.JavaType;
23945 amit.gupta 36
import com.fasterxml.jackson.databind.ObjectMapper;
37
import com.fasterxml.jackson.databind.ObjectReader;
38
import com.spice.profitmandi.common.enumuration.ReporticoProject;
23819 govind 39
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
23945 amit.gupta 40
import com.spice.profitmandi.common.model.ClosingStockOnDate;
41
import com.spice.profitmandi.common.model.GrnPendingDataModel;
23951 amit.gupta 42
import com.spice.profitmandi.common.model.ImeiDropSummaryModel;
23884 amit.gupta 43
import com.spice.profitmandi.common.model.ItemDescriptionModel;
23945 amit.gupta 44
import com.spice.profitmandi.common.model.PartnerImeiNotSold;
23884 amit.gupta 45
import com.spice.profitmandi.common.model.PriceDropModel;
23968 amit.gupta 46
import com.spice.profitmandi.common.model.PriceDropProcessModel;
23945 amit.gupta 47
import com.spice.profitmandi.common.model.ReporticoResponseModel;
48
import com.spice.profitmandi.common.services.ReporticoService;
23951 amit.gupta 49
import com.spice.profitmandi.common.util.FileUtil;
23945 amit.gupta 50
import com.spice.profitmandi.common.util.FormattingUtils;
23819 govind 51
import com.spice.profitmandi.dao.entity.catalog.Item;
23884 amit.gupta 52
import com.spice.profitmandi.dao.entity.catalog.TagListing;
23968 amit.gupta 53
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
23884 amit.gupta 54
import com.spice.profitmandi.dao.entity.inventory.VendorItemPricing;
23819 govind 55
import com.spice.profitmandi.dao.entity.transaction.PriceDrop;
56
import com.spice.profitmandi.dao.repository.catalog.ItemRepository;
23884 amit.gupta 57
import com.spice.profitmandi.dao.repository.catalog.TagListingRepository;
23968 amit.gupta 58
import com.spice.profitmandi.dao.repository.fofo.InventoryItemRepository;
23884 amit.gupta 59
import com.spice.profitmandi.dao.repository.inventory.VendorItemPricingRepository;
23819 govind 60
import com.spice.profitmandi.dao.repository.transaction.PriceDropRepository;
61
import com.spice.profitmandi.service.inventory.InventoryService;
23968 amit.gupta 62
import com.spice.profitmandi.service.scheme.SchemeService;
23884 amit.gupta 63
import com.spice.profitmandi.service.transaction.TransactionService;
23819 govind 64
import com.spice.profitmandi.service.wallet.WalletService;
65
import com.spice.profitmandi.web.util.MVCResponseSender;
66
 
23968 amit.gupta 67
import in.shop2020.model.v1.order.WalletReferenceType;
68
 
23819 govind 69
@Controller
70
@Transactional
71
public class PriceDropController {
72
 
73
	private static final Logger LOGGER = LogManager.getLogger(PriceDropController.class);
74
 
75
	@Autowired
76
	private PriceDropRepository priceDropRepository;
77
 
23951 amit.gupta 78
	@Autowired
79
	private ObjectMapper objectMapper;
23945 amit.gupta 80
 
23819 govind 81
	@Autowired
23884 amit.gupta 82
	private VendorItemPricingRepository vendorItemPricingRepository;
23819 govind 83
 
84
	@Autowired
23884 amit.gupta 85
	@Qualifier("fofoInventoryService")
86
	private InventoryService inventoryService;
23945 amit.gupta 87
 
23884 amit.gupta 88
	@Autowired
23968 amit.gupta 89
	private InventoryItemRepository inventoryItemRepository;
90
 
91
	@Autowired
23819 govind 92
	private MVCResponseSender mvcResponseSender;
93
 
94
	@Autowired
95
	private WalletService walletService;
96
 
97
	@Autowired
23884 amit.gupta 98
	private TagListingRepository tagListingRepository;
23945 amit.gupta 99
 
23884 amit.gupta 100
	@Autowired
101
	private TransactionService transactionService;
23819 govind 102
 
103
	@Autowired
104
	@Qualifier("catalogItemRepository")
105
	private ItemRepository itemRepository;
106
 
23945 amit.gupta 107
	@Autowired
23968 amit.gupta 108
	private SchemeService schemeService;
109
 
110
	@Autowired
23945 amit.gupta 111
	ReporticoService reporticoService;
112
 
23819 govind 113
	@RequestMapping(value = "/getItemDescription", method = RequestMethod.GET)
23945 amit.gupta 114
	public String getItemDescription(HttpServletRequest request, Model model) throws Throwable {
23819 govind 115
 
23884 amit.gupta 116
		List<TagListing> tagListings = tagListingRepository.selectAll(false);
117
		Map<Integer, TagListing> tagListingMap = new HashMap<>();
118
		List<ItemDescriptionModel> customItems = new ArrayList<>();
23968 amit.gupta 119
		Map<Integer, String> catalogDescription = new HashMap<>();
23945 amit.gupta 120
		for (TagListing tagListing : tagListings) {
23968 amit.gupta 121
			Item item = itemRepository.selectById(tagListing.getItemId());
122
			tagListing.setItemDescription(item.getItemDescription());
23884 amit.gupta 123
			tagListingMap.put(tagListing.getItemId(), tagListing);
124
			ItemDescriptionModel itemDescriptionModel = new ItemDescriptionModel();
125
			itemDescriptionModel.setItemId(tagListing.getItemId());
23945 amit.gupta 126
			itemDescriptionModel
127
					.setItemDescription(tagListing.getItemDescription() + "(" + tagListing.getItemId() + ")");
128
			customItems.add(itemDescriptionModel);
23968 amit.gupta 129
			catalogDescription.put(item.getCatalogItemId(), item.getItemDescriptionNoColor());
23884 amit.gupta 130
		}
23945 amit.gupta 131
 
23819 govind 132
		List<PriceDrop> priceDrops = priceDropRepository.selectAll();
23884 amit.gupta 133
		model.addAttribute("tagListingMap", tagListingMap);
134
		model.addAttribute("customItems", new JSONArray(customItems).toString());
23819 govind 135
		model.addAttribute("priceDrops", priceDrops);
23968 amit.gupta 136
		model.addAttribute("catalogDescription", catalogDescription);
23819 govind 137
		return "price-drop";
138
 
139
	}
140
 
23945 amit.gupta 141
	/*
142
	 * @RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method =
143
	 * RequestMethod.GET) public ResponseEntity<?>
144
	 * downloadPriceDropIMEI(HttpServletRequest request, @PathVariable int
145
	 * priceDropId, Model model) throws ProfitMandiBusinessException {
146
	 * 
147
	 * PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
148
	 * List<PriceDropIMEI> priceDropIMEIs =
149
	 * priceDropIMEIRepository.selectByPriceDropId(priceDrop.getId()); List<String>
150
	 * imeis = priceDropIMEIs.stream().map(x ->
151
	 * x.getImei()).collect(Collectors.toList()); List<LineItemImei> lineItemImeis =
152
	 * lineItemImeisRepository.selectByIMEI(imeis); Map<String, String>
153
	 * priceDropIMEIfofoId = priceDropService.getIMEIandRetailerName(lineItemImeis,
154
	 * priceDrop); if (priceDropIMEIfofoId.size() > 0) { ByteArrayOutputStream
155
	 * byteArrayOutputStream = new ByteArrayOutputStream();
156
	 * ExcelUtils.writePriceDrop(priceDropIMEIfofoId, priceDrop.getItemId(),
157
	 * byteArrayOutputStream); final HttpHeaders headers = new HttpHeaders(); //
158
	 * private static final String CONTENT_TYPE_XLSX = //
159
	 * "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
160
	 * headers.set("Content-Type",
161
	 * "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"); //
162
	 * headers.set("Content-Type", "application/vnd.ms-excel");
163
	 * headers.set("Content-disposition", "inline; filename=priceDrop" +
164
	 * priceDrop.getId() + ".xlsx");
165
	 * headers.setContentLength(byteArrayOutputStream.toByteArray().length); final
166
	 * InputStream inputStream = new
167
	 * ByteArrayInputStream(byteArrayOutputStream.toByteArray()); final
168
	 * InputStreamResource inputStreamResource = new
169
	 * InputStreamResource(inputStream); return new
170
	 * ResponseEntity<InputStreamResource>(inputStreamResource, headers,
171
	 * HttpStatus.OK); } else { throw new
172
	 * ProfitMandiBusinessException("priceDropId", priceDropId,
173
	 * "No IMEI is Eligible For PriceDrop"); }
174
	 * 
175
	 * }
176
	 */
23819 govind 177
 
23951 amit.gupta 178
	@RequestMapping(value = "/price-drop/imes/download")
179
	public ResponseEntity<ByteArrayResource> downloadPriceDropImeis(HttpServletRequest request,
180
			@RequestParam LocalDateTime affectedDate, @RequestParam int itemId) throws Exception {
181
		Item item = itemRepository.selectById(itemId);
23968 amit.gupta 182
		ByteArrayOutputStream baos = getByteArrayOutputStream(affectedDate, item.getCatalogItemId());
23951 amit.gupta 183
		final HttpHeaders headers = new HttpHeaders();
184
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
185
		headers.set("Content-disposition", "inline; filename=imei-" + item.getItemDescriptionNoColor() + ".csv");
186
		byte[] byteArray = baos.toByteArray();
187
		headers.setContentLength(byteArray.length);
188
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
189
	}
190
 
23968 amit.gupta 191
	@RequestMapping(value = "/processPriceDrop", method = RequestMethod.POST)
192
	public String processPriceDrop(HttpServletRequest request, @RequestBody PriceDropProcessModel priceDropProcess,
193
			Model model) throws Exception {
194
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropProcess.getPriceDropId());
195
		boolean response = false;
196
		if (priceDrop.getProcessTimestamp() == null) {
197
			priceDrop.setPartnerPayout(priceDropProcess.getPartnerPayout());
198
			priceDrop.setPriceDropIn(priceDropProcess.getPriceDropIn());
199
			priceDrop.setProcessTimestamp(LocalDateTime.now());
200
			priceDropRepository.persist(priceDrop);
23977 amit.gupta 201
			String description  = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0).getItemDescriptionNoColor();
23968 amit.gupta 202
			List<ImeiDropSummaryModel> partnerPendingImeis = getPartnerPendingImeis(priceDrop.getAffectedOn(),
203
					priceDrop.getCatalogItemId());
204
			if (partnerPendingImeis.size() > 0) {
205
				Map<Integer, List<ImeiDropSummaryModel>> partnerImeiMap = new HashMap<>();
206
				for (ImeiDropSummaryModel pendingImei : partnerPendingImeis) {
207
					if (!partnerImeiMap.containsKey(pendingImei.getRetailerId())) {
208
						partnerImeiMap.put(pendingImei.getRetailerId(), new ArrayList<>());
209
					}
210
					partnerImeiMap.get(pendingImei.getRetailerId()).add(pendingImei);
211
				}
23819 govind 212
 
23968 amit.gupta 213
				for (Map.Entry<Integer, List<ImeiDropSummaryModel>> pendingPartnerImei : partnerImeiMap.entrySet()) {
214
					List<ImeiDropSummaryModel> retailerImeiList = pendingPartnerImei.getValue();
215
					int fofoId = pendingPartnerImei.getKey();
216
					List<InventoryItem> inventoryItems = inventoryItemRepository.selectByFofoIdSerialNumbers(fofoId,
23969 amit.gupta 217
							retailerImeiList.stream().map(x -> x.getSerialNumber()).collect(Collectors.toSet()), false);
23968 amit.gupta 218
					String reversalReason = MessageFormat.format(
219
							"Scheme amount reversal due to Price Drop of Rs.{0} on {1}. Affected on {3}, Total {2} item(s)",
23977 amit.gupta 220
							priceDrop.getAmount(), description, pendingPartnerImei.getValue().size(),
23968 amit.gupta 221
							FormattingUtils.formatDate(priceDrop.getAffectedOn()));
222
					String aReason = MessageFormat.format(
223
							"Per unit payout of Rs.{4} Price Drop of Rs.{0} on {1} affected on {3}. Total {2} item(s)",
23977 amit.gupta 224
							priceDrop.getAmount(), description, pendingPartnerImei.getValue().size(),
23968 amit.gupta 225
							FormattingUtils.formatDate(priceDrop.getAffectedOn()), priceDropProcess.getPartnerPayout());
23977 amit.gupta 226
					inventoryService.updatePriceDrop(inventoryItems, priceDrop.getAmount());
23968 amit.gupta 227
					schemeService.reverseSchemes(inventoryItems, priceDropProcess.getPriceDropId(), reversalReason);
228
					walletService.addAmountToWallet(fofoId, priceDrop.getId(), WalletReferenceType.PRICE_DROP,
229
							aReason, priceDropProcess.getPartnerPayout()*pendingPartnerImei.getValue().size());
23819 govind 230
				}
231
 
232
			}
23968 amit.gupta 233
			response = true;
23819 govind 234
		}
23968 amit.gupta 235
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
236
		return "response";
23819 govind 237
	}
238
 
23884 amit.gupta 239
	@RequestMapping(value = "/priceDrop", method = RequestMethod.POST)
23945 amit.gupta 240
	public String addPriceDrop(HttpServletRequest request, Model model, @RequestBody PriceDropModel priceDropModel)
241
			throws Exception {
23884 amit.gupta 242
		boolean response = false;
23968 amit.gupta 243
		priceDropModel.setAllColors(true);
23945 amit.gupta 244
		if (this.validatePriceDrop(priceDropModel)) {
23884 amit.gupta 245
			TagListing tagListing = tagListingRepository.selectByItemId(priceDropModel.getItemId());
246
			float newDp = tagListing.getSellingPrice() - priceDropModel.getPd();
23945 amit.gupta 247
			if (newDp > 0) {
23884 amit.gupta 248
				List<Item> allItems = null;
249
				Item currentItem = itemRepository.selectById(priceDropModel.getItemId());
23945 amit.gupta 250
				if (priceDropModel.isAllColors()) {
23884 amit.gupta 251
					allItems = itemRepository.selectAllByCatalogItemId(currentItem.getCatalogItemId());
23945 amit.gupta 252
 
23884 amit.gupta 253
				} else {
23945 amit.gupta 254
					allItems = Arrays.asList(currentItem);
23884 amit.gupta 255
				}
23945 amit.gupta 256
				for (Item item : allItems) {
23884 amit.gupta 257
					TagListing itemTagListing = tagListingRepository.selectByItemId(item.getId());
23945 amit.gupta 258
					if (itemTagListing == null)
259
						continue;
23884 amit.gupta 260
					itemTagListing.setSellingPrice(newDp);
261
					itemTagListing.setMop(priceDropModel.getMop());
262
					tagListingRepository.persist(tagListing);
263
					List<VendorItemPricing> vipList = vendorItemPricingRepository.selectAll(item.getId());
23945 amit.gupta 264
					for (VendorItemPricing vip : vipList) {
23884 amit.gupta 265
						vip.setDp(newDp);
266
						vip.setMop(priceDropModel.getMop());
267
						vip.setNlc(priceDropModel.getNlc());
268
						vip.setTp(priceDropModel.getTp());
269
						vendorItemPricingRepository.persist(vip);
270
					}
271
					transactionService.updatePriceDrop(item.getId(), newDp);
272
				}
23951 amit.gupta 273
				PriceDrop priceDrop = new PriceDrop();
274
				priceDrop.setAffectedOn(priceDropModel.getAffectedDate());
23968 amit.gupta 275
				priceDrop.setOldDp(newDp + priceDropModel.getPd());
23951 amit.gupta 276
				priceDrop.setAmount(priceDropModel.getPd());
23968 amit.gupta 277
				priceDrop.setNewDp(newDp);
278
				priceDrop.setNlc(priceDropModel.getNlc());
279
				priceDrop.setTp(priceDropModel.getTp());
23951 amit.gupta 280
				priceDrop.setCreatedOn(LocalDateTime.now());
281
				priceDrop.setCatalogItemId(currentItem.getCatalogItemId());
282
				priceDropRepository.persist(priceDrop);
23884 amit.gupta 283
				response = true;
284
			} else {
23945 amit.gupta 285
				throw new ProfitMandiBusinessException("Price Drop", priceDropModel.getPd(),
286
						"Price Drop Cannot be more than Current DP");
23884 amit.gupta 287
			}
288
		}
289
		model.addAttribute("response", mvcResponseSender.createResponseString(response));
290
		return "response";
291
	}
23945 amit.gupta 292
 
23819 govind 293
	@RequestMapping(value = "/downloadtotalPriceDropIMEI/{priceDropId}", method = RequestMethod.GET)
294
	public ResponseEntity<?> downloadTotalPriceDropIMEI(HttpServletRequest request, @PathVariable int priceDropId,
23945 amit.gupta 295
			Model model) throws ProfitMandiBusinessException, Exception {
23819 govind 296
 
297
		PriceDrop priceDrop = priceDropRepository.selectById(priceDropId);
23968 amit.gupta 298
		Item item = itemRepository.selectAllByCatalogItemId(priceDrop.getCatalogItemId()).get(0);
299
		ByteArrayOutputStream baos = getByteArrayOutputStream(priceDrop.getAffectedOn(), priceDrop.getCatalogItemId());
300
		final HttpHeaders headers = new HttpHeaders();
301
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
302
		headers.set("Content-disposition", "inline; filename=pricedrop-" + item.getItemDescriptionNoColor() + "-"
303
				+ FormattingUtils.formatDate(priceDrop.getAffectedOn()) + ".csv");
304
		byte[] byteArray = baos.toByteArray();
305
		headers.setContentLength(byteArray.length);
306
		return new ResponseEntity<ByteArrayResource>(new ByteArrayResource(byteArray), headers, HttpStatus.OK);
23951 amit.gupta 307
 
308
	}
309
 
23968 amit.gupta 310
	private List<ImeiDropSummaryModel> getPartnerPendingImeis(LocalDateTime affectedOn, Integer catalogItemId)
23951 amit.gupta 311
			throws Exception {
23945 amit.gupta 312
		Map<String, String> params = new HashMap<>();
23951 amit.gupta 313
		params.put("MANUAL_criteria1_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
314
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogItemId);
315
		List<String> itemIds = items.stream().map(x -> String.valueOf(x.getId())).collect(Collectors.toList());
316
		params.put("MANUAL_itemId", StringUtils.join(itemIds, ","));
23945 amit.gupta 317
		Map<String, String> params1 = new HashMap<>();
23951 amit.gupta 318
		params1.put("MANUAL_criteriaDate_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
319
		params1.put("MANUAL_criteriaItemId", StringUtils.join(itemIds, ","));
23945 amit.gupta 320
 
23951 amit.gupta 321
		List<? extends ImeiDropSummaryModel> grnPendingList = getReports(GrnPendingDataModel.class,
322
				ReporticoProject.FOCO, "imeispendinggrn.xml", params);
323
		List<? extends ImeiDropSummaryModel> partnerImeiNotSoldList = getReports(PartnerImeiNotSold.class,
324
				ReporticoProject.FOCO, "PartnerIMEINotSold.xml", params1);
23970 amit.gupta 325
 
23951 amit.gupta 326
		List<ImeiDropSummaryModel> mergedImeis = new ArrayList<>();
327
		mergedImeis.addAll(grnPendingList);
328
		mergedImeis.addAll(partnerImeiNotSoldList);
23968 amit.gupta 329
 
330
		return mergedImeis;
331
	}
332
 
333
	private ByteArrayOutputStream getByteArrayOutputStream(LocalDateTime affectedOn, Integer catalogItemId)
334
			throws Exception {
335
 
336
		List<Item> items = itemRepository.selectAllByCatalogItemId(catalogItemId);
337
		List<String> itemIds = items.stream().map(x -> String.valueOf(x.getId())).collect(Collectors.toList());
338
 
339
		Map<String, String> params = new HashMap<>();
340
		params.put("MANUAL_criteria1_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn));
341
		params.put("MANUAL_itemId", StringUtils.join(itemIds, ","));
342
 
343
		Map<String, String> params1 = new HashMap<>();
23979 amit.gupta 344
		params1.put("MANUAL_criteriaDate_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn.minusDays(1)));
23968 amit.gupta 345
		params1.put("MANUAL_criteriaItemId", StringUtils.join(itemIds, ","));
23970 amit.gupta 346
 
23968 amit.gupta 347
 
23970 amit.gupta 348
		Map<String, String> params2 = new HashMap<>();
23981 amit.gupta 349
		params2.put("MANUAL_Criteria2_FROMDATE", FormattingUtils.formatReporitcoDate(affectedOn.minusDays(1)));
23970 amit.gupta 350
		params2.put("MANUAL_Criteria1", StringUtils.join(itemIds, ","));
351
 
352
 
23968 amit.gupta 353
		List<? extends ImeiDropSummaryModel> grnPendingList = getReports(GrnPendingDataModel.class,
354
				ReporticoProject.FOCO, "imeispendinggrn.xml", params);
355
		List<? extends ImeiDropSummaryModel> partnerImeiNotSoldList = getReports(PartnerImeiNotSold.class,
356
				ReporticoProject.FOCO, "PartnerIMEINotSold.xml", params1);
23970 amit.gupta 357
		List<? extends ImeiDropSummaryModel> itemStockOnDateList = getReports(ClosingStockOnDate.class,
358
				ReporticoProject.WAREHOUSENEW, "itemstockondate.xml", params2);
359
 
23968 amit.gupta 360
		List<ImeiDropSummaryModel> mergedImeis = new ArrayList<>();
361
		mergedImeis.addAll(grnPendingList);
362
		mergedImeis.addAll(partnerImeiNotSoldList);
23970 amit.gupta 363
		mergedImeis.addAll(itemStockOnDateList);
23968 amit.gupta 364
 
23951 amit.gupta 365
		List<List<Object>> rows = new ArrayList<>();
366
		for (ImeiDropSummaryModel imeiDropSummaryModel : mergedImeis) {
367
			List<Object> row = new ArrayList<>();
368
			row.add(imeiDropSummaryModel.getSerialNumber());
369
			row.add(imeiDropSummaryModel.getStoreName());
370
			row.add(imeiDropSummaryModel.getPartnerCode());
371
			row.add(imeiDropSummaryModel.getItemId());
372
			row.add(imeiDropSummaryModel.getBrand());
373
			row.add(imeiDropSummaryModel.getModelName());
374
			row.add(imeiDropSummaryModel.getModelNumber());
375
			row.add(imeiDropSummaryModel.getColor());
376
			row.add(FormattingUtils.formatReporitcoDate(imeiDropSummaryModel.getLastScanned()));
377
			rows.add(row);
378
		}
379
 
380
		return FileUtil.getCSVByteStream(Arrays.asList("IMEI Number", "Store Name", "Store Code", "Item ID", "Brand",
381
				"Model Name", "Model Number", "Color", "Last Scanned"), rows);
23819 govind 382
	}
383
 
23945 amit.gupta 384
	private <T> List<T> getReports(Class<T> className, ReporticoProject project, String reportName,
385
			Map<String, String> params) throws Exception {
386
		HttpResponse reportResponse = reporticoService.getJsonFile(project, reportName, params);
23951 amit.gupta 387
		JavaType type = objectMapper.getTypeFactory().constructParametricType(ReporticoResponseModel.class, className);
388
		ObjectReader or = objectMapper.readerFor(type);
23945 amit.gupta 389
		ReporticoResponseModel<T> responseObj = or.readValue(reportResponse.getEntity().getContent());
390
		return responseObj.getData();
391
	}
392
 
23884 amit.gupta 393
	private boolean validatePriceDrop(PriceDropModel priceDropModel) throws ProfitMandiBusinessException {
23945 amit.gupta 394
		if (priceDropModel.getMop() > 0 && priceDropModel.getMop() > 0 && priceDropModel.getNlc() > 0
395
				&& priceDropModel.getTp() > 0 && priceDropModel.getNlc() > 0) {
23884 amit.gupta 396
			return true;
397
		}
398
		return false;
399
	}
23945 amit.gupta 400
 
23819 govind 401
}