Subversion Repositories SmartDukaan

Rev

Rev 28495 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 28495 Rev 28504
Line 1... Line 1...
1
package com.spice.profitmandi.web.controller;
1
package com.spice.profitmandi.web.controller;
2
 
2
 
3
import java.io.File;
3
import java.io.File;
-
 
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;
4
import java.util.List;
9
import java.util.List;
-
 
10
import java.util.stream.Collectors;
5
 
11
 
6
import javax.servlet.http.HttpServletRequest;
12
import javax.servlet.http.HttpServletRequest;
7
import javax.servlet.http.HttpServletResponse;
13
import javax.servlet.http.HttpServletResponse;
8
 
14
 
-
 
15
import org.apache.commons.csv.CSVFormat;
-
 
16
import org.apache.commons.csv.CSVParser;
-
 
17
import org.apache.commons.csv.CSVRecord;
9
import org.apache.logging.log4j.LogManager;
18
import org.apache.logging.log4j.LogManager;
10
import org.apache.logging.log4j.Logger;
19
import org.apache.logging.log4j.Logger;
11
import org.springframework.beans.factory.annotation.Autowired;
20
import org.springframework.beans.factory.annotation.Autowired;
12
import org.springframework.stereotype.Controller;
21
import org.springframework.stereotype.Controller;
13
import org.springframework.transaction.annotation.Transactional;
22
import org.springframework.transaction.annotation.Transactional;
14
import org.springframework.ui.Model;
23
import org.springframework.ui.Model;
15
import org.springframework.web.bind.annotation.PathVariable;
24
import org.springframework.web.bind.annotation.PathVariable;
16
import org.springframework.web.bind.annotation.RequestMapping;
25
import org.springframework.web.bind.annotation.RequestMapping;
17
import org.springframework.web.bind.annotation.RequestMethod;
26
import org.springframework.web.bind.annotation.RequestMethod;
-
 
27
import org.springframework.web.bind.annotation.RequestPart;
-
 
28
import org.springframework.web.multipart.MultipartFile;
18
 
29
 
-
 
30
import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;
19
import com.spice.profitmandi.common.web.util.ResponseSender;
31
import com.spice.profitmandi.common.web.util.ResponseSender;
20
import com.spice.profitmandi.dao.entity.catalog.StateGstRate;
32
import com.spice.profitmandi.dao.entity.catalog.StateGstRate;
21
import com.spice.profitmandi.dao.entity.dtr.Document;
33
import com.spice.profitmandi.dao.entity.dtr.Document;
-
 
34
import com.spice.profitmandi.dao.model.ContentPojo;
-
 
35
import com.spice.profitmandi.dao.model.StateGstRateModel;
22
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
36
import com.spice.profitmandi.dao.repository.dtr.DocumentRepository;
23
import com.spice.profitmandi.web.util.MVCResponseSender;
37
import com.spice.profitmandi.web.util.MVCResponseSender;
24
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
38
import com.spice.profitmandi.dao.repository.catalog.StateGstRateRepository;
25
@Controller
39
@Controller
26
@Transactional(rollbackFor = Throwable.class)
40
@Transactional(rollbackFor = Throwable.class)
Line 30... Line 44...
30
	@Autowired
44
	@Autowired
31
	private DocumentRepository documentRepository;
45
	private DocumentRepository documentRepository;
32
	
46
	
33
	
47
	
34
	@Autowired
48
	@Autowired
35
	private StateGstRateRepository StateGstRateRepository;
49
	private StateGstRateRepository stateGstRateRepository;
36
	
50
	
37
	@Autowired
51
	@Autowired
38
	private MVCResponseSender mvcResponseSender;
52
	private MVCResponseSender mvcResponseSender;
39
 
53
 
40
	
54
	
Line 43... Line 57...
43
	
57
	
44
	private static final Logger LOGGER = LogManager.getLogger(SellerController.class);
58
	private static final Logger LOGGER = LogManager.getLogger(SellerController.class);
45
	
59
	
46
	@RequestMapping(value = "/csvFileUploader", method = RequestMethod.POST)
60
	@RequestMapping(value = "/csvFileUploader", method = RequestMethod.POST)
47
	public String getFileUploader(HttpServletRequest request, Model model ,HttpServletResponse response,
61
	public String getFileUploader(HttpServletRequest request, Model model ,HttpServletResponse response,
48
			@PathVariable(value = "fileName") String fileName) throws Throwable {
62
			@RequestPart MultipartFile file) throws Throwable {
-
 
63
		
-
 
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
				
49
		List<StateGstRate> sgtFileName = documentRepository.csvFileUploaderStateGstRate(fileName);
72
		List<StateGstRateModel> sgtFileName = this.readFile(file);
50
		
73
		
51
		LOGGER.info("sgtFileName"+sgtFileName);
74
		LOGGER.info("sgtFileName"+sgtFileName);
52
		
75
		
-
 
76
		
-
 
77
		
-
 
78
		stateGstRateRepository.addStateGstRates(sgtFileName);
-
 
79
		
-
 
80
		
-
 
81
		
53
		model.addAttribute("responseSTG", mvcResponseSender.createResponseString(true));
82
		model.addAttribute("responseSTG", mvcResponseSender.createResponseString(true));
-
 
83
		
54
		return "response";
84
		return "response";
55
		
85
		
56
	
86
	
57
	}
87
	}
-
 
88
	
-
 
89
	private static StateGstRateModel createStateGstRate(CSVRecord record) {
-
 
90
 
-
 
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
	}
58
 
135
 
59
}
136
}