zm
2020-05-18 a18bfacbf56b401f6e0fdae8710fbca4df8cff77
commit | author | age
a18bfa 1 package cn.autoform.web.client.impl;
Z 2
3 import cn.autoform.db.entity.IpAndPortEntity;
4 import cn.autoform.db.exten.Process;
5 import cn.autoform.util.thread.Keys;
6 import cn.autoform.util.thread.ThreadData;
7 import cn.autoform.util.tool.JSONTool;
8 import cn.autoform.web.client.WorkflowClient;
9 import cn.autoform.web.client.util.HttpClientTool;
10 import cn.autoform.web.client.util.IpAndPortTool;
11 import cn.autoform.web.mapper.process.ProcessInstanceMapper;
12 import com.alibaba.fastjson.TypeReference;
13 import com.iemsoft.framework.cloud.core.tools.http.Http;
14 import lombok.extern.slf4j.Slf4j;
15 import org.springframework.beans.factory.annotation.Autowired;
16 import org.springframework.beans.factory.annotation.Value;
17 import org.springframework.stereotype.Service;
18
19 import javax.annotation.Resource;
20 import java.io.IOException;
21 import java.util.Collections;
22 import java.util.HashMap;
23 import java.util.Map;
24 import java.util.concurrent.TimeoutException;
25 @Slf4j
26 @Service
27 public class WorkflowClientImpl implements WorkflowClient {
28     
29     @Value("${autoForm.processSystem}")
30     private String ProcessClient;
31     
32     private static final Map<String,String> ipMap = new HashMap<>();
33     
34     /**
35      * 用于保存流程实例
36      */
37     @Resource
38     private ProcessInstanceMapper processInstanceMapper;
39     
40     
41     
42     static {
43         ipMap.put("definedelete",      "%s/ubp/ubp-api-control/process/def/delete");
44         ipMap.put("definedeploy",      "%s/ubp/ubp-api-control/process/def/deploy");
45         ipMap.put("defineseache",      "%s/ubp/ubp-api-seache/process/def/seache");
46         ipMap.put("definecreate",      "%s/ubp/ubp-api-control/process/def/create");
47         
48         ipMap.put("instback",           "%s/ubp/ubp-api-control/process/inst/back");
49         ipMap.put("agentcreat",         "%s/ubp/ubp-api-control/process/create/agent");
50         ipMap.put("instcreate",         "%s/ubp/ubp-api-control/process/inst/create");
51         ipMap.put("autoFinish",         "%s/ubp/ubp-api-control/process/inst/autofinish");
52         ipMap.put("instdrawback",       "%s/ubp/ubp-api-control/process/inst/drawBack");
53         ipMap.put("instover",           "%s/ubp/ubp-api-control/process/inst/over");
54         ipMap.put("chargecreate",       "%s/ubp/ubp-api-control/process/create/charge");
55         ipMap.put("instfinish",         "%s/ubp/ubp-api-control/process/inst/otherfinish");
56         ipMap.put("instseachehandle",   "%s/ubp/ubp-api-seache/process/inst/seache/handle");
57         ipMap.put("instlog",            "%s/ubp/ubp-api-seache/process/inst/log");
58         ipMap.put("getback",            "%s/ubp/ubp-api-seache/process/get/back");
59         ipMap.put("instagent",             "%s/ubp/ubp-api-seache/process/inst/agent");
60         ipMap.put("instagentdefmsg",     "%s/ubp/ubp-api-seache/process/inst/agent/defMsg");
61         ipMap.put("instseache",         "%s/ubp/ubp-api-seache/process/inst/seache");
62         ipMap.put("querypeople",            "%s/ubp/ubp-api-seache/process/inst/querypeople");
63         ipMap.put("setp",            "%s/ubp/ubp-api-control/process/inst/setp");
64         
65         ipMap.put("appcreate",             "%s/ubp/ubp-api-control/process/app/create");
66         ipMap.put("getSystem",             "%s/ubp/process-system/system/userInfo");
67         
68         ipMap.put("initialization",     "%s/ubp/ubp-api-control/process/rest/initialization");
69         ipMap.put("check",                 "%s/ubp/ubp-api-control/process/rest/check");
70     }
71     
72     @Autowired
73     IpAndPortTool ipAndPortTool;
74     
75     /**
76      * 返回安全登录码
77      */
78     @SuppressWarnings({ "rawtypes", "unchecked" })
79     @Override
80     public Map<String, Object> getSystem(Process process) throws TimeoutException, IOException {
81         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
82         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("getSystem"), ipAndPortEntity.getIp()));
83         System.out.println("IP:"+String.format(ipMap.get("getSystem"), ipAndPortEntity.getIp()));
84         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
85         System.out.println("参数:"+JSONTool.toJson(process.getFlowmap()));
86         Map<String,Object> cookie = new HashMap();
87         cookie.put("token",ThreadData.get(Keys.TOKEN));
88         cookie.put("openId",ThreadData.get(Keys.OPEN_ID));
89         cookie.put("companyId", ThreadData.get(Keys.COMPANY_ID));
90         cookie.put("appId", 1);
91         cookie.put("tenantId",ThreadData.get(Keys.TENANT_ID));
92         hc.setCookie(cookie);
93         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
94         return hcData;
95     }
96     
97     @SuppressWarnings({ "rawtypes", "unchecked" })
98     @Override
99     public Map<String, Object> defineDelete(Process process) throws TimeoutException {
100         // TODO 删除流程定义
101         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
102         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("definedelete"), ipAndPortEntity.getIp()));
103         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
104         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
105         return hcData;
106     }
107
108     @SuppressWarnings({ "rawtypes", "unchecked" })
109     @Override
110     public Map<String, Object> definePeploy(Process process) throws TimeoutException {
111         // TODO 部署流程定义
112         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
113         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("definedeploy"), ipAndPortEntity.getIp()));
114         System.out.println("最后的参数:"+JSONTool.toJson(process.getFlowmap()));
115         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
116         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
117         return hcData;
118     }
119
120     @SuppressWarnings({ "rawtypes", "unchecked" })
121     @Override
122     public Map<String, Object> defineSeache(Process process) throws TimeoutException {
123         // TODO 流程定义分页查询
124         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
125         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("defineseache"), ipAndPortEntity.getIp()));
126         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
127         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
128         return hcData;
129     }
130     
131     @SuppressWarnings({ "rawtypes", "unchecked" })
132     @Override
133     public Map<String, Object> defineCreate(Process process) throws TimeoutException {
134         // TODO 创建流程定义
135         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
136         System.out.println("IP:"+JSONTool.toJson(ipAndPortEntity));
137         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("definecreate"), ipAndPortEntity.getIp()));
138         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
139         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
140         return hcData;
141     }
142     
143     @SuppressWarnings({ "rawtypes", "unchecked" })
144     @Override
145     public Map<String, String> instBack(Process process) throws TimeoutException {
146         // TODO 退回流程实例
147         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
148         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("instback"), ipAndPortEntity.getIp()));
149         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
150         Map<String, String> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, String>>(){}));
151         return hcData;
152     }
153     
154     @SuppressWarnings({ "rawtypes", "unchecked" })
155     @Override
156     public Map<String, Object> agentCreat(Process process) throws TimeoutException {
157         // TODO 设置代理
158         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
159         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("agentcreat"), ipAndPortEntity.getIp()));
160         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
161         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
162         return hcData;
163     }
164     
165     @SuppressWarnings({ "rawtypes", "unchecked" })
166     @Override
167     public Map<String, Object> instCreat(Process process) throws TimeoutException {
168         // TODO 创建流程实例
169         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
170         return (Map<String, Object>)
171                 Http.post(String.format(ipMap.get("instcreate"), ipAndPortEntity.getIp()), Map.class)
172                         .addUrlParam(process.getFlowmap())
173                         .execute(new TypeReference<Map<String, Object>>(){}.getType())
174                         .orElse(Collections.emptyMap());
175     }
176
177     @Override
178     public Map<String, Object> autoFinish(Process process) {
179         // TODO 创建流程实例并执行第一个活动
180         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
181         return (Map<String, Object>)
182                 Http.post(String.format(ipMap.get("autoFinish"), ipAndPortEntity.getIp()), Map.class)
183                         .addUrlParam(process.getFlowmap())
184                         .execute(new TypeReference<Map<String, Object>>(){}.getType())
185                         .orElse(Collections.emptyMap());
186     }
187
188     @SuppressWarnings({ "rawtypes", "unchecked" })
189     @Override
190     public Map<String, Object> instDrawBack(Process process) throws TimeoutException {
191         // TODO 撤销流程实例
192         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
193         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("instdrawback"), ipAndPortEntity.getIp()));
194         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
195         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
196         return hcData;
197     }
198     
199     @SuppressWarnings({ "rawtypes", "unchecked" })
200     @Override
201     public Map<String, Object> instOver(Process process) throws TimeoutException {
202         // TODO 结束流程实例
203         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
204         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("instover"), ipAndPortEntity.getIp()));
205         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
206         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
207         return hcData;
208     }
209     
210     @SuppressWarnings({ "rawtypes", "unchecked" })
211     @Override
212     public Map<String, Object> chargeCreate(Process process) throws TimeoutException {
213         // TODO 设置代办
214         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
215         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("chargecreate"), ipAndPortEntity.getIp()));
216         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
217         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
218         return hcData;
219     }
220     
221     @SuppressWarnings({ "rawtypes", "unchecked" })
222     @Override
223     public Map<String, Object> instFinish(Process process) throws TimeoutException {
224         // TODO 执行流程实例
225         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
226         return (Map<String, Object>)
227                 Http.post(String.format(ipMap.get("instfinish"), ipAndPortEntity.getIp()), Map.class)
228                         .addUrlParam(process.getFlowmap())
229                         .execute(new TypeReference<Map<String, Object>>(){}.getType())
230                         .orElse(Collections.emptyMap());
231     }
232     
233     @SuppressWarnings({ "rawtypes", "unchecked" })
234     @Override
235     public Map<String, Object> instSeacheHandle(Process process) throws TimeoutException {
236         // TODO 查询流程待办
237         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
238         return (Map<String, Object>)
239             Http.post(String.format(ipMap.get("instseachehandle"), ipAndPortEntity.getIp()), Map.class)
240                 .addUrlParam(process.getFlowmap())
241                 .execute(new TypeReference<Map<String, Object>>(){}.getType())
242                 .orElse(Collections.emptyMap());
243     }
244     
245     @SuppressWarnings({ "rawtypes", "unchecked" })
246     @Override
247     public Map<String, Object> instLog(Process process) throws TimeoutException {
248         // TODO 流程实例log(参数为空即查询所有)
249         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
250         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("instlog"), ipAndPortEntity.getIp()));
251         System.out.println("IP"+String.format(ipMap.get("instlog"), ipAndPortEntity.getIp()));
252         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
253         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
254         return hcData;
255     }
256     
257     @SuppressWarnings({ "rawtypes", "unchecked" })
258     @Override
259     public Map<String, Object> getBack(Process process) throws TimeoutException {
260         // TODO 获取所有可退回项目
261         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
262         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("getback"), ipAndPortEntity.getIp()));
263         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
264         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
265         return hcData;
266     }
267     
268     @SuppressWarnings({ "rawtypes", "unchecked" })
269     @Override
270     public Map<String, Object> instAgent(Process process) throws TimeoutException {
271         // TODO 查询代理(参数为空即查询所有信息)
272         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
273         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("instagent"), ipAndPortEntity.getIp()));
274         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
275         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
276         return hcData;
277     }
278     
279     @SuppressWarnings({ "rawtypes", "unchecked" })
280     @Override
281     public Map<String, Object> instAgentDefMsg(Process process) throws TimeoutException {
282         // TODO 查询代理去除流程定义信息
283         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
284         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("instagentdefmsg"), ipAndPortEntity.getIp()));
285         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
286         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
287         return hcData;
288     }
289     
290     @SuppressWarnings({ "rawtypes", "unchecked" })
291     @Override
292     public Map<String, Object> instSeache(Process process) throws TimeoutException {
293         // TODO 查询流程实例(参数都为空,即查询所有)
294         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
295         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("instseache"), ipAndPortEntity.getIp()));
296         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
297         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
298         return hcData;
299     }
300     
301     @SuppressWarnings({ "rawtypes", "unchecked" })
302     @Override
303     public Map<String, Object> appCreate(Process process) throws TimeoutException {
304         // TODO 租户注册系统
305         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
306         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("appcreate"), ipAndPortEntity.getIp()));
307         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
308         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
309         return hcData;
310     }
311     @SuppressWarnings({ "rawtypes", "unchecked" })
312     @Override
313     public Map<String, Object> initialization(Process process) throws TimeoutException {
314         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
315         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("initialization"), ipAndPortEntity.getIp()));
316         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
317         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
318         return hcData;
319
320     }
321     
322     @SuppressWarnings({ "rawtypes", "unchecked" })
323     @Override
324     public Map<String, Object> check(Process process) throws TimeoutException {
325         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
326         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("check"), ipAndPortEntity.getIp()));
327         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
328         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
329         return hcData;
330
331     }
332
333
334     @SuppressWarnings({ "rawtypes", "unchecked" })
335     @Override
336     public Map<String, Object> querypeople(Process process) throws TimeoutException {
337         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
338         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("querypeople"), ipAndPortEntity.getIp()));
339         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
340         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
341         return hcData;
342
343     }
344
345     @SuppressWarnings({ "rawtypes", "unchecked" })
346     @Override
347     public Map<String, Object> setp(Process process) throws TimeoutException {
348         IpAndPortEntity ipAndPortEntity = ipAndPortTool.queryIpAndPortByServiceName(ProcessClient);
349         HttpClientTool<Map> hc = new HttpClientTool(String.format(ipMap.get("setp"), ipAndPortEntity.getIp()));
350         hc.setBodyInfos(HttpClientTool.getUrlEntity(process.getFlowmap()));
351         Map<String, Object> hcData = hc.sendPost(j->JSONTool.toObj(j, new TypeReference<Map<String, Object>>(){}));
352         return hcData;
353
354     }
355     
356     
357 }