Subversion Repositories SmartDukaan

Rev

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

Rev 27544 Rev 27583
Line 29... Line 29...
29
import org.apache.commons.io.FileUtils;
29
import org.apache.commons.io.FileUtils;
30
import org.apache.commons.lang3.StringUtils;
30
import org.apache.commons.lang3.StringUtils;
31
import org.apache.logging.log4j.LogManager;
31
import org.apache.logging.log4j.LogManager;
32
import org.apache.logging.log4j.Logger;
32
import org.apache.logging.log4j.Logger;
33
import org.apache.thrift.TException;
33
import org.apache.thrift.TException;
-
 
34
import org.hibernate.type.CurrencyType;
34
import org.json.JSONObject;
35
import org.json.JSONObject;
35
import org.springframework.beans.factory.annotation.Autowired;
36
import org.springframework.beans.factory.annotation.Autowired;
36
import org.springframework.beans.factory.annotation.Qualifier;
37
import org.springframework.beans.factory.annotation.Qualifier;
37
import org.springframework.beans.factory.annotation.Value;
38
import org.springframework.beans.factory.annotation.Value;
38
import org.springframework.core.io.ClassPathResource;
39
import org.springframework.core.io.ClassPathResource;
Line 70... Line 71...
70
import com.spice.profitmandi.common.util.ExcelUtils;
71
import com.spice.profitmandi.common.util.ExcelUtils;
71
import com.spice.profitmandi.common.util.PdfUtils;
72
import com.spice.profitmandi.common.util.PdfUtils;
72
import com.spice.profitmandi.dao.entity.catalog.Item;
73
import com.spice.profitmandi.dao.entity.catalog.Item;
73
import com.spice.profitmandi.dao.entity.catalog.TagListing;
74
import com.spice.profitmandi.dao.entity.catalog.TagListing;
74
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
75
import com.spice.profitmandi.dao.entity.catalog.TagRanking;
-
 
76
import com.spice.profitmandi.dao.entity.fofo.CurrentInventorySnapshot;
75
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
77
import com.spice.profitmandi.dao.entity.fofo.FofoOrder;
76
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
78
import com.spice.profitmandi.dao.entity.fofo.FofoStore;
77
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
79
import com.spice.profitmandi.dao.entity.fofo.InventoryItem;
78
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
80
import com.spice.profitmandi.dao.entity.fofo.LiveDemoSerialNumber;
79
import com.spice.profitmandi.dao.entity.transaction.NotifyCancel;
81
import com.spice.profitmandi.dao.entity.transaction.NotifyCancel;
Line 116... Line 118...
116
public class InventoryController {
118
public class InventoryController {
117
 
119
 
118
	private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
120
	private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
119
 
121
 
120
	private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy H:m:s");
122
	private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy H:m:s");
121
	
123
 
122
	private static final List<String> imeis = Arrays.asList(
124
	private static final List<String> imeis = Arrays.asList("351030944216680", "351030944217183", "351030944217886",
123
			"351030944216680",
-
 
124
			"351030944217183",
-
 
125
			"351030944217886",
-
 
126
			"351030944507286",
-
 
127
			"351081710231270",
-
 
128
			"351081710238713",
-
 
129
			"351081710238796",
-
 
130
			"351081710241279",
125
			"351030944507286", "351081710231270", "351081710238713", "351081710238796", "351081710241279",
131
			"351081710244737",
126
			"351081710244737", "355777112655976");
132
			"355777112655976"
-
 
133
	);
-
 
134
 
127
 
135
	@Autowired
128
	@Autowired
136
	private CookiesProcessor cookiesProcessor;
129
	private CookiesProcessor cookiesProcessor;
137
 
130
 
138
	@Autowired
131
	@Autowired
Line 190... Line 183...
190
	@Autowired
183
	@Autowired
191
	private UserAccountRepository userAccountRepository;
184
	private UserAccountRepository userAccountRepository;
192
 
185
 
193
	@Autowired
186
	@Autowired
194
	private OrderService orderService;
187
	private OrderService orderService;
195
	
188
 
196
	@Value("${saholic.api.host}")
189
	@Value("${saholic.api.host}")
197
	private String host;
190
	private String host;
198
 
191
 
199
	@Value("${saholic.api.port}")
192
	@Value("${saholic.api.port}")
200
	private int port;
193
	private int port;
Line 256... Line 249...
256
		return "inventory-snapshot-paginated";
249
		return "inventory-snapshot-paginated";
257
	}
250
	}
258
 
251
 
259
	@RequestMapping(value = "/getCatalog")
252
	@RequestMapping(value = "/getCatalog")
