|
@@ -2,8 +2,11 @@ package org.jeecg.modules.activiti.service.Impl;
|
|
|
|
|
|
import cn.hutool.core.collection.CollUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
+import com.google.common.collect.Lists;
|
|
|
import com.google.common.collect.Maps;
|
|
|
import org.activiti.bpmn.model.Process;
|
|
|
import org.activiti.bpmn.model.*;
|
|
@@ -17,6 +20,7 @@ import org.activiti.engine.impl.pvm.PvmActivity;
|
|
|
import org.activiti.engine.impl.pvm.PvmTransition;
|
|
|
import org.activiti.engine.impl.pvm.process.ActivityImpl;
|
|
|
import org.activiti.engine.runtime.ProcessInstance;
|
|
|
+import org.activiti.engine.task.IdentityLink;
|
|
|
import org.activiti.engine.task.Task;
|
|
|
import org.apache.shiro.SecurityUtils;
|
|
|
import org.jeecg.common.exception.JeecgBootException;
|
|
@@ -128,7 +132,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
|
|
|
for(Task task : tasks){
|
|
|
if(actBusiness.getFirstGateway()){
|
|
|
// 网关类型
|
|
|
- List<LoginUser> users = getNode(task.getTaskDefinitionKey()).getUsers();
|
|
|
+ List<LoginUser> users = getNode2(task.getTaskDefinitionKey(), pi.getId()).getUsers();
|
|
|
// 如果下个节点未分配审批人为空 取消结束流程
|
|
|
if(users==null||users.size()==0){
|
|
|
throw new RuntimeException("任务节点未分配任何候选审批人,发起流程失败");
|
|
@@ -223,13 +227,21 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
|
|
|
}
|
|
|
|
|
|
public ProcessNodeVo getNode(String nodeId) {
|
|
|
-
|
|
|
ProcessNodeVo node = new ProcessNodeVo();
|
|
|
// 设置关联用户
|
|
|
List<LoginUser> users = getNodetUsers(nodeId);
|
|
|
node.setUsers(removeDuplicate(users));
|
|
|
return node;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ public ProcessNodeVo getNode2(String nodeId, String procInstId) {
|
|
|
+ ProcessNodeVo node = new ProcessNodeVo();
|
|
|
+ // 设置关联用户
|
|
|
+ List<LoginUser> users = getNodetUsers2(nodeId, procInstId);
|
|
|
+ node.setUsers(removeDuplicate(users));
|
|
|
+ return node;
|
|
|
+ }
|
|
|
/**
|
|
|
* 设置节点审批人
|
|
|
* @param nodeId
|
|
@@ -264,7 +276,73 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
|
|
|
if(actNodeService.hasChooseDepHeader2(nodeId)){
|
|
|
List<LoginUser> allUser = actNodeService.queryAllUser();
|
|
|
LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
- List<String> departIds = sysBaseAPI.getDepartById(user.getId());
|
|
|
+ List<String> departIds = sysBaseAPI.getDepartByUsername(user.getUsername());
|
|
|
+ for (String departId : departIds) {
|
|
|
+ List<LoginUser> collect = allUser.stream().filter(u -> u.getDepartIds() != null && u.getDepartIds().indexOf(departId) > -1).collect(Collectors.toList());
|
|
|
+ users.addAll(collect);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 判断获取发起人
|
|
|
+ if(actNodeService.hasChooseSponsor(nodeId)){
|
|
|
+ LoginUser loginUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
|
|
|
+ users.add(loginUser);
|
|
|
+ }
|
|
|
+ users = users.stream().filter(u->StrUtil.equals("0",u.getDelFlag())).collect(Collectors.toList());
|
|
|
+ return users;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 设置节点审批人
|
|
|
+ * @param nodeId
|
|
|
+ */
|
|
|
+ public List<LoginUser> getNodetUsers2(String nodeId, String procInstId){
|
|
|
+ List<LoginUser> users = actNodeService.findUserByNodeId(nodeId);
|
|
|
+ // 设置关联角色的用户
|
|
|
+ List<Role> roles = actNodeService.findRoleByNodeId(nodeId);
|
|
|
+ for(Role r : roles){
|
|
|
+ List<LoginUser> userList = actNodeService.findUserByRoleId(r.getId());
|
|
|
+ users.addAll(userList);
|
|
|
+ }
|
|
|
+ // 设置关联部门负责人
|
|
|
+ List<Department> departments = actNodeService.findDepartmentByNodeId(nodeId);
|
|
|
+ for (Department d : departments){
|
|
|
+ List<LoginUser> userList = actNodeService.findUserDepartmentId(d.getId());
|
|
|
+ users.addAll(userList);
|
|
|
+ }
|
|
|
+ // 判断获取部门负责人
|
|
|
+ if(actNodeService.hasChooseDepHeader(nodeId)){
|
|
|
+ List<LoginUser> allUser = actNodeService.queryAllUser();
|
|
|
+ List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(procInstId);
|
|
|
+ List<String> departIds = Lists.newArrayList();
|
|
|
+ for(IdentityLink ik : identityLinks){
|
|
|
+ // 关联发起人
|
|
|
+ if("starter".equals(ik.getType())&&StrUtil.isNotBlank(ik.getUserId())){
|
|
|
+ departIds = sysBaseAPI.getDepartIdsByUsername(ik.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+// List<String> departIds = sysBaseAPI.getDepartIdsByUsername(loginUser.getUsername());
|
|
|
+ for (String departId : departIds) {
|
|
|
+ List<LoginUser> collect = allUser.stream().filter(u -> u.getDepartIds() != null && u.getDepartIds().indexOf(departId) > -1).collect(Collectors.toList());
|
|
|
+ users.addAll(collect);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //根据当前用户配置负责人
|
|
|
+ if(actNodeService.hasChooseDepHeader2(nodeId)){
|
|
|
+ List<LoginUser> allUser = actNodeService.queryAllUser();
|
|
|
+ List<IdentityLink> identityLinks = runtimeService.getIdentityLinksForProcessInstance(procInstId);
|
|
|
+ List<String> departIds = Lists.newArrayList();
|
|
|
+ for(IdentityLink ik : identityLinks){
|
|
|
+ // 关联发起人
|
|
|
+ if("starter".equals(ik.getType())&&StrUtil.isNotBlank(ik.getUserId())){
|
|
|
+// tv.setApplyer(sysBaseAPI.getUserByName(ik.getUserId()).getRealname());
|
|
|
+ departIds = sysBaseAPI.getDepartByUsername(ik.getUserId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
for (String departId : departIds) {
|
|
|
List<LoginUser> collect = allUser.stream().filter(u -> u.getDepartIds() != null && u.getDepartIds().indexOf(departId) > -1).collect(Collectors.toList());
|
|
|
users.addAll(collect);
|
|
@@ -281,6 +359,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
|
|
|
return users;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
/**
|
|
|
* 去重
|
|
|
* @param list
|
|
@@ -347,7 +426,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
|
|
|
return node;
|
|
|
}
|
|
|
|
|
|
- public ProcessNodeVo getNextNode(String procDefId, String currActId) {
|
|
|
+ public ProcessNodeVo getNextNode(String procDefId, String currActId, String procInstId) {
|
|
|
ProcessNodeVo node = new ProcessNodeVo();
|
|
|
|
|
|
// 当前执行节点id
|
|
@@ -368,7 +447,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
|
|
|
node.setType(ActivitiConstant.NODE_TYPE_TASK);
|
|
|
node.setTitle(pvmActivity.getProperty("name").toString());
|
|
|
// 设置关联用户
|
|
|
- List<LoginUser> users = getNodetUsers(pvmActivity.getId());
|
|
|
+ List<LoginUser> users = getNodetUsers2(pvmActivity.getId(), procInstId);
|
|
|
node.setUsers(removeDuplicate(users));
|
|
|
}else if("exclusiveGateway".equals(type)){
|
|
|
// 排他网关
|