Commit f16f2ad3 by 赵剑炜

工作流联调

parent fee7bc8a
......@@ -4,7 +4,7 @@
server:
tomcat:
uri-encoding: UTF-8 #tomcat编码
port: 10032 #tomcat端口
port: 10031 #tomcat端口
spring:
main:
#bea同名类进行注册时,准许覆盖注册
......
artifactId=jyzb-mq-consumer
groupId=com.junmp.jyzb
version=1.0.0
artifactId=jyzb-mq-producer
groupId=com.junmp.jyzb
version=1.0.0
......@@ -5,7 +5,7 @@ package com.junmp.junmpProcess.common;
* @create 2022-10-10 17:40
*/
public interface WorkFlowConstants {
String PROCESS_PREFIX = "Flowable";
String PROCESS_PREFIX = "Process_";
String START_EVENT_ID = "startEventNode";
String END_EVENT_ID = "endEventNode";
String EXPRESSION_CLASS = "exUtils.";
......
......@@ -136,6 +136,11 @@ public class BpmnController {
public ApiRes<Boolean> start(@RequestBody StartProcessInstanceDTO startProcessInstanceDTO) {
return WorkProcessService.start(startProcessInstanceDTO);
}
@ApiOperation("通过流程定义查看详情")
@PostMapping("instanceInfo")
public ApiRes<HandleDataVO> instanceInfo(@RequestBody HandleDataDTO handleDataDTO) {
return WorkProcessService.instanceInfo(handleDataDTO);
}
@ApiOperation("查看我发起的流程")
@PostMapping("applyList")
public ApiRes<PageResult<HistoryProcessInstanceVO>> applyList(@RequestBody ApplyDTO ApplyDTO) {
......@@ -151,6 +156,11 @@ public class BpmnController {
public ResponseResult agree(@RequestBody HandleDataDTO handleDataDTO){
return WorkProcessService.agree(handleDataDTO);
}
@ApiOperation("查看我的已办")
@PostMapping("doneList")
public ApiRes<PageResult<TaskVO>> doneList(@RequestBody TaskDTO taskDTO){
return ApiRes.success(WorkProcessService.doneList(taskDTO));
}
@ApiOperation("撤销按钮")
@PostMapping("revoke")
public ResponseResult revoke(@RequestBody HandleDataDTO handleDataDTO){
......
......@@ -17,6 +17,7 @@ import com.junmp.v2.sys.api.bean.user.vo.QueryUserInfoVo;
import org.flowable.bpmn.model.Process;
import org.flowable.bpmn.model.UserTask;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.DelegateExecution;
import org.flowable.engine.delegate.ExecutionListener;
import com.junmp.junmpProcess.enums.AssigneeTypeEnums;
......@@ -38,12 +39,15 @@ import static com.junmp.junmpProcess.utils.BpmnModelUtils.getChildNode;
@Component
public class CounterSignListener implements ExecutionListener {
@Resource
private TaskService taskService;
@Resource
private RepositoryService repositoryService;
@Resource
private OrgUserMapper orgUserMapper;
@Override
public void notify(DelegateExecution execution) {
String currentActivityId = execution.getCurrentActivityId();
Process mainProcess = repositoryService.getBpmnModel(execution.getProcessDefinitionId()).getMainProcess();
UserTask userTask = (UserTask) mainProcess.getFlowElement(currentActivityId);
String flowJson = mainProcess.getAttributeValue("http://flowable.org/bpmn", "Junmp");
......@@ -65,6 +69,7 @@ public class CounterSignListener implements ExecutionListener {
String Type=group.getApproverType();
if (Type.equals("1"))//指定人员,不处理
{
List<String> assignedUser = group.getApproverIds();
for (String userInfo : assignedUser) {
assigneeList.add(userInfo);
......@@ -136,7 +141,7 @@ public class CounterSignListener implements ExecutionListener {
else if (Type.equals("5"))//上级审批
{
LoginUser StartUser= LoginContext.getContext().getLoginUser();
List<UserListDTO> userList= orgUserMapper.QueryUserParentOrg(StartUser.getUserId().toString());
List<UserListDTO> userList= orgUserMapper.QueryUserWithParentOrg(StartUser.getUserId().toString());
if (userList.size()<=0)//没有上级则本身已是上级
{
......@@ -147,14 +152,18 @@ public class CounterSignListener implements ExecutionListener {
{
for (UserListDTO userId :userList)
{
assigneeList.add(userId.getUserID());
assigneeList.add("1");
// assigneeList.add(userId.getUserID());
}
}
}
if (assigneeList.size()!=0)
{execution.setVariable(variable, assigneeList);}
{
execution.setVariable(variable, assigneeList);
}
} else {
}
......
......@@ -32,6 +32,7 @@ public class GlobalEndListener extends AbstractFlowableEngineEventListener {
//流程结束后工作在这里写
//得到流程定义id
String processDefinitionId = event.getProcessDefinitionId();
//得到流程实例id
String processInstanceId = event.getProcessInstanceId();
/**
......
......@@ -21,6 +21,7 @@ public class ProcessListener implements ExecutionListener {
@Override
public void notify(DelegateExecution execution) {
execution.setVariable(PROCESS_STATUS, BUSINESS_STATUS_4);
execution.setVariable(PROCESS_STATUS, BUSINESS_STATUS_4);
}
}
//package com.junmp.junmpProcess.listener;
//
//import org.flowable.engine.RepositoryService;
//import org.flowable.engine.RuntimeService;
//import org.flowable.engine.TaskService;
//import org.flowable.engine.delegate.TaskListener;
//import org.flowable.task.service.delegate.DelegateTask;
//import com.junmp.junmpProcess.utils.SpringContextHolder;
//import org.springframework.stereotype.Component;
//
//import javax.annotation.Resource;
//
///**
// * @author LoveMyOrange
// * @create 2022-10-15 14:51
// */
//@Component
//public class TaskCreatedListener implements TaskListener {
// @Resource
// private TaskService taskService;
// @Resource
// private RepositoryService repositoryService;
//
// @Override
// public void notify(DelegateTask delegateTask) {
// String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
// if ("root".equalsIgnoreCase(taskDefinitionKey)) {
// taskService.complete(delegateTask.getId());
// } else {
// if ("100000".equals(delegateTask.getAssignee())) {
// Object autoRefuse = delegateTask.getVariable("autoRefuse");
// if (autoRefuse == null) {
// taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "opinion", "审批人为空,自动通过");
// taskService.complete(delegateTask.getId());
// } else {
// taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "opinion", "审批人为空,自动驳回");
// RuntimeService runtimeService = SpringContextHolder.getBean(RuntimeService.class);
// runtimeService.deleteProcessInstance(delegateTask.getProcessInstanceId(), "审批人为空,自动驳回");
// }
// }
// }
// }
//}
package com.junmp.junmpProcess.listener;
import org.flowable.engine.RepositoryService;
import org.flowable.engine.RuntimeService;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.delegate.DelegateTask;
import com.junmp.junmpProcess.utils.SpringContextHolder;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* @author LoveMyOrange
* @create 2022-10-15 14:51
*/
@Component
public class TaskCreatedListener implements TaskListener {
@Resource
private TaskService taskService;
@Resource
private RepositoryService repositoryService;
@Override
public void notify(DelegateTask delegateTask) {
String taskDefinitionKey = delegateTask.getTaskDefinitionKey();
if ("root".equalsIgnoreCase(taskDefinitionKey)) {
taskService.complete(delegateTask.getId());
} else {
if ("100000".equals(delegateTask.getAssignee())) {
Object autoRefuse = delegateTask.getVariable("autoRefuse");
if (autoRefuse == null) {
taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "opinion", "审批人为空,自动通过");
taskService.complete(delegateTask.getId());
} else {
taskService.addComment(delegateTask.getId(), delegateTask.getProcessInstanceId(), "opinion", "审批人为空,自动驳回");
RuntimeService runtimeService = SpringContextHolder.getBean(RuntimeService.class);
runtimeService.deleteProcessInstance(delegateTask.getProcessInstanceId(), "审批人为空,自动驳回");
}
}
}
}
}
......@@ -23,5 +23,5 @@ public interface OrgUserMapper {
*/
public List<UserListDTO> QueryUserByRoleIdAndOrg(String roleId,String orgId);
public List<UserListDTO> QueryUserParentOrg(String userId);
public List<UserListDTO> QueryUserWithParentOrg(String userId);
}
......@@ -101,6 +101,9 @@ public interface WorkProcessService {
*/
ApiRes<Boolean> start(StartProcessInstanceDTO startProcessInstanceDTO);
/**
* 查看我发起的流程
*
......@@ -120,7 +123,7 @@ public interface WorkProcessService {
*
* @return
*/
Result<Page<TaskVO>> doneList(@RequestBody TaskDTO taskDTO);
PageResult<TaskVO> doneList(@RequestBody TaskDTO taskDTO);
/**
* 同意
......@@ -205,7 +208,7 @@ public interface WorkProcessService {
*
* @return
*/
Result<HandleDataVO> instanceInfo(HandleDataDTO HandleDataDTO);
ApiRes<HandleDataVO> instanceInfo(HandleDataDTO HandleDataDTO);
// /**
// * 上传文件
// * @return
......
......@@ -281,7 +281,6 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
if (req.getIsStop() == true){
repositoryService.suspendProcessDefinitionById(req.getProcessDefinitionId(), true, null);
processTemplates.setIsStop(true);
}else {
processTemplates.setIsStop(false);
repositoryService.activateProcessDefinitionById(req.getProcessDefinitionId(), true, null);
......@@ -314,7 +313,7 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
BpmnModel bpmnModel = toBpmn(processJsonNode,formJsonNode,formName,templateId);
Deployment deploy = repositoryService.createDeployment()
.addBpmnModel(templateId+".bpmn20.xml", bpmnModel)
.addBpmnModel(formName+".bpmn20.xml", bpmnModel)
.name(formName)
.category(templateId)
.deploy();
......@@ -416,7 +415,7 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
Deployment deploy = repositoryService.createDeployment()
.addBpmnModel(process.getTemplateId()+".bpmn20.xml", bpmnModel)
.addBpmnModel(formName+".bpmn20.xml", bpmnModel)
.name(formName)
.category(process.getTemplateId())
.deploy();
......@@ -594,11 +593,7 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
userTask.setId(id);
userTask.setName(node.get("name").toString());
// 设置多实例
// userTask.setAssignee("${user}");
MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = new MultiInstanceLoopCharacteristics();
// if (node.getAssignee().getMultiMode().equals("顺序审批")) {
// multiInstanceLoopCharacteristics.setSequential(true);
// }
multiInstanceLoopCharacteristics.setElementVariable("user");
// 完成条件
multiInstanceLoopCharacteristics.setCompletionCondition("${nrOfInstances == nrOfCompletedInstances}");
......@@ -679,15 +674,11 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
processVariables.put(FORM_VAR,formData);
processVariables.put(START_USER_INFO,JSONObject.toJSONString(StartUser));
processVariables.put(PROCESS_STATUS,BUSINESS_STATUS_1);
// processVariables.put("initiator",JSONObject.toJSONString(startUserInfo));
ArrayList<LoginUser> userInfos = CollUtil.newArrayList(StartUser);
Map formValue = JSONObject.parseObject(formData.toJSONString(), new TypeReference<Map>() {
});
processVariables.putAll(formValue);
ProcessInstanceBuilder processInstanceBuilder = runtimeService.createProcessInstanceBuilder();
ProcessDefinition processDefinition = repositoryService.createProcessDefinitionQuery().processDefinitionKey(processInstanceDto.getProcessDefinitionId())
.latestVersion().singleResult();
......@@ -707,12 +698,12 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
.businessStatus(BUSINESS_STATUS_1)
.start();
//手动完成第一个任务
Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
Object ts=new Object();
if(task!=null){
taskService.complete(task.getId());
}
// Task task = taskService.createTaskQuery().processInstanceId(processInstance.getId()).singleResult();
// Object ts=new Object();
// if(task!=null){
// taskService.complete(task.getId());
//
// }
return ApiRes.success(true);
}
catch (Exception e){
......@@ -837,7 +828,7 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
* @return
*/
@Override
public Result<Page<TaskVO>> doneList(TaskDTO taskDTO) {
public PageResult<TaskVO> doneList(TaskDTO taskDTO) {
LoginUser StartUser= LoginContext.getContext().getLoginUser();
List<HistoricTaskInstance> tasks = historyService.createHistoricTaskInstanceQuery()
.taskAssignee(StartUser.getUserId().toString())
......@@ -882,7 +873,9 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
page.setCurrent(taskDTO.getPageNo());
page.setSize(taskDTO.getPageSize());
page.setTotal(count);
return Result.OK(page);
return PageResultFactory.createPageResult(page);
}
......@@ -952,9 +945,9 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
}
}
if (StringUtils.isNotBlank(handleDataDTO.getSignInfo())) {
taskService.addComment(task.getId(), task.getProcessInstanceId(), "sign", handleDataDTO.getSignInfo());
}
// if (StringUtils.isNotBlank(handleDataDTO.getSignInfo())) {
// taskService.addComment(task.getId(), task.getProcessInstanceId(), "sign", handleDataDTO.getSignInfo());
// }
taskService.complete(task.getId());
......@@ -1282,11 +1275,12 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
}
@Override
public Result<HandleDataVO> instanceInfo(HandleDataDTO HandleDataDTO) {
public ApiRes<HandleDataVO> instanceInfo(HandleDataDTO HandleDataDTO) {
String processInstanceId = HandleDataDTO.getProcessInstanceId();
HistoricProcessInstance historicProcessInstance = historyService.createHistoricProcessInstanceQuery().processInstanceId(processInstanceId)
.includeProcessVariables().singleResult();
String processDefinitionKey = historicProcessInstance.getProcessDefinitionKey();
String pro=processDefinitionKey.replace(PROCESS_PREFIX, "");
ProcessTemplates processTemplates = processTemplateService.getById(processDefinitionKey.replace(PROCESS_PREFIX, ""));
// processTemplates.setLogo(processTemplates.getIcon());
processTemplates.setFormId(processTemplates.getTemplateId());
......@@ -1304,40 +1298,40 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
});
SettingsInfo settingsInfo = JSONObject.parseObject(processTemplates.getSettings(), new TypeReference<SettingsInfo>() {
});
Boolean sign = settingsInfo.getSign();
// Boolean sign = settingsInfo.getSign();
ChildNode currentNode = null;
if (StringUtils.isNotBlank(HandleDataDTO.getTaskId())) {
HistoricTaskInstance historicTaskInstance = historyService.createHistoricTaskInstanceQuery().taskId(HandleDataDTO.getTaskId()).singleResult();
currentNode = getChildNode(childNode, historicTaskInstance.getTaskDefinitionKey());
List<FormOperates> formPerms = currentNode.getProps().getFormPerms();
if (CollUtil.isNotEmpty(formPerms)) {
Iterator<FormOperates> iterator = formPerms.iterator();
while (iterator.hasNext()) {
FormOperates next = iterator.next();
if ("H".equals(next.getPerm())) {
iterator.remove();
if (jsonObject != null) {
jsonObject.remove(next.getId());
}
}
}
}
// List<FormOperates> formPerms = currentNode.getProps().getFormPerms();
// if (CollUtil.isNotEmpty(formPerms)) {
// Iterator<FormOperates> iterator = formPerms.iterator();
// while (iterator.hasNext()) {
// FormOperates next = iterator.next();
// if ("H".equals(next.getPerm())) {
// iterator.remove();
// if (jsonObject != null) {
// jsonObject.remove(next.getId());
// }
// }
// }
// }
handleDataVO.setCurrentNode(currentNode);
handleDataVO.setTaskId(HandleDataDTO.getTaskId());
}
if (sign) {
handleDataVO.setSignFlag(true);
}
if (StringUtils.isNotBlank(HandleDataDTO.getTaskId())) {
if (currentNode != null) {
if (currentNode.getProps().getSign()) {
handleDataVO.setSignFlag(true);
} else {
handleDataVO.setSignFlag(false);
}
}
}
// if (sign) {
// handleDataVO.setSignFlag(true);
// }
// if (StringUtils.isNotBlank(HandleDataDTO.getTaskId())) {
// if (currentNode != null) {
// if (currentNode.getProps().getSign()) {
// handleDataVO.setSignFlag(true);
// } else {
// handleDataVO.setSignFlag(false);
// }
// }
// }
List<HistoricActivityInstance> list = historyService.createHistoricActivityInstanceQuery().processInstanceId(historicProcessInstance.getId()).list();
Map<String, List<HistoricActivityInstance>> historicActivityInstanceMap = new HashMap<>();
......@@ -1422,7 +1416,7 @@ public class WorkProcessServiceImpl extends ServiceImpl<ProcessTemplatesMapper,
}
handleDataVO.setProcessTemplates(processTemplates);
handleDataVO.setDetailVOList(deatailMap);
return Result.OK(handleDataVO);
return ApiRes.success(handleDataVO);
}
private void collectUserTaskInfo(List<Comment> processInstanceComments,
......
......@@ -11,6 +11,7 @@ import org.flowable.bpmn.model.*;
import org.flowable.bpmn.model.Process;
import org.flowable.engine.TaskService;
import org.flowable.engine.delegate.ExecutionListener;
import org.flowable.engine.delegate.TaskListener;
import org.flowable.task.service.impl.persistence.entity.TaskEntity;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -62,7 +63,7 @@ public class BpmnConvert {
process.addFlowElement(endEvent);
// 三.递归绘制节点
drawNode("root",process, processNode,formNode, "_start", "_end", null);
drawNode("0",process, processNode,formNode, "_start", "_end", null);
// 四.自动布局
new BpmnAutoLayout(bpmnModel).execute();
// 五.转xml
......@@ -119,8 +120,9 @@ public class BpmnConvert {
* @return Inout
*/
private static Inout drawBzNode(Process process, JsonNode node,JsonNode formJson,String typeNode) {
// String id= "Node_"+UUID.randomUUID();
String id="Node_"+ node.get("id").asText();
// String id= "Node_"+UUID.randomUUID();
String id="root";
//创建发起人结点
UserTask task = new UserTask();
//设置结点ID
......@@ -129,11 +131,23 @@ public class BpmnConvert {
task.setName(node.get("name").asText());
//通过将 ${initiator} 作为指派人的值,可以将用户任务分配给流程的发起人。当流程实例启动时,${initiator} 会被替换为实际的发起人信息。
//需要注意的是,在使用表达式时,需要确保流程引擎的配置中启用了表达式语言(例如使用 Flowable 的默认配置,会启用表达式语言)。
task.setAssignee("${initiator}");
// task.setAssignee("${initiator}");
List<FormProperty> formProperties = formJsonToFormProperty(formJson);
task.setFormProperties(formProperties);
ArrayList<FlowableListener> taskListeners = new ArrayList<>();
FlowableListener taskListener = new FlowableListener();
// 事件类型,
taskListener.setEvent(TaskListener.EVENTNAME_CREATE);
// 监听器类型
taskListener.setImplementationType(IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
// 设置实现了,这里设置监听器的类型是delegateExpression,这样可以在实现类注入Spring bean.
taskListener.setImplementation("${taskCreatedListener}");
taskListeners.add(taskListener);
task.setTaskListeners(taskListeners);
//添加连线
process.addFlowElement(task);
return new Inout(id, id);
}
......@@ -175,11 +189,11 @@ public class BpmnConvert {
multiInstanceLoopCharacteristics.setInputDataItem(userTask.getId()+"assigneeList");
// 迭代集合
multiInstanceLoopCharacteristics.setElementVariable("assigneeName");
//
//
multiInstanceLoopCharacteristics.setSequential(false);
multiInstanceLoopCharacteristics.setCompletionCondition("${nrOfCompletedInstances/nrOfInstances > 0}");
userTask.setAssignee("${assigneeName}");
// 设置多实例属性
// 设置多实例属性
userTask.setLoopCharacteristics(multiInstanceLoopCharacteristics);
process.addFlowElement(userTask);
return new Inout(id, id);
......@@ -197,7 +211,12 @@ public class BpmnConvert {
listener.setEvent(ExecutionListener.EVENTNAME_START);//监听任务启动
listener.setImplementationType(IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
listener.setImplementation("${counterSignListener}");//启动角色分配监听事件
FlowableListener flowableListener = new FlowableListener();
flowableListener.setEvent(ExecutionListener.EVENTNAME_END);
flowableListener.setImplementationType(ImplementationType.IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
flowableListener.setImplementation("${processListener}");
taskListeners.add(listener);
taskListeners.add(flowableListener);
return taskListeners;
}
......
......@@ -200,506 +200,13 @@ public class BpmnModelUtils {
return endEvent;
}
// public static String FlowCreate(String fromId, FlowChildNode flowNode, Process process, BpmnModel bpmnModel, List<SequenceFlow> sequenceFlows, Map<String,ChildNode> childNodeMap) throws InvocationTargetException, IllegalAccessException {
// Integer nodeType = flowNode.getType();
// if (FlowType.CONCURRENTS.isEqual(nodeType)) {
// return createParallelGatewayBuilder(fromId, flowNode,process,bpmnModel,sequenceFlows,childNodeMap);
// } else if (FlowType.CONDITIONS.isEqual(nodeType)) {
// return createExclusiveGatewayBuilder(fromId, flowNode,process,bpmnModel,sequenceFlows,childNodeMap);
// } else if (FlowType.USER_TASK.isEqual(nodeType)) {
// childNodeMap.put(flowNode.getId(),flowNode);
// JSONObject incoming = flowNode.getIncoming();
// incoming.put("incoming", Collections.singletonList(fromId));
// String id = createTask(process,flowNode,sequenceFlows,childNodeMap);
// // 如果当前任务还有后续任务,则遍历创建后续任务
// ChildNode children = flowNode.getChildren();
// if (Objects.nonNull(children) &&StringUtils.isNotBlank(children.getId())) {
// return create(id, children,process,bpmnModel,sequenceFlows,childNodeMap);
// } else {
// return id;
// }
// }
// else if(Type.ROOT.isEqual(nodeType)){
// childNodeMap.put(flowNode.getId(),flowNode);
// JSONObject incoming = flowNode.getIncoming();
// incoming.put("incoming", Collections.singletonList(fromId));
// String id = createTask(process,flowNode,sequenceFlows,childNodeMap);
// // 如果当前任务还有后续任务,则遍历创建后续任务
// ChildNode children = flowNode.getChildren();
// if (Objects.nonNull(children) &&StringUtils.isNotBlank(children.getId())) {
// return create(id, children,process,bpmnModel,sequenceFlows,childNodeMap);
// } else {
// return id;
// }
// }
// else if(Type.DELAY.isEqual(nodeType)){
// throw new WorkFlowException("还不想写这个功能");
//// childNodeMap.put(flowNode.getId(),flowNode);
//// JSONObject incoming = flowNode.getIncoming();
//// incoming.put("incoming", Collections.singletonList(fromId));
//// String id = createTask(process,flowNode,sequenceFlows,childNodeMap);
//// // 如果当前任务还有后续任务,则遍历创建后续任务
//// ChildNode children = flowNode.getChildren();
//// if (Objects.nonNull(children) &&StringUtils.isNotBlank(children.getId())) {
//// return create(id, children,process,bpmnModel,sequenceFlows,childNodeMap);
//// } else {
//// return id;
//// }
// }
// else if(Type.TRIGGER.isEqual(nodeType)){
// throw new WorkFlowException("还不想写这个功能");
// }
// else if(Type.CC.isEqual(nodeType)){
// throw new WorkFlowException("代码呗回滚了 丢了,暂时先不做");
//// childNodeMap.put(flowNode.getId(),flowNode);
//// JSONObject incoming = flowNode.getIncoming();
//// incoming.put("incoming", Collections.singletonList(fromId));
//// String id = createServiceTask(process,flowNode,sequenceFlows,childNodeMap);
//// // 如果当前任务还有后续任务,则遍历创建后续任务
//// ChildNode children = flowNode.getChildren();
//// if (Objects.nonNull(children) &&StringUtils.isNotBlank(children.getId())) {
//// return create(id, children,process,bpmnModel,sequenceFlows,childNodeMap);
//// } else {
//// return id;
//// }
// }
// else {
// throw new RuntimeException("未知节点类型: nodeType=" + nodeType);
// }
// }
public static String create(String fromId, ChildNode flowNode, Process process, BpmnModel bpmnModel, List<SequenceFlow> sequenceFlows, Map<String, ChildNode> childNodeMap) throws InvocationTargetException, IllegalAccessException {
String nodeType = flowNode.getType();
if (Type.CONCURRENTS.isEqual(nodeType)) {
return createParallelGatewayBuilder(fromId, flowNode, process, bpmnModel, sequenceFlows, childNodeMap);
} else if (Type.CONDITIONS.isEqual(nodeType)) {
return createExclusiveGatewayBuilder(fromId, flowNode, process, bpmnModel, sequenceFlows, childNodeMap);
} else if (Type.USER_TASK.isEqual(nodeType)) {
childNodeMap.put(flowNode.getId(), flowNode);
JSONObject incoming = flowNode.getIncoming();
incoming.put("incoming", Collections.singletonList(fromId));
String id = createTask(process, flowNode, sequenceFlows, childNodeMap);
// 如果当前任务还有后续任务,则遍历创建后续任务
ChildNode children = flowNode.getChildNode();
if (Objects.nonNull(children) && StringUtils.isNotBlank(children.getId())) {
return create(id, children, process, bpmnModel, sequenceFlows, childNodeMap);
} else {
return id;
}
} else if (Type.ROOT.isEqual(nodeType)) {
childNodeMap.put(flowNode.getId(), flowNode);
JSONObject incoming = flowNode.getIncoming();
incoming.put("incoming", Collections.singletonList(fromId));
String id = createTask(process, flowNode, sequenceFlows, childNodeMap);
// 如果当前任务还有后续任务,则遍历创建后续任务
ChildNode children = flowNode.getChildNode();
if (Objects.nonNull(children) && StringUtils.isNotBlank(children.getId())) {
return create(id, children, process, bpmnModel, sequenceFlows, childNodeMap);
} else {
return id;
}
} else if (Type.DELAY.isEqual(nodeType)) {
throw new WorkFlowException("还不想写这个功能");
// childNodeMap.put(flowNode.getId(),flowNode);
// JSONObject incoming = flowNode.getIncoming();
// incoming.put("incoming", Collections.singletonList(fromId));
// String id = createTask(process,flowNode,sequenceFlows,childNodeMap);
// // 如果当前任务还有后续任务,则遍历创建后续任务
// ChildNode children = flowNode.getChildren();
// if (Objects.nonNull(children) &&StringUtils.isNotBlank(children.getId())) {
// return create(id, children,process,bpmnModel,sequenceFlows,childNodeMap);
// } else {
// return id;
// }
} else if (Type.TRIGGER.isEqual(nodeType)) {
throw new WorkFlowException("还不想写这个功能");
} else if (Type.CC.isEqual(nodeType)) {
throw new WorkFlowException("代码呗回滚了 丢了,暂时先不做");
// childNodeMap.put(flowNode.getId(),flowNode);
// JSONObject incoming = flowNode.getIncoming();
// incoming.put("incoming", Collections.singletonList(fromId));
// String id = createServiceTask(process,flowNode,sequenceFlows,childNodeMap);
// // 如果当前任务还有后续任务,则遍历创建后续任务
// ChildNode children = flowNode.getChildren();
// if (Objects.nonNull(children) &&StringUtils.isNotBlank(children.getId())) {
// return create(id, children,process,bpmnModel,sequenceFlows,childNodeMap);
// } else {
// return id;
// }
} else {
throw new RuntimeException("未知节点类型: nodeType=" + nodeType);
}
}
private static String createExclusiveGatewayBuilder(String formId, ChildNode flowNode, Process process, BpmnModel bpmnModel, List<SequenceFlow> sequenceFlows, Map<String, ChildNode> childNodeMap) throws InvocationTargetException, IllegalAccessException {
childNodeMap.put(flowNode.getId(), flowNode);
String name = flowNode.getName();
String exclusiveGatewayId = flowNode.getId();
ExclusiveGateway exclusiveGateway = new ExclusiveGateway();
exclusiveGateway.setId(exclusiveGatewayId);
exclusiveGateway.setName(name);
process.addFlowElement(exclusiveGateway);
process.addFlowElement(connect(formId, exclusiveGatewayId, sequenceFlows, childNodeMap, process));
if (Objects.isNull(flowNode.getConditionNodes()) && Objects.isNull(flowNode.getChildNode())) {
return exclusiveGatewayId;
}
List<ChildNode> flowNodes = flowNode.getConditionNodes();
List<String> incoming = Lists.newArrayListWithCapacity(flowNodes.size());
List<JSONObject> conditions = Lists.newCopyOnWriteArrayList();
for (ChildNode element : flowNodes) {
Boolean typeElse = element.getTypeElse();
if (Boolean.TRUE.equals(typeElse)) {
exclusiveGateway.setDefaultFlow(element.getId());
}
childNodeMap.put(element.getId(), element);
ChildNode childNode = element.getChildNode();
String nodeName = element.getName();
Properties props = element.getProps();
String expression = props.getExpression();
if (Objects.isNull(childNode) || StringUtils.isBlank(childNode.getId())) {
incoming.add(exclusiveGatewayId);
JSONObject condition = new JSONObject();
condition.fluentPut("nodeName", nodeName)
.fluentPut("expression", expression)
.fluentPut("groups", props.getGroups())
.fluentPut("groupsType", props.getGroupsType()
)
.fluentPut("elseSequenceFlowId", element.getId());
conditions.add(condition);
continue;
}
// 只生成一个任务,同时设置当前任务的条件
JSONObject incomingObj = childNode.getIncoming();
incomingObj.put("incoming", Collections.singletonList(exclusiveGatewayId));
String identifier = create(exclusiveGatewayId, childNode, process, bpmnModel, sequenceFlows, childNodeMap);
List<SequenceFlow> flows = sequenceFlows.stream().filter(flow -> StringUtils.equals(exclusiveGatewayId, flow.getSourceRef()))
.collect(Collectors.toList());
flows.stream().forEach(
e -> {
if (StringUtils.isBlank(e.getName()) && StringUtils.isNotBlank(nodeName)) {
e.setName(nodeName);
}
// 设置条件表达式
if (Objects.isNull(e.getConditionExpression()) && StringUtils.isNotBlank(expression)) {
e.setConditionExpression(expression);
}
}
);
if (Objects.nonNull(identifier)) {
incoming.add(identifier);
}
}
ChildNode childNode = flowNode.getChildNode();
if (Objects.nonNull(childNode) && StringUtils.isNotBlank(childNode.getId())) {
String parentId = childNode.getParentId();
ChildNode parentChildNode = childNodeMap.get(parentId);
boolean conFlag = Type.CONCURRENTS.type
.equals(parentChildNode.getType());
if (!conFlag) {
String type = childNode.getType();
if (!Type.EMPTY.type.equals(type)) {
} else {
if (Type.CONDITIONS.type.equals(parentChildNode.getType())) {
String endExId = parentChildNode.getId() + "end";
process.addFlowElement(createExclusiveGateWayEnd(endExId));
if (incoming == null || incoming.isEmpty()) {
return create(exclusiveGatewayId, childNode, process, bpmnModel, sequenceFlows,
childNodeMap);
} else {
JSONObject incomingObj = childNode.getIncoming();
// 所有 service task 连接 end exclusive gateway
incomingObj.put("incoming", incoming);
FlowElement flowElement = bpmnModel.getFlowElement(incoming.get(0));
// 1.0 先进行边连接, 暂存 nextNode
ChildNode nextNode = childNode.getChildNode();
childNode.setChildNode(null);
String identifier = endExId;
for (int i = 0; i < incoming.size(); i++) {
process.addFlowElement(connect(incoming.get(i), identifier, sequenceFlows, childNodeMap, process));
}
// 针对 gateway 空任务分支 添加条件表达式
if (!conditions.isEmpty()) {
FlowElement flowElement1 = bpmnModel.getFlowElement(identifier);
// 获取从 gateway 到目标节点 未设置条件表达式的节点
List<SequenceFlow> flows = sequenceFlows.stream().filter(
flow -> StringUtils.equals(flowElement1.getId(), flow.getTargetRef()))
.filter(
flow -> StringUtils.equals(flow.getSourceRef(), exclusiveGatewayId))
.collect(Collectors.toList());
flows.stream().forEach(sequenceFlow -> {
if (!conditions.isEmpty()) {
JSONObject condition = conditions.get(0);
String nodeName = condition.getString("nodeName");
String expression = condition.getString("expression");
if (StringUtils.isBlank(sequenceFlow.getName()) && StringUtils
.isNotBlank(nodeName)) {
sequenceFlow.setName(nodeName);
}
// 设置条件表达式
if (Objects.isNull(sequenceFlow.getConditionExpression())
&& StringUtils.isNotBlank(expression)) {
sequenceFlow.setConditionExpression(expression);
}
FlowElement flowElement2 = process.getFlowElement(sequenceFlow.getId());
if (flowElement2 != null) {
flowElement2.setId(condition.getString("elseSequenceFlowId"));
exclusiveGateway.setDefaultFlow(flowElement2.getId());
;
}
conditions.remove(0);
}
});
}
// 1.1 边连接完成后,在进行 nextNode 创建
if (Objects.nonNull(nextNode) && StringUtils.isNotBlank(nextNode.getId())) {
return create(identifier, nextNode, process, bpmnModel, sequenceFlows,
childNodeMap);
} else {
return identifier;
}
}
}
}
} else {
System.err.println("-");
}
}
return exclusiveGatewayId;
}
public static ExclusiveGateway createExclusiveGateWayEnd(String id) {
ExclusiveGateway exclusiveGateway = new ExclusiveGateway();
exclusiveGateway.setId(id);
return exclusiveGateway;
}
private static ParallelGateway createParallelGateWayEnd(String id) {
ParallelGateway parallelGateway = new ParallelGateway();
parallelGateway.setId(id);
return parallelGateway;
}
private static String createParallelGatewayBuilder(String formId, ChildNode flowNode, Process process, BpmnModel bpmnModel, List<SequenceFlow> sequenceFlows, Map<String, ChildNode> childNodeMap) throws InvocationTargetException, IllegalAccessException {
childNodeMap.put(flowNode.getId(), flowNode);
String name = flowNode.getName();
ParallelGateway parallelGateway = new ParallelGateway();
String parallelGatewayId = flowNode.getId();
parallelGateway.setId(parallelGatewayId);
parallelGateway.setName(name);
process.addFlowElement(parallelGateway);
process.addFlowElement(connect(formId, parallelGatewayId, sequenceFlows, childNodeMap, process));
if (Objects.isNull(flowNode.getConditionNodes()) && Objects.isNull(flowNode.getChildNode())) {
return parallelGatewayId;
}
List<ChildNode> flowNodes = flowNode.getConditionNodes();
List<String> incoming = Lists.newArrayListWithCapacity(flowNodes.size());
for (ChildNode element : flowNodes) {
childNodeMap.put(element.getId(), element);
ChildNode childNode = element.getChildNode();
if (Objects.isNull(childNode) || StringUtils.isBlank(childNode.getId())) {
incoming.add(parallelGatewayId);
continue;
}
String identifier = create(parallelGatewayId, childNode, process, bpmnModel, sequenceFlows, childNodeMap);
if (Objects.nonNull(identifier)) {
incoming.add(identifier);
}
}
ChildNode childNode = flowNode.getChildNode();
if (Objects.nonNull(childNode) && StringUtils.isNotBlank(childNode.getId())) {
String parentId = childNode.getParentId();
ChildNode parentChildNode = childNodeMap.get(parentId);
boolean conFlag = Type.CONCURRENTS.type
.equals(parentChildNode.getType());
if (!conFlag) {
String type = childNode.getType();
if (!Type.EMPTY.type.equals(type)) {
} else {
if (Type.CONCURRENTS.type.equals(parentChildNode.getType())) {
String endExId = parentChildNode.getId() + "end";
process.addFlowElement(createParallelGateWayEnd(endExId));
// 普通结束网关
if (CollectionUtils.isEmpty(incoming)) {
return create(parallelGatewayId, childNode, process, bpmnModel, sequenceFlows, childNodeMap);
} else {
JSONObject incomingObj = childNode.getIncoming();
// 所有 service task 连接 end parallel gateway
incomingObj.put("incoming", incoming);
FlowElement flowElement = bpmnModel.getFlowElement(incoming.get(0));
// 1.0 先进行边连接, 暂存 nextNode
ChildNode nextNode = childNode.getChildNode();
childNode.setChildNode(null);
String identifier = endExId;
for (int i = 0; i < incoming.size(); i++) {
FlowElement flowElement1 = bpmnModel.getFlowElement(incoming.get(i));
process.addFlowElement(connect(flowElement1.getId(), identifier, sequenceFlows, childNodeMap, process));
}
// 1.1 边连接完成后,在进行 nextNode 创建
if (Objects.nonNull(nextNode) && StringUtils.isNotBlank(nextNode.getId())) {
return create(identifier, nextNode, process, bpmnModel, sequenceFlows, childNodeMap);
} else {
return identifier;
}
}
}
}
} else {
String type = childNode.getType();
if (!Type.EMPTY.type.equals(type)) {
} else {
if (Type.CONCURRENTS.type.equals(parentChildNode.getType())) {
String endExId = parentChildNode.getId() + "end";
process.addFlowElement(createParallelGateWayEnd(endExId));
// 普通结束网关
if (CollectionUtils.isEmpty(incoming)) {
return create(parallelGatewayId, childNode, process, bpmnModel, sequenceFlows, childNodeMap);
} else {
JSONObject incomingObj = childNode.getIncoming();
// 所有 service task 连接 end parallel gateway
incomingObj.put("incoming", incoming);
FlowElement flowElement = bpmnModel.getFlowElement(incoming.get(0));
// 1.0 先进行边连接, 暂存 nextNode
ChildNode nextNode = childNode.getChildNode();
childNode.setChildNode(null);
String identifier = endExId;
for (int i = 0; i < incoming.size(); i++) {
FlowElement flowElement1 = bpmnModel.getFlowElement(incoming.get(i));
process.addFlowElement(connect(flowElement1.getId(), identifier, sequenceFlows, childNodeMap, process));
}
// 1.1 边连接完成后,在进行 nextNode 创建
if (Objects.nonNull(nextNode) && StringUtils.isNotBlank(nextNode.getId())) {
return create(identifier, nextNode, process, bpmnModel, sequenceFlows, childNodeMap);
} else {
return identifier;
}
}
}
}
}
}
return parallelGatewayId;
}
private static String createTask(Process process, ChildNode flowNode, List<SequenceFlow> sequenceFlows, Map<String, ChildNode> childNodeMap) {
JSONObject incomingJson = flowNode.getIncoming();
List<String> incoming = incomingJson.getJSONArray("incoming").toJavaList(String.class);
// 自动生成id
// String id = id("serviceTask");
String id = flowNode.getId();
if (incoming != null && !incoming.isEmpty()) {
UserTask userTask = new UserTask();
userTask.setName(flowNode.getName());
userTask.setId(id);
process.addFlowElement(userTask);
process.addFlowElement(connect(incoming.get(0), id, sequenceFlows, childNodeMap, process));
ArrayList<FlowableListener> taskListeners = new ArrayList<>();
FlowableListener taskListener = new FlowableListener();
// 事件类型,
taskListener.setEvent(TaskListener.EVENTNAME_CREATE);
// 监听器类型
taskListener.setImplementationType(IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
// 设置实现了,这里设置监听器的类型是delegateExpression,这样可以在实现类注入Spring bean.
taskListener.setImplementation("${taskCreatedListener}");
taskListeners.add(taskListener);
userTask.setTaskListeners(taskListeners);
if ("root".equalsIgnoreCase(id)) {
} else {
ArrayList<FlowableListener> listeners = new ArrayList<>();
FlowableListener activitiListener = new FlowableListener();
// 事件类型,
activitiListener.setEvent(ExecutionListener.EVENTNAME_START);
// 监听器类型
activitiListener.setImplementationType(IMPLEMENTATION_TYPE_DELEGATEEXPRESSION);
// 设置实现了,这里设置监听器的类型是delegateExpression,这样可以在实现类注入Spring bean.
activitiListener.setImplementation("${counterSignListener}");
listeners.add(activitiListener);
userTask.setExecutionListeners(listeners);
Properties props = flowNode.getProps();
String mode = props.getMode();
MultiInstanceLoopCharacteristics multiInstanceLoopCharacteristics = new MultiInstanceLoopCharacteristics();
// 审批人集合参数
multiInstanceLoopCharacteristics.setInputDataItem(userTask.getId() + "assigneeList");
// 迭代集合
multiInstanceLoopCharacteristics.setElementVariable("assigneeName");
// 并行
multiInstanceLoopCharacteristics.setSequential(false);
userTask.setAssignee("${assigneeName}");
// 设置多实例属性
userTask.setLoopCharacteristics(multiInstanceLoopCharacteristics);
if (ModeEnums.OR.getTypeName().equals(mode)) {
multiInstanceLoopCharacteristics.setCompletionCondition("${nrOfCompletedInstances/nrOfInstances > 0}");
} else if (ModeEnums.NEXT.getTypeName().equals(mode)) {
multiInstanceLoopCharacteristics.setSequential(true);
}
JSONObject timeLimit = props.getTimeLimit();
if (timeLimit != null && !timeLimit.isEmpty()) {
JSONObject timeout = timeLimit.getJSONObject("timeout");
if (timeout != null && !timeout.isEmpty()) {
String unit = timeout.getString("unit");
Integer value = timeout.getInteger("value");
if (value > 0) {
List<BoundaryEvent> boundaryEvents = new ArrayList<>();
BoundaryEvent boundaryEvent = new BoundaryEvent();
boundaryEvent.setId(id("boundaryEvent"));
boundaryEvent.setAttachedToRefId(id);
boundaryEvent.setAttachedToRef(userTask);
boundaryEvent.setCancelActivity(Boolean.TRUE);
TimerEventDefinition timerEventDefinition = new TimerEventDefinition();
timerEventDefinition.setTimeDuration("PT" + 1 + "M");
timerEventDefinition.setId(id("timerEventDefinition"));
boundaryEvent.addEventDefinition(timerEventDefinition);
FlowableListener flowableListener = new FlowableListener();
flowableListener.setEvent(ExecutionListener.EVENTNAME_END);
flowableListener.setImplementationType(IMPLEMENTATION_TYPE_CLASS);
flowableListener.setImplementation("com.dingding.mid.listener.TimerListener");
List<FlowableListener> listenerList = new ArrayList<>();
listenerList.add(flowableListener);
boundaryEvent.setExecutionListeners(listenerList);
process.addFlowElement(boundaryEvent);
boundaryEvents.add(boundaryEvent);
userTask.setBoundaryEvents(boundaryEvents);
}
}
}
}
}
return id;
}
private static String createServiceTask(Process process, ChildNode flowNode, List<SequenceFlow> sequenceFlows, Map<String, ChildNode> childNodeMap) {
JSONObject incomingJson = flowNode.getIncoming();
List<String> incoming = incomingJson.getJSONArray("incoming").toJavaList(String.class);
String id = flowNode.getId();
if (incoming != null && !incoming.isEmpty()) {
}
return id;
}
private enum Type {
/**
......@@ -744,48 +251,7 @@ public class BpmnModelUtils {
}
private enum FlowType {
/**
* 并行事件
*/
CONCURRENTS(0, ParallelGateway.class),
CONCURRENT(1, SequenceFlow.class),
/**
* 排他事件
*/
CONDITION(2, ExclusiveGateway.class),
CONDITIONS(3, ExclusiveGateway.class),
/**
* 任务
*/
USER_TASK(4, UserTask.class),
EMPTY(5, Object.class),
ROOT(6, UserTask.class),
CC(7, ServiceTask.class),
TRIGGER(8, ServiceTask.class),
DELAY(9, IntermediateCatchEvent.class);
private int type;
private Class<?> typeClass;
FlowType(int type, Class<?> typeClass) {
this.type = type;
this.typeClass = typeClass;
}
public final static Map<String, Class<?>> TYPE_MAP = Maps.newHashMap();
static {
for (Type element : Type.values()) {
TYPE_MAP.put(element.type, element.typeClass);
}
}
public boolean isEqual(int type) {
return this.type == (type);
}
}
public static ChildNode getChildNode(ChildNode childNode, String nodeId) {
Map<String, ChildNode> childNodeMap = new HashMap<>();
......
......@@ -21,7 +21,7 @@
GROUP BY su.user_id,su.real_name
</select>
<select id="QueryUserParentOrg" resultMap="UserListDTO">
<select id="QueryUserWithParentOrg" resultMap="UserListDTO">
SELECT
CASE
WHEN userorg2.org_id = -1 THEN mainUser.user_id
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论