package com.idea.oa.activiti.service; import com.idea.oa.activiti.exception.FlowException; import com.idea.oa.activiti.model.UserTaskMore; import com.idea.oa.apply.util.constant.ConstantFlowType; import com.idea.oa.flow2.model.FlowMain; import com.idea.oa.flow2.model.FlowMainPush; import com.idea.oa.flow2.service.FlowMainLogService; import com.idea.oa.flow2.service.FlowMainService; import com.rockstar.flow.dto.TaskDto; import com.rockstar.flow.service.FlowService; import com.rockstar.frame.model.FrameRoleData; import com.rockstar.frame.model.FrameUser; import com.rockstar.frame.service.FrameUserService; import com.rockstar.system.model.SysDept; import com.rockstar.system.model.SysDeptExample; import com.rockstar.system.service.SysDeptService; import com.rockstar.util.StringUtils; import org.activiti.bpmn.model.*; import org.activiti.engine.*; import org.activiti.engine.runtime.ProcessInstance; import org.activiti.engine.task.Task; import org.activiti.engine.task.TaskQuery; import org.apache.commons.collections.CollectionUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.math.BigDecimal; import java.util.*; @Service public class ProActiService { @Autowired private FlowMainLogService flowMainLogService; //todo 到时候如果先会签,串并联的问题,flowService.runTask和flowService.start判断一下,是否需要串联会签还是并联会签,如果是3的单人签核,1是并联会签,0是串联会签 @Autowired private TaskService taskService; @Autowired private FlowService flowService; @Autowired private FlowMainService flowMainService; @Autowired private FrameUserService userService; @Autowired RuntimeService runtimeService; // // @Autowired // private FramePostService postService; // @Autowired private SysDeptService sysDeptService; // // // @Autowired // private FrameUserDeptService frameUserDeptService; @Autowired private FrameUserService frameUserService; /** * ok * 删除并结束指定活动实例 * * @param processInstanceId 启动流程的流程对象id * @param comments 评论/备注 */ @Transactional public void endTaskProcess(String processInstanceId, String comments) { flowService.deleteInstance(processInstanceId, comments); } /** * ok * 启动流程 * 启动方法时,ActiDto内的必须值是:processType, currentUserId 和 businessId * * @param actiDto * @return * @throws FlowException */ @Transactional public Map startAutoTask(Map actiDto) throws FlowException, com.rockstar.flow.exception.FlowException { // processDefine 流程定义 apply_pay // dataRole 角色??是传什么? // businessId 流程id,就用主流程的id flow_main // targetUser 目标人员 // currUser 当前人员 String processDefine = "apply_pay"; FrameUser targetUser = userService.selectByPrimaryKey("1080517374995595264"); FrameUser currUser = userService.selectByPrimaryKey("1"); // String businessId="1088138622709792768"; // String businessId="1088140716548292608"; String businessId = "1088140517679562752";//主申请表id Map startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); //返回数据{processInstanceId=7501}{processInstanceId=12501}{processInstanceId=17501} String taskId = "任务ID:17516"; String flow_id = startTask.get("processInstanceId").toString(); ; return startTask; } /** * ok * 执行当前流程节点 * 该方法中,ActiDto内除了businessId,其他都是必须值 * * @param actiDto isEndSet,当业务发现可以结束审核的时候向方法外传送是否结束审核的信号 * @return * @throws FlowException */ @Transactional public Object runAutoTask(Map actiDto) throws FlowException, com.rockstar.flow.exception.FlowException { FrameUser targetUser = userService.selectByPrimaryKey("1080522875951120384"); FrameUser currUser = userService.selectByPrimaryKey("1080517374995595264"); // private String processType; // private String currentUserId; // private String operateUserId; // private String dataRole; // private String agree;==>yes/no // private String comments;===================>???? // private String businessId; // private String taskId;===>在展示列表里面有taskId // flowDto.getTaskId(), flowDto.getDataRole(), flowDto.getAgree(), flowDto.getComments() Map map = new HashMap<>(); map.put("billMoney", 1250); return flowService.runTask("12516", null, "yes", "zt omments", targetUser, currUser, null); } /** * 查询数据 * * @param taskDto * @return * @throws FlowException */ @Transactional public List findTask(TaskDto taskDto) throws FlowException { List taskGroups = new ArrayList<>(); return flowService.findTask(taskDto, taskGroups); } /** * 还不知道干什么用的,猜是查看备注用的 * * @param taskId * @param isHistoric * @return * @throws FlowException */ @Transactional public List getCommentsByTid(String taskId, Boolean isHistoric) throws FlowException { if (StringUtils.isEmpty(taskId)) throw new FlowException("任务ID为空"); if (null == isHistoric) { isHistoric = false; } return flowService.getComments(taskId, isHistoric); } /** * 通过taskId获取任务后续得任务组列表,任务组列表定义如下: * 1,任务组是有('岗位'和yes) 或('curr_user'和'no')组合而成得字符串,具体如:director-yes,office_leader-yes或curr_user-no等 * 2,一般来说curr_user-no都是被退回之后指向得任务组,而带-yes后缀的是同意所指向得任务组 *

* 使用方式: * 1,在待审批列表中打开某个审批任务,先通过taskId(任务ID)获取该任务后续得任务组 * 2,分析所拥有得任务组,一般是2个或者1个任务组 * 3,根据所获得得任务组,来安排界面'同意'和'不同意'得按钮显示或隐藏 * 4,任务组含curr_user-no,就具备'不同意'按钮,点击不同意按钮,传输值:agree值为no, dataRole:'-no'之前的 * 5,任务组含带-yes后缀的,就具备'同意'按钮,点击同意按钮,传输值:agree值为yes, dataRole:'-yes'之前的 * 6,任务组如果只含curr_user-no,没其他的,那就具备'不同意'和'结束'按钮,点结束按钮,传输值:agree值为yes即可 * * @param taskId 任务ID * @param isHistoric 是否历史任务 * @return */ @Transactional public List nextTaskGroups(String taskId, boolean isHistoric) throws FlowException { if (StringUtils.isEmpty(taskId)) throw new FlowException("任务ID为空"); List strings = flowService.nextTaskGroups(taskId, isHistoric); List userTasks = flowService.nextTasks(taskId, isHistoric); System.out.println("nextTasks数据为:" + userTasks); return strings; } //=======偏业务的,到时候要搬走的========================================================================================================================================================= public String getNodeName(FlowMainPush flowMainPush) { { Task task = null; List taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId()).taskId(flowMainPush.getTaskId()).list(); if (taskList == null || taskList.isEmpty()) { return null; } task = taskList.get(0); return task.getName(); } } /** * 通用方法 //当前审核人/委托人代表的用户id * * @param flowMainPush * @return */ public String getMyFrameUserId(FlowMainPush flowMainPush) { //当前审核人/委托人代表的用户id String myFrameUserId = null; { Integer pushRole = flowMainPush.getPushRole(); if (new Integer(1).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)', myFrameUserId = flowMainPush.getPushUser(); } else if (new Integer(2).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)', //因为是被委托人,所以查到这个委托人的信息 // {//通过流程监控进行操的时候就会有问题,不能找到原来的审核用户id 第一种方式,通过关联查询进行被委托人查询 // FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId()); // String auditResult = flowMainLog.getAuditResult(); // if (!"4".equals(auditResult)) {// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)', // return null;//异常情况 // } // myFrameUserId = flowMainLog.getAuditUser(); // } {//第二种方式 // 通过 flowMainPush.getFlowPost()来获取对应的被委托人的信息,只是还没有测试不知道 第二种方式是否好用 myFrameUserId = flowMainPush.getFlowPost(); } } else { return null;//异常情况 } } return myFrameUserId; } /** * 审核通过,进行下一步操作 * * @return * @throws FlowException */ @Transactional public Map passToRunTask(FlowMainPush flowMainPush, String deploymentid, String businessId, Map conditionMap) throws com.rockstar.flow.exception.FlowException { // 发起流程引擎操作 并查看下一节点的操作要求 //0,如果是收纳且匹配上角色就正常流程审核,没有匹配上就返回null,异常错误 ok, //1. 如果当前角色是自己,就进行正常的审核流程 ok //2. 先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok //当前审核人/委托人代表的用户id String myFrameUserId = this.getMyFrameUserId(flowMainPush); if (myFrameUserId == null) { return null; } // { // Integer pushRole = flowMainPush.getPushRole(); // if (new Integer(1).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)', // myFrameUserId = flowMainPush.getPushUser(); // } else if (new Integer(2).equals(pushRole)) {//'推送人身份:1本人审核,2被委托人(代理审核人审核权限)', // //因为是被委托人,所以查到这个委托人的信息 // {//第一种方式,通过关联查询进行被委托人查询 // FlowMainLog flowMainLog = flowMainLogService.selectByPrimaryKey(flowMainPush.getUpMainLogId()); // String auditResult = flowMainLog.getAuditResult(); // if (!"4".equals(auditResult)) {// `audit_result` varchar(4) DEFAULT NULL COMMENT '审批结果(1同意或者2不同意驳回到申请人,3不同意驳回到上一个审核人,4,委托别人进行审核,null没有审核)', // return null;//异常情况 // } // myFrameUserId = flowMainLog.getAuditUser(); // } // {//第二种方式 // //通过 flowMainPush.getFlowPost()来获取对应的被委托人的信息,只是还没有测试不知道 第二种方式是否好用 //// myFrameUserId = flowMainPush.getFlowPost() // } // } else { // return null;//异常情况 // } // } //当前审核人/委托人代表的用户 FrameUser myframeUser = frameUserService.selectByPrimaryKey(myFrameUserId); //根据任务id获取任务信息 //当前任务流程 Task task = null; { List taskList = taskService.createTaskQuery().processInstanceBusinessKey(flowMainPush.getFlowMainId()).taskId(flowMainPush.getTaskId()).list(); if (taskList == null || taskList.isEmpty()) { return null; } task = taskList.get(0); } //本节点的关键子 例如flow_cnjs_1_1_0-yes String pushUserKey = flowMainPush.getPushUserKey(); //本节点的角色 例如cnjs String setRurrRole = this.getSetRurrRole(pushUserKey); //判断setRurrRole是不是出纳类的角色,如果是出纳的角色,就判断当前审核人是不是也是出纳,是就继续,不是就是异常错误,返回null //判断是否符合出纳类型的要求 ok { for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是出纳关系的查收纳 //查看谁是对应角色并查找对应的人 String role = ConstantFlowType.ROLES_CHECK[i];//找到是出纳类的角色 // List FrameRoleDatas = flowMainService.findFrameRoleDatasByUserId(myFrameUserId, ConstantFlowType.ROLETYPE);//"FLOW" // for (FrameRoleData frameRoleData : FrameRoleDatas) { // String roleKey = frameRoleData.getRoleKey(); // if (roleKey.equals(role)) { // //匹配到对应的人,用正常流程做审核 // return this.donaturalTask(deploymentid, myframeUser, task, conditionMap); // } // } //如果没有匹配到就是异常错误,返回null // return null; //只所以注释掉上面的,是觉得原来订的审核人已经确认了,若中途改掉了也不需要校验了,确保流程的一致性,并能正常运行 return this.donaturalTask(deploymentid, myframeUser, task, conditionMap,businessId); } } } { //当前审核人/委托人代表的用户角色(只判断了是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的) String currRole = this.getCurrRole(myframeUser); //没有获取到角色,直接对到admin那里 if (currRole == null || currRole.equals("")) { // 直接对到admin那里 System.out.println("8没有找到对应人:" + " if (currRole == null || currRole.equals(\"\"))"); FrameUser targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } {//下面的替换这里的数据,来解决管理员无法结束流程的问题 // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap); // return new HashMap<>(); } { return this.donaturalTask(deploymentid, myframeUser, task, conditionMap,businessId); } } //当发现this.getCurrRole(myframeUser);获取的角色是普通员工的时候,就知道他作为审核人只是直接上级,并不是领导,所以把角色调上一级 if (currRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[0])) { currRole = ConstantFlowType.FLOW_ROLES_DEPT[1]; } // 不是出纳的情况下进行的判断 //1.如果当前角色是自己,就进行正常的审核流程 ok //2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok if ("dept_head".equals(setRurrRole) || "flow_sjfgld".equals(setRurrRole) || setRurrRole.equals(currRole)) {//1.如果当前角色是自己,就进行正常的审核流程 ok return this.donaturalTask(deploymentid, myframeUser, task, conditionMap,businessId); } else {//2.先查看当前角色是不是自己,不是自己就移动到自己的角色,然后再进行正常的审核流程 ok FrameUser targetUser = null; UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid); // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上 if (userPosition == null) {//没有找到数据 System.out.println("9没有找到对应人:" + "if (userPosition == null) {"); targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, myframeUser, conditionMap); return new HashMap<>(); } else {//找到userPosition数据录了 //还不是自己的角色,还要遍历查找 return getNextFlow(businessId, userPosition, deploymentid, myframeUser, conditionMap, task); } } } } /** * 通用方法 写一个正常流程,正常下审核到下一个环节 * * @param deploymentid 流程任务唯一id * @param currUser 当前审核人/委托人代表的用户 * @param task2 当前的任务Task * @param conditionMap 所需要用到的条件 * @return */ public Map donaturalTask(String deploymentid, FrameUser currUser, Task task2, Map conditionMap, String businessId) throws com.rockstar.flow.exception.FlowException { { FrameUser targetUser = null; //可以开始正常走流程了 嘻嘻... { UserTask myNowUserTask = this.getUserTaskById(task2.getTaskDefinitionKey(), deploymentid);//id的值如:_9 //获取到了出去的各条路径 List outgoingFlows = myNowUserTask.getOutgoingFlows(); //我的下一个节点位置 SequenceFlow myNextSequenceFlow = null; for (SequenceFlow outgoingFlow : outgoingFlows) { String conditionExpression = outgoingFlow.getConditionExpression(); //如果是空就跳过 if (conditionExpression == null) { continue; } else //只有是yes的时候才是需要往下运行的,如果 if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'} continue; } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'} continue; } else //只有是yes的时候才是需要往下运行的,如果 if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx //发现没有判断条件,那本流程就是下个节点 myNextSequenceFlow = outgoingFlow; } else { //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点 //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧 //获取路径的判断条件 // List myconditionExpressions = new ArrayList(); // myconditionExpressions.add(conditionExpression); // int isOkNum = 0; // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { // boolean isOk = false; // //这是我的判断条件(通过条件判断库去比对数据) // String mycondition = myconditionExpressions.get(i1); // if (mycondition.contains("billMoney")) { //// ${billMoney>3000} // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); // if (mycondition.contains("<=")) { // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); // if (billMoney <= Double.valueOf(substring)) { //// ok // isOk = true; // // } // } else if (mycondition.contains("<")) { // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); // if (billMoney < Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">=")) { // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); // if (billMoney >= Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">")) { // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); // if (billMoney > Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains("==")) { // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); // BigDecimal data1 = new BigDecimal(billMoney); // BigDecimal data2 = new BigDecimal(substring); // int i2 = data1.compareTo(data2); // if (i2 == 0) { //// ok // isOk = true; // } // } // } // // if (isOk) { // isOkNum = isOkNum + 1; // } // } // if (isOkNum == myconditionExpressions.size()) { // myNextSequenceFlow = outgoingFlow; // break; // } if (this.booleanConditionIsOk(conditionExpression, conditionMap)) { myNextSequenceFlow = outgoingFlow; } } //如果没有找到下个流程节点就继续找 if (myNextSequenceFlow == null) { continue; } { //下面是找到了下个流程节点,需要进行正常的运行节点了 //================================================================ //TaskList.get(1).getOutgoingFlows().get(1).getTargetFlowElement().getCandidateGroups() // TaskList.get(7).getOutgoingFlows().get(1).getTargetFlowElement().getClass().isInstance(EndEvent.class); FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement(); if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态 System.out.println("已经是结束流程了,直接完成审核就行了1"); boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap); HashMap objectObjectHashMap = new HashMap<>(); objectObjectHashMap.put("isEnd", "1"); return objectObjectHashMap; } //class org.activiti.bpmn.model.EndEvent String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups(); String setRurrRole = this.getSetRurrRole(candidateGroup); boolean end = false; for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 {//统一到同一个方法中了:getTargerUser_FLOW_ROLES_DEPT // if (s.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导 // String department = currUser.getDepartment(); // SysDept sysDept = sysDeptService.selectByPrimaryKey(department); // if (sysDept == null) {//没有部门信息 // // } else { // String changedBy = sysDept.getChangedBy(); // if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管 // // } else { // targetUser = userService.selectByPrimaryKey(changedBy); // } // } // } else { // String leader = currUser.getLeader(); // if (StringUtils.isEmpty(leader)) {//没有找到直接领导 // } else { // targetUser = userService.selectByPrimaryKey(leader); // } // } // if (targetUser == null) {//没有找到目标人就都传到admin中去 //// return null; // targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); // if (targetUser == null) { // System.err.println("异常,没有找到目标人"); // return null; // } // } } // 写一个通用方法,专门根据条件获取部门领导是谁 targetUser = this.getTargerUser_FLOW_ROLES_DEPT(s, currUser,businessId); if (targetUser == null) { return null; } //todo SysDept sysDept = sysDeptService.selectByPrimaryKey(department); boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); end = true; return new HashMap<>(); } } if (!end) { for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 //查看谁是对应角色并查找对应的人 String role = ConstantFlowType.ROLES[i]; List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE,currUser.getGroupId()); if (!targetUserList.isEmpty()) { if (targetUserList.size() >= 1) { targetUser = targetUserList.get(0); } } if (targetUser == null) { // return null; // System.out.println("1没有找到对应人:" + "if (targetUser == null) {==>" + role + "==>" + ConstantFlowType.ROLETYPE); // targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); // if (targetUser == null) { // System.err.println("异常,没有找到目标人"); // return null; // } return this.jumpNextNode(task2,deploymentid,currUser,setRurrRole,conditionMap,businessId); } boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); end = true; return new HashMap<>(); } } } if (!end) { for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 //查看谁是对应角色并查找对应的人 String role = ConstantFlowType.ROLES_CHECK[i]; List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE,currUser.getGroupId()); if (!targetUserList.isEmpty()) { if (targetUserList.size() >= 1) { targetUser = targetUserList.get(0); } } if (targetUser == null) { // return null; System.out.println("2没有找到对应人:" + "if (targetUser == null) {"); targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } } boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); end = true; return new HashMap<>(); } } } break; } } //都没有就是没有下个流程了,可以结束流程了 System.out.println("已经没有下个申请流程了,已经结束了1"); // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap); HashMap objectObjectHashMap = new HashMap<>(); objectObjectHashMap.put("isEnd", "1"); return objectObjectHashMap; } //下面的代码要替换掉========================================================================================== // { // // //可以开始正常走流程了 嘻嘻... // List nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task2.getTaskDefinitionKey(), false); // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) { // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) { // UserTask myNextTask = null;//我要走的流程 // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii); // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes // if (!"-yes".equals(candidateGroup.substring(candidateGroup.indexOf("-")))){ // continue; // } // String setRurrRole = this.getSetRurrRole(candidateGroup); // { // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断 // //获取路径的判断条件 // List myconditionExpressions = new ArrayList(); // List outgoingFlows = userTask.getOutgoingFlows(); // for (SequenceFlow outgoingFlow : outgoingFlows) { // String conditionExpression = outgoingFlow.getConditionExpression(); // if (conditionExpression == null) { // continue; // } // if (conditionExpression.contains("${agree==")) { // continue; // } // myconditionExpressions.add(conditionExpression); // } // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用 // myNextTask = userTask; // // } else {//有条件就判断是否满足条件,不满足就运行下一个 // int isOkNum = 0; // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { // boolean isOk = false; // //这是我的判断条件(通过条件判断库去比对数据) // String mycondition = myconditionExpressions.get(i1); // if (mycondition.contains("billMoney")) { //// ${billMoney>3000} // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); // if (mycondition.contains("<=")) { // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); // if (billMoney <= Double.valueOf(substring)) { //// ok // isOk = true; // // } // } else if (mycondition.contains("<")) { // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); // if (billMoney < Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">=")) { // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); // if (billMoney >= Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">")) { // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); // if (billMoney > Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains("==")) { // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); // BigDecimal data1 = new BigDecimal(billMoney); // BigDecimal data2 = new BigDecimal(substring); // int i2 = data1.compareTo(data2); // if (i2 == 0) { //// ok // isOk = true; // } // } // } // // if (isOk) { // isOkNum = isOkNum + 1; // } // } // if (isOkNum == myconditionExpressions.size()) { // myNextTask = userTask; // } // // if (myNextTask == null) { // continue; // } // // } // } // //================================================================ // boolean end = false; // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 // String leader = currUser.getLeader(); // targetUser = userService.selectByPrimaryKey(leader); // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); // // end = true; // return new HashMap<>(); // } // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); // end = true; // return new HashMap<>(); // } // } // // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES_CHECK[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); // end = true; // return new HashMap<>(); // } // } // } // break; // } // //都没有就是没有下个流程了,可以结束流程了 // System.out.println("已经没有下个申请流程了,已经结束了"); // // // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap); // // HashMap objectObjectHashMap = new HashMap<>(); // objectObjectHashMap.put("isEnd","1"); // return objectObjectHashMap; // } else { // System.out.println("已经没有下个申请流程了,已经结束了"); // // // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, currUser, currUser, conditionMap); // // HashMap objectObjectHashMap = new HashMap<>(); // objectObjectHashMap.put("isEnd","1"); // return objectObjectHashMap; // } // } } } /** * 写一个通用方法判断流程中的条件是否符合要求 * conditionExpression 判断的条件 * conditionMap拥有的条件 */ public boolean booleanConditionIsOk(String conditionExpression, Map conditionMap) { //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点 //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧 //获取路径的判断条件 List myconditionExpressions = new ArrayList(); myconditionExpressions.add(conditionExpression); int isOkNum = 0; for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { boolean isOk = false; //这是我的判断条件(通过条件判断库去比对数据) String mycondition = myconditionExpressions.get(i1); if (mycondition.contains("billMoney")) { // ${billMoney>3000} Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); if (mycondition.contains("<=")) { String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); if (billMoney <= Double.valueOf(substring)) { // ok isOk = true; } } else if (mycondition.contains("<")) { String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); if (billMoney < Double.valueOf(substring)) { // ok isOk = true; } } else if (mycondition.contains(">=")) { String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); if (billMoney >= Double.valueOf(substring)) { // ok isOk = true; } } else if (mycondition.contains(">")) { String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); if (billMoney > Double.valueOf(substring)) { // ok isOk = true; } } else if (mycondition.contains("==")) { String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); BigDecimal data1 = new BigDecimal(billMoney); BigDecimal data2 = new BigDecimal(substring); int i2 = data1.compareTo(data2); if (i2 == 0) { // ok isOk = true; } } } else if (mycondition.contains("isExchangeOnly==")) { String isExchangeOnly = conditionMap.get("isExchangeOnly").toString(); Integer applyDay = Integer.valueOf(conditionMap.get("applyDay").toString()); if (mycondition.contains("(isExchangeOnly=='no') and (applyDay>3)")) { if ("no".equals(isExchangeOnly) && applyDay > 3) { isOk = true; } } else if (mycondition.contains("(isExchangeOnly=='yes') or (applyDay<=3)")) { if ("yes".equals(isExchangeOnly) || applyDay <= 3) { isOk = true; } } } else if (mycondition.contains("isProSales==")) { String isExchangeOnly = conditionMap.get("isProSales").toString(); Double applyDay = Double.valueOf(conditionMap.get("preSales").toString()); if (mycondition.contains("(isProSales=='no') or (preSales>=2000000)")) { if ("no".equals(isExchangeOnly) && applyDay >= 2000000) { isOk = true; } } else if (mycondition.contains("(isProSales=='yes') or (preSales<2000000)")) { if ("yes".equals(isExchangeOnly) || applyDay < 2000000) { isOk = true; } } } if (isOk) { isOkNum = isOkNum + 1; } } if (isOkNum == myconditionExpressions.size()) { return true; } else { return false; } } /** * 流程重新梳理 pany 2023/11/22 * processDefine 在ConstantFlowType中的PAYMEN_PROCESSDEFINE * String businessId = "1088140517679562752";//主申请表id * deploymentid 在ConstantFlowType.USE_MONEY_DEPLOYMENTID * conditionMap 是条件数据,比如目前需要的条件是${billMoney>3000} * return 返回的数据是flow_id字段,如果是null,说明异常有问题了 如果是end就是没有下个流程了,可以结束了 */ // public Map startTask2(String processDefine, String deploymentid, String businessId, FrameUser currUser, Map conditionMap) throws com.rockstar.flow.exception.FlowException { // FrameUser targetUser = null; // List taskList = flowService.getTaskList(deploymentid); // for(UserTask userTask : taskList){ // String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no // String setRurrRole = this.getSetRurrRole(s); // } // // } /** * 根据用户位置启动信息启动流程 * processDefine 在ConstantFlowType中的PAYMEN_PROCESSDEFINE * String businessId = "1088140517679562752";//主申请表id * deploymentid 在ConstantFlowType.USE_MONEY_DEPLOYMENTID * conditionMap 是条件数据,比如目前需要的条件是${billMoney>3000} * return 返回的数据是flow_id字段,如果是null,说明异常有问题了 如果是end就是没有下个流程了,可以结束了 */ public Map startTask(String processDefine, String deploymentid, String businessId, FrameUser currUser, Map conditionMap) throws com.rockstar.flow.exception.FlowException { FrameUser targetUser = null; String currRole = this.getCurrRole(currUser); UserTaskMore userPosition = this.findUserPosition(currRole, deploymentid); // 返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上 Map startTask = null; if (userPosition == null) {//没有找到数据 System.out.println("7没有找到对应人:" + " if (userPosition == null) {"); targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); return startTask; } else {//找到userPosition对象数据了 // 1.如果是1就正常网下写,如果发现目标审核人的角色不是正常角色,就要去找他的对应位置的角色,不管是谁都要审核通过才行, 所以开始的时候只要找到直接领导传下去就好了,在运行节点进行角色判断,将流程跳到自己的角色位置结束 //1.1查看下个节点人员角色的需求 //1.1.1如果是部门关系的查部门 //1.1.2如果是领导关系的查领导 //1.1.3如果是收纳关系的查收纳 //2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上 int nodeNum = userPosition.getNodeNum(); UserTask currentUserTask = userPosition.getCurrentUserTask(); if (nodeNum == 1) { { List outgoingFlows = currentUserTask.getOutgoingFlows(); //我的下一个节点位置 SequenceFlow myNextSequenceFlow = null; for (SequenceFlow outgoingFlow : outgoingFlows) { String conditionExpression = outgoingFlow.getConditionExpression(); //如果是空就跳过 if (conditionExpression == null) { continue; } else //只有是yes的时候才是需要往下运行的,如果 if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'} continue; } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'} continue; } else //只有是yes的时候才是需要往下运行的,如果 if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx //发现没有判断条件,那本流程就是下个节点 myNextSequenceFlow = outgoingFlow; } else { //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点 //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧 //获取路径的判断条件 // List myconditionExpressions = new ArrayList(); // myconditionExpressions.add(conditionExpression); // int isOkNum = 0; // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { // boolean isOk = false; // //这是我的判断条件(通过条件判断库去比对数据) // String mycondition = myconditionExpressions.get(i1); // if (mycondition.contains("billMoney")) { //// ${billMoney>3000} // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); // if (mycondition.contains("<=")) { // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); // if (billMoney <= Double.valueOf(substring)) { //// ok // isOk = true; // // } // } else if (mycondition.contains("<")) { // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); // if (billMoney < Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">=")) { // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); // if (billMoney >= Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">")) { // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); // if (billMoney > Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains("==")) { // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); // BigDecimal data1 = new BigDecimal(billMoney); // BigDecimal data2 = new BigDecimal(substring); // int i2 = data1.compareTo(data2); // if (i2 == 0) { //// ok // isOk = true; // } // } // } // // if (isOk) { // isOkNum = isOkNum + 1; // } // } // if (isOkNum == myconditionExpressions.size()) { // myNextSequenceFlow = outgoingFlow; // break; // } if (this.booleanConditionIsOk(conditionExpression, conditionMap)) { myNextSequenceFlow = outgoingFlow; } } //如果没有找到下个流程节点就继续找 if (myNextSequenceFlow == null) { continue; } //下面是找到了下个流程节点,需要进行正常的运行节点了 FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement(); if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态 System.out.println("已经是结束流程了,直接完成审核就行了2"); return null; } String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups(); String setRurrRole = this.getSetRurrRole(candidateGroup); boolean end = false; for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 //统一到同一个方法中了:getTargerUser_FLOW_ROLES_DEPT // 写一个通用方法,专门根据条件获取部门领导是谁 targetUser = this.getTargerUser_FLOW_ROLES_DEPT(s, currUser,businessId); if (targetUser == null) { return null; } //todo SysDept sysDept = sysDeptService.selectByPrimaryKey(department); startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); end = true; return startTask; } } if (!end) { for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 //查看谁是对应角色并查找对应的人 String role = ConstantFlowType.ROLES[i]; List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE,currUser.getGroupId()); if (!targetUserList.isEmpty()) { if (targetUserList.size() >= 1) { targetUser = targetUserList.get(0); } } if (targetUser == null) { // return null; System.out.println("3没有找到对应人:" + "if (targetUser == null) {"); targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } } startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); end = true; return startTask; } } } if (!end) { for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 //查看谁是对应角色并查找对应的人 String role = ConstantFlowType.ROLES_CHECK[i]; List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE,currUser.getGroupId()); if (!targetUserList.isEmpty()) { if (targetUserList.size() >= 1) { targetUser = targetUserList.get(0); } } if (targetUser == null) { // return null; System.out.println("4没有找到对应人:" + "if (targetUser == null) {"); targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } } startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); end = true; return startTask; } } } return null; } //走到这里就没有找到对应的流程节点,所以需要报错 返回null System.out.println("异常错误,没有找到对应的流程节点"); return null; } //下面的要作废了================================================================ //获取下个节点数据 // { // List nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, currentUserTask.getId(), false); // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) { // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(0); // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes // String setRurrRole = this.getSetRurrRole(candidateGroup); // boolean end = false; // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 // String leader = currUser.getLeader(); // targetUser = userService.selectByPrimaryKey(leader); // if (targetUser == null) { // return null; // } // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); // end = true; // return startTask; // } // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); // end = true; // return startTask; // } // } // // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES_CHECK[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); // end = true; // return startTask; // } // } // } // return null; // // } else { // return null; // } // } } else if (nodeNum > 1) { // 2.如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上 // 需要进行循环审核过程 boolean isZhuYaoLingDao="flow_zyld".equals(currRole)?true:false; //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以注释掉下面的判断 if(isZhuYaoLingDao) {//2023年7月5日 章总在第七批次又改回来了 //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以注释掉下面的判断 targetUser = currUser; startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); if (!startTask.isEmpty()) { { // String flow_id = startTask.get("processInstanceId").toString();//"流程实例ID:" + task.getProcessInstanceId());是会变化的所以没有用 List list = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象 .taskAssignee(targetUser.getId())//指定个人任务查询 // .processInstanceId("12516") .list(); if (list == null || list.isEmpty() || list.size() <= 0) { System.err.println("异常,没有找到任务对象"); return null; } //2.1通过flow_id和targetUser获取下一个UserTask Task task = list.get(0); //task是当前流程的信息 //如果发现task对应的角色就是自己的角色,就开始正常的走 //如果发现task对应的角色还不是,就需要再进行设置自己的操作 String taskDefinitionKey = task.getTaskDefinitionKey(); //id的值如:_9 String flowId = userPosition.getUserTask().getId();//流程唯一id(我猜的) if (flowId.equals(taskDefinitionKey)) { //可以开始正常走流程了 嘻嘻... { // List nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task.getTaskDefinitionKey(), false); // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) { // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) { // UserTask myNextTask = null;//我要走的流程 // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii); // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes // //需要的角色 // String setRurrRole = this.getSetRurrRole(candidateGroup); // { // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断 // //获取路径的判断条件 // List myconditionExpressions = new ArrayList(); // List outgoingFlows = userTask.getOutgoingFlows(); // for (SequenceFlow outgoingFlow : outgoingFlows) { // String conditionExpression = outgoingFlow.getConditionExpression(); // if (conditionExpression == null) { // continue; // } // if (conditionExpression.contains("${agree==")) { // continue; // } // myconditionExpressions.add(conditionExpression); // } // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用 // myNextTask = userTask; // // } else {//有条件就判断是否满足条件,不满足就运行下一个 // int isOkNum = 0; // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { // boolean isOk = false; // //这是我的判断条件(通过条件判断库去比对数据) // String mycondition = myconditionExpressions.get(i1); // if (mycondition.contains("billMoney")) { //// ${billMoney>3000} // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); // if (mycondition.contains("<=")) { // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); // if (billMoney <= Double.valueOf(substring)) { //// ok // isOk = true; // // } // } else if (mycondition.contains("<")) { // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); // if (billMoney < Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">=")) { // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); // if (billMoney >= Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">")) { // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); // if (billMoney > Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains("==")) { // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); // BigDecimal data1 = new BigDecimal(billMoney); // BigDecimal data2 = new BigDecimal(substring); // int i2 = data1.compareTo(data2); // if (i2 == 0) { //// ok // isOk = true; // } // } // } // // if (isOk) { // isOkNum = isOkNum + 1; // } // } // if (isOkNum == myconditionExpressions.size()) { // myNextTask = userTask; // } // // if (myNextTask == null) { // continue; // } // // } // } // //================================================================ // boolean end = false; // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 // String leader = currUser.getLeader(); // targetUser = userService.selectByPrimaryKey(leader); // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap); // // end = true; // return new HashMap<>(); // } // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap); // end = true; // return new HashMap<>(); // } // } // // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES_CHECK[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap); // end = true; // return new HashMap<>(); // } // } // } // break; // } // } else { // System.out.println("已经没有下个申请流程了,已经结束了"); // return null; // } } Map donaturalTaskMap = this.donaturalTask(deploymentid, currUser, task, conditionMap,businessId); if (donaturalTaskMap == null) { return null; } else { return startTask; } }else { //还不是自己的角色,还要遍历查找(但是要写在getNextFlow方法里面,且通过flowServiceNextFlow方法改造一下) // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); {//遍历对象 Map getNextFlowMap = getNextFlow(businessId, userPosition, deploymentid, currUser, conditionMap, task); if (getNextFlowMap == null) { return null; } else { //todo 如果getNextFlowMap返回数据是:{isEnd=1} 需要特殊处理 if (getNextFlowMap.get("isEnd") == null) { return startTask; } else { startTask.put("isEnd", getNextFlowMap.get("isEnd")); return startTask; } } } } } } else { return null; } }else { //2023年5月17日 章总修改,在开始申请的时候不判断身份是否是该节点本身份,而是必须要进行审核,所以新增掉下面的操作 if (currUser.getLeader()!=null) { targetUser = userService.selectByPrimaryKey(currUser.getLeader()); } if (targetUser==null){ targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); } startTask = flowService.startTask(processDefine, null, businessId, targetUser, currUser); if (!startTask.isEmpty()) { return startTask; } else { return null; } } } else { return null; } //为了实现并联串联审核流程的方法需求 //要求:flowService.startTask(processDefine, null, businessId, targetUser, currUser);改成flowService.startTask(processDefine, null, businessId, targetUsers,totalnumber, currUser);(修改内容目标人改成数组targetUsers,审核通过数量totalnumber自己定义) //要求2:flowService.runTask(taskId, null, agree, comments, targetUser, currUser, null);改成flowService.runTask(taskId, null, agree, comments, targetUsers,totalnumber, currUser, null);(修改内容目标人改成数组targetUsers,审核通过数量totalnumber自己定义) } //返回数据{processInstanceId=7501}{processInstanceId=12501}{processInstanceId=17501} } /** * 做一个通用方法,通过UserTask的id和deloymentId来获取指定的UserTask */ public UserTask getUserTaskById(String id, String deloymentId) { List taskList = flowService.getTaskList(deloymentId); for (int i = 0; i < taskList.size(); i++) { if (taskList.get(i).getId().equals(id)) { return taskList.get(i); } } return null; // List collect = taskList.stream().filter(x -> x.getId().equals(id)).collect(Collectors.toList()); // if (collect.isEmpty()){ // return null; // }else{ // return collect.get(0); // } } /** * 通过任务id获取userTask信息 * * @param taskId * @return */ public UserTask getUserTaskByTaskId(String taskId) { return (UserTask) flowService.getCurrentFlowNode(taskId); } /** * 写一个方法,当还不是自己的角色时,需要进入下个节点,若下个节点是收纳就可以结束运行,返回false,说明是end结束了,若返回true,说明正常继续运行 * * @return */ public Boolean flowServiceNextFlow(String deploymentid, Map conditionMap, FrameUser currUser, Task task) throws com.rockstar.flow.exception.FlowException { //获取到了我的userTask { UserTask myNowUserTask = this.getUserTaskById(task.getTaskDefinitionKey(), deploymentid);//id的值如:_9 //获取到了出去的各条路径 List outgoingFlows = myNowUserTask.getOutgoingFlows(); //我的下一个节点位置 SequenceFlow myNextSequenceFlow = null; for (SequenceFlow outgoingFlow : outgoingFlows) { String conditionExpression = outgoingFlow.getConditionExpression(); //如果是空就跳过 if (conditionExpression == null) { continue; } else //只有是yes的时候才是需要往下运行的,如果 if (conditionExpression.contains("${agree=='no'}")) {//${agree=='yes'} continue; } else if (conditionExpression.contains("${agree=='back'}")) {//${agree=='yes'} continue; } else //只有是yes的时候才是需要往下运行的,如果 if (conditionExpression.contains("${agree=='yes'}")) {//${agree=='yes'}//xxxx //发现没有判断条件,那本流程就是下个节点 myNextSequenceFlow = outgoingFlow; } else { //发现有明确的判断条件,需要判断是否满足条件才能确认是否本流程就是下个节点 //原来计划会有多个条件判断,但是现在就一个,所以就先写死一个条件吧 //获取路径的判断条件 // List myconditionExpressions = new ArrayList(); // myconditionExpressions.add(conditionExpression); // int isOkNum = 0; // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { // boolean isOk = false; // //这是我的判断条件(通过条件判断库去比对数据) // String mycondition = myconditionExpressions.get(i1); // if (mycondition.contains("billMoney")) { //// ${billMoney>3000} // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); // if (mycondition.contains("<=")) { // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); // if (billMoney <= Double.valueOf(substring)) { //// ok // isOk = true; // // } // } else if (mycondition.contains("<")) { // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); // if (billMoney < Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">=")) { // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); // if (billMoney >= Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">")) { // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); // if (billMoney > Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains("==")) { // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); // BigDecimal data1 = new BigDecimal(billMoney); // BigDecimal data2 = new BigDecimal(substring); // int i2 = data1.compareTo(data2); // if (i2 == 0) { //// ok // isOk = true; // } // } // } // // if (isOk) { // isOkNum = isOkNum + 1; // } // } // if (isOkNum == myconditionExpressions.size()) { // myNextSequenceFlow = outgoingFlow; // } if (this.booleanConditionIsOk(conditionExpression, conditionMap)) { myNextSequenceFlow = outgoingFlow; } } //如果没有找到下个流程节点就继续找 if (myNextSequenceFlow == null) { continue; } {//下面是找到了下个流程节点,需要进行正常的运行节点了 //================================================================================================ // TaskList.get(1).getOutgoingFlows().get(1).getTargetFlowElement().getCandidateGroups() FlowElement targetFlowElement = myNextSequenceFlow.getTargetFlowElement(); if (targetFlowElement instanceof EndEvent) {//如果是的话就是最后审核状态 System.out.println("已经是结束流程了,直接完成审核就行了3"); boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); return null; } String candidateGroup = ((UserTask) targetFlowElement).getCandidateGroups().get(0);//targetFlowElement.getCandidateGroups(); String setRurrRole = this.getSetRurrRole(candidateGroup); boolean end = false; for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 // String leader = currUser.getLeader(); // targetUser = userService.selectByPrimaryKey(leader); // if (targetUser == null) { // return null; // } boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); end = true; return true; } } if (!end) { for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); end = true; return true; } } } if (!end) { for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 //查看谁是对应角色并查找对应的人 String role = ConstantFlowType.ROLES_CHECK[i]; List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE,currUser.getGroupId()); FrameUser targetUser = null; if (!targetUserList.isEmpty()) { if (targetUserList.size() >= 1) { targetUser = targetUserList.get(0); } } if (targetUser == null) { // return null; System.out.println("5没有找到对应人:" + "if (targetUser == null) {"); targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } } boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap); end = true; return false; } } } break; } } //如果运行找到这里就说明没有找到下个流程节点了,流程可以结束了 System.out.println("已经没有下个申请流程了,已经结束了2"); // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); return null; } // { // //下面的部分将会被淘汰掉..................................................... // List nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task.getTaskDefinitionKey(), false); // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) { // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) { // UserTask myNextTask = null;//我要走的流程 // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii); // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes // if (!"-yes".equals(candidateGroup.substring(candidateGroup.indexOf("-")))) { // continue; // } // //需要的角色 // String setRurrRole = this.getSetRurrRole(candidateGroup); // { // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断 // //获取路径的判断条件 // List myconditionExpressions = new ArrayList(); // List outgoingFlows = userTask.getOutgoingFlows(); // for (SequenceFlow outgoingFlow : outgoingFlows) { // String conditionExpression = outgoingFlow.getConditionExpression(); // if (conditionExpression == null) { // continue; // } // if (conditionExpression.contains("${agree==")) { // continue; // } // myconditionExpressions.add(conditionExpression); // } // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用 // myNextTask = userTask; // // } else {//有条件就判断是否满足条件,不满足就运行下一个 // int isOkNum = 0; // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { // boolean isOk = false; // //这是我的判断条件(通过条件判断库去比对数据) // String mycondition = myconditionExpressions.get(i1); // if (mycondition.contains("billMoney")) { //// ${billMoney>3000} // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); // if (mycondition.contains("<=")) { // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); // if (billMoney <= Double.valueOf(substring)) { //// ok // isOk = true; // // } // } else if (mycondition.contains("<")) { // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); // if (billMoney < Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">=")) { // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); // if (billMoney >= Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">")) { // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); // if (billMoney > Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains("==")) { // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); // BigDecimal data1 = new BigDecimal(billMoney); // BigDecimal data2 = new BigDecimal(substring); // int i2 = data1.compareTo(data2); // if (i2 == 0) { //// ok // isOk = true; // } // } // } // // if (isOk) { // isOkNum = isOkNum + 1; // } // } // if (isOkNum == myconditionExpressions.size()) { // myNextTask = userTask; // } // // if (myNextTask == null) { // continue; // } // // } // } // //================================================================ // boolean end = false; // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 //// String leader = currUser.getLeader(); //// targetUser = userService.selectByPrimaryKey(leader); //// if (targetUser == null) { //// return null; //// } // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); // // end = true; // return true; // } // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 // //查看谁是对应角色并查找对应的人 //// String role = ConstantFlowType.ROLES[i]; //// List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); //// if (!targetUserList.isEmpty()) { //// if (targetUserList.size() >= 1) { //// targetUser = targetUserList.get(0); //// } //// } //// if (targetUser == null) { //// return null; //// } // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); // end = true; // return true; // } // } // // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES_CHECK[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // FrameUser targetUser = null; // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task.getId(), null, "yes", null, targetUser, currUser, conditionMap); // end = true; // return false; // } // } // } // break; // } // System.out.println("已经没有下个申请流程了,已经结束了"); // // // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); // return null; // } else { // System.out.println("已经没有下个申请流程了,已经结束了"); // // // boolean yes = flowService.runTask(task.getId(), null, "yes", null, currUser, currUser, conditionMap); // return null; // } // } } /** * 遍历进行操作最终获取用户自己的角色 * * @return */ public Map getNextFlow(String businessId, UserTaskMore userPosition, String deploymentid, FrameUser currUser, Map conditionMap, Task task) throws com.rockstar.flow.exception.FlowException { FrameUser targetUser = currUser; Boolean aBoolean = this.flowServiceNextFlow(deploymentid, conditionMap, currUser, task); if (aBoolean == null) { Map objectObjectHashMap = new HashMap<>(); objectObjectHashMap.put("isEnd", "1"); return objectObjectHashMap; } else if (!aBoolean) { return new HashMap<>(); } else if (aBoolean) { //继续运行下面的步骤 } {//遍历对象 List list2 = taskService.createTaskQuery().processInstanceBusinessKey(businessId)//创建任务查询对象 .taskAssignee(targetUser.getId())//指定个人任务查询 // .processInstanceId("12516") .list(); if (list2 == null || list2.isEmpty() || list2.size() <= 0) { System.err.println("异常,没有找到任务对象2"); return null; } //2.1通过flow_id和targetUser获取下一个UserTask Task task2 = list2.get(0); //task是当前流程的信息 //如果发现task对应的角色就是自己的角色,就开始正常的走 //如果发现task对应的角色还不是,就需要再进行设置自己的操作 String taskDefinitionKey2 = task2.getTaskDefinitionKey(); //id的值如:_9 String flowId2 = userPosition.getUserTask().getId();//流程唯一id(我猜的) if (flowId2.equals(taskDefinitionKey2)||"_5".equals(taskDefinitionKey2)||"_7".equals(taskDefinitionKey2)) { //可以开始正常走流程了 嘻嘻... { // //可以开始正常走流程了 嘻嘻... // List nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, task2.getTaskDefinitionKey(), false); // if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) { // for (int ii = 0; ii < nextCandidateGroupByDeploy.size(); ii++) { // UserTask myNextTask = null;//我要走的流程 // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(ii); // String candidateGroup = userTask.getCandidateGroups().get(0);//dept_superior_1_0_1-yes // String setRurrRole = this.getSetRurrRole(candidateGroup); // { // // 获取判断条件进行判断是否符合条件,符合就往下走,不符合就跳到下一个节点进行判断 // //获取路径的判断条件 // List myconditionExpressions = new ArrayList(); // List outgoingFlows = userTask.getOutgoingFlows(); // for (SequenceFlow outgoingFlow : outgoingFlows) { // String conditionExpression = outgoingFlow.getConditionExpression(); // if (conditionExpression == null) { // continue; // } // if (conditionExpression.contains("${agree==")) { // continue; // } // myconditionExpressions.add(conditionExpression); // } // if (myconditionExpressions.isEmpty()) {//没有条件就直接可以使用 // myNextTask = userTask; // // } else {//有条件就判断是否满足条件,不满足就运行下一个 // int isOkNum = 0; // for (int i1 = 0; i1 < myconditionExpressions.size(); i1++) { // boolean isOk = false; // //这是我的判断条件(通过条件判断库去比对数据) // String mycondition = myconditionExpressions.get(i1); // if (mycondition.contains("billMoney")) { //// ${billMoney>3000} // Double billMoney = Double.valueOf(conditionMap.get("billMoney").toString()); // if (mycondition.contains("<=")) { // String substring = mycondition.substring(mycondition.indexOf("<=") + 2, mycondition.length() - 1); // if (billMoney <= Double.valueOf(substring)) { //// ok // isOk = true; // // } // } else if (mycondition.contains("<")) { // String substring = mycondition.substring(mycondition.indexOf("<") + 1, mycondition.length() - 1); // if (billMoney < Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">=")) { // String substring = mycondition.substring(mycondition.indexOf(">=") + 2, mycondition.length() - 1); // if (billMoney >= Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains(">")) { // String substring = mycondition.substring(mycondition.indexOf(">") + 1, mycondition.length() - 1); // if (billMoney > Double.valueOf(substring)) { //// ok // isOk = true; // } // } else if (mycondition.contains("==")) { // String substring = mycondition.substring(mycondition.indexOf("==") + 2, mycondition.length() - 1); // BigDecimal data1 = new BigDecimal(billMoney); // BigDecimal data2 = new BigDecimal(substring); // int i2 = data1.compareTo(data2); // if (i2 == 0) { //// ok // isOk = true; // } // } // } // // if (isOk) { // isOkNum = isOkNum + 1; // } // } // if (isOkNum == myconditionExpressions.size()) { // myNextTask = userTask; // } // // if (myNextTask == null) { // continue; // } // // } // } // //================================================================ // boolean end = false; // for (String s : ConstantFlowType.FLOW_ROLES_DEPT) { // if (s.equals(setRurrRole)) {//1.1.1如果是部门关系的查部门 // String leader = currUser.getLeader(); // targetUser = userService.selectByPrimaryKey(leader); // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); // // end = true; // return new HashMap<>(); // } // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES.length; i++) { // if (ConstantFlowType.FLOW_ROLES[i].equals(setRurrRole)) {//1.1.2如果是领导关系的查领导 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); // end = true; // return new HashMap<>(); // } // } // // } // if (!end) { // for (int i = 0; i < ConstantFlowType.FLOW_ROLES_CHECK.length; i++) { // if (ConstantFlowType.FLOW_ROLES_CHECK[i].equals(setRurrRole)) {//1.1.3如果是收纳关系的查收纳 // //查看谁是对应角色并查找对应的人 // String role = ConstantFlowType.ROLES_CHECK[i]; // List targetUserList = flowMainService.findFrameUsersByRoleKey(role, ConstantFlowType.ROLETYPE); // if (!targetUserList.isEmpty()) { // if (targetUserList.size() >= 1) { // targetUser = targetUserList.get(0); // } // } // if (targetUser == null) { // return null; // } // boolean yes = flowService.runTask(task2.getId(), null, "yes", null, targetUser, currUser, conditionMap); // end = true; // return new HashMap<>(); // } // } // } // break; // } // } else { // System.out.println("已经没有下个申请流程了,已经结束了"); // return null; // } // } return this.donaturalTask(deploymentid, currUser, task2, conditionMap,businessId); } else { //还不是自己的角色,还要遍历查找 return getNextFlow(businessId, userPosition, deploymentid, currUser, conditionMap, task2); } } // return null; } /** * 共用方法 //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管), * 但是注意,这只是判断是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的 * * @param currUser * @return */ public String getCurrRole(FrameUser currUser) { //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管) String currRole = "";//flow_fgld", "flow_sjfgld", "flow_zyld或者curr_user,dept_head { //1获取用户流程类型 { String[] flow_roles = ConstantFlowType.FLOW_ROLES;//{"flow_fgld", "flow_sjfgld", "flow_zyld"}; String[] roles = ConstantFlowType.ROLES;// {"fgld", "sjfgld", "zyld"}; // frame_role_data List FrameRoleDatas = flowMainService.findFrameRoleDatasByUserId(currUser.getId(), ConstantFlowType.ROLETYPE);//"FLOW" Integer c = null; //判断用户的最高用户流类型 for (FrameRoleData frameRoleData : FrameRoleDatas) { String roleKey = frameRoleData.getRoleKey(); for (int i = 0; i < roles.length; i++) { if (roles[i].equals(roleKey)) { if (c == null) { c = i; } else if (c < i) { c = i; } break; } } } if (c != null) { currRole = flow_roles[c]; return currRole; } } //2获取用户部门是否是主管 { String department = currUser.getDepartment(); SysDept sysDept = sysDeptService.selectByPrimaryKey(department); if (sysDept == null) {//没有部门信息 if (currRole.equals("")) { currRole = ""; return null; } else { //是领导流程类型 } } else { String changedBy = sysDept.getChangedBy(); if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管 if (currRole.equals("")) { currRole = ""; } else { //是领导流程类型 } return null; } else {//找到部门主管 if (changedBy.equals(currUser.getId())) {//自己是部门主管 if (currRole.equals("")) { currRole = ConstantFlowType.FLOW_ROLES_DEPT[2];//"dept_head"; } else { //是领导流程类型 } } else {//部门主管是别人,自己不是部门主管 //在用该用户作为部门负责人在部门表中再查一次,防止部门的负责人不在此部门中 SysDeptExample sysDeptExample = new SysDeptExample(); sysDeptExample.createCriteria().andChangedByLike(currUser.getId()); List sysDepts = sysDeptService.selectByExample(sysDeptExample); if(CollectionUtils.isNotEmpty(sysDepts)){ if (currRole.equals("")) { currRole = ConstantFlowType.FLOW_ROLES_DEPT[2];//"dept_head"; } else { //是领导流程类型 } }else{ if (currRole.equals("")) { currRole = ConstantFlowType.FLOW_ROLES_DEPT[0];//"curr_user"; } else { //是领导流程类型 } } } } } } } return currRole; } /** * 写一个方法, 已知用户信息 zt ok * 申请付款时 通过用户信号获取用户在全流程中的位置,如果没有找到对象,返回为null就直接提交到admin用户去审核,如果对象里面的nodeNum是1就是正常流程,如果大于1就是非正常流程需要把目标人填自己直到自己流转到自己流程上 */ public UserTaskMore findUserPosition(String currRole, String deploymentid) { //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管) // String currRole = this.getCurrRole(currUser2); //没有获取到角色异常返回null if (currRole == null || currRole.equals("")) { return null; } //获取活动节点 //这是流程排序编号 int nodeNum = 0; List taskList = flowService.getTaskList(deploymentid); UserTask userTask = taskList.get(0); nodeNum = nodeNum + 1; String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no String setRurrRole = this.getSetRurrRole(s); if (currRole.equals(setRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上 // return userTask; // return nodeNum; return new UserTaskMore(userTask, nodeNum, userTask); } else {//要进行轮查获取用户位置 UserTaskMore nextCandidateGroupByDeploy = this.getNextMyUserTask(taskList, currRole, nodeNum); // UserTaskMore nextCandidateGroupByDeploy = getNextCandidateGroupByDeploy(userTask, currRole, nodeNum, deploymentid); nextCandidateGroupByDeploy.setCurrentUserTask(userTask); return nextCandidateGroupByDeploy; } } /** * 申请付款时 通过传递的数据递归获取用户角色实际的运行节点 * * @return */ public UserTaskMore getNextMyUserTask(List taskList, String currRole, Integer nodeNum) { for (int i = 1; i < taskList.size(); i++) { nodeNum = 2; UserTask myuserTask = taskList.get(i); String taskKey = myuserTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no String taskSetRurrRole = this.getSetRurrRole(taskKey); if (currRole.equals(taskSetRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上 System.out.println("2结束节点" + nodeNum); // return userTask; // return nodeNum; return new UserTaskMore(myuserTask, nodeNum); } } return null; } /** * 这个方法有问题,不能获取自己想要的,放弃使用了 * 申请付款时 通过传递的数据递归获取用户角色实际的运行节点 * * @param newUserTask * @param currRole * @param nodeNum * @return */ public UserTaskMore getNextCandidateGroupByDeploy(UserTask newUserTask, String currRole, Integer nodeNum, String deploymentid) { List nextCandidateGroupByDeploy = flowService.getNextCandidateGroupByDeploy(deploymentid, newUserTask.getId(), false); if (!nextCandidateGroupByDeploy.isEmpty() && nextCandidateGroupByDeploy.size() >= 1) { // //进行分支判断 // for (int i = 0; i < nextCandidateGroupByDeploy.size(); i++) { // UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(i); // String taskKey = userTask.getCandidateGroups().get(0);//dept_head_1_0_1-yes // String yesNo = taskKey.substring(taskKey.indexOf("-")); // if (!"yes".equals(yesNo)) { // continue; // } // String setRurrRole = this.getSetRurrRole(taskKey);//获取任务的角色 // // } nodeNum = nodeNum + 1; System.out.println("运行节点" + nodeNum); UserTask userTask = (UserTask) nextCandidateGroupByDeploy.get(0); String s = userTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no String setRurrRole = this.getSetRurrRole(s); if (currRole.equals(setRurrRole)) {//如果设置角色和当前用户角色一致,表示用户就是当前流程排序编号上 System.out.println("1结束节点" + nodeNum); // return userTask; // return nodeNum; return new UserTaskMore(userTask, nodeNum); } else { getNextCandidateGroupByDeploy(userTask, currRole, nodeNum, deploymentid); } } else { return null; } return null; } /** * 通过原key获取角色数据 * * @param s * @return */ public static String getSetRurrRole(String s) { // String s="dept_head_1_0_1-yes";或者curr_user-no String[] s1 = s.contains("-") ? s.substring(0, s.indexOf("-")).split("_") : s.split("_"); s = s1[0] + "_" + s1[1]; // System.out.println(s); return s; } /** * 写一个通用方法,专门根据条件获取部门领导是谁 * targetRole:下一个审核人的角色 * currUser:当前的审核人角色 */ public FrameUser getTargerUser_FLOW_ROLES_DEPT(String targetRole, FrameUser currUser,String businessId) { FrameUser targetUser = null; FlowMain flowMain = flowMainService.selectByPrimaryKey(businessId); if(flowMain!=null){ currUser = userService.selectByPrimaryKey(flowMain.getApplyUser()); } if (targetRole.equals(ConstantFlowType.FLOW_ROLES_DEPT[2])) {//发现下一个审核人是部门领导,要去找部门领导 String department = currUser.getDepartment(); SysDept sysDept = sysDeptService.selectByPrimaryKey(department); if (sysDept == null) {//没有部门信息 } else { String changedBy = sysDept.getChangedBy(); if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管 } else { targetUser = userService.selectByPrimaryKey(changedBy); } } } else { String leader = currUser.getLeader(); if (StringUtils.isEmpty(leader)) {//没有找到直接领导 } else { targetUser = userService.selectByPrimaryKey(leader); } } if (targetUser == null) {//没有找到目标人就都传到admin中去 // return null; System.out.println("6没有找到对应人:" + "if (targetUser == null) {"); targetUser = userService.selectByPrimaryKey(ConstantFlowType.ADMINID); if (targetUser == null) { System.err.println("异常,没有找到目标人"); return null; } } return targetUser; } /** * 共用方法 //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管), * 但是注意,这只是判断是否是主管还是 分管领导的问题, 还没有判断是否是出纳的问题,不是哪里都适用的 * * @param currUser * @return */ public Boolean getHasCurrRole(FrameUser currUser) { //当前用户的角色定义(如果判断下来还是""就是没有确认是否是部门主管) String currRole = "";//flow_fgld", "flow_sjfgld", "flow_zyld或者curr_user,dept_head Boolean currRoleBo = false; { //1获取用户流程类型 { String[] flow_roles = ConstantFlowType.FLOW_ROLES;//{"flow_fgld", "flow_sjfgld", "flow_zyld"}; String[] roles = ConstantFlowType.ROLES;// {"fgld", "sjfgld", "zyld"}; // frame_role_data List FrameRoleDatas = flowMainService.findFrameRoleDatasByUserId(currUser.getId(), ConstantFlowType.ROLETYPE);//"FLOW" Integer c = null; //判断用户的最高用户流类型 for (FrameRoleData frameRoleData : FrameRoleDatas) { if(Arrays.asList(flow_roles).contains(frameRoleData.getRoleKey())){ currRoleBo = true; } } if(currRoleBo)return currRoleBo; } //2获取用户部门是否是主管 { String department = currUser.getDepartment(); SysDept sysDept = sysDeptService.selectByPrimaryKey(department); if (sysDept == null) {//没有部门信息 if (currRole.equals("")) { currRole = ""; return currRoleBo; } else { //是领导流程类型 } } else { String changedBy = sysDept.getChangedBy(); if (StringUtils.isEmpty(changedBy)) {//没有找到部门主管 if (currRole.equals("")) { currRole = ""; } else { //是领导流程类型 } return currRoleBo; } else {//找到部门主管 if (changedBy.equals(currUser.getId())) {//自己是部门主管 if (currRole.equals("")) { currRole = ConstantFlowType.FLOW_ROLES_DEPT[2];//"dept_head"; } else { //是领导流程类型 } } else {//部门主管是别人,自己不是部门主管 //在用该用户作为部门负责人在部门表中再查一次,防止部门的负责人不在此部门中 SysDeptExample sysDeptExample = new SysDeptExample(); sysDeptExample.createCriteria().andChangedByLike(currUser.getId()); List sysDepts = sysDeptService.selectByExample(sysDeptExample); if(CollectionUtils.isNotEmpty(sysDepts)){ if (currRole.equals("")) { currRole = ConstantFlowType.FLOW_ROLES_DEPT[2];//"dept_head"; } else { //是领导流程类型 } }else{ if (currRole.equals("")) { currRole = ConstantFlowType.FLOW_ROLES_DEPT[0];//"curr_user"; } else { //是领导流程类型 } } } } } } } return currRoleBo; } /** * 当sourceTask 的审核人是空的话,跳过该任务节点 * @param sourceTask 当前的任务节点 * @param deploymentId 流程ID * @param currUser 当前操作人 * @param currRole 当前角色 * @param conditionMap * @param businessId flowMainId * @return * @throws com.rockstar.flow.exception.FlowException */ public Map jumpNextNode(Task sourceTask,String deploymentId,FrameUser currUser,String currRole, Map conditionMap, String businessId) throws com.rockstar.flow.exception.FlowException { List taskList = flowService.getTaskList(deploymentId); UserTask myuserTask2 = null; for (int i = 1; i < taskList.size(); i++) { UserTask myuserTask = taskList.get(i); String taskKey = myuserTask.getCandidateGroups().get(0);//s=dept_head_1_0_1-yes/curr_user-no String taskSetRurrRole = this.getSetRurrRole(taskKey); if(taskSetRurrRole.equals(currRole)){ myuserTask2 = myuserTask; break; } } //跳过当前节点 jumpToTask(sourceTask,myuserTask2.getId()); //获取新节点 Task task = null; { List taskList2 = taskService.createTaskQuery().processInstanceBusinessKey(businessId).list(); if (taskList == null || taskList.isEmpty()) { return new HashMap<>(); } task = taskList2.get(0); } //继续正常审核 return donaturalTask(deploymentId,currUser,task,conditionMap,businessId); } private void jumpToTask(Task sourceTask,String targetTaskDefinitionKey){ //取得当前节点的信息 //取得指定节点的信息(TaskDefinitionKey) //保存当前节点的流向 //新建流向,由当前节点指向新节点(指定节点) //当前节点完成任务=流向指定节点 //将当前节点的流向还原 ProcessEngine processEngine = ProcessEngines.getDefaultProcessEngine(); RepositoryService repositoryService = processEngine.getRepositoryService(); TaskService taskService = processEngine.getTaskService(); //获取该工作流的bpmn模板 BpmnModel bpmnModel = repositoryService.getBpmnModel(sourceTask.getProcessDefinitionId()); // 获取当前活动节点 FlowNode currentFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(sourceTask.getTaskDefinitionKey()); // 获取指定活动节点 FlowNode lastFlowNode = (FlowNode) bpmnModel.getMainProcess().getFlowElement(targetTaskDefinitionKey); // 临时保存当前活动的原始方向 ,最后需要用到他恢复正确的方向 List originalSequenceFlowList = new ArrayList<>(); originalSequenceFlowList.addAll(currentFlowNode.getOutgoingFlows()); // 清理当前活动方向 currentFlowNode.getOutgoingFlows().clear(); // 建立新方向 SequenceFlow newSequenceFlow = new SequenceFlow(); newSequenceFlow.setId("newSequenceFlowId");//这个可以随机 newSequenceFlow.setSourceFlowElement(currentFlowNode);//源 newSequenceFlow.setTargetFlowElement(lastFlowNode);//目标 List newSequenceFlowList = new ArrayList<>(); newSequenceFlowList.add(newSequenceFlow); // 当前节点指向新的方向 currentFlowNode.setOutgoingFlows(newSequenceFlowList); // 完成当前任务 = 跳转到指定的节点任务 taskService.complete(sourceTask.getId()); // 恢复原始方向 currentFlowNode.setOutgoingFlows(originalSequenceFlowList); } }