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