From ad853219d4a8c85eaf8c51e66e6efc49df5433bc Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期三, 09 七月 2025 18:51:22 +0800
Subject: [PATCH] art: 技术状态鉴定规范3个导入-接口修改

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamTechnicalStatusEvaluationStandardServiceImpl.java |  627 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 590 insertions(+), 37 deletions(-)

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 8ba1b11..8bb7a21 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
@@ -6,36 +6,43 @@
 import com.baomidou.mybatisplus.core.metadata.IPage;
 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.eam.base.entity.BaseFactory;
-import org.jeecg.modules.eam.base.entity.BaseFactoryUser;
-import org.jeecg.modules.eam.base.service.IBaseFactoryService;
-import org.jeecg.modules.eam.base.service.IBaseFactoryUserService;
-import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum;
+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.EamMaintenanceStandard;
-import org.jeecg.modules.eam.entity.EamMaintenanceStandardDetail;
+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.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 com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -45,6 +52,7 @@
  * @Version: V1.0
  */
 @Service
+@Slf4j
 public class EamTechnicalStatusEvaluationStandardServiceImpl extends ServiceImpl<EamTechnicalStatusEvaluationStandardMapper, EamTechnicalStatusEvaluationStandard> implements IEamTechnicalStatusEvaluationStandardService {
 
     @Autowired
@@ -53,6 +61,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) {
@@ -72,9 +84,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_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;
             }
@@ -105,6 +117,10 @@
     @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())) {
+            //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫�
+            throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒");
+        }
         EamTechnicalStatusEvaluationStandard entity = new EamTechnicalStatusEvaluationStandard();
         BeanUtils.copyProperties(request, entity);
         entity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name());
@@ -116,16 +132,40 @@
         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());
             });
-            standardDetailService.saveBatch(request.getTableDetailList());
+            //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨
+            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)) {
+                    throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
+            }
+            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)) {
+                    throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
+            }
+            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)) {
+                    throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
+            }
         }
         return true;
     }
@@ -138,11 +178,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);
@@ -151,36 +191,549 @@
     @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())) {
+            //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫�
+            throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒");
+        }
         EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId());
-        if(entity == null){
+        if (entity == null) {
             throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
         }
         entity.setStandardName(request.getStandardName());
         entity.setEvaluationPeriod(request.getEvaluationPeriod());
+        entity.setHasOtherCheck(request.getHasOtherCheck());
+        entity.setHasPrecisionCheck(request.getHasPrecisionCheck());
+        entity.setHasSafetyEquipmentCheck(request.getHasSafetyEquipmentCheck());
+        entity.setRemark(request.getRemark());
         this.getBaseMapper().updateById(entity);
         //澶勭悊璇︽儏
-        if(CollectionUtil.isNotEmpty(request.getTableDetailList())) {
-            List<EamTechnicalStatusEvaluationStandardDetail> addList = new ArrayList<>();
-            List<EamTechnicalStatusEvaluationStandardDetail> updateList = new ArrayList<>();
+        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
+            //鍏堝垹闄ゆ鏌ラ」
+            standardDetailService.removeByStandardId(entity.getId());
             request.getTableDetailList().forEach(tableDetail -> {
                 tableDetail.setStandardId(entity.getId());
-                if(tableDetail.getId() == null){
-                    addList.add(tableDetail);
-                }else {
-                    updateList.add(tableDetail);
-                }
             });
-            if(CollectionUtil.isNotEmpty(addList)){
-                standardDetailService.saveBatch(addList);
+            //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨
+            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)) {
+                    throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
             }
-            if(CollectionUtil.isNotEmpty(updateList)){
-                standardDetailService.updateBatchById(updateList);
+            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)) {
+                    throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
             }
-        }
-        if(CollectionUtil.isNotEmpty(request.getRemoveDetailList())) {
-            List<String> ids = request.getRemoveDetailList().stream().map(EamTechnicalStatusEvaluationStandardDetail::getId).collect(Collectors.toList());
-            standardDetailService.removeBatchByIds(ids);
+            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)) {
+                    throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
+            }
         }
         return true;
     }
