|
|
@@ -153,126 +153,23 @@ public class BpmProcInstServiceImpl implements BpmProcInstService {
|
|
|
// 在流程发起之前发布事件。 改异步
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "BpmStartEventPrev");
|
|
|
AppUtil.publishEvent(getBpmStartEvent(instance,baseActionCmd,AopType.PREV));//TODO 性能点
|
|
|
- new Thread(() ->{
|
|
|
- try {
|
|
|
- // 设置流程变量。
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "addVariable");
|
|
|
- baseActionCmd.addVariable(BpmConstants.BUSINESS_KEY, finalInstance.getBizKey());
|
|
|
- baseActionCmd.addVariable(BpmConstants.SUBJECT, finalInstance.getSubject());
|
|
|
- baseActionCmd.addVariable(BpmConstants.PROCESS_INST_ID, finalInstance.getId());
|
|
|
- baseActionCmd.addVariable(BpmConstants.PROCESS_DEF_ID, finalInstance.getProcDefId());
|
|
|
- baseActionCmd.addVariable(BpmConstants.BPM_FLOW_KEY, finalInstance.getProcDefKey());
|
|
|
-
|
|
|
- String bpmnInstId = "";
|
|
|
- String jumpType = baseActionCmd.getJumpType();
|
|
|
- if (JumpType.COMMON.getKey().equalsIgnoreCase(jumpType)) {
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "natProInstService.startProcInst.0");
|
|
|
- // 启动流程实例
|
|
|
- bpmnInstId = natProInstService.startProcInst(finalInstance.getBpmnDefId(), finalInstance.getBizKey(),
|
|
|
- baseActionCmd.getVariables(), curUser);//TODO 性能点
|
|
|
- } else {
|
|
|
- //是否指定目标节点
|
|
|
- String destination = baseActionCmd.getDestination();
|
|
|
- boolean isDestEmpty = StringUtil.isBlank(destination);
|
|
|
-
|
|
|
- if (isDestEmpty) {
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "natProInstService.startProcInst.1");
|
|
|
- // 启动流程实例
|
|
|
- bpmnInstId = natProInstService.startProcInst(finalInstance.getBpmnDefId(), finalInstance.getBizKey(),
|
|
|
- baseActionCmd.getVariables(), curUser);//TODO 性能点
|
|
|
- } else {
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "natProInstService.startProcInst.2");
|
|
|
- bpmnInstId = natProInstService.startProcInst(finalInstance.getBpmnDefId(), finalInstance.getBizKey(),
|
|
|
- baseActionCmd.getVariables(), curUser, destination);//TODO 性能点
|
|
|
- }
|
|
|
- }
|
|
|
- finalInstance.setBpmnInstId(bpmnInstId);
|
|
|
-
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "BpmStartEventPost");
|
|
|
- // 在流程发起之后发布事件
|
|
|
- AppUtil.publishEvent(getBpmStartEvent(finalInstance, baseActionCmd, AopType.POST));
|
|
|
- // 是否从草稿启动。
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "bpmInstSave");
|
|
|
- BpmInst bpmInst = bpmInstRepository.newInstance(finalInstance);//TODO 性能点,频繁创建对象的损耗
|
|
|
- if (isAdd) {
|
|
|
- bpmInst.create();
|
|
|
- } else {
|
|
|
- bpmInst.update();
|
|
|
- }
|
|
|
- // 处理任务跳过.
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "handlerSkipTask");
|
|
|
- handlerSkipTask(finalInstance, curUser, step, stepId);
|
|
|
- }catch (Exception e){
|
|
|
- throw e;
|
|
|
- }finally {
|
|
|
- StopWatchUtil.stopAndPrintLocal(stepId, step);
|
|
|
- }
|
|
|
- }).start();
|
|
|
- } catch (Exception e) {
|
|
|
- throw e;
|
|
|
- }
|
|
|
-
|
|
|
- return instance;
|
|
|
- }
|
|
|
- /*自定义,单线程开启流程*/
|
|
|
- @Override
|
|
|
- public IBpmProcInst startProcInst(ProcInstCmd procInstCmd,String subject,String userId,String userName) {
|
|
|
- if(BeanUtils.isEmpty(procInstCmd)){
|
|
|
- throw new RuntimeException("流程实例命令对象为空!");
|
|
|
- }
|
|
|
-
|
|
|
- String step = "startProcInst";
|
|
|
- String stepId = UniqueIdUtil.getId();
|
|
|
- // 主键从cmd中获取
|
|
|
- BpmInstPo instance = null;
|
|
|
- try {
|
|
|
- StopWatchUtil.initAndStartLocal(stepId, Level.DEBUG, step, "getBpmInst");
|
|
|
- instance = getBpmInst(procInstCmd, false);//TODO 性能点
|
|
|
-
|
|
|
- /*流程标题参数*/
|
|
|
- if(StringUtil.isNotEmpty(subject)) {
|
|
|
- instance.setSubject(subject); //设置标题
|
|
|
- }else{
|
|
|
- instance.setSubject(instance.getSubject());
|
|
|
- }
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "baseActionCmd");
|
|
|
- String curUser = StringUtil.isNotEmpty(userId) ? userId : procInstCmd.getCurUser();
|
|
|
- String curUserName = StringUtil.isNotEmpty(userName) ? userName : procInstCmd.getCurUserName();
|
|
|
-
|
|
|
- BaseActionCmd baseActionCmd = (BaseActionCmd) procInstCmd;
|
|
|
- // 设置流程实例
|
|
|
- boolean isAdd = StringUtil.isEmpty(procInstCmd.getInstId());
|
|
|
- baseActionCmd.setInstId(instance.getId());
|
|
|
- baseActionCmd.addTransitVars(BpmConstants.PROCESS_INST, instance);
|
|
|
- baseActionCmd.setCurUser(curUser);
|
|
|
- baseActionCmd.setTenantId(procInstCmd.getTenantId());
|
|
|
- baseActionCmd.setCurUserName(curUserName);
|
|
|
- baseActionCmd.setFormOptions(procInstCmd.getFormOptions());
|
|
|
- baseActionCmd.setVersion(procInstCmd.getVersion());
|
|
|
-
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "setActionCmd");
|
|
|
- BpmnContextUtil.setActionCmd(baseActionCmd);
|
|
|
- // 在流程发起之前发布事件。
|
|
|
- StopWatchUtil.stopAndStartNewLocal(stepId, step, "BpmStartEventPrev");
|
|
|
- AppUtil.publishEvent(getBpmStartEvent(instance,baseActionCmd,AopType.PREV));//TODO 性能点
|
|
|
|
|
|
// 设置流程变量。
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "addVariable");
|
|
|
- baseActionCmd.addVariable(BpmConstants.BUSINESS_KEY, instance.getBizKey());
|
|
|
- baseActionCmd.addVariable(BpmConstants.SUBJECT, instance.getSubject());
|
|
|
- baseActionCmd.addVariable(BpmConstants.PROCESS_INST_ID, instance.getId());
|
|
|
- baseActionCmd.addVariable(BpmConstants.PROCESS_DEF_ID, instance.getProcDefId());
|
|
|
- baseActionCmd.addVariable(BpmConstants.BPM_FLOW_KEY, instance.getProcDefKey());
|
|
|
+ baseActionCmd.addVariable(BpmConstants.BUSINESS_KEY, finalInstance.getBizKey());
|
|
|
+ baseActionCmd.addVariable(BpmConstants.SUBJECT, finalInstance.getSubject());
|
|
|
+ baseActionCmd.addVariable(BpmConstants.PROCESS_INST_ID, finalInstance.getId());
|
|
|
+ baseActionCmd.addVariable(BpmConstants.PROCESS_DEF_ID, finalInstance.getProcDefId());
|
|
|
+ baseActionCmd.addVariable(BpmConstants.BPM_FLOW_KEY, finalInstance.getProcDefKey());
|
|
|
|
|
|
String bpmnInstId = "";
|
|
|
String jumpType = baseActionCmd.getJumpType();
|
|
|
- if(JumpType.COMMON.getKey().equalsIgnoreCase(jumpType)) {
|
|
|
+ if (JumpType.COMMON.getKey().equalsIgnoreCase(jumpType)) {
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "natProInstService.startProcInst.0");
|
|
|
// 启动流程实例
|
|
|
- bpmnInstId = natProInstService.startProcInst(instance.getBpmnDefId(), instance.getBizKey(),
|
|
|
+ bpmnInstId = natProInstService.startProcInst(finalInstance.getBpmnDefId(), finalInstance.getBizKey(),
|
|
|
baseActionCmd.getVariables(), curUser);//TODO 性能点
|
|
|
- }
|
|
|
- else {
|
|
|
+ } else {
|
|
|
//是否指定目标节点
|
|
|
String destination = baseActionCmd.getDestination();
|
|
|
boolean isDestEmpty = StringUtil.isBlank(destination);
|
|
|
@@ -280,42 +177,52 @@ public class BpmProcInstServiceImpl implements BpmProcInstService {
|
|
|
if (isDestEmpty) {
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "natProInstService.startProcInst.1");
|
|
|
// 启动流程实例
|
|
|
- bpmnInstId = natProInstService.startProcInst(instance.getBpmnDefId(), instance.getBizKey(),
|
|
|
+ bpmnInstId = natProInstService.startProcInst(finalInstance.getBpmnDefId(), finalInstance.getBizKey(),
|
|
|
baseActionCmd.getVariables(), curUser);//TODO 性能点
|
|
|
} else {
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "natProInstService.startProcInst.2");
|
|
|
- bpmnInstId = natProInstService.startProcInst(instance.getBpmnDefId(), instance.getBizKey(),
|
|
|
+ bpmnInstId = natProInstService.startProcInst(finalInstance.getBpmnDefId(), finalInstance.getBizKey(),
|
|
|
baseActionCmd.getVariables(), curUser, destination);//TODO 性能点
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
- instance.setBpmnInstId(bpmnInstId);
|
|
|
+ finalInstance.setBpmnInstId(bpmnInstId);
|
|
|
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "BpmStartEventPost");
|
|
|
// 在流程发起之后发布事件
|
|
|
- AppUtil.publishEvent(getBpmStartEvent(instance, baseActionCmd, AopType.POST));
|
|
|
-
|
|
|
+ AppUtil.publishEvent(getBpmStartEvent(finalInstance, baseActionCmd, AopType.POST));
|
|
|
// 是否从草稿启动。
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "bpmInstSave");
|
|
|
- BpmInst bpmInst = bpmInstRepository.newInstance(instance);//TODO 性能点,频繁创建对象的损耗
|
|
|
+ BpmInst bpmInst = bpmInstRepository.newInstance(finalInstance);//TODO 性能点,频繁创建对象的损耗
|
|
|
if (isAdd) {
|
|
|
bpmInst.create();
|
|
|
} else {
|
|
|
bpmInst.update();
|
|
|
}
|
|
|
-
|
|
|
// 处理任务跳过.
|
|
|
StopWatchUtil.stopAndStartNewLocal(stepId, step, "handlerSkipTask");
|
|
|
- this.handlerSkipTask(instance, curUser, step, stepId);
|
|
|
+ handlerSkipTask(finalInstance, curUser, step, stepId);
|
|
|
+
|
|
|
} catch (Exception e) {
|
|
|
throw e;
|
|
|
- }
|
|
|
- finally {
|
|
|
+ } finally {
|
|
|
StopWatchUtil.stopAndPrintLocal(stepId, step);
|
|
|
}
|
|
|
-
|
|
|
return instance;
|
|
|
}
|
|
|
+ /*自定义,单线程开启流程*/
|
|
|
+ @Override
|
|
|
+ public IBpmProcInst startProcInst(ProcInstCmd procInstCmd,String subject,String userId,String userName) {
|
|
|
+ if(BeanUtils.isEmpty(procInstCmd)){
|
|
|
+ throw new RuntimeException("流程实例命令对象为空!");
|
|
|
+ }
|
|
|
+ if(StringUtil.isNotEmpty(userId)){
|
|
|
+ procInstCmd.setCurUser(userId);
|
|
|
+ }
|
|
|
+ if(StringUtil.isNotEmpty(userName)){
|
|
|
+ procInstCmd.setCurUserName(userName);
|
|
|
+ }
|
|
|
+ return startProcInst(procInstCmd);
|
|
|
+ }
|
|
|
public String getSysYear(){
|
|
|
SimpleDateFormat sdf = new SimpleDateFormat("yyyy");
|
|
|
Date data = new Date();
|