提交 | 用户 | 时间
|
e7c126
|
1 |
package com.iailab.module.bpm.convert.definition; |
H |
2 |
|
|
3 |
import cn.hutool.core.util.ArrayUtil; |
|
4 |
import cn.hutool.core.util.StrUtil; |
|
5 |
import com.iailab.framework.common.pojo.PageResult; |
|
6 |
import com.iailab.framework.common.util.collection.CollectionUtils; |
|
7 |
import com.iailab.framework.common.util.date.DateUtils; |
|
8 |
import com.iailab.framework.common.util.json.JsonUtils; |
|
9 |
import com.iailab.framework.common.util.object.BeanUtils; |
|
10 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO; |
|
11 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO; |
|
12 |
import com.iailab.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO; |
|
13 |
import com.iailab.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO; |
|
14 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmCategoryDO; |
|
15 |
import com.iailab.module.bpm.dal.dataobject.definition.BpmFormDO; |
|
16 |
import com.iailab.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO; |
|
17 |
import org.flowable.common.engine.impl.db.SuspensionState; |
|
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 |
|
|
24 |
import java.util.List; |
|
25 |
import java.util.Map; |
|
26 |
import java.util.Objects; |
|
27 |
|
|
28 |
/** |
|
29 |
* 流程模型 Convert |
|
30 |
* |
|
31 |
* @author yunlongn |
|
32 |
*/ |
|
33 |
@Mapper |
|
34 |
public interface BpmModelConvert { |
|
35 |
|
|
36 |
BpmModelConvert INSTANCE = Mappers.getMapper(BpmModelConvert.class); |
|
37 |
|
|
38 |
default PageResult<BpmModelRespVO> buildModelPage(PageResult<Model> pageResult, |
|
39 |
Map<Long, BpmFormDO> formMap, |
|
40 |
Map<String, BpmCategoryDO> categoryMap, Map<String, Deployment> deploymentMap, |
|
41 |
Map<String, ProcessDefinition> processDefinitionMap) { |
|
42 |
List<BpmModelRespVO> list = CollectionUtils.convertList(pageResult.getList(), model -> { |
|
43 |
BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model); |
|
44 |
BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null; |
|
45 |
BpmCategoryDO category = categoryMap.get(model.getCategory()); |
|
46 |
Deployment deployment = model.getDeploymentId() != null ? deploymentMap.get(model.getDeploymentId()) : null; |
|
47 |
ProcessDefinition processDefinition = model.getDeploymentId() != null ? processDefinitionMap.get(model.getDeploymentId()) : null; |
|
48 |
return buildModel0(model, metaInfo, form, category, deployment, processDefinition); |
|
49 |
}); |
|
50 |
return new PageResult<>(list, pageResult.getTotal()); |
|
51 |
} |
|
52 |
|
|
53 |
default BpmModelRespVO buildModel(Model model, |
|
54 |
byte[] bpmnBytes) { |
|
55 |
BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model); |
|
56 |
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null); |
|
57 |
if (ArrayUtil.isNotEmpty(bpmnBytes)) { |
|
58 |
modelVO.setBpmnXml(new String(bpmnBytes)); |
|
59 |
} |
|
60 |
return modelVO; |
|
61 |
} |
|
62 |
|
|
63 |
default BpmModelRespVO buildModel0(Model model, |
|
64 |
BpmModelMetaInfoRespDTO metaInfo, BpmFormDO form, BpmCategoryDO category, |
|
65 |
Deployment deployment, ProcessDefinition processDefinition) { |
|
66 |
BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName()) |
|
67 |
.setKey(model.getKey()).setCategory(model.getCategory()) |
|
68 |
.setCreateTime(DateUtils.of(model.getCreateTime())); |
|
69 |
// Form |
|
70 |
if (metaInfo != null) { |
|
71 |
modelRespVO.setFormType(metaInfo.getFormType()).setFormId(metaInfo.getFormId()) |
|
72 |
.setFormCustomCreatePath(metaInfo.getFormCustomCreatePath()) |
|
73 |
.setFormCustomViewPath(metaInfo.getFormCustomViewPath()); |
|
74 |
modelRespVO.setIcon(metaInfo.getIcon()).setDescription(metaInfo.getDescription()); |
|
75 |
} |
|
76 |
if (form != null) { |
|
77 |
modelRespVO.setFormId(form.getId()).setFormName(form.getName()); |
|
78 |
} |
|
79 |
// Category |
|
80 |
if (category != null) { |
|
81 |
modelRespVO.setCategoryName(category.getName()); |
|
82 |
} |
|
83 |
// ProcessDefinition |
|
84 |
if (processDefinition != null) { |
|
85 |
modelRespVO.setProcessDefinition(BeanUtils.toBean(processDefinition, BpmProcessDefinitionRespVO.class)); |
|
86 |
modelRespVO.getProcessDefinition().setSuspensionState(processDefinition.isSuspended() ? |
|
87 |
SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode()); |
|
88 |
if (deployment != null) { |
|
89 |
modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime())); |
|
90 |
} |
|
91 |
} |
|
92 |
return modelRespVO; |
|
93 |
} |
|
94 |
|
|
95 |
default void copyToCreateModel(Model model, BpmModelCreateReqVO bean) { |
|
96 |
model.setName(bean.getName()); |
|
97 |
model.setKey(bean.getKey()); |
|
98 |
model.setMetaInfo(buildMetaInfoStr(null, |
|
99 |
null, bean.getDescription(), |
|
100 |
null, null, null, null)); |
|
101 |
} |
|
102 |
|
|
103 |
default void copyToUpdateModel(Model model, BpmModelUpdateReqVO bean) { |
|
104 |
model.setName(bean.getName()); |
|
105 |
model.setCategory(bean.getCategory()); |
|
106 |
model.setMetaInfo(buildMetaInfoStr(buildMetaInfo(model), |
|
107 |
bean.getIcon(), bean.getDescription(), |
|
108 |
bean.getFormType(), bean.getFormId(), bean.getFormCustomCreatePath(), bean.getFormCustomViewPath())); |
|
109 |
} |
|
110 |
|
|
111 |
default String buildMetaInfoStr(BpmModelMetaInfoRespDTO metaInfo, |
|
112 |
String icon, String description, |
|
113 |
Integer formType, Long formId, String formCustomCreatePath, String formCustomViewPath) { |
|
114 |
if (metaInfo == null) { |
|
115 |
metaInfo = new BpmModelMetaInfoRespDTO(); |
|
116 |
} |
|
117 |
// 只有非空,才进行设置,避免更新时的覆盖 |
|
118 |
if (StrUtil.isNotEmpty(icon)) { |
|
119 |
metaInfo.setIcon(icon); |
|
120 |
} |
|
121 |
if (StrUtil.isNotEmpty(description)) { |
|
122 |
metaInfo.setDescription(description); |
|
123 |
} |
|
124 |
if (Objects.nonNull(formType)) { |
|
125 |
metaInfo.setFormType(formType); |
|
126 |
metaInfo.setFormId(formId); |
|
127 |
metaInfo.setFormCustomCreatePath(formCustomCreatePath); |
|
128 |
metaInfo.setFormCustomViewPath(formCustomViewPath); |
|
129 |
} |
|
130 |
return JsonUtils.toJsonString(metaInfo); |
|
131 |
} |
|
132 |
|
|
133 |
default BpmModelMetaInfoRespDTO buildMetaInfo(Model model) { |
|
134 |
return JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class); |
|
135 |
} |
|
136 |
|
|
137 |
} |