From 929e92a12bd1d5144141862e1c80ab98af55f300 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 09 七月 2025 16:56:36 +0800
Subject: [PATCH] art: 数据权限相关代码修改,技术状态鉴定规范导入

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java |  258 +++++++++++++++++++++++++++++++-----
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java                  |   20 +-
 lxzn-boot-base-core/src/main/java/org/jeecg/common/util/WordParseUtils.java                                           |   42 ++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamTechnicalStatusEvaluationStandardService.java         |    9 +
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java                   |    6 
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamTechnicalStatusEvaluationStandardController.java    |   71 +++++++++
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java               |    6 
 7 files changed, 356 insertions(+), 56 deletions(-)

diff --git a/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/WordParseUtils.java b/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/WordParseUtils.java
new file mode 100644
index 0000000..9bf9d00
--- /dev/null
+++ b/lxzn-boot-base-core/src/main/java/org/jeecg/common/util/WordParseUtils.java
@@ -0,0 +1,42 @@
+package org.jeecg.common.util;
+
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFRun;
+import org.apache.poi.xwpf.usermodel.XWPFTableCell;
+
+public class WordParseUtils {
+    /**
+     * 鍏煎鐗堝崟鍏冩牸鏂囨湰鎻愬彇
+     */
+    public static String getCellText(XWPFTableCell cell) {
+        if (cell == null) {
+            return "";
+        }
+        String text = cell.getText();
+
+        return text.toString();
+    }
+
+    /**
+     * 鍐呭娓呯悊
+     */
+    private String cleanContent(String text) {
+        if (text == null) {
+            return "";
+        }
+        // 鏇挎崲鐗规畩绌烘牸鍜屽悎骞惰繛缁┖鏍�
+        text = text.replace('\u00A0', ' ')
+                .replace('\u2007', ' ')
+                .replace('\u202F', ' ')
+                .replaceAll("\\s+", " ");
+
+        // 瑙勮寖鏍囩偣绗﹀彿
+        return text.replace(',', '銆�')
+                .replace('锛�', '銆�')
+                .replace(';', '锛�')
+                .replace('锛�', '锛�')
+                .replace(':', '锛�')
+                .replace('锛�', '锛�')
+                .trim();
+    }
+}
diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
index dfc744c..7c1226b 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamEquipmentServiceImpl.java
@@ -167,9 +167,11 @@
             List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
             if(!CollectionUtils.isEmpty(baseFactoryUserList)){
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                 queryWrapper.in("e.factory_org_code", factoryCode);
+            }else {
+                return page;
             }
         }
         //鏌ヨ鏉′欢杩囨护
@@ -255,9 +257,11 @@
             List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
             if(!CollectionUtils.isEmpty(baseFactoryUserList)){
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                 queryWrapper.in("e.factory_org_code", factoryCode);
+            } else {
+                return Collections.emptyList();
             }
         }
 
@@ -298,7 +302,7 @@
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
             if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
                 Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
-                Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toSet());
+                Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                 queryWrapper.in("factory_org_code", factoryCodeList);
             } else {
                 return null;
@@ -334,9 +338,11 @@
             List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
             if(!CollectionUtils.isEmpty(baseFactoryUserList)){
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                 queryWrapper.in("e.factory_org_code", factoryCode);
+            }else {
+                return Collections.emptyList();
             }
 
         }
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamTechnicalStatusEvaluationStandardController.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamTechnicalStatusEvaluationStandardController.java
index 8f79288..d169644 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamTechnicalStatusEvaluationStandardController.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/controller/EamTechnicalStatusEvaluationStandardController.java
@@ -8,20 +8,23 @@
 import lombok.extern.slf4j.Slf4j;
 import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.aspect.annotation.AutoLog;
-import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.system.base.controller.JeecgController;
 import org.jeecg.modules.eam.constant.BusinessCodeConst;
 import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationStandardEnum;
-import org.jeecg.modules.eam.entity.EamMaintenanceStandard;
 import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandard;
 import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationStandardRequest;
 import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardService;
 import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
