cczhang преди 2 месеца
родител
ревизия
dceb6a01a5

+ 145
- 0
src/main/java/com/horizon/third/adapter/FlowManageAdapter.java Целия файл

@@ -0,0 +1,145 @@
1
+package com.horizon.third.adapter;
2
+
3
+import java.util.ArrayList;
4
+import java.util.List;
5
+import java.util.Map;
6
+
7
+import org.slf4j.Logger;
8
+import org.slf4j.LoggerFactory;
9
+
10
+import com.horizon.common.base.Objects;
11
+import com.horizon.third.Authority;
12
+import com.horizon.third.Persistence;
13
+import com.horizon.third.init.WorkflowAdapterInit;
14
+
15
+/**
16
+ * 流程管理适配器
17
+ *
18
+ * @author mwr
19
+ *
20
+ */
21
+public class FlowManageAdapter extends WorkflowBaseAdapther implements Authority {
22
+
23
+    private static final Logger LOGGER = LoggerFactory.getLogger(FlowManageAdapter.class);
24
+
25
+    private static final String SELECT_FLOWS = "SELECT A.FLOWID FROM TW_HZ_FLOW_DEF"
26
+            + " A WHERE A.VERSION=(SELECT MAX(VERSION) FROM TW_HZ_FLOW_DEF WHERE FLOWID=A.FLOWID)";
27
+
28
+    /*
29
+     * (non-Javadoc)
30
+     *
31
+     * @see com.horizon.third.Authority#getManager(java.lang.String)
32
+     */
33
+    @Override
34
+    public String getManager(String flowId) {
35
+
36
+        LOGGER.info("流程 {} 默认管理员为 admin ", flowId);
37
+        return "admin";
38
+    }
39
+
40
+    /*
41
+     * (non-Javadoc)
42
+     *
43
+     * @see com.horizon.third.Authority#isStart(java.lang.String,
44
+     * java.lang.String)
45
+     */
46
+    @Override
47
+    public boolean isStart(String flowId, String userId) {
48
+
49
+        LOGGER.info("用户 {} 拥有启动流程 {},默认返回 true ", userId, flowId);
50
+        return true;
51
+    }
52
+
53
+    /*
54
+     * (non-Javadoc)
55
+     *
56
+     * @see com.horizon.third.Authority#isManager(java.lang.String,
57
+     * java.lang.String)
58
+     */
59
+    @Override
60
+    public boolean isManager(String flowId, String userId) {
61
+
62
+        LOGGER.info("流程 {} 管理员 admin ", flowId);
63
+        return Objects.equal("1", userId);
64
+    }
65
+
66
+    /*
67
+     * (non-Javadoc)
68
+     *
69
+     * @see com.horizon.third.Authority#getFlowManageList(java.lang.String,
70
+     * java.lang.String)
71
+     */
72
+    @Override
73
+    public List<String> getFlowManageList(String userid, String identifier) {
74
+
75
+        return getFlowDesignList(userid, identifier);
76
+    }
77
+
78
+    /*
79
+     * (non-Javadoc)
80
+     *
81
+     * @see com.horizon.third.Authority#getFlowDesignList(java.lang.String,
82
+     * java.lang.String)
83
+     */
84
+    @Override
85
+    public List<String> getFlowDesignList(String userId, String dbIdentifier) {
86
+
87
+        Persistence access = (Persistence) WorkflowAdapterInit.getWorkflowAdapthers("access");
88
+        List<List<Object>> lst = access.getMultiList(SELECT_FLOWS, null, dbIdentifier);
89
+        List<String> lstResult = new ArrayList<String>();
90
+        if (lst != null && !lst.isEmpty()) {
91
+            for (List<Object> l : lst) {
92
+                lstResult.add((String) l.get(0));
93
+            }
94
+        }
95
+        return lstResult;
96
+    }
97
+
98
+    /**
99
+     * 获得流程启动权限列表
100
+     *
101
+     * @param userid
102
+     *            用户Id
103
+     * @param identifier
104
+     *            数据源标识
105
+     * @return 具有启动权限的流程Id
106
+     */
107
+    public List<String> getFlowStartList(String userid, String identifier) {
108
+
109
+        Persistence access = (Persistence) WorkflowAdapterInit.getWorkflowAdapthers("access");
110
+        List<List<Object>> lst = access.getMultiList(SELECT_FLOWS, null, identifier);
111
+
112
+        List<String> lstResult = new ArrayList<String>();
113
+        if (lst != null && !lst.isEmpty()) {
114
+            for (List<Object> lstObject : lst) {
115
+
116
+                lstResult.add(String.valueOf(lstObject.get(0)));
117
+            }
118
+        }
119
+        return lstResult;
120
+
121
+    }
122
+
123
+    @Override
124
+    public void authInit(String userId, String dataid, String resourceType, Map<String, List<Object>> saveMap,
125
+                         String dbIdentifier) {
126
+
127
+        // TODO Auto-generated method stub
128
+
129
+    }
130
+
131
+    @Override
132
+    public void releaseBizPermission(String[] dataids, Map<String, List<List<Object>>> saveMap) {
133
+
134
+        // TODO Auto-generated method stub
135
+
136
+    }
137
+
138
+    @Override
139
+    public boolean validateOperatorTenant(String userId, String tenantCode, String dbIdentifier) {
140
+
141
+        // TODO Auto-generated method stub
142
+        return false;
143
+    }
144
+
145
+}