260
	public String getCatalog(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
253
	public String getCatalog(HttpServletRequest request, @RequestParam(name = "offset", defaultValue = "0") int offset,
261
			@RequestParam(name = "limit", defaultValue = "10") int limit,
254
			@RequestParam(name = "limit", defaultValue = "20") int limit,
262
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
255
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
-
 
256
			@RequestParam(name = "itemId", required = false, defaultValue = "0") int itemId, Model model)
263
			throws ProfitMandiBusinessException {
257
			throws ProfitMandiBusinessException {
264
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
258
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
265
		if (searchTerm == null) {
259
		if (searchTerm == null) {
266
			searchTerm = "";
260
			searchTerm = "";
267
		}
261
		}
268
 
262
 
269
		Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm);
263
		Map<String, Object> map = inventoryService.getCatalog(loginDetails.getFofoId(), offset, limit, searchTerm,
-
 
264
				itemId);
270
		model.addAllAttributes(map);
265
		model.addAllAttributes(map);
271
		model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
266
		model.addAttribute("hasGift", hasGift(loginDetails.getFofoId()));
272
 
267
 
273
		return "catalog";
268
		return "catalog";
274
	}
269
	}
Line 281... Line 276...
281
		} catch (ProfitMandiBusinessException e) {
276
		} catch (ProfitMandiBusinessException e) {
282
			return false;
277
			return false;
283
		}
278
		}
284
	}
279
	}
285
 
280
 
-
 
281
	/*
-
 
282
	 * @RequestMapping(value = "/getSimilarItem") public String
-
 
283
	 * getCatalog(HttpServletRequest request, @RequestParam(name = "offset",
-
 
284
	 * defaultValue = "0") int offset,
-
 
285
	 * 
-
 
286
	 * @RequestParam(name = "limit", defaultValue = "10") int limit, @RequestParam
-
 
287
	 * int catalogItemId,
-
 
288
	 * 
-
 
289
	 * @RequestParam(name = "searchTerm", required = false, defaultValue = "")
-
 
290
	 * String searchTerm, Model model) throws ProfitMandiBusinessException
-
 
291
	 * 
-
 
292
	 * { LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
-
 
293
	 * 
-
 
294
	 * if (catalogItemId != 0) { TagListing tagListing = null; List<Item> items =
-
 
295
	 * itemRepository.selectAllByCatalogItemId(catalogItemId); Map<Integer, Float>
-
 
296
	 * itemPriceing = new HashMap<>(); List<CustomCurrentInventorySnapshot>
-
 
297
	 * inventoryList = new ArrayList<>();
-
 
298
	 * 
-
 
299
	 * for (Item item : items) { tagListing =
-
 
300
	 * tagListingRepository.selectByItemId(item.getId());
-
 
301
	 * CustomCurrentInventorySnapshot customCurrentInventorySnapshot =
-
 
302
	 * inventoryService .checkItemAvailability(item.getId(),
-
 
303
	 * loginDetails.getFofoId()); inventoryList.add(customCurrentInventorySnapshot);
-
 
304
	 * itemPriceing.put(item.getId(), tagListing.getMop()); } if (tagListing !=
-
 
305
	 * null) {
-
 
306
	 * 
-
 
307
	 * float tagStartPrice = tagListing.getMop() - 1000; float tagEndPrice =
-
 
308
	 * tagListing.getMop() + 2000; List<TagListing> tagMoplists =
-
 
309
	 * tagListingRepository.selectAllBetweenMopPrice(tagStartPrice, tagEndPrice);
-
 
310
	 * 
-
 
311
	 * for (TagListing tagListings : tagMoplists) {
-
 
312
	 * 
-
 
313
	 * int TagListingItemid = tagListings.getItemId();
-
 
314
	 * 
-
 
315
	 * itemPriceing.put(TagListingItemid, tagListings.getMop());
-
 
316
	 * CustomCurrentInventorySnapshot customCurrentInventorySnapshotMopPrice =
-
 
317
	 * inventoryService .checkItemAvailability(TagListingItemid,
-
 
318
	 * loginDetails.getFofoId());
-
 
319
	 * 
-
 
320
	 * inventoryList.add(customCurrentInventorySnapshotMopPrice); }
-
 
321
	 * 
-
 
322
	 * }
-
 
323
	 * 
-
 
324
	 * else { LOGGER.info("tagBrandlist is null"); }
-
 
325
	 * 
-
 
326
	 * model.addAttribute("inventoryLists", inventoryList);
-
 
327
	 * model.addAttribute("itemPriceing", itemPriceing);
-
 
328
	 * 
-
 
329
	 * }
-
 
330
	 * 
-
 
331
	 * return "catalog-similar-Id"; }
-
 
332
	 */
286
	@RequestMapping(value = "/getPaginatedCatalog")
333
	@RequestMapping(value = "/getPaginatedCatalog")
