From 0c929802702bca00b24b8c74f52723b21ba5b4c2 Mon Sep 17 00:00:00 2001
From: zhangherong <571457620@qq.com>
Date: 星期五, 11 七月 2025 09:43:45 +0800
Subject: [PATCH] art: 查询岗位用户信息修改

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java |  762 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 409 insertions(+), 353 deletions(-)

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 4084807..73d7efd 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
@@ -10,12 +10,8 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.jeecg.weibo.exception.BusinessException;
-import liquibase.pro.packaged.R;
-import liquibase.pro.packaged.S;
-import lombok.extern.slf4j.Slf4j;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.poi.ss.usermodel.*;
-import org.apache.poi.xssf.usermodel.XSSFWorkbook;
 import org.apache.poi.xwpf.usermodel.*;
 import org.apache.shiro.SecurityUtils;
 import org.flowable.engine.TaskService;
@@ -24,10 +20,6 @@
 import org.jeecg.common.constant.CommonConstant;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
-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.BusinessCodeConst;
 import org.jeecg.modules.eam.constant.EamMaintenanceStandardDetailCategory;
 import org.jeecg.modules.eam.constant.MaintenanceStandardStatusEnum;
@@ -42,15 +34,17 @@
 import org.jeecg.modules.eam.service.IEamEquipmentService;
 import org.jeecg.modules.eam.service.IEamMaintenanceStandardDetailService;
 import org.jeecg.modules.eam.service.IEamMaintenanceStandardService;
-import org.jeecg.modules.eam.vo.*;
+import org.jeecg.modules.eam.vo.EamMaintenanceStandardVo;
 import org.jeecg.modules.flowable.apithird.business.entity.FlowMyBusiness;
 import org.jeecg.modules.flowable.apithird.business.service.IFlowMyBusinessService;
 import org.jeecg.modules.flowable.apithird.service.FlowCallBackServiceI;
 import org.jeecg.modules.flowable.apithird.service.FlowCommonService;
 import org.jeecg.modules.flowable.service.IFlowDefinitionService;
 import org.jeecg.modules.flowable.service.IFlowTaskService;
-import org.jeecg.modules.system.service.ISysBusinessCodeRuleService;
-import org.jeecg.modules.system.service.ISysUserService;
+import org.jeecg.modules.system.entity.BaseFactory;
+import org.jeecg.modules.system.entity.BaseFactoryUser;
+import org.jeecg.modules.system.entity.SysParams;
+import org.jeecg.modules.system.service.*;
 import org.jeecg.modules.system.vo.UserSelector;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -69,11 +63,11 @@
 /**
  * @Description: 淇濆吇鏍囧噯
  * @Author: jeecg-boot
- * @Date:   2025-03-26
+ * @Date: 2025-03-26
  * @Version: V1.0
  */
 @Service("IEamMaintenanceStandardService")
-public class EamMaintenanceStandardServiceImpl extends ServiceImpl<EamMaintenanceStandardMapper, EamMaintenanceStandard> implements IEamMaintenanceStandardService , FlowCallBackServiceI {
+public class EamMaintenanceStandardServiceImpl extends ServiceImpl<EamMaintenanceStandardMapper, EamMaintenanceStandard> implements IEamMaintenanceStandardService, FlowCallBackServiceI {
 
     @Resource
     private EamMaintenanceStandardMapper eamMaintenanceStandardMapper;
@@ -101,6 +95,8 @@
     private IEamEquipmentExtendService eamEquipmentExtendService;
     @Autowired
     private ISysBusinessCodeRuleService businessCodeRuleService;
+    @Autowired
+    private ISysParamsService sysParamsService;
 
     // 甯搁噺瀹氫箟
     private static final String REPAIR_TITLE = "缁翠慨浜哄憳淇濆吇鍐呭";
@@ -128,43 +124,45 @@
             queryWrapper.in("e.equipment_code", equipArr);
         } else {
             //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶�
-            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);
+            List<BaseFactoryUser> baseFactoryUserList = baseFactoryUserService.
+                    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> factoryCode = baseFactoryService.listByIds(factoryIds).stream().map(BaseFactory::getOrgCode).collect(Collectors.toSet());
+                queryWrapper.in("e.factory_org_code", factoryCode);
+            } else {
+                return page;
             }
         }
-        if(eamMaintenanceStandard != null) {
+        if (eamMaintenanceStandard != null) {
             //缂栫爜 妯$硦鏌ヨ
-            if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardCode())) {
+            if (StringUtils.isNotBlank(eamMaintenanceStandard.getStandardCode())) {
                 queryWrapper.like("ems.standard_code", eamMaintenanceStandard.getStandardCode());
             }
             //鍚嶇О 妯$硦鏌ヨ
-            if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardName())) {
+            if (StringUtils.isNotBlank(eamMaintenanceStandard.getStandardName())) {
                 queryWrapper.like("ems.standard_name", eamMaintenanceStandard.getStandardName());
             }
             //璁惧
-            if(StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentId())) {
+            if (StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentId())) {
                 queryWrapper.eq("ems.equipment_id", eamMaintenanceStandard.getEquipmentId());
             }
             //淇濆吇鍒嗙被
