From b16d7f9fd029bf9d37bcc3c6f3cf8472a0081888 Mon Sep 17 00:00:00 2001
From: lyh <925863403@qq.com>
Date: 星期六, 26 七月 2025 16:34:46 +0800
Subject: [PATCH] 设备故障登记修改与产品安全确认

---
 lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamReportProductHazardsServiceImpl.java |  233 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 228 insertions(+), 5 deletions(-)

diff --git a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamReportProductHazardsServiceImpl.java b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamReportProductHazardsServiceImpl.java
index 2d0e9f1..21645f0 100644
--- a/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamReportProductHazardsServiceImpl.java
+++ b/lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/service/impl/EamReportProductHazardsServiceImpl.java
@@ -1,5 +1,8 @@
 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.conditions.update.UpdateWrapper;
@@ -8,22 +11,39 @@
 import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
 import org.apache.commons.lang3.StringUtils;
 import org.apache.shiro.SecurityUtils;
+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.constant.DataBaseConstant;
+import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.common.util.oConvertUtils;
+import org.jeecg.modules.eam.constant.BusinessCodeConst;
+import org.jeecg.modules.eam.constant.EamReportAccidentsRegisterEnum;
+import org.jeecg.modules.eam.constant.EamReportProductHazardsEnum;
 import org.jeecg.modules.eam.dto.EamReportProductHazardsDto;
+import org.jeecg.modules.eam.entity.EamEquipment;
+import org.jeecg.modules.eam.entity.EamReportAccidentsRegister;
 import org.jeecg.modules.eam.entity.EamReportProductHazards;
 import org.jeecg.modules.eam.entity.EamReportRepair;
 import org.jeecg.modules.eam.mapper.EamReportProductHazardsMapper;
 import org.jeecg.modules.eam.request.EamReportProductHazardsQuery;
+import org.jeecg.modules.eam.service.IEamEquipmentService;
 import org.jeecg.modules.eam.service.IEamReportProductHazardsService;
 import org.jeecg.modules.eam.service.IEamReportRepairService;
+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.entity.BaseFactory;
 import org.jeecg.modules.system.entity.BaseFactoryUser;
 import org.jeecg.modules.system.service.IBaseFactoryService;
 import org.jeecg.modules.system.service.IBaseFactoryUserService;
+import org.jeecg.modules.system.service.ISysUserService;
+import org.jeecg.modules.system.vo.UserSelector;
 import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.context.annotation.Lazy;
@@ -31,9 +51,8 @@
 
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 
-import java.util.Arrays;
-import java.util.List;
-import java.util.Set;
+import javax.annotation.Resource;
+import java.util.*;
 import java.util.stream.Collectors;
 
 /**
@@ -43,7 +62,7 @@
  * @Version: V1.0
  */
 @Service("IEamReportProductHazardsService")
