|
@@ -1,5 +1,6 @@
|
|
|
package com.ruoyi.project.pssr.controller;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
import com.ruoyi.common.utils.DateUtils;
|
|
|
import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
|
@@ -9,24 +10,28 @@ import com.ruoyi.framework.web.controller.BaseController;
|
|
|
import com.ruoyi.framework.web.domain.AjaxResult;
|
|
|
import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
import com.ruoyi.project.pssr.domain.TPssrSafetyBreath;
|
|
|
+import com.ruoyi.project.pssr.domain.TPssrSafetyBreath;
|
|
|
import com.ruoyi.project.pssr.service.ITPssrFileService;
|
|
|
import com.ruoyi.project.pssr.service.ITPssrSafetyBreathService;
|
|
|
import com.ruoyi.project.pssr.service.ITPssrTurndownService;
|
|
|
+import com.ruoyi.project.system.domain.SysDept;
|
|
|
import com.ruoyi.project.system.domain.SysUser;
|
|
|
+import com.ruoyi.project.system.service.ISysDeptService;
|
|
|
import com.ruoyi.project.system.service.ISysUserService;
|
|
|
-import org.apache.poi.ss.usermodel.Cell;
|
|
|
-import org.apache.poi.ss.usermodel.CellStyle;
|
|
|
-import org.apache.poi.ss.usermodel.Row;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
|
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.security.access.prepost.PreAuthorize;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
import java.io.FileOutputStream;
|
|
|
import java.io.IOException;
|
|
|
import java.io.InputStream;
|
|
|
import java.io.OutputStream;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
|
|
|
/**
|
|
@@ -50,6 +55,101 @@ public class TPssrSafetyBreathController extends BaseController {
|
|
|
private ISysUserService sysUserService;
|
|
|
private String forShort = "aqss-bh";
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService iSysDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('pssr:safetyBreath:add')")
|
|
|
+ @PostMapping("/importData")
|
|
|
+ public AjaxResult importInterlockData(MultipartFile file, Long subId) throws IOException
|
|
|
+ {
|
|
|
+ //获取操作人员ID
|
|
|
+ Long userId = getUserId();
|
|
|
+ //报错行数统计
|
|
|
+ List<Integer> failRow =new ArrayList<Integer>();
|
|
|
+ Workbook workbook = ExcelUtils.getWorkBook(file);
|
|
|
+ Sheet sheet = workbook.getSheetAt(0);
|
|
|
+ List<TPssrSafetyBreath> list = new ArrayList<TPssrSafetyBreath>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ //部门查询
|
|
|
+ List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
|
|
|
+ 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();
|
|
|
+ TPssrSafetyBreath entity = new TPssrSafetyBreath();
|
|
|
+ entity.setDeptId(userService.selectUserById(getUserId()).getDeptId());
|
|
|
+ entity.setSubId(subId);
|
|
|
+ entity.setApproveStatus(0L);
|
|
|
+ for (int j = 0; j < cellNum; j++) {
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ logger.info("cellValue:" + cellValue);
|
|
|
+ if (j == 0) {
|
|
|
+ entity.setUnit(cellValue);
|
|
|
+ } else if (j == 1) {
|
|
|
+ entity.setPidNo(cellValue);
|
|
|
+ } else if (j == 2) {
|
|
|
+ entity.setDevNo(cellValue);
|
|
|
+ } else if (j == 3) {
|
|
|
+ entity.setVerify(cellValue);
|
|
|
+ } else if (j == 4) {
|
|
|
+ entity.setInValidity(cellValue);
|
|
|
+ } else if (j == 5) {
|
|
|
+ entity.setInstallLocation(cellValue);
|
|
|
+ } else if (j == 6) {
|
|
|
+ entity.setInstallAccuracy(cellValue);
|
|
|
+ } else if (j == 7) {
|
|
|
+ entity.setPutUse(cellValue);
|
|
|
+ } else if (j == 8) {
|
|
|
+ entity.setSetPressure(cellValue);
|
|
|
+ } else if (j == 9) {
|
|
|
+ entity.setUniformPressure(cellValue);
|
|
|
+ } else if (j == 10) {
|
|
|
+ if (cellValue.length() > 3) {
|
|
|
+ entity.setConfirmationTime(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
|
|
|
+ }
|
|
|
+ } else if (j == 11) {
|
|
|
+ entity.setRemarks(cellValue);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ entity.setCreaterCode(userId.toString());
|
|
|
+ logger.info("entity:" + entity);
|
|
|
+ list.add(entity);
|
|
|
+ }catch (Exception e){
|
|
|
+ failNumber++;
|
|
|
+ failRow.add(i+1);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ int successNumber = 0;
|
|
|
+ int failNum = 0;
|
|
|
+ for (TPssrSafetyBreath t : list
|
|
|
+ ) {
|
|
|
+ failNum++;
|
|
|
+ try {
|
|
|
+ tPssrSafetyBreathService.insertTPssrSafetyBreath(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));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询安全设施-呼吸阀列表
|
|
|
*/
|