+import org.springframework.web.multipart.MultipartFile;
+import org.springframework.web.multipart.MultipartHttpServletRequest;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.Map;
 
 /**
  * @Description: 鎶�鏈姸鎬侀壌瀹氳鑼�
@@ -162,15 +165,71 @@
     }
 
     /**
-     * 閫氳繃excel瀵煎叆鏁版嵁
+     * 瀹夊叏瑁呯疆妫�鏌ユ槑缁嗗鍏�
+     *
+     * @param request
+     * @return
+     */
+    @PostMapping(value = "/importSafetyEquipmentCheck")
+    public Result<?> importSafetyEquipmentCheck(HttpServletRequest request) {
+        MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
+        Map<String, String> results = new LinkedHashMap<>();
+        Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
+        // 缁熻瀵煎叆缁撴灉
+        int successCount = 0;
+        int failureCount = 0;
+        for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
+            MultipartFile file = entity.getValue();
+            String fileName = file.getOriginalFilename();
+
+            Result<?> importResult = eamTechnicalStatusEvaluationStandardService.importSafetyEquipmentCheck(file);
+
+            if (importResult.isSuccess()) {
+                results.put(fileName, "鎴愬姛: " + importResult.getMessage());
+                successCount++;
+            } else {
+                results.put(fileName, "澶辫触: " + importResult.getMessage());
+                failureCount++;
+            }
+        }
+        // 鏋勫缓鏈�缁堝搷搴�
+        Map<String, Object> response = new HashMap<>();
+        response.put("results", results);
+        response.put("totalFiles", fileMap.size());
+        response.put("successCount", successCount);
+        response.put("failureCount", failureCount);
+
+        if (failureCount > 0) {
+            return Result.error("閮ㄥ垎鏂囦欢瀵煎叆澶辫触", response);
+        }
+
+        return Result.ok("鎵�鏈夋枃浠跺鍏ユ垚鍔�"+response);
+    }
+
+    /**
+     * 瀹夊叏瑁呯疆妫�鏌ユ槑缁嗗鍏�
      *
      * @param request
      * @param response
      * @return
      */
-    @RequestMapping(value = "/importExcel", method = RequestMethod.POST)
-    public Result<?> importExcel(HttpServletRequest request, HttpServletResponse response) {
-        return super.importExcel(request, response, EamTechnicalStatusEvaluationStandard.class);
+    @PostMapping(value = "/importPrecisionCheck")
+    public Result<?> importPrecisionCheck(HttpServletRequest request, HttpServletResponse response) {
+        return null;
     }
 
+
+    /**
+     * 瀹夊叏瑁呯疆妫�鏌ユ槑缁嗗鍏�
+     *
+     * @param request
+     * @param response
+     * @return
+     */
+    @PostMapping(value = "/importOtherCheck")
+    public Result<?> importOtherCheck(HttpServletRequest request, HttpServletResponse response) {
+        return null;
+    }
+
+
 }
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamTechnicalStatusEvaluationStandardService.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamTechnicalStatusEvaluationStandardService.java
index 5e24179..6056f42 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamTechnicalStatusEvaluationStandardService.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/IEamTechnicalStatusEvaluationStandardService.java
@@ -3,8 +3,10 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.IService;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandard;
 import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationStandardRequest;
+import org.springframework.web.multipart.MultipartFile;
 
 /**
  * @Description: 鎶�鏈姸鎬侀壌瀹氳鑼�
@@ -50,4 +52,11 @@
      * @return
      */
     boolean upgrade(EamTechnicalStatusEvaluationStandardRequest request);
+
+    /**
+     * 瀹夊叏瑁呯疆瀵煎叆
+     * @param file
+     * @return
+     */
+    Result<?> importSafetyEquipmentCheck(MultipartFile file);
 }
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java
index 4065bf5..fa8dc1f 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamInspectionOrderServiceImpl.java
@@ -102,9 +102,11 @@
             List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
             if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                 queryWrapper.in("e.factory_org_code", factoryCode);
