提交 | 用户 | 时间
|
722af2
|
1 |
package com.dl.workflow.service.impl; |
X |
2 |
|
|
3 |
import cn.hutool.core.collection.CollUtil; |
|
4 |
import cn.hutool.core.convert.Convert; |
|
5 |
import cn.hutool.core.util.ObjectUtil; |
|
6 |
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
|
7 |
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; |
|
8 |
import com.baomidou.mybatisplus.core.toolkit.Wrappers; |
|
9 |
import com.dl.common.exception.ServiceException; |
|
10 |
import com.dl.common.utils.StringUtils; |
|
11 |
import com.dl.flowable.utils.ModelUtils; |
|
12 |
import com.dl.workflow.domain.WfDeployForm; |
|
13 |
import com.dl.workflow.domain.WfForm; |
|
14 |
import com.dl.workflow.domain.vo.WfFormVo; |
|
15 |
import com.dl.workflow.mapper.WfDeployFormMapper; |
|
16 |
import com.dl.workflow.mapper.WfFormMapper; |
|
17 |
import com.dl.workflow.service.IWfDeployFormService; |
|
18 |
import lombok.RequiredArgsConstructor; |
|
19 |
import org.flowable.bpmn.model.BpmnModel; |
|
20 |
import org.flowable.bpmn.model.FlowNode; |
|
21 |
import org.flowable.bpmn.model.StartEvent; |
|
22 |
import org.flowable.bpmn.model.UserTask; |
|
23 |
import org.springframework.stereotype.Service; |
|
24 |
import org.springframework.transaction.annotation.Transactional; |
|
25 |
|
|
26 |
import java.util.ArrayList; |
|
27 |
import java.util.Collection; |
|
28 |
import java.util.List; |
|
29 |
|
|
30 |
/** |
|
31 |
* 流程实例关联表单Service业务层处理 |
|
32 |
* |
|
33 |
* @author KonBAI |
|
34 |
* @createTime 2022/3/7 22:07 |
|
35 |
*/ |
|
36 |
@RequiredArgsConstructor |
|
37 |
@Service |
|
38 |
public class WfDeployFormServiceImpl implements IWfDeployFormService { |
|
39 |
|
|
40 |
private final WfDeployFormMapper baseMapper; |
|
41 |
|
|
42 |
private final WfFormMapper formMapper; |
|
43 |
|
|
44 |
/** |
|
45 |
* 新增流程实例关联表单 |
|
46 |
* |
|
47 |
* @param deployForm 流程实例关联表单 |
|
48 |
* @return 结果 |
|
49 |
*/ |
|
50 |
@Override |
|
51 |
@Transactional(rollbackFor = Exception.class) |
|
52 |
public int insertWfDeployForm(WfDeployForm deployForm) { |
|
53 |
// 删除部署流程和表单的关联关系 |
|
54 |
baseMapper.delete(new LambdaQueryWrapper<WfDeployForm>().eq(WfDeployForm::getDeployId, deployForm.getDeployId())); |
|
55 |
// 新增部署流程和表单关系 |
|
56 |
return baseMapper.insert(deployForm); |
|
57 |
} |
|
58 |
|
|
59 |
@Override |
|
60 |
@Transactional(rollbackFor = Exception.class) |
|
61 |
public boolean saveInternalDeployForm(String deployId, BpmnModel bpmnModel) { |
|
62 |
List<WfDeployForm> deployFormList = new ArrayList<>(); |
|
63 |
// 获取开始节点 |
|
64 |
StartEvent startEvent = ModelUtils.getStartEvent(bpmnModel); |
|
65 |
if (ObjectUtil.isNull(startEvent)) { |
|
66 |
throw new RuntimeException("开始节点不存在,请检查流程设计是否有误!"); |
|
67 |
} |
|
68 |
// 保存开始节点表单信息 |
|
69 |
WfDeployForm startDeployForm = buildDeployForm(deployId, startEvent); |
|
70 |
if (ObjectUtil.isNotNull(startDeployForm)) { |
|
71 |
deployFormList.add(startDeployForm); |
|
72 |
} |
|
73 |
// 保存用户节点表单信息 |
|
74 |
Collection<UserTask> userTasks = ModelUtils.getAllUserTaskEvent(bpmnModel); |
|
75 |
if (CollUtil.isNotEmpty(userTasks)) { |
|
76 |
for (UserTask userTask : userTasks) { |
|
77 |
WfDeployForm userTaskDeployForm = buildDeployForm(deployId, userTask); |
|
78 |
if (ObjectUtil.isNotNull(userTaskDeployForm)) { |
|
79 |
deployFormList.add(userTaskDeployForm); |
|
80 |
} |
|
81 |
} |
|
82 |
} |
|
83 |
// 批量新增部署流程和表单关联信息 |
|
84 |
return baseMapper.insertBatch(deployFormList); |
|
85 |
} |
|
86 |
|
|
87 |
/** |
|
88 |
* 查询流程挂着的表单 |
|
89 |
* |
|
90 |
* @param deployId |
|
91 |
* @return |
|
92 |
*/ |
|
93 |
@Override |
|
94 |
public WfFormVo selectDeployFormByDeployId(String deployId) { |
|
95 |
QueryWrapper<WfForm> wrapper = Wrappers.query(); |
|
96 |
wrapper.eq("t2.deploy_id", deployId); |
|
97 |
List<WfFormVo> list = formMapper.selectFormVoList(wrapper); |
|
98 |
if (ObjectUtil.isNotEmpty(list)) { |
|
99 |
if (list.size() != 1) { |
|
100 |
throw new ServiceException("表单信息查询错误"); |
|
101 |
} else { |
|
102 |
return list.get(0); |
|
103 |
} |
|
104 |
} else { |
|
105 |
return null; |
|
106 |
} |
|
107 |
} |
|
108 |
|
|
109 |
/** |
|
110 |
* 构建部署表单关联信息对象 |
|
111 |
* @param deployId 部署ID |
|
112 |
* @param node 节点信息 |
|
113 |
* @return 部署表单关联对象。若无表单信息(formKey),则返回null |
|
114 |
*/ |
|
115 |
private WfDeployForm buildDeployForm(String deployId, FlowNode node) { |
|
116 |
String formKey = ModelUtils.getFormKey(node); |
|
117 |
if (StringUtils.isEmpty(formKey)) { |
|
118 |
return null; |
|
119 |
} |
|
120 |
// Long formId = Convert.toLong(StringUtils.substringAfter(formKey, "key_")); |
|
121 |
// WfForm wfForm = formMapper.selectById(formId); |
|
122 |
// if (ObjectUtil.isNull(wfForm)) { |
|
123 |
// throw new ServiceException("表单信息查询错误"); |
|
124 |
// } |
|
125 |
WfDeployForm deployForm = new WfDeployForm(); |
|
126 |
deployForm.setDeployId(deployId); |
|
127 |
deployForm.setFormKey(formKey); |
|
128 |
deployForm.setNodeKey(node.getId()); |
|
129 |
deployForm.setFormName(formKey);//wfForm.getFormName() |
|
130 |
deployForm.setNodeName(node.getName()); |
|
131 |
deployForm.setContent(formKey);//wfForm.getContent() |
|
132 |
return deployForm; |
|
133 |
} |
|
134 |
} |