| Line 1... |
Line 1... |
| 1 |
package com.spice.profitmandi.web.controller;
|
1 |
package com.spice.profitmandi.web.controller;
|
| 2 |
|
2 |
|
| 3 |
import java.io.ByteArrayInputStream;
|
3 |
import java.io.ByteArrayInputStream;
|
| 4 |
import java.io.ByteArrayOutputStream;
|
4 |
import java.io.ByteArrayOutputStream;
|
| 5 |
import java.io.InputStream;
|
5 |
import java.io.InputStream;
|
| - |
|
6 |
import java.io.InputStreamReader;
|
| 6 |
import java.time.LocalDateTime;
|
7 |
import java.time.LocalDateTime;
|
| - |
|
8 |
import java.time.format.DateTimeFormatter;
|
| 7 |
import java.util.ArrayList;
|
9 |
import java.util.ArrayList;
|
| 8 |
import java.util.Arrays;
|
10 |
import java.util.Arrays;
|
| 9 |
import java.util.HashMap;
|
11 |
import java.util.HashMap;
|
| 10 |
import java.util.HashSet;
|
12 |
import java.util.HashSet;
|
| 11 |
import java.util.Iterator;
|
13 |
import java.util.Iterator;
|
| Line 16... |
Line 18... |
| 16 |
import java.util.stream.Collectors;
|
18 |
import java.util.stream.Collectors;
|
| 17 |
|
19 |
|
| 18 |
import javax.servlet.http.HttpServletRequest;
|
20 |
import javax.servlet.http.HttpServletRequest;
|
| 19 |
import javax.servlet.http.HttpServletResponse;
|
21 |
import javax.servlet.http.HttpServletResponse;
|
| 20 |
|
22 |
|
| - |
|
23 |
import org.apache.commons.csv.CSVFormat;
|
| - |
|
24 |
import org.apache.commons.csv.CSVParser;
|
| - |
|
25 |
import org.apache.commons.csv.CSVRecord;
|
| 21 |
import org.apache.logging.log4j.LogManager;
|
26 |
import org.apache.logging.log4j.LogManager;
|
| 22 |
import org.apache.logging.log4j.Logger;
|
27 |
import org.apache.logging.log4j.Logger;
|
| 23 |
import org.apache.thrift.TException;
|
28 |
import org.apache.thrift.TException;
|
| 24 |
import org.json.JSONObject;
|
29 |
import org.json.JSONObject;
|
| 25 |
import org.springframework.beans.factory.annotation.Autowired;
|
30 |
import org.springframework.beans.factory.annotation.Autowired;
|
| Line 32... |
Line 37... |
| 32 |
import org.springframework.http.ResponseEntity;
|
37 |
import org.springframework.http.ResponseEntity;
|
| 33 |
import org.springframework.mail.javamail.JavaMailSender;
|
38 |
import org.springframework.mail.javamail.JavaMailSender;
|
| 34 |
import org.springframework.stereotype.Controller;
|
39 |
import org.springframework.stereotype.Controller;
|
| 35 |
import org.springframework.transaction.annotation.Transactional;
|
40 |
import org.springframework.transaction.annotation.Transactional;
|
| 36 |
import org.springframework.ui.Model;
|
41 |
import org.springframework.ui.Model;
|
| - |
|
42 |
import org.springframework.web.bind.annotation.PostMapping;
|
| 37 |
import org.springframework.web.bind.annotation.RequestBody;
|
43 |
import org.springframework.web.bind.annotation.RequestBody;
|
| 38 |
import org.springframework.web.bind.annotation.RequestMapping;
|
44 |
import org.springframework.web.bind.annotation.RequestMapping;
|
| 39 |
import org.springframework.web.bind.annotation.RequestMethod;
|
45 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 40 |
import org.springframework.web.bind.annotation.RequestParam;
|
46 |
import org.springframework.web.bind.annotation.RequestParam;
|
| - |
|
47 |
import org.springframework.web.bind.annotation.RequestPart;
|
| - |
|
48 |
import org.springframework.web.multipart.MultipartFile;
|
| 41 |
|
49 |
|
| 42 |
import com.google.gson.Gson;
|
50 |
import com.google.gson.Gson;
|
| 43 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
51 |
import com.spice.profitmandi.common.enumuration.MessageType;
|
| 44 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
52 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 45 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
53 |
import com.spice.profitmandi.common.model.CustomCurrentInventorySnapshot;
|
| Line 87... |
Line 95... |
| 87 |
import com.spice.profitmandi.service.user.RetailerService;
|
95 |
import com.spice.profitmandi.service.user.RetailerService;
|
| 88 |
import com.spice.profitmandi.web.model.LoginDetails;
|
96 |
import com.spice.profitmandi.web.model.LoginDetails;
|
| 89 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
97 |
import com.spice.profitmandi.web.util.CookiesProcessor;
|
| 90 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
98 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
| 91 |
|
99 |
|
| - |
|
100 |
|
| - |
|
101 |
|
| 92 |
import in.shop2020.model.v1.order.OrderStatus;
|
102 |
import in.shop2020.model.v1.order.OrderStatus;
|
| 93 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
103 |
import in.shop2020.model.v1.order.TransactionServiceException;
|
| 94 |
|
104 |
|
| 95 |
@Controller
|
105 |
@Controller
|
| 96 |
@Transactional(rollbackFor = Throwable.class)
|
106 |
@Transactional(rollbackFor = Throwable.class)
|
| 97 |
public class InventoryController {
|
107 |
public class InventoryController {
|
| 98 |
|
108 |
|
| 99 |
private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
|
109 |
private static final Logger LOGGER = LogManager.getLogger(InventoryController.class);
|
| - |
|
110 |
|
| - |
|
111 |
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("M/d/yyyy h:m:s a");
|
| 100 |
|
112 |
|
| 101 |
@Autowired
|
113 |
@Autowired
|
| 102 |
private CookiesProcessor cookiesProcessor;
|
114 |
private CookiesProcessor cookiesProcessor;
|
| 103 |
|
115 |
|
| 104 |
@Autowired
|
116 |
@Autowired
|
| Line 462... |
Line 474... |
| 462 |
|
474 |
|
| 463 |
return "feature";
|
475 |
return "feature";
|
| 464 |
|
476 |
|
| 465 |
}
|
477 |
}
|
| 466 |
|
478 |
|
| - |
|
479 |
@PostMapping(value = "/imei/upload")
|
| - |
|
480 |
public boolean uploadContent(HttpServletRequest request, @RequestParam String brand, @RequestPart("file") MultipartFile file, Model model)
|
| - |
|
481 |
throws Exception {
|
| - |
|
482 |
/*if(brand==null) {
|
| - |
|
483 |
throw new ProfitMandiBusinessException("Please select brand", "Brand empty", "Brand required");
|
| - |
|
484 |
}*/
|
| - |
|
485 |
List<CSVRecord> masterDataList = readFile(file);
|
| - |
|
486 |
|
| - |
|
487 |
|
| - |
|
488 |
Map<String, LocalDateTime> imeisActivationMap = masterDataList.stream().collect(Collectors.toMap(x->x.get(0),
|
| - |
|
489 |
x-> LocalDateTime.parse((String)(x.get(1)), formatter)));
|
| - |
|
490 |
List<InventoryItem> inventoryItems = inventoryItemRepository.selectBySerialNumbers(imeisActivationMap.keySet());
|
| - |
|
491 |
inventoryItems.stream().forEach(inventoryItem -> {
|
| - |
|
492 |
if (inventoryItem.getActivationTimestamp() == null) {
|
| - |
|
493 |
if (inventoryItem.getLastScanType().equals(com.spice.profitmandi.dao.enumuration.fofo.ScanType.SALE)
|
| - |
|
494 |
|| inventoryItem.getGoodQuantity() + inventoryItem.getBadQuantity() == 1) {
|
| - |
|
495 |
inventoryItem.setActivationTimestamp(imeisActivationMap.get(inventoryItem.getSerialNumber()));
|
| - |
|
496 |
}
|
| - |
|
497 |
}
|
| - |
|
498 |
});
|
| - |
|
499 |
return true;
|
| - |
|
500 |
}
|
| - |
|
501 |
|
| - |
|
502 |
private List<CSVRecord> readFile(MultipartFile file) throws Exception {
|
| - |
|
503 |
List<CSVRecord> records = null;
|
| - |
|
504 |
try (CSVParser parser = new CSVParser(new InputStreamReader(file.getInputStream()), CSVFormat.DEFAULT)) {
|
| - |
|
505 |
records = parser.getRecords();
|
| - |
|
506 |
if (records.size() < 2) {
|
| - |
|
507 |
throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
|
| - |
|
508 |
}
|
| - |
|
509 |
records.remove(0);
|
| - |
|
510 |
} catch(Exception e) {
|
| - |
|
511 |
throw new ProfitMandiBusinessException("Parsing Failed", "parse failed", "file parse failed");
|
| - |
|
512 |
}
|
| - |
|
513 |
return records;
|
| - |
|
514 |
}
|
| - |
|
515 |
|
| 467 |
@RequestMapping(value = "/itemfeature", method = RequestMethod.POST)
|
516 |
@RequestMapping(value = "/itemfeature", method = RequestMethod.POST)
|
| 468 |
public String Itemfeature(HttpServletRequest request, @RequestBody ItemFeatureDataModel itemFeatureDatatModel,
|
517 |
public String Itemfeature(HttpServletRequest request, @RequestBody ItemFeatureDataModel itemFeatureDatatModel,
|
| 469 |
Model model) throws Exception {
|
518 |
Model model) throws Exception {
|
| 470 |
TagRanking tagRanking = tagRankingRepository.selectBycatalogItemId(itemFeatureDatatModel.getCatalogItemId());
|
519 |
TagRanking tagRanking = tagRankingRepository.selectBycatalogItemId(itemFeatureDatatModel.getCatalogItemId());
|
| 471 |
LOGGER.info("tagRanking" + tagRanking);
|
520 |
LOGGER.info("tagRanking" + tagRanking);
|