287
	public String getCatalogPaginated(HttpServletRequest request,
334
	public String getCatalogPaginated(HttpServletRequest request,
288
			@RequestParam(name = "offset", defaultValue = "0") int offset,
335
			@RequestParam(name = "offset", defaultValue = "0") int offset,
289
			@RequestParam(name = "limit", defaultValue = "10") int limit,
336
			@RequestParam(name = "limit", defaultValue = "20") int limit,
290
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm, Model model)
337
			@RequestParam(name = "searchTerm", required = false, defaultValue = "") String searchTerm,
-
 
338
			@RequestParam(name = "itemId", required = false, defaultValue = "0") int itemId, Model model)
291
			throws ProfitMandiBusinessException {
339
			throws ProfitMandiBusinessException {
292
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
340
		LoginDetails loginDetails = cookiesProcessor.getCookiesObject(request);
293
		if (searchTerm == null) {
341
		if (searchTerm == null) {
294
			searchTerm = "";
342
			searchTerm = "";
295
		}
343
		}
296
		Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit,
344
		Map<String, Object> map = inventoryService.getPaginatedCatalog(loginDetails.getFofoId(), offset, limit,
297
				searchTerm);
345
				searchTerm, itemId);
298
		model.addAllAttributes(map);
346
		model.addAllAttributes(map);
299
		return "catalog-paginated";
347
		return "catalog-paginated";
300
	}
348
	}
301
 
349
 
302
	@RequestMapping(value = "/checkItemAvailability")
350
	@RequestMapping(value = "/checkItemAvailability")
Line 440... Line 488...
440
			}
488
			}
441
		});
489
		});
442
		model.addAttribute("inventoryItems", inventoryItems);
490
		model.addAttribute("inventoryItems", inventoryItems);
443
		return "activated-imeis";
491
		return "activated-imeis";
444
	}
492
	}
445
	
493
 
446
	@RequestMapping(value = "/view-invoices")
494
	@RequestMapping(value = "/view-invoices")
447
	public String viewInvoices(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
495
	public String viewInvoices(HttpServletRequest request, Model model) throws ProfitMandiBusinessException {
448
		return "view-dummy-invoices";
496
		return "view-dummy-invoices";
449
	}
497
	}
450
	
498
 
451
	@RequestMapping(value = "/dummy-invoices")
499
	@RequestMapping(value = "/dummy-invoices")
452
	public ResponseEntity<?> downloadInvoices(HttpServletRequest request, @RequestParam String serialNumber, Model model) throws ProfitMandiBusinessException {
500
	public ResponseEntity<?> downloadInvoices(HttpServletRequest request, @RequestParam String serialNumber,
-
 
501
			Model model) throws ProfitMandiBusinessException {
453
		byte[] bytes = null;
502
		byte[] bytes = null;
454
		if(!imeis.contains(serialNumber)) {
503
		if (!imeis.contains(serialNumber)) {
-
 
504
 
455
			PdfModel pdfModel = orderService.getDummyPdfModel(serialNumber);
505
			PdfModel pdfModel = orderService.getDummyPdfModel(serialNumber);
456
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
506
			ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
457
			PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
507
			PdfUtils.generateAndWrite(Arrays.asList(pdfModel), byteArrayOutputStream);
458
			bytes = byteArrayOutputStream.toByteArray();
508
			bytes = byteArrayOutputStream.toByteArray();
459
		} else {
509
		} else {
460
			ClassPathResource resource = new ClassPathResource("/META-INF/" + serialNumber + ".pdf");
510
			ClassPathResource resource = new ClassPathResource("/META-INF/" + serialNumber + ".pdf");
461
			try {
511
			try {
462
				bytes = FileUtils.readFileToByteArray(resource.getFile());
512
				bytes = FileUtils.readFileToByteArray(resource.getFile());
463
			} catch(Exception e) {
513
			} catch (Exception e) {
464
				
514
 
465
			}
515
			}
466
		}
516
		}
467
		final HttpHeaders headers = new HttpHeaders();
517
		final HttpHeaders headers = new HttpHeaders();
468
		headers.setContentType(MediaType.APPLICATION_PDF);
518
		headers.setContentType(MediaType.APPLICATION_PDF);
469
		headers.set("Content-disposition", "inline; filename=invoice-" + serialNumber + ".pdf");
519
		headers.set("Content-disposition", "inline; filename=invoice-" + serialNumber + ".pdf");
Line 506... Line 556...
506
		headers.setContentLength(byteArrayOutputStream.toByteArray().length);
556
		headers.setContentLength(byteArrayOutputStream.toByteArray().length);
507
		final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
557
		final InputStream inputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
508
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
558
		final InputStreamResource inputStreamResource = new InputStreamResource(inputStream);
509
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
559
		return new ResponseEntity<InputStreamResource>(inputStreamResource, headers, HttpStatus.OK);
510
	}
560
	}
511
	
561
 
512
	@RequestMapping(value = "/aging-report", method = RequestMethod.GET)
