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