提交 059355ae 编写于 作者: zhouweidong's avatar zhouweidong

流程跳转与流程重启相关逻辑

上级 480ca49a
package cn.ibizlab.core.extensions.service; package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.workflow.domain.WFProcessInstance;
import cn.ibizlab.core.workflow.extensions.service.WFCoreService;
import cn.ibizlab.core.workflow.filter.WFProcessInstanceSearchContext;
import cn.ibizlab.core.workflow.service.impl.WFProcessInstanceServiceImpl; import cn.ibizlab.core.workflow.service.impl.WFProcessInstanceServiceImpl;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import cn.ibizlab.core.workflow.domain.WFProcessInstance; import org.flowable.engine.RuntimeService;
import org.flowable.ui.common.service.exception.BadRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.context.annotation.Primary; import org.springframework.util.ObjectUtils;
import java.util.*; import org.springframework.util.StringUtils;
import java.util.LinkedHashSet;
import java.util.Set;
/** /**
* 实体[流程实例] 自定义服务对象 * 实体[流程实例] 自定义服务对象
...@@ -16,6 +28,11 @@ import java.util.*; ...@@ -16,6 +28,11 @@ import java.util.*;
@Service("WFProcessInstanceExService") @Service("WFProcessInstanceExService")
public class WFProcessInstanceExService extends WFProcessInstanceServiceImpl { public class WFProcessInstanceExService extends WFProcessInstanceServiceImpl {
@Autowired
WFCoreService wfCoreService;
@Autowired
private RuntimeService runtimeService;
/** /**
* [Jump:流程跳转] 行为扩展 * [Jump:流程跳转] 行为扩展
...@@ -25,7 +42,26 @@ public class WFProcessInstanceExService extends WFProcessInstanceServiceImpl { ...@@ -25,7 +42,26 @@ public class WFProcessInstanceExService extends WFProcessInstanceServiceImpl {
@Override @Override
@Transactional @Transactional
public WFProcessInstance jump(WFProcessInstance et) { public WFProcessInstance jump(WFProcessInstance et) {
return super.jump(et);
Object users = et.get("wfusers") ;
if(ObjectUtils.isEmpty(users)){
throw new BadRequestException("未传入流程步骤用户");
}
//参数格式转换
Set <String> userSets = new LinkedHashSet();
JSONArray.parseArray(users.toString()).forEach(item -> {
JSONObject obj = (JSONObject) item;
Object userId = obj.get("srfkey");
if(!ObjectUtils.isEmpty(userId)){
userSets.add(userId.toString());
}
});
et.set("wfusers",String.join(",",userSets));
wfCoreService.jump(et);
return et;
} }
/** /**
* [Restart:重启流程] 行为扩展 * [Restart:重启流程] 行为扩展
...@@ -35,7 +71,41 @@ public class WFProcessInstanceExService extends WFProcessInstanceServiceImpl { ...@@ -35,7 +71,41 @@ public class WFProcessInstanceExService extends WFProcessInstanceServiceImpl {
@Override @Override
@Transactional @Transactional
public WFProcessInstance restart(WFProcessInstance et) { public WFProcessInstance restart(WFProcessInstance et) {
return super.restart(et);
String strProcessInstanceBusinessKey = et.getBusinesskey();
if(StringUtils.isEmpty(strProcessInstanceBusinessKey)){
throw new BadRequestException("未传入业务标识");
}
String strSystemId = null;
String strEntityId = null;
String strBusinessKey = null;
if(strProcessInstanceBusinessKey.contains(":")){
String [] arrays = strProcessInstanceBusinessKey.split(":");
if(arrays.length == 3){
strSystemId = arrays[0];
strEntityId = arrays[1];
strBusinessKey = arrays[2];
if(strBusinessKey.indexOf(":k-")>0)
strBusinessKey = strBusinessKey.split(":k-")[1];
}
}
if(StringUtils.isEmpty(strSystemId) || StringUtils.isEmpty(strEntityId) || StringUtils.isEmpty(strBusinessKey)){
throw new BadRequestException("未传入流程参数失败");
}
wfCoreService.restart(strSystemId,strEntityId,strBusinessKey,et);
return et;
} }
@Override
public Page<WFProcessInstance> searchActiveProcessInstance(WFProcessInstanceSearchContext context) {
return wfCoreService.searchActiveInstance(context);
}
} }
package cn.ibizlab.core.extensions.service;
import cn.ibizlab.core.workflow.domain.WFProcessNode;
import cn.ibizlab.core.workflow.extensions.service.WFModelService;
import cn.ibizlab.core.workflow.filter.WFProcessNodeSearchContext;
import cn.ibizlab.core.workflow.service.impl.WFProcessNodeServiceImpl;
import org.flowable.bpmn.model.UserTask;
import org.flowable.ui.common.service.exception.BadRequestException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
@Primary
@Service("WFProcessNodeExService")
public class WFProcessNodeExService extends WFProcessNodeServiceImpl {
@Autowired
WFModelService modelService;
@Override
public Page<WFProcessNode> searchDefault(WFProcessNodeSearchContext context) {
String processDefinitionId = context.getN_definitionid_eq();
if(StringUtils.isEmpty(processDefinitionId)){
throw new BadRequestException("为传入流程定义标识");
}
List<WFProcessNode> processNodes = new ArrayList<>();
LinkedHashMap<String, UserTask> userTasks = modelService.getModelStepById(processDefinitionId);
if(!ObjectUtils.isEmpty(userTasks)){
for(Map.Entry<String,UserTask> entry : userTasks.entrySet()){
String userTaskId = entry.getKey();
UserTask userTask = entry.getValue();
WFProcessNode node = new WFProcessNode();
node.setUsertaskid(userTaskId);
node.setUsertaskname(userTask.getName());
node.setProcessdefinitionkey(processDefinitionId);
// node.setProcessdefinitionname(instance.getProcessdefinitionname());
processNodes.add(node);
}
}
return new PageImpl<WFProcessNode>(processNodes,context.getPageable(),processNodes.size());
}
}
...@@ -2,6 +2,7 @@ package cn.ibizlab.core.workflow.extensions.service; ...@@ -2,6 +2,7 @@ package cn.ibizlab.core.workflow.extensions.service;
import cn.ibizlab.core.workflow.domain.*; import cn.ibizlab.core.workflow.domain.*;
import cn.ibizlab.core.workflow.extensions.domain.FlowUser; import cn.ibizlab.core.workflow.extensions.domain.FlowUser;
import cn.ibizlab.core.workflow.filter.WFProcessInstanceSearchContext;
import cn.ibizlab.core.workflow.filter.WFTaskSearchContext; import cn.ibizlab.core.workflow.filter.WFTaskSearchContext;
import cn.ibizlab.core.workflow.mapper.WFCoreMapper; import cn.ibizlab.core.workflow.mapper.WFCoreMapper;
import cn.ibizlab.core.workflow.service.IWFGroupService; import cn.ibizlab.core.workflow.service.IWFGroupService;
...@@ -17,6 +18,7 @@ import cn.ibizlab.util.security.AuthTokenUtil; ...@@ -17,6 +18,7 @@ import cn.ibizlab.util.security.AuthTokenUtil;
import cn.ibizlab.util.security.AuthenticationUser; import cn.ibizlab.util.security.AuthenticationUser;
import cn.ibizlab.util.service.RemoteService; import cn.ibizlab.util.service.RemoteService;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.flowable.bpmn.BpmnAutoLayout; import org.flowable.bpmn.BpmnAutoLayout;
...@@ -363,6 +365,13 @@ public class WFCoreService ...@@ -363,6 +365,13 @@ public class WFCoreService
return new PageImpl<WFTask>(pages.getRecords(), context.getPageable(), pages.getTotal()); return new PageImpl<WFTask>(pages.getRecords(), context.getPageable(), pages.getTotal());
} }
public Page<WFProcessInstance> searchActiveInstance(WFProcessInstanceSearchContext context){
com.baomidou.mybatisplus.extension.plugins.pagination.Page page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page(context.getPageable().getPageNumber()+1,context.getPageable().getPageSize());
com.baomidou.mybatisplus.extension.plugins.pagination.Page<WFProcessInstance> pages = wfCoreMapper.searchActiveInstance(page,context,new QueryWrapper<>());
return new PageImpl<WFProcessInstance>(pages.getRecords(), context.getPageable(), pages.getTotal());
}
/** /**
* 获取所有用户分页存储催办消息 * 获取所有用户分页存储催办消息
* @return * @return
...@@ -2340,17 +2349,22 @@ public class WFCoreService ...@@ -2340,17 +2349,22 @@ public class WFCoreService
*/ */
public boolean jump(WFProcessInstance instance) { public boolean jump(WFProcessInstance instance) {
Object taskDefinitionKey = instance.get("taskdefinitionkey") ; String processDefinitionId = instance.getProcessdefinitionid();
if(ObjectUtils.isEmpty(processDefinitionId)){
throw new BadRequestException("未传入流程定义标识");
}
String taskDefinitionKey = instance.getTaskdefinitionkey() ;
if(ObjectUtils.isEmpty(taskDefinitionKey)){ if(ObjectUtils.isEmpty(taskDefinitionKey)){
throw new BadRequestException("未传入目标步骤"); throw new BadRequestException("未传入目标步骤");
} }
String userIds = getStringValue(instance.get("wfusers")); String userIds = instance.getWfusers();
if(ObjectUtils.isEmpty(userIds)){ if(ObjectUtils.isEmpty(userIds)){
throw new BadRequestException("未传入流程步骤用户"); throw new BadRequestException("未传入流程步骤用户");
} }
UserTask userTask = wfModelService.getModelStepByKey(instance.getProcessdefinitionkey()).get(taskDefinitionKey); UserTask userTask = wfModelService.getModelStepById(processDefinitionId).get(taskDefinitionKey);
if(ObjectUtils.isEmpty(userTask)){ if(ObjectUtils.isEmpty(userTask)){
throw new BadRequestException("未能获取目标步骤信息"); throw new BadRequestException("未能获取目标步骤信息");
} }
...@@ -2358,7 +2372,7 @@ public class WFCoreService ...@@ -2358,7 +2372,7 @@ public class WFCoreService
Map activeData = new LinkedHashMap(); Map activeData = new LinkedHashMap();
activeData.put("srfwfpredefinedusers",userIds); activeData.put("srfwfpredefinedusers",userIds);
// 查询跳转下所有同节点实例,执行跳转 //查询当前实例所有执行器信息
List<String> executionIds = new ArrayList<>(); List<String> executionIds = new ArrayList<>();
runtimeService.createExecutionQuery().parentId(instance.getId()).list().forEach(item ->{ runtimeService.createExecutionQuery().parentId(instance.getId()).list().forEach(item ->{
executionIds.add(item.getId()); executionIds.add(item.getId());
...@@ -2368,10 +2382,12 @@ public class WFCoreService ...@@ -2368,10 +2382,12 @@ public class WFCoreService
throw new BadRequestException("未能获取当前流程实例的执行器信息"); throw new BadRequestException("未能获取当前流程实例的执行器信息");
} }
//执行跳转
runtimeService.createChangeActivityStateBuilder(). runtimeService.createChangeActivityStateBuilder().
processVariable("activedata",activeData). processVariable("activedata",activeData).
moveExecutionsToSingleActivityId(executionIds, userTask.getId()). moveExecutionsToSingleActivityId(executionIds, userTask.getId()).
changeState(); changeState();
return true; return true;
} }
...@@ -2393,14 +2409,26 @@ public class WFCoreService ...@@ -2393,14 +2409,26 @@ public class WFCoreService
} }
Object activeData = null; Object activeData = null;
Object appName = null ;
if(!ObjectUtils.isEmpty(processInstance.getEndTime())) { //流程中 if(ObjectUtils.isEmpty(processInstance.getEndTime())) { //流程中
activeData = runtimeService.getVariable(processInstanceId, "activedata"); Map variables = runtimeService.getVariables(processInstanceId);
if(variables != null){
activeData = variables.get("activedata");
appName = variables.get("appname");
}
} }
else{ else{
HistoricVariableInstance variableInstance = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).variableName("activedata").singleResult(); List<HistoricVariableInstance> variables = historyService.createHistoricVariableInstanceQuery().processInstanceId(processInstanceId).list();
if(variableInstance != null){ if(!ObjectUtils.isEmpty(variables)){
activeData = variableInstance.getValue(); for(HistoricVariableInstance variable : variables){
String variableName = variable.getVariableName();
if("activedata".equals(variableName)){
activeData = variable.getValue();
}
else if("appname".equals(variableName)){
appName = variable.getValue();
}
}
} }
} }
...@@ -2408,7 +2436,6 @@ public class WFCoreService ...@@ -2408,7 +2436,6 @@ public class WFCoreService
throw new BadRequestException("未能获取流程上下文参数"); throw new BadRequestException("未能获取流程上下文参数");
} }
Object appName = ((Map)activeData).get("appname");
if(StringUtils.isEmpty(appName)){ if(StringUtils.isEmpty(appName)){
throw new BadRequestException("未能获取当前实例应用标识"); throw new BadRequestException("未能获取当前实例应用标识");
} }
...@@ -2427,15 +2454,4 @@ public class WFCoreService ...@@ -2427,15 +2454,4 @@ public class WFCoreService
throw new BadRequestException("暂未实现"); throw new BadRequestException("暂未实现");
} }
/**
* 字符串处理
* @param value
* @return
*/
protected String getStringValue(Object value){
if(ObjectUtils.isEmpty(value)){
return null;
}
return value.toString();
}
} }
package cn.ibizlab.core.workflow.mapper; package cn.ibizlab.core.workflow.mapper;
import cn.ibizlab.core.workflow.domain.WFProcessInstance;
import cn.ibizlab.core.workflow.domain.WFProcessNode; import cn.ibizlab.core.workflow.domain.WFProcessNode;
import cn.ibizlab.core.workflow.domain.WFTask; import cn.ibizlab.core.workflow.domain.WFTask;
import cn.ibizlab.core.workflow.filter.WFProcessInstanceSearchContext;
import cn.ibizlab.core.workflow.filter.WFTaskSearchContext; import cn.ibizlab.core.workflow.filter.WFTaskSearchContext;
import com.baomidou.mybatisplus.core.conditions.Wrapper; import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
...@@ -35,4 +37,7 @@ public interface WFCoreMapper { ...@@ -35,4 +37,7 @@ public interface WFCoreMapper {
Page<WFTask> searchDoneTask(IPage page, @Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ; Page<WFTask> searchDoneTask(IPage page, @Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ;
Page<WFTask> searchFinishTask(IPage page, @Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ; Page<WFTask> searchFinishTask(IPage page, @Param("srf") WFTaskSearchContext context, @Param("ew") Wrapper<WFTask> wrapper) ;
Page<WFProcessInstance> searchActiveInstance(IPage page, @Param("srf") WFProcessInstanceSearchContext context, @Param("ew") Wrapper<WFProcessInstance> wrapper) ;
} }
...@@ -323,4 +323,26 @@ ...@@ -323,4 +323,26 @@
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if> <if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select> </select>
<select id="searchActiveInstance" parameterType="cn.ibizlab.core.workflow.filter.WFProcessInstanceSearchContext" resultType="cn.ibizlab.core.workflow.domain.WFProcessInstance">
SELECT * FROM (
SELECT
PROCINST.PROC_INST_ID_ AS id,
PROCINST.BUSINESS_KEY_ AS businessKey,
PROCINST.START_TIME_ AS startTime,
PROCINST.START_USER_ID_ AS startUserId,
PROCDEF.NAME_ AS processDefinitionName,
PROCDEF.KEY_ AS processDefinitionKey,
PROCDEF.ID_ AS processDefinitionId
FROM ACT_HI_PROCINST PROCINST INNER JOIN ACT_RE_PROCDEF PROCDEF
ON PROCINST.PROC_DEF_ID_ = PROCDEF.ID_ WHERE END_TIME_ IS NULL ORDER BY PROCINST.START_TIME_ DESC
) t1
<where><if test="ew!=null and ew.sqlSegment!=null and !ew.emptyOfWhere">${ew.sqlSegment}</if></where>
<if test="ew!=null and ew.sqlSegment!=null and ew.emptyOfWhere">${ew.sqlSegment}</if>
</select>
</mapper> </mapper>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册