|
@@ -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
|
+}
|