|
@@ -1,20 +1,19 @@
|
|
|
package cn.iocoder.yudao.module.bpm.convert.definition;
|
|
|
|
|
|
import cn.hutool.core.util.ArrayUtil;
|
|
|
-import cn.hutool.core.util.StrUtil;
|
|
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
|
|
-import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.json.JsonUtils;
|
|
|
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
|
|
-import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelCreateReqVO;
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.base.user.UserSimpleBaseVO;
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelRespVO;
|
|
|
-import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelUpdateReqVO;
|
|
|
+import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
|
|
|
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.process.BpmProcessDefinitionRespVO;
|
|
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmCategoryDO;
|
|
|
import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmFormDO;
|
|
|
import cn.iocoder.yudao.module.bpm.framework.flowable.core.util.BpmnModelUtils;
|
|
|
-import cn.iocoder.yudao.module.bpm.service.definition.dto.BpmModelMetaInfoRespDTO;
|
|
|
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
|
|
import org.flowable.common.engine.impl.db.SuspensionState;
|
|
|
import org.flowable.engine.repository.Deployment;
|
|
|
import org.flowable.engine.repository.Model;
|
|
@@ -22,9 +21,11 @@ import org.flowable.engine.repository.ProcessDefinition;
|
|
|
import org.mapstruct.Mapper;
|
|
|
import org.mapstruct.factory.Mappers;
|
|
|
|
|
|
+import java.util.Collections;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
-import java.util.Objects;
|
|
|
+
|
|
|
+import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
|
|
|
|
|
/**
|
|
|
* 流程模型 Convert
|
|
@@ -39,22 +40,24 @@ public interface BpmModelConvert {
|
|
|
default PageResult<BpmModelRespVO> buildModelPage(PageResult<Model> pageResult,
|
|
|
Map<Long, BpmFormDO> formMap,
|
|
|
Map<String, BpmCategoryDO> categoryMap, Map<String, Deployment> deploymentMap,
|
|
|
- Map<String, ProcessDefinition> processDefinitionMap) {
|
|
|
- List<BpmModelRespVO> list = CollectionUtils.convertList(pageResult.getList(), model -> {
|
|
|
- BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model);
|
|
|
+ Map<String, ProcessDefinition> processDefinitionMap,
|
|
|
+ Map<Long, AdminUserRespDTO> userMap) {
|
|
|
+ List<BpmModelRespVO> list = convertList(pageResult.getList(), model -> {
|
|
|
+ BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
|
|
|
BpmFormDO form = metaInfo != null ? formMap.get(metaInfo.getFormId()) : null;
|
|
|
BpmCategoryDO category = categoryMap.get(model.getCategory());
|
|
|
Deployment deployment = model.getDeploymentId() != null ? deploymentMap.get(model.getDeploymentId()) : null;
|
|
|
ProcessDefinition processDefinition = model.getDeploymentId() != null ? processDefinitionMap.get(model.getDeploymentId()) : null;
|
|
|
- return buildModel0(model, metaInfo, form, category, deployment, processDefinition);
|
|
|
+ List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null;
|
|
|
+ return buildModel0(model, metaInfo, form, category, deployment, processDefinition, startUsers);
|
|
|
});
|
|
|
return new PageResult<>(list, pageResult.getTotal());
|
|
|
}
|
|
|
|
|
|
default BpmModelRespVO buildModel(Model model,
|
|
|
byte[] bpmnBytes) {
|
|
|
- BpmModelMetaInfoRespDTO metaInfo = buildMetaInfo(model);
|
|
|
- BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null);
|
|
|
+ BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
|
|
|
+ BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
|
|
|
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
|
|
|
modelVO.setBpmnXml(BpmnModelUtils.getBpmnXml(bpmnBytes));
|
|
|
}
|
|
@@ -62,20 +65,16 @@ public interface BpmModelConvert {
|
|
|
}
|
|
|
|
|
|
default BpmModelRespVO buildModel0(Model model,
|
|
|
- BpmModelMetaInfoRespDTO metaInfo, BpmFormDO form, BpmCategoryDO category,
|
|
|
- Deployment deployment, ProcessDefinition processDefinition) {
|
|
|
+ BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
|
|
|
+ Deployment deployment, ProcessDefinition processDefinition,
|
|
|
+ List<AdminUserRespDTO> startUsers) {
|
|
|
BpmModelRespVO modelRespVO = new BpmModelRespVO().setId(model.getId()).setName(model.getName())
|
|
|
.setKey(model.getKey()).setCategory(model.getCategory())
|
|
|
.setCreateTime(DateUtils.of(model.getCreateTime()));
|
|
|
// Form
|
|
|
- if (metaInfo != null) {
|
|
|
- modelRespVO.setFormType(metaInfo.getFormType()).setFormId(metaInfo.getFormId())
|
|
|
- .setFormCustomCreatePath(metaInfo.getFormCustomCreatePath())
|
|
|
- .setFormCustomViewPath(metaInfo.getFormCustomViewPath());
|
|
|
- modelRespVO.setIcon(metaInfo.getIcon()).setDescription(metaInfo.getDescription());
|
|
|
- }
|
|
|
+ BeanUtils.copyProperties(metaInfo, modelRespVO);
|
|
|
if (form != null) {
|
|
|
- modelRespVO.setFormId(form.getId()).setFormName(form.getName());
|
|
|
+ modelRespVO.setFormName(form.getName());
|
|
|
}
|
|
|
// Category
|
|
|
if (category != null) {
|
|
@@ -90,49 +89,30 @@ public interface BpmModelConvert {
|
|
|
modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime()));
|
|
|
}
|
|
|
}
|
|
|
+ // User
|
|
|
+ modelRespVO.setStartUsers(BeanUtils.toBean(startUsers, UserSimpleBaseVO.class));
|
|
|
return modelRespVO;
|
|
|
}
|
|
|
|
|
|
- default void copyToCreateModel(Model model, BpmModelCreateReqVO bean) {
|
|
|
- model.setName(bean.getName());
|
|
|
- model.setKey(bean.getKey());
|
|
|
- model.setMetaInfo(buildMetaInfoStr(null,
|
|
|
- null, bean.getDescription(),
|
|
|
- null, null, null, null));
|
|
|
- }
|
|
|
-
|
|
|
- default void copyToUpdateModel(Model model, BpmModelUpdateReqVO bean) {
|
|
|
- model.setName(bean.getName());
|
|
|
- model.setCategory(bean.getCategory());
|
|
|
- model.setMetaInfo(buildMetaInfoStr(buildMetaInfo(model),
|
|
|
- bean.getIcon(), bean.getDescription(),
|
|
|
- bean.getFormType(), bean.getFormId(), bean.getFormCustomCreatePath(), bean.getFormCustomViewPath()));
|
|
|
+ default void copyToModel(Model model, BpmModelSaveReqVO reqVO) {
|
|
|
+ model.setName(reqVO.getName());
|
|
|
+ model.setKey(reqVO.getKey());
|
|
|
+ model.setCategory(reqVO.getCategory());
|
|
|
+ model.setMetaInfo(JsonUtils.toJsonString(BeanUtils.toBean(reqVO, BpmModelMetaInfoVO.class)));
|
|
|
}
|
|
|
|
|
|
- default String buildMetaInfoStr(BpmModelMetaInfoRespDTO metaInfo,
|
|
|
- String icon, String description,
|
|
|
- Integer formType, Long formId, String formCustomCreatePath, String formCustomViewPath) {
|
|
|
- if (metaInfo == null) {
|
|
|
- metaInfo = new BpmModelMetaInfoRespDTO();
|
|
|
+ default BpmModelMetaInfoVO parseMetaInfo(Model model) {
|
|
|
+ BpmModelMetaInfoVO vo = JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoVO.class);
|
|
|
+ if (vo == null) {
|
|
|
+ return null;
|
|
|
}
|
|
|
- // 只有非空,才进行设置,避免更新时的覆盖
|
|
|
- if (StrUtil.isNotEmpty(icon)) {
|
|
|
- metaInfo.setIcon(icon);
|
|
|
+ if (vo.getManagerUserIds() == null) {
|
|
|
+ vo.setManagerUserIds(Collections.emptyList());
|
|
|
}
|
|
|
- if (StrUtil.isNotEmpty(description)) {
|
|
|
- metaInfo.setDescription(description);
|
|
|
+ if (vo.getStartUserIds() == null) {
|
|
|
+ vo.setStartUserIds(Collections.emptyList());
|
|
|
}
|
|
|
- if (Objects.nonNull(formType)) {
|
|
|
- metaInfo.setFormType(formType);
|
|
|
- metaInfo.setFormId(formId);
|
|
|
- metaInfo.setFormCustomCreatePath(formCustomCreatePath);
|
|
|
- metaInfo.setFormCustomViewPath(formCustomViewPath);
|
|
|
- }
|
|
|
- return JsonUtils.toJsonString(metaInfo);
|
|
|
- }
|
|
|
-
|
|
|
- default BpmModelMetaInfoRespDTO buildMetaInfo(Model model) {
|
|
|
- return JsonUtils.parseObject(model.getMetaInfo(), BpmModelMetaInfoRespDTO.class);
|
|
|
+ return vo;
|
|
|
}
|
|
|
|
|
|
}
|