【代码评审】Bpm:更多设置-流程编码
This commit is contained in:
parent
4afdcb4699
commit
f486790def
|
@ -66,10 +66,10 @@ public class BpmModelMetaInfoVO {
|
|||
@Schema(description = "允许撤销审批中的申请", example = "true")
|
||||
private Boolean allowCancelRunningProcess;
|
||||
|
||||
@Schema(description = "流程 Id 规则", example = "{}")
|
||||
@Schema(description = "流程 ID 规则", example = "{}")
|
||||
private ProcessIdRule processIdRule;
|
||||
|
||||
@Schema(description = "流程 Id 规则")
|
||||
@Schema(description = "流程 ID 规则")
|
||||
@Data
|
||||
@Valid
|
||||
public static class ProcessIdRule {
|
||||
|
@ -78,18 +78,19 @@ public class BpmModelMetaInfoVO {
|
|||
@NotNull(message = "是否启用不能为空")
|
||||
private Boolean enable;
|
||||
|
||||
@Schema(description = "前缀", example = "xx")
|
||||
@Schema(description = "前缀", example = "XX")
|
||||
private String prefix;
|
||||
|
||||
@Schema(description = "前缀", example = "20250120")
|
||||
private String infix;
|
||||
@Schema(description = "中缀", example = "20250120")
|
||||
private String infix; // 精确到日、精确到时、精确到分、精确到秒
|
||||
|
||||
@Schema(description = "前缀", example = "xx")
|
||||
@Schema(description = "后缀", example = "YY")
|
||||
private String postfix;
|
||||
|
||||
@Schema(description = "序列长度", example = "5")
|
||||
@NotNull(message = "序列长度不能为空")
|
||||
private Integer length;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -157,7 +157,7 @@ public class BpmProcessDefinitionInfoDO extends BaseDO {
|
|||
private Boolean allowCancelRunningProcess;
|
||||
|
||||
/**
|
||||
* 流程 Id 规则
|
||||
* 流程 ID 规则
|
||||
*/
|
||||
@TableField(typeHandler = JacksonTypeHandler.class)
|
||||
private BpmModelMetaInfoVO.ProcessIdRule processIdRule;
|
||||
|
|
|
@ -17,6 +17,7 @@ import java.time.LocalDateTime;
|
|||
@Repository
|
||||
public class BpmProcessIdRedisDAO {
|
||||
|
||||
// TODO @lesan:要枚举到 rediskeyconstants 哈
|
||||
public static final String BPM_PROCESS_ID_PREFIX = "BPMPID";
|
||||
|
||||
@Resource
|
||||
|
@ -29,6 +30,7 @@ public class BpmProcessIdRedisDAO {
|
|||
* @return 序号
|
||||
*/
|
||||
public String generate(BpmModelMetaInfoVO.ProcessIdRule processIdRule) {
|
||||
// 生成日期前缀
|
||||
String infix = "";
|
||||
switch (processIdRule.getInfix()) {
|
||||
case "DAY":
|
||||
|
@ -44,6 +46,8 @@ public class BpmProcessIdRedisDAO {
|
|||
infix = DateUtil.format(LocalDateTime.now(), "yyyyMMDDHHmmss");
|
||||
break;
|
||||
}
|
||||
|
||||
// 生成序号
|
||||
String noPrefix = processIdRule.getPrefix() + infix + processIdRule.getPostfix();
|
||||
String key = BPM_PROCESS_ID_PREFIX + noPrefix;
|
||||
Long no = stringRedisTemplate.opsForValue().increment(key);
|
||||
|
|
|
@ -606,17 +606,18 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
|
|||
variables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_SELECT_ASSIGNEES, startUserSelectAssignees);
|
||||
}
|
||||
|
||||
// 3. 流程 Id
|
||||
// 3. 创建流程
|
||||
ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder()
|
||||
.processDefinitionId(definition.getId())
|
||||
.businessKey(businessKey)
|
||||
.name(definition.getName().trim())
|
||||
.variables(variables);
|
||||
// 3.1 创建流程 ID
|
||||
BpmModelMetaInfoVO.ProcessIdRule processIdRule = processDefinitionInfo.getProcessIdRule();
|
||||
if (processIdRule != null && processIdRule.getEnable()) {
|
||||
String id = processIdRedisDAO.generate(processIdRule);
|
||||
processInstanceBuilder.predefineProcessInstanceId(id);
|
||||
if (processIdRule != null && Boolean.TRUE.equals(processIdRule.getEnable())) {
|
||||
processInstanceBuilder.predefineProcessInstanceId(processIdRedisDAO.generate(processIdRule));
|
||||
}
|
||||
// 3.2 发起流程实例
|
||||
ProcessInstance instance = processInstanceBuilder.start();
|
||||
return instance.getId();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue