ny
昨天 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
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
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
package jnpf.flowable.util;
 
import cn.hutool.core.util.ObjectUtil;
import com.google.common.collect.ImmutableList;
import jnpf.base.UserInfo;
import jnpf.base.model.systemconfig.SysConfigModel;
import jnpf.exception.WorkFlowException;
import jnpf.flowable.entity.*;
import jnpf.flowable.enums.FieldEnum;
import jnpf.flowable.enums.NodeEnum;
import jnpf.flowable.enums.OpTypeEnum;
import jnpf.flowable.model.message.ContModel;
import jnpf.flowable.model.message.DelegateModel;
import jnpf.flowable.model.message.FlowEventModel;
import jnpf.flowable.model.message.FlowMsgModel;
import jnpf.flowable.model.task.FlowModel;
import jnpf.flowable.model.templatenode.nodejson.MsgConfig;
import jnpf.flowable.model.templatenode.nodejson.NodeModel;
import jnpf.flowable.model.templatenode.nodejson.SendConfigJson;
import jnpf.flowable.model.templatenode.nodejson.TemplateJsonModel;
import jnpf.flowable.model.util.FlowConstant;
import jnpf.flowable.model.util.FlowNature;
import jnpf.message.model.SentMessageForm;
import jnpf.permission.entity.UserEntity;
import jnpf.util.JsonUtil;
import jnpf.util.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
 
import java.util.*;
import java.util.stream.Collectors;
 
/**
 * @author :JNPF开发平台组
 * @version: V3.1.0
 * @copyright 引迈信息技术有限公司
 * @date :2022/3/30 11:45
 */
@Slf4j
@Component
public class MsgUtil {
 
    @Autowired
    private ServiceUtil serviceUtil;
    @Autowired
    private FlowUtil flowUtil;
 
