Lius
7 天以前 a93ad6deba13025c021e59d209aec90f30ec79f9
三保流程处理
已修改5个文件
621 ■■■■■ 文件已修改
db/LS/dict_ls.sql 39 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/constant/ThirdMaintenanceStatusEnum.java 5 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamThirdMaintenanceOrder.java 5 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/request/EamThirdMaintenanceRequest.java 124 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamThirdMaintenanceOrderServiceImpl.java 448 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
db/LS/dict_ls.sql
@@ -1,6 +1,6 @@
--点检工单状态
delete from [dbo].[sys_dict] where dict_code='inspection_status';
delete from [dbo].[sys_dict_item] where dict_id in (select id from [dbo].[sys_dict] where dict_code='inspection_status');
delete from [dbo].[sys_dict] where dict_code='inspection_status';
INSERT INTO [dbo].[sys_dict] ([id], [dict_name], [dict_code], [description], [del_flag], [create_by], [create_time], [update_by], [update_time], [type]) VALUES (N'1907309268858290177', N'点检状态', N'inspection_status', N'设备管理-点检状态', 0, N'admin', '2025-04-02 13:49:00.0000000', N'admin', '2025-04-02 13:49:19.6510000', NULL);
@@ -12,8 +12,8 @@
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1919938438058639361', N'1907309268858290177', N'已过期', N'EXPIRED', '', 6, 1, N'admin', '2025-05-07 10:12:49.0210000', NULL, NULL);
--点检结果状态
delete from [dbo].[sys_dict] where dict_code='inspection_project_result';
delete from [dbo].[sys_dict_item] where dict_id in (select id from [dbo].[sys_dict] where dict_code='inspection_project_result');
delete from [dbo].[sys_dict] where dict_code='inspection_project_result';
INSERT INTO [dbo].[sys_dict] ([id], [dict_name], [dict_code], [description], [del_flag], [create_by], [create_time], [update_by], [update_time], [type]) VALUES (N'1745288324644782081', N'点检结果', N'inspection_project_result', '', 0, N'admin', '2024-01-11 11:35:37.1360000', NULL, NULL, NULL);
@@ -26,3 +26,38 @@
delete from [dbo].[sys_fill_rule] where rule_code='org_repair_deport_rule';
INSERT INTO [dbo].[sys_fill_rule] ([id], [rule_name], [rule_code], [rule_class], [rule_params], [update_by], [update_time], [create_by], [create_time]) VALUES (N'1676142178556973058', N'维修部门班组编码生成', N'org_repair_deport_rule', N'org.jeecg.modules.system.rule.OrgCodeRepDepRule', N'{"parentId":""}', N'admin', '2025-07-03 11:27:21.0000000', NULL, NULL);
--三保工单
delete from [dbo].[sys_dict_item] where dict_id in (select id from [dbo].[sys_dict] where dict_code='third_maintenance_status');
delete from [dbo].[sys_dict] where dict_code='third_maintenance_status';
INSERT INTO [dbo].[sys_dict] ([id], [dict_name], [dict_code], [description], [del_flag], [create_by], [create_time], [update_by], [update_time], [type]) VALUES (N'1922909404263276545', N'三保状态', N'third_maintenance_status', N'设备管理使用', 0, N'admin', '2025-05-15 14:58:22.0000000', N'admin', '2025-05-15 14:58:49.8990000', NULL);
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1922910056741789698', N'1922909404263276545', N'待保养', N'WAIT_MAINTENANCE', '', 1, 1, N'admin', '2025-05-15 15:00:58.1250000', NULL, NULL);
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1922910108998623233', N'1922909404263276545', N'保养中', N'UNDER_MAINTENANCE', '', 2, 1, N'admin', '2025-05-15 15:01:10.5850000', NULL, NULL);
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1922910161423228930', N'1922909404263276545', N'已完成', N'COMPLETE', '', 10, 1, N'admin', '2025-05-15 15:01:23.0000000', N'admin', '2025-07-15 17:13:54.3750000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1922910236320915457', N'1922909404263276545', N'已作废', N'ABOLISH', '', 16, 1, N'admin', '2025-05-15 15:01:40.0000000', N'admin', '2025-07-15 17:14:40.2330000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958519301062657', N'1922909404263276545', N'待检查', N'WAIT_CHECK', '', 3, 1, N'admin', '2025-07-12 17:00:02.0000000', N'admin', '2025-07-12 17:01:49.4260000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958562884075521', N'1922909404263276545', N'操作人签字', N'OPERATOR_SIGNATURE', '', 6, 1, N'admin', '2025-07-12 17:00:13.0000000', N'admin', '2025-07-15 17:12:54.6730000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958611886129153', N'1922909404263276545', N'维修人签字', N'REPAIRMAN_SIGNATURE', '', 7, 1, N'admin', '2025-07-12 17:00:24.0000000', N'admin', '2025-07-15 17:13:01.7110000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_or der], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958653095165954', N'1922909404263276545', N'维修室主任签字', N'REPAIR_MANAGER_SIGNATURE', '', 8, 1, N'admin', '2025-07-12 17:00:34.0000000', N'admin', '2025-07-15 17:13:42.1570000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958696120336385', N'1922909404263276545', N'设备检查人签字', N'INSPECTOR_SIGNATURE', '', 9, 1, N'admin', '2025-07-12 17:00:44.0000000', N'admin', '2025-07-15 17:13:47.3310000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958736733782017', N'1922909404263276545', N'已锁定', N'FREEZE', '', 11, 1, N'admin', '2025-07-12 17:00:54.0000000', N'admin', '2025-07-15 17:14:00.0630000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958772678967297', N'1922909404263276545', N'变更中', N'CHANGE', '', 14, 1, N'admin', '2025-07-12 17:01:03.0000000', N'admin', '2025-07-15 17:14:14.6490000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1943958818908585985', N'1922909404263276545', N'已取消', N'CANCEL', '', 15, 1, N'admin', '2025-07-12 17:01:14.0000000', N'admin', '2025-07-15 17:14:32.3000000');
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1945048767556866049', N'1922909404263276545', N'第一次验收中', N'UNDER_FIRST_ACCEPTANCE', '', 4, 1, N'admin', '2025-07-15 17:12:18.1080000', NULL, NULL);
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1945048856438362113', N'1922909404263276545', N'第二次验收中', N'UNDER_SECOND_ACCEPTANCE', '', 5, 1, N'admin', '2025-07-15 17:12:39.2920000', NULL, NULL);
--设备功能是否
delete from [dbo].[sys_dict_item] where dict_id in (select id from [dbo].[sys_dict] where dict_code='equipment_function_yn');
delete from [dbo].[sys_dict] where dict_code='equipment_function_yn';
INSERT INTO [dbo].[sys_dict] ([id], [dict_name], [dict_code], [description], [del_flag], [create_by], [create_time], [update_by], [update_time], [type]) VALUES (N'1945027073496698882', N'设备功能是否', N'equipment_function_yn', N'设备管理使用', 0, N'admin', '2025-07-15 15:46:05.8310000', NULL, NULL, NULL);
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1945027150818693122', N'1945027073496698882', N'是', N'Y', '', 1, 1, N'admin', '2025-07-15 15:46:24.2780000', NULL, NULL);
INSERT INTO [dbo].[sys_dict_item] ([id], [dict_id], [item_text], [item_value], [description], [sort_order], [status], [create_by], [create_time], [update_by], [update_time]) VALUES (N'1945027186277339138', N'1945027073496698882', N'否', N'N', '', 2, 1, N'admin', '2025-07-15 15:46:32.7290000', NULL, NULL);
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/constant/ThirdMaintenanceStatusEnum.java
@@ -1,9 +1,14 @@
package org.jeecg.modules.eam.constant;
import lombok.Getter;
@Getter
public enum ThirdMaintenanceStatusEnum {
    WAIT_MAINTENANCE, //待保养
    UNDER_MAINTENANCE, //保养中
    WAIT_CHECK, //待检查
    UNDER_FIRST_ACCEPTANCE, //第一次验收中
    UNDER_SECOND_ACCEPTANCE, //第二次验收中
    OPERATOR_SIGNATURE, // 操作人签字
    REPAIRMAN_SIGNATURE, // 维修人签字
    REPAIR_MANAGER_SIGNATURE, //维修室主任签字
lxzn-module-eam-common/src/main/java/org/jeecg/modules/eam/entity/EamThirdMaintenanceOrder.java
@@ -1,6 +1,5 @@
package org.jeecg.modules.eam.entity;
import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.fasterxml.jackson.annotation.JsonFormat;
@@ -98,7 +97,7 @@
     */
    @Excel(name = "维修人", width = 15)
    @ApiModelProperty(value = "维修人")
    @Dict(dicCode = "sys_user, realname, username")
    @Dict(dictTable = "sys_user", dicCode = "username", dicText = "realname")
    private String repairman;
    /**
     * 保养状态
@@ -159,7 +158,6 @@
     */
    @Excel(name = "协助操作人", width = 15)
    @ApiModelProperty(value = "协助操作人")
    @Dict(dicCode = "sys_user, realname, username")
    private String assistantOperator;
    /**
     * 操作人签字时间
@@ -181,7 +179,6 @@
     */
    @Excel(name = "协助维修人", width = 15)
    @ApiModelProperty(value = "协助维修人")
    @Dict(dicCode = "sys_user, realname, username")
    private String assistantRepairman;
    /**
     * 维修人签字时间
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/request/EamThirdMaintenanceRequest.java
@@ -6,9 +6,10 @@
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.jeecg.common.api.vo.FileUploadResult;
import org.jeecg.common.aspect.annotation.Dict;
import org.jeecg.modules.eam.entity.EamThirdMaintenanceOrderDetail;
import org.jeecg.modules.flowable.domain.vo.FlowTaskVo;
import org.jeecgframework.poi.excel.annotation.Excel;
import org.springframework.format.annotation.DateTimeFormat;
import java.io.Serializable;
@@ -18,55 +19,120 @@
@Data
@EqualsAndHashCode(callSuper = false)
@Accessors(chain = true)
@ApiModel(value="三保对象", description="三保")
@ApiModel(value = "三保对象", description = "三保")
public class EamThirdMaintenanceRequest extends FlowTaskVo implements Serializable {
    /**主键*/
    private static final long serialVersionUID = -385597100123768119L;
    /**
     * 主键
     */
    @ApiModelProperty(value = "主键")
    private String id;
    /**工单号*/
    /**
     * 工单号
     */
    @ApiModelProperty(value = "工单号")
    private String orderNum;
    /**设备ID*/
    /**
     * 设备ID
     */
    @ApiModelProperty(value = "设备ID")
    private String equipmentId;
    /**标准ID*/
    /**
     * 标准ID
     */
    @ApiModelProperty(value = "标准ID")
    private String standardId;
    /**保养日期*/
    /**
     * 保养日期
     */
    @ApiModelProperty(value = "保养日期")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd")
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date maintenanceDate;
    /**保养人*/
    @ApiModelProperty(value = "保养人")
    private String operator;
    /**保养图片*/
    @ApiModelProperty(value = "保养图片")
    private String imageFiles;
    /**保养图片*/
    @ApiModelProperty(value = "保养图片")
    private List<FileUploadResult> imageFilesResult;
    /**备注*/
    /**
     * 维修人
     */
    @ApiModelProperty(value = "维修人")
    @Dict(dictTable = "sys_user", dicCode = "username", dicText = "realname")
    private String repairman;
    /**
     * 保养状态
     */
    @ApiModelProperty(value = "保养状态;待保养、保养中、待检查、操作人签字、维修人签字、维修室主任签字、设备检查人签字、已完成、已锁定、变更中、已取消")
    @Dict(dicCode = "third_maintenance_status")
    private String maintenanceStatus;
    /**
     * 备注
     */
    @ApiModelProperty(value = "备注")
    private String remark;
    /**创建方式*/
    /**
     * 创建方式
     */
    @ApiModelProperty(value = "创建方式")
    @Dict(dicCode = "order_creation_method")
    private String creationMethod;
    /**列表 保养项明细*/
    /**
     * 设备功能是否齐备;是否
     */
    @ApiModelProperty(value = "设备功能是否齐备;是否")
    @Dict(dicCode = "equipment_function_yn")
    private String fullyFunctional;
    /**
     * 设备功能是否齐备;是否
     */
    @ApiModelProperty(value = "设备功能是否正常运转;是否")
    @Dict(dicCode = "equipment_function_yn")
    private String runningNormally;
    /**
     * 问题描述
     */
    @ApiModelProperty(value = "问题描述")
    private String problemDescription;
    /**
     * 列表 保养项明细
     */
    @ApiModelProperty(value = "列表 保养项明细")
    private List<EamThirdMaintenanceOrderDetail> tableDetailList;
    /**删除 保养项明细*/
    /**
     * 删除 保养项明细
     */
    @ApiModelProperty(value = "删除 保养项明细")
    private List<EamThirdMaintenanceOrderDetail> removeDetailList;
    //确认操作
    /**确认意见*/
    @ApiModelProperty(value = "确认意见")
    private String confirmComment;
    @ApiModelProperty(value = "确认类型")
    private String confirmDealType;
    /**领导确认意见*/
    @ApiModelProperty(value = "领导确认意见")
    private String leaderConfirmComment;
    /**
     * 操作人签字
     */
    @ApiModelProperty(value = "操作人签字")
    private String operatorSignatureResult;
    /**
     * 协助操作人
     */
    @ApiModelProperty(value = "协助操作人")
    private String assistantOperator;
    /**
     * 维修人签字
     */
    @ApiModelProperty(value = "维修人签字")
    private String repairmanSignatureResult;
    /**
     * 协助维修人
     */
    @Excel(name = "协助维修人", width = 15)
    @ApiModelProperty(value = "协助维修人")
    private String assistantRepairman;
    /**
     * 维修室主任签字
     */
    @ApiModelProperty(value = "维修室主任签字")
    private String repairManagerSignatureResult;
    /**
     * 设备检查人签字
     */
    @ApiModelProperty(value = "设备检查人签字")
    private String inspectorSignatureResult;
}
lxzn-module-eam/src/main/java/org/jeecg/modules/eam/service/impl/EamThirdMaintenanceOrderServiceImpl.java
@@ -18,6 +18,7 @@
import org.jeecg.common.constant.DataBaseConstant;
import org.jeecg.common.exception.JeecgBootException;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.StrUtils;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.eam.aspect.annotation.EquipmentHistoryLog;
import org.jeecg.modules.eam.constant.*;
@@ -40,6 +41,7 @@
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.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
@@ -76,8 +78,6 @@
    @Autowired
    private IEamEquipmentService eamEquipmentService;
    @Autowired
    private IEamReportRepairService eamReportRepairService;
    @Autowired
    private IEamEquipmentExtendService eamEquipmentExtendService;
    @Resource
@@ -87,6 +87,8 @@
    @Resource
    private IEamBaseHFCodeService eamBaseHFCodeService;
    @Resource
    private IEamThirdMaintenanceOrderDetailService eamThirdMaintenanceOrderDetailService;
    @Override
    public IPage<EamThirdMaintenanceOrder> queryPageList(Page<EamThirdMaintenanceOrder> page, EamThirdMaintenanceQuery query) {
@@ -108,7 +110,7 @@
                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 {
            } else {
                return page;
            }
        }
@@ -254,24 +256,19 @@
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,添加失败!");
        }
//        if (StringUtils.isBlank(equipment.getEquipmentManager())) {
//            throw new JeecgBootException("设备未分配设备管理员,无法进入下级审批!");
//        }
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (sysUser == null || !BusinessCodeConst.PCR0001.equals(sysUser.getPost())) {
            throw new JeecgBootException("不是操作工,无法领取此工单!");
        if (sysUser == null || !BusinessCodeConst.PCR0002.equals(sysUser.getPost())) {
            throw new JeecgBootException("不是维修工,无法领取此工单!");
        }
        entity.setRepairman(sysUser.getUsername());
        entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
        entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.WAIT_CHECK.name());
        entity.setActualStartTime(new Date());
        eamThirdMaintenanceOrderMapper.updateById(entity);
        //启动流程
        flowCommonService.initActBusiness("工单号:" + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + ";安装位置" + equipment.getInstallationPosition(),
        flowCommonService.initActBusiness("工单号:" + entity.getOrderNum() + ";设备编号: " + equipment.getEquipmentCode() + (equipment.getInstallationPosition() == null ? "" : ";安装位置: " + equipment.getInstallationPosition()),
                entity.getId(), "IEamThirdMaintenanceOrderService", "third_maintenance_process", null);
        Map<String, Object> variables = new HashMap<>();
//        boolean equipmentPrecisionFlag = precisionCheckDetailService.hasPrecisionCheckDetail(entity.getId());
//        variables.put("equipmentPrecisionFlag", equipmentPrecisionFlag);
        variables.put("dataId", entity.getId());
        if (StrUtil.isEmpty(entity.getRemark())) {
            variables.put("organization", "新增三保工单默认启动流程");
@@ -281,9 +278,10 @@
            variables.put("comment", entity.getRemark());
        }
        variables.put("proofreading", true);
        //并行任务会签
        variables.put("maintenance_execution", Collections.singletonList(sysUser.getUsername()));
//        variables.put("precision_check", Collections.singletonList(equipment.getEquipmentManager()));
        // 设置下一步处理人
        List<String> usernames = new ArrayList<>();
        usernames.add(entity.getRepairman());
        variables.put("NextAssignee", usernames);
        Result result = flowDefinitionService.startProcessInstanceByKey("third_maintenance_process", variables);
        if (result != null) {
            //更新设备保养状态
@@ -296,144 +294,290 @@
    @Override
    @Transactional(rollbackFor = Exception.class)
    @EquipmentHistoryLog(operationTag = EquipmentOperationTagEnum.THIRD_MAINTENANCE, businessTable = "eam_third_maintenance_order")
    public EamThirdMaintenanceOrder approval(EamThirdMaintenanceRequest request) {
        EamThirdMaintenanceOrder entity = eamThirdMaintenanceOrderMapper.selectById(request.getId());
        if (entity == null) {
            throw new JeecgBootException("审批的数据已删除,请刷新重试!");
    public EamThirdMaintenanceOrder approval(EamThirdMaintenanceRequest eamThirdMaintenanceRequest) {
        EamThirdMaintenanceOrder eamThirdMaintenanceOrder = eamThirdMaintenanceOrderMapper.selectById(eamThirdMaintenanceRequest.getId());
        if (eamThirdMaintenanceOrder == null) {
            throw new JeecgBootException("待处理的数据已删除,请刷新重试!");
        }
//        // 获取当前登录用户
//        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
//        if (user == null || StrUtil.isBlank(user.getId())) {
//            throw new JeecgBootException("未获取到登录用户,请重新登录后再试!");
//        }
//        request.setAssignee(user.getUsername());
//        // 获取流程业务记录
//        FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(request.getInstanceId(), request.getTaskId());
//        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(entity.getEquipmentId());
//        if (equipment == null) {
//            throw new JeecgBootException("设备不存在,请检查!");
//        }
//
//        ThirdMaintenanceStatusEnum status = ThirdMaintenanceStatusEnum.getInstance(entity.getMaintenanceStatus());
//        if (status == null) {
//            return null;
//        }
//        //流程变量
//        Map<String, Object> values = new HashMap<>();
//        List<String> userApprovalList;
//        List<UserSelector> userSelectors;
//        switch (status) {
//            case UNDER_MAINTENANCE:
//                boolean parallelCompletion = flowTaskService.checkParallelCompletion(flowMyBusiness.getTaskId());
//                //执行完成
//                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), null, BusinessCodeConst.PCR0006);
//                if (CollectionUtil.isEmpty(userSelectors)) {
//                    throw new JeecgBootException("设备未分配给车间班组长,无法进入下级审批!");
//                }
//                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
//                values.put("dataId", entity.getId());
//                values.put("organization", "三保执行结束");
//                values.put("comment", "三保执行结束");
//                if (parallelCompletion) {
//                    values.put("NextAssignee", userApprovalList);
//                }
//                request.setComment("三保执行结束");
//                //设置entity
//                if (parallelCompletion) {
//                    entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.WAIT_CONFIRM.name());
//                    entity.setActualEndTime(new Date());
//                }
//                if ("maintenance_execution".equals(flowMyBusiness.getTaskNameId())) {
//                    //执行保养
//                    //处理附件
//                    if (CollectionUtil.isNotEmpty(request.getImageFilesResult())) {
//                        List<FileUploadResult> fileUploadResultList = request.getImageFilesResult();
//                        ObjectMapper mapper = new ObjectMapper();
//                        try {
//                            String referenceFile = mapper.writeValueAsString(fileUploadResultList);
//                            entity.setImageFiles(referenceFile);
//                        } catch (JsonProcessingException e) {
//                            log.error("JSON转换失败:" + e.getMessage(), e);
//                        }
//                    }
//                    //处理详情
//                    if (CollectionUtil.isNotEmpty(request.getTableDetailList())) {
//                        thirdMaintenanceOrderDetailService.updateBatchById(request.getTableDetailList());
//                    }
//                } else if ("precision_check".equals(flowMyBusiness.getTaskNameId())) {
//                    entity.setPrecisionChecker(user.getUsername());
//                    entity.setPrecisionCheckTime(new Date());
//                    //处理精度检验
//                    if (CollectionUtil.isNotEmpty(request.getPrecisionDetailList())) {
//                        precisionCheckDetailService.updateBatchById(request.getPrecisionDetailList());
//                    }
//                }
//                if (parallelCompletion) {
//                    //更新设备保养状态
//                    eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.THIRD_MAINTENANCE_WAIT_CONFIRM.name());
//                }
//                break;
//            case WAIT_CONFIRM:
//                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(),null, BusinessCodeConst.PCR0003);
//                if (CollectionUtil.isEmpty(userSelectors)) {
//                    throw new JeecgBootException("设备未分配给车间班组长,无法进入下级审批!");
//                }
//                //班组长确认
//                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
//                values.put("dataId", entity.getId());
//                values.put("organization", request.getConfirmComment());
//                values.put("comment", request.getConfirmComment());
//                values.put("NextAssignee", userApprovalList);
//                values.put("confirmation", request.getConfirmDealType());
//                request.setComment(request.getConfirmComment());
//                //设置entity
//                entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.WAIT_LEADER_CONFIRM.name());
//                entity.setConfirmUser(user.getUsername());
//                entity.setConfirmComment(request.getConfirmComment());
//                entity.setConfirmTime(new Date());
//                //处理报修
//                List<EamThirdMaintenanceOrderDetail> collect = request.getTableDetailList().stream().filter((detail) -> CommonConstant.DEFAULT_1.equals(detail.getReportFlag())).collect(Collectors.toList());
//                if (CollectionUtil.isNotEmpty(collect)) {
//                    eamReportRepairService.reportRepairFromThirdMaintenance(equipment.getId(), entity.getOperator(), collect);
//                }
//                break;
//            case WAIT_LEADER_CONFIRM:
//                values.put("dataId", entity.getId());
//                values.put("organization", request.getLeaderConfirmComment());
//                values.put("comment", request.getLeaderConfirmComment());
//                request.setComment(request.getLeaderConfirmComment());
//                //设置entity
//                entity.setMaintenanceStatus(ThirdMaintenanceStatusEnum.COMPLETE.name());
//                entity.setConfirmLeader(user.getUsername());
//                entity.setLeaderConfirmComment(request.getLeaderConfirmComment());
//                entity.setLeaderConfirmTime(new Date());
//                //更新设备保养状态
//                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(entity.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name());
//                break;
//        }
//        request.setValues(values);
//
//        // 完成流程任务
//        Result result = flowTaskService.complete(request);
//        if (!result.isSuccess()) {
//            throw new JeecgBootException("审批失败,请刷新查看!");
//        }
//        //保存工单
//        eamThirdMaintenanceOrderMapper.updateById(entity);
        return entity;
        // 获取当前登录用户
        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        if (user == null || StrUtil.isBlank(user.getId())) {
            throw new JeecgBootException("未获取到登录用户,请重新登录后再试!");
        }
        eamThirdMaintenanceRequest.setAssignee(user.getUsername());
        // 获取流程业务记录
        FlowMyBusiness flowMyBusiness = flowMyBusinessService.getFlowMyBusiness(eamThirdMaintenanceRequest.getInstanceId(), eamThirdMaintenanceRequest.getTaskId());
        if (flowMyBusiness == null) {
            throw new JeecgBootException("流程实例不存在,请刷新后重试!");
        }
        if (!isUserAuthorized(flowMyBusiness, user)) {
            throw new JeecgBootException("用户无权操作此任务,请刷新后重试!");
        }
        // 认领任务
        if (!claimTask(flowMyBusiness.getTaskId(), user)) {
            throw new JeecgBootException("任务不存在、已完成或已被他人认领!");
        }
        EamEquipment equipment = eamEquipmentService.getById(eamThirdMaintenanceOrder.getEquipmentId());
        if (equipment == null) {
            throw new JeecgBootException("设备不存在,请检查!");
        }
        // 设置流程变量
        setupProcessVariables(eamThirdMaintenanceRequest, eamThirdMaintenanceOrder, user, equipment);
        // 完成流程任务
        Result result = flowTaskService.complete(eamThirdMaintenanceRequest);
        // 根据任务完成结果更新工单状态
        updateOrderStatus(result, eamThirdMaintenanceRequest, eamThirdMaintenanceOrder, user);
        //更新工单信息
        eamThirdMaintenanceOrderMapper.updateById(eamThirdMaintenanceOrder);
        return eamThirdMaintenanceOrder;
    }
    /**
     * 设置流程变量
     */
    private void setupProcessVariables(EamThirdMaintenanceRequest request, EamThirdMaintenanceOrder order, LoginUser user, EamEquipment equipment) {
        //流程变量
        Map<String, Object> values = new HashMap<>();
        List<String> userApprovalList;
        List<UserSelector> userSelectors;
        ThirdMaintenanceStatusEnum status = ThirdMaintenanceStatusEnum.getInstance(order.getMaintenanceStatus());
        switch (status) {
            case WAIT_CHECK:
                // 技术状态鉴定结束
                values.put("dataId", order.getId());
                values.put("organization", "技术状态鉴定结束");
                values.put("comment", "技术状态鉴定结束");
                if (CommonConstant.YN_Y.equals(request.getFullyFunctional()) && CommonConstant.YN_Y.equals(request.getRunningNormally())) {
                    values.put("confirmation", "1");
                    // 获取下一步执行人
                    userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
                    if (CollectionUtil.isEmpty(userSelectors)) {
                        throw new JeecgBootException("设备未分配给维修工,无法进入下级审批!");
                    }
                    userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                    values.put("NextAssignee", userApprovalList);
                    request.setComment("检查人检查结束");
                    //更新设备保养状态
                    eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.UNDER_THIRD_MAINTENANCE.name());
                } else {
                    values.put("confirmation", "2");
                }
                break;
            case UNDER_MAINTENANCE:
                // 保养结束
                values.put("dataId", order.getId());
                values.put("organization", "保养人保养结束");
                values.put("comment", "保养人保养结束");
                // 获取下一步执行人
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给维修工,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("NextAssignee", userApprovalList);
                request.setComment("保养人保养结束");
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.THIRD_MAINTENANCE_WAIT_CONFIRM.name());
                break;
            case UNDER_FIRST_ACCEPTANCE:
                // 第一次验收结束
                values.put("dataId", order.getId());
                values.put("organization", "第一次验收结束");
                values.put("comment", "第一次验收结束");
                boolean flag = false;
                if (!CollectionUtil.isEmpty(request.getTableDetailList())) {
                    for (EamThirdMaintenanceOrderDetail eamThirdMaintenanceOrderDetail : request.getTableDetailList()) {
                        if ("2".equals(eamThirdMaintenanceOrderDetail.getFirstInspectResult())) {
                            flag = true;
                            break;
                        }
                    }
                }
                if (flag) {
                    // 开启第二次验收
                    values.put("confirmation", "2");
                    List<String> usernames = new ArrayList<>();
                    usernames.add(user.getUsername());
                    values.put("NextAssignee", usernames);
                } else {
                    // 流程流转到操作人签字
                    values.put("confirmation", "1");
                    // 获取下一步执行人
                    userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0001);
                    if (CollectionUtil.isEmpty(userSelectors)) {
                        throw new JeecgBootException("设备未分配给操作工,无法进入下级审批!");
                    }
                    userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                    values.put("NextAssignee", userApprovalList);
                }
                request.setComment("第一次验收结束");
                break;
            case UNDER_SECOND_ACCEPTANCE:
                // 第二次验收结束
                values.put("dataId", order.getId());
                values.put("organization", "第二次验收结束");
                values.put("comment", "第二次验收结束");
                // 获取下一步执行人
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0001);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给操作工,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("NextAssignee", userApprovalList);
                request.setComment("第二次验收结束");
                break;
            case OPERATOR_SIGNATURE:
                // 操作人签字结束
                values.put("dataId", order.getId());
                values.put("organization", "操作人签字结束");
                values.put("comment", "操作人签字结束");
                // 获取下一步执行人
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0002);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给维修工,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("NextAssignee", userApprovalList);
                request.setComment("操作人签字结束");
                break;
            case REPAIRMAN_SIGNATURE:
                // 维修人签字结束
                values.put("dataId", order.getId());
                values.put("organization", "维修人签字结束");
                values.put("comment", "维修人签字结束");
                // 获取下一步执行人
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0008);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给维修室主任,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("NextAssignee", userApprovalList);
                request.setComment("维修人签字结束");
                break;
            case REPAIR_MANAGER_SIGNATURE:
                // 维修室主任签字结束
                values.put("dataId", order.getId());
                values.put("organization", "维修室主任签字结束");
                values.put("comment", "维修室主任签字结束");
                // 获取下一步执行人
                userSelectors = sysUserService.selectOperatorList(equipment.getEquipmentCode(), equipment.getFactoryOrgCode(), BusinessCodeConst.PCR0003);
                if (CollectionUtil.isEmpty(userSelectors)) {
                    throw new JeecgBootException("设备未分配给设备检验员,无法进入下级审批!");
                }
                userApprovalList = userSelectors.stream().map(UserSelector::getUsername).collect(Collectors.toList());
                values.put("NextAssignee", userApprovalList);
                request.setComment("维修室主任签字结束");
                break;
            case INSPECTOR_SIGNATURE:
                // 设备检查人签字结束
                values.put("dataId", order.getId());
                values.put("organization", "维修室主任签字结束");
                values.put("comment", "维修室主任签字结束");
                request.setComment("维修室主任签字结束");
                //更新设备保养状态
                eamEquipmentExtendService.updateEquipmentMaintenanceStatus(order.getEquipmentId(), EquipmentMaintenanceStatus.NORMAL.name());
                break;
        }
        request.setValues(values);
    }
    /**
     * 更新工单状态
     */
    private void updateOrderStatus(Result result, EamThirdMaintenanceRequest request, EamThirdMaintenanceOrder order, LoginUser user) {
        if (result.isSuccess()) {
            ThirdMaintenanceStatusEnum status = ThirdMaintenanceStatusEnum.getInstance(order.getMaintenanceStatus());
            switch (status) {
                case WAIT_CHECK:
                    // 技术状态鉴定结束
                    order.setInspector(user.getUsername());
                    order.setFullyFunctional(request.getFullyFunctional());
                    order.setRunningNormally(request.getRunningNormally());
                    order.setInspectTime(new Date());
                    if (CommonConstant.YN_Y.equals(request.getFullyFunctional()) && CommonConstant.YN_Y.equals(request.getRunningNormally())) {
                        // 鉴定通过
                        order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.UNDER_MAINTENANCE.name());
                    } else {
                        // 鉴定未通过
                        order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.CANCEL.name());
                        order.setProblemDescription(request.getProblemDescription());
                        order.setActualEndTime(new Date());
                    }
                    break;
                case UNDER_MAINTENANCE:
                    // 保养结束
                    order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.UNDER_FIRST_ACCEPTANCE.name());
                    order.setRepairman(user.getUsername());
                    order.setActualEndTime(new Date());
                    // 三保明细处理
                    eamThirdMaintenanceOrderDetailService.remove(new LambdaQueryWrapper<EamThirdMaintenanceOrderDetail>().eq(EamThirdMaintenanceOrderDetail::getOrderId, order.getId()));
                    eamThirdMaintenanceOrderDetailService.saveBatch(request.getTableDetailList());
                    break;
                case UNDER_FIRST_ACCEPTANCE:
                    // 第一次验收结束
                    boolean flag = false;
                    if (!CollectionUtil.isEmpty(request.getTableDetailList())) {
                        for (EamThirdMaintenanceOrderDetail eamThirdMaintenanceOrderDetail : request.getTableDetailList()) {
                            if ("2".equals(eamThirdMaintenanceOrderDetail.getFirstInspectResult())) {
                                flag = true;
                                break;
                            }
                        }
                    }
                    if (flag) {
                        order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.UNDER_SECOND_ACCEPTANCE.name());
                    } else {
                        order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.OPERATOR_SIGNATURE.name());
                    }
                    // 三保明细处理
                    eamThirdMaintenanceOrderDetailService.remove(new LambdaQueryWrapper<EamThirdMaintenanceOrderDetail>().eq(EamThirdMaintenanceOrderDetail::getOrderId, order.getId()));
                    eamThirdMaintenanceOrderDetailService.saveBatch(request.getTableDetailList());
                    break;
                case UNDER_SECOND_ACCEPTANCE:
                    // 第二次验收结束
                    order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.OPERATOR_SIGNATURE.name());
                    // 三保明细处理
                    eamThirdMaintenanceOrderDetailService.remove(new LambdaQueryWrapper<EamThirdMaintenanceOrderDetail>().eq(EamThirdMaintenanceOrderDetail::getOrderId, order.getId()));
                    eamThirdMaintenanceOrderDetailService.saveBatch(request.getTableDetailList());
                    break;
                case OPERATOR_SIGNATURE:
                    // 操作人签字结束
                    if (!StrUtils.isEmpty(request.getAssistantOperator())) {
                        order.setAssistantOperator(request.getAssistantOperator());
                    }
                    order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.REPAIRMAN_SIGNATURE.name());
                    order.setOperatorSignature(user.getUsername());
                    order.setOperatorSignatureTime(new Date());
                    break;
                case REPAIRMAN_SIGNATURE:
                    // 维修人签字结束
                    if (!StrUtils.isEmpty(request.getAssistantRepairman())) {
                        order.setAssistantRepairman(request.getAssistantRepairman());
                    }
                    order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.REPAIR_MANAGER_SIGNATURE.name());
                    order.setRepairmanSignature(user.getUsername());
                    order.setRepairmanSignatureTime(new Date());
                    break;
                case REPAIR_MANAGER_SIGNATURE:
                    // 维修室主任签字结束
                    order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.INSPECTOR_SIGNATURE.name());
                    order.setRepairManagerSignature(user.getUsername());
                    order.setRepairManagerSignatureTime(new Date());
                    break;
                case INSPECTOR_SIGNATURE:
                    // 设备检查人签字结束
                    order.setMaintenanceStatus(ThirdMaintenanceStatusEnum.COMPLETE.name());
                    order.setInspectorSignature(user.getUsername());
                    order.setInspectorSignatureTime(new Date());
                    break;
            }
        }
    }
    private boolean isUserAuthorized(FlowMyBusiness flowMyBusiness, LoginUser user) {