yangys
2025-09-13 e853c35455332a4652ec604c650ca82c411c864d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package org.springblade.mdm.flow.service.execute;
 
import org.apache.commons.lang3.StringUtils;
import org.flowable.task.api.Task;
import org.springblade.core.log.exception.ServiceException;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.support.Kv;
import org.springblade.core.tool.utils.Func;
import org.springblade.core.tool.utils.StringUtil;
import org.springblade.mdm.basesetting.machine.entity.Machine;
import org.springblade.mdm.basesetting.machine.service.MachineService;
import org.springblade.mdm.commons.service.ParamService;
import org.springblade.mdm.commons.service.UserCommonService;
import org.springblade.mdm.flow.constants.FlowContants;
import org.springblade.mdm.flow.constants.FlowVariableContants;
import org.springblade.mdm.flow.service.FlowCommonService;
import org.springblade.mdm.flow.service.FlowProgramFileService;
import org.springblade.mdm.flow.service.FlowProgramProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
 
import java.util.Map;
 
/**
 * 试切流程完成任务的实现
 */
@Service("tryFlowCompleteService")
public class TryFlowCompleteService extends AbstractFlowCompleteService {
    @Autowired
    private FlowProgramFileService flowProgramFileService;
 
    @Autowired
    private ParamService paramService;
    @Autowired
    private FlowCommonService flowCommonService;
    @Autowired
    private UserCommonService userCommonService;
    @Autowired
    private MachineService machineService;
 
    @Transactional
    @Override
    public void completeTask(String taskId, String processInstanceId, String comment, Map<String, Object> variables) {
        Task task = currentTask(taskId);
 
        // 非空判断
        if (Func.isEmpty(variables)) {
            variables = Kv.create();
        }
        String operateResult = this.getApproveResult(variables);
 
        FlowProgramProperties props = flowCommonService.getProgramProperties(processInstanceId);
        if(!variables.containsKey("assignee")) {
            throw new ServiceException("请指定流程下一步处理人");
        }
 
        if(task.getTaskDefinitionKey().equals("programmingTask") ) {//编制节点
            //记录实际编程员
            variables.put(FlowVariableContants.ACT_PROGRAMMER,Func.toStr(AuthUtil.getUserId()));
            String programOnMachine = Func.toStr(variables.getOrDefault("programOnMachine",FlowContants.N));//是否现场编程
            if(this.needUploadProgramFile(props.getMachineCode()) && programOnMachine.equals(FlowContants.N)) {
                flowProgramFileService.checkProgramFiles(processInstanceId, FlowContants.Y.equals(operateResult));
            }
        }else if(task.getTaskDefinitionKey().equals("teamLeaderTask")){
            if(FlowContants.Y.equals(operateResult)) {
                runtimeService.setVariable(task.getExecutionId(),FlowContants.PROGRAMMER_NAME,userCommonService.getUserNameById(Func.toLong(variables.get("assignee"))));
            }
        }else if(task.getTaskDefinitionKey().equals("check")){
            variables.put(FlowVariableContants.ACT_CHECKER,Func.toStr(AuthUtil.getUserId()));
        }else if(task.getTaskDefinitionKey().equals("approveTask")){
            variables.put(FlowVariableContants.ACT_SENIOR,Func.toStr(AuthUtil.getUserId()));
        }
        variables.remove("programOnMachine");//其他节点,忽略现场编程标记
        if (StringUtil.isNoneBlank(processInstanceId, comment)) {
            taskService.addComment(taskId, processInstanceId, comment);
        }
 
        variables.put(FlowVariableContants.LAST_STEP_USER_NICKNAME, AuthUtil.getNickName());
 
        variables.remove(FlowVariableContants.PROCESS_EDITION);//不要升版了
 
        if("confirmIsUseableTask".equals(task.getTaskDefinitionKey())){
            variables.put(FlowContants.CURE_PROGRAM_USEABLE,operateResult);
 
            if(FlowContants.Y.equals(operateResult)) {
                //判定可用,记录为实际编程员
                variables.put(FlowVariableContants.ACT_PROGRAMMER,Func.toStr(AuthUtil.getUserId()));
            }
        }
        taskService.complete(taskId, variables);
    }
 
 
    /**
     * 是否需要上传文件(车床不需要)
     * @param machineCode 机床编码
     * @return 是否需要上传
     */
    boolean needUploadProgramFile(String machineCode){
        boolean need;
        Machine machine = machineService.getByCode(machineCode);
        String turning = paramService.turninngValue();
        need = !StringUtils.equals(turning,machine.getMachineSpec());
        return need;
    }
 
}