| | |
| | | package com.ruoyi.project.tr.riskList.controller; |
| | | |
| | | import com.github.pagehelper.util.StringUtil; |
| | | import com.ruoyi.common.utils.DateUtils; |
| | | import com.ruoyi.common.utils.StringUtils; |
| | | import com.ruoyi.common.utils.poi.ExcelUtil; |
| | | import com.ruoyi.common.utils.security.ShiroUtils; |
| | | import com.ruoyi.doublePrevention.entity.PreventRiskCheckUnit; |
| | | import com.ruoyi.doublePrevention.entity.PreventRiskControlMeasure; |
| | | import com.ruoyi.doublePrevention.repository.param.PreventPointAndMeasureParams; |
| | | import com.ruoyi.doublePrevention.service.RiskService; |
| | | import com.ruoyi.doublePrevention.service.baseService.PreventCJReportRiskControlMeasureService; |
| | | import com.ruoyi.doublePrevention.service.baseService.PreventRiskControlMeasureService; |
| | | import com.ruoyi.framework.aspectj.lang.annotation.Log; |
| | | import com.ruoyi.framework.aspectj.lang.enums.BusinessType; |
| | | import com.ruoyi.framework.web.controller.BaseController; |
| | |
| | | import com.ruoyi.framework.web.page.TableDataInfo; |
| | | import com.ruoyi.project.enumerate.TrRiskTypeEnum; |
| | | import com.ruoyi.project.system.user.domain.User; |
| | | import com.ruoyi.project.tr.baseCheckPoint.domain.BaseCheckPoint; |
| | | import com.ruoyi.project.tr.baseCheckPoint.service.IBaseCheckPointService; |
| | | import com.ruoyi.project.tr.riskCheckPoint.service.IRiskCheckPointService; |
| | | import com.ruoyi.project.tr.riskList.domain.ImportDataRespBO; |
| | | import com.ruoyi.project.tr.riskList.domain.RiskList; |
| | | import com.ruoyi.project.tr.riskList.service.IRiskListService; |
| | | import org.apache.commons.lang3.ObjectUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.springframework.ui.ModelMap; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import java.util.ArrayList; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | /** |
| | |
| | | |
| | | @Autowired |
| | | private IRiskListService riskListService; |
| | | |
| | | @Autowired |
| | | private IBaseCheckPointService baseCheckPointService; |
| | | |
| | | @Autowired |
| | | private PreventRiskControlMeasureService riskControlMeasureService; |
| | | |
| | | @Autowired |
| | | private RiskService riskService; |
| | | |
| | | |
| | | /** |
| | | * 查询基础清单列表 |
| | |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 基础排查清单+检查点的导入 todo |
| | | * @param file |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | @Log(title = "基础排查清单+检查点的导入", businessType = BusinessType.IMPORT) |
| | | @PostMapping("/importData") |
| | | @ResponseBody |
| | | @Transactional |
| | | public AjaxResult importData(MultipartFile file) throws Exception { |
| | | |
| | | if (file.isEmpty()){ |
| | | return AjaxResult.error("文件不能为空"); |
| | | }else { |
| | | ExcelUtil<ImportDataRespBO> util = new ExcelUtil<ImportDataRespBO>(ImportDataRespBO.class); |
| | | System.out.println(file.getInputStream()); |
| | | List<ImportDataRespBO> importDataList = util.importExcel(file.getInputStream()); |
| | | System.out.println(importDataList.size()); |
| | | Boolean judgeDataBlean = Boolean.TRUE; |
| | | String errorMessage = ""; |
| | | for (int i = 0; i < importDataList.size(); i++) { |
| | | ImportDataRespBO importData = importDataList.get(i); |
| | | if (StringUtil.isEmpty(importData.getRiskListName())) { |
| | | judgeDataBlean = Boolean.FALSE; |
| | | errorMessage += |
| | | StringUtils.isEmpty(errorMessage)? |
| | | "第" + (i + 1) + "行,该[基础清单名称]不能为空" :"<br/> 第" + (i + 1) + "行,该[检查内容]不能为空"; |
| | | } |
| | | if (StringUtil.isEmpty(importData.getCheckType())) { |
| | | judgeDataBlean = Boolean.FALSE; |
| | | errorMessage += |
| | | StringUtils.isEmpty(errorMessage)? |
| | | "第" + (i + 1) + "行,该[检查类别]不能为空" :"<br/> 第" + (i + 1) + "行,该[检查内容]不能为空"; |
| | | } |
| | | if (StringUtil.isEmpty(importData.getCheckContent())) { |
| | | judgeDataBlean = Boolean.FALSE; |
| | | errorMessage += |
| | | StringUtils.isEmpty(errorMessage)? |
| | | "第" + (i + 1) + "行,该[检查内容]不能为空" :"<br/> 第" + (i + 1) + "行,该[检查内容]不能为空"; |
| | | } |
| | | if (StringUtil.isEmpty(importData.getControlMeasureCode())) { |
| | | judgeDataBlean = Boolean.FALSE; |
| | | errorMessage += |
| | | StringUtils.isEmpty(errorMessage)? |
| | | "第" + (i + 1) + "行,该[管控措施编号]不能为空" :"<br/> 第" + (i + 1) + "行,该[检查内容]不能为空"; |
| | | } |
| | | |
| | | } |
| | | if(!judgeDataBlean){ |
| | | return AjaxResult.error(errorMessage); |
| | | } |
| | | |
| | | // List<RiskList> riskLists = new ArrayList<>(); 先不使用批量插入 |
| | | // List<BaseCheckPoint> baseCheckPoints = new ArrayList<>(); |
| | | for (int i = 0; i < importDataList.size(); i++) { |
| | | ImportDataRespBO importData = importDataList.get(i); |
| | | RiskList riskList = new RiskList(); |
| | | BaseCheckPoint baseCheckPoint = new BaseCheckPoint(); |
| | | PreventPointAndMeasureParams preventPointAndMeasureParams = new PreventPointAndMeasureParams(); |
| | | |
| | | User sysUser = getSysUser(); |
| | | Date nowDate = DateUtils.getNowDate(); |
| | | //1.RiskList,拿到id -需要根据那么判断,是否已经存在 |
| | | RiskList infoByRiskListName = riskListService.getInfoByRiskListName(importData.getRiskListName()); |
| | | if (ObjectUtils.isEmpty(infoByRiskListName)){ |
| | | riskList.setRiskListName(importData.getRiskListName()); |
| | | riskList.setCreateBy(sysUser.getUserName()); |
| | | riskList.setCreateTime(nowDate); |
| | | riskList.setRiskType(TrRiskTypeEnum.BASE.getCode()); |
| | | riskList.setCompanyId(getSysUser().getCompanyId()); |
| | | int resultRiskList = riskListService.insertRiskList(riskList); |
| | | if (resultRiskList < 1){ //todo 需要检查是否收到标题行影响 |
| | | return AjaxResult.error("第" + i + "行基础清单插入错误,导入失败"); |
| | | } |
| | | }else { |
| | | riskList.setRiskListId(infoByRiskListName.getRiskListId()); |
| | | } |
| | | //2.baseCheckPoint,拿到id |
| | | baseCheckPoint.setRiskId(riskList.getRiskListId()); |
| | | baseCheckPoint.setCreateBy(sysUser.getUserName()); |
| | | baseCheckPoint.setCreateTime(nowDate); |
| | | baseCheckPoint.setCheckContent(importData.getCheckContent()); |
| | | baseCheckPoint.setCheckType(importData.getCheckType()); |
| | | if (ObjectUtils.isEmpty(importData.getCheckResult())){ |
| | | baseCheckPoint.setCheckResult(importData.getCheckResult()); |
| | | } |
| | | int resultBaseCheckPoint = baseCheckPointService.insertBaseCheckPoint(baseCheckPoint); |
| | | if (resultBaseCheckPoint < 1){ |
| | | return AjaxResult.error("第" + i + "行风险点插入错误,导入失败"); |
| | | } |
| | | //3.preventRiskCheckUnit |
| | | PreventRiskControlMeasure controlMeasure = |
| | | riskControlMeasureService.getPreventRiskControlMeasureByControlMeasureCode(importData.getControlMeasureCode()); |
| | | if (ObjectUtils.isEmpty(controlMeasure)){ |
| | | return AjaxResult.error("第" + i + "行管控措施不存在,导入失败"); |
| | | } |
| | | preventPointAndMeasureParams.setRiskId(riskList.getRiskListId()); |
| | | preventPointAndMeasureParams.setBaseCheckPointId(baseCheckPoint.getCheckPointId()); |
| | | preventPointAndMeasureParams.setControlMeasureId(controlMeasure.getId()); |
| | | int result = riskService.insertPointAndMeasure(preventPointAndMeasureParams); |
| | | if (ObjectUtils.isEmpty(controlMeasure)){ |
| | | return AjaxResult.error("第" + i + "行风险点与管控措施关联关系保持出错,导入失败"); |
| | | } |
| | | |
| | | } |
| | | return AjaxResult.success("导入成功!"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | } |