| 28495 |
tejbeer |
1 |
package com.spice.profitmandi.web.controller;
|
|
|
2 |
|
|
|
3 |
import java.io.File;
|
| 28504 |
amit.gupta |
4 |
import java.io.IOException;
|
|
|
5 |
import java.io.InputStreamReader;
|
|
|
6 |
import java.sql.SQLClientInfoException;
|
|
|
7 |
import java.util.ArrayList;
|
|
|
8 |
import java.util.Arrays;
|
| 28495 |
tejbeer |
9 |
import java.util.List;
|
| 28504 |
amit.gupta |
10 |
import java.util.stream.Collectors;
|
| 28495 |
tejbeer |
11 |
|
|
|
12 |
import javax.servlet.http.HttpServletRequest;
|
|
|
13 |
import javax.servlet.http.HttpServletResponse;
|
|
|
14 |
|
| 28504 |
amit.gupta |
15 |
import org.apache.commons.csv.CSVFormat;
|
|
|
16 |
import org.apache.commons.csv.CSVParser;
|
|
|
17 |
import org.apache.commons.csv.CSVRecord;
|
| 28495 |
tejbeer |
18 |
import org.apache.logging.log4j.LogManager;
|
|
|
19 |
import org.apache.logging.log4j.Logger;
|
|
|
20 |
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
21 |
import org.springframework.stereotype.Controller;
|
|
|
22 |
import org.springframework.transaction.annotation.Transactional;
|
|
|
23 |
import org.springframework.ui.Model;
|
|
|
24 |
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
25 |
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
26 |
import org.springframework.web.bind.annotation.RequestMethod;
|
| 28504 |
amit.gupta |
27 |
import org.springframework.web.bind.annotation.RequestPart;
|
|
|
28 |
import org.springframework.web.multipart.MultipartFile;
|
| 28495 |
tejbeer |
29 |
|
| 28504 |
amit.gupta |
30 |
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
|
| 28495 |
tejbeer |
31 |
import com.spice.profitmandi.common.web.util.ResponseSender;
|
|
|
32 |
import com.spice.profitmandi.dao.entity.catalog.StateGstRate;
|
|
|
33 |
import com.spice.profitmandi.dao.entity.dtr.Document;
|
| 28504 |
amit.gupta |
34 |
import com.spice.profitmandi.dao.model.ContentPojo;
|
|
|
35 |
import com.spice.profitmandi.dao.model.StateGstRateModel;
|
| 28495 |
tejbeer |
36 |
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
|
|
|
37 |
import com.spice.profitmandi.web.util.MVCResponseSender;
|
|
|
38 |
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
|
|
|
39 |
@Controller
|
|
|
40 |
@Transactional(rollbackFor = Throwable.class)
|
|
|
41 |
public class TaxationController {
|
|
|
42 |
|
|
|
43 |
|
|
|
44 |
@Autowired
|
|
|
45 |
private DocumentRepository documentRepository;
|
|
|
46 |
|
|
|
47 |
|
|
|
48 |
@Autowired
|
| 28504 |
amit.gupta |
49 |
private StateGstRateRepository stateGstRateRepository;
|
| 28495 |
tejbeer |
50 |
|
|
|
51 |
@Autowired
|
|
|
52 |
private MVCResponseSender mvcResponseSender;
|
|
|
53 |
|
|
|
54 |
|
|
|
55 |
@Autowired
|
|
|
56 |
private ResponseSender<?> responseSender;
|
|
|
57 |
|
|
|
58 |
private static final Logger LOGGER = LogManager.getLogger(SellerController.class);
|
|
|
59 |
|
|
|
60 |
@RequestMapping(value = "/csvFileUploader", method = RequestMethod.POST)
|
|
|
61 |
public String getFileUploader(HttpServletRequest request, Model model ,HttpServletResponse response,
|
| 28504 |
amit.gupta |
62 |
@RequestPart MultipartFile file) throws Throwable {
|
| 28495 |
tejbeer |
63 |
|
| 28504 |
amit.gupta |
64 |
LOGGER.info("file"+file.toString());
|
|
|
65 |
String fileName= file.getName();
|
|
|
66 |
|
|
|
67 |
String fileNames = file.getOriginalFilename();
|
|
|
68 |
|
|
|
69 |
LOGGER.info("fileName"+ fileName);
|
|
|
70 |
LOGGER.info("fileNames"+ fileNames);
|
|
|
71 |
|
|
|
72 |
List<StateGstRateModel> sgtFileName = this.readFile(file);
|
|
|
73 |
|
| 28495 |
tejbeer |
74 |
LOGGER.info("sgtFileName"+sgtFileName);
|
|
|
75 |
|
| 28504 |
amit.gupta |
76 |
|
|
|
77 |
|
|
|
78 |
stateGstRateRepository.addStateGstRates(sgtFileName);
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
| 28495 |
tejbeer |
82 |
model.addAttribute("responseSTG", mvcResponseSender.createResponseString(true));
|
| 28504 |
amit.gupta |
83 |
|
| 28495 |
tejbeer |
84 |
return "response";
|
|
|
85 |
|
|
|
86 |
|
|
|
87 |
}
|
| 28504 |
amit.gupta |
88 |
|
|
|
89 |
private static StateGstRateModel createStateGstRate(CSVRecord record) {
|
| 28495 |
tejbeer |
90 |
|
| 28504 |
amit.gupta |
91 |
int itemId = Integer.parseInt(record.get(0));
|
|
|
92 |
LOGGER.info("itemId"+itemId);
|
|
|
93 |
double igstRate = Double.parseDouble(record.get(1));
|
|
|
94 |
LOGGER.info("igstRate"+igstRate);
|
|
|
95 |
// create and return book of this metadata
|
|
|
96 |
return new StateGstRateModel(itemId, igstRate);
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
|
|
|
100 |
private List<StateGstRateModel> readFile(MultipartFile file) throws Exception {
|
|
|
101 |
CSVParser parser = new CSVParser(new InputStreamReader(file.getInputStream()), CSVFormat.DEFAULT);
|
|
|
102 |
List<CSVRecord> records = parser.getRecords();
|
|
|
103 |
LOGGER.info("records"+records);
|
|
|
104 |
LOGGER.info("parser"+parser);
|
|
|
105 |
if (records.size() < 2) {
|
|
|
106 |
parser.close();
|
|
|
107 |
throw new ProfitMandiBusinessException("Uploaded File", "", "No records Found");
|
|
|
108 |
}
|
|
|
109 |
// Remove header
|
|
|
110 |
records.remove(0);
|
|
|
111 |
List<StateGstRateModel> returnList = new ArrayList<StateGstRateModel>();
|
|
|
112 |
for (CSVRecord record : records) {
|
|
|
113 |
StateGstRateModel cp = null;
|
|
|
114 |
StateGstRateModel sgr = createStateGstRate(record);
|
|
|
115 |
returnList.add(sgr);
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
LOGGER.info("records"+record.get(1));
|
|
|
119 |
}
|
|
|
120 |
parser.close();
|
|
|
121 |
return returnList;
|
|
|
122 |
}
|
|
|
123 |
|
|
|
124 |
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
|
|
|
128 |
@RequestMapping(value = "/createTaxation", method = RequestMethod.GET)
|
|
|
129 |
public String showUploaderTaxation(HttpServletRequest request, Model model) throws Exception {
|
|
|
130 |
|
|
|
131 |
|
|
|
132 |
return "taxation";
|
|
|
133 |
|
|
|
134 |
}
|
|
|
135 |
|
| 28495 |
tejbeer |
136 |
}
|