BasicDataController.java
15.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
package com.lhcredit.project.model.basicData.controller;
import com.lhcredit.common.utils.StringUtils;
import com.lhcredit.common.utils.file.FileUploadUtils;
import com.lhcredit.common.utils.poi.ExcelUtil;
import com.lhcredit.common.utils.security.ShiroUtils;
import com.lhcredit.framework.aspectj.lang.annotation.Log;
import com.lhcredit.framework.aspectj.lang.enums.BusinessType;
import com.lhcredit.framework.config.CommonConfig;
import com.lhcredit.framework.web.controller.BaseController;
import com.lhcredit.framework.web.domain.AjaxResult;
import com.lhcredit.framework.web.page.TableDataInfo;
import com.lhcredit.project.model.basicData.domain.BasicData;
import com.lhcredit.project.model.basicData.service.IBasicDataService;
import org.apache.poi.openxml4j.exceptions.InvalidFormatException;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
* 静态池信息操作处理
*
* @author lhcredit
* @date 2019-10-14
*/
@Controller
@RequestMapping("/model/basicData")
public class BasicDataController extends BaseController {
private String prefix = "model/basicData";
@Autowired
private IBasicDataService basicDataService;
@RequiresPermissions("model:basicData:view")
@GetMapping()
public String basicData() {
return prefix + "/basicData";
}
/**
* 查询静态池列表
*/
@RequiresPermissions("model:basicData:list")
@PostMapping("/list")
@ResponseBody
public TableDataInfo list(BasicData basicData) {
startPage();
List<BasicData> list = basicDataService.selectBasicDataList(basicData);
return getDataTable(list);
}
/**
* 导出静态池列表
*/
@RequiresPermissions("model:basicData:export")
@Log(title = "静态池", businessType = BusinessType.EXPORT)
@PostMapping("/export")
@ResponseBody
public AjaxResult export(BasicData basicData) {
List<BasicData> list = basicDataService.selectBasicDataList(basicData);
ExcelUtil<BasicData> util = new ExcelUtil<BasicData>(BasicData. class);
return util.exportExcel(list, "basicData");
}
/**
* 新增静态池
*/
@GetMapping("/add")
public String add() {
return prefix + "/add";
}
/**
* 新增保存静态池
*/
@RequiresPermissions("model:basicData:add")
@Log(title = "静态池", businessType = BusinessType.INSERT)
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(BasicData basicData) {
basicData.setCreateBy(ShiroUtils.getLoginName());
basicData.setCreateTime(new Date());
basicData.setUpdateBy(ShiroUtils.getLoginName());
basicData.setUpdateTime(new Date());
return toAjax(basicDataService.insertBasicData(basicData));
}
/**
* 修改静态池
*/
@GetMapping("/edit/{id}")
public String edit(@PathVariable("id") Long id, ModelMap mmap) {
BasicData basicData =basicDataService.selectBasicDataById(id);
mmap.put("basicData", basicData);
return prefix + "/edit";
}
/**
* 修改保存静态池
*/
@RequiresPermissions("model:basicData:edit")
@Log(title = "静态池", businessType = BusinessType.UPDATE)
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(BasicData basicData) {
basicData.setUpdateBy(ShiroUtils.getLoginName());
basicData.setUpdateTime(new Date());
return toAjax(basicDataService.updateBasicData(basicData));
}
/**
* 删除静态池
*/
@RequiresPermissions("model:basicData:remove")
@Log(title = "静态池", businessType = BusinessType.DELETE)
@PostMapping("/remove")
@ResponseBody
public AjaxResult remove(String ids) {
return toAjax(basicDataService.deleteBasicDataByIds(ids));
}
public AjaxResult excel(MultipartFile file) {
try {
//先上传fastdfs
String filePath = CommonConfig.getUploadPath();
// 上传并返回新文件名称
String fileName = FileUploadUtils.upload(filePath, file);
//读取上传的文件
File newfile = new File(filePath + fileName);
// File newfile = new File("C:/Users/Administrator/Desktop/财信/test1.xlsx");
Workbook book = null;
book = new XSSFWorkbook(newfile);
Sheet sheet1 = book.getSheetAt(0);
int rownum1 = sheet1.getLastRowNum();
List<BasicData> list = new ArrayList<BasicData>();
Date dkffsj = null;
//期次序号
int qcnum = 1;
for (int a = 1; a <= rownum1; a++) {
BasicData basicData = new BasicData();
Row row = sheet1.getRow(a);
if (null != row) {
if (null == row.getCell(0)) {
continue;
}
basicData.setSign(newfile.getName());
if (row.getCell(0) != null && !row.getCell(0).equals("")) {
basicData.setCp(String.valueOf(row.getCell(0).getNumericCellValue()));
}
//对期次为空的数据补全期次字段
if (null != getCellValue(row.getCell(1))) {
//每当新期次开始录入,重置期次序号
qcnum = 1;
dkffsj = getCellValue(row.getCell(1));
basicData.setDkffsj(dkffsj);
basicData.setQcnum(qcnum);
} else {
qcnum += 1;
basicData.setDkffsj(dkffsj);
basicData.setQcnum(qcnum);
}
basicData.setBgyf(getCellValue(row.getCell(2)));
if (null == basicData.getBgyf()) {
continue;
}
if (row.getCell(3) != null && !row.getCell(3).equals("")) {
if (0 < row.getCell(3).getNumericCellValue()) {
basicData.setXzdk(new BigDecimal(row.getCell(3).getNumericCellValue()));
}
}
if (row.getCell(4) != null && !row.getCell(4).equals("")) {
basicData.setXzdkdybs(new BigDecimal(row.getCell(4).getNumericCellValue()));
}
if (row.getCell(5) != null && !row.getCell(5).equals("")) {
basicData.setXzdkdykhs(new BigDecimal(row.getCell(5).getNumericCellValue()));
}
if (row.getCell(6) != null && !row.getCell(6).equals("")) {
basicData.setDysdbj(new BigDecimal(row.getCell(6).getNumericCellValue()));
}
if (row.getCell(7) != null && !row.getCell(7).equals("")) {
basicData.setDysdlx(new BigDecimal(row.getCell(7).getNumericCellValue()));
}
if (row.getCell(8) != null && !row.getCell(8).equals("")) {
basicData.setYmbjye(new BigDecimal(row.getCell(8).getNumericCellValue()));
}
if (row.getCell(9) != null && !row.getCell(9).equals("")) {
basicData.setSrbjce(new BigDecimal(row.getCell(9).getNumericCellValue()));
}
if (row.getCell(10) != null && !row.getCell(10).equals("")) {
basicData.setSrlxce(new BigDecimal(row.getCell(10).getNumericCellValue()));
}
if (row.getCell(11) != null && !row.getCell(11).equals("")) {
basicData.setBjyece(new BigDecimal(row.getCell(11).getNumericCellValue()));
}
if (row.getCell(12) != null && !row.getCell(12).equals("")) {
basicData.setBj(new BigDecimal(row.getCell(12).getNumericCellValue()));
}
if (row.getCell(13) != null && !row.getCell(13).equals("")) {
basicData.setZclx(new BigDecimal(row.getCell(13).getNumericCellValue()));
}
if (row.getCell(14) != null && !row.getCell(14).equals("")) {
basicData.setZcbj(new BigDecimal(row.getCell(14).getNumericCellValue()));
}
if (row.getCell(15) != null && !row.getCell(15).equals("")) {
basicData.setZcbx(new BigDecimal(row.getCell(15).getNumericCellValue()));
}
if (row.getCell(16) != null && !row.getCell(16).equals("")) {
basicData.setDyhxbj(new BigDecimal(row.getCell(16).getNumericCellValue()));
}
if (row.getCell(17) != null && !row.getCell(17).equals("")) {
basicData.setTqbjh(new BigDecimal(row.getCell(17).getNumericCellValue()));
}
if (row.getCell(18) != null && !row.getCell(18).equals("")) {
basicData.setTq1(new BigDecimal(row.getCell(18).getNumericCellValue()));
}
if (row.getCell(19) != null && !row.getCell(19).equals("")) {
basicData.setTq2(new BigDecimal(row.getCell(19).getNumericCellValue()));
}
if (row.getCell(20) != null && !row.getCell(20).equals("")) {
basicData.setTq3(new BigDecimal(row.getCell(20).getNumericCellValue()));
}
if (row.getCell(21) != null && !row.getCell(21).equals("")) {
basicData.setTq4(new BigDecimal(row.getCell(21).getNumericCellValue()));
}
if (row.getCell(22) != null && !row.getCell(22).equals("")) {
basicData.setTq5(new BigDecimal(row.getCell(22).getNumericCellValue()));
}
if (row.getCell(23) != null && !row.getCell(23).equals("")) {
basicData.setTq6(new BigDecimal(row.getCell(23).getNumericCellValue()));
}
if (row.getCell(24) != null && !row.getCell(24).equals("")) {
basicData.setTq7(new BigDecimal(row.getCell(24).getNumericCellValue()));
}
if (row.getCell(25) != null && !row.getCell(25).equals("")) {
basicData.setHsbjh(new BigDecimal(row.getCell(25).getNumericCellValue()));
}
if (row.getCell(26) != null && !row.getCell(26).equals("")) {
basicData.setBjtq1(new BigDecimal(row.getCell(26).getNumericCellValue()));
}
if (row.getCell(27) != null && !row.getCell(27).equals("")) {
basicData.setBjtq2(new BigDecimal(row.getCell(27).getNumericCellValue()));
}
if (row.getCell(28) != null && !row.getCell(28).equals("")) {
basicData.setBjtq3(new BigDecimal(row.getCell(28).getNumericCellValue()));
}
if (row.getCell(29) != null && !row.getCell(29).equals("")) {
basicData.setBjtq4(new BigDecimal(row.getCell(29).getNumericCellValue()));
}
if (row.getCell(30) != null && !row.getCell(30).equals("")) {
basicData.setBjtq5(new BigDecimal(row.getCell(30).getNumericCellValue()));
}
if (row.getCell(31) != null && !row.getCell(31).equals("")) {
basicData.setBjtq6(new BigDecimal(row.getCell(31).getNumericCellValue()));
}
if (row.getCell(32) != null && !row.getCell(32).equals("")) {
basicData.setBjtq7(new BigDecimal(row.getCell(32).getNumericCellValue()));
}
if (row.getCell(33) != null && !row.getCell(33).equals("")) {
basicData.setHsjeh(new BigDecimal(row.getCell(33).getNumericCellValue()));
}
if (row.getCell(34) != null && !row.getCell(34).equals("")) {
basicData.setJetq1(new BigDecimal(row.getCell(34).getNumericCellValue()));
}
if (row.getCell(35) != null && !row.getCell(35).equals("")) {
basicData.setJetq2(new BigDecimal(row.getCell(35).getNumericCellValue()));
}
if (row.getCell(36) != null && !row.getCell(36).equals("")) {
basicData.setJetq3(new BigDecimal(row.getCell(36).getNumericCellValue()));
}
if (row.getCell(37) != null && !row.getCell(37).equals("")) {
basicData.setJetq4(new BigDecimal(row.getCell(37).getNumericCellValue()));
}
if (row.getCell(38) != null && !row.getCell(38).equals("")) {
basicData.setJetq5(new BigDecimal(row.getCell(38).getNumericCellValue()));
}
if (row.getCell(39) != null && !row.getCell(39).equals("")) {
basicData.setJetq6(new BigDecimal(row.getCell(39).getNumericCellValue()));
}
if (row.getCell(40) != null && !row.getCell(40).equals("")) {
basicData.setJetq7(new BigDecimal(row.getCell(40).getNumericCellValue()));
}
basicData.setDelFlag("0");
list.add(basicData);
}
if (list.size() >= 100) {
basicDataService.insertData(list);
list.clear();
}
}
if (list.size() > 0) {
basicDataService.insertData(list);
// }
BasicData st = new BasicData();
st.setSign("test1.xlsx");
st.setQcCount(37);
st.setDelFlag("0");
basicDataService.getLjwyl(st);
}
} catch(IOException e){
e.printStackTrace();
return toAjax("解析失败,原因为" + e.getMessage());
} catch(InvalidFormatException e){
e.printStackTrace();
return toAjax("解析失败,原因为" + e.getMessage());
}
return toAjax("解析成功");
}
private Date getCellValue(Cell cell) {
Date cellValue = null;
try {
if (null == cell) {
return null;
}
switch (cell.getCellType()) {
case NUMERIC:
cellValue = cell.getDateCellValue();
break;
case STRING:
if (StringUtils.isEmpty(cell.getStringCellValue())) {
return null;
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
cellValue = sdf.parse(cell.getStringCellValue());
break;
}
}catch (Exception e){
e.printStackTrace();
}finally {
return cellValue;
}
}
}