Commit f486790defc75e8afd7b9e852d4e7fb210b3217f

Authored by YunaiV
1 parent 4afdcb46

【代码评审】Bpm:更多设置-流程编码

yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/controller/admin/definition/vo/model/BpmModelMetaInfoVO.java
... ... @@ -66,10 +66,10 @@ public class BpmModelMetaInfoVO {
66 66 @Schema(description = "允许撤销审批中的申请", example = "true")
67 67 private Boolean allowCancelRunningProcess;
68 68  
69   - @Schema(description = "流程 Id 规则", example = "{}")
  69 + @Schema(description = "流程 ID 规则", example = "{}")
70 70 private ProcessIdRule processIdRule;
71 71  
72   - @Schema(description = "流程 Id 规则")
  72 + @Schema(description = "流程 ID 规则")
73 73 @Data
74 74 @Valid
75 75 public static class ProcessIdRule {
... ... @@ -78,18 +78,19 @@ public class BpmModelMetaInfoVO {
78 78 @NotNull(message = "是否启用不能为空")
79 79 private Boolean enable;
80 80  
81   - @Schema(description = "前缀", example = "xx")
  81 + @Schema(description = "前缀", example = "XX")
82 82 private String prefix;
83 83  
84   - @Schema(description = "前缀", example = "20250120")
85   - private String infix;
  84 + @Schema(description = "中缀", example = "20250120")
  85 + private String infix; // 精确到日、精确到时、精确到分、精确到秒
86 86  
87   - @Schema(description = "前缀", example = "xx")
  87 + @Schema(description = "后缀", example = "YY")
88 88 private String postfix;
89 89  
90 90 @Schema(description = "序列长度", example = "5")
91 91 @NotNull(message = "序列长度不能为空")
92 92 private Integer length;
  93 +
93 94 }
94 95  
95 96 }
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/dataobject/definition/BpmProcessDefinitionInfoDO.java
... ... @@ -157,7 +157,7 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
157 157 private Boolean allowCancelRunningProcess;
158 158  
159 159 /**
160   - * 流程 Id 规则
  160 + * 流程 ID 规则
161 161 */
162 162 @TableField(typeHandler = JacksonTypeHandler.class)
163 163 private BpmModelMetaInfoVO.ProcessIdRule processIdRule;
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/dal/redis/BpmProcessIdRedisDAO.java
... ... @@ -17,6 +17,7 @@ import java.time.LocalDateTime;
17 17 @Repository
18 18 public class BpmProcessIdRedisDAO {
19 19  
  20 + // TODO @lesan:要枚举到 rediskeyconstants 哈
20 21 public static final String BPM_PROCESS_ID_PREFIX = "BPMPID";
21 22  
22 23 @Resource
... ... @@ -29,6 +30,7 @@ public class BpmProcessIdRedisDAO {
29 30 * @return 序号
30 31 */
31 32 public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) {
  33 + // 生成日期前缀
32 34 String infix = "";
33 35 switch (processIdRule.getInfix()) {
34 36 case "DAY":
... ... @@ -44,6 +46,8 @@ public class BpmProcessIdRedisDAO {
44 46 infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmmss");
45 47 break;
46 48 }
  49 +
  50 + // 生成序号
47 51 String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix();
48 52 String key = BPM_PROCESS_ID_PREFIX + noPrefix;
49 53 Long no = stringRedisTemplate.opsForValue().increment(key);
... ...
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/service/task/BpmProcessInstanceServiceImpl.java
... ... @@ -606,17 +606,18 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
606 606 variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees);
607 607 }
608 608  
609   - // 3. 流程 Id
  609 + // 3. 创建流程
610 610 ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder()
611 611 .processDefinitionId(definition.getId())
612 612 .businessKey(businessKey)
613 613 .name(definition.getName().trim())
614 614 .variables(variables);
  615 + // 3.1 创建流程 ID
615 616 BpmModelMetaInfoVO.ProcessIdRule processIdRule = processDefinitionInfo.getProcessIdRule();
616   - if (processIdRule != null && processIdRule.getEnable()) {
617   - String id = processIdRedisDAO.generate(processIdRule);
618   - processInstanceBuilder.predefineProcessInstanceId(id);
  617 + if (processIdRule != null && Boolean.TRUE.equals(processIdRule.getEnable())) {
  618 + processInstanceBuilder.predefineProcessInstanceId(processIdRedisDAO.generate(processIdRule));
619 619 }
  620 + // 3.2 发起流程实例
620 621 ProcessInstance instance = processInstanceBuilder.start();
621 622 return instance.getId();
622 623 }
... ...