+ 100
- 0
src/main/java/com/horizon/wf/core/rule/SignRule.java Целия файл

@@ -0,0 +1,100 @@
1
+package com.horizon.wf.core.rule;
2
+
3
+import cn.hutool.http.HttpUtil;
4
+import com.horizon.common.constant.Constants;
5
+import com.horizon.wf.bean.WorkParaBean;
6
+import com.horizon.wf.core.runtime.RunningData;
7
+import com.horizon.wf.definition.pub.IFlowNode;
8
+import com.horizon.wf.entity.db.DBTrack;
9
+import com.horizon.wf.entity.db.DBWork;
10
+import com.horizon.wf.entity.user.IRunUser;
11
+import com.horizon.wf.global.StaticVarExtend;
12
+
13
+import java.util.HashMap;
14
+import java.util.List;
15
+import java.util.Map;
16
+
17
+/**
18
+ * 合同业务相关的事件触发器
19
+ * 用于更新合同状态
20
+ */
21
+public class SignRule extends BaseRuleImpl implements IBaseRule {
22
+
23
+    /**
24
+     * 具体的实现,参考下面方法中的说明,所有的实现都差不多结构,
25
+     * 只有自定义的异常处理接口实现中是没有传入 runningdata的.
26
+     * 不同的接口 仅仅是额外传入的参数有些差异,额外的参数多数都是可以从runningdata中获取的
27
+     * 系统为了方便接口的实现,额外传入了一些认为会用到的参数
28
+     *
29
+     * @return
30
+     */
31
+    @Override
32
+    public boolean executeRule() {
33
+        // 从引擎获取到核心数据对象(如果接口没有额外传入需要的数据时,可以从此对象中获取)
34
+        RunningData runningdata = getRunningdata();
35
+        Map<String, String> flowVar = runningdata.getFlowVar().getAllFlowVarMap();
36
+        //事件处理类额外传入参数
37
+        // 1.执行事件的节点对象
38
+        IFlowNode eventNode = (IFlowNode) getParameter(StaticVarExtend.Parameter_IFlowNode);
39
+        // 2.当前节点对象
40
+        IFlowNode curNode = (IFlowNode) getParameter(StaticVarExtend.Parameter_Current_IFlowNode);
41
+        // 3.引擎调用时,传入的参数对象
42
+        WorkParaBean paraBean = (WorkParaBean) getParameter(StaticVarExtend.Parameter_WorkParaBean);
43
+        Map<String, String> varMap = paraBean.getFlowVarMap();
44
+        String action = paraBean.getActionname();
45
+        // 4.当前实例对象
46
+        DBWork work = (DBWork) getParameter(StaticVarExtend.Parameter_DBWork);
47
+        // 5.当前执行人对象
48
+        IRunUser user = (IRunUser) getParameter(StaticVarExtend.Parameter_RunUser);
49
+        // 6.当前路径对象
50
+        DBTrack track = (DBTrack) getParameter(StaticVarExtend.Parameter_DBTrack);
51
+        int status = track.getFlowstatus();
52
+        String nodeId = track.getNodeid();
53
+        String statusName = track.getFunname();
54
+        String nodeName = track.getNodename();
55
+        // 7.需要保存的SQL数据如果需要引擎来保存,请放入此 map中(key=SQL,value=List为SQL中对应的参数)
56
+        Map<String, List<Object>> dataMap = (Map<String, List<Object>>) getParameter(StaticVarExtend.Parameter_SaveMap);
57
+        // 8.事件类型
58
+        String eventType = (String) getParameter("eventType");
59
+        // 9.事件实际执行内容
60
+        // 10.返回 true 表示执行成功,引擎从第7步中的dataMap里获取需要保存的数据,引擎继续往下执行,
61
+        // 返回 false表示执行失败, 引擎会根据事件类型,确定是否继续往下执行
62
+
63
+        if (eventNode.getNodeid().contains("End")) {
64
+            status = 170;
65
+        } else if (eventNode.getNodeid().equals("Node1")) {
66
+            if (statusName.equals("JumpReject") || statusName.equals("Reject")) {
67
+                status = 130;
68
+            } else if (statusName.equals("Getback")) {
69
+                status = 190;
70
+            } else if (statusName.equals("autofirst")) {
71
+                status = 110;
72
+            }
73
+        } else {
74
+            status = 110;
75
+        }
76
+        System.err.println(
77
+                "status:" + status +
78
+                        ",nodeId:" + nodeId +
79
+                        ",nodeName:" + nodeName +
80
+                        ",statusName:" + statusName +
81
+                        ",action:" + action +
82
+                        ",eventNodeId:" + eventNode.getNodeid() +
83
+                        ",eventNodeName:" + eventNode.getNodename());
84
+
85
+        String url = Constants.WF_PRE_URL + "/cot/SignRequest/horizonApprovalProcess";
86
+        // String url = Constants.WF_PRE_URL + "/framework/Schedule/horizonApprovalProcess";
87
+        String id = varMap.get("id");
88
+        System.err.println(id);
89
+        System.err.println(varMap.toString());
90
+        Map<String, Object> params = new HashMap<>();
91
+        params.put("id", id);
92
+        params.put("processInstanceStatus", status);
93
+        System.err.println(url);
94
+        String result = HttpUtil.post(url, params);
95
+        System.err.println("result:" + result);
96
+        return true;
97
+    }
98
+}
99
+
100
+