+
+    @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())) {
+            //蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫�
+            throw new JeecgBootException("蹇呴』瑕侀�夋嫨涓�涓鏌ュ垎绫伙紒");
+        }
+        EamTechnicalStatusEvaluationStandard entity = this.getBaseMapper().selectById(request.getId());
+        if (entity == null) {
+            throw new JeecgBootException("鍗囩増鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
+        }
+
+        //鏂板涓�涓増鏈�
+        EamTechnicalStatusEvaluationStandard newEntity = new EamTechnicalStatusEvaluationStandard();
+        newEntity.setStandardCode(request.getStandardCode());
+        newEntity.setStandardName(request.getStandardName());
+        newEntity.setEvaluationPeriod(request.getEvaluationPeriod());
+        newEntity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.ENABLE.name());
+        //鐗堟湰閫掑
+        newEntity.setStandardVersion(SimpleVersionGenerateUtil.addVersion(entity.getStandardVersion()));
+        //璁惧澶勭悊
+        newEntity.setEquipmentId(request.getEquipmentId());
+        newEntity.setHasOtherCheck(request.getHasOtherCheck());
+        newEntity.setHasPrecisionCheck(request.getHasPrecisionCheck());
+        newEntity.setHasSafetyEquipmentCheck(request.getHasSafetyEquipmentCheck());
+        //鍒犻櫎鏍囪
+        newEntity.setDelFlag(CommonConstant.DEL_FLAG_0);
+        newEntity.setRemark(request.getRemark());
+        //閲嶅鎬ф牎楠�
+        EamTechnicalStatusEvaluationStandard exist = checkDuplicate(newEntity.getEquipmentId(), entity.getId());
+        if (exist != null) {
+            throw new JeecgBootException("閴村畾瑙勮寖宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�");
+        }
+        this.getBaseMapper().insert(newEntity);
+        //澶勭悊鏄庣粏鏁版嵁
+        if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
+            request.getTableDetailList().forEach(tableDetail -> {
+                tableDetail.setId(null);
+                tableDetail.setCreateBy(null);
+                tableDetail.setUpdateBy(null);
+                tableDetail.setCreateTime(null);
+                tableDetail.setUpdateTime(null);
+                tableDetail.setStandardId(newEntity.getId());
+            });
+            //鏍规嵁鍒嗙被鍒ゆ柇鏄惁淇濆瓨
+            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)) {
+                    throw new JeecgBootException("鍏朵粬妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
+            }
+            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)) {
+                    throw new JeecgBootException("瀹夊叏瑁呯疆妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
+            }
+            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)) {
+                    throw new JeecgBootException("绮惧害妫�鏌ユ槑缁嗕笉鑳戒负绌猴紒");
+                }
+                standardDetailService.saveBatch(collect);
+            }
+        }
+        //绂佺敤鍘熸潵鐨勭増鏈�
+        entity.setStandardStatus(TechnicalStatusEvaluationStandardEnum.DISABLE.name());
+        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.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.SAFETY_EQUIPMENT_CHECK.name());
+                    //閲嶆柊娣诲姞
+                    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 (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error(fileName + ":" + e.getMessage() + "锛�");
+            }
+        } else {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+
+        return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�");
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> importPrecisionCheck(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.PRECISION_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 = extractPrecisionCheckItems(tables);
+                if(CollectionUtil.isEmpty(detailList)){
+                    return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒");
+                }
+                if(originalStandard != null) {
+                    //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜�
+                    originalStandard.setHasPrecisionCheck(CommonConstant.STATUS_1);
+                    originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name());
+                    super.getBaseMapper().updateById(originalStandard);
+                    detailList.forEach(standardDetail -> {
+                        standardDetail.setStandardId(originalStandard.getId());
+                    });
+                    //鍏堝垹闄わ紝鍚庢坊鍔�
+                    standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name());
+                    //閲嶆柊娣诲姞
+                    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_0);
+                    request.setHasOtherCheck(CommonConstant.STATUS_0);
+                    request.setHasPrecisionCheck(CommonConstant.STATUS_1);
+                    request.setStandardCode(codeSeq);
+                    request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�");
+                    request.setTableDetailList(detailList);
+                    this.addEamTechnicalStatusEvaluationStandard(request);
+                }
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error(fileName + ":" + e.getMessage() + "锛�");
+            }
+        } else {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+
+        return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�");
+    }
+
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> importOtherCheck(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.OTHER_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 = extractOtherCheckItems(tables);
+                if(CollectionUtil.isEmpty(detailList)){
+                    return Result.error(fileName + ":鏈В鏋愬埌妫�鏌ラ」鍐呭锛岃妫�鏌ワ紒");
+                }
+                if(originalStandard != null) {
+                    //宸插瓨鍦ㄦ妧鏈姸鎬侀壌瀹氳鑼�,涓旇鑼冪姸鎬佷负宸叉彁浜�
+                    originalStandard.setHasOtherCheck(CommonConstant.STATUS_1);
+                    originalStandard.setStandardStatus(TechnicalStatusEvaluationStandardEnum.WAIT_SUBMIT.name());
+                    super.getBaseMapper().updateById(originalStandard);
+                    detailList.forEach(standardDetail -> {
+                        standardDetail.setStandardId(originalStandard.getId());
+                    });
+                    //鍏堝垹闄わ紝鍚庢坊鍔�
+                    standardDetailService.removeByStandardIdAndCategory(originalStandard.getId(), TechnicalStatusEvaluationCheckCategoryEnum.OTHER_CHECK.name());
+                    //閲嶆柊娣诲姞
+                    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_0);
+                    request.setHasOtherCheck(CommonConstant.STATUS_1);
+                    request.setHasPrecisionCheck(CommonConstant.STATUS_0);
+                    request.setStandardCode(codeSeq);
+                    request.setStandardName(equipment.getEquipmentName() + "鎶�鏈姸鎬侀壌瀹氳鑼�");
+                    request.setTableDetailList(detailList);
+                    this.addEamTechnicalStatusEvaluationStandard(request);
+                }
+            } catch (Exception e) {
+                log.error(e.getMessage(), e);
+                return Result.error(fileName + ":" + e.getMessage() + "锛�");
+            }
+        } else {
+            return Result.error(fileName + ":鏂囦欢鏍煎紡閿欒,鏃犳硶瑙f瀽锛�");
+        }
+
+        return Result.OK(fileName + ":瀵煎叆鎴愬姛锛�");
+    }
+
+    /**
+     * 妫�鏌ュ鍏ユ枃浠跺垎绫绘槸鍚﹀尮閰�
+     * @param title 鏍囬娈佃惤瀛楃涓�
+     * @param category 鍒嗙被
+     * @return true 涓嶅尮閰嶏紝 false  鍖归厤
+     */
+    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 true;
+    }
+
+
+    /**
+     * 鎻愬彇璁惧鍩烘湰淇℃伅
+     */
+    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;
+    }
+
+    /**
+     * 鎻愬彇鍏朵粬妫�鏌ラ」鏄庣粏鍐呭
+     * @param tables
+     * @return
+     */
+    private List<EamTechnicalStatusEvaluationStandardDetail> extractOtherCheckItems(List<XWPFTable> tables) {
+        List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>();
+        EamTechnicalStatusEvaluationStandardDetail item = null;
+        //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭�
+        XWPFTable table = tables.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.OTHER_CHECK.name());
+                items.add(item);
+            }
+        }
+        return items;
+    }
+
+    private List<EamTechnicalStatusEvaluationStandardDetail> extractPrecisionCheckItems(List<XWPFTable> tables) {
+        List<EamTechnicalStatusEvaluationStandardDetail> items = new ArrayList<>();
+        EamTechnicalStatusEvaluationStandardDetail item = null;
+        //瑙f瀽绗竴涓〃鏍硷紝甯﹁澶囦俊鎭�
+        XWPFTable table = tables.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) {
+                //涓嶆槸妫�鏌ラ」鍐呭锛岃烦杩囨琛�
+                if(item == null) {
+                    continue;
+                }else {
+                    itemCode = item.getItemCode();
+                }
+            }
+            //鑾峰彇绗簩涓崟鍏冩牸
+            String itemName = row.getCell(1).getText().trim();
+            if(StringUtils.isBlank(itemName)) {
+                if(item != null) {
+                    itemName = item.getItemName();
+                }else {
+                    continue;
+                }
+            }
+            String subItemName = null;
+            String toleranceValue = null;
+            if(row.getTableCells().size() == 4) {
+                toleranceValue = row.getCell(2).getText().trim();
+            }else if(row.getTableCells().size() == 5) {
+                subItemName = row.getCell(2).getText().trim();
+                toleranceValue = row.getCell(3).getText().trim();
+            }else {
+                continue;
+            }
+            if(StringUtils.isBlank(toleranceValue)) {
+               //鍏佸樊鍊间笉瀛樺湪锛岃烦杩�
+               if(item != null) {
+                   toleranceValue = item.getToleranceValue();
+               }else {
+                   continue;
+               }
+            }
+            //鎷艰鏄庣粏鏁版嵁
+            item = new EamTechnicalStatusEvaluationStandardDetail();
+            item.setItemCode(itemCode);
+            item.setItemName(itemName);
+            item.setSubItemName(subItemName);
+            item.setToleranceValue(toleranceValue);
+            item.setCheckCategory(TechnicalStatusEvaluationCheckCategoryEnum.PRECISION_CHECK.name());
+            items.add(item);
+        }
+        return items;
+    }
+
 }

--
Gitblit v1.9.3