Commit 4afdcb46997c67ec869e8bfddd1023d3f61500a4
Committed by
Gitee
!1199 BPM-更多设置-流程编码
Merge pull request !1199 from Lesan/feature/bpm-流程编码
Showing
4 changed files
with
104 additions
and
3 deletions
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
| @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.validation.InEnum; | @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; | 4 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; |
| 5 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; | 5 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; |
| 6 | import io.swagger.v3.oas.annotations.media.Schema; | 6 | import io.swagger.v3.oas.annotations.media.Schema; |
| 7 | +import jakarta.validation.Valid; | ||
| 7 | import jakarta.validation.constraints.NotEmpty; | 8 | import jakarta.validation.constraints.NotEmpty; |
| 8 | import jakarta.validation.constraints.NotNull; | 9 | import jakarta.validation.constraints.NotNull; |
| 9 | import lombok.Data; | 10 | import lombok.Data; |
| @@ -65,4 +66,30 @@ public class BpmModelMetaInfoVO { | @@ -65,4 +66,30 @@ public class BpmModelMetaInfoVO { | ||
| 65 | @Schema(description = "允许撤销审批中的申请", example = "true") | 66 | @Schema(description = "允许撤销审批中的申请", example = "true") |
| 66 | private Boolean allowCancelRunningProcess; | 67 | private Boolean allowCancelRunningProcess; |
| 67 | 68 | ||
| 69 | + @Schema(description = "流程 Id 规则", example = "{}") | ||
| 70 | + private ProcessIdRule processIdRule; | ||
| 71 | + | ||
| 72 | + @Schema(description = "流程 Id 规则") | ||
| 73 | + @Data | ||
| 74 | + @Valid | ||
| 75 | + public static class ProcessIdRule { | ||
| 76 | + | ||
| 77 | + @Schema(description = "是否启用", example = "false") | ||
| 78 | + @NotNull(message = "是否启用不能为空") | ||
| 79 | + private Boolean enable; | ||
| 80 | + | ||
| 81 | + @Schema(description = "前缀", example = "xx") | ||
| 82 | + private String prefix; | ||
| 83 | + | ||
| 84 | + @Schema(description = "前缀", example = "20250120") | ||
| 85 | + private String infix; | ||
| 86 | + | ||
| 87 | + @Schema(description = "前缀", example = "xx") | ||
| 88 | + private String postfix; | ||
| 89 | + | ||
| 90 | + @Schema(description = "序列长度", example = "5") | ||
| 91 | + @NotNull(message = "序列长度不能为空") | ||
| 92 | + private Integer length; | ||
| 93 | + } | ||
| 94 | + | ||
| 68 | } | 95 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
| @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.bpm.dal.dataobject.definition; | @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.bpm.dal.dataobject.definition; | ||
| 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | 3 | import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; |
| 4 | import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; | 4 | import cn.iocoder.yudao.framework.mybatis.core.type.LongListTypeHandler; |
| 5 | import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler; | 5 | import cn.iocoder.yudao.framework.mybatis.core.type.StringListTypeHandler; |
| 6 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; | ||
| 6 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; | 7 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelFormTypeEnum; |
| 7 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; | 8 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; |
| 8 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; | 9 | import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO; |
| @@ -155,4 +156,10 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { | @@ -155,4 +156,10 @@ public class BpmProcessDefinitionInfoDO extends BaseDO { | ||
| 155 | */ | 156 | */ |
| 156 | private Boolean allowCancelRunningProcess; | 157 | private Boolean allowCancelRunningProcess; |
| 157 | 158 | ||
| 159 | + /** | ||
| 160 | + * 流程 Id 规则 | ||
| 161 | + */ | ||
| 162 | + @TableField(typeHandler = JacksonTypeHandler.class) | ||
| 163 | + private BpmModelMetaInfoVO.ProcessIdRule processIdRule; | ||
| 164 | + | ||
| 158 | } | 165 | } |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/redis/BpmProcessIdRedisDAO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.bpm.dal.redis; | ||
| 2 | + | ||
| 3 | +import cn.hutool.core.date.DateUtil; | ||
| 4 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; | ||
| 5 | +import jakarta.annotation.Resource; | ||
| 6 | +import org.springframework.data.redis.core.StringRedisTemplate; | ||
| 7 | +import org.springframework.stereotype.Repository; | ||
| 8 | + | ||
| 9 | +import java.time.Duration; | ||
| 10 | +import java.time.LocalDateTime; | ||
| 11 | + | ||
| 12 | +/** | ||
| 13 | + * BPM 流程 Id 编码的 Redis DAO | ||
| 14 | + * | ||
| 15 | + * @author Lesan | ||
| 16 | + */ | ||
| 17 | +@Repository | ||
| 18 | +public class BpmProcessIdRedisDAO { | ||
| 19 | + | ||
| 20 | + public static final String BPM_PROCESS_ID_PREFIX = "BPMPID"; | ||
| 21 | + | ||
| 22 | + @Resource | ||
| 23 | + private StringRedisTemplate stringRedisTemplate; | ||
| 24 | + | ||
| 25 | + /** | ||
| 26 | + * 生成序号,使用定义的 processIdRule 规则生成 | ||
| 27 | + * | ||
| 28 | + * @param processIdRule 规则 | ||
| 29 | + * @return 序号 | ||
| 30 | + */ | ||
| 31 | + public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) { | ||
| 32 | + String infix = ""; | ||
| 33 | + switch (processIdRule.getInfix()) { | ||
| 34 | + case "DAY": | ||
| 35 | + infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDD"); | ||
| 36 | + break; | ||
| 37 | + case "HOUR": | ||
| 38 | + infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHH"); | ||
| 39 | + break; | ||
| 40 | + case "MINUTE": | ||
| 41 | + infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmm"); | ||
| 42 | + break; | ||
| 43 | + case "SECOND": | ||
| 44 | + infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmmss"); | ||
| 45 | + break; | ||
| 46 | + } | ||
| 47 | + String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix(); | ||
| 48 | + String key = BPM_PROCESS_ID_PREFIX + noPrefix; | ||
| 49 | + Long no = stringRedisTemplate.opsForValue().increment(key); | ||
| 50 | + stringRedisTemplate.expire(key, Duration.ofDays(1L)); | ||
| 51 | + return noPrefix + String.format("%0" + processIdRule.getLength() + "d", no); | ||
| 52 | + } | ||
| 53 | + | ||
| 54 | +} |
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
| @@ -12,12 +12,14 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | @@ -12,12 +12,14 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 12 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; | 12 | import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; |
| 13 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; | 13 | import cn.iocoder.yudao.framework.common.util.object.PageUtils; |
| 14 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; | 14 | import cn.iocoder.yudao.module.bpm.api.task.dto.BpmProcessInstanceCreateReqDTO; |
| 15 | +import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.BpmModelMetaInfoVO; | ||
| 15 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; | 16 | import cn.iocoder.yudao.module.bpm.controller.admin.definition.vo.model.simple.BpmSimpleModelNodeVO; |
| 16 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*; | 17 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.*; |
| 17 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ActivityNodeTask; | 18 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.instance.BpmApprovalDetailRespVO.ActivityNodeTask; |
| 18 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO; | 19 | import cn.iocoder.yudao.module.bpm.controller.admin.task.vo.task.BpmTaskRespVO; |
| 19 | import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert; | 20 | import cn.iocoder.yudao.module.bpm.convert.task.BpmProcessInstanceConvert; |
| 20 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; | 21 | import cn.iocoder.yudao.module.bpm.dal.dataobject.definition.BpmProcessDefinitionInfoDO; |
| 22 | +import cn.iocoder.yudao.module.bpm.dal.redis.BpmProcessIdRedisDAO; | ||
| 21 | import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants; | 23 | import cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants; |
| 22 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; | 24 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmModelTypeEnum; |
| 23 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; | 25 | import cn.iocoder.yudao.module.bpm.enums.definition.BpmSimpleModelNodeType; |
| @@ -50,6 +52,7 @@ import org.flowable.engine.history.HistoricProcessInstance; | @@ -50,6 +52,7 @@ import org.flowable.engine.history.HistoricProcessInstance; | ||
| 50 | import org.flowable.engine.history.HistoricProcessInstanceQuery; | 52 | import org.flowable.engine.history.HistoricProcessInstanceQuery; |
| 51 | import org.flowable.engine.repository.ProcessDefinition; | 53 | import org.flowable.engine.repository.ProcessDefinition; |
| 52 | import org.flowable.engine.runtime.ProcessInstance; | 54 | import org.flowable.engine.runtime.ProcessInstance; |
| 55 | +import org.flowable.engine.runtime.ProcessInstanceBuilder; | ||
| 53 | import org.flowable.task.api.history.HistoricTaskInstance; | 56 | import org.flowable.task.api.history.HistoricTaskInstance; |
| 54 | import org.springframework.context.annotation.Lazy; | 57 | import org.springframework.context.annotation.Lazy; |
| 55 | import org.springframework.stereotype.Service; | 58 | import org.springframework.stereotype.Service; |
| @@ -109,6 +112,9 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | @@ -109,6 +112,9 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | ||
| 109 | @Resource | 112 | @Resource |
| 110 | private BpmTaskCandidateInvoker taskCandidateInvoker; | 113 | private BpmTaskCandidateInvoker taskCandidateInvoker; |
| 111 | 114 | ||
| 115 | + @Resource | ||
| 116 | + private BpmProcessIdRedisDAO processIdRedisDAO; | ||
| 117 | + | ||
| 112 | // ========== Query 查询相关方法 ========== | 118 | // ========== Query 查询相关方法 ========== |
| 113 | 119 | ||
| 114 | @Override | 120 | @Override |
| @@ -599,12 +605,19 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | @@ -599,12 +605,19 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService | ||
| 599 | if (CollUtil.isNotEmpty(startUserSelectAssignees)) { | 605 | if (CollUtil.isNotEmpty(startUserSelectAssignees)) { |
| 600 | variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); | 606 | variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees); |
| 601 | } | 607 | } |
| 602 | - ProcessInstance instance = runtimeService.createProcessInstanceBuilder() | 608 | + |
| 609 | + // 3. 流程 Id | ||
| 610 | + ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder() | ||
| 603 | .processDefinitionId(definition.getId()) | 611 | .processDefinitionId(definition.getId()) |
| 604 | .businessKey(businessKey) | 612 | .businessKey(businessKey) |
| 605 | .name(definition.getName().trim()) | 613 | .name(definition.getName().trim()) |
| 606 | - .variables(variables) | ||
| 607 | - .start(); | 614 | + .variables(variables); |
| 615 | + BpmModelMetaInfoVO.ProcessIdRule processIdRule = processDefinitionInfo.getProcessIdRule(); | ||
| 616 | + if (processIdRule != null && processIdRule.getEnable()) { | ||
| 617 | + String id = processIdRedisDAO.generate(processIdRule); | ||
| 618 | + processInstanceBuilder.predefineProcessInstanceId(id); | ||
| 619 | + } | ||
| 620 | + ProcessInstance instance = processInstanceBuilder.start(); | ||
| 608 | return instance.getId(); | 621 | return instance.getId(); |
| 609 | } | 622 | } |
| 610 | 623 |