kimi42345
2020-03-11 2c43f24c1a778b48ac20b07e17f5da38136cafb4
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
package com.highdatas.mdm.service.act.impl;
 
import com.highdatas.mdm.entity.TUser;
import org.activiti.engine.IdentityService;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.repository.Model;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
 
import java.util.HashMap;
import java.util.List;
 
@Service
public class IdentityServiceImpl extends BaseServiceImpl implements com.highdatas.mdm.service.act.IdentityService{
    @Autowired
    IdentityService identityService;
    @Autowired
    RuntimeService runtimeService;
    @Autowired
    RepositoryService repositoryService;
 
 
    @Override
    public String startProcess(String businessId, String key) {
        return startProcess(businessId, key, null, null);
    }
 
    @Override
    public String startProcess(String businessId, String key, String workflowStall, HashMap<String, Object> variables) {
        TUser user = getOnlineUser();
        if (user == null) {
            error(" user is null");
            return "";
        }
        
        ProcessInstance processInstance = null;
        try {
            // add workflowstall
 
            if (StringUtils.isEmpty(workflowStall)) {
                workflowStall = "1";
            }
 
            if (variables == null) {
                variables = new HashMap<>();
            }
 
            int workflowStallInt = Integer.parseInt(workflowStall);
            variables.put("workflowstall", workflowStallInt);
            
            identityService.setAuthenticatedUserId(user.getUserId());
 
            //get max version processDefinition
            List<Model> modelList = repositoryService.createModelQuery().modelKey(key).orderByModelVersion().desc().list();
            ProcessDefinition processDefinition = null;
            
            for (Model model : modelList) {
                if (processDefinition == null && model.getDeploymentId() != null) {
                    String deploymentId = model.getDeploymentId();
                    processDefinition = repositoryService.createProcessDefinitionQuery().deploymentId(deploymentId).singleResult();
                }
            }
            
            processInstance = runtimeService.startProcessInstanceById(processDefinition.getId(), businessId, variables);
 
            String processInstanceId = processInstance.getId();
            //TODO db
//            NamedSQL updateActinstUserSql = NamedSQL.getInstance("updateActinstUser");
//            updateActinstUserSql.setParam("userid", user.getId());
//            updateActinstUserSql.setParam("id", processInstanceId);
//            SQLRunner.execSQL(updateActinstUserSql);
            
            return processInstanceId;
           
        }
        finally {
            identityService.setAuthenticatedUserId(null);
        }
    }
 
 
}