jihs 3 years ago
parent
commit
6ce716a124

+ 1 - 1
jeecg-boot/jeecg-boot-base-common/src/main/java/org/jeecg/common/system/api/ISysBaseAPI.java

@@ -272,6 +272,6 @@ public interface ISysBaseAPI {
 	public String upload(MultipartFile file,String bizPath,String uploadType);
 	public String upload(MultipartFile file,String bizPath,String uploadType);
 
 
 
 
-	public List<String> getDepartById(String id);
+	public List<String> getDepartByUsername(String username);
 
 
 }
 }

+ 84 - 5
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/service/Impl/ActZprocessServiceImpl.java

@@ -2,8 +2,11 @@ package org.jeecg.modules.activiti.service.Impl;
 
 
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.collection.CollUtil;
 import cn.hutool.core.util.StrUtil;
 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.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
 import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import com.google.common.collect.Maps;
 import org.activiti.bpmn.model.Process;
 import org.activiti.bpmn.model.Process;
 import org.activiti.bpmn.model.*;
 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.PvmTransition;
 import org.activiti.engine.impl.pvm.process.ActivityImpl;
 import org.activiti.engine.impl.pvm.process.ActivityImpl;
 import org.activiti.engine.runtime.ProcessInstance;
 import org.activiti.engine.runtime.ProcessInstance;
+import org.activiti.engine.task.IdentityLink;
 import org.activiti.engine.task.Task;
 import org.activiti.engine.task.Task;
 import org.apache.shiro.SecurityUtils;
 import org.apache.shiro.SecurityUtils;
 import org.jeecg.common.exception.JeecgBootException;
 import org.jeecg.common.exception.JeecgBootException;
