|
@@ -0,0 +1,268 @@
|
|
1
|
+package com.cn.esermis.excelReader;
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+import com.cn.esermis.coding.PollutionGas;
|
|
5
|
+import com.cn.esermis.dpld.model.DataAllVo;
|
|
6
|
+import org.apache.poi.hssf.usermodel.HSSFWorkbook;
|
|
7
|
+import org.apache.poi.ss.usermodel.Cell;
|
|
8
|
+import org.apache.poi.ss.usermodel.Row;
|
|
9
|
+import org.apache.poi.ss.usermodel.Sheet;
|
|
10
|
+import org.apache.poi.ss.usermodel.Workbook;
|
|
11
|
+
|
|
12
|
+import java.io.File;
|
|
13
|
+import java.io.FileInputStream;
|
|
14
|
+import java.io.IOException;
|
|
15
|
+import java.util.*;
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+public class ExcelReader {
|
|
19
|
+
|
|
20
|
+ public List<Map<Integer,Object>> readExcelFile(String filePath) throws IOException {
|
|
21
|
+ List<Map<Integer,Object>> data = new LinkedList<>();
|
|
22
|
+
|
|
23
|
+ FileInputStream fis = new FileInputStream(new File(filePath));
|
|
24
|
+ Workbook workbook = new HSSFWorkbook(fis);
|
|
25
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
26
|
+
|
|
27
|
+ Iterator<Row> rowIterator = sheet.iterator();
|
|
28
|
+ while (rowIterator.hasNext()) {
|
|
29
|
+ Row row = rowIterator.next();
|
|
30
|
+ if(row.getRowNum() == 0){
|
|
31
|
+ continue;
|
|
32
|
+ }
|
|
33
|
+// List<String> rowData = new ArrayList<>();
|
|
34
|
+ Map<Integer,Object> map = new LinkedHashMap<>();
|
|
35
|
+ Iterator<Cell> cellIterator = row.cellIterator();
|
|
36
|
+
|
|
37
|
+ while (cellIterator.hasNext()) {
|
|
38
|
+ Cell cell = cellIterator.next();
|
|
39
|
+ // 行标
|
|
40
|
+ int columnIndex = cell.getColumnIndex();
|
|
41
|
+ switch (cell.getCellType()) {
|
|
42
|
+ case STRING:
|
|
43
|
+ map.put(columnIndex,cell.getStringCellValue());
|
|
44
|
+ break;
|
|
45
|
+ case NUMERIC:
|
|
46
|
+ map.put(columnIndex,String.valueOf(cell.getNumericCellValue()));
|
|
47
|
+ break;
|
|
48
|
+ case BOOLEAN:
|
|
49
|
+ map.put(columnIndex,String.valueOf(cell.getBooleanCellValue()));
|
|
50
|
+ break;
|
|
51
|
+ default:
|
|
52
|
+ map.put(columnIndex,"");
|
|
53
|
+ break;
|
|
54
|
+ }
|
|
55
|
+ }
|
|
56
|
+ data.add(map);
|
|
57
|
+ }
|
|
58
|
+
|
|
59
|
+ workbook.close();
|
|
60
|
+ fis.close();
|
|
61
|
+
|
|
62
|
+ return data;
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ public List<DataAllVo> getData() {
|
|
66
|
+ String filePath = "E:\\Desktop\\排口信息.xls";
|
|
67
|
+ List<DataAllVo> dataAcquisitionInstrumentret = new ArrayList<>();
|
|
68
|
+ ExcelReader excelReader = new ExcelReader();
|
|
69
|
+ try {
|
|
70
|
+ List<Map<Integer, Object>> maps = excelReader.readExcelFile(filePath);
|
|
71
|
+ List<DataAllVo> dataAcquisitionInstruments = new ArrayList<>();
|
|
72
|
+
|
|
73
|
+ maps.forEach(x->{
|
|
74
|
+ DataAllVo instrumentVo = new DataAllVo();
|
|
75
|
+// instrumentVo.setAnalyticalInstruments();
|
|
76
|
+// instrumentVo.setPageNum();
|
|
77
|
+// instrumentVo.setPageSize();
|
|
78
|
+// instrumentVo.setCompanyName();
|
|
79
|
+// instrumentVo.setDepartmentName();
|
|
80
|
+// instrumentVo.setId();
|
|
81
|
+ instrumentVo.setOutletName(String.valueOf(x.get(6)!=null?x.get(6):""));
|
|
82
|
+ instrumentVo.setOutletCode(String.valueOf(x.get(6)!=null?x.get(6):""));
|
|
83
|
+ instrumentVo.setType(String.valueOf(x.get(6)!=null?x.get(6):"").equals("废气")?1:2);
|
|
84
|
+// instrumentVo.setUseData();
|
|
85
|
+ if (x.get(14)!=null
|
|
86
|
+ && !String.valueOf(x.get(14)).equals("是")){
|
|
87
|
+ instrumentVo.setCompleteFilings(1);
|
|
88
|
+ }
|
|
89
|
+// instrumentVo.setCompleteFilingsTime();
|
|
90
|
+ instrumentVo.setCollectionName(x.get(18)!=null? String.valueOf(x.get(18)) :"");
|
|
91
|
+ instrumentVo.setCollectionBrand(x.get(18)!=null? String.valueOf(x.get(18)) :"");
|
|
92
|
+ instrumentVo.setCollectionModel(x.get(19)!=null? String.valueOf(x.get(19)) :"");
|
|
93
|
+ instrumentVo.setMnCode(x.get(17)!=null? String.valueOf(x.get(17)) :"");
|
|
94
|
+// if ()
|
|
95
|
+
|
|
96
|
+// instrumentVo.setDepartmentCode();
|
|
97
|
+ instrumentVo.setHaveExhaust(String.valueOf(x.get(9)).equals("是")?1:0);
|
|
98
|
+ instrumentVo.setExhaustTemperature(x.get(11)!=null? String.valueOf(x.get(11)) :"");
|
|
99
|
+ instrumentVo.setExhaustHeight(x.get(10)!=null? String.valueOf(x.get(10)) :"");
|
|
100
|
+ instrumentVo.setExhaustDiameter(x.get(12)!=null? String.valueOf(x.get(12)) :"");
|
|
101
|
+ if (x.get(2)==null) {
|
|
102
|
+ DataAllVo instrumentVo1 = dataAcquisitionInstruments.get(0);
|
|
103
|
+ instrumentVo.setIndustryCategory(instrumentVo1.getIndustryCategory());
|
|
104
|
+ instrumentVo.setLicenseNumber(instrumentVo1.getLicenseNumber());
|
|
105
|
+ instrumentVo.setLicenseData(instrumentVo1.getLicenseData());
|
|
106
|
+ instrumentVo.setCompanyCode(instrumentVo1.getCompanyCode());
|
|
107
|
+ }else if(x.get(2)!=null && String.valueOf(x.get(2)).equals("") ){
|
|
108
|
+ DataAllVo instrumentVo1 = dataAcquisitionInstruments.get(0);
|
|
109
|
+ instrumentVo.setIndustryCategory(instrumentVo1.getIndustryCategory());
|
|
110
|
+ instrumentVo.setLicenseNumber(instrumentVo1.getLicenseNumber());
|
|
111
|
+ instrumentVo.setLicenseData(instrumentVo1.getLicenseData());
|
|
112
|
+ instrumentVo.setCompanyCode(instrumentVo1.getCompanyCode());
|
|
113
|
+ }
|
|
114
|
+ else{
|
|
115
|
+ dataAcquisitionInstrumentret.addAll(dataAcquisitionInstruments);
|
|
116
|
+ dataAcquisitionInstruments.clear();
|
|
117
|
+ instrumentVo.setIndustryCategory(x.get(2)!=null? String.valueOf(x.get(2)) :"");
|
|
118
|
+ instrumentVo.setLicenseNumber(x.get(3)!=null? String.valueOf(x.get(3)) :"");
|
|
119
|
+ instrumentVo.setLicenseData(x.get(4)!=null? String.valueOf(x.get(4)) :"");
|
|
120
|
+ instrumentVo.setCompanyCode(x.get(1)!=null? String.valueOf(x.get(1)) :"");
|
|
121
|
+ }
|
|
122
|
+ // 分析仪
|
|
123
|
+ instrumentVo.setBrand(x.get(20)!=null? String.valueOf(x.get(20)) :"");
|
|
124
|
+ instrumentVo.setModel(x.get(21)!=null? String.valueOf(x.get(21)) :"");
|
|
125
|
+ instrumentVo.setName(x.get(20)!=null? String.valueOf(x.get(20)) :"");
|
|
126
|
+// instrumentVo.setFactorInfor(x.get(22)!=null? String.valueOf(x.get(22)) :"");
|
|
127
|
+// instrumentVo.setRange(x.get(23)!=null? String.valueOf(x.get(23)) :"");
|
|
128
|
+// instrumentVo.setDataAcquisitionInstrumentId(x.get(24)!=null? String.valueOf(x.get(24)) :"");
|
|
129
|
+ instrumentVo.setReferenceOxygenContent(x.get(22)!=null? String.valueOf(x.get(22)) :"");
|
|
130
|
+ instrumentVo.setVelocityFieldCoefficient(x.get(23)!=null? String.valueOf(x.get(23)) :"");
|
|
131
|
+ instrumentVo.setPitotTubeCoefficient(x.get(24)!=null? String.valueOf(x.get(24)) :"");
|
|
132
|
+ instrumentVo.setKvalue(x.get(26)!=null? String.valueOf(x.get(26)) :"");
|
|
133
|
+ instrumentVo.setFlueArea(x.get(25)!=null? String.valueOf(x.get(25)) :"");
|
|
134
|
+ instrumentVo.setDilutionRatio(x.get(27)!=null? String.valueOf(x.get(27)) :"");
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+ instrumentVo.setHoursAvg(x.get(31)!=null? String.valueOf(x.get(31)) :"");
|
|
139
|
+ instrumentVo.setHoursUnit(x.get(32)!=null? String.valueOf(x.get(32)) :null);
|
|
140
|
+ instrumentVo.setMonthlyEmissions(x.get(33)!=null? String.valueOf(x.get(33)) :"");
|
|
141
|
+ instrumentVo.setMonthlyEmissionsUnit(x.get(34)!=null? String.valueOf(x.get(34)) :null);
|
|
142
|
+ instrumentVo.setYearEmissions(x.get(35)!=null? String.valueOf(x.get(35)) :"");
|
|
143
|
+ instrumentVo.setYearEmissionsUnit(x.get(36)!=null? String.valueOf(x.get(36)) :null);
|
|
144
|
+ instrumentVo.setRangeStr(x.get(37)!=null? String.valueOf(x.get(37)) :"");
|
|
145
|
+ instrumentVo.setRangeUnit(x.get(38)!=null? String.valueOf(x.get(38)) :"");
|
|
146
|
+ // 检测因子信息
|
|
147
|
+ instrumentVo.setFactorName(x.get(30)!=null? String.valueOf(x.get(30)) :"");
|
|
148
|
+
|
|
149
|
+ PollutionGas[] values = PollutionGas.values();
|
|
150
|
+ for (PollutionGas value : values) {
|
|
151
|
+ if (value.mean().equals(instrumentVo.getFactorName())){
|
|
152
|
+ instrumentVo.setFactor(value.code());
|
|
153
|
+ }
|
|
154
|
+ }
|
|
155
|
+
|
|
156
|
+ dataAcquisitionInstruments.add(instrumentVo);
|
|
157
|
+
|
|
158
|
+ });
|
|
159
|
+// System.out.println(dataAcquisitionInstrumentret);
|
|
160
|
+ } catch (IOException e) {
|
|
161
|
+ e.printStackTrace();
|
|
162
|
+ }
|
|
163
|
+ return dataAcquisitionInstrumentret;
|
|
164
|
+ }
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+ public static void main(String[] args) {
|
|
169
|
+ String filePath = "E:\\Desktop\\排口信息.xls";
|
|
170
|
+
|
|
171
|
+ ExcelReader excelReader = new ExcelReader();
|
|
172
|
+ try {
|
|
173
|
+ List<Map<Integer, Object>> maps = excelReader.readExcelFile(filePath);
|
|
174
|
+ List<DataAllVo> dataAcquisitionInstruments = new ArrayList<>();
|
|
175
|
+ List<DataAllVo> dataAcquisitionInstrumentret = new ArrayList<>();
|
|
176
|
+ maps.forEach(x->{
|
|
177
|
+ DataAllVo instrumentVo = new DataAllVo();
|
|
178
|
+// instrumentVo.setAnalyticalInstruments();
|
|
179
|
+// instrumentVo.setPageNum();
|
|
180
|
+// instrumentVo.setPageSize();
|
|
181
|
+// instrumentVo.setCompanyName();
|
|
182
|
+// instrumentVo.setDepartmentName();
|
|
183
|
+// instrumentVo.setId();
|
|
184
|
+ instrumentVo.setOutletName(String.valueOf(x.get(6)!=null?x.get(6):""));
|
|
185
|
+ instrumentVo.setOutletCode(String.valueOf(x.get(6)!=null?x.get(6):""));
|
|
186
|
+ instrumentVo.setType(String.valueOf(x.get(6)!=null?x.get(6):"").equals("废气")?1:2);
|
|
187
|
+// instrumentVo.setUseData();
|
|
188
|
+ if (x.get(14)!=null
|
|
189
|
+ && !String.valueOf(x.get(14)).equals("是")){
|
|
190
|
+ instrumentVo.setCompleteFilings(1);
|
|
191
|
+ }
|
|
192
|
+// instrumentVo.setCompleteFilingsTime();
|
|
193
|
+ instrumentVo.setCollectionName(x.get(18)!=null? String.valueOf(x.get(18)) :"");
|
|
194
|
+ instrumentVo.setCollectionBrand(x.get(18)!=null? String.valueOf(x.get(18)) :"");
|
|
195
|
+ instrumentVo.setCollectionModel(x.get(19)!=null? String.valueOf(x.get(19)) :"");
|
|
196
|
+ instrumentVo.setMnCode(x.get(17)!=null? String.valueOf(x.get(17)) :"");
|
|
197
|
+// if ()
|
|
198
|
+
|
|
199
|
+// instrumentVo.setDepartmentCode();
|
|
200
|
+ instrumentVo.setHaveExhaust(String.valueOf(x.get(9)).equals("是")?1:0);
|
|
201
|
+ instrumentVo.setExhaustTemperature(x.get(11)!=null? String.valueOf(x.get(11)) :"");
|
|
202
|
+ instrumentVo.setExhaustHeight(x.get(10)!=null? String.valueOf(x.get(10)) :"");
|
|
203
|
+ instrumentVo.setExhaustDiameter(x.get(12)!=null? String.valueOf(x.get(12)) :"");
|
|
204
|
+ if (x.get(2)==null) {
|
|
205
|
+ DataAllVo instrumentVo1 = dataAcquisitionInstruments.get(0);
|
|
206
|
+ instrumentVo.setIndustryCategory(instrumentVo1.getIndustryCategory());
|
|
207
|
+ instrumentVo.setLicenseNumber(instrumentVo1.getLicenseNumber());
|
|
208
|
+ instrumentVo.setLicenseData(instrumentVo1.getLicenseData());
|
|
209
|
+ instrumentVo.setCompanyCode(instrumentVo1.getCompanyCode());
|
|
210
|
+ }else if(x.get(2)!=null && String.valueOf(x.get(2)).equals("") ){
|
|
211
|
+ DataAllVo instrumentVo1 = dataAcquisitionInstruments.get(0);
|
|
212
|
+ instrumentVo.setIndustryCategory(instrumentVo1.getIndustryCategory());
|
|
213
|
+ instrumentVo.setLicenseNumber(instrumentVo1.getLicenseNumber());
|
|
214
|
+ instrumentVo.setLicenseData(instrumentVo1.getLicenseData());
|
|
215
|
+ instrumentVo.setCompanyCode(instrumentVo1.getCompanyCode());
|
|
216
|
+ }
|
|
217
|
+ else{
|
|
218
|
+ dataAcquisitionInstrumentret.addAll(dataAcquisitionInstruments);
|
|
219
|
+ dataAcquisitionInstruments.clear();
|
|
220
|
+ instrumentVo.setIndustryCategory(x.get(2)!=null? String.valueOf(x.get(2)) :"");
|
|
221
|
+ instrumentVo.setLicenseNumber(x.get(3)!=null? String.valueOf(x.get(3)) :"");
|
|
222
|
+ instrumentVo.setLicenseData(x.get(4)!=null? String.valueOf(x.get(4)) :"");
|
|
223
|
+ instrumentVo.setCompanyCode(x.get(1)!=null? String.valueOf(x.get(1)) :"");
|
|
224
|
+ }
|
|
225
|
+ // 分析仪
|
|
226
|
+ instrumentVo.setBrand(x.get(20)!=null? String.valueOf(x.get(20)) :"");
|
|
227
|
+ instrumentVo.setModel(x.get(21)!=null? String.valueOf(x.get(21)) :"");
|
|
228
|
+ instrumentVo.setName(x.get(20)!=null? String.valueOf(x.get(20)) :"");
|
|
229
|
+// instrumentVo.setFactorInfor(x.get(22)!=null? String.valueOf(x.get(22)) :"");
|
|
230
|
+// instrumentVo.setRange(x.get(23)!=null? String.valueOf(x.get(23)) :"");
|
|
231
|
+// instrumentVo.setDataAcquisitionInstrumentId(x.get(24)!=null? String.valueOf(x.get(24)) :"");
|
|
232
|
+ instrumentVo.setReferenceOxygenContent(x.get(22)!=null? String.valueOf(x.get(22)) :"");
|
|
233
|
+ instrumentVo.setVelocityFieldCoefficient(x.get(23)!=null? String.valueOf(x.get(23)) :"");
|
|
234
|
+ instrumentVo.setPitotTubeCoefficient(x.get(24)!=null? String.valueOf(x.get(24)) :"");
|
|
235
|
+ instrumentVo.setKvalue(x.get(26)!=null? String.valueOf(x.get(26)) :"");
|
|
236
|
+ instrumentVo.setFlueArea(x.get(25)!=null? String.valueOf(x.get(25)) :"");
|
|
237
|
+ instrumentVo.setDilutionRatio(x.get(27)!=null? String.valueOf(x.get(27)) :"");
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
|
|
241
|
+ instrumentVo.setHoursAvg(x.get(31)!=null? String.valueOf(x.get(31)) :"");
|
|
242
|
+ instrumentVo.setHoursUnit(x.get(32)!=null? String.valueOf(x.get(32)) :null);
|
|
243
|
+ instrumentVo.setMonthlyEmissions(x.get(33)!=null? String.valueOf(x.get(33)) :"");
|
|
244
|
+ instrumentVo.setMonthlyEmissionsUnit(x.get(34)!=null? String.valueOf(x.get(34)) :null);
|
|
245
|
+ instrumentVo.setYearEmissions(x.get(35)!=null? String.valueOf(x.get(35)) :"");
|
|
246
|
+ instrumentVo.setYearEmissionsUnit(x.get(36)!=null? String.valueOf(x.get(36)) :null);
|
|
247
|
+ instrumentVo.setRangeStr(x.get(37)!=null? String.valueOf(x.get(37)) :"");
|
|
248
|
+ instrumentVo.setRangeUnit(x.get(38)!=null? String.valueOf(x.get(38)) :"");
|
|
249
|
+ // 检测因子信息
|
|
250
|
+ instrumentVo.setFactorName(x.get(30)!=null? String.valueOf(x.get(30)) :"");
|
|
251
|
+
|
|
252
|
+ PollutionGas[] values = PollutionGas.values();
|
|
253
|
+ for (PollutionGas value : values) {
|
|
254
|
+ if (value.mean().equals(instrumentVo.getFactorName())){
|
|
255
|
+ instrumentVo.setFactor(value.code());
|
|
256
|
+ }
|
|
257
|
+ }
|
|
258
|
+
|
|
259
|
+ dataAcquisitionInstruments.add(instrumentVo);
|
|
260
|
+
|
|
261
|
+ });
|
|
262
|
+ System.out.println(dataAcquisitionInstrumentret);
|
|
263
|
+ } catch (IOException e) {
|
|
264
|
+ e.printStackTrace();
|
|
265
|
+ }
|
|
266
|
+
|
|
267
|
+ }
|
|
268
|
+}
|