houzhongyi
2024-07-11 e7c1260db32209a078a962aaa0ad5492c35774fb
提交 | 用户 | 时间
e7c126 1 package com.iailab.module.bpm.convert.definition;
H 2
3 import cn.hutool.core.date.LocalDateTimeUtil;
4 import cn.hutool.core.map.MapUtil;
5 import com.iailab.framework.common.pojo.PageResult;
6 import com.iailab.framework.common.util.collection.CollectionUtils;
7 import com.iailab.framework.common.util.object.BeanUtils;
8 import com.iailab.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
9 import com.iailab.module.bpm.dal.dataobject.definition.BpmCategoryDO;
10 import com.iailab.module.bpm.dal.dataobject.definition.BpmFormDO;
11 import com.iailab.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO;
12 import com.iailab.module.bpm.framework.flowable.core.util.BpmnModelUtils;
13 import org.flowable.bpmn.model.BpmnModel;
14 import org.flowable.bpmn.model.UserTask;
15 import org.flowable.common.engine.impl.db.SuspensionState;
16 import org.flowable.engine.repository.Deployment;
17 import org.flowable.engine.repository.ProcessDefinition;
18 import org.mapstruct.Mapper;
19 import org.mapstruct.Mapping;
20 import org.mapstruct.MappingTarget;
21 import org.mapstruct.factory.Mappers;
22
23 import java.util.List;
24 import java.util.Map;
25
26 /**
27  * Bpm 流程定义的 Convert
28  *
29  * @author yunlong.li
30  */
31 @Mapper
32 public interface BpmProcessDefinitionConvert {
33
34     BpmProcessDefinitionConvert INSTANCE = Mappers.getMapper(BpmProcessDefinitionConvert.class);
35
36     default PageResult<BpmProcessDefinitionRespVO> buildProcessDefinitionPage(PageResult<ProcessDefinition> page,
37                                                                               Map<String, Deployment> deploymentMap,
38                                                                               Map<String, BpmProcessDefinitionInfoDO> processDefinitionInfoMap,
39                                                                               Map<Long, BpmFormDO> formMap,
40                                                                               Map<String, BpmCategoryDO> categoryMap) {
41         List<BpmProcessDefinitionRespVO> list = buildProcessDefinitionList(page.getList(), deploymentMap, processDefinitionInfoMap, formMap, categoryMap);
42         return new PageResult<>(list, page.getTotal());
43     }
44
45     default List<BpmProcessDefinitionRespVO> buildProcessDefinitionList(List<ProcessDefinition> list,
46                                                                         Map<String, Deployment> deploymentMap,
47                                                                         Map<String, BpmProcessDefinitionInfoDO> processDefinitionInfoMap,
48                                                                         Map<Long, BpmFormDO> formMap,
49                                                                         Map<String, BpmCategoryDO> categoryMap) {
50         return CollectionUtils.convertList(list, definition -> {
51             Deployment deployment = MapUtil.get(deploymentMap, definition.getDeploymentId(), Deployment.class);
52             BpmProcessDefinitionInfoDO processDefinitionInfo = MapUtil.get(processDefinitionInfoMap, definition.getId(), BpmProcessDefinitionInfoDO.class);
53             BpmFormDO form = null;
54             if (processDefinitionInfo != null) {
55                 form = MapUtil.get(formMap, processDefinitionInfo.getFormId(), BpmFormDO.class);
56             }
57             BpmCategoryDO category = MapUtil.get(categoryMap, definition.getCategory(), BpmCategoryDO.class);
58             return buildProcessDefinition(definition, deployment, processDefinitionInfo, form, category, null, null);
59         });
60     }
61
62     default BpmProcessDefinitionRespVO buildProcessDefinition(ProcessDefinition definition,
63                                                               Deployment deployment,
64                                                               BpmProcessDefinitionInfoDO processDefinitionInfo,
65                                                               BpmFormDO form,
66                                                               BpmCategoryDO category,
67                                                               BpmnModel bpmnModel,
68                                                               List<UserTask> startUserSelectUserTaskList) {
69         BpmProcessDefinitionRespVO respVO = BeanUtils.toBean(definition, BpmProcessDefinitionRespVO.class);
70         respVO.setSuspensionState(definition.isSuspended() ? SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode());
71         // Deployment
72         if (deployment != null) {
73             respVO.setDeploymentTime(LocalDateTimeUtil.of(deployment.getDeploymentTime()));
74         }
75         // BpmProcessDefinitionInfoDO
76         if (processDefinitionInfo != null) {
77             copyTo(processDefinitionInfo, respVO);
78             // Form
79             if (form != null) {
80                 respVO.setFormName(form.getName());
81             }
82         }
83         // Category
84         if (category != null) {
85             respVO.setCategoryName(category.getName());
86         }
87         // BpmnModel
88         if (bpmnModel != null) {
89             respVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnModel));
90             respVO.setStartUserSelectTasks(BeanUtils.toBean(startUserSelectUserTaskList, BpmProcessDefinitionRespVO.UserTask.class));
91         }
92         return respVO;
93     }
94
95     @Mapping(source = "from.id", target = "to.id", ignore = true)
96     void copyTo(BpmProcessDefinitionInfoDO from, @MappingTarget BpmProcessDefinitionRespVO to);
97
98 }