Bladeren bron

故障上报

lipenghui 1 maand geleden
bovenliggende
commit
fc16f92ea1

+ 96 - 0
yudao-module-bpm/yudao-module-bpm-biz/src/main/java/cn/iocoder/yudao/module/bpm/framework/flowable/core/candidate/expression/BpmTaskPostExpression.java

@@ -0,0 +1,96 @@
+package cn.iocoder.yudao.module.bpm.framework.flowable.core.candidate.expression;
+
+import cn.hutool.core.collection.CollUtil;
+import cn.hutool.core.lang.Assert;
+import cn.iocoder.yudao.framework.common.exception.ErrorCode;
+import cn.iocoder.yudao.framework.common.exception.ServiceException;
+import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
+import cn.iocoder.yudao.module.bpm.service.task.BpmProcessInstanceService;
+import cn.iocoder.yudao.module.system.api.dept.DeptApi;
+import cn.iocoder.yudao.module.system.api.dept.PostApi;
+import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
+import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
+import cn.iocoder.yudao.module.system.api.dict.DictDataApi;
+import cn.iocoder.yudao.module.system.api.dict.dto.DictDataRespDTO;
+import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
+import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
+import org.flowable.engine.delegate.DelegateExecution;
+import org.flowable.engine.runtime.ProcessInstance;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Component;
+
+import javax.annotation.Resource;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import static java.util.Collections.emptySet;
+
+@Component
+public class BpmTaskPostExpression {
+    @Resource
+    private AdminUserApi adminUserApi;
+    @Resource
+    private DeptApi deptApi;
+    @Resource
+    private BpmProcessInstanceService processInstanceService;
+    @Autowired
+    private DictDataApi dictDataApi;
+    @Autowired
+    private PostApi postApi;
+
+
+    public Set<Long> calculateUsers(DelegateExecution execution, int level) {
+        Assert.isTrue(level>0, "leve必须大于0");
+        ProcessInstance processInstance = processInstanceService.getProcessInstance(execution.getProcessInstanceId());
+        Long startId = NumberUtils.parseLong(processInstance.getStartUserId());
+        DeptRespDTO dept = null;
+        for (int i = 0; i < level; i++) {
+            // 获得 level 对应的部门
+            if (dept == null) {
+                dept = getStartUserDept(startId);
+                if (dept == null) { // 找不到发起人的部门,所以无法使用该规则
+                    return emptySet();
+                }
+            } else {
+                DeptRespDTO parentDept = deptApi.getDept(dept.getParentId());
+                if (parentDept == null) { // 找不到父级部门,所以只好结束寻找。原因是:例如说,级别比较高的人,所在部门层级比较少
+                    break;
+                }
+                dept = parentDept;
+            }
+        }
+        if (dept == null) {
+            throw new ServiceException(new ErrorCode(12,"部门不存在"));
+        }
+        Long deptId = dept.getId();
+        List<DictDataRespDTO> dictDataList = dictDataApi.getDictDataList("failure_report_post");
+        if (CollUtil.isEmpty(dictDataList)) {
+            throw new ServiceException();
+        }
+        String label = dictDataList.get(0).getLabel();
+        PostRespDTO postByName = postApi.getPostByName(label);
+        if (postByName == null) {
+            throw new ServiceException();
+        }
+        Set<Long> users = adminUserApi.getUserListByDept(deptId).stream().filter(e -> {
+            if (CollUtil.isNotEmpty(e.getPostIds())) {
+                return e.getPostIds().contains(postByName.getId());
+            } else {
+                return false;
+            }
+        }).map(AdminUserRespDTO::getId).collect(Collectors.toSet());
+//        List<Long> roleUserIds = roleApi.getRoleUserIds("公司设备管理");
+//        Set<Long> collect = users.stream().filter(roleUserIds::contains).collect(Collectors.toSet());
+//        return collect;
+        return users;
+    }
+
+    private DeptRespDTO getStartUserDept(Long startUserId) {
+        AdminUserRespDTO startUser = adminUserApi.getUser(startUserId);
+        if (startUser.getDeptId() == null) { // 找不到部门,所以无法使用该规则
+            return null;
+        }
+        return deptApi.getDept(startUser.getDeptId());
+    }
+}

+ 2 - 0
yudao-module-system/yudao-module-system-api/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApi.java

@@ -36,4 +36,6 @@ public interface PostApi {
         return CollectionUtils.convertMap(list, PostRespDTO::getId);
     }
 
+
+    PostRespDTO getPostByName(String postName);
 }

+ 6 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dept/PostApiImpl.java

@@ -32,4 +32,10 @@ public class PostApiImpl implements PostApi {
         return BeanUtils.toBean(list, PostRespDTO.class);
     }
 
+    @Override
+    public PostRespDTO getPostByName(String postName) {
+        PostDO post = postService.getPostsByName(postName);
+        return BeanUtils.toBean(post, PostRespDTO.class);
+    }
+
 }

+ 1 - 1
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostService.java

@@ -15,7 +15,7 @@ import java.util.List;
  * @author 芋道源码
  */
 public interface PostService {
-
+    PostDO getPostsByName(String name);
     /**
      * 创建岗位
      *

+ 6 - 0
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/service/dept/PostServiceImpl.java

@@ -33,6 +33,12 @@ public class PostServiceImpl implements PostService {
     @Resource
     private PostMapper postMapper;
 
+    @Override
+    public PostDO getPostsByName(String name) {
+        PostDO postDO = postMapper.selectByName(name);
+        return postDO;
+    }
+
     @Override
     public Long createPost(PostSaveReqVO createReqVO) {
         // 校验正确性