mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-02-03 04:04:58 +08:00
【功能实现】工作流:流程模型,增加 sort 字段的返回(不包括修改)
This commit is contained in:
parent
a122253a93
commit
30e4f0c09c
@ -2,8 +2,6 @@ package cn.iocoder.yudao.module.bpm.controller.admin.definition;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.*;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
|
||||
@ -28,10 +26,7 @@ import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
@ -56,38 +51,38 @@ public class BpmModelController {
|
||||
@Resource
|
||||
private AdminUserApi adminUserApi;
|
||||
|
||||
@GetMapping("/page")
|
||||
@GetMapping("/list")
|
||||
@Operation(summary = "获得模型分页")
|
||||
public CommonResult<PageResult<BpmModelRespVO>> getModelPage(BpmModelPageReqVO pageVO) {
|
||||
PageResult<Model> pageResult = modelService.getModelPage(pageVO);
|
||||
if (CollUtil.isEmpty(pageResult.getList())) {
|
||||
return success(PageResult.empty(pageResult.getTotal()));
|
||||
@Parameter(name = "name", description = "模型名称", example = "芋艿")
|
||||
public CommonResult<List<BpmModelRespVO>> getModelPage(@RequestParam(value = "name", required = false) String name) {
|
||||
List<Model> list = modelService.getModelList(name);
|
||||
if (CollUtil.isEmpty(list)) {
|
||||
return success(Collections.emptyList());
|
||||
}
|
||||
|
||||
// 拼接数据
|
||||
// 获得 Form 表单
|
||||
Set<Long> formIds = convertSet(pageResult.getList(), model -> {
|
||||
Set<Long> formIds = convertSet(list, model -> {
|
||||
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
|
||||
return metaInfo != null ? metaInfo.getFormId() : null;
|
||||
});
|
||||
Map<Long, BpmFormDO> formMap = formService.getFormMap(formIds);
|
||||
// 获得 Category Map
|
||||
Map<String, BpmCategoryDO> categoryMap = categoryService.getCategoryMap(
|
||||
convertSet(pageResult.getList(), Model::getCategory));
|
||||
convertSet(list, Model::getCategory));
|
||||
// 获得 Deployment Map
|
||||
Set<String> deploymentIds = new HashSet<>();
|
||||
pageResult.getList().forEach(model -> CollectionUtils.addIfNotNull(deploymentIds, model.getDeploymentId()));
|
||||
Map<String, Deployment> deploymentMap = processDefinitionService.getDeploymentMap(deploymentIds);
|
||||
Map<String, Deployment> deploymentMap = processDefinitionService.getDeploymentMap(
|
||||
convertSet(list, Model::getDeploymentId));
|
||||
// 获得 ProcessDefinition Map
|
||||
List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds(deploymentIds);
|
||||
List<ProcessDefinition> processDefinitions = processDefinitionService.getProcessDefinitionListByDeploymentIds(
|
||||
deploymentMap.keySet());
|
||||
Map<String, ProcessDefinition> processDefinitionMap = convertMap(processDefinitions, ProcessDefinition::getDeploymentId);
|
||||
// 获得 User Map
|
||||
Set<Long> userIds = convertSetByFlatMap(pageResult.getList(), model -> {
|
||||
Set<Long> userIds = convertSetByFlatMap(list, model -> {
|
||||
BpmModelMetaInfoVO metaInfo = BpmModelConvert.INSTANCE.parseMetaInfo(model);
|
||||
return metaInfo != null ? metaInfo.getStartUserIds().stream() : Stream.empty();
|
||||
});
|
||||
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(userIds);
|
||||
return success(BpmModelConvert.INSTANCE.buildModelPage(pageResult,
|
||||
return success(BpmModelConvert.INSTANCE.buildModelList(list,
|
||||
formMap, categoryMap, deploymentMap, processDefinitionMap, userMap));
|
||||
}
|
||||
|
||||
|
@ -15,7 +15,9 @@ import java.util.List;
|
||||
* BPM 流程 MetaInfo Response DTO
|
||||
* 主要用于 { Model#setMetaInfo(String)} 的存储
|
||||
*
|
||||
* 最终,它的字段和 {@link cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO} 是一致的
|
||||
* 最终,它的字段和
|
||||
* {@link cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO}
|
||||
* 是一致的
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@ -40,13 +42,11 @@ public class BpmModelMetaInfoVO {
|
||||
@NotNull(message = "表单类型不能为空")
|
||||
private Integer formType;
|
||||
@Schema(description = "表单编号", example = "1024")
|
||||
private Long formId; // formType 为 NORMAL 使用,必须非空
|
||||
@Schema(description = "自定义表单的提交路径,使用 Vue 的路由地址",
|
||||
example = "/bpm/oa/leave/create")
|
||||
private String formCustomCreatePath; // 表单类型为 CUSTOM 时,必须非空
|
||||
@Schema(description = "自定义表单的查看路径,使用 Vue 的路由地址",
|
||||
example = "/bpm/oa/leave/view")
|
||||
private String formCustomViewPath; // 表单类型为 CUSTOM 时,必须非空
|
||||
private Long formId; // formType 为 NORMAL 使用,必须非空
|
||||
@Schema(description = "自定义表单的提交路径,使用 Vue 的路由地址", example = "/bpm/oa/leave/create")
|
||||
private String formCustomCreatePath; // 表单类型为 CUSTOM 时,必须非空
|
||||
@Schema(description = "自定义表单的查看路径,使用 Vue 的路由地址", example = "/bpm/oa/leave/view")
|
||||
private String formCustomViewPath; // 表单类型为 CUSTOM 时,必须非空
|
||||
|
||||
@Schema(description = "是否可见", requiredMode = Schema.RequiredMode.REQUIRED, example = "true")
|
||||
@NotNull(message = "是否可见不能为空")
|
||||
@ -59,4 +59,7 @@ public class BpmModelMetaInfoVO {
|
||||
@NotEmpty(message = "可管理用户编号数组不能为空")
|
||||
private List<Long> managerUserIds;
|
||||
|
||||
@Schema(description = "排序", example = "1")
|
||||
private Long sort; // 创建时,后端自动生成
|
||||
|
||||
}
|
||||
|
@ -1,23 +0,0 @@
|
||||
package cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
|
||||
|
||||
@Schema(description = "管理后台 - 流程模型分页 Request VO")
|
||||
@Data
|
||||
public class BpmModelPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "标识,精准匹配", example = "process1641042089407")
|
||||
private String key;
|
||||
|
||||
@Schema(description = "名字,模糊匹配", example = "芋道")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "流程分类", example = "1")
|
||||
private String category;
|
||||
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
package cn.iocoder.yudao.module.bpm.convert.definition;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
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;
|
||||
@ -22,6 +21,7 @@ import org.mapstruct.Mapper;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@ -37,25 +37,31 @@ public interface BpmModelConvert {
|
||||
|
||||
BpmModelConvert INSTANCE = Mappers.getMapper(BpmModelConvert.class);
|
||||
|
||||
default PageResult<BpmModelRespVO> buildModelPage(PageResult<Model> pageResult,
|
||||
Map<Long, BpmFormDO> formMap,
|
||||
Map<String, BpmCategoryDO> categoryMap, Map<String, Deployment> deploymentMap,
|
||||
Map<String, ProcessDefinition> processDefinitionMap,
|
||||
Map<Long, AdminUserRespDTO> userMap) {
|
||||
List<BpmModelRespVO> list = convertList(pageResult.getList(), model -> {
|
||||
default List<BpmModelRespVO> buildModelList(List<Model> list,
|
||||
Map<Long, BpmFormDO> formMap,
|
||||
Map<String, BpmCategoryDO> categoryMap,
|
||||
Map<String, Deployment> deploymentMap,
|
||||
Map<String, ProcessDefinition> processDefinitionMap,
|
||||
Map<Long, AdminUserRespDTO> userMap) {
|
||||
List<BpmModelRespVO> result = convertList(list, 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;
|
||||
List<AdminUserRespDTO> startUsers = metaInfo != null ? convertList(metaInfo.getStartUserIds(), userMap::get) : null;
|
||||
ProcessDefinition processDefinition = model.getDeploymentId() != null
|
||||
? processDefinitionMap.get(model.getDeploymentId())
|
||||
: null;
|
||||
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());
|
||||
// 排序
|
||||
result.sort(Comparator.comparing(BpmModelMetaInfoVO::getSort));
|
||||
return result;
|
||||
}
|
||||
|
||||
default BpmModelRespVO buildModel(Model model,
|
||||
byte[] bpmnBytes) {
|
||||
byte[] bpmnBytes) {
|
||||
BpmModelMetaInfoVO metaInfo = parseMetaInfo(model);
|
||||
BpmModelRespVO modelVO = buildModel0(model, metaInfo, null, null, null, null, null);
|
||||
if (ArrayUtil.isNotEmpty(bpmnBytes)) {
|
||||
@ -65,9 +71,9 @@ public interface BpmModelConvert {
|
||||
}
|
||||
|
||||
default BpmModelRespVO buildModel0(Model model,
|
||||
BpmModelMetaInfoVO metaInfo, BpmFormDO form, BpmCategoryDO category,
|
||||
Deployment deployment, ProcessDefinition processDefinition,
|
||||
List<AdminUserRespDTO> startUsers) {
|
||||
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()));
|
||||
@ -83,8 +89,9 @@ public interface BpmModelConvert {
|
||||
// ProcessDefinition
|
||||
if (processDefinition != null) {
|
||||
modelRespVO.setProcessDefinition(BeanUtils.toBean(processDefinition, BpmProcessDefinitionRespVO.class));
|
||||
modelRespVO.getProcessDefinition().setSuspensionState(processDefinition.isSuspended() ?
|
||||
SuspensionState.SUSPENDED.getStateCode() : SuspensionState.ACTIVE.getStateCode());
|
||||
modelRespVO.getProcessDefinition()
|
||||
.setSuspensionState(processDefinition.isSuspended() ? SuspensionState.SUSPENDED.getStateCode()
|
||||
: SuspensionState.ACTIVE.getStateCode());
|
||||
if (deployment != null) {
|
||||
modelRespVO.getProcessDefinition().setDeploymentTime(DateUtils.of(deployment.getDeploymentTime()));
|
||||
}
|
||||
@ -112,6 +119,10 @@ public interface BpmModelConvert {
|
||||
if (vo.getStartUserIds() == null) {
|
||||
vo.setStartUserIds(Collections.emptyList());
|
||||
}
|
||||
// 如果为空,兜底处理,使用 createTime 创建时间
|
||||
if (vo.getSort() == null) {
|
||||
vo.setSort(model.getCreateTime().getTime());
|
||||
}
|
||||
return vo;
|
||||
}
|
||||
|
||||
|
@ -1,7 +1,5 @@
|
||||
package cn.iocoder.yudao.module.bpm.service.definition;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
|
||||
@ -9,20 +7,22 @@ import jakarta.validation.Valid;
|
||||
import org.flowable.bpmn.model.BpmnModel;
|
||||
import org.flowable.engine.repository.Model;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Flowable流程模型接口
|
||||
* 流程模型接口
|
||||
*
|
||||
* @author yunlongn
|
||||
*/
|
||||
public interface BpmModelService {
|
||||
|
||||
/**
|
||||
* 获得流程模型分页
|
||||
* 获得流程模型列表
|
||||
*
|
||||
* @param pageVO 分页查询
|
||||
* @return 流程模型分页
|
||||
* @param name 模型名称
|
||||
* @return 流程模型列表
|
||||
*/
|
||||
PageResult<Model> getModelPage(BpmModelPageReqVO pageVO);
|
||||
List<Model> getModelList(String name);
|
||||
|
||||
/**
|
||||
* 创建流程模型
|
||||
|
@ -3,12 +3,9 @@ package cn.iocoder.yudao.module.bpm.service.definition;
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
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.json.JsonUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.object.PageUtils;
|
||||
import cn.iocoder.yudao.framework.common.util.validation.ValidationUtils;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelPageReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelSaveReqVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO;
|
||||
import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelUpdateReqVO;
|
||||
@ -41,8 +38,7 @@ import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionU
|
||||
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* Flowable流程模型实现
|
||||
* 主要进行 Flowable {@link Model} 的维护
|
||||
* 流程模型实现:主要进行 Flowable {@link Model} 的维护
|
||||
*
|
||||
* @author yunlongn
|
||||
* @author 芋道源码
|
||||
@ -64,27 +60,12 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
private BpmTaskCandidateInvoker taskCandidateInvoker;
|
||||
|
||||
@Override
|
||||
public PageResult<Model> getModelPage(BpmModelPageReqVO pageVO) {
|
||||
public List<Model> getModelList(String name) {
|
||||
ModelQuery modelQuery = repositoryService.createModelQuery();
|
||||
modelQuery.modelTenantId(FlowableUtils.getTenantId());
|
||||
if (StrUtil.isNotBlank(pageVO.getKey())) {
|
||||
modelQuery.modelKey(pageVO.getKey());
|
||||
if (StrUtil.isNotEmpty(name)) {
|
||||
modelQuery.modelNameLike(name);
|
||||
}
|
||||
if (StrUtil.isNotBlank(pageVO.getName())) {
|
||||
modelQuery.modelNameLike("%" + pageVO.getName() + "%"); // 模糊匹配
|
||||
}
|
||||
if (StrUtil.isNotBlank(pageVO.getCategory())) {
|
||||
modelQuery.modelCategory(pageVO.getCategory());
|
||||
}
|
||||
// 执行查询
|
||||
long count = modelQuery.count();
|
||||
if (count == 0) {
|
||||
return PageResult.empty(count);
|
||||
}
|
||||
List<Model> models = modelQuery
|
||||
.orderByCreateTime().desc()
|
||||
.listPage(PageUtils.getStart(pageVO), pageVO.getPageSize());
|
||||
return new PageResult<>(models, count);
|
||||
return modelQuery.list();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -100,6 +81,7 @@ public class BpmModelServiceImpl implements BpmModelService {
|
||||
}
|
||||
|
||||
// 2.1 创建流程定义
|
||||
createReqVO.setSort(System.currentTimeMillis()); // 使用当前时间,作为排序
|
||||
Model model = repositoryService.newModel();
|
||||
BpmModelConvert.INSTANCE.copyToModel(model, createReqVO);
|
||||
model.setTenantId(FlowableUtils.getTenantId());
|
||||
|
Loading…
Reference in New Issue
Block a user