提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.bpm.convert.definition; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.ArrayUtil; |
|
4 |
import com.iailab.framework.common.util.date.DateUtils; |
|
5 |
import com.iailab.framework.common.util.json.JsonUtils; |
|
6 |
import com.iailab.framework.common.util.object.BeanUtils; |
bb2880
|
7 |
import com.iailab.module.bpm.controller.admin.base.user.UserSimpleBaseVO; |
H |
8 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; |
e7c126
|
9 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO; |
bb2880
|
10 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO; |
f4f940
|
11 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
e7c126
|
12 |
import com.iailab.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; |
H |
13 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmCategoryDO; |
|
14 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmFormDO; |
bb2880
|
15 |
import com.iailab.module.bpm.framework.flowable.core.util.BpmnModelUtils; |
H |
16 |
import com.iailab.module.system.api.user.dto.AdminUserRespDTO; |
e7c126
|
17 |
import org.flowable.common.engine.impl.db.SuspensionState; |
H |
18 |
import org.flowable.engine.repository.Deployment; |
|
19 |
import org.flowable.engine.repository.Model; |
|
20 |
import org.flowable.engine.repository.ProcessDefinition; |
|
21 |
import org.mapstruct.Mapper; |
|
22 |
import org.mapstruct.factory.Mappers; |
|
23 |
|
bb2880
|
24 |
import java.util.Collections; |
H |
25 |
import java.util.Comparator; |
e7c126
|
26 |
import java.util.List; |
H |
27 |
import java.util.Map; |
bb2880
|
28 |
|
H |
29 |
import static com.iailab.framework.common.util.collection.CollectionUtils.convertList; |
e7c126
|
30 |
|
H |
31 |
/** |
|
32 |
* 流程模型 Convert |
|
33 |
* |
bb2880
|
34 |
* @author hou |
e7c126
|
35 |
*/ |
H |
36 |
@Mapper |
|
37 |
public interface BpmModelConvert { |
|
38 |
|
|
39 |
BpmModelConvert INSTANCE = Mappers.getMapper(BpmModelConvert.class); |
|
40 |
|
bb2880
|
41 |
default List<BpmModelRespVO> buildModelList(List<Model> list, |
H |
42 |
Map<Long, BpmFormDO> formMap, |
|
43 |
Map<String, BpmCategoryDO> categoryMap, |
|
44 |
Map<String, Deployment> deploymentMap, |
|
45 |
Map<String, ProcessDefinition> processDefinitionMap, |
|
46 |
Map<Long, AdminUserRespDTO> userMap) { |
|
47 |
List<BpmModelRespVO> result = convertList(list, model -> { |
|
48 |
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); |
e7c126
|
49 |
BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null; |
H |
50 |
BpmCategoryDO category = categoryMap.get(model.getCategory()); |
|
51 |
Deployment deployment = model.getDeploymentId() != null ? deploymentMap.get(model.getDeploymentId()) : null; |
bb2880
|
52 |
ProcessDefinition processDefinition = model.getDeploymentId() != null ? |
H |
53 |
processDefinitionMap.get(model.getDeploymentId()) : null; |
|
54 |
List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null; |
|
55 |
return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers); |
e7c126
|
56 |
}); |
bb2880
|
57 |
// 排序 |
H |
58 |
result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort)); |
|
59 |
return result; |
e7c126
|
60 |
} |
H |
61 |
|
f4f940
|
62 |
default BpmModelRespVO buildModel(Model model, byte[] bpmnBytes, BpmSimpleModelNodeVO simpleModel) { |
bb2880
|
63 |
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model); |
H |
64 |
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null); |
e7c126
|
65 |
if (ArrayUtil.isNotEmpty(bpmnBytes)) { |
bb2880
|
66 |
modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes)); |
e7c126
|
67 |
} |
f4f940
|
68 |
modelVO.setSimpleModel(simpleModel); |
e7c126
|
69 |
return modelVO; |
H |
70 |
} |
|
71 |
|
|
72 |
default BpmModelRespVO buildModel0(Model model, |
bb2880
|
73 |
BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category, |
H |
74 |
Deployment deployment, ProcessDefinition processDefinition, |
|
75 |
List<AdminUserRespDTO> startUsers) { |
e7c126
|
76 |
BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName()) |
H |
77 |
.setKey(model.getKey()).setCategory(model.getCategory()) |
|
78 |
.setCreateTime(DateUtils.of(model.getCreateTime())); |
|
79 |
// Form |
bb2880
|
80 |
BeanUtils.copyProperties(metaInfo, modelRespVO); |
e7c126
|
81 |
if (form != null) { |
bb2880
|
82 |
modelRespVO.setFormName(form.getName()); |
e7c126
|
83 |
} |
H |
84 |
// Category |
|
85 |
if (category != null) { |
|
86 |
modelRespVO.setCategoryName(category.getName()); |
|
87 |
} |
|
88 |
// ProcessDefinition |
|
89 |
if (processDefinition != null) { |
|
90 |
modelRespVO.setProcessDefinition(BeanUtils.toBean(processDefinition, BpmProcessDefinitionRespVO.class)); |
|
91 |
modelRespVO.getProcessDefinition().setSuspensionState(processDefinition.isSuspended() ? |
|
92 |
SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode()); |
|
93 |
if (deployment != null) { |
|
94 |
modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime())); |
|
95 |
} |
|
96 |
} |
bb2880
|
97 |
// User |
H |
98 |
modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class)); |
e7c126
|
99 |
return modelRespVO; |
H |
100 |
} |
|
101 |
|
bb2880
|
102 |
default void copyToModel(Model model, BpmModelSaveReqVO reqVO) { |
H |
103 |
model.setName(reqVO.getName()); |
|
104 |
model.setKey(reqVO.getKey()); |
|
105 |
model.setCategory(reqVO.getCategory()); |
|
106 |
model.setMetaInfo(JsonUtils.toJsonString(BeanUtils.toBean(reqVO, BpmModelMetaInfoVO.class))); |
e7c126
|
107 |
} |
H |
108 |
|
bb2880
|
109 |
default BpmModelMetaInfoVO parseMetaInfo(Model model) { |
H |
110 |
BpmModelMetaInfoVO vo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class); |
|
111 |
if (vo == null) { |
|
112 |
return null; |
e7c126
|
113 |
} |
bb2880
|
114 |
if (vo.getManagerUserIds() == null) { |
H |
115 |
vo.setManagerUserIds(Collections.emptyList()); |
e7c126
|
116 |
} |
bb2880
|
117 |
if (vo.getStartUserIds() == null) { |
H |
118 |
vo.setStartUserIds(Collections.emptyList()); |
e7c126
|
119 |
} |
bb2880
|
120 |
// 如果为空,兜底处理,使用 createTime 创建时间 |
H |
121 |
if (vo.getSort() == null) { |
|
122 |
vo.setSort(model.getCreateTime().getTime()); |
e7c126
|
123 |
} |
bb2880
|
124 |
return vo; |
e7c126
|
125 |
} |
H |
126 |
|
|
127 |
} |