Sfoglia il codice sorgente

演练计划导入功能开发

huangpeng 10 ore fa
parent
commit
35edb78405

+ 16 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/dao/QhseEmergencyDrilPlanDao.java

@@ -0,0 +1,16 @@
+package com.rongwei.bscommon.system.dao;
+
+import com.rongwei.bsentity.domain.QhseEmergencyDrilPlanDo;
+
+/**
+* @author shangmi
+* @description 针对表【qhse_emergency_dril_plan(应急管理-演练计划)】的数据库操作Mapper
+* @createDate 2025-09-17 15:55:58
+* @Entity generator.domain.QhseEmergencyDrilPlan
+*/
+public interface QhseEmergencyDrilPlanDao extends QHSEMapper<QhseEmergencyDrilPlanDo> {
+
+}
+
+
+

+ 72 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/excelImportListener/EmergencyDrilPlanListenner.java

@@ -0,0 +1,72 @@
+package com.rongwei.bscommon.system.excelImportListener;
+
+import com.alibaba.excel.context.AnalysisContext;
+import com.alibaba.excel.event.AnalysisEventListener;
+import com.rongwei.bsentity.domain.QhseEmergencyDrilPlanDo;
+import com.rongwei.bsentity.dto.EmergencyDrilPlanListennerImportDto;
+import org.apache.commons.lang.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * UserPointsEegistrationListener class
+ *
+ * @author XH
+ * @date 2025/09/10
+ */
+public class EmergencyDrilPlanListenner extends AnalysisEventListener<EmergencyDrilPlanListennerImportDto> {
+    private static final Logger log = LoggerFactory.getLogger(EmergencyDrilPlanListenner.class);
+    private final List<QhseEmergencyDrilPlanDo> saveList = new ArrayList<>();
+
+
+
+    @Override
+    public void invoke(EmergencyDrilPlanListennerImportDto currentRowDto, AnalysisContext analysisContext) {
+
+        // 必填项校验
+        if (StringUtils.isBlank(currentRowDto.getMonth()) ||
+                StringUtils.isBlank(currentRowDto.getQuarter()) ||
+                StringUtils.isBlank(currentRowDto.getHostdepartment()) ||
+                StringUtils.isBlank(currentRowDto.getDrillitem()) ||
+                StringUtils.isBlank(currentRowDto.getDrilltype()) ||
+                StringUtils.isBlank(currentRowDto.getDrillform()) ||
+                StringUtils.isBlank(currentRowDto.getPersonincharge()) ||
+                StringUtils.isBlank(currentRowDto.getParticipants()) ||
+                currentRowDto.getYear() == null
+
+        ) {
+            log.error("第{}行的数据,存在必填项未填的数据", analysisContext.readRowHolder().getRowIndex());
+            throw new RuntimeException("存在必填字段为空的数据");
+        }
+
+        QhseEmergencyDrilPlanDo drilPlanDo = new QhseEmergencyDrilPlanDo();
+        drilPlanDo.setYear(currentRowDto.getYear())
+                .setMonth(currentRowDto.getMonth().trim())
+                .setQuarter(currentRowDto.getQuarter().trim())
+                .setHostdepartment(currentRowDto.getHostdepartment().trim())
+                .setDrillform(currentRowDto.getDrillform().trim())
+                .setDrillitem(currentRowDto.getDrillitem().trim())
+                .setDrilltype(currentRowDto.getDrilltype().trim())
+                .setPersonincharge(currentRowDto.getPersonincharge().trim())
+                .setPersoninchargeid("")
+                .setParticipants(currentRowDto.getParticipants().trim())
+                .setParticipantids("")
+                .setDirectinput(currentRowDto.getDirectinput())
+                .setRemark(currentRowDto.getRemark().trim());
+        saveList.add(drilPlanDo);
+
+    }
+
+    @Override
+    public void doAfterAllAnalysed(AnalysisContext analysisContext) {
+
+    }
+
+    // 获取Excel 中的数据
+    public List<QhseEmergencyDrilPlanDo> getData() {
+        return saveList;
+    }
+
+}

+ 17 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/service/QhseEmergencyDrilPlanService.java

