From 9729cb7cb30ba7a11119f84dc680c8f302098dc3 Mon Sep 17 00:00:00 2001
From: Lius <Lius2225@163.com>
Date: 星期一, 07 七月 2025 11:36:17 +0800
Subject: [PATCH] update

---
 lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamMaintenanceStandardServiceImpl.java |  735 +++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 files changed, 666 insertions(+), 69 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 6d30e4b..596714b 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
@@ -1,35 +1,59 @@
 package org.jeecg.modules.eam.service.impl;
 
 import cn.hutool.core.collection.CollectionUtil;
+import cn.hutool.core.util.StrUtil;
+import com.alibaba.fastjson.JSON;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
 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 com.fasterxml.jackson.core.JsonProcessingException;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import com.jeecg.weibo.exception.BusinessException;
 import org.apache.commons.lang3.StringUtils;
+import org.apache.poi.ss.usermodel.*;
 import org.apache.shiro.SecurityUtils;
-import org.jeecg.common.api.vo.FileUploadResult;
+import org.flowable.engine.TaskService;
+import org.flowable.task.api.Task;
+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.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.MaintenanceStandardStatusEnum;
+import org.jeecg.modules.eam.entity.EamEquipment;
 import org.jeecg.modules.eam.entity.EamMaintenanceStandard;
 import org.jeecg.modules.eam.entity.EamMaintenanceStandardDetail;
 import org.jeecg.modules.eam.mapper.EamMaintenanceStandardMapper;
 import org.jeecg.modules.eam.request.EamMaintenanceStandardRequest;
+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.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.ISysUserService;
+import org.jeecg.modules.system.vo.UserSelector;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
+import org.springframework.web.multipart.MultipartFile;
 
 import javax.annotation.Resource;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.*;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
 import java.util.stream.Collectors;
 
 /**
@@ -38,15 +62,31 @@
  * @Date:   2025-03-26
  * @Version: V1.0
  */
-@Service
-public class EamMaintenanceStandardServiceImpl extends ServiceImpl<EamMaintenanceStandardMapper, EamMaintenanceStandard> implements IEamMaintenanceStandardService {
+@Service("IEamMaintenanceStandardService")
+public class EamMaintenanceStandardServiceImpl extends ServiceImpl<EamMaintenanceStandardMapper, EamMaintenanceStandard> implements IEamMaintenanceStandardService , FlowCallBackServiceI {
 
     @Resource
     private EamMaintenanceStandardMapper eamMaintenanceStandardMapper;
-
     @Autowired
     private IEamMaintenanceStandardDetailService eamMaintenanceStandardDetailService;
-
+    @Autowired
+    private IBaseFactoryUserService baseFactoryUserService;
+    @Autowired
+    private IBaseFactoryService baseFactoryService;
+    @Resource
+    private FlowCommonService flowCommonService;
+    @Resource
+    private IFlowDefinitionService flowDefinitionService;
+    @Autowired
+    private IFlowTaskService flowTaskService;
+    @Autowired
+    private TaskService taskService;
+    @Autowired
+    private IFlowMyBusinessService flowMyBusinessService;
+    @Autowired
+    private ISysUserService sysUserService;
+    @Autowired
+    private IEamEquipmentService eamEquipmentService;
     @Override
     public IPage<EamMaintenanceStandard> queryPageList(Page<EamMaintenanceStandard> page, EamMaintenanceStandard eamMaintenanceStandard) {
         QueryWrapper<EamMaintenanceStandard> queryWrapper = new QueryWrapper<>();
@@ -56,13 +96,19 @@
         if (sysUser == null) {
             return page;
         }
-        if (StringUtils.isNotBlank(sysUser.getEquipmentIds())) {
+        if (StringUtils.isNotBlank(sysUser.getEamEquipmentIds())) {
             //閫夋嫨浜嗚澶囷紝鏍规嵁璁惧id杩囨护璁惧
-            List<String> equipArr = Arrays.asList(sysUser.getEquipmentIds().split(","));
+            List<String> equipArr = Arrays.asList(sysUser.getEamEquipmentIds().split(","));
             queryWrapper.in("e.equipment_code", equipArr);
         } else {
-            //娌℃湁閫夋嫨璁惧锛屾牴鎹溅闂磋繃婊よ澶�
-            queryWrapper.exists("select 1 from mdc_user_production t where t.user_id={0} and t.pro_id=e.org_id ", sysUser.getId());
+            //娌℃湁閫夋嫨璁惧锛屾牴鎹腑蹇冭繃婊よ澶�
+            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);
+            }
         }
         if(eamMaintenanceStandard != null) {
             //缂栫爜 妯$硦鏌ヨ
@@ -71,7 +117,7 @@
             }
             //鍚嶇О 妯$硦鏌ヨ
             if(StringUtils.isNotBlank(eamMaintenanceStandard.getStandardName())) {
-                queryWrapper.like("ems.standard_name", eamMaintenanceStandard.getStandardCode());
+                queryWrapper.like("ems.standard_name", eamMaintenanceStandard.getStandardName());
             }
             //璁惧
             if(StringUtils.isNotBlank(eamMaintenanceStandard.getEquipmentId())) {
@@ -91,6 +137,10 @@
                         .or()
                         .like("e.equipment_code", eamMaintenanceStandard.getKeyword()));
             }
+            //id
+            if(StringUtils.isNotBlank(eamMaintenanceStandard.getId())) {
+                queryWrapper.eq("ems.id", eamMaintenanceStandard.getId());
+            }
         }
         queryWrapper.orderByDesc("ems.create_time");
         return eamMaintenanceStandardMapper.queryPageList(page, queryWrapper);