+            }else {
+                return page;
             }
         }
         //鏌ヨ鏉′欢杩囨护
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
index 6ac4eae..2df2d93 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java
@@ -127,9 +127,11 @@
             List<BaseFactoryUser> baseFactoryUserList=baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId,sysUser.getId()));
             if(!CollectionUtils.isEmpty(baseFactoryUserList)){
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCode= baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
                 queryWrapper.in("e.factory_org_code", factoryCode);
+            } else {
+                return page;
             }
         }
         if(eamMaintenanceStandard != null) {
diff --git a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java
index 2f52af9..4c8d7b6 100644
--- a/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java
+++ b/lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java
@@ -7,31 +7,43 @@
 import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.xwpf.usermodel.XWPFDocument;
+import org.apache.poi.xwpf.usermodel.XWPFParagraph;
+import org.apache.poi.xwpf.usermodel.XWPFTable;
+import org.apache.poi.xwpf.usermodel.XWPFTableRow;
 import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.api.vo.Result;
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
+import org.jeecg.common.util.FileUtil;
 import org.jeecg.common.util.SimpleVersionGenerateUtil;
-import org.jeecg.modules.system.entity.BaseFactory;
-import org.jeecg.modules.system.entity.BaseFactoryUser;
-import org.jeecg.modules.system.service.IBaseFactoryService;
-import org.jeecg.modules.system.service.IBaseFactoryUserService;
+import org.jeecg.modules.eam.constant.BusinessCodeConst;
 import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationCheckCategoryEnum;
 import org.jeecg.modules.eam.constant.TechnicalStatusEvaluationStandardEnum;
+import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandard;
 import org.jeecg.modules.eam.entity.EamTechnicalStatusEvaluationStandardDetail;
 import org.jeecg.modules.eam.mapper.EamTechnicalStatusEvaluationStandardMapper;
 import org.jeecg.modules.eam.request.EamTechnicalStatusEvaluationStandardRequest;
+import org.jeecg.modules.eam.request.ImportException;
+import org.jeecg.modules.eam.service.IEamEquipmentService;
 import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardDetailService;
 import org.jeecg.modules.eam.service.IEamTechnicalStatusEvaluationStandardService;
+import org.jeecg.modules.system.entity.BaseFactory;
+import org.jeecg.modules.system.entity.BaseFactoryUser;
+import org.jeecg.modules.system.service.IBaseFactoryService;
+import org.jeecg.modules.system.service.IBaseFactoryUserService;
+import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
 import org.springframework.beans.BeanUtils;
 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.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -41,6 +53,7 @@
  * @Version: V1.0
  */
 @Service
+@Slf4j
 public class EamTechnicalStatusEvaluationStandardServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationStandardMapper, EamTechnicalStatusEvaluationStandard> implements IEamTechnicalStatusEvaluationStandardService {
 
     @Autowired
@@ -49,6 +62,10 @@
     private IBaseFactoryService baseFactoryService;
     @Autowired
     private IEamTechnicalStatusEvaluationStandardDetailService standardDetailService;
+    @Autowired
+    private IEamEquipmentService equipmentService;
+    @Autowired
+    private ISysBusinessCodeRuleService businessCodeRuleService;
 
     @Override
     public IPage<EamTechnicalStatusEvaluationStandard> queryPageList(Page<EamTechnicalStatusEvaluationStandard> page, EamTechnicalStatusEvaluationStandard query) {
@@ -68,9 +85,9 @@
             List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
                     list(new LambdaQueryWrapper<BaseFactoryUser>().eq(BaseFactoryUser::getUserId, sysUser.getId()));
             if (!CollectionUtils.isEmpty(baseFactoryUserList)) {
-                List<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toList());
-                List<String> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getFactoryCode).collect(Collectors.toList());
-                queryWrapper.in("e.factory_org_code", factoryCode);
+                Set<String> factoryIds = baseFactoryUserList.stream().map(BaseFactoryUser::getFactoryId).collect(Collectors.toSet());
+                Set<String> factoryCodeList = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
+                queryWrapper.in("e.factory_org_code", factoryCodeList);
             } else {
                 return page;
             }
@@ -101,7 +118,7 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean addEamTechnicalStatusEvaluationStandard(EamTechnicalStatusEvaluationStandardRequest request) {
-        if(!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) {
+        if (!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) {
             //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫�
             throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒");
         }
@@ -116,36 +133,36 @@
         entity.setDelFlag(CommonConstant.DEL_FLAG_0);
         //閲嶅鎬ф牎楠�
         EamTechnicalStatusEvaluationStandard exist = checkDuplicate(entity.getEquipmentId(), null);
-        if(exist != null){
+        if (exist != null) {
             throw new JeecgBootException("瑙勮寖宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�");
         }
         this.getBaseMapper().insert(entity);
         //澶勭悊鏄庣粏鏁版嵁
-        if(CollectionUtil.isNotEmpty(request.getTableDetailList())) {
+        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
             request.getTableDetailList().forEach(tableDetail -> {
                 tableDetail.setStandardId(entity.getId());
             });
             //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨
-            if(CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) {
                 //淇濆瓨鍏朵粬鍒嗙被
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
             }
-            if(CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) {
                 //淇濆瓨瀹夊叏瑁呯疆鍒嗙被
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
             }
-            if(CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) {
                 //淇濆瓨绮惧害妫�楠屽垎绫�
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
@@ -162,11 +179,11 @@
         //寰呮彁浜ゃ�佸惎鐢ㄧ姸鎬�
         queryWrapper.in(EamTechnicalStatusEvaluationStandard::getStandardStatus, Arrays.asList(TechnicalStatusEvaluationStandardEnum.ENABLE.name(), TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name()));
         queryWrapper.orderByDesc(EamTechnicalStatusEvaluationStandard::getStandardVersion);
-        if(StringUtils.isNotBlank(id)){
+        if (StringUtils.isNotBlank(id)) {
             queryWrapper.ne(EamTechnicalStatusEvaluationStandard::getId, id);
         }
         List<EamTechnicalStatusEvaluationStandard> list = this.getBaseMapper().selectList(queryWrapper);
-        if(CollectionUtil.isEmpty(list)) {
+        if (CollectionUtil.isEmpty(list)) {
             return null;
         }
         return list.get(0);
@@ -175,12 +192,12 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean editEamTechnicalStatusEvaluationStandard(EamTechnicalStatusEvaluationStandardRequest request) {
-        if(!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) {
+        if (!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) {
             //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫�
             throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒");
         }
         EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId());
-        if(entity == null){
+        if (entity == null) {
             throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
         }
         entity.setStandardName(request.getStandardName());
@@ -191,33 +208,33 @@
         entity.setRemark(request.getRemark());
         this.getBaseMapper().updateById(entity);
         //澶勭悊璇︽儏
-        if(CollectionUtil.isNotEmpty(request.getTableDetailList())) {
+        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
             //鍏堝垹闄ゆ鏌ラ」
             standardDetailService.removeByStandardId(entity.getId());
             request.getTableDetailList().forEach(tableDetail -> {
                 tableDetail.setStandardId(entity.getId());
             });
             //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨
-            if(CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) {
                 //淇濆瓨鍏朵粬鍒嗙被
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
             }
-            if(CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) {
                 //淇濆瓨瀹夊叏瑁呯疆鍒嗙被
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
             }
-            if(CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) {
                 //淇濆瓨绮惧害妫�楠屽垎绫�
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
@@ -229,12 +246,12 @@
     @Override
     @Transactional(rollbackFor = Exception.class)
     public boolean upgrade(EamTechnicalStatusEvaluationStandardRequest request) {
-        if(!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) {
+        if (!CommonConstant.STATUS_1.equals(request.getHasOtherCheck()) && !CommonConstant.STATUS_1.equals(request.getHasSafetyEquipmentCheck()) && !CommonConstant.STATUS_1.equals(request.getHasPrecisionCheck())) {
             //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫�
             throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒");
         }
         EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId());
-        if(entity == null){
+        if (entity == null) {
             throw new JeecgBootException("鍗囩増鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
         }
 
@@ -256,12 +273,12 @@
         newEntity.setRemark(request.getRemark());
         //閲嶅鎬ф牎楠�
         EamTechnicalStatusEvaluationStandard exist = checkDuplicate(newEntity.getEquipmentId(), entity.getId());
-        if(exist != null){
+        if (exist != null) {
             throw new JeecgBootException("閴村畾瑙勮寖宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�");
         }
         this.getBaseMapper().insert(newEntity);
         //澶勭悊鏄庣粏鏁版嵁
-        if(CollectionUtil.isNotEmpty(request.getTableDetailList())) {
+        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
             request.getTableDetailList().forEach(tableDetail -> {
                 tableDetail.setId(null);
                 tableDetail.setCreateBy(null);
@@ -271,26 +288,26 @@
                 tableDetail.setStandardId(newEntity.getId());
             });
             //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨
-            if(CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasOtherCheck())) {
                 //淇濆瓨鍏朵粬鍒嗙被
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
             }
-            if(CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasSafetyEquipmentCheck())) {
                 //淇濆瓨瀹夊叏瑁呯疆鍒嗙被
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
             }
-            if(CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) {
+            if (CommonConstant.STATUS_1.equals(entity.getHasPrecisionCheck())) {
                 //淇濆瓨绮惧害妫�楠屽垎绫�
                 List<EamTechnicalStatusEvaluationStandardDetail> collect = request.getTableDetailList().stream().filter(item -> TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name().equals(item.getCheckCategory())).collect(Collectors.toList());
-                if(CollectionUtils.isEmpty(collect)) {
+                if (CollectionUtils.isEmpty(collect)) {
                     throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
                 }
                 standardDetailService.saveBatch(collect);
@@ -301,4 +318,167 @@
         this.getBaseMapper().updateById(entity);
         return true;
     }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> importSafetyEquipmentCheck(MultipartFile file) {
+        String fileName = file.getOriginalFilename();
+        if (StringUtils.isBlank(fileName)) {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+        String fileSuffix = FileUtil.getFileSuffix(fileName);
+        //鍙敮鎸� .docx 鐨剋ord鏂囨。
+        if ("docx".equals(fileSuffix)) {
+            try (XWPFDocument doc = new XWPFDocument(file.getInputStream())) {
+                List<XWPFParagraph> paragraphs = doc.getParagraphs();
+                List<XWPFTable> tables = doc.getTables();
+                if (CollectionUtil.isEmpty(paragraphs) || CollectionUtil.isEmpty(tables)) {
+                    return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒");
+                }
+                //鑾峰彇鏂囦欢鏍囬
+                StringBuilder builder = new StringBuilder();
+                paragraphs.forEach(paragraph -> {
+                    if (StringUtils.isNotBlank(paragraph.getText())) {
+                        builder.append(paragraph.getText().trim());
+                    }
+                });
+                if (!checkImportCategory(builder.toString(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK)) {
+                    return Result.error(fileName + ":姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌ワ紒");
+                }
+                //鑾峰彇璁惧淇℃伅
+                EamEquipment equipment = extractEquipmentInfo(tables.get(0));
+                //鏌ョ湅鏄惁鏈夋璁惧鍚敤鐨勮鑼冧俊鎭�
+                EamTechnicalStatusEvaluationStandard originalStandard = checkDuplicate(equipment.getId(), null);
+                if (originalStandard != null && TechnicalStatusEvaluationStandardEnum.ENABLE.name().equals(originalStandard.getStandardStatus())) {
+                    return Result.error(fileName + ":姝よ澶囩殑瀹夊叏瑁呯疆妫�鏌ラ」宸叉坊鍔狅紝璇疯繘琛岀紪杈戞垨鍗囩増锛�");
+                }
+                //鑾峰彇妫�鏌ラ」淇℃伅
+                List<EamTechnicalStatusEvaluationStandardDetail> detailList = extractSafetyEquipmentCheckItems(tables);
+                if(CollectionUtil.isEmpty(detailList)){
+                    return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒");
+                }
+                if(originalStandard != null) {
+                    //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜�
+                    originalStandard.setHasSafetyEquipmentCheck(CommonConstant.STATUS_1);
+                    originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name());
+                    super.getBaseMapper().updateById(originalStandard);
+                    detailList.forEach(standardDetail -> {
+                        standardDetail.setStandardId(originalStandard.getId());
+                    });
+                    standardDetailService.saveBatch(detailList);
+                }else {
+                    String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.TECHNICAL_STATUS_EVALUATION_STANDARD_CODE_RULE);
+                    //鏂板鎶�鏈姸鎬侀壌瀹氳鑼�
+                    EamTechnicalStatusEvaluationStandardRequest request = new EamTechnicalStatusEvaluationStandardRequest();
+                    request.setEquipmentId(equipment.getId());
+                    request.setHasSafetyEquipmentCheck(CommonConstant.STATUS_1);
+                    request.setHasOtherCheck(CommonConstant.STATUS_0);
+                    request.setHasPrecisionCheck(CommonConstant.STATUS_0);
+                    request.setStandardCode(codeSeq);
+                    request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�");
+                    request.setTableDetailList(detailList);
+                    this.addEamTechnicalStatusEvaluationStandard(request);
+                }
+            } catch (ImportException e) {
+                log.error(e.getMessage(), e);
+                return Result.error(fileName + ":" + e.getMessage() + "锛�");
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error(fileName + ":绯荤粺閿欒-" + e.getMessage() + "锛�");
+            }
+        } else {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+
+        return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�");
+    }
+
+    private boolean checkImportCategory(String title, TechnicalStatusEvaluationCheckCategoryEnum category) {
+        switch (category) {
+            case SAFETY_EQUIPMENT_CHECK:
+                return title.contains("瀹夊叏瑁呯疆妫�鏌�");
+            case PRECISION_CHECK:
+                return title.contains("绮惧害妫�鏌ュ崟");
+            case OTHER_CHECK:
+                return title.contains("鍏朵粬妫�鏌�");
+        }
+        return false;
+    }
+
+
+    /**
+     * 鎻愬彇璁惧鍩烘湰淇℃伅
+     */
+    private EamEquipment extractEquipmentInfo(XWPFTable table) {
+        if (table.getNumberOfRows() < 4) {
+            //濡傛灉 table 灏忎簬4琛� 浠h〃涓嶇鍚堟ā鏉胯鑼冿紝瀵煎叆澶辫触
+            throw new JeecgBootException("姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌�");
+        }
+        // 鎻愬彇绗簩琛屾暟鎹�
+        Map<String, String> row2Data = extractHeadRowData(table.getRow(1));
+        //鑾峰彇璁惧缁熶竴缂栫爜
+        String equipmentCode = row2Data.get("缁熶竴缂栧彿") == null ? null : row2Data.get("缁熶竴缂栧彿").trim();
+        EamEquipment eamEquipment = equipmentService.selectByEquipmentCode(equipmentCode);
+        if (eamEquipment == null) {
+            throw new JeecgBootException("鏈壘鍒拌澶囦俊鎭紝璇锋煡鐪嬭澶囧彴璐︽槸鍚︽湁姝よ澶�");
+        }
+        return eamEquipment;
+    }
+
+    /**
+     * 琛ㄦ牸琛ㄥご鏁版嵁瑙f瀽
+     */
+    private Map<String, String> extractHeadRowData(XWPFTableRow row) {
+        Map<String, String> data = new HashMap<>();
+        if(CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() != 4) {
+            throw new JeecgBootException("姝ゆ枃浠朵笉绗﹀悎瀹夊叏瑁呯疆妫�鏌ユā鏉胯鑼冿紝璇锋鏌�");
+        }
+        int cellCount = row.getTableCells().size();
+        for (int i = 0; i < cellCount; i += 2) {
+            String key = row.getCell(i).getText().trim();
+            String value = row.getCell(i + 1).getText().trim();
+            if (StringUtils.isNotBlank(key) && StringUtils.isNotBlank(value)) {
+                data.put(key, value);
+            }
+        }
+        return data;
+    }
+
+    /**
+     * 鎻愬彇瀹夊叏瑁呯疆妫�鏌ユ槑缁�
+     */
+    private List<EamTechnicalStatusEvaluationStandardDetail> extractSafetyEquipmentCheckItems(List<XWPFTable> tableList) {
+
+        List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>();
+        EamTechnicalStatusEvaluationStandardDetail item = null;
+        //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭�
+        XWPFTable table = tableList.get(0);
+        for (int i = 0; i < table.getNumberOfRows(); i++) {
+            XWPFTableRow row = table.getRow(i);
+            if (row == null || CollectionUtil.isEmpty(row.getTableCells()) || row.getTableCells().size() < 2) {
+                //璇诲彇鍒扮┖row鍊�
+                continue;
+            }
+            //妫�鏌ユ槸鍚﹀埌妫�鏌ラ」搴忓彿
+            String firstCell = row.getCell(0).getText().trim();
+            Integer itemCode = null;
+            try {
+                itemCode = Integer.parseInt(firstCell);
+            } catch (NumberFormatException e) {
+                //涓嶆槸妫�鏌ラ」鍐呭锛岃烦杩囨琛�
+                continue;
+            }
+            //鑾峰彇绗簩涓崟鍏冩牸
+            String secondCell = row.getCell(1).getText().trim();
+            //濡傛灉杩欎竴琛屼负搴忓彿鍒欒В鏋愭暣琛�
+            if (StringUtils.isNotBlank(secondCell)) {
+                item = new EamTechnicalStatusEvaluationStandardDetail();
+                item.setItemCode(itemCode);
+                item.setItemName(secondCell);
+                item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name());
+                items.add(item);
+            }
+        }
+        return items;
+    }
 }

--
Gitblit v1.9.3