|
@@ -1,17 +1,23 @@
|
|
|
package com.ruoyi.project.ehs.controller;
|
|
|
|
|
|
+import java.io.IOException;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
import java.util.List;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.ruoyi.common.utils.DateUtils;
|
|
|
+import com.ruoyi.common.utils.file.ExcelUtils;
|
|
|
+import com.ruoyi.project.plant.domain.TStaffmgr;
|
|
|
+import com.ruoyi.project.plant.service.ITStaffmgrService;
|
|
|
+import com.ruoyi.project.system.domain.SysDept;
|
|
|
+import com.ruoyi.project.system.domain.SysDictData;
|
|
|
+import com.ruoyi.project.system.service.ISysDeptService;
|
|
|
+import com.ruoyi.project.system.service.ISysDictTypeService;
|
|
|
+import org.apache.poi.ss.usermodel.*;
|
|
|
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.ehs.domain.THealthapproval;
|
|
@@ -20,6 +26,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
|
|
@@ -34,6 +41,15 @@ public class THealthapprovalController extends BaseController
|
|
|
@Autowired
|
|
|
private ITHealthapprovalService tHealthapprovalService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysDeptService iSysDeptService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ISysDictTypeService iSysDictTypeService;
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private ITStaffmgrService tStaffmgrService;
|
|
|
+
|
|
|
/**
|
|
|
* 查询卫生批文清单列表
|
|
|
*/
|
|
@@ -43,12 +59,6 @@ public class THealthapprovalController extends BaseController
|
|
|
{
|
|
|
startPage();
|
|
|
List<THealthapproval> list = tHealthapprovalService.selectTHealthapprovalList(tHealthapproval);
|
|
|
- for (THealthapproval h : list) {
|
|
|
- SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd");
|
|
|
- if (h.getValidityBefore() != null && h.getValidityAfter() != null) {
|
|
|
- h.setValidity(sdf.format(h.getValidityBefore()) + "-" + sdf.format(h.getValidityAfter()));
|
|
|
- }
|
|
|
- }
|
|
|
return getDataTable(list);
|
|
|
}
|
|
|
|
|
@@ -107,4 +117,133 @@ public class THealthapprovalController extends BaseController
|
|
|
{
|
|
|
return toAjax(tHealthapprovalService.deleteTHealthapprovalByIds(ids));
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 批量导入安全批文清单
|
|
|
+ */
|
|
|
+ @PreAuthorize("@ss.hasPermi('ehs:healthapproval:add')")
|
|
|
+ @Log(title = "卫生批文清单", businessType = BusinessType.INSERT)
|
|
|
+ @PostMapping("/importData")
|
|
|
+ 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<THealthapproval> list = new ArrayList<THealthapproval>();
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ //字典查询
|
|
|
+ List<SysDictData> plant = iSysDictTypeService.selectDictDataByType("PLANT_DIVIDE");
|
|
|
+ List<SysDictData> yesNo = iSysDictTypeService.selectDictDataByType("YES_NO");
|
|
|
+ //部门查询
|
|
|
+ List<SysDept> dept = iSysDeptService.selectDeptList(new SysDept());
|
|
|
+ //人员查询
|
|
|
+ List<TStaffmgr> staffmgrs = tStaffmgrService.selectTStaffmgrList(new TStaffmgr());
|
|
|
+ int rowNum = sheet.getPhysicalNumberOfRows();
|
|
|
+ int failNumber = 0;
|
|
|
+ for (int i = 1; i < rowNum; i++) {
|
|
|
+ try {
|
|
|
+ logger.info("读取行数:" + i);
|
|
|
+ Row row = sheet.getRow(i);
|
|
|
+ int cellNum = row.getPhysicalNumberOfCells();
|
|
|
+ THealthapproval entity = new THealthapproval();
|
|
|
+ for (int j = 0; j < cellNum; j++) {
|
|
|
+ Cell cell = row.getCell(j);
|
|
|
+ cell.setCellType(CellType.STRING);
|
|
|
+ String cellValue = ExcelUtils.getCellValue(cell);
|
|
|
+ logger.info("cellValue:" + cellValue);
|
|
|
+ if (j == 0) {
|
|
|
+ entity.setApprovalname(cellValue);//批文名称
|
|
|
+ } else if (j == 1) {
|
|
|
+ entity.setCertno(cellValue);//证书编号
|
|
|
+ } else if (j == 2) {
|
|
|
+ if (cellValue.length() > 3) {
|
|
|
+ entity.setEffetivedate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//批准日期
|
|
|
+ }
|
|
|
+ } else if (j == 3) {
|
|
|
+ entity.setScope(cellValue);//适用范围
|
|
|
+ } else if (j == 4) {
|
|
|
+ entity.setRelatedlaw(cellValue);//相关法规
|
|
|
+ } else if (j == 5) {
|
|
|
+ entity.setResponsauth(cellValue);//审批单位
|
|
|
+ } else if (j == 6) {
|
|
|
+ if (cellValue.length() > 3) {
|
|
|
+ entity.setValidityBefore(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//证书有效期前
|
|
|
+ entity.setIsPermanent(Long.parseLong("0"));
|
|
|
+ }else {
|
|
|
+ entity.setIsPermanent(Long.parseLong("1"));
|
|
|
+ }
|
|
|
+ } else if (j == 7) {
|
|
|
+ if (cellValue.length() > 3) {
|
|
|
+ entity.setValidityAfter(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//证书有效期后
|
|
|
+ }
|
|
|
+ } else if (j == 8) {
|
|
|
+ for (SysDictData p : yesNo) {
|
|
|
+ if (p.getDictLabel().equals(cellValue.trim())) {
|
|
|
+ entity.setFollow(p.getDictValue());//是否需要跟进
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (j == 9) {
|
|
|
+ entity.setAllowance(cellValue);//使用/储存/废物最大量
|
|
|
+ } else if (j == 10) {
|
|
|
+ entity.setRequirements(cellValue);//排放/监控要求
|
|
|
+ } else if (j == 11) {
|
|
|
+ entity.setContent(cellValue);//主要内容
|
|
|
+ } else if (j == 12) {
|
|
|
+ entity.setOwner(cellValue);//负责人
|
|
|
+ } else if (j == 14) {
|
|
|
+ for (TStaffmgr s : staffmgrs) {
|
|
|
+ if (s.getStaffid().equals(cellValue.trim())) {
|
|
|
+ entity.setReviewer(s.getStaffid());//回顾人
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (j == 15) {
|
|
|
+ if (cellValue.length() > 3) {
|
|
|
+ entity.setReviewdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//本次回顾日期
|
|
|
+ }
|
|
|
+ } else if (j == 16) {
|
|
|
+ entity.setReviewResult(cellValue);//回顾结果
|
|
|
+ } else if (j == 17) {
|
|
|
+ if (cellValue.length() > 3) {
|
|
|
+ entity.setNextreviewdate(new SimpleDateFormat(DateUtils.getDateFormat(cellValue)).parse(cellValue));//下次回顾日期
|
|
|
+ }
|
|
|
+ } else if (j == 18) {
|
|
|
+ for (SysDept d : dept) {
|
|
|
+ if (d.getDeptName().equals(cellValue.trim())) {
|
|
|
+ entity.setDeptId(d.getDeptId());//部门编号
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else if (j == 19) {
|
|
|
+ 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 (THealthapproval t : list
|
|
|
+ ) {
|
|
|
+ failNum++;
|
|
|
+ try {
|
|
|
+ tHealthapprovalService.insertTHealthapproval(t);
|
|
|
+ successNumber++;
|
|
|
+ }catch (Exception e){
|
|
|
+ failNumber++;
|
|
|
+ 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);
|
|
|
+ }
|
|
|
}
|