@@ -100,15 +150,10 @@
     @Transactional(rollbackFor = Exception.class)
     public boolean addMaintenanceStandard(EamMaintenanceStandardRequest standardRequest) {
         EamMaintenanceStandard entity = new EamMaintenanceStandard();
-        entity.setStandardCode(standardRequest.getStandardCode());
-        entity.setStandardName(standardRequest.getStandardName());
-        entity.setMaintenanceCategory(standardRequest.getMaintenanceCategory());
-        entity.setMaintenancePeriod(standardRequest.getMaintenancePeriod());
-        entity.setInitialDate(standardRequest.getInitialDate());
-        entity.setFileCode(standardRequest.getFileCode());
-        entity.setStandardStatus(MaintenanceStandardStatusEnum.NORMAL.name());
+        BeanUtils.copyProperties(standardRequest, entity);
+        entity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
         //鐗堟湰閫掑
-        entity.setStandardVersion(CommonConstant.OPERATE_TYPE_1);
+        entity.setStandardVersion("v"+CommonConstant.OPERATE_TYPE_1);
         //璁惧澶勭悊
         entity.setEquipmentId(standardRequest.getEquipmentId());
         //鍒犻櫎鏍囪
@@ -117,17 +162,6 @@
         EamMaintenanceStandard exist = checkDuplicate(entity.getEquipmentId(), entity.getMaintenanceCategory());
         if(exist != null){
             throw new JeecgBootException("璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�");
-        }
-        //澶勭悊闄勪欢
-        if(CollectionUtil.isNotEmpty(standardRequest.getFileList())) {
-            FileUploadResult fileUploadResult = standardRequest.getFileList().get(0);
-            ObjectMapper mapper = new ObjectMapper();
-            try {
-                String referenceFile = mapper.writeValueAsString(fileUploadResult);
-                entity.setReferenceFile(referenceFile);
-            } catch (JsonProcessingException e) {
-                log.error("JSON杞崲澶辫触锛�" + e.getMessage(), e);
-            }
         }
         eamMaintenanceStandardMapper.insert(entity);
         //澶勭悊鏄庣粏鏁版嵁
@@ -149,20 +183,6 @@
         }
         entity.setStandardName(standardRequest.getStandardName());
         entity.setMaintenancePeriod(standardRequest.getMaintenancePeriod());
-        entity.setFileCode(standardRequest.getFileCode());
-        //澶勭悊闄勪欢
-        if(CollectionUtil.isNotEmpty(standardRequest.getFileList())) {
-            FileUploadResult fileUploadResult = standardRequest.getFileList().get(0);
-            ObjectMapper mapper = new ObjectMapper();
-            try {
-                String referenceFile = mapper.writeValueAsString(fileUploadResult);
-                entity.setReferenceFile(referenceFile);
-            } catch (JsonProcessingException e) {
-                log.error("JSON杞崲澶辫触锛�" + e.getMessage(), e);
-            }
-        }else {
-            entity.setReferenceFile(null);
-        }
         eamMaintenanceStandardMapper.updateById(entity);
         //澶勭悊璇︽儏
         if(CollectionUtil.isNotEmpty(standardRequest.getTableDetailList())) {
@@ -197,9 +217,6 @@
         if(entity == null){
             throw new JeecgBootException("缂栬緫鐨勬暟鎹凡鍒犻櫎锛岃鍒锋柊閲嶈瘯锛�");
         }
-        entity.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name());
-        //鍘熸潵鐨勪綔搴�
-        eamMaintenanceStandardMapper.updateById(entity);
 
         //鏂板涓�涓増鏈�
         EamMaintenanceStandard newEntity = new EamMaintenanceStandard();