    /**
     * 发送消息
     *
     * @param flowMsgModel
     */
    public void message(FlowMsgModel flowMsgModel) throws WorkFlowException {
        List<SentMessageForm> messageListAll = new ArrayList<>();
        TaskEntity task = flowMsgModel.getTaskEntity();
        String taskId = task.getId();
        UserEntity user = StringUtil.isNotEmpty(task.getCreatorUserId()) ? serviceUtil.getUserInfo(task.getCreatorUserId()) : null;
        flowMsgModel.setCreateUser(user);
        UserEntity delegate = StringUtil.isNotEmpty(task.getDelegateUserId()) ? serviceUtil.getUserInfo(task.getDelegateUserId()) : null;
        flowMsgModel.setDelegate(delegate);
        Map<String, Map<String, Object>> formData = flowMsgModel.getFormData();
        String nodeCode = flowMsgModel.getNodeCode();
        List<TemplateNodeEntity> nodeList = flowMsgModel.getNodeList();
        List<OperatorEntity> operatorList = flowMsgModel.getOperatorList();
        List<CirculateEntity> circulateList = flowMsgModel.getCirculateList();
        TemplateNodeEntity startNodeEntity = nodeList.stream().filter(t -> NodeEnum.start.getType().equals(t.getNodeType())).findFirst().orElse(null);
        String nodeJson = startNodeEntity != null ? startNodeEntity.getNodeJson() : "{}";
        NodeModel startNode = JsonUtil.getJsonToBean(nodeJson, NodeModel.class);
        //同意
        if (flowMsgModel.getApprove()) {
            MsgConfig msgConfig = startNode.getApproveMsgConfig();
            TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(nodeCode)).findFirst().orElse(null);
            NodeModel taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodeJson(), NodeModel.class);
            MsgConfig taskMsgConfig = taskChildNode.getApproveMsgConfig();
            if (taskMsgConfig.getOn() == 2) {
                taskMsgConfig = msgConfig;
            }
            if (taskMsgConfig.getOn() == 3) {
                taskMsgConfig.setMsgId("PZXTLC002");
            }
            List<SentMessageForm> messageList = new ArrayList<>();
            flowMsgModel.setOpType(OpTypeEnum.LaunchDetail.getType());
            Map<String, Object> data = flowUtil.infoData(startNode.getFormId(), taskId, formData);
            flowMsgModel.setData(data);
            flowMsgModel.setMsgConfig(taskMsgConfig);
            List<OperatorEntity> taskOperatorList = new ArrayList() {{
                OperatorEntity operatorEntity = new OperatorEntity();
                operatorEntity.setTaskId(task.getId());
                operatorEntity.setHandleId(task.getCreatorUserId());
                add(operatorEntity);
            }};
            FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
            setMessageList(messageList, msgModel);
            messageListAll.addAll(messageList);
        }
        // 拒绝
        if (flowMsgModel.getReject()) {
            MsgConfig msgConfig = startNode.getRejectMsgConfig();
            TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(nodeCode)).findFirst().orElse(null);
            NodeModel taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodeJson(), NodeModel.class);
            MsgConfig taskMsgConfig = taskChildNode.getRejectMsgConfig();
            if (taskMsgConfig.getOn() == 2) {
                taskMsgConfig = msgConfig;
            }
            if (taskMsgConfig.getOn() == 3) {
                taskMsgConfig.setMsgId("PZXTLC018");
            }
            List<SentMessageForm> messageList = new ArrayList<>();
            flowMsgModel.setOpType(OpTypeEnum.LaunchDetail.getType());
            Map<String, Object> data = flowUtil.infoData(startNode.getFormId(), taskId, formData);
            flowMsgModel.setData(data);
            flowMsgModel.setMsgConfig(taskMsgConfig);
            List<OperatorEntity> taskOperatorList = new ArrayList() {{
                OperatorEntity operatorEntity = new OperatorEntity();
                operatorEntity.setTaskId(task.getId());
                operatorEntity.setHandleId(task.getCreatorUserId());
                add(operatorEntity);
            }};
            FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
            setMessageList(messageList, msgModel);
            messageListAll.addAll(messageList);
        }
        //等待
        if (flowMsgModel.getWait()) {
            MsgConfig taskMsgConfig = startNode.getWaitMsgConfig();
            if (taskMsgConfig.getOn() == 3) {
                if (flowMsgModel.getTransfer()) {
                    taskMsgConfig.setMsgId("PZXTLC006");
                } else if (flowMsgModel.getAssign()) {
                    taskMsgConfig.setMsgId("PZXTLC005");
                } else if (flowMsgModel.getPress()) {
                    taskMsgConfig.setMsgId("PZXTLC004");
                } else {
                    taskMsgConfig.setMsgId("PZXTLC001");
                }
            }
            Map<String, List<OperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(OperatorEntity::getNodeCode));
            for (String key : operatorMap.keySet()) {
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = operatorMap.get(key);
                flowMsgModel.setOpType(OpTypeEnum.Sign.getType());
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(key)).findFirst().orElse(null);
                // 获取表单数据
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(taskMsgConfig);
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
                for (OperatorEntity operator : taskOperatorList) {
                    List<SentMessageForm> delegationMsg = delegationMsg(operator, msgModel);
                    messageListAll.addAll(delegationMsg);
                }
            }
        }
        //结束
        if (flowMsgModel.getEnd()) {
            MsgConfig taskMsgConfig = startNode.getEndMsgConfig();
            if (taskMsgConfig.getOn() == 3) {
                taskMsgConfig.setMsgId("PZXTLC010");
            }
            List<SentMessageForm> messageList = new ArrayList<>();
            flowMsgModel.setOpType(OpTypeEnum.LaunchDetail.getType());
            Map<String, Object> data = flowUtil.infoData(startNode.getFormId(), taskId, formData);
            flowMsgModel.setData(data);
            flowMsgModel.setMsgConfig(taskMsgConfig);
            List<OperatorEntity> taskOperatorList = new ArrayList() {{
                OperatorEntity operatorEntity = new OperatorEntity();
                operatorEntity.setTaskId(task.getId());
                operatorEntity.setHandleId(task.getCreatorUserId());
                add(operatorEntity);
            }};
            FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
            setMessageList(messageList, msgModel);
            messageListAll.addAll(messageList);
        }
        //退回
        if (flowMsgModel.getBack()) {
            MsgConfig msgConfig = startNode.getBackMsgConfig();
            Map<String, List<OperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(OperatorEntity::getNodeCode));
            for (String key : operatorMap.keySet()) {
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(nodeCode)).findFirst().orElse(null);
                NodeModel taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodeJson(), NodeModel.class);
                MsgConfig taskMsgConfig = taskChildNode.getBackMsgConfig();
                if (taskMsgConfig.getOn() == 2) {
                    taskMsgConfig = msgConfig;
                }
                if (taskMsgConfig.getOn() == 3) {
                    taskMsgConfig.setMsgId("PZXTLC003");
                }
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = operatorMap.get(key);
                if (ObjectUtil.equals(flowMsgModel.getWait(), true)) {
                    flowMsgModel.setOpType(OpTypeEnum.Sign.getType());
                }
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(taskMsgConfig);
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
                for (OperatorEntity operator : taskOperatorList) {
                    List<SentMessageForm> delegationMsg = delegationMsg(operator, msgModel);
                    messageListAll.addAll(delegationMsg);
                }
            }
        }
        //抄送
        if (flowMsgModel.getCopy()) {
            MsgConfig msgConfig = startNode.getCopyMsgConfig();
            Map<String, List<CirculateEntity>> circulateMap = circulateList.stream().collect(Collectors.groupingBy(CirculateEntity::getNodeCode));
            for (String key : circulateMap.keySet()) {
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(key)).findFirst().orElse(null);
                NodeModel taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodeJson(), NodeModel.class);
                MsgConfig taskMsgConfig = taskChildNode.getCopyMsgConfig();
                if (taskMsgConfig.getOn() == 2) {
                    taskMsgConfig = msgConfig;
                }
                if (taskMsgConfig.getOn() == 3) {
                    taskMsgConfig.setMsgId("PZXTLC007");
                }
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = new ArrayList<>();
                for (CirculateEntity circulateEntity : circulateMap.get(key)) {
                    OperatorEntity operatorEntity = JsonUtil.getJsonToBean(circulateEntity, OperatorEntity.class);
                    operatorEntity.setHandleId(circulateEntity.getUserId());
                    taskOperatorList.add(operatorEntity);
                }
                flowMsgModel.setOpType(OpTypeEnum.Circulate.getType());
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(taskMsgConfig);
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
            }
        }
        //子流程
        if (flowMsgModel.getLaunch()) {
            MsgConfig msgConfig = startNode.getLaunchMsgConfig();
            Map<String, List<OperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(OperatorEntity::getNodeCode));
            for (String key : operatorMap.keySet()) {
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(key)).findFirst().orElse(null);
                NodeModel taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodeJson(), NodeModel.class);
                MsgConfig taskMsgConfig = taskChildNode.getLaunchMsgConfig();
                if (taskMsgConfig.getOn() == 2) {
                    taskMsgConfig = msgConfig;
                }
                if (taskMsgConfig.getOn() == 3) {
                    taskMsgConfig.setMsgId("PZXTLC011");
                }
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = operatorMap.get(key);
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(taskMsgConfig);
                flowMsgModel.setOpType(taskChildNode.getAutoSubmit().equals(1) ? OpTypeEnum.LaunchDetail.getType() : OpTypeEnum.LaunchCreate.getType());
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
            }
        }
        //超时
        if (flowMsgModel.getOvertime()) {
            MsgConfig msgConfig = startNode.getOverTimeMsgConfig();
            Map<String, List<OperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(OperatorEntity::getNodeCode));
            for (String key : operatorMap.keySet()) {
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(key)).findFirst().orElse(null);
                NodeModel taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodeJson(), NodeModel.class);
                MsgConfig taskMsgConfig = taskChildNode.getOverTimeMsgConfig();
                if (taskMsgConfig.getOn() == 2) {
                    taskMsgConfig = msgConfig;
                }
                if (taskMsgConfig.getOn() == 3) {
                    taskMsgConfig.setMsgId("PZXTLC009");
                }
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = operatorMap.get(key);
                flowMsgModel.setOpType(OpTypeEnum.Sign.getType());
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(taskMsgConfig);
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
                for (OperatorEntity operator : taskOperatorList) {
                    List<SentMessageForm> delegationMsg = delegationMsg(operator, flowMsgModel);
                    messageListAll.addAll(delegationMsg);
                }
            }
        }
        //提醒
        if (flowMsgModel.getNotice()) {
            MsgConfig msgConfig = startNode.getNoticeMsgConfig();
            Map<String, List<OperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(OperatorEntity::getNodeCode));
            for (String key : operatorMap.keySet()) {
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(key)).findFirst().orElse(null);
                NodeModel taskChildNode = JsonUtil.getJsonToBean(taskNode.getNodeJson(), NodeModel.class);
                MsgConfig taskMsgConfig = taskChildNode.getNoticeMsgConfig();
                if (taskMsgConfig.getOn() == 2) {
                    taskMsgConfig = msgConfig;
                }
                if (taskMsgConfig.getOn() == 3) {
                    taskMsgConfig.setMsgId("PZXTLC008");
                }
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = operatorMap.get(key);
                flowMsgModel.setOpType(OpTypeEnum.Sign.getType());
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(taskMsgConfig);
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
                for (OperatorEntity operator : taskOperatorList) {
                    List<SentMessageForm> delegationMsg = delegationMsg(operator, msgModel);
                    messageListAll.addAll(delegationMsg);
                }
            }
        }
        //评论
        if (flowMsgModel.getComment()) {
            MsgConfig msgConfig = startNode.getCommentMsgConfig();
            if (msgConfig.getOn() == 3) {
                msgConfig.setMsgId("PZXTLC017");
            }
            Map<String, List<OperatorEntity>> operatorMap = operatorList.stream().collect(Collectors.groupingBy(OperatorEntity::getNodeCode));
            for (String key : operatorMap.keySet()) {
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = operatorMap.get(key);
                flowMsgModel.setOpType(OpTypeEnum.Circulate.getType());
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(key)).findFirst().orElse(null);
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(msgConfig);
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
            }
            //抄送
            Map<String, List<CirculateEntity>> circulateMap = circulateList.stream().collect(Collectors.groupingBy(CirculateEntity::getNodeCode));
            for (String key : circulateMap.keySet()) {
                TemplateNodeEntity taskNode = nodeList.stream().filter(t -> t.getNodeCode().equals(key)).findFirst().orElse(null);
                List<SentMessageForm> messageList = new ArrayList<>();
                List<OperatorEntity> taskOperatorList = new ArrayList<>();
                for (CirculateEntity circulateEntity : circulateMap.get(key)) {
                    OperatorEntity operatorEntity = JsonUtil.getJsonToBean(circulateEntity, OperatorEntity.class);
                    operatorEntity.setHandleId(circulateEntity.getUserId());
                    taskOperatorList.add(operatorEntity);
                }
                flowMsgModel.setOpType(OpTypeEnum.Circulate.getType());
                Map<String, Object> data = flowUtil.infoData(taskNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                flowMsgModel.setMsgConfig(msgConfig);
                FlowMsgModel msgModel = messageModel(taskOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
            }
            if (flowMsgModel.getStartHandId()) {
                List<SentMessageForm> messageList = new ArrayList<>();
                flowMsgModel.setOpType(OpTypeEnum.LaunchDetail.getType());
                Map<String, Object> data = flowUtil.infoData(startNode.getFormId(), taskId, formData);
                flowMsgModel.setData(data);
                OperatorEntity operatorEntity = new OperatorEntity();
                operatorEntity.setTaskId(task.getId());
                operatorEntity.setHandleId(task.getCreatorUserId());
                List<OperatorEntity> meOperatorList = new ArrayList<>();
                meOperatorList.add(operatorEntity);
                FlowMsgModel msgModel = messageModel(meOperatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
                messageListAll.addAll(messageList);
            }
        }
        for (SentMessageForm sentMessageForm : messageListAll) {
            sentMessageForm.setFlowName(task.getFullName());
            sentMessageForm.setUserName(user != null ? user.getRealName() : "");
        }
        serviceUtil.sendMessage(messageListAll);
    }
 
    private void setMessageList(List<SentMessageForm> messageList, FlowMsgModel flowMsgModel) {
        HashMap<String, Object> data = new HashMap<>(flowMsgModel.getData());
        MsgConfig msgConfig = flowMsgModel.getMsgConfig() != null ? flowMsgModel.getMsgConfig() : new MsgConfig();
        List<String> userList = flowMsgModel.getUserList();
        UserInfo userInfo = flowMsgModel.getFlowModel().getUserInfo();
        TaskEntity task = flowMsgModel.getTaskEntity();
        UserEntity createUser = flowMsgModel.getCreateUser();
        UserEntity delegate = flowMsgModel.getDelegate();
        if (!userList.isEmpty()) {
            String templateId = msgConfig.getOn() == 0 ? "0" : msgConfig.getMsgId();
            boolean sysMessage = msgConfig.getOn() != 0;
            //解析发送配置json,获取消息模板参数
            List<TemplateJsonModel> templateJson = new ArrayList<>();
            for (SendConfigJson configJson : msgConfig.getTemplateJson()) {
                List<TemplateJsonModel> paramJson = configJson.getParamJson();
                templateJson.addAll(paramJson);
                List<String> list = ImmutableList.of(FlowConstant.MANDATOR, FlowConstant.MANDATARY, FlowConstant.CREATORUSERNAME, FlowConstant.SENDTIME);
                for (String field : list) {
                    TemplateJsonModel jsonModel = new TemplateJsonModel();
                    jsonModel.setMsgTemplateId(configJson.getId());
                    jsonModel.setRelationField(field);
                    jsonModel.setField(field);
                    jsonModel.setSourceType(FieldEnum.System.getCode());
                    templateJson.add(jsonModel);
                }
            }
            SentMessageForm sentMessageForm = new SentMessageForm();
            sentMessageForm.setSysMessage(sysMessage);
            sentMessageForm.setTemplateId(templateId);
            sentMessageForm.setToUserIds(userList);
            RecordEntity record = new RecordEntity();
            record.setNodeCode(flowMsgModel.getNodeCode());
            FlowModel parameterModel = new FlowModel();
            parameterModel.setFormData(data);
            parameterModel.setRecordEntity(record);
            parameterModel.setTaskEntity(task);
            Map<String, String> parameterMap = flowUtil.parameterMap(parameterModel, templateJson, createUser, delegate);
            data.putAll(parameterMap);
            sentMessageForm.setUserInfo(userInfo);
            sentMessageForm.setParameterMap(data);
            sentMessageForm.setContentMsg(flowMsgModel.getContMsg());
            sentMessageForm.setTitle(task.getFullName());
            messageList.add(sentMessageForm);
        }
    }
 
    private FlowMsgModel messageModel(List<OperatorEntity> taskOperatorList, FlowMsgModel flowMsgModel) {
        FlowMsgModel msgModel = JsonUtil.getJsonToBean(flowMsgModel, FlowMsgModel.class);
        List<String> userList = new ArrayList<>();
        TaskEntity task = flowMsgModel.getTaskEntity();
        Map<String, String> contMsg = new HashMap<>();
        for (OperatorEntity taskOperator : taskOperatorList) {
            ContModel contModel = new ContModel();
            contModel.setFlowId(task.getFlowId());
            contModel.setOperatorId(taskOperator.getId());
            contModel.setTaskId(task.getId());
            contModel.setOpType(flowMsgModel.getOpType());
            if (StringUtil.equals(flowMsgModel.getOpType(), OpTypeEnum.Sign.getType())) {
                if (null == taskOperator.getSignTime() && null == taskOperator.getStartHandleTime() && null == taskOperator.getHandleStatus()) {
                    contModel.setOpType(OpTypeEnum.Sign.getType());
                } else if (null != taskOperator.getSignTime() && null == taskOperator.getStartHandleTime() && null == taskOperator.getHandleStatus()) {
                    contModel.setOpType(OpTypeEnum.Todo.getType());
                } else if (null != taskOperator.getSignTime() && null != taskOperator.getStartHandleTime() && null == taskOperator.getHandleStatus()) {
                    contModel.setOpType(OpTypeEnum.Doing.getType());
                }
            }
            contMsg.put(taskOperator.getHandleId(), JsonUtil.getObjectToString(contModel));
            userList.add(taskOperator.getHandleId());
        }
        msgModel.setUserList(userList);
        msgModel.setContMsg(contMsg);
        return msgModel;
    }
 
    private List<SentMessageForm> delegationMsg(OperatorEntity operator, FlowMsgModel flowMsgModel) {
        List<SentMessageForm> messageList = new ArrayList<>();
        TaskEntity task = flowMsgModel.getTaskEntity();
        if (task != null) {
            // 获取委托人
            List<String> userList = flowUtil.getToUser(operator.getHandleId(), task.getFlowId());
            List<OperatorEntity> operatorList = new ArrayList<>();
            for (String user : userList) {
                OperatorEntity delegate = JsonUtil.getJsonToBean(operator, OperatorEntity.class);
                delegate.setHandleId(user);
                operatorList.add(delegate);
                FlowMsgModel msgModel = messageModel(operatorList, flowMsgModel);
                setMessageList(messageList, msgModel);
            }
        }
        return messageList;
    }
 
 
    //--------------------------------------委托消息------------------------------------------------------
    public void delegateMsg(DelegateModel flowDelegate) {
        SysConfigModel sysConfig = serviceUtil.getSysConfig();
        // 委托/代理确认通知
        Integer ack = flowDelegate.getDelegate() ? sysConfig.getDelegateAck() : sysConfig.getProxyAck();
        flowDelegate.setAck(ack);
        List<String> toUserIds = flowDelegate.getToUserIds();
        if (!toUserIds.isEmpty()) {
            UserInfo userInfo = flowDelegate.getUserInfo();
            TaskEntity flowTask = flowDelegate.getFlowTask();
            Map<String, String> contentMsg = new HashMap<>();
            Boolean delegate = flowDelegate.getDelegate();
            boolean approve = flowDelegate.getApprove();
            if (approve) {
                SentMessageForm flowMsgModel = new SentMessageForm();
                flowMsgModel.setToUserIds(toUserIds);
                flowMsgModel.setUserInfo(flowDelegate.getUserInfo());
                Map<String, Object> parameterMap = new HashMap<>();
                parameterMap.put(FlowConstant.MANDATOR, userInfo.getUserName());
                UserEntity mandatary = StringUtil.isNotEmpty(flowTask.getDelegateUserId()) ? serviceUtil.getUserInfo(flowTask.getDelegateUserId()) : null;
                parameterMap.put(FlowConstant.MANDATARY, mandatary != null ? mandatary.getRealName() : "");
                parameterMap.put(FlowConstant.TITLE, delegate ? "委托" : "代理");
                flowMsgModel.setParameterMap(parameterMap);
                //1.委托设置 2.委托给我
                Integer type = flowDelegate.getType();
                String templateId = FlowNature.EndMsg.equals(type) ? "PZXTLG021" : ObjectUtil.equals(ack, 1) ? "PZXTLG020" : "PZXTLG019";
                flowMsgModel.setTemplateId(templateId);
 
                Integer delegateType = FlowNature.EndMsg.equals(type) ? 0 : delegate ? 2 : 4;
                contentMsg.put("type", delegateType + "");
 
                flowMsgModel.setContentMsg(contentMsg);
                flowMsgModel.setFlowType(2);
                flowMsgModel.setType(2);
                List<SentMessageForm> messageListAll = new ArrayList<>();
                messageListAll.add(flowMsgModel);
                serviceUtil.sendDelegateMsg(messageListAll);
            }
        }
    }
 
 
 
    // 接口调用的参数需转为字符串
    public Map<String, String> intefaceParameterMap(Map<String, Object> data, List<TemplateJsonModel> templateJsonModelList, RecordEntity record, TaskEntity task, UserEntity createUser, UserEntity delegate) {
        Map<String, String> parameterMap = new HashMap<>();
        for (TemplateJsonModel templateJsonModel : templateJsonModelList) {
            String fieldId = templateJsonModel.getField();
            String msgTemplateId = templateJsonModel.getMsgTemplateId();
            String relationField = templateJsonModel.getRelationField();
            boolean isList = data.get(relationField) instanceof List;
            String dataValue = data.get(relationField) != null ? isList ? JsonUtil.getObjectToString(data.get(relationField)) : String.valueOf(data.get(relationField)) : null;
            String dataFieldValue = relationField;
            String dataJson = Objects.equals(FieldEnum.Field.getCode(), templateJsonModel.getSourceType()) ? dataValue : dataFieldValue;
            FlowEventModel eventModel = FlowEventModel.builder().data(data).dataJson(dataJson).record(record).templateJson(templateJsonModel).taskEntity(task).createUser(createUser).delegate(delegate).build();
            dataJson = flowUtil.data(eventModel);
            parameterMap.put(StringUtil.isNotEmpty(msgTemplateId) ? msgTemplateId : "" + fieldId, dataJson);
        }
        return parameterMap;
    }
}