@@ -0,0 +1,17 @@
+package com.rongwei.bscommon.system.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import com.rongwei.bsentity.domain.QhseEmergencyDrilPlanDo;
+import com.rongwei.rwcommon.base.R;
+
+import java.util.List;
+
+/**
+* @author shangmi
+* @description 针对表【qhse_emergency_dril_plan(应急管理-演练计划)】的数据库操作Service
+* @createDate 2025-09-17 15:55:59
+*/
+public interface QhseEmergencyDrilPlanService extends IService<QhseEmergencyDrilPlanDo> {
+
+    R ProcessImportedData(List<QhseEmergencyDrilPlanDo> data);
+}

+ 30 - 8
qhse-common/src/main/java/com/rongwei/bscommon/system/service/impl/ExcelImportServiceImpl.java

@@ -3,14 +3,18 @@ package com.rongwei.bscommon.system.service.impl;
 import com.alibaba.excel.EasyExcel;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.google.common.collect.Lists;
+import com.rongwei.bscommon.system.excelImportListener.EmergencyDrilPlanListenner;
 import com.rongwei.bscommon.system.excelImportListener.UnitPointsRegistrationListener;
 import com.rongwei.bscommon.system.excelImportListener.UserPointsRegistrationListener;
 import com.rongwei.bscommon.system.service.ExcelImportService;
+import com.rongwei.bscommon.system.service.QhseEmergencyDrilPlanService;
 import com.rongwei.bscommon.system.service.QhsePointsUnitDetailsService;
 import com.rongwei.bscommon.system.utils.QHSEUtils;
 import com.rongwei.bsentity.domain.QhseContractWorkersDo;
+import com.rongwei.bsentity.domain.QhseEmergencyDrilPlanDo;
 import com.rongwei.bsentity.domain.QhsePointsDetailsUserDo;
 import com.rongwei.bsentity.domain.QhsePointsRecordUserDo;
+import com.rongwei.bsentity.dto.EmergencyDrilPlanListennerImportDto;
 import com.rongwei.bsentity.dto.UnitPointsRegistrationImportDto;
 import com.rongwei.bsentity.dto.UserPointsRegistrationImportDto;
 import com.rongwei.bsentity.vo.QhsePointsUnitDetailsVo;
@@ -19,14 +23,11 @@ import com.rongwei.rwcommon.base.BaseDo;
 import com.rongwei.rwcommon.base.R;
 import com.rongwei.rwcommon.utils.SecurityUtil;
 import com.rongwei.rwcommon.utils.StringUtils;
-import com.rongwei.rwcommonentity.commonservers.domain.SysFileItemDo;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Transactional;
 import org.springframework.web.multipart.MultipartFile;
 
 import java.io.File;