@@ -208,10 +225,18 @@
         newEntity.setMaintenanceCategory(standardRequest.getMaintenanceCategory());
         newEntity.setMaintenancePeriod(standardRequest.getMaintenancePeriod());
         newEntity.setInitialDate(standardRequest.getInitialDate());
-        newEntity.setFileCode(standardRequest.getFileCode());
-        newEntity.setStandardStatus(MaintenanceStandardStatusEnum.NORMAL.name());
+        newEntity.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
         //鐗堟湰閫掑
-        newEntity.setStandardVersion(entity.getStandardVersion() + 1);
+        //鑾峰彇鏁板瓧
+        Pattern pattern = Pattern.compile("(\\d+)(?:\\.\\d+)*$");
+        Matcher matcher = pattern.matcher(entity.getStandardVersion());
+        if (matcher.find()) {
+            try {
+                int mainVersion = Integer.parseInt(matcher.group(1));
+                newEntity.setStandardVersion("v"+(mainVersion+1));
+            } catch (NumberFormatException ignored) {
+            }
+        }
         //璁惧澶勭悊
         newEntity.setEquipmentId(standardRequest.getEquipmentId());
         //鍒犻櫎鏍囪
@@ -220,17 +245,6 @@
         EamMaintenanceStandard exist = checkDuplicate(newEntity.getEquipmentId(), newEntity.getMaintenanceCategory());
         if(exist != null){
             throw new JeecgBootException("璁惧鏍囧噯宸插瓨鍦紝涓嶈兘閲嶅娣诲姞锛�");
-        }
-        //澶勭悊闄勪欢
-        if(CollectionUtil.isNotEmpty(standardRequest.getFileList())) {
-            FileUploadResult fileUploadResult = standardRequest.getFileList().get(0);
-            ObjectMapper mapper = new ObjectMapper();
-            try {
-                String referenceFile = mapper.writeValueAsString(fileUploadResult);
-                newEntity.setReferenceFile(referenceFile);
-            } catch (JsonProcessingException e) {
-                log.error("JSON杞崲澶辫触锛�" + e.getMessage(), e);
-            }
         }
         eamMaintenanceStandardMapper.insert(newEntity);
         //澶勭悊鏄庣粏鏁版嵁
@@ -254,7 +268,7 @@
         queryWrapper.eq(EamMaintenanceStandard::getEquipmentId, equipmentId);
         queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory);
         queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0);
-        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.NORMAL.name());
+        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
         queryWrapper.orderByDesc(EamMaintenanceStandard::getStandardVersion);
 
         List<EamMaintenanceStandard> list = eamMaintenanceStandardMapper.selectList(queryWrapper);
@@ -277,7 +291,7 @@
         query.setEquipmentId(equipmentId);
         query.setKeyword(keyword);
         query.setMaintenanceCategory(maintenanceCategory);
-        query.setStandardStatus(MaintenanceStandardStatusEnum.NORMAL.name());
+        query.setStandardStatus(MaintenanceStandardStatusEnum.START.name());
         IPage<EamMaintenanceStandard> pageData = this.queryPageList(page, query);
         return pageData.getRecords();
     }
@@ -287,7 +301,590 @@
         LambdaQueryWrapper<EamMaintenanceStandard> queryWrapper = new LambdaQueryWrapper<>();
         queryWrapper.eq(EamMaintenanceStandard::getDelFlag, CommonConstant.DEL_FLAG_0);
         queryWrapper.eq(EamMaintenanceStandard::getMaintenanceCategory, maintenanceCategory);
-        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.NORMAL.name());
+        queryWrapper.eq(EamMaintenanceStandard::getStandardStatus, MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
         return eamMaintenanceStandardMapper.selectList(queryWrapper);
     }