-            if(StringUtils.isNotBlank(eamMaintenanceStandard.getMaintenanceCategory())) {
+            if (StringUtils.isNotBlank(eamMaintenanceStandard.getMaintenanceCategory())) {
                 queryWrapper.eq("ems.maintenance_category", eamMaintenanceStandard.getMaintenanceCategory());
             }
             //淇濆吇鍒嗙被
-            if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardStatus())) {
+            if (StringUtils.isNotBlank(eamMaintenanceStandard.getStandardStatus())) {
                 queryWrapper.eq("ems.standard_status", eamMaintenanceStandard.getStandardStatus());
             }
             //璁惧缂栫爜
-            if(StringUtils.isNotBlank(eamMaintenanceStandard.getKeyword())) {
+            if (StringUtils.isNotBlank(eamMaintenanceStandard.getKeyword())) {
                 queryWrapper.and(wrapper -> wrapper.like("e.equipment_name", eamMaintenanceStandard.getKeyword())
                         .or()
                         .like("e.equipment_code", eamMaintenanceStandard.getKeyword()));
             }
             //id
-            if(StringUtils.isNotBlank(eamMaintenanceStandard.getId())) {
+            if (StringUtils.isNotBlank(eamMaintenanceStandard.getId())) {
                 queryWrapper.eq("ems.id", eamMaintenanceStandard.getId());
             }
         }
@@ -179,19 +177,19 @@
         BeanUtils.copyProperties(standardRequest, entity);
         entity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
         //鐗堟湰閫掑
-        entity.setStandardVersion("v"+CommonConstant.OPERATE_TYPE_1);
+        entity.setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1);
         //璁惧澶勭悊
         entity.setEquipmentId(standardRequest.getEquipmentId());
         //鍒犻櫎鏍囪
         entity.setDelFlag(CommonConstant.DEL_FLAG_0);
         //閲嶅鎬ф牎楠�
-        EamMaintenanceStandard exist = checkDuplicate(entity.getEquipmentId(), entity.getMaintenanceCategory());
-        if(exist != null){
+        EamMaintenanceStandard exist = checkDuplicate(entity.getEquipmentId(), entity.getMaintenanceCategory(), MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+        if (exist != null) {
             throw new JeecgBootException("璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�");
         }
         eamMaintenanceStandardMapper.insert(entity);
         //澶勭悊鏄庣粏鏁版嵁
-        if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) {
+        if (CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) {
             standardRequest.getTableDetailList().forEach(tableDetail -> {
                 tableDetail.setStandardId(entity.getId());
             });
@@ -204,32 +202,32 @@
     @Transactional(rollbackFor = Exception.class)
     public boolean editMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) {
         EamMaintenanceStandard entity = eamMaintenanceStandardMapper.selectById(standardRequest.getId());
-        if(entity == null){
+        if (entity == null) {
             throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
         }
         entity.setStandardName(standardRequest.getStandardName());
         entity.setMaintenancePeriod(standardRequest.getMaintenancePeriod());
         eamMaintenanceStandardMapper.updateById(entity);
         //澶勭悊璇︽儏
-        if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) {
+        if (CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) {
             List<EamMaintenanceStandardDetail> addList = new ArrayList<>();
             List<EamMaintenanceStandardDetail> updateList = new ArrayList<>();
             standardRequest.getTableDetailList().forEach(tableDetail -> {
                 tableDetail.setStandardId(entity.getId());
-                if(tableDetail.getId() == null){
+                if (tableDetail.getId() == null) {
                     addList.add(tableDetail);
-                }else {
+                } else {
                     updateList.add(tableDetail);
                 }
             });
-            if(CollectionUtil.isNotEmpty(addList)){
+            if (CollectionUtil.isNotEmpty(addList)) {
                 eamMaintenanceStandardDetailService.saveBatch(addList);
             }
-            if(CollectionUtil.isNotEmpty(updateList)){
+            if (CollectionUtil.isNotEmpty(updateList)) {
                 eamMaintenanceStandardDetailService.updateBatchById(updateList);
             }
         }
-        if(CollectionUtil.isNotEmpty(standardRequest.getRemoveDetailList())) {
+        if (CollectionUtil.isNotEmpty(standardRequest.getRemoveDetailList())) {
             List<String> ids = standardRequest.getRemoveDetailList().stream().map(EamMaintenanceStandardDetail::getId).collect(Collectors.toList());
             eamMaintenanceStandardDetailService.removeBatchByIds(ids);
         }
@@ -240,7 +238,7 @@
     @Transactional(rollbackFor = Exception.class)
     public boolean upgradeMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) {
         EamMaintenanceStandard entity = eamMaintenanceStandardMapper.selectById(standardRequest.getId());
-        if(entity == null){
+        if (entity == null) {
             throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
         }
 
@@ -251,6 +249,7 @@
         newEntity.setMaintenanceCategory(standardRequest.getMaintenanceCategory());
         newEntity.setMaintenancePeriod(standardRequest.getMaintenancePeriod());
         newEntity.setInitialDate(standardRequest.getInitialDate());
+        newEntity.setPeriodUnit(standardRequest.getPeriodUnit());
         newEntity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
         //鐗堟湰閫掑
         //鑾峰彇鏁板瓧
@@ -259,7 +258,7 @@
         if (matcher.find()) {
             try {
                 int mainVersion = Integer.parseInt(matcher.group(1));
-                newEntity.setStandardVersion("v"+(mainVersion+1));
+                newEntity.setStandardVersion("v" + (mainVersion + 1));
             } catch (NumberFormatException ignored) {
             }
         }
@@ -268,13 +267,13 @@
         //鍒犻櫎鏍囪
         newEntity.setDelFlag(CommonConstant.DEL_FLAG_0);
         //閲嶅鎬ф牎楠�
-        EamMaintenanceStandard exist = checkDuplicate(newEntity.getEquipmentId(), newEntity.getMaintenanceCategory());
-        if(exist != null){
+        EamMaintenanceStandard exist = checkDuplicate(newEntity.getEquipmentId(), newEntity.getMaintenanceCategory(), MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+        if (exist != null) {
             throw new JeecgBootException("璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�");
         }
         eamMaintenanceStandardMapper.insert(newEntity);
         //澶勭悊鏄庣粏鏁版嵁
-        if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) {
+        if (CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) {
             standardRequest.getTableDetailList().forEach(tableDetail -> {
                 tableDetail.setId(null);
                 tableDetail.setCreateBy(null);
@@ -289,16 +288,16 @@
     }
 
     @Override
-    public EamMaintenanceStandard checkDuplicate(String equipmentId, String maintenanceCategory) {
+    public EamMaintenanceStandard checkDuplicate(String equipmentId, String maintenanceCategory, String standardStatus) {
         LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, equipmentId);
         queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory);
         queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0);
-        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, standardStatus);
         queryWrapper.orderByDesc(EamMaintenanceStandard::getStandardVersion);
 
         List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper);
-        if(CollectionUtil.isEmpty(list)) {
+        if (CollectionUtil.isEmpty(list)) {
             return null;
         }
         return list.get(0);
@@ -306,12 +305,13 @@
 
     /**
      * 鏌ヨ鏍囧噯鍒楄〃-鍓嶇灞曠ず璇ョ敤鎴锋嫢鏈夌殑鏍囧噯
-     * @param keyword 璁惧缂栧彿
+     *
+     * @param keyword             璁惧缂栧彿
      * @param maintenanceCategory 淇濆吇绫诲瀷
      * @return
      */
     @Override
-    public List<EamMaintenanceStandard> queryListByKeywordAndCategory(String keyword, String equipmentId, Integer pageSize, String maintenanceCategory){
+    public List<EamMaintenanceStandard> queryListByKeywordAndCategory(String keyword, String equipmentId, Integer pageSize, String maintenanceCategory) {
         Page<EamMaintenanceStandard> page = new Page<EamMaintenanceStandard>(1, pageSize);
         EamMaintenanceStandard query = new EamMaintenanceStandard();
         query.setEquipmentId(equipmentId);
@@ -327,7 +327,7 @@
         LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0);
         queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory);
-        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.START.name());
         return eamMaintenanceStandardMapper.selectList(queryWrapper);
     }
 
@@ -336,28 +336,29 @@
 
     /**
      * 娴佺▼鍚姩,淇濆瓨瀵瑰簲鐨勬暟鎹�
+     *
      * @param id
      * @return
      */
     @Override
-    public Result<?> saveEamMaintenanceStandardProcess(String id){
+    public Result<?> saveEamMaintenanceStandardProcess(String id) {
         LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
-        EamMaintenanceStandard maintenanceStandard=this.getById(id);
-        if (maintenanceStandard==null){
+        EamMaintenanceStandard maintenanceStandard = this.getById(id);
+        if (maintenanceStandard == null) {
             return Result.error("鏈壘鍒板搴斾繚鍏绘爣鍑�");
         }
         System.out.println("淇濆吇瑙勮寖娴佺▼锛�" + maintenanceStandard.getId());
-        flowCommonService.initActBusiness(maintenanceStandard.getStandardName()+"瑙勮寖杩涜娴佺▼瀹℃牳",
+        flowCommonService.initActBusiness(maintenanceStandard.getStandardName() + "瑙勮寖杩涜娴佺▼瀹℃牳",
                 maintenanceStandard.getId(), "IEamMaintenanceStandardService", "eam_maintenance_standard", null);
         Map<String, Object> variables = new HashMap<>();
         variables.put("dataId", maintenanceStandard.getId());
         variables.put("organization", "淇濆吇瑙勮寖鍚姩娴佺▼");
         variables.put("comment", "淇濆吇瑙勮寖鍚姩娴佺▼");
-        variables.put("proofreading",true);
-        Result result= flowDefinitionService.startProcessInstanceByKey("eam_maintenance_standard", variables);
+        variables.put("proofreading", true);
+        Result result = flowDefinitionService.startProcessInstanceByKey("eam_maintenance_standard", variables);
         if (!result.isSuccess()) {
             super.removeById(maintenanceStandard.getId());
-        }else {
+        } else {
             maintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name());
             maintenanceStandard.setDesigner(user.getUsername());
             maintenanceStandard.setDesignTime(new Date());
@@ -371,11 +372,10 @@
                 return Result.error("娴佺▼璁板綍涓嶅瓨鍦�");
             }
             FlowMyBusiness flowMyBusiness = businessList.get(0);
-            EamEquipment eamEquipment=eamEquipmentService.getById(maintenanceStandard.getEquipmentId());
-            BaseFactory baseFactory=baseFactoryService.getOne(new QueryWrapper<BaseFactory>().eq("org_code", eamEquipment.getFactoryOrgCode()));
-            List<UserSelector> userSelectorList=sysUserService.selectOperatorFactoryList(eamEquipment.getEquipmentCode(),baseFactory.getId(), BusinessCodeConst.PCR0007);
+            EamEquipment eamEquipment = eamEquipmentService.getById(maintenanceStandard.getEquipmentId());
+            List<UserSelector> userSelectorList = sysUserService.selectOperatorList(eamEquipment.getEquipmentCode(), eamEquipment.getFactoryOrgCode(), BusinessCodeConst.PCR0008);
             if (!CollectionUtils.isEmpty(userSelectorList)) {
-                List<String> usernameList=userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
+                List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                 flowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList));
                 flowMyBusinessService.updateById(flowMyBusiness);
             }
@@ -385,11 +385,12 @@
 
     /**
      * 瀹℃壒鎿嶄綔
+     *
      * @param eamMaintenanceStandardVo
      * @return
      */
     @Override
-    public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo){
+    public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo) {
         try {
             // 鍙傛暟鏍¢獙
             if (StrUtil.isEmpty(eamMaintenanceStandardVo.getTaskId()) || StrUtil.isEmpty(eamMaintenanceStandardVo.getDataId())) {
@@ -443,23 +444,22 @@
             Result result = flowTaskService.complete(eamMaintenanceStandardVo);
             if (result.isSuccess()) {
                 if (eamMaintenanceStandardVo.getRepairManagerApproveResult() != null) {
-                    if (eamMaintenanceStandardVo.getRepairManagerApproveResult().equals("1")){
+                    if (eamMaintenanceStandardVo.getRepairManagerApproveResult().equals("1")) {
                         List<FlowMyBusiness> newbusinessList = flowMyBusinessService.list(
                                 new QueryWrapper<FlowMyBusiness>()
                                         .eq("process_instance_id", eamMaintenanceStandardVo.getInstanceId()));
                         FlowMyBusiness newflowMyBusiness = newbusinessList.get(0);
                         eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_TECHNICAL_DIRECTOR.name());
                         //鑾峰彇flow鐨勬祦绋嬪疄渚媔d,璁剧疆涓嬩竴姝ョ殑澶勭悊浜哄憳
-                        EamMaintenanceStandard maintenanceStandard=this.getById(eamMaintenanceStandardVo.getDataId());
-                        EamEquipment eamEquipment=eamEquipmentService.getById(maintenanceStandard.getEquipmentId());
-                        BaseFactory baseFactory=baseFactoryService.getOne(new QueryWrapper<BaseFactory>().eq("org_code", eamEquipment.getFactoryOrgCode()));
-                        List<UserSelector> userSelectorList=sysUserService.selectOperatorFactoryList(eamEquipment.getEquipmentCode(),baseFactory.getId(), BusinessCodeConst.PCR0008);
+                        EamMaintenanceStandard maintenanceStandard = this.getById(eamMaintenanceStandardVo.getDataId());
+                        EamEquipment eamEquipment = eamEquipmentService.getById(maintenanceStandard.getEquipmentId());
+                        List<UserSelector> userSelectorList = sysUserService.selectOperatorList(eamEquipment.getEquipmentCode(), eamEquipment.getFactoryOrgCode(), BusinessCodeConst.PCR0009);
                         if (!CollectionUtils.isEmpty(userSelectorList)) {
-                            List<String> usernameList=userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
+                            List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                             newflowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList));
                             flowMyBusinessService.updateById(newflowMyBusiness);
                         }
-                    }else {
+                    } else {
                         eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
                     }
                     eamMaintenanceStandard.setRepairManager(user.getUsername());
@@ -468,15 +468,15 @@
                     eamMaintenanceStandard.setRepairManagerApproveComment(eamMaintenanceStandardVo.getComment());
                 }
                 if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult() != null) {
-                    if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("1")){
+                    if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("1")) {
                         eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.START.name());
                         //鍒ゆ柇鏄惁杩涜鍗囩増锛岄�氳繃璁惧缂栧彿銆佷繚鍏诲垎绫汇�佺姸鎬佽繘琛岀瓫閫�
-                        EamMaintenanceStandard maintenanceStandard=this.getById(eamMaintenanceStandardVo.getDataId());
-                        QueryWrapper<EamMaintenanceStandard> queryWrapper=new QueryWrapper<>();
+                        EamMaintenanceStandard maintenanceStandard = this.getById(eamMaintenanceStandardVo.getDataId());
+                        QueryWrapper<EamMaintenanceStandard> queryWrapper = new QueryWrapper<>();
                         queryWrapper.eq("equipment_id", maintenanceStandard.getEquipmentId());
                         queryWrapper.eq("maintenance_category", maintenanceStandard.getMaintenanceCategory());
                         queryWrapper.eq("standard_status", MaintenanceStandardStatusEnum.START.name());
-                        List<EamMaintenanceStandard> list=eamMaintenanceStandardMapper.selectList(queryWrapper);
+                        List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper);
                         if (!CollectionUtils.isEmpty(list)) {
                             //浣滃簾鍘熸湁
                             for (EamMaintenanceStandard eamMaintenanceStandard1 : list) {
@@ -484,7 +484,7 @@
                                 this.updateById(eamMaintenanceStandard1);
                             }
                         }
-                    }else {
+                    } else {
                         eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
                     }
                     eamMaintenanceStandard.setTechnicalManager(user.getUsername());
@@ -547,9 +547,10 @@
 
 
     /*瀵煎叆鐐规鏂囦欢Excel--------------------------寮�濮�*/
+
     /**
-        * 鐐规琛ㄥ鍏ュ叆鍙�
-    */
+     * 鐐规琛ㄥ鍏ュ叆鍙�
+     */
     @Override
     @Transactional(rollbackFor = Exception.class)
     public Result<?> importPointInspectionExcel(MultipartFile file) {
@@ -563,20 +564,30 @@
             EamMaintenanceStandard eamMaintenanceStandard = extractDeviceInfo(sheet);
             if (eamMaintenanceStandard == null) {
                 return Result.error("璁惧淇℃伅鎻愬彇澶辫触");
+            } else {
+                if (eamMaintenanceStandard.getEquipmentId() == null) {
+                    return Result.error("璁惧淇℃伅鎻愬彇澶辫触");
+                }
             }
 
             eamMaintenanceStandard.setStandardName(name);
+
+            EamMaintenanceStandard exist = checkDuplicate(eamMaintenanceStandard.getEquipmentId(), eamMaintenanceStandard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.START.name());
+            if (exist != null) {
+                return Result.error(name + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞");
+            }
+
             eamMaintenanceStandardMapper.insert(eamMaintenanceStandard);
 
             // 2. 鎻愬彇姣忔棩鐐规椤圭洰
             List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard);
-            if(dailyDetails.isEmpty()){
+            if (dailyDetails.isEmpty()) {
                 return Result.error("鏈壘鍒版瘡鏃ョ偣妫�椤圭洰");
             }
 
             // 3. 鎻愬彇鍛ㄤ繚鍏婚」鐩�
             List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard);
-            if(weeklyDetails.isEmpty()){
+            if (weeklyDetails.isEmpty()) {
                 return Result.error("鏈壘鍒板懆淇濆吇椤圭洰");
             }
 
@@ -589,6 +600,18 @@
                 eamMaintenanceStandardDetailService.saveBatch(allDetails);
             }
 
+            SysParams sysParams = sysParamsService.getSysPramBySettingKey("maintenance_import_type");
+
+            if (sysParams != null) {
+                if (sysParams.getSettingValue().equals("1")) {
+                    //瑙﹀彂淇濆吇娴佺▼
+                    eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+                    eamMaintenanceStandardMapper.updateById(eamMaintenanceStandard);
+                }
+            } else {
+                return Result.error("鏈壘鍒颁繚鍏绘祦绋嬪鍏ョ浉鍏抽厤缃�,璇疯仈绯荤鐞嗗憳");
+            }
+
             return Result.OK("鐐规琛ㄥ鍏ユ垚鍔�");
 
         } catch (Exception e) {
@@ -597,8 +620,8 @@
     }
 
     /**
-        * 鎻愬彇鐐规琛ㄦ爣棰�
-    */
+     * 鎻愬彇鐐规琛ㄦ爣棰�
+     */
     private String extractInspectionTitle(MultipartFile file) {
         try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
             Sheet sheet = workbook.getSheetAt(0);
@@ -622,7 +645,7 @@
     }
 
     /**
-        * 鎻愬彇鐐规琛ㄤ箣鍓嶇殑鏂囧瓧
+     * 鎻愬彇鐐规琛ㄤ箣鍓嶇殑鏂囧瓧
      */
     private String extractTextBeforeInspection(String title) {
         if (StringUtils.isBlank(title)) {
@@ -634,8 +657,8 @@
     }
 
     /**
-        * 鎻愬彇璁惧淇℃伅
-    */
+     * 鎻愬彇璁惧淇℃伅
+     */
     private EamMaintenanceStandard extractDeviceInfo(Sheet sheet) {
         Row headerRow = sheet.getRow(0);
         if (headerRow == null) {
@@ -649,6 +672,7 @@
 
         EamMaintenanceStandard standard = new EamMaintenanceStandard();
         standard.setEquipmentName(extractField(headerText, "璁惧鍚嶇О[:锛歖\\s*(\\S+)"));
+        standard.setEquipmentCode(extractField(headerText, "缁熶竴缂栧彿[:锛歖\\s*(\\S+)"));
 
 
         // 鏃ユ湡澶勭悊
@@ -665,22 +689,14 @@
         }
 
         // 鍏宠仈璁惧ID
-        if (isNotBlank(standard.getEquipmentCode()) &&
-                isNotBlank(standard.getEquipmentName())) {
-
-            List<EamEquipment> equipments = eamEquipmentService.list(
-                    new QueryWrapper<EamEquipment>()
-                            .eq("equipment_code", standard.getEquipmentCode())
-                            .eq("equipment_name", standard.getEquipmentName())
-            );
-
-            if (!equipments.isEmpty()) {
-                standard.setEquipmentId(equipments.get(0).getId());
-            }else {
+        if (StrUtil.isNotEmpty(standard.getEquipmentCode())) {
+            EamEquipment equipments = eamEquipmentService.selectByEquipmentCode(standard.getEquipmentCode());
+            if (equipments == null) {
                 return null;
+            } else {
+                standard.setEquipmentId(equipments.getId());
             }
         }
-
         String codeSeq = businessCodeRuleService.generateBusinessCodeSeq(BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE);
         standard.setStandardCode(codeSeq);
         standard.setMaintenanceCategory("POINT_INSPECTION");
@@ -694,7 +710,7 @@
     }
 
     /**
-        * 瑙f瀽鏃ユ湡瀛楃涓�
+     * 瑙f瀽鏃ユ湡瀛楃涓�
      */
     private Date parseDate(String dateStr) throws ParseException {
         // 灏濊瘯澶氱鏃ユ湡鏍煎紡
@@ -720,22 +736,22 @@
     }
 
     /**
-        * 鎻愬彇姣忔棩鐐规椤圭洰
-    */
+     * 鎻愬彇姣忔棩鐐规椤圭洰
+     */
     private List<EamMaintenanceStandardDetail> extractDailyItems(Sheet sheet, EamMaintenanceStandard standard) {
         return extractItems(sheet, standard, "鐐规椤圭洰", "瀹屾垚鏁版嵁/瑕佹眰", "DAY_INSPECTION");
     }
 
     /**
-        * 鎻愬彇鍛ㄤ繚鍏婚」鐩�
-    */
+     * 鎻愬彇鍛ㄤ繚鍏婚」鐩�
+     */
     private List<EamMaintenanceStandardDetail> extractWeeklyItems(Sheet sheet, EamMaintenanceStandard standard) {
         return extractItems(sheet, standard, "鍛ㄤ繚鍏婚」鐩�", "妫�鏌ユ爣鍑�", "WEEK_INSPECTION");
     }
 
     /**
-        * 閫氱敤椤圭洰鎻愬彇鏂规硶
-    */
+     * 閫氱敤椤圭洰鎻愬彇鏂规硶
+     */
     private List<EamMaintenanceStandardDetail> extractItems(Sheet sheet, EamMaintenanceStandard standard,
                                                             String primaryHeader, String secondaryHeader,
                                                             String itemCategory) {
@@ -760,6 +776,7 @@
             // 鍒涘缓椤圭洰璇︽儏
             EamMaintenanceStandardDetail detail = new EamMaintenanceStandardDetail();
             detail.setStandardId(standard.getId());
+            detail.setItemCode(Integer.parseInt(getCellStringValue(row.getCell(0))));
             detail.setItemName(getCellStringValue(row.getCell(1)));
             detail.setItemCategory(itemCategory);
 
@@ -777,7 +794,7 @@
     }
 
     /**
-        * 鏌ユ壘琛ㄦ牸鍖哄煙
+     * 鏌ユ壘琛ㄦ牸鍖哄煙
      */
     private int[] findTableSection(Sheet sheet, String primaryHeader, String secondaryHeader) {
         for (int rowIdx = 0; rowIdx <= sheet.getLastRowNum(); rowIdx++) {
@@ -794,8 +811,8 @@
     }
 
     /**
-        * 妫�鏌ユ槸鍚︿负琛ㄥご琛�
-    */
+     * 妫�鏌ユ槸鍚︿负琛ㄥご琛�
+     */
     private boolean isHeaderRow(Row row, String header1, String header2) {
         boolean foundHeader1 = false;
         boolean foundHeader2 = false;
@@ -813,7 +830,7 @@
     }
 
     /**
-        * 鏌ユ壘鏁版嵁缁撴潫浣嶇疆
+     * 鏌ユ壘鏁版嵁缁撴潫浣嶇疆
      */
     private int findDataEnd(Sheet sheet, int startRow) {
         for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) {
@@ -834,8 +851,8 @@
     }
 
     /**
-        * 璇嗗埆绛惧瓧琛岀壒寰�
-    */
+     * 璇嗗埆绛惧瓧琛岀壒寰�
+     */
     private boolean isSignatureRow(Row row) {
         for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
             Cell cell = row.getCell(colIdx);
@@ -852,7 +869,7 @@
 
     /**
      * 璇嗗埆鏂拌〃澶村紑濮�
-    */
+     */
     private boolean isNewHeaderStart(Row row) {
         for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
             Cell cell = row.getCell(colIdx);
@@ -867,8 +884,8 @@
     }
 
     /**
-        * 妫�鏌ヨ鏄惁涓虹┖
-    */
+     * 妫�鏌ヨ鏄惁涓虹┖
+     */
     private boolean isEmptyRow(Row row) {
         if (row == null) return true;
         for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
@@ -884,8 +901,8 @@
     }
 
     /**
-        * 浣跨敤姝e垯鎻愬彇瀛楁
-    */
+     * 浣跨敤姝e垯鎻愬彇瀛楁
+     */
     private String extractField(String text, String regex) {
         if (StringUtils.isBlank(text)) return "";
         Pattern pattern = Pattern.compile(regex);
@@ -894,8 +911,8 @@
     }
 
     /**
-        * 鑾峰彇鍗曞厓鏍煎瓧绗︿覆鍊�
-    */
+     * 鑾峰彇鍗曞厓鏍煎瓧绗︿覆鍊�
+     */
     private String getCellStringValue(Cell cell) {
         if (cell == null) return "";
         switch (cell.getCellType()) {
@@ -916,8 +933,8 @@
     }
 
     /**
-        * 澶勭悊鍏紡鍗曞厓鏍�
-    */
+     * 澶勭悊鍏紡鍗曞厓鏍�
+     */
     private String handleFormulaCell(Cell cell) {
         try {
             FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
@@ -926,10 +943,14 @@
             if (cellValue == null) return "";
 
             switch (cellValue.getCellType()) {
-                case STRING: return cellValue.getStringValue();
-                case NUMERIC: return String.valueOf((int) cellValue.getNumberValue());
-                case BOOLEAN: return String.valueOf(cellValue.getBooleanValue());
-                default: return "";
+                case STRING:
+                    return cellValue.getStringValue();
+                case NUMERIC:
+                    return String.valueOf((int) cellValue.getNumberValue());
+                case BOOLEAN:
+                    return String.valueOf(cellValue.getBooleanValue());
+                default:
+                    return "";
             }
         } catch (Exception e) {
             return "";
@@ -938,8 +959,10 @@
     /*瀵煎叆鐐规鏂囦欢Excel--------------------------缁撴潫*/
 
     /*瀵煎叆浜屼繚涓変繚鏂囦欢Excel--------------------------寮�濮�*/
+
     /**
      * 缁熶竴淇濆吇瑙勮寖瀵煎叆鍏ュ彛
+     *
      * @param file 涓婁紶鏂囦欢
      * @param type 淇濆吇绫诲瀷 (SECOND/THIRD)
      * @return 瀵煎叆缁撴灉锛堝寘鍚垚鍔�/澶辫触淇℃伅锛�
@@ -955,41 +978,81 @@
                 return Result.error(fileName + ": 鏂囨。涓湭鎵惧埌琛ㄦ牸");
             }
 
-            XWPFTable table = doc.getTables().get(0);
+            List<XWPFTable> tables = doc.getTables();
+            EamMaintenanceStandard standard = null;
+            List<EamMaintenanceStandardDetail> items = new ArrayList<>();
+            String standardId = null;
 
-            // 鏂囨。绫诲瀷鏍¢獙 - 闃叉浜屼繚浼犲叆涓変繚鎴栧弽涔�
-            if (isWrongDocumentType(table, type)) {
-                return Result.error(fileName + ": 鏂囨。绫诲瀷涓嶅尮閰� - " +
-                        ("SECOND".equals(type) ? "璇峰鍏ヤ簩绾т繚鍏绘枃妗�" : "璇峰鍏ヤ笁绾т繚鍏绘枃妗�"));
+            // 1. 澶勭悊鎵�鏈夎〃鏍�
+            for (int i = 0; i < tables.size(); i++) {
+                XWPFTable table = tables.get(i);
+
+                if (i == 0) { // 绗竴椤佃〃鏍�
+                    // 楠岃瘉璁惧淇℃伅琛ㄦ牸
+                    if (isWrongDocumentType(table, type)) {
+                        return Result.error(fileName + ": 鏂囨。绫诲瀷涓嶅尮閰� - " +
+                                ("SECOND".equals(type) ? "璇峰鍏ヤ簩绾т繚鍏绘枃妗�" : "璇峰鍏ヤ笁绾т繚鍏绘枃妗�"));
+                    }
+
+                    // 鎻愬彇璁惧淇℃伅
+                    standard = extractDeviceInfo(table, type);
+                    if (standard == null) {
+                        return Result.error(fileName + ": 璁惧淇℃伅鎻愬彇澶辫触");
+                    }
+
+                    // 閰嶇疆绫诲瀷鐩稿叧鍙傛暟
+                    configureStandard(standard, type, file);
+                    EamMaintenanceStandard exist = checkDuplicate(standard.getEquipmentId(), standard.getMaintenanceCategory(), MaintenanceStandardStatusEnum.START.name());
+                    if (exist != null) {
+                        return Result.error(fileName + ": 璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞");
+                    }
+                    eamMaintenanceStandardMapper.insert(standard);
+                    standardId = standard.getId();
+
+                    // 鎻愬彇绗竴椤电殑淇濆吇椤圭洰
+                    if ("SECOND".equals(type)) {
+                        items.addAll(extractSecondMaintenanceItems(table, standardId, true));
+                    } else if ("THIRD".equals(type)) {
+                        items.addAll(extractThirdMaintenanceItems(table, standardId, true));
+                    }
+
+                } else { // 鍚庣画椤甸潰
+                    // 鎻愬彇鍚庣画椤甸潰鐨勪繚鍏婚」鐩�
+                    if ("SECOND".equals(type)) {
+                        items.addAll(extractSecondMaintenanceItems(table, standardId, false));
+                    } else if ("THIRD".equals(type)) {
+                        items.addAll(extractThirdMaintenanceItems(table, standardId, false));
+                    }
+                }
             }
 
-            EamMaintenanceStandard standard = extractDeviceInfo(table);
+            // 楠岃瘉璁惧淇℃伅鎻愬彇
             if (standard == null) {
                 return Result.error(fileName + ": 璁惧淇℃伅鎻愬彇澶辫触");
             }
 
-            // 閰嶇疆绫诲瀷鐩稿叧鍙傛暟
-            configureStandard(standard, type, file);
-            eamMaintenanceStandardMapper.insert(standard);
-            String standardId = standard.getId();
+            // 2. 鍚庡鐞嗭細鏍规嵁涓嶅悓绫诲瀷杩涜澶勭悊
+            processItemsAfterExtraction(items, type);
 
-            // 鎻愬彇淇濆吇椤圭洰
-            List<EamMaintenanceStandardDetail> items;
-            if ("SECOND".equals(type)) {
-                items = extractSecondMaintenanceItems(table, standardId);
-            } else if ("THIRD".equals(type)) {
-                items = extractThirdMaintenanceItems(table, standardId);
-            } else {
-                return Result.error(fileName + ": 涓嶆敮鎸佺殑淇濆吇绫诲瀷: " + type);
-            }
-
-            // 椤圭洰楠岃瘉
+            // 3. 椤圭洰楠岃瘉
             if (items.isEmpty()) {
                 return Result.error(fileName + ": 鏈彁鍙栧埌浠讳綍淇濆吇椤圭洰");
             }
 
-            // 淇濆瓨椤圭洰
+            // 4. 淇濆瓨椤圭洰
             eamMaintenanceStandardDetailService.saveBatch(items);
+
+
+            SysParams sysParams = sysParamsService.getSysPramBySettingKey("maintenance_import_type");
+
+            if (sysParams != null) {
+                if (sysParams.getSettingValue().equals("1")) {
+                    standard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+                    eamMaintenanceStandardMapper.updateById(standard);
+                }
+            } else {
+                return Result.error("鏈壘鍒颁繚鍏绘祦绋嬪鍏ョ浉鍏抽厤缃�,璇疯仈绯荤鐞嗗憳");
+            }
 
             return Result.ok(fileName + ": 瀵煎叆鎴愬姛, 椤圭洰鏁�: " + items.size());
 
@@ -1001,8 +1064,199 @@
     }
 
     /**
+     * 鍚庡鐞嗘柟娉曪細鏍规嵁涓嶅悓绫诲瀷杩涜澶勭悊
+     */
+    private void processItemsAfterExtraction(List<EamMaintenanceStandardDetail> items, String type) {
+        if ("SECOND".equals(type)) {
+            // 浜岀骇淇濆吇: 鍒犻櫎娌℃湁搴忓彿鐨勬暟鎹�
+            items.removeIf(item -> item.getItemCode() == null);
+        } else {
+            // 涓夌骇淇濆吇:
+            // 1. 鍒犻櫎绗竴鏉℃暟鎹紙閫氬父鏄爣棰樿锛�
+            if (!items.isEmpty()) {
+                items.remove(0);
+            }
+            // 2. 涓虹己澶遍儴浣嶇殑鏁版嵁濉厖鍓嶄竴鏉$殑淇濆吇閮ㄤ綅
+            String lastPart = "";
+            int i = 1;
+            for (EamMaintenanceStandardDetail item : items) {
+                item.setItemCode(i);
+                if (item.getItemPart() != null && !item.getItemPart().isEmpty()) {
+                    lastPart = item.getItemPart();
+                } else if (!lastPart.isEmpty()) {
+                    item.setItemPart(lastPart);
+                }
+                i++;
+            }
+        }
+    }
+
+    /**
+     * 鎻愬彇浜岀骇淇濆吇椤圭洰锛堝尯鍒嗙涓�椤靛拰鍚庣画椤甸潰锛�
+     */
+    private List<EamMaintenanceStandardDetail> extractSecondMaintenanceItems(
+            XWPFTable table, String standardId, boolean isFirstTable) {
+
+        List<EamMaintenanceStandardDetail> items = new ArrayList<>();
+        String currentCategory = null;
+        int startRow = 0;
+
+        // 瀵逛簬绗竴椤佃〃鏍硷紝璺宠繃鍓嶄袱琛岋紙璁惧淇℃伅琛岋級
+        if (isFirstTable && table.getNumberOfRows() > 2) {
+            startRow = 2; // 浠庣涓夎寮�濮嬫槸淇濆吇鍐呭
+        }
+
+        for (int i = startRow; i < table.getNumberOfRows(); i++) {
+            XWPFTableRow row = table.getRow(i);
+            if (row == null) continue;
+
+            // 妫�鏌ユ槸鍚︽槸鏍囬琛岋紙缁翠慨浜哄憳淇濆吇鍐呭鎴栨搷浣滀汉鍛樹繚鍏诲唴瀹癸級
+            String firstCell = getCellText(row.getCell(0));
+            // 澶勭悊绌鸿鍚庣殑閮ㄤ綅缁ф壙
+            if (firstCell.contains(REPAIR_TITLE)) {
+                currentCategory = "REPAIRER_MAINTENANCE";
+            } else if (firstCell.contains(OPERATOR_TITLE)) {
+                currentCategory = "OPERATOR_MAINTENANCE";
+            }
+
+            // 澶勭悊鏅�氶」鐩
+            if (currentCategory != null && isValidItemRow(row)) {
+                EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail();
+                item.setItemCategory(currentCategory);
+                item.setStandardId(standardId);
+
+                // 鎻愬彇搴忓彿锛堢浜屽垪锛�
+                if (row.getTableCells().size() > 1) {
+                    String seqText = getCellText(row.getCell(1));
+                    try {
+                        if (!seqText.equals("搴忓彿")) {
+                            item.setItemCode(Integer.parseInt(seqText.trim()));
+                        }
+                    } catch (NumberFormatException e) {
+                        // 蹇界暐搴忓彿瑙f瀽閿欒
+                    }
+                }
+
+                // 鎻愬彇鍐呭锛堢涓夊垪锛�
+                if (row.getTableCells().size() > 2) {
+                    String seqText = getCellText(row.getCell(2));
+                    item.setItemName(seqText);
+                }
+
+                items.add(item);
+            }
+        }
+        return items;
+    }
+
+    /**
+     * 鎻愬彇涓夌骇淇濆吇椤圭洰锛堣В鍐宠法椤电┖琛岄棶棰橈級
+     */
+    private List<EamMaintenanceStandardDetail> extractThirdMaintenanceItems(
+            XWPFTable table, String standardId, boolean isFirstTable) {
+
+        List<EamMaintenanceStandardDetail> items = new ArrayList<>();
+        String currentPart = "";
+        int startRow = 0;
+
+        // 瀵逛簬绗竴椤佃〃鏍硷紝璺宠繃鍓嶄袱琛岋紙璁惧淇℃伅琛岋級
+        if (isFirstTable && table.getNumberOfRows() > 2) {
+            startRow = 2; // 浠庣涓夎寮�濮嬫槸淇濆吇鍐呭
+        }
+
+        for (int i = startRow; i < table.getNumberOfRows(); i++) {
+            XWPFTableRow row = table.getRow(i);
+            if (row == null) continue;  // 纭繚琛屽璞′笉涓虹┖
+
+            // 妫�鏌ユ槸鍚︽槸绌鸿锛堝寘鍚墍鏈夊崟鍏冩牸閮戒负绌虹殑鎯呭喌锛�
+            if (isRowEmpty(row)) {
+                // 绌鸿澶勭悊锛氫繚鐣欏綋鍓嶄綅缃絾涓嶅垱寤洪」鐩�
+                continue;
+            }
+
+            // 鍒涘缓淇濆吇椤圭洰
+            EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail();
+            item.setItemCategory("THIRD_MAINTENANCE");
+            item.setStandardId(standardId);
+            int colCount = row.getTableCells().size();
+
+            // 澶勭悊閮ㄤ綅鍒楋紙绗竴鍒楋級
+            if (colCount > 0) {
+                String firstCell = getCellText(row.getCell(0)).trim();
+
+                // 鍏抽敭鏀硅繘锛氭纭鐞嗙┖琛屽悗鐨勯儴浣嶇户鎵�
+                if (!firstCell.isEmpty() && !firstCell.equals("淇濆吇閮ㄤ綅")) {
+                    // 鏇存柊褰撳墠閮ㄤ綅
+                    currentPart = firstCell;
+                }
+                item.setItemPart(currentPart);
+            } else {
+                // 濡傛灉娌℃湁鍗曞厓鏍硷紝浣跨敤褰撳墠閮ㄤ綅
+                item.setItemPart(currentPart);
+            }
+
+            // 鏍规嵁鍒楁暟鎻愬彇鍐呭锛堣�冭檻鍚堝苟鍗曞厓鏍兼儏鍐碉級
+            List<String> cellContents = new ArrayList<>();
+            for (int j = 0; j < colCount; j++) {
+                XWPFTableCell cell = row.getCell(j);
+                String text = getCellText(cell).trim();
+
+                // 鐗规畩澶勭悊锛氱浜岄〉绗竴琛屽彲鑳芥槸绌鸿鍚庣殑鍐呭
+                if (j == 0 && !text.isEmpty() && !text.equals(currentPart)) {
+                    // 濡傛灉涓嶆槸閮ㄤ綅鍒楋紝鍒欐坊鍔犱负鍐呭
+                    cellContents.add(text);
+                } else if (j > 0) {
+                    // 鍏朵粬鍒椾綔涓哄唴瀹�
+                    cellContents.add(text);
+                }
+            }
+
+            // 鏅鸿兘瑙f瀽鍗曞厓鏍煎唴瀹�
+            if (cellContents.size() >= 2) {
+                // 榛樿澶勭悊鏂瑰紡锛氭渶鍚庝袱涓綔涓哄唴瀹瑰拰鏍囧噯
+                item.setItemName(cellContents.get(cellContents.size() - 2));
+                item.setItemDemand(cellContents.get(cellContents.size() - 1));
+            } else if (cellContents.size() == 1) {
+                // 鍗曞垪妯″紡锛氳涓哄唴瀹�
+                item.setItemName(cellContents.get(0));
+            } else if (!isRowEmpty(row)) {
+                // 鐗规畩澶勭悊锛氳闈炵┖浣嗘病鏈夋彁鍙栧埌鍐呭锛堝彲鑳芥槸澶嶆潅鍚堝苟鍗曞厓鏍硷級
+                // 灏濊瘯鎻愬彇鏁磋鏂囨湰浣滀负鍐呭
+                StringBuilder content = new StringBuilder();
+                for (XWPFTableCell cell : row.getTableCells()) {
+                    content.append(getCellText(cell).trim()).append(" ");
+                }
+                item.setItemName(content.toString().trim());
+            }
+
+            items.add(item);
+        }
+        return items;
+    }
+
+    /**
+     * 浼樺寲鍚庣殑绌鸿妫�娴嬶紙瑙e喅璺ㄩ〉绌鸿闂锛�
+     */
+    private boolean isRowEmpty(XWPFTableRow row) {
+        if (row == null || row.getTableCells().isEmpty()) {
+            return true;
+        }
+
+        boolean allCellsEmpty = true;
+        for (XWPFTableCell cell : row.getTableCells()) {
+            String text = getCellText(cell).trim();
+            // 淇濈暀鍖呭惈鎹㈣绗︾瓑鐨勫崟鍏冩牸浣滀负闈炵┖琛�
+            if (!text.isEmpty() && !text.replaceAll("\\s+", "").isEmpty()) {
+                allCellsEmpty = false;
+                break;
+            }
+        }
+        return allCellsEmpty;
+    }
+
+    /**
      * 鏂囨。绫诲瀷鏍¢獙 - 闃叉浜屼繚浼犲叆涓変繚鎴栧弽涔�
-    */
+     */
     private boolean isWrongDocumentType(XWPFTable table, String requestedType) {
         boolean hasRepairTitle = false;
         boolean hasOperatorTitle = false;
@@ -1049,7 +1303,7 @@
     /**
      * 鎻愬彇璁惧鍩烘湰淇℃伅
      */
-    private EamMaintenanceStandard extractDeviceInfo(XWPFTable table) {
+    private EamMaintenanceStandard extractDeviceInfo(XWPFTable table, String type) {
         if (table.getNumberOfRows() < 2) return null;
 
         // 鎻愬彇鍓嶄袱琛屾暟鎹�
@@ -1064,29 +1318,22 @@
         standard.setEquipmentModel(row2Data.get("璁惧鍨嬪彿"));
 
         // 鍏宠仈璁惧ID
-        if (isNotBlank(standard.getEquipmentCode()) &&
-                isNotBlank(standard.getEquipmentName())) {
-
-            List<EamEquipment> equipments = eamEquipmentService.list(
-                    new QueryWrapper<EamEquipment>()
-                            .eq("equipment_code", standard.getEquipmentCode())
-                            .eq("equipment_name", standard.getEquipmentName())
-            );
-
-            if (!equipments.isEmpty()) {
-                standard.setEquipmentId(equipments.get(0).getId());
-            }else {
+        if (StrUtil.isNotEmpty(standard.getEquipmentCode())) {
+            EamEquipment equipments = eamEquipmentService.selectByEquipmentCode(standard.getEquipmentCode());
+            if (equipments == null) {
                 return null;
+            } else {
+                standard.setEquipmentId(equipments.getId());
+            }
+            if (type.equals("THIRD")) {
+                EamEquipmentExtend eamEquipmentExtend = eamEquipmentExtendService.getById(standard.getEquipmentId());
+                standard.setMaintenancePeriod(eamEquipmentExtend.getThirdMaintenancePeriod());
             }
         }
 
         return standard;
     }
 
-    // 绠�鏄撶増瀛楃涓查潪绌哄垽鏂�
-    private boolean isNotBlank(String str) {
-        return str != null && !str.trim().isEmpty();
-    }
 
     /**
      * 琛ㄦ牸琛屾暟鎹В鏋�
@@ -1144,7 +1391,7 @@
         standard.setStandardName(filename)
                 .setInitialDate(new Date())
                 .setStandardStatus(MaintenanceStandardStatusEnum.START.name())
-                .setStandardVersion("v1.0")
+                .setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1)
                 .setDelFlag(0)
                 .setStandardCode(businessCodeRuleService.generateBusinessCodeSeq(
                         BusinessCodeConst.MAINTENANCE_STANDARD_CODE_RULE
@@ -1170,161 +1417,6 @@
     }
 
     /**
-     * 鎻愬彇浜岀骇淇濆吇椤圭洰
-     */
-    private List<EamMaintenanceStandardDetail> extractSecondMaintenanceItems(
-            XWPFTable table, String standardId) {
-
-        List<EamMaintenanceStandardDetail> items = new ArrayList<>();
-        EamMaintenanceStandardDetailCategory currentCategory = null;
-
-        for (int i = 0; i < table.getNumberOfRows(); i++) {
-            XWPFTableRow row = table.getRow(i);
-            if (row == null) continue;
-
-            // 妫�鏌ユ槸鍚︽槸鏍囬琛岋紙缁翠慨浜哄憳淇濆吇鍐呭鎴栨搷浣滀汉鍛樹繚鍏诲唴瀹癸級
-            String firstCell = getCellText(row.getCell(0));
-            if (firstCell != null) {
-                for (String title : SECOND_CATEGORY_MAPPING.keySet()) {
-                    if (firstCell.contains(title)) {
-                        currentCategory = SECOND_CATEGORY_MAPPING.get(title);
-
-                        // 妫�鏌ョ浜屽垪鍜岀涓夊垪鏄惁鏄�"搴忓彿"鍜�"淇濆吇鍐呭"
-                        if (row.getTableCells().size() > 2) {
-                            String secondCell = getCellText(row.getCell(1));
-                            String thirdCell = getCellText(row.getCell(2));
-
-                            // 鏄庣‘璺宠繃鏍囬琛�
-                            if ("搴忓彿".equals(secondCell) && "淇濆吇鍐呭".equals(thirdCell)) {
-                                continue; // 璺宠繃杩欎竴琛�
-                            }
-                        }
-
-                        // 灏濊瘯鎻愬彇鏍囬琛屼腑鐨勯」鐩紙濡傛灉瀛樺湪锛�
-                        if (row.getTableCells().size() > 2) {
-                            String content = getCellText(row.getCell(2));
-                            if (content != null && !content.trim().isEmpty() &&
-                                    !"淇濆吇鍐呭".equals(content.trim())) { // 杩囨护鏃犳晥鍐呭
-                                items.add(createItem(currentCategory, content.trim(), standardId));
-                            }
-                        }
-                        continue;
-                    }
-                }
-            }
-
-            // 澶勭悊鏅�氶」鐩
-            if (currentCategory != null && isValidItemRow(row)) {
-                // 鑾峰彇鍐呭
-                String content = row.getTableCells().size() > 2 ?
-                        getCellText(row.getCell(2)) : "";
-
-                // 鎺掗櫎鏍囬鍐呭
-                if ("淇濆吇鍐呭".equals(content) ||
-                        "搴忓彿".equals(content) ||
-                        content.contains("缁翠慨浜哄憳淇濆吇鍐呭") ||
-                        content.contains("鎿嶄綔浜哄憳淇濆吇鍐呭")) {
-                    continue;
-                }
-
-                EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail();
-                item.setItemCategory(String.valueOf(currentCategory));
-                item.setStandardId(standardId);
-                item.setItemName(cleanContent(content));
-
-                // 澶勭悊搴忓彿锛堢浜屽垪锛�
-                if (row.getTableCells().size() > 1) {
-                    String seqText = getCellText(row.getCell(1));
-                    try {
-                        if (seqText != null && !seqText.trim().isEmpty()) {
-                            item.setItemCode(Integer.parseInt(seqText.trim()));
-                        }
-                    } catch (NumberFormatException e) {
-                        // 蹇界暐搴忓彿瑙f瀽閿欒
-                    }
-                }
-
-                items.add(item);
-            }
-        }
-        return items;
-    }
-
-    /**
-     * 鍒涘缓淇濆吇椤圭洰
-     */
-    private EamMaintenanceStandardDetail createItem(
-            EamMaintenanceStandardDetailCategory category,
-            String content,
-            String standardId) {
-
-        EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail();
-        item.setItemCategory(category.name());
-        item.setStandardId(standardId);
-        item.setItemName(cleanContent(content));
-        return item;
-    }
-
-    /**
-     * 鎻愬彇涓夌骇淇濆吇椤圭洰锛堟棤绫诲瀷锛�
-     */
-    private List<EamMaintenanceStandardDetail> extractThirdMaintenanceItems(
-            XWPFTable table, String standardId) {
-
-        List<EamMaintenanceStandardDetail> items = new ArrayList<>();
-        String currentPart = "";
-        int itemCount = 1;
-
-        // 浠庣涓夎寮�濮嬶紙璺宠繃琛ㄥご鍜岃澶囦俊鎭級
-        for (int i = 2; i < table.getNumberOfRows(); i++) {
-            XWPFTableRow row = table.getRow(i);
-            if (row == null || isRowEmpty(row)) continue;
-
-            // 璺宠繃"淇濆吇閮ㄤ綅"鏍囬琛�
-            String firstCell = getCellText(row.getCell(0));
-            if ("淇濆吇閮ㄤ綅".equals(firstCell)) {
-                continue;
-            }
-
-            EamMaintenanceStandardDetail item = new EamMaintenanceStandardDetail();
-            // 涓夌骇淇濆吇涓嶉渶瑕佺被鍨嬶紝涓嶈缃甶temCategory
-            item.setStandardId(standardId);
-            item.setItemCode(itemCount++);
-
-            // 澶勭悊閮ㄤ綅鍒�
-            if (!row.getTableCells().isEmpty()) {
-                String partCell = getCellText(row.getCell(0));
-                if (!partCell.trim().isEmpty()) {
-                    currentPart = partCell.trim();
-                }
-            }
-            item.setItemPart(currentPart);
-
-            // 鏍规嵁鍒楁暟纭畾鍐呭鍜屾爣鍑嗙殑浣嶇疆
-            int cellCount = row.getTableCells().size();
-            if (cellCount == 3) { // 閮ㄤ綅|鍐呭|鏍囧噯
-                item.setItemName(getCellText(row.getCell(1)));
-                item.setItemDemand(getCellText(row.getCell(2)));
-            }
-            else if (cellCount == 2) { // 鍐呭|鏍囧噯
-                item.setItemName(getCellText(row.getCell(0)));
-                item.setItemDemand(getCellText(row.getCell(1)));
-            }
-            else if (cellCount == 1) { // 鍗曞垪鍐呭
-                item.setItemName(getCellText(row.getCell(0)));
-            }
-            else if (cellCount > 3) { // 澶氬垪澶勭悊
-                // 鍙栫2鍒椾綔涓哄唴瀹癸紝鏈�鍚庝竴鍒椾綔涓烘爣鍑�
-                item.setItemName(getCellText(row.getCell(1)));
-                item.setItemDemand(getCellText(row.getCell(cellCount - 1)));
-            }
-
-            items.add(item);
-        }
-        return items;
-    }
-
-    /**
      * 鍏煎鐗堝崟鍏冩牸鏂囨湰鎻愬彇
      */
     private String getCellText(XWPFTableCell cell) {
@@ -1347,48 +1439,12 @@
     }
 
     /**
-     * 鍐呭娓呯悊
-     */
-    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();
-    }
-
-    /**
      * 楠岃瘉鏈夋晥椤圭洰琛�
      */
     private boolean isValidItemRow(XWPFTableRow row) {
         return row != null &&
                 row.getTableCells().size() >= 2 &&
                 !getCellText(row.getCell(1)).trim().isEmpty();
-    }
-
-    /**
-     * 绌鸿妫�娴�
-     */
-    private boolean isRowEmpty(XWPFTableRow row) {
-        if (row == null) return true;
-        for (XWPFTableCell cell : row.getTableCells()) {
-            String text = getCellText(cell);
-            if (text != null && !text.trim().isEmpty()) {
-                return false;
-            }
-        }
-        return true;
     }
 
     /*瀵煎叆浜屼繚涓変繚鏂囦欢Excel--------------------------缁撴潫*/

--
Gitblit v1.9.3