|
@@ -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;
|
|
@@ -10,30 +11,33 @@ import com.ruoyi.framework.web.domain.AjaxResult;
|
|
|
import com.ruoyi.framework.web.page.TableDataInfo;
|
|
|
import com.ruoyi.project.pssr.domain.TPssrApprove;
|
|
|
import com.ruoyi.project.pssr.domain.TPssrCleaning;
|
|
|
+import com.ruoyi.project.pssr.domain.TPssrCleaning;
|
|
|
import com.ruoyi.project.pssr.domain.TPssrSubcontent;
|
|
|
import com.ruoyi.project.pssr.service.ITPssrApproveService;
|
|
|
import com.ruoyi.project.pssr.service.ITPssrCleaningService;
|
|
|
import com.ruoyi.project.pssr.service.ITPssrFileService;
|
|
|
import com.ruoyi.project.pssr.service.ITPssrSubcontentService;
|
|
|
+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.activiti.engine.ProcessEngine;
|
|
|
import org.activiti.engine.ProcessEngines;
|
|
|
import org.activiti.engine.TaskService;
|
|
|
import org.activiti.engine.task.Task;
|
|
|
-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.*;
|
|
|
|
|
|
/**
|
|
@@ -59,6 +63,91 @@ public class TPssrCleaningController extends BaseController {
|
|
|
@Autowired
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService iSysDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysUserService userService;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('pssr:cleaning: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<TPssrCleaning> list = new ArrayList<TPssrCleaning>();
|
|
|
+ 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();
|
|
|
+ TPssrCleaning entity = new TPssrCleaning();
|
|
|
+ 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.setDevNo(cellValue);
|
|
|
+ }else if (j == 2) {
|
|
|
+ entity.setSerialNumber(Long.parseLong(cellValue));
|
|
|
+ }else if (j == 3) {
|
|
|
+ entity.setCheckContent(cellValue);
|
|
|
+ } else if (j == 4) {
|
|
|
+ entity.setCheckResult(cellValue);
|
|
|
+ } else if (j == 5) {
|
|
|
+ if (cellValue.length() > 3) {
|
|
|
+ entity.setConfirmationDate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));
|
|
|
+ }
|
|
|
+ } else if (j == 6) {
|
|
|
+ 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 (TPssrCleaning t : list
|
|
|
+ ) {
|
|
|
+ failNum++;
|
|
|
+ try {
|
|
|
+ tPssrCleaningService.insertTPssrCleaning(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));
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 查询设备清洁列表
|
|
|
*/
|