+
+
+    /*娴佺▼涓氬姟浠g爜--------------------------寮�濮�*/
+
+    /**
+     * 娴佺▼鍚姩,淇濆瓨瀵瑰簲鐨勬暟鎹�
+     * @param id
+     * @return
+     */
+    @Override
+    public Result<?> saveEamMaintenanceStandardProcess(String id){
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        EamMaintenanceStandard maintenanceStandard=this.getById(id);
+        if (maintenanceStandard==null){
+            return Result.error("鏈壘鍒板搴斾繚鍏绘爣鍑�");
+        }
+        System.out.println("淇濆吇瑙勮寖娴佺▼锛�" + maintenanceStandard.getId());
+        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);
+        if (!result.isSuccess()) {
+            super.removeById(maintenanceStandard.getId());
+        }else {
+            maintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_REPAIR_DIRECTOR.name());
+            maintenanceStandard.setDesigner(user.getUsername());
+            maintenanceStandard.setDesignTime(new Date());
+            eamMaintenanceStandardMapper.updateById(maintenanceStandard);
+            //鑾峰彇flow鐨勬祦绋嬪疄渚媔d,璁剧疆涓嬩竴姝ョ殑澶勭悊浜哄憳
+            List<FlowMyBusiness> businessList = flowMyBusinessService.list(
+                    new QueryWrapper<FlowMyBusiness>()
+                            .eq("data_id", maintenanceStandard.getId())
+            );
+            if (businessList.isEmpty()) {
+                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);
+            if (!CollectionUtils.isEmpty(userSelectorList)) {
+                List<String> usernameList=userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
+                flowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList));
+                flowMyBusinessService.updateById(flowMyBusiness);
+            }
+        }
+        return result;
+    }
+
+    /**
+     * 瀹℃壒鎿嶄綔
+     * @param eamMaintenanceStandardVo
+     * @return
+     */
+    @Override
+    public Result<?> auditEamMaintenanceStandard(EamMaintenanceStandardVo eamMaintenanceStandardVo){
+        try {
+            // 鍙傛暟鏍¢獙
+            if (StrUtil.isEmpty(eamMaintenanceStandardVo.getTaskId()) || StrUtil.isEmpty(eamMaintenanceStandardVo.getDataId())) {
+                return Result.error("鍙傛暟閿欒");
+            }
+            LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+            String userId = user.getId();
+            eamMaintenanceStandardVo.setAssignee(user.getUsername());
+            if (StrUtil.isEmpty(userId)) {
+                return Result.error("鏈壘鍒板搴旂敤鎴�");
+            }
+
+            // 鏁版嵁鏌ヨ
+            EamMaintenanceStandard eamMaintenanceStandard = this.getById(eamMaintenanceStandardVo.getDataId());
+            if (eamMaintenanceStandard == null) {
+                return Result.error("鏈壘鍒板搴斾繚鍏绘爣鍑�");
+            }
+
+            // 2. 鏌ヨ娴佺▼涓氬姟璁板綍锛堝鐞嗙┖缁撴灉锛�
+            List<FlowMyBusiness> businessList = flowMyBusinessService.list(
+                    new QueryWrapper<FlowMyBusiness>()
+                            .eq("process_instance_id", eamMaintenanceStandardVo.getInstanceId())
+            );
+            if (businessList.isEmpty()) {
+                return Result.error("娴佺▼璁板綍涓嶅瓨鍦�");
+            }
+            FlowMyBusiness flowMyBusiness = businessList.get(0);
+
+            // 3. 鏍¢獙鐢ㄦ埛鏄惁涓哄�欓�夊鐞嗕汉
+            List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class);
+            if (todoUsers == null || !todoUsers.contains(user.getUsername())) {
+                return Result.error("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔�");
+            }
+
+            // 4. 璁ら浠诲姟锛堝鐞嗗凡琚棰嗙殑鎯呭喌锛�
+            String taskId = flowMyBusiness.getTaskId();
+            Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+            if (task == null) {
+                return Result.error("浠诲姟涓嶅瓨鍦ㄦ垨宸插畬鎴�");
+            }
+            if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) {
+                return Result.error("浠诲姟宸茶浠栦汉璁ら");
+            }
+            taskService.claim(taskId, user.getUsername());
+
+            // 璁剧疆娴佺▼鍙橀噺
+            Map<String, Object> values = setProcessVariables(eamMaintenanceStandard, userId, eamMaintenanceStandardVo);
+            eamMaintenanceStandardVo.setValues(values);
+            eamMaintenanceStandardVo.setComment(values.get("comment").toString());
+            // 瀹屾垚娴佺▼浠诲姟
+            Result result = flowTaskService.complete(eamMaintenanceStandardVo);
+            if (result.isSuccess()) {
+                if (eamMaintenanceStandardVo.getRepairManagerApproveResult() != null) {
+                    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);
+                        if (!CollectionUtils.isEmpty(userSelectorList)) {
+                            List<String> usernameList=userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
+                            newflowMyBusiness.setTodoUsers(JSON.toJSONString(usernameList));
+                            flowMyBusinessService.updateById(newflowMyBusiness);
+                        }
+                    }else {
+                        eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+                    }
+                    eamMaintenanceStandard.setRepairManager(user.getUsername());
+                    eamMaintenanceStandard.setRepairManagerApproveResult(eamMaintenanceStandardVo.getRepairManagerApproveResult());
+                    eamMaintenanceStandard.setRepairManagerApproveTime(new Date());
+                    eamMaintenanceStandard.setRepairManagerApproveComment(eamMaintenanceStandardVo.getComment());
+                }
+                if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult() != null) {
+                    if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult().equals("1")){
+                        eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.START.name());
+                        //鍒ゆ柇鏄惁杩涜鍗囩増锛岄�氳繃璁惧缂栧彿銆佷繚鍏诲垎绫汇�佺姸鎬佽繘琛岀瓫閫�
+                        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);
+                        if (!CollectionUtils.isEmpty(list)) {
+                            //浣滃簾鍘熸湁
+                            for (EamMaintenanceStandard eamMaintenanceStandard1 : list) {
+                                eamMaintenanceStandard1.setStandardStatus(MaintenanceStandardStatusEnum.ABOLISH.name());
+                                this.updateById(eamMaintenanceStandard1);
+                            }
+                        }
+                    }else {
+                        eamMaintenanceStandard.setStandardStatus(MaintenanceStandardStatusEnum.WAIT_SUBMIT.name());
+                    }
+                    eamMaintenanceStandard.setTechnicalManager(user.getUsername());
+                    eamMaintenanceStandard.setTechnicalManagerApproveResult(eamMaintenanceStandardVo.getTechnicalManagerApproveResult());
+                    eamMaintenanceStandard.setTechnicalManagerApproveTime(new Date());
+                    eamMaintenanceStandard.setTechnicalManagerApproveComment(eamMaintenanceStandardVo.getComment());
+                }
+                this.updateById(eamMaintenanceStandard);
+            } else {
+                return result;
+            }
+            return Result.OK("鎿嶄綔鎴愬姛");
+        } catch (Exception e) {
+            return Result.error("鎿嶄綔澶辫触锛�" + e.getMessage());
+        }
+    }
+
+    private Map<String, Object> setProcessVariables(EamMaintenanceStandard eamMaintenanceStandard, String userId, EamMaintenanceStandardVo eamMaintenanceStandardVo) {
+        Map<String, Object> values = new HashMap<>();
+        values.put("dataId", eamMaintenanceStandard.getId());
+        values.put("assignee", userId);
+        if (eamMaintenanceStandardVo.getRepairManagerApproveResult() != null) {
+            values.put("repairManagerApproveResult", eamMaintenanceStandardVo.getRepairManagerApproveResult());
+            values.put("organization", eamMaintenanceStandardVo.getRepairManagerApproveComment());
+            values.put("comment", eamMaintenanceStandardVo.getRepairManagerApproveComment());
+        }
+        if (eamMaintenanceStandardVo.getTechnicalManagerApproveResult() != null) {
+            values.put("technicalManagerApproveResult", eamMaintenanceStandardVo.getTechnicalManagerApproveResult());
+            values.put("organization", eamMaintenanceStandardVo.getTechnicalManagerApproveComment());
+            values.put("comment", eamMaintenanceStandardVo.getTechnicalManagerApproveComment());
+        }
+        return values;
+    }
+
+
+    @Override
+    public void afterFlowHandle(FlowMyBusiness business) {
+        business.getTaskNameId();//鎺ヤ笅鏉ュ鎵圭殑鑺傜偣
+        business.getValues();//鍓嶇浼犺繘鏉ョ殑鍙傛暟
+        business.getActStatus();
+    }
+
+    @Override
+    public Object getBusinessDataById(String dataId) {
+        return this.getById(dataId);
+    }
+
+    @Override
+    public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) {
+        return null;
+    }
+
+    @Override
+    public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
+        //涓氬姟鏄惁骞查娴佺▼锛屼笟鍔″共棰勶紝娴佺▼骞查锛屾寚瀹氫汉鍛樿繘琛屽鐞�
+        return null;
+    }
+
+    /*娴佺▼涓氬姟浠g爜--------------------------缁撴潫*/
+
+
+    /*瀵煎叆鏂囦欢--------------------------寮�濮�*/
+    /**
+        * 鐐规琛ㄥ鍏ュ叆鍙�
+    */
+    @Override
+    @Transactional(rollbackFor = Exception.class)
+    public Result<?> importPointInspectionExcel(MultipartFile file) {
+        try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
+            Sheet sheet = workbook.getSheetAt(0);
+
+            // 鎻愬彇鍚嶇О
+            String name = extractInspectionTitle(file) + "鐐规琛�";
+
+            // 1. 鎻愬彇璁惧淇℃伅
+            EamMaintenanceStandard eamMaintenanceStandard = extractDeviceInfo(sheet);
+            if (eamMaintenanceStandard == null) {
+                throw new BusinessException("璁惧淇℃伅鎻愬彇澶辫触");
+            }
+
+            eamMaintenanceStandard.setStandardName(name);
+            eamMaintenanceStandardMapper.insert(eamMaintenanceStandard);
+
+            // 2. 鎻愬彇姣忔棩鐐规椤圭洰
+            List<EamMaintenanceStandardDetail> dailyDetails = extractDailyItems(sheet, eamMaintenanceStandard);
+
+            // 3. 鎻愬彇鍛ㄤ繚鍏婚」鐩�
+            List<EamMaintenanceStandardDetail> weeklyDetails = extractWeeklyItems(sheet, eamMaintenanceStandard);
+
+            // 鍚堝苟骞朵繚瀛樻墍鏈夐」鐩�
+            List<EamMaintenanceStandardDetail> allDetails = new ArrayList<>();
+            allDetails.addAll(dailyDetails);
+            allDetails.addAll(weeklyDetails);
+
+            if (!CollectionUtils.isEmpty(allDetails)) {
+                eamMaintenanceStandardDetailService.saveBatch(allDetails);
+            }
+
+            return Result.OK("鐐规琛ㄥ鍏ユ垚鍔�");
+
+        } catch (Exception e) {
+            throw new BusinessException("鐐规琛ㄥ鍏ュけ璐�: " + e.getMessage());
+        }
+    }
+
+    /**
+        * 鎻愬彇鐐规琛ㄦ爣棰�
+    */
+    private String extractInspectionTitle(MultipartFile file) {
+        try (Workbook workbook = WorkbookFactory.create(file.getInputStream())) {
+            Sheet sheet = workbook.getSheetAt(0);
+            Row firstRow = sheet.getRow(0);
+
+            if (firstRow == null) {
+                return "鏈壘鍒版爣棰�";
+            }
+
+            Cell firstCell = firstRow.getCell(0);
+            if (firstCell == null) {
+                return "";
+            }
+
+            String title = getCellStringValue(firstCell);
+            return extractTextBeforeInspection(title);
+
+        } catch (Exception e) {
+            return "";
+        }
+    }
+
+    /**
+        * 鎻愬彇鐐规琛ㄤ箣鍓嶇殑鏂囧瓧
+     */
+    private String extractTextBeforeInspection(String title) {
+        if (StringUtils.isBlank(title)) {
+            return "";
+        }
+
+        int index = title.indexOf("鐐规琛�");
+        return index > 0 ? title.substring(0, index).trim() : title;
+    }
+
+    /**
+        * 鎻愬彇璁惧淇℃伅
+    */
+    private EamMaintenanceStandard extractDeviceInfo(Sheet sheet) {
+        Row headerRow = sheet.getRow(0);
+        if (headerRow == null) {
+            return null;
+        }
+
+        String headerText = getCellStringValue(headerRow.getCell(0));
+        if (StringUtils.isBlank(headerText)) {
+            return null;
+        }
+
+        EamMaintenanceStandard standard = new EamMaintenanceStandard();
+        standard.setEquipmentName(extractField(headerText, "璁惧鍚嶇О[:锛歖\\s*(\\S+)"));
+        standard.setEquipmentId(extractField(headerText, "璁惧鍨嬪彿[:锛歖\\s*(\\S+)"));
+        standard.setStandardCode(extractField(headerText, "缁熶竴缂栧彿[:锛歖\\s*(\\S+)"));
+
+        // 鏃ユ湡澶勭悊
+        String dateStr = extractField(headerText, "鏃ユ湡[:锛歖\\s*(\\S+)");
+        if (StringUtils.isNotBlank(dateStr)) {
+            try {
+                // 鏀寔澶氱鏃ユ湡鏍煎紡
+                Date date = parseDate(dateStr);
+                standard.setDesignTime(date);
+                standard.setInitialDate(date);
+            } catch (ParseException ignored) {
+
+            }
+        }
+
+        standard.setMaintenanceCategory("POINT_INSPECTION");
+        standard.setPeriodUnit("澶�");
+        standard.setStandardStatus(MaintenanceStandardStatusEnum.START.name());
+        standard.setStandardVersion("v" + CommonConstant.OPERATE_TYPE_1);
+        standard.setDelFlag(0);
+
+        return standard;
+    }
+
+    /**
+        * 瑙f瀽鏃ユ湡瀛楃涓�
+     */
+    private Date parseDate(String dateStr) throws ParseException {
+        // 灏濊瘯澶氱鏃ユ湡鏍煎紡
+        String[] patterns = {
+                "yyyy骞碝M鏈�",
+                "yyyy-MM",
+                "yyyy/MM",
+                "yyyyMM",
+                "yyyy骞碝鏈�"
+        };
+
+        for (String pattern : patterns) {
+            try {
+                SimpleDateFormat sdf = new SimpleDateFormat(pattern);
+                sdf.setLenient(false);
+                return sdf.parse(dateStr);
+            } catch (ParseException e) {
+                // 灏濊瘯涓嬩竴涓牸寮�
+            }
+        }
+
+        throw new ParseException("鏃犳硶瑙f瀽鏃ユ湡: " + dateStr, 0);
+    }
+
+    /**
+        * 鎻愬彇姣忔棩鐐规椤圭洰
+    */
+    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) {
+        int[] section = findTableSection(sheet, primaryHeader, secondaryHeader);
+        if (section == null) {
+            return Collections.emptyList();
+        }
+
+        List<EamMaintenanceStandardDetail> details = new ArrayList<>();
+        for (int rowIdx = section[0]; rowIdx <= section[1]; rowIdx++) {
+            Row row = sheet.getRow(rowIdx);
+            if (row == null || isEmptyRow(row)) {
+                continue;
+            }
+
+            // 纭繚绗竴鍒楁槸搴忓彿锛堟暟瀛楋級
+            Cell seqCell = row.getCell(0);
+            if (seqCell == null || seqCell.getCellType() != CellType.NUMERIC) {
+                continue;
+            }
+
+            // 鍒涘缓椤圭洰璇︽儏
+            EamMaintenanceStandardDetail detail = new EamMaintenanceStandardDetail();
+            detail.setStandardId(standard.getId());
+            detail.setItemName(getCellStringValue(row.getCell(1)));
+            detail.setItemCategory(itemCategory);
+
+            // 鏍规嵁椤圭洰绫诲瀷璁剧疆闇�姹傚瓧娈�
+            if ("DAY_INSPECTION".equals(itemCategory)) {
+                detail.setItemDemand(getCellStringValue(row.getCell(2)));
+            } else if ("WEEK_INSPECTION".equals(itemCategory)) {
+                detail.setItemDemand(getCellStringValue(row.getCell(2)));
+            }
+
+            details.add(detail);
+        }
+
+        return details;
+    }
+
+    /**
+        * 鏌ユ壘琛ㄦ牸鍖哄煙
+     */
+    private int[] findTableSection(Sheet sheet, String primaryHeader, String secondaryHeader) {
+        for (int rowIdx = 0; rowIdx <= sheet.getLastRowNum(); rowIdx++) {
+            Row row = sheet.getRow(rowIdx);
+            if (row == null) continue;
+
+            if (isHeaderRow(row, primaryHeader, secondaryHeader)) {
+                int startRow = rowIdx + 1;
+                int endRow = findDataEnd(sheet, startRow);
+                return new int[]{startRow, endRow};
+            }
+        }
+        return null;
+    }
+
+    /**
+        * 妫�鏌ユ槸鍚︿负琛ㄥご琛�
+    */
+    private boolean isHeaderRow(Row row, String header1, String header2) {
+        boolean foundHeader1 = false;
+        boolean foundHeader2 = false;
+
+        for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
+            Cell cell = row.getCell(colIdx);
+            if (cell == null) continue;
+
+            String cellValue = getCellStringValue(cell);
+            if (cellValue.contains(header1)) foundHeader1 = true;
+            if (cellValue.contains(header2)) foundHeader2 = true;
+        }
+
+        return foundHeader1 && foundHeader2;
+    }
+
+    /**
+        * 鏌ユ壘鏁版嵁缁撴潫浣嶇疆
+     */
+    private int findDataEnd(Sheet sheet, int startRow) {
+        for (int rowIdx = startRow; rowIdx <= sheet.getLastRowNum(); rowIdx++) {
+            Row row = sheet.getRow(rowIdx);
+            if (row == null) return rowIdx - 1;
+
+            // 妫�鏌ユ槸鍚︾粨鏉熸爣蹇楄锛堝绛惧瓧琛岋級
+            if (isSignatureRow(row)) {
+                return rowIdx - 1;
+            }
+
+            // 妫�鏌ユ槸鍚︽柊鐨勮〃澶村紑濮�
+            if (isNewHeaderStart(row)) {
+                return rowIdx - 1;
+            }
+        }
+        return sheet.getLastRowNum();
+    }
+
+    /**
+        * 璇嗗埆绛惧瓧琛岀壒寰�
+    */
+    private boolean isSignatureRow(Row row) {
+        for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
+            Cell cell = row.getCell(colIdx);
+            if (cell == null) continue;
+
+            String value = getCellStringValue(cell);
+            if (value.contains("绛惧瓧") || value.contains("璐d换浜�") ||
+                    value.contains("鎵ц") || value.contains("纭")) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+        * 璇嗗埆鏂拌〃澶村紑濮�
+    */
+    private boolean isNewHeaderStart(Row row) {
+        for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
+            Cell cell = row.getCell(colIdx);
+            if (cell == null) continue;
+
+            String value = getCellStringValue(cell);
+            if ("搴忓彿".equals(value) || "鐐规椤圭洰".equals(value) || "鍛ㄤ繚鍏婚」鐩�".equals(value)) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    /**
+        * 妫�鏌ヨ鏄惁涓虹┖
+    */
+    private boolean isEmptyRow(Row row) {
+        if (row == null) return true;
+        for (int colIdx = 0; colIdx < row.getLastCellNum(); colIdx++) {
+            Cell cell = row.getCell(colIdx);
+            if (cell != null && cell.getCellType() != CellType.BLANK) {
+                String value = getCellStringValue(cell);
+                if (StringUtils.isNotBlank(value)) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+    /**
+        * 浣跨敤姝e垯鎻愬彇瀛楁
+    */
+    private String extractField(String text, String regex) {
+        if (StringUtils.isBlank(text)) return "";
+
+        Pattern pattern = Pattern.compile(regex);
+        Matcher matcher = pattern.matcher(text);
+        return matcher.find() ? matcher.group(1) : "";
+    }
+
+    /**
+        * 鑾峰彇鍗曞厓鏍煎瓧绗︿覆鍊�
+    */
+    private String getCellStringValue(Cell cell) {
+        if (cell == null) return "";
+
+        switch (cell.getCellType()) {
+            case STRING:
+                return cell.getStringCellValue().trim();
+            case NUMERIC:
+                if (DateUtil.isCellDateFormatted(cell)) {
+                    return new SimpleDateFormat("yyyy骞碝M鏈�").format(cell.getDateCellValue());
+                }
+                return String.valueOf((int) cell.getNumericCellValue());
+            case BOOLEAN:
+                return String.valueOf(cell.getBooleanCellValue());
+            case FORMULA:
+                return handleFormulaCell(cell);
+            default:
+                return "";
+        }
+    }
+
+    /**
+        * 澶勭悊鍏紡鍗曞厓鏍�
+    */
+    private String handleFormulaCell(Cell cell) {
+        try {
+            FormulaEvaluator evaluator = cell.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
+            CellValue cellValue = evaluator.evaluate(cell);
+
+            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 "";
+            }
+        } catch (Exception e) {
+            return "";
+        }
+    }
+    /*瀵煎叆鏂囦欢--------------------------缁撴潫*/
 }

--
Gitblit v1.9.3