@@ -128,7 +132,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
         for(Task task : tasks){
         for(Task task : tasks){
             if(actBusiness.getFirstGateway()){
             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){
                 if(users==null||users.size()==0){
                     throw new RuntimeException("任务节点未分配任何候选审批人,发起流程失败");
                     throw new RuntimeException("任务节点未分配任何候选审批人,发起流程失败");
@@ -223,13 +227,21 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
     }
     }
 
 
     public ProcessNodeVo getNode(String nodeId) {
     public ProcessNodeVo getNode(String nodeId) {
-
         ProcessNodeVo node = new ProcessNodeVo();
         ProcessNodeVo node = new ProcessNodeVo();
         // 设置关联用户
         // 设置关联用户
         List<LoginUser> users = getNodetUsers(nodeId);
         List<LoginUser> users = getNodetUsers(nodeId);
         node.setUsers(removeDuplicate(users));
         node.setUsers(removeDuplicate(users));
         return node;
         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
      * @param nodeId
@@ -264,7 +276,73 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
         if(actNodeService.hasChooseDepHeader2(nodeId)){
         if(actNodeService.hasChooseDepHeader2(nodeId)){
             List<LoginUser> allUser = actNodeService.queryAllUser();
             List<LoginUser> allUser = actNodeService.queryAllUser();
             LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
             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) {
             for (String departId : departIds) {
                 List<LoginUser> collect = allUser.stream().filter(u -> u.getDepartIds() != null && u.getDepartIds().indexOf(departId) > -1).collect(Collectors.toList());
                 List<LoginUser> collect = allUser.stream().filter(u -> u.getDepartIds() != null && u.getDepartIds().indexOf(departId) > -1).collect(Collectors.toList());
                 users.addAll(collect);
                 users.addAll(collect);
@@ -281,6 +359,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
         return users;
         return users;
     }
     }
 
 
+
     /**
     /**
      * 去重
      * 去重
      * @param list
      * @param list
@@ -347,7 +426,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
         return node;
         return node;
     }
     }
 
 
-    public ProcessNodeVo getNextNode(String procDefId, String currActId) {
+    public ProcessNodeVo getNextNode(String procDefId, String currActId, String procInstId) {
         ProcessNodeVo node = new ProcessNodeVo();
         ProcessNodeVo node = new ProcessNodeVo();
 
 
         // 当前执行节点id
         // 当前执行节点id
@@ -368,7 +447,7 @@ public class ActZprocessServiceImpl extends ServiceImpl<ActZprocessMapper, ActZp
                     node.setType(ActivitiConstant.NODE_TYPE_TASK);
                     node.setType(ActivitiConstant.NODE_TYPE_TASK);
                     node.setTitle(pvmActivity.getProperty("name").toString());
                     node.setTitle(pvmActivity.getProperty("name").toString());
                     // 设置关联用户
                     // 设置关联用户
-                    List<LoginUser> users = getNodetUsers(pvmActivity.getId());
+                   List<LoginUser> users = getNodetUsers2(pvmActivity.getId(), procInstId);
                     node.setUsers(removeDuplicate(users));
                     node.setUsers(removeDuplicate(users));
                 }else if("exclusiveGateway".equals(type)){
                 }else if("exclusiveGateway".equals(type)){
                     // 排他网关
                     // 排他网关

+ 1 - 1
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/web/ActTaskController.java

@@ -384,7 +384,7 @@ public class ActTaskController {
             for(Task t : tasks){
             for(Task t : tasks){
                 if(StrUtil.isBlank(assignees)){
                 if(StrUtil.isBlank(assignees)){
                     // 如果下个节点未分配审批人为空 取消结束流程
                     // 如果下个节点未分配审批人为空 取消结束流程
-                    List<LoginUser> users = actZprocessService.getNode(t.getTaskDefinitionKey()).getUsers();
+                    List<LoginUser> users = actZprocessService.getNode2(t.getTaskDefinitionKey(), procInstId).getUsers();
                     if(users==null||users.size()==0){
                     if(users==null||users.size()==0){
                         runtimeService.deleteProcessInstance(procInstId, "canceled-审批节点未分配审批人,流程自动中断取消");
                         runtimeService.deleteProcessInstance(procInstId, "canceled-审批节点未分配审批人,流程自动中断取消");
                         actBusiness.setStatus(ActivitiConstant.STATUS_CANCELED);
                         actBusiness.setStatus(ActivitiConstant.STATUS_CANCELED);

+ 5 - 4
jeecg-boot/jeecg-boot-module-activiti/src/main/java/org/jeecg/modules/activiti/web/ActivitiProcessController.java

@@ -369,15 +369,16 @@ public class ActivitiProcessController {
     @RequestMapping(value = "/getNextNode", method = RequestMethod.GET)
     @RequestMapping(value = "/getNextNode", method = RequestMethod.GET)
     @ApiOperation(value = "通过当前节点定义id获取下一个节点")
     @ApiOperation(value = "通过当前节点定义id获取下一个节点")
     public Result getNextNode(@ApiParam("当前节点定义id")  String procDefId,
     public Result getNextNode(@ApiParam("当前节点定义id")  String procDefId,
-                             @ApiParam("当前节点定义id")  String currActId){
-        ProcessNodeVo node = actZprocessService.getNextNode(procDefId, currActId);
+                             @ApiParam("当前节点定义id")  String currActId,
+                              String procInstId){
+        ProcessNodeVo node = actZprocessService.getNextNode(procDefId, currActId, procInstId);
         return Result.ok(node);
         return Result.ok(node);
     }
     }
     @RequestMapping(value = "/getNode/{nodeId}", method = RequestMethod.GET)
     @RequestMapping(value = "/getNode/{nodeId}", method = RequestMethod.GET)
     @ApiOperation(value = "通过节点nodeId获取审批人")
     @ApiOperation(value = "通过节点nodeId获取审批人")
     public Result getNode(@ApiParam("节点nodeId") @PathVariable String nodeId){
     public Result getNode(@ApiParam("节点nodeId") @PathVariable String nodeId){
-
-        ProcessNodeVo node = actZprocessService.getNode(nodeId);
+        String[] str = nodeId.split("&");
+        ProcessNodeVo node = actZprocessService.getNode2(str[0], str[1]);
         return Result.ok(node);
         return Result.ok(node);
     }
     }
 }
 }

+ 3 - 3
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/mapper/SysDepartMapper.java

@@ -51,7 +51,7 @@ public interface SysDepartMapper extends BaseMapper<SysDepart> {
 	 * @return
 	 * @return
 	 */
 	 */
 	List<String> getSubDepIdsByOrgCodes(@org.apache.ibatis.annotations.Param("orgCodes") String[] orgCodes);
 	List<String> getSubDepIdsByOrgCodes(@org.apache.ibatis.annotations.Param("orgCodes") String[] orgCodes);
-
-	@Select("select id from sys_depart WHERE id in (SELECT parent_id FROM sys_depart WHERE  id in (SELECT  dep_id FROM sys_user_depart WHERE user_id = #{id}))")
-    List<String> getDepartById(@Param("id") String id);
+//	@Select("select id from sys_depart WHERE id in (SELECT parent_id FROM sys_depart WHERE  id in (SELECT  dep_id FROM sys_user_depart WHERE user_id = #{id}))")
+	@Select("select id from sys_depart WHERE id in (SELECT parent_id FROM sys_depart WHERE  id in (SELECT  dep_id FROM sys_user_depart WHERE user_id = (SELECT id  FROM sys_user WHERE username = #{username})))")
+    List<String> getDepartByUsername(@Param("username") String username);
 }
 }

+ 1 - 1
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/ISysDepartService.java

@@ -103,5 +103,5 @@ public interface ISysDepartService extends IService<SysDepart>{
      */
      */
     List<String> getMySubDepIdsByDepId(String departIds);
     List<String> getMySubDepIdsByDepId(String departIds);
 
 
-    List<String> getDepartById(String id);
+    List<String> getDepartByUsername(String username);
 }
 }

+ 2 - 2
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysBaseApiImpl.java

@@ -637,8 +637,8 @@ public class SysBaseApiImpl implements ISysBaseAPI {
 	}
 	}
 
 
 	@Override
 	@Override
-	public List<String> getDepartById(String id) {
-		return sysDepartService.getDepartById(id);
+	public List<String> getDepartByUsername(String username) {
+		return sysDepartService.getDepartByUsername(username);
 	}
 	}
 
 
 }
 }

+ 2 - 2
jeecg-boot/jeecg-boot-module-system/src/main/java/org/jeecg/modules/system/service/impl/SysDepartServiceImpl.java

@@ -236,8 +236,8 @@ public class SysDepartServiceImpl extends ServiceImpl<SysDepartMapper, SysDepart
 	}
 	}
 
 
 	@Override
 	@Override
-	public List<String> getDepartById(String id) {
-		return baseMapper.getDepartById(id);
+	public List<String> getDepartByUsername(String username) {
+		return baseMapper.getDepartByUsername(username);
 	}
 	}
 
 
 	/**
 	/**