Browse Source

解决机构下无用户还不能删除的问题

dzx 1 year ago
parent
commit
63a5b90bfa

+ 10 - 5
src/main/java/com/xjrsoft/module/organization/controller/DepartmentController.java

@@ -10,8 +10,10 @@ import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
 import com.baomidou.mybatisplus.core.toolkit.StringPool;
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.fasterxml.jackson.core.type.TypeReference;
+import com.github.yulichang.wrapper.MPJLambdaWrapper;
 import com.xjrsoft.common.annotation.XjrLog;
 import com.xjrsoft.common.constant.GlobalConstant;
+import com.xjrsoft.common.enums.DeleteMark;
 import com.xjrsoft.common.enums.YesOrNoEnum;
 import com.xjrsoft.common.model.result.R;
 import com.xjrsoft.common.page.ConventPage;
@@ -228,11 +230,14 @@ public class DepartmentController {
     @XjrLog(value = "删除机构")
     public R delete(@RequestBody List<Long> ids) {
         //删除岗位时,需要判断,此机构下是不是存在人员,存在人员就不能删除
-        List<UserDeptRelation> userDeptRelationList = redisUtil.get(GlobalConstant.USER_DEPT_RELATION_CACHE_KEY, new TypeReference<List<UserDeptRelation>>() {
-        });
-        //拿ids进行过滤,如果存在,就不能删除
-        List<UserDeptRelation> users = userDeptRelationList.stream().filter(u -> ids.contains(u.getDeptId())).collect(Collectors.toList());
-        if (users.size()>0){
+        Integer count = userService.selectJoinCount(
+                new MPJLambdaWrapper<User>()
+                        .leftJoin(" xjr_user_dept_relation t1 on t.id = t1.user_id")
+                        .in("t1.dept_id", ids)
+                        .eq(User::getDeleteMark, DeleteMark.NODELETE.getCode())
+        );
+
+        if (count > 0){
             return R.error("此机构下存在用户!");
         }
         departmentService.removeBatchByIds(ids);