|
@@ -1,17 +1,18 @@
|
|
|
package com.ruoyi.project.sems.controller;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
+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.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.web.bind.annotation.GetMapping;
|
|
|
-import org.springframework.web.bind.annotation.PostMapping;
|
|
|
-import org.springframework.web.bind.annotation.PutMapping;
|
|
|
-import org.springframework.web.bind.annotation.DeleteMapping;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
-import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
import com.ruoyi.framework.aspectj.lang.annotation.Log;
|
|
|
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
|
|
|
import com.ruoyi.project.sems.domain.TReportYlgd;
|
|
@@ -20,6 +21,7 @@ import com.ruoyi.framework.web.controller.BaseController;
|
|
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
|
import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
/**
|
|
|
* 压力管道年检报告Controller
|
|
@@ -106,4 +108,126 @@ public class TReportYlgdController extends BaseController {
|
|
|
public AjaxResult remove(@PathVariable Long[] ids) {
|
|
|
return toAjax(tReportYlgdService.deleteTReportYlgdByIds(ids));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入
|
|
|
+ */
|
|
|
+ @Log(title = "压力容器批量导入更新", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping("/importForUpdate")
|
|
|
+ public AjaxResult importData(@RequestParam("file") MultipartFile file) throws IOException {
|
|
|
+ //获取操作人员ID
|
|
|
+ Long userId = getUserId();
|
|
|
+ //报错行数统计
|
|
|
+ List<Integer> failRow = new ArrayList<Integer>();
|
|
|
+ Workbook workbook = ExcelUtils.getWorkBook(file);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ List<TReportYlgd> list = new ArrayList<>();
|
|
|
+
|
|
|
+ int rowNum = sheet.getPhysicalNumberOfRows();
|
|
|
+ int failNumber = 0;
|
|
|
+ for (int i = 2; i < rowNum; i++) {
|
|
|
+ try {
|
|
|
+ logger.info("读取行数:" + i);
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ int cellNum = row.getPhysicalNumberOfCells();
|
|
|
+ TReportYlgd entity = new TReportYlgd();
|
|
|
+ for (int j = 0; j < cellNum; j++) {
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ if (cell == null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ logger.info("cellValue:" + cellValue);
|
|
|
+ if (j == 0) {
|
|
|
+ //使用证
|
|
|
+ entity.setUseno(cellValue);
|
|
|
+ } else if (j == 1) {
|
|
|
+ //注册编号
|
|
|
+ entity.setRegno(cellValue);
|
|
|
+ } else if (j == 2) {
|
|
|
+ //位号
|
|
|
+ entity.setDevno(cellValue);
|
|
|
+ } else if (j == 3) {
|
|
|
+ //位号
|
|
|
+ entity.setPj1(cellValue);
|
|
|
+ } else if (j == 4) {
|
|
|
+ //位号
|
|
|
+ entity.setPj2(cellValue);
|
|
|
+ } else if (j == 5) {
|
|
|
+ //位号
|
|
|
+ entity.setPj3(cellValue);
|
|
|
+ } else if (j == 6) {
|
|
|
+ //位号
|
|
|
+ entity.setPj4(cellValue);
|
|
|
+ } else if (j == 7) {
|
|
|
+ //位号
|
|
|
+ entity.setPj5(cellValue);
|
|
|
+ } else if (j == 8) {
|
|
|
+ //位号
|
|
|
+ entity.setPj6(cellValue);
|
|
|
+ } else if (j == 9) {
|
|
|
+ //位号
|
|
|
+ entity.setPj7(cellValue);
|
|
|
+ } else if (j == 10) {
|
|
|
+ //位号
|
|
|
+ entity.setPj8(cellValue);
|
|
|
+ } else if (j == 11) {
|
|
|
+ //位号
|
|
|
+ entity.setPj9(cellValue);
|
|
|
+ } else if (j == 12) {
|
|
|
+ //位号
|
|
|
+ entity.setPj10(cellValue);
|
|
|
+ } else if (j == 13) {
|
|
|
+ //位号
|
|
|
+ entity.setPj11(cellValue);
|
|
|
+ } else if (j == 14) {
|
|
|
+ //位号
|
|
|
+ entity.setPj12(cellValue);
|
|
|
+ } else if (j == 15) {
|
|
|
+ //位号
|
|
|
+ entity.setPj13(cellValue);
|
|
|
+ } else if (j == 16) {
|
|
|
+ //位号
|
|
|
+ entity.setPj14(cellValue);
|
|
|
+ } else if (j == 17) {
|
|
|
+ //位号
|
|
|
+ entity.setPj15(cellValue);
|
|
|
+ } else if (j == 18) {
|
|
|
+ //位号
|
|
|
+ entity.setPj16(cellValue);
|
|
|
+ } else if (j == 19) {
|
|
|
+ //位号
|
|
|
+ entity.setPj17(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ entity.setCreaterCode(userId);
|
|
|
+ logger.info("entity:" + entity);
|
|
|
+ list.add(entity);
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ logger.info("e:" + JSON.toJSONString(e));
|
|
|
+ failRow.add(i + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int successNumber = 0;
|
|
|
+ int failNum = 0;
|
|
|
+ for (TReportYlgd t : list
|
|
|
+ ) {
|
|
|
+ failNum++;
|
|
|
+ try {
|
|
|
+ //根据使用证、注册编号、位号,进行数据更新
|
|
|
+ this.tReportYlgdService.updateForImport(t);
|
|
|
+ successNumber++;
|
|
|
+ } catch (Exception e) {
|
|
|
+ failNumber++;
|
|
|
+ logger.info("e:" + e);
|
|
|
+ failRow.add(failNum + 1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ logger.info("list:" + JSON.toJSONString(list));
|
|
|
+ logger.info("successNumber:" + String.valueOf(successNumber));
|
|
|
+ logger.info("failNumber:" + String.valueOf(failNumber));
|
|
|
+ logger.info("failRow:" + String.valueOf(failRow));
|
|
|
+ return AjaxResult.success(String.valueOf(successNumber), failRow);
|
|
|
+ }
|
|
|
}
|