562
	@RequestMapping(value = "/aging-report", method = RequestMethod.GET)
513
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request) throws ProfitMandiBusinessException {
563
	public ResponseEntity<?> downloadInventoryItemAgingByInterval(HttpServletRequest request)
-
 
564
			throws ProfitMandiBusinessException {
514
		
565
 
515
		List<Integer> intervals = Arrays.asList(5,15,30,45);
566
		List<Integer> intervals = Arrays.asList(5, 15, 30, 45);
516
		List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService.getItemAgingByInterval(intervals)
567
		List<InventoryItemAgingModel> inventoryItemAgingModels = inventoryService.getItemAgingByInterval(intervals)
517
				.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
568
				.values().stream().flatMap(Collection::stream).collect(Collectors.toList());
518
		LOGGER.info("Fofo Id {}", inventoryItemAgingModels.get(0).getFofoId());
569
		LOGGER.info("Fofo Id {}", inventoryItemAgingModels.get(0).getFofoId());
519
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
570
		ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
520
		ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
571
		ExcelUtils.writeInventoryItemAgingModels(inventoryItemAgingModels, intervals, byteArrayOutputStream);
521
		
572
 
522
		final HttpHeaders headers = new HttpHeaders();
573
		final HttpHeaders headers = new HttpHeaders();
523
		// private static final String CONTENT_TYPE_XLSX =
574
		// private static final String CONTENT_TYPE_XLSX =
524
		// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
575
		// "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
525
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
576
		headers.set("Content-Type", "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
526
		// headers.set("Content-Type", "application/vnd.ms-excel");
577
		// headers.set("Content-Type", "application/vnd.ms-excel");
Line 1151... Line 1202...
1151
 
1202
 
1152
	@RequestMapping(value = "/getProductCompareInfo", method = RequestMethod.GET)
1203
	@RequestMapping(value = "/getProductCompareInfo", method = RequestMethod.GET)
1153
	public String getProductCompareInfo(HttpServletRequest request, @RequestParam List<Long> catalogIds, Model model)
1204
	public String getProductCompareInfo(HttpServletRequest request, @RequestParam List<Long> catalogIds, Model model)
1154
			throws Exception {
1205
			throws Exception {
1155
		List<ContentPojo> cps = new ArrayList<>();
1206
		List<ContentPojo> cps = new ArrayList<>();
-
 
1207
		Set<Integer> cataogIds = catalogIds.stream().mapToInt(Long::intValue).boxed().collect(Collectors.toSet());
-
 
1208
 
1156
		for (Long cId : catalogIds) {
1209
		for (Long cId : catalogIds) {
1157
			ContentPojo cp = mongoClient.getEntityById(cId);
1210
			ContentPojo cp = mongoClient.getEntityById(cId);
1158
			if (cp.getName() == null) {
1211
			if (cp.getName() == null) {
1159
				cp.setName(itemRepository.selectAllByCatalogItemId(cId.intValue()).get(0).getItemDescriptionNoColor());
1212
				cp.setName(itemRepository.selectAllByCatalogItemId(cId.intValue()).get(0).getItemDescriptionNoColor());
1160
			}
1213
			}
-
 
1214
			List<Item> items = itemRepository.selectAllByCatalogItemId(cId.intValue());
-
 
1215
			TagListing tagListing = tagListingRepository.selectByItemId(items.get(0).getId());
-
 
1216
			cp.setPrice(tagListing.getMop());
1161
			cps.add(cp);
1217
			cps.add(cp);
-
 
1218
 
1162
		}
1219
		}
1163
 
1220
 
1164
		List<Map<String, String>> entityList = new ArrayList<>();
1221
		List<Map<String, String>> entityList = new ArrayList<>();
1165
		for (ContentPojo cp : cps) {
1222
		for (ContentPojo cp : cps) {
1166
			Map<String, String> specsMap = new HashMap<>();
1223
			Map<String, String> specsMap = new HashMap<>();
Line 1170... Line 1227...
1170
					String key = title + s.getName();
1227
					String key = title + s.getName();
1171
					specsMap.put(key, String.join(", ", s.getValues()));
1228
					specsMap.put(key, String.join(", ", s.getValues()));
1172
				}
1229
				}
1173
			}
1230
			}
1174
			entityList.add(specsMap);
1231
			entityList.add(specsMap);
-
 
1232
		
1175
		}
1233
		}
1176
 
1234
 
1177
		LOGGER.info("cps" + cps);
1235
		LOGGER.info("cps" + cps);
1178
		model.addAttribute("cps", cps);
1236
		model.addAttribute("cps", cps);
1179
		model.addAttribute("catalogIds", gson.toJson(catalogIds, List.class));
1237
		model.addAttribute("catalogIds", gson.toJson(catalogIds, List.class));