-import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.nio.file.Files;
@@ -60,6 +61,9 @@ public class ExcelImportServiceImpl implements ExcelImportService {
     @Autowired
     private QhsePointsUnitDetailsService qhsePointsUnitDetailsService;
 
+    @Autowired
+    private QhseEmergencyDrilPlanService qhseEmergencyDrilPlanService;
+
     @Override
     public R userPointsRegistration(MultipartFile file) {
         Path tempPath;
@@ -177,18 +181,36 @@ public class ExcelImportServiceImpl implements ExcelImportService {
     public R unitPointsRegistration(MultipartFile file) {
         UnitPointsRegistrationListener listener = new UnitPointsRegistrationListener();
 
-        try {
-            EasyExcel.read(file.getInputStream())
+        try (InputStream is = file.getInputStream()) {
+            EasyExcel.read(is)
                     .head(UnitPointsRegistrationImportDto.class)
                     .registerReadListener(listener)
                     .sheet()
                     .doRead();
-        }catch (Exception e){
-            throw new RuntimeException("读取单位积分文件失败");
+        } catch (Exception e) {
+            throw new RuntimeException("读取应急演练计划文件失败: " + e.getMessage());
         }
-
         // 3. 读取完成后获取数据(此时数据已完整)
         List<QhsePointsUnitDetailsVo> parsedData = listener.getData();
         return qhsePointsUnitDetailsService.ProcessImportedData(parsedData);
     }
+
+    public R emergencyDrilPlanImport(MultipartFile file) {
+        EmergencyDrilPlanListenner listener = new EmergencyDrilPlanListenner();
+
+        try (InputStream is = file.getInputStream()) {
+            EasyExcel.read(is)
+                    .head(EmergencyDrilPlanListennerImportDto.class)
+                    .registerReadListener(listener)
+                    .sheet()
+                    .doRead();
+        } catch (Exception e) {
+            throw new RuntimeException("读取应急演练计划文件失败: " + e.getMessage());
+        }
+
+        // 3. 读取完成后获取数据(此时数据已完整)
+        List<QhseEmergencyDrilPlanDo> data = listener.getData();
+        return qhseEmergencyDrilPlanService.ProcessImportedData(data);
+
+    }
 }

+ 130 - 0
qhse-common/src/main/java/com/rongwei/bscommon/system/service/impl/QhseEmergencyDrilPlanServiceImpl.java

@@ -0,0 +1,130 @@
+package com.rongwei.bscommon.system.service.impl;
+
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.rongwei.bscommon.system.dao.QhseEmergencyDrilPlanDao;
+import com.rongwei.bscommon.system.dao.QhsePointsUnitRecordDao;
+import com.rongwei.bscommon.system.service.QhseEmergencyDrilPlanService;
+import com.rongwei.bscommon.system.utils.QHSEUtils;
+import com.rongwei.bsentity.domain.QhseEmergencyDrilPlanDo;
+import com.rongwei.bsentity.domain.QhsePointsUnitRecordDo;
+import com.rongwei.bsentity.dto.UnitPointsImportValidationResult;
+import com.rongwei.rwadmincommon.system.dao.SysDictDao;
+import com.rongwei.rwadmincommon.system.dao.SysOrganizationDao;
+import com.rongwei.rwadmincommon.system.domain.SysDictDo;
+import com.rongwei.rwadmincommon.system.domain.SysOrganizationDo;
+import com.rongwei.rwadmincommon.system.vo.SysUserVo;
+import com.rongwei.rwcommon.base.R;
+import com.rongwei.rwcommon.utils.SecurityUtil;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+
+/**
+* @author shangmi
+* @description 针对表【qhse_emergency_dril_plan(应急管理-演练计划)】的数据库操作Service实现
+* @createDate 2025-09-17 15:55:58
+*/
+@Service
+public class QhseEmergencyDrilPlanServiceImpl extends ServiceImpl<QhseEmergencyDrilPlanDao, QhseEmergencyDrilPlanDo>
+    implements QhseEmergencyDrilPlanService {
+
+    @Autowired
+    private QhseEmergencyDrilPlanDao qhseEmergencyDrilPlanDao;
+
+    @Autowired
+    private SysDictDao sysDictDao;
+
+    @Autowired
+    private SysOrganizationDao sysOrganizationDao;
+
+
+    /**
+     * 季度
+     * 应急-预案类型
+     * 应急-演练形式
+     */
+    private static final List<String> DICT_TYPES =
+            Arrays.asList(
+                    "quarterly",
+                    "yj-yalx",
+                    "yj-ylxs"
+            );
+
+    @Override
+    @Transactional
+    public R ProcessImportedData(List<QhseEmergencyDrilPlanDo> parsedData) {
+        if (parsedData.isEmpty()) {
+            return R.error("无有效数据需要处理");
+        }
+
+        SysUserVo currentUser = QHSEUtils.getCurrentUser();
+
+        //校验数据
+        validateImportedData(parsedData, currentUser);
+
+
+        //更新子表
+        this.getBaseMapper().insertBatchSomeColumn(parsedData);
+
+        return R.ok();
+    }
+
+    /**
+     * 校验数据
+     * @param parsedData
+     * @param currentUser
+     */
+    private void validateImportedData(List<QhseEmergencyDrilPlanDo> parsedData, SysUserVo currentUser) {
+        //1.匹配数据字典
+        Map<String, Map<String, String>> dictCollect = sysDictDao.selectList(new LambdaQueryWrapper<SysDictDo>().
+                        eq(SysDictDo::getDeleted, "0").in(SysDictDo::getDicttype, DICT_TYPES))
+                .stream().collect(Collectors.groupingBy(SysDictDo::getDicttype,
+                        Collectors.toMap(SysDictDo::getName, SysDictDo::getValue)));
+
+        //查询一级部门
+        Map<String, String> orgCollect = sysOrganizationDao.selectList(new LambdaQueryWrapper<SysOrganizationDo>().eq(SysOrganizationDo::getDeleted, "0")
+                .eq(SysOrganizationDo::getOrgtype, "1")).stream().collect(Collectors.toMap(SysOrganizationDo::getFullname, SysOrganizationDo::getId));
+
+        QhseEmergencyDrilPlanDo qhseEmergencyDrilPlanDo =null;
+
+        // 查询一级部门
+        for (int i = 0; i < parsedData.size(); i++) {
+             qhseEmergencyDrilPlanDo = parsedData.get(i);
+            if (dictCollect.get(DICT_TYPES.get(0)).get(qhseEmergencyDrilPlanDo.getQuarter()) == null) {
+                throw new RuntimeException("第:"+ (i+2 )+"行季度不匹配,请重新检查");
+            }else {
+                qhseEmergencyDrilPlanDo.setQuarter(dictCollect.get(DICT_TYPES.get(0)).get(qhseEmergencyDrilPlanDo.getQuarter()));
+            }
+            if (dictCollect.get(DICT_TYPES.get(1)).get(qhseEmergencyDrilPlanDo.getDrilltype()) == null) {
+                throw new RuntimeException("第:"+ (i+2 )+"行演练类型不匹配,请重新检查");
+            }else {
+                qhseEmergencyDrilPlanDo.setDrilltype(dictCollect.get(DICT_TYPES.get(1)).get(qhseEmergencyDrilPlanDo.getDrilltype()));
+            }
+            if (dictCollect.get(DICT_TYPES.get(2)).get(qhseEmergencyDrilPlanDo.getDrillform()) == null) {
+                throw new RuntimeException("第:"+(i+2 ) +"行演练形式不匹配,请重新检查");
+            }else {
+                qhseEmergencyDrilPlanDo.setDrillform(dictCollect.get(DICT_TYPES.get(2)).get(qhseEmergencyDrilPlanDo.getDrillform()));
+            }
+
+            if (orgCollect.get(qhseEmergencyDrilPlanDo.getHostdepartment()) == null) {
+                throw new RuntimeException("第:"+ i+2 +"主办部门不匹配,请重新检查");
+            }else {
+                qhseEmergencyDrilPlanDo.setHostdepartmentid(orgCollect.get(qhseEmergencyDrilPlanDo.getHostdepartment()));
+            }
+
+            QHSEUtils.initModelGeneralParameters(qhseEmergencyDrilPlanDo, currentUser);
+            qhseEmergencyDrilPlanDo.setId(SecurityUtil.getUUID());
+        }
+
+    }
+}
+
+
+
+

+ 83 - 0
qhse-entity/src/main/java/com/rongwei/bsentity/Dto/EmergencyDrilPlanListennerImportDto.java

@@ -0,0 +1,83 @@
+package com.rongwei.bsentity.dto;
+
+import com.alibaba.excel.annotation.ExcelProperty;
+import lombok.Data;
+
+import java.math.BigDecimal;
+
+@Data
+public class EmergencyDrilPlanListennerImportDto {
+
+    /**
+     * 年份
+     */
+    @ExcelProperty(index = 0)
+    private Integer year;
+
+    /**
+     * 季度
+     */
+    @ExcelProperty(index = 1)
+    private String quarter;
+
+    /**
+     * 月份
+     */
+    @ExcelProperty(index = 2)
+    private String month;
+
+    /**
+     * 主办部门
+     */
+    @ExcelProperty(index = 3)
+    private String hostdepartment;
+
+    /**
+     * 演练科目
+     */
+    @ExcelProperty(index = 4)
+    private String drillitem;
+
+    /**
+     * 演练类型
+     */
+    @ExcelProperty(index = 5)
+    private String drilltype;
+
+    /**
+     * 演练形式
+     */
+    @ExcelProperty(index = 6)
+    private String drillform;
+
+    /**
+     * 负责人
+     */
+    @ExcelProperty(index = 7)
+    private String personincharge;
+
+    /**
+     * 参演人员
+     */
+    @ExcelProperty(index = 8)
+    private String participants;
+
+    /**
+     * 参演人数
+     */
+    @ExcelProperty(index = 9)
+    private Integer participantcount;
+
+    /**
+     * 直接投入(元)
+     */
+    @ExcelProperty(index = 10)
+    private BigDecimal directinput;
+
+    /**
+     * 备注
+     */
+    @ExcelProperty(index = 11)
+    private String remark;
+
+}

+ 12 - 0
qhse-server/src/main/java/com/rongwei/controller/ExcelImportController.java

@@ -48,4 +48,16 @@ public class ExcelImportController {
         log.info("开始单位积分导入");
         return excelImportService.unitPointsRegistration(file);
     }
+
+
+    /**
+     * 急管理-演练计划 开始导入
+     * @param file
+     * @return
+     */
+    @PostMapping("/emergency/plan")
+    public R emergencyDrilPlanImport(@RequestParam("file") MultipartFile file){
+        log.info("应急管理-演练计划 开始导入");
+        return excelImportService.emergencyDrilPlanImport(file);
+    }
 }