-public class EamReportProductHazardsServiceImpl extends ServiceImpl<EamReportProductHazardsMapper, EamReportProductHazards> implements IEamReportProductHazardsService {
+public class EamReportProductHazardsServiceImpl extends ServiceImpl<EamReportProductHazardsMapper, EamReportProductHazards> implements IEamReportProductHazardsService, FlowCallBackServiceI {
 
     @Autowired
     private IBaseFactoryUserService baseFactoryUserService;
@@ -52,7 +71,25 @@
     @Autowired
     @Lazy
     private IEamReportRepairService iEamReportRepairService;
+    @Resource
+    private IFlowMyBusinessService flowMyBusinessService;
 
+    @Resource
+    private TaskService taskService;
+
+    @Resource
+    private IFlowTaskService flowTaskService;
+
+    @Autowired
+    private ISysUserService sysUserService;
+
+    @Resource
+    private FlowCommonService flowCommonService;
+
+    @Resource
+    private IFlowDefinitionService flowDefinitionService;
+    @Resource
+    private IEamEquipmentService eamEquipmentService;
     /**
      * 鍒嗛〉鍒楄〃
      * @param page
@@ -94,6 +131,13 @@
             if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getEquipmentName())) {
                 queryWrapper.like("e.equipment_name", eamReportProductHazardsQuery.getEquipmentName());
             }
+            if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getConfirmStatus())) {
+                queryWrapper.eq("erph.confirm_status", eamReportProductHazardsQuery.getConfirmStatus());
+            }
+            if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getProductLoss())) {
+                queryWrapper.eq("erph.product_loss", eamReportProductHazardsQuery.getProductLoss());
+            }
+            queryWrapper.eq("erph.del_flag", CommonConstant.DEL_FLAG_0);
             //鎺掑簭
             if (StringUtils.isNotBlank(eamReportProductHazardsQuery.getColumn()) && StringUtils.isNotBlank(eamReportProductHazardsQuery.getOrder())) {
                 String column = eamReportProductHazardsQuery.getColumn();
@@ -137,7 +181,164 @@
      */
     @Override
     public Result<?> submit(String id){
-        return null;
+        EamReportProductHazards eamReportProductHazards=this.getById(id);
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        EamEquipment eamEquipment = eamEquipmentService.getById(eamReportProductHazards.getEquipmentId());
+        List<UserSelector> userSelectorList = sysUserService.selectOperatorList(eamEquipment.getEquipmentCode(), eamEquipment.getFactoryOrgCode(), BusinessCodeConst.PCR0024);
+        // 鍚姩璁惧浜嬫晠鐧昏娴佺▼
+        flowCommonService.initActBusiness("璁惧缂栧彿锛�" + eamEquipment.getEquipmentCode() + ", 璁惧鍚嶇О锛�" + eamEquipment.getEquipmentName()+"鍙戣捣浜у搧瀹夊叏闅愭偅纭娴佺▼",
+                eamReportProductHazards.getId(),
+                "IEamReportProductHazardsService",
+                "eam_report_product_hazards",
+                null);
+        Map<String, Object> variables = new HashMap<>();
+        variables.put("dataId", eamReportProductHazards.getId());
+        variables.put("organization", "鎿嶄綔宸ユ彁浜ゅ惎鍔ㄦ祦绋�");
+        variables.put("comment", "鎿嶄綔宸ユ彁浜ゅ崟鍚姩娴佺▼");
+        variables.put("proofreading", true);
+        if (CollectionUtils.isEmpty(userSelectorList)) {
+            throw new JeecgBootException("璁惧鏈瓨鍦ㄤ富绠″伐鑹猴紝鏃犳硶杩涘叆涓嬬骇瀹℃壒锛�");
+        }else {
+            List<String> usernameList = userSelectorList.stream().map(UserSelector::getUsername).collect(Collectors.toList());
+            variables.put("NextAssignee", usernameList);
+        }
+        Result result = flowDefinitionService.startProcessInstanceByKey("eam_report_product_hazards", variables);
+        if (!result.isSuccess()) {
+            return Result.error("娴佺▼鍚姩澶辫触");
+        } else {
+            eamReportProductHazards.setConfirmer(user.getUsername());
+            eamReportProductHazards.setConfirmTime(new Date());
+            eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.PENDING_SUPERIOR_TECHNICAL_CONFIRMATION.name());
+            this.updateById(eamReportProductHazards);
+            return result;
+        }
+    }
+
+    /**
+     * 娴佺▼瀹℃牳
+     * @param eamReportProductHazardsDto
+     */
+    @Override
+    public Result<?> audit(EamReportProductHazardsDto eamReportProductHazardsDto){
+        EamReportProductHazards eamReportProductHazards = this.baseMapper.selectById(eamReportProductHazardsDto.getId());
+        if (eamReportProductHazards == null) {
+            throw new JeecgBootException("宸ュ崟涓嶅瓨鍦紝璇峰埛鏂伴噸璇曪紒");
+        }
+        // 鑾峰彇褰撳墠鐧诲綍鐢ㄦ埛
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
+        if (user == null || StrUtil.isBlank(user.getId())) {
+            throw new JeecgBootException("鏈幏鍙栧埌鐧诲綍鐢ㄦ埛锛岃閲嶆柊鐧诲綍鍚庡啀璇曪紒");
+        }
+        eamReportProductHazardsDto.setAssignee(user.getUsername());
+        // 鑾峰彇娴佺▼涓氬姟璁板綍
+        FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(eamReportProductHazardsDto.getInstanceId());
+        if (flowMyBusiness == null) {
+            throw new JeecgBootException("娴佺▼瀹炰緥涓嶅瓨鍦紝璇峰埛鏂板悗閲嶈瘯锛�");
+        }
+        boolean userAuthorized = isUserAuthorized(flowMyBusiness, user);
+        if (!userAuthorized) {
+            throw new JeecgBootException("鐢ㄦ埛鏃犳潈鎿嶄綔姝や换鍔★紝璇峰埛鏂板悗閲嶈瘯锛�");
+        }
+        // 璁ら浠诲姟
+        if (!claimTask(flowMyBusiness.getTaskId(), user)) {
+            throw new JeecgBootException("浠诲姟涓嶅瓨鍦ㄣ�佸凡瀹屾垚鎴栧凡琚粬浜鸿棰嗭紒");
+        }
+        EamEquipment equipment = eamEquipmentService.getById(eamReportProductHazardsDto.getEquipmentId());
+        if (equipment == null) {
+            throw new JeecgBootException("璁惧涓嶅瓨鍦紝璇锋鏌ワ紒");
+        }
+        EamReportProductHazardsEnum status = EamReportProductHazardsEnum.getInstance(eamReportProductHazards.getConfirmStatus());
+        if (status == null) {
+            return null;
+        }
+        //娴佺▼鍙橀噺
+        Map<String, Object> values = new HashMap<>();
+        List<String> userApprovalList;
+        List<UserSelector> userSelectors;
+        switch (status) {
+            //寰呬富绠″伐鑹虹‘璁�
+            case PENDING_SUPERIOR_TECHNICAL_CONFIRMATION:
+                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0025);
+                if (CollectionUtil.isEmpty(userSelectors)) {
+                    throw new JeecgBootException("璁惧鏈瓨鍦ㄥ壇閮ㄧ骇棰嗗锛屾棤娉曡繘鍏ヤ笅绾у鎵癸紒");
+                }else{
+                    userApprovalList= userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
+                    values.put("NextAssignee", userApprovalList);
+                    values.put("dataId", eamReportProductHazardsDto.getId());
+                    if (StrUtil.isEmpty(eamReportProductHazardsDto.getTechnologistComment())){
+                        eamReportProductHazardsDto.setTechnologistComment("");
+                    }
+                    values.put("organization",eamReportProductHazardsDto.getTechnologistComment());
+                    values.put("comment", eamReportProductHazardsDto.getTechnologistComment());
+                    values.put("technologistResult", eamReportProductHazardsDto.getTechnologistResult());
+                    eamReportProductHazardsDto.setComment(eamReportProductHazardsDto.getTechnologistComment());
+                    eamReportProductHazards.setTechnologist(user.getUsername());
+                    eamReportProductHazards.setTechnologistTime(new Date());
+                    eamReportProductHazards.setTechnologistResult(eamReportProductHazardsDto.getTechnologistResult());
+                    eamReportProductHazards.setTechnologistComment(eamReportProductHazardsDto.getTechnologistComment());
+                    if ("2".equals(eamReportProductHazardsDto.getTechnologistResult())){
+                        //涓荤宸ヨ壓鎷掔粷
+                        eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.REJECTED.name());
+                    }else {
+                        eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.PENDING_DEPARTMENT_LEADER_CONFIRMATION.name());
+                    }
+                }
+                break;
+            //寰呭壇閮ㄧ骇棰嗗纭
+            case PENDING_DEPARTMENT_LEADER_CONFIRMATION:
+                values.put("dataId", eamReportProductHazardsDto.getId());
+                if (StrUtil.isEmpty(eamReportProductHazardsDto.getDeputyDepartmentComment())){
+                    eamReportProductHazardsDto.setDeputyDepartmentComment("");
+                }
+                values.put("organization",eamReportProductHazardsDto.getDeputyDepartmentComment());
+                values.put("comment", eamReportProductHazardsDto.getDeputyDepartmentComment());
+                values.put("deputyDepartmentResult", eamReportProductHazardsDto.getDeputyDepartmentResult());
+                eamReportProductHazardsDto.setComment(eamReportProductHazardsDto.getDeputyDepartmentComment());
+                eamReportProductHazards.setDeputyDepartment(user.getUsername());
+                eamReportProductHazards.setDeputyDepartmentTime(new Date());
+                eamReportProductHazards.setDeputyDepartmentResult(eamReportProductHazardsDto.getDeputyDepartmentResult());
+                eamReportProductHazards.setDeputyDepartmentComment(eamReportProductHazardsDto.getDeputyDepartmentComment());
+                if ("2".equals(eamReportProductHazardsDto.getDeputyDepartmentResult())){
+                    //鍓儴绾ч瀵兼嫆缁�
+                    eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.REJECTED.name());
+                }else {
+                    eamReportProductHazards.setConfirmStatus(EamReportProductHazardsEnum.REPAIR_COMPLETED.name());
+                }
+                break;
+            default:
+                throw  new JeecgBootException("瀹℃壒澶辫触");
+        }
+        eamReportProductHazardsDto.setValues(values);
+        //淇濆瓨宸ュ崟
+        this.updateById(eamReportProductHazards);
+        Result result = flowTaskService.complete(eamReportProductHazardsDto);
+        if (!result.isSuccess()) {
+            throw new JeecgBootException("瀹℃壒澶辫触锛岃鍒锋柊鏌ョ湅锛�");
+        }
+        return Result.ok("瀹℃壒鎴愬姛");
+    }
+
+    private boolean claimTask(String taskId, LoginUser user) {
+        Task task = taskService.createTaskQuery().taskId(taskId).singleResult();
+        if (task == null) {
+            return false;
+        }
+        if (task.getAssignee() != null && !task.getAssignee().equals(user.getUsername())) {
+            return false;
+        }
+        taskService.claim(taskId, user.getUsername());
+        return true;
+    }
+
+    /**
+     * 鍒ゆ柇鐢ㄦ埛鏄惁鎷ユ湁姝ゆ潈闄�
+     * @param flowMyBusiness
+     * @param user
+     * @return
+     */
+    private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) {
+        List<String> todoUsers = JSON.parseArray(flowMyBusiness.getTodoUsers(), String.class);
+        return todoUsers != null && todoUsers.contains(user.getUsername());
     }
 
     /**
@@ -166,4 +367,26 @@
         this.removeById(id);
         return true;
     }
+
+    @Override
+    public void afterFlowHandle(FlowMyBusiness business) {
+
+    }
+
+    @Override
+    public Object getBusinessDataById(String dataId) {
+        return null;
+    }
+
+    @Override
+    public Map<String, Object> flowValuesOfTask(String taskNameId, Map<String, Object> values) {
+        return Collections.emptyMap();
+    }
+
+    @Override
+    public List<String> flowCandidateUsernamesOfTask(String taskNameId, Map<String, Object> values) {
+        //鑾峰彇涓嬩竴姝ュ鐞嗕汉
+        Object object = values.get("NextAssignee");
+        return (List<String>) object;
+    }
 }

--
Gitblit v1.9.3