Browse Source

计量系统-任务查看-可审批

DengLinLang 7 months ago
parent
commit
97710e9c7d

+ 107 - 32
blade-service/blade-meter/src/main/java/org/springblade/meter/controller/TaskController.java

@@ -1148,40 +1148,44 @@ public class TaskController extends BladeController {
         /*获取预设流程Map*/
         Map<Long, String> flowMap = jdbcTemplate.query("select id,fixed_flow_name from u_fixed_flow where is_deleted = 0 and contract_id = "+dto.getContractId(), new BeanPropertyRowMapper<>(FixedFlow.class)).stream().collect(Collectors.toMap(FixedFlow::getId, FixedFlow::getFixedFlowName, (key1, key2) -> key1));
 
-        if(ObjectUtil.isNotEmpty(dto.getStatusValue()) && dto.getStatusValue() .equals(4) ){
+        //筛选出可审批的数据
+         if(ObjectUtil.isNotEmpty(dto.getStatusValue()) && dto.getStatusValue() .equals(4) && ObjectUtil.isNotEmpty(resultList)){
             //获取当前用户id
             Long userId = AuthUtil.getUserId();
-            //根据条件过滤出可审批的数据
-            Map<Long, List<Task>> flowIdMaps = resultList.stream().collect(Collectors.groupingBy(Task::getFixedFlowId));
-            String join = StringUtils.join(flowIdMaps.keySet(), ",");
-            //结果集中垂直审批的数据
-            String sql = "select distinct fixed_flow_id from u_fixed_flow_link where  is_deleted = 0  and fixed_flow_link_type = 1 and  fixed_flow_id in ( "+join+")";
-            List<FixedFlowLink> fixedFlowLinks = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(FixedFlowLink.class));
-            for (FixedFlowLink fixedFlowLink : fixedFlowLinks) {
-                List<Task> tasks = flowIdMaps.get(fixedFlowLink.getFixedFlowId());
-                for (Task task : tasks) {
-                    //当前任务的processInstanceId
-                    String processInstanceId = task.getProcessInstanceId();
-                    String sqlForTaskParallel = "select task_user ,status,sort from u_task_parallel where is_deleted = 0 and process_instance_id = "+processInstanceId;
-                    List<TaskParallel> taskParallels = jdbcTemplate.query(sqlForTaskParallel, new BeanPropertyRowMapper<>(TaskParallel.class));
-                    //按照sort升序排序
-                    taskParallels.sort(Comparator.comparingInt(TaskParallel::getSort));
-                    boolean isApprove = true;
-                    for (TaskParallel taskParallel : taskParallels) {
-                        if(taskParallel.getTaskUser().toString().equals(userId.toString())){
-                            break;
-                        }else {
-                            if(taskParallel.getStatus() != 2){//不为2说明 还未审批
-                                isApprove = false;
-                                break;
-                            }
-                        }
+
+            String processIdsStr = resultList.stream().map(task -> task.getProcessInstanceId()).collect(Collectors.joining(","));
+            //查询出所有proccesId的数据转换成map  map为processId键为u_task_papallel对象
+            Map<String, List<TaskParallel>> taskParallelMap = jdbcTemplate.query("select * from u_task_parallel where process_instance_id in (" + processIdsStr + ")", new BeanPropertyRowMapper<>(TaskParallel.class)).stream().collect(Collectors.groupingBy(TaskParallel::getProcessInstanceId));
+
+            //根据条件过滤出可审批的数据(流程审批-非自定义流程)   flowid为0的是自定义审批的流程
+            Map<Long, List<Task>> flowIdMaps = resultList.stream().filter(task->!"0".equals(task.getFixedFlowId().toString())).collect(Collectors.groupingBy(Task::getFixedFlowId));
+            if(ObjectUtil.isNotEmpty(flowIdMaps)){
+                String join = StringUtils.join(flowIdMaps.keySet(), ",");
+                //结果集所有数据
+                String sql = "select fixed_flow_id ,fixed_flow_branch_sort,fixed_flow_link_type,fixed_flow_link_sort from u_fixed_flow_link where  is_deleted = 0  and  fixed_flow_id in ( "+join+")";
+                List<FixedFlowLink> fixedFlowLinks = jdbcTemplate.query(sql, new BeanPropertyRowMapper<>(FixedFlowLink.class));
+                Map<Long, List<FixedFlowLink>> fixedsMap = fixedFlowLinks.stream().collect(Collectors.groupingBy(FixedFlowLink::getFixedFlowId));
+                for (Long l : flowIdMaps.keySet()) {
+                    List<Task> tasks = flowIdMaps.get(l);
+                    for (Task task : tasks) {
+                        handleTaskParallel1(task,fixedsMap, taskParallelMap,userId, resultList);
                     }
-                    if(!isApprove){//不可审批的数据
-                        resultList.remove(task);
-                    }else {
-                        //可审批的数据设置他的状态为4
-                        resultList.stream().filter(task2 -> task2.getId().equals(task.getId())).findFirst().ifPresent(task1->task1.setStatus(4));
+                }
+            }
+            //自定义流程判断 查询出所有垂直审批的项目
+            //String sqlForchuizhi = "select id from m_project_info where approval_type = 1 and is_deleted = 0";
+            //目前默认所有项目都是垂直审批  上面的注释掉的是以后要用的内容 1为垂直审批2为流程审批
+            String sqlForchuizhi = "select id from m_project_info where  is_deleted = 0";
+            List<Long> projectIds = jdbcTemplate.query(sqlForchuizhi, new BeanPropertyRowMapper<>(ProjectInfo.class)).stream().map(ProjectInfo::getId).collect(Collectors.toList());
+            if(ObjectUtil.isNotEmpty(projectIds)){
+                //所有自定义审批的任务
+                Set<Task> tasks = resultList.stream().filter(task -> "0".equals(task.getFixedFlowId().toString())).collect(Collectors.toSet());
+                if(ObjectUtil.isNotEmpty(tasks)){
+                    for (Task task : tasks) {
+                        if(projectIds.contains(Long.parseLong(task.getProjectId()))){
+                            //是自定义垂直审批
+                            handleTaskParallel(task, taskParallelMap,userId, resultList);
+                        }
                     }
                 }
             }
@@ -1194,7 +1198,7 @@ public class TaskController extends BladeController {
             vo.setId(task.getId());
             vo.setTaskName(task.getTaskName());
             vo.setTaskTypeName(task.getType().equals(1) ? "普通任务" : task.getType().equals(2) ? "验收任务" : "移交任务");
-            vo.setTaskStatusName(task.getStatus().equals(1) ? "待审批" : task.getStatus().equals(2) ? "已审批" : task.getStatus().equals(4) ? "可审批" : "已废除");
+            vo.setTaskStatusName(task.getStatus().equals(1) ? "待审批" : task.getStatus().equals(2) ? "已审批" : "已废除");
             vo.setStartTime(task.getStartTime());
             vo.setEndTime(task.getEndTime());
             vo.setType(task.getType());
@@ -1250,6 +1254,77 @@ public class TaskController extends BladeController {
         return R.data(page);
     }
 
+    private void handleTaskParallel1(Task task, Map<Long, List<FixedFlowLink>> fixedsMap, Map<String, List<TaskParallel>> taskParallelMap, Long userId, List<Task> resultList) {
+        Long fixedFlowId = task.getFixedFlowId();
+        String processInstanceId = task.getProcessInstanceId();
+        //查出当前电签到的节点sort
+        List<TaskParallel> taskParallels = taskParallelMap.get(processInstanceId);
+        Optional<Integer> sortDq = taskParallels.stream()
+                .filter(t -> t.getStatus() == 1)
+                .min(Comparator.comparing(TaskParallel::getSort))
+                .map(TaskParallel::getSort);
+        //获取当前用户的sort值
+        List<Integer> userSort = taskParallels.stream()
+                .filter(t -> t.getTaskUser().equals(userId.toString()))
+                .sorted(Comparator.comparing(TaskParallel::getSort))
+                .map(TaskParallel::getSort).collect(Collectors.toList());
+        Integer dqSort = sortDq.get();
+        if(ObjectUtil.isNotEmpty(dqSort)){
+            List<Integer> list1 = userSort.stream().filter(a -> dqSort.compareTo(a) <= 0).collect(Collectors.toList());
+            if(ObjectUtil.isEmpty(list1)){
+                //当前用户已经签字过
+                resultList.remove(task);
+            }else {
+                //筛选出最近的一条没有电签的当前用户的sort
+                Integer userMinSort = Collections.min(list1);
+                if(userMinSort.toString().equals(dqSort.toString())){
+                    //当前用户就是下一个电签用户 可审批 放行
+                    return;
+                }
+                List<FixedFlowLink> fixedFlowLinks = fixedsMap.get(fixedFlowId);
+                Optional<FixedFlowLink> dqFlowLink = fixedFlowLinks.stream().filter(f -> f.getFixedFlowBranchSort().equals(dqSort)).findFirst();
+                Optional<FixedFlowLink> userFlowLink = fixedFlowLinks.stream().filter(f -> f.getFixedFlowBranchSort().equals(userMinSort)).findFirst();
+                if(dqFlowLink.get().getFixedFlowLinkSort() == userFlowLink.get().getFixedFlowLinkSort()){
+                    //在同一个小流程里面去判断是否垂直还是水平
+                    if(dqFlowLink.get().getFixedFlowLinkType() == 2){//平行
+                        //通过
+                        return;
+                    }else {
+                        resultList.remove(task);
+                    }
+                }else {
+                    //不在一个小流程 不可审批
+                    resultList.remove(task);
+                }
+            }
+        }else {
+            //全部签完了 肯定不是可审批
+            resultList.remove(task);
+        }
+    }
+
+    //判断当前任务当前用户是否可审批  如果不可审批则从resultList中删除
+    private void handleTaskParallel(Task task,Map<String, List<TaskParallel>> map, Long userId, List<Task> resultList) {
+        String processInstanceId = task.getProcessInstanceId();
+        List<TaskParallel> taskParallels = map.get(processInstanceId.toString());
+        //按照sort升序排序
+        taskParallels.sort(Comparator.comparingInt(TaskParallel::getSort));
+        boolean isApprove = true;
+        for (TaskParallel taskParallel : taskParallels) {
+            if(taskParallel.getTaskUser().toString().equals(userId.toString())){
+                break;
+            }else {
+                if(taskParallel.getStatus() != 2){//不为2说明 还未审批  流程未到当前用户 不可审批
+                    isApprove = false;
+                    break;
+                }
+            }
+        }
+        if(!isApprove){//不可审批的数据
+            resultList.remove(task);
+        }
+    }
+
     /**
      * 任务详情
      */