dongyukun
6 天以前 ed8fc5f674544d3af63c6f68093ffc038385c493
提交 | 用户 | 时间
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.common.engine.impl.db.SuspensionState;
15 import org.flowable.engine.repository.Deployment;
16 import org.flowable.engine.repository.ProcessDefinition;
17 import org.mapstruct.Mapper;
18 import org.mapstruct.Mapping;
19 import org.mapstruct.MappingTarget;
20 import org.mapstruct.factory.Mappers;
21
bb2880 22 import java.util.Comparator;
e7c126 23 import java.util.List;
H 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) {
bb2880 50         List<BpmProcessDefinitionRespVO> result = CollectionUtils.convertList(list, definition -> {
e7c126 51             Deployment deployment = MapUtil.get(deploymentMap, definition.getDeploymentId(), Deployment.class);
H 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);
bb2880 58             return buildProcessDefinition(definition, deployment, processDefinitionInfo, form, category, null);
e7c126 59         });
bb2880 60         // 排序
H 61         result.sort(Comparator.comparing(BpmProcessDefinitionRespVO::getSort));
62         return result;
e7c126 63     }
H 64
65     default BpmProcessDefinitionRespVO buildProcessDefinition(ProcessDefinition definition,
66                                                               Deployment deployment,
67                                                               BpmProcessDefinitionInfoDO processDefinitionInfo,
68                                                               BpmFormDO form,
69                                                               BpmCategoryDO category,
bb2880 70                                                               BpmnModel bpmnModel) {
e7c126 71         BpmProcessDefinitionRespVO respVO = BeanUtils.toBean(definition, BpmProcessDefinitionRespVO.class);
H 72         respVO.setSuspensionState(definition.isSuspended() ? SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode());
73         // Deployment
74         if (deployment != null) {
75             respVO.setDeploymentTime(LocalDateTimeUtil.of(deployment.getDeploymentTime()));
76         }
77         // BpmProcessDefinitionInfoDO
78         if (processDefinitionInfo != null) {
79             copyTo(processDefinitionInfo, respVO);
80             // Form
81             if (form != null) {
82                 respVO.setFormName(form.getName());
83             }
84         }
85         // Category
86         if (category != null) {
87             respVO.setCategoryName(category.getName());
88         }
89         // BpmnModel
90         if (bpmnModel != null) {
91             respVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnModel));
92         }
93         return respVO;
94     }
95
96     @Mapping(source = "from.id", target = "to.id", ignore = true)
97     void copyTo(BpmProcessDefinitionInfoDO from, @MappingTarget BpmProcessDefinitionRespVO to);
98
99 }