+ 173
- 0
src/main/java/com/horizon/workflow/rest/web/RestFlowSupportController.java Целия файл

@@ -0,0 +1,173 @@
1
+//
2
+// Source code recreated from a .class file by IntelliJ IDEA
3
+// (powered by FernFlower decompiler)
4
+//
5
+
6
+package com.horizon.workflow.rest.web;
7
+
8
+import com.horizon.common.base.Function;
9
+import com.horizon.common.base.Objects;
10
+import com.horizon.common.collect.Collections2;
11
+import com.horizon.common.collect.Lists;
12
+import com.horizon.core.HorizonCore;
13
+import com.horizon.language.Hi18n;
14
+import com.horizon.utils.HorizonPorps;
15
+import com.horizon.utils.StringUtil;
16
+import com.horizon.utils.json.JsonUtil;
17
+import com.horizon.wf.bean.WorkParaBean;
18
+import com.horizon.wf.core.mem.MemCacheUtil;
19
+import com.horizon.wf.entity.db.DBLog;
20
+import com.horizon.workflow.form.entity.FieldAuth;
21
+import com.horizon.workflow.form.service.ISimpleFormFieldAuthService;
22
+import com.horizon.workflow.monitor.service.IFlowLogService;
23
+import com.horizon.workflow.rest.model.RequestParams;
24
+import com.horizon.workflow.rest.model.ResponseResult;
25
+import com.horizon.workflow.rest.util.RestWorkUtil;
26
+import com.horizon.workflow.rest.web.base.RestSuperController;
27
+import com.horizon.workflow.support.model.FlowAction;
28
+import com.horizon.workflow.support.model.FlowForm;
29
+import com.horizon.workflow.support.model.FlowResult;
30
+import com.horizon.workflow.support.service.IFlowSupportService;
31
+import com.horizon.workflow.tenant.service.ITenantGrantService;
32
+import java.util.Collection;
33
+import java.util.Iterator;
34
+import java.util.List;
35
+import java.util.Map;
36
+import javax.servlet.http.HttpServletRequest;
37
+import org.springframework.beans.factory.annotation.Autowired;
38
+import org.springframework.stereotype.Controller;
39
+import org.springframework.web.bind.annotation.RequestMapping;
40
+import org.springframework.web.bind.annotation.ResponseBody;
41
+
42
+@Controller
43
+@RequestMapping({"${url.prefix}/rest"})
44
+public class RestFlowSupportController extends RestSuperController {
45
+    @Autowired
46
+    private IFlowSupportService flowSupportService;
47
+    @Autowired
48
+    private IFlowLogService flowLogService;
49
+    @Autowired
50
+    private ISimpleFormFieldAuthService simpleFormFieldAuthService;
51
+    @Autowired
52
+    private ITenantGrantService tenantGrantService;
53
+
54
+    public RestFlowSupportController() {
55
+    }
56
+
57
+    @ResponseBody
58
+    @RequestMapping({"/flow/support/open${url.suffix}"})
59
+    public String open() {
60
+        WorkParaBean workParaBean = null;
61
+        ResponseResult result = super.getParamWithToken();
62
+        if (!result.isSuccess()) {
63
+            return this.renderJson(result);
64
+        } else {
65
+            RequestParams params = (RequestParams)result.getData();
66
+            workParaBean = RestWorkUtil.workParaBeanSet(params);
67
+            String workId = workParaBean.getWorkId();
68
+            List activeInstanceIds;
69
+            if ("true".equals(HorizonPorps.getConfig("isValidateOfTenant"))) {
70
+                activeInstanceIds = this.findActiveInstanceIds();
71
+                if (!activeInstanceIds.contains(workId)) {
72
+                    boolean check = this.tenantGrantService.checkTenantWork(HorizonCore.TENANT_CODE.value(), activeInstanceIds.size());
73
+                    if (!check) {
74
+                        return this.renderJson(ResponseResult.failure(Hi18n.getVal("tenant-grant", "checkWork")));
75
+                    }
76
+                }
77
+            }
78
+
79
+            activeInstanceIds = null;
80
+            FlowResult flowResult;
81
+            if (StringUtil.hasValue(workId)) {
82
+                flowResult = this.flowSupportService.open(workParaBean);
83
+            } else {
84
+                //2023-06-09 yangff add 创建流程增加变量传递
85
+                if (null != params.get("actionData")) {
86
+                    String actionData = JsonUtil.toJson(params.get("actionData"));
87
+                    FlowAction flowAction = JsonUtil.fromJson(actionData, FlowAction.class);
88
+                    if(null!=flowAction.getFlowVars()) workParaBean.setFlowVarMap(flowAction.getFlowVars());
89
+                }
90
+                //2023-06-09 add 创建流程增加变量传递 end
91
+                flowResult = this.flowSupportService.create(workParaBean);
92
+            }
93
+
94
+            this.setFormFieldAuth(flowResult.getFlowForms());
95
+            return this.renderJson(flowResult);
96
+        }
97
+    }
98
+
99
+    @ResponseBody
100
+    @RequestMapping({"/flow/support/action${url.suffix}"})
101
+    public String action(HttpServletRequest request) {
102
+        ResponseResult result = super.getParamWithToken();
103
+        if (!result.isSuccess()) {
104
+            return this.renderJson(result);
105
+        } else {
106
+            RequestParams params = (RequestParams)result.getData();
107
+            WorkParaBean workParaBean = new WorkParaBean();
108
+            FlowAction flowAction = RestWorkUtil.getFlowPara(params, workParaBean);
109
+            String data = "";
110
+            if (flowAction != null) {
111
+                if (!Objects.equal("close", flowAction.getOperate())) {
112
+                    RestWorkUtil.setMessageType(workParaBean, flowAction.getMessageType());
113
+                    RestWorkUtil.setFormData(request, workParaBean);
114
+                    data = this.flowSupportService.operate(workParaBean, flowAction);
115
+                } else if (Objects.equal(flowAction.getReOpen(), "false")) {
116
+                    this.flowSupportService.close(flowAction.getWorkId(), flowAction.getTrackId(), workParaBean.getUserId());
117
+                    flowAction.setOperateStatus("success");
118
+                    data = flowAction.toString();
119
+                }
120
+            }
121
+
122
+            return data;
123
+        }
124
+    }
125
+
126
+    @ResponseBody
127
+    @RequestMapping({"/flow/support/history${url.suffix}"})
128
+    public String history() {
129
+        ResponseResult result = super.getParamWithToken();
130
+        if (!result.isSuccess()) {
131
+            return this.renderJson(result);
132
+        } else {
133
+            RequestParams params = (RequestParams)result.getData();
134
+            String workId = (String)params.get("workId");
135
+            List<DBLog> flowLogs = this.flowLogService.findFlowLogById(workId);
136
+            ResponseResult responseResult = ResponseResult.success().data(flowLogs).recordsTotal(flowLogs.size() + "");
137
+            return super.skipFieldsToJson(responseResult, params);
138
+        }
139
+    }
140
+
141
+    protected void setFormFieldAuth(List<FlowForm> forms) {
142
+        if (forms != null && !forms.isEmpty()) {
143
+            Iterator var2 = forms.iterator();
144
+
145
+            while(var2.hasNext()) {
146
+                FlowForm flowForm = (FlowForm)var2.next();
147
+                String formId = flowForm.getFormId();
148
+                if (!"FlowTrack".equals(formId)) {
149
+                    String authId = flowForm.getFormAuthId();
150
+                    if (!"allreadonly".equals(authId) && !"alleditable".equals(authId)) {
151
+                        FieldAuth fieldAuth = this.simpleFormFieldAuthService.getFieldAuth(authId);
152
+                        flowForm.setFormFieldAuth(fieldAuth);
153
+                    }
154
+                }
155
+            }
156
+        }
157
+
158
+    }
159
+
160
+    private List<String> findActiveInstanceIds() {
161
+        List<Map<String, Object>> instanceLst = MemCacheUtil.getInstanceLstFromMemory(HorizonCore.TENANT_CODE.value());
162
+        if (instanceLst == null && instanceLst.isEmpty()) {
163
+            return Lists.newArrayList();
164
+        } else {
165
+            Collection<String> instanceIds = Collections2.transform(instanceLst, new Function<Map<String, Object>, String>() {
166
+                public String apply(Map<String, Object> instance) {
167
+                    return (String)instance.get("workid");
168
+                }
169
+            });
170
+            return Lists.newArrayList(instanceIds.iterator());
171
+        }
172
+    }
173
+}

Loading…
Отказ
Запис