Procházet zdrojové kódy

获取部门及用户列表

tags/v1.0.0^2
chengwang před 1 rokem
rodič
revize
08425b3618
7 změnil soubory, kde provedl 87 přidání a 1 odebrání
  1. +8
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/DeptController.java
  2. +9
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/UserController.java
  3. +2
    -1
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/DataPermissionEnum.java
  4. +2
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IDeptService.java
  5. +3
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IUserService.java
  6. +48
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/DeptServiceImpl.java
  7. +15
    -0
      tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/IUserServiceImpl.java

+ 8
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/DeptController.java Zobrazit soubor

@@ -32,6 +32,14 @@ public class DeptController {
return iDeptService.test(id);
}

/**
* 根据当前登录用户获取部门列表
* @return
*/
@GetMapping("/list")
public JsonResult list(){
return iDeptService.list();
}




+ 9
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/controller/UserController.java Zobrazit soubor

@@ -39,6 +39,15 @@ public class UserController {
return iUserService.resetPwd(dto);
}

/**
* 根据部门id获取用户信息
* @return
*/
@GetMapping("/getList")
public JsonResult getList(){
return iUserService.getList();
}





+ 2
- 1
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/enums/DataPermissionEnum.java Zobrazit soubor

@@ -16,7 +16,8 @@ public enum DataPermissionEnum {

ALL(1,"查看所有部门数据"),
DEPT_AND_SUB_DEPT(2,"查看本部门及子部门数据"),
DEPT(3,"查看本部门数据");
DEPT(3,"查看本部门数据"),
DATA_PERMISSION_IS_NOT_EXIST(4,"用户数据权限为空");

DataPermissionEnum(int code, String description){
this.code = code;

+ 2
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IDeptService.java Zobrazit soubor

@@ -10,4 +10,6 @@ public interface IDeptService {
JsonResult treeList();

JsonResult test(String id);

JsonResult list();
}

+ 3
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/IUserService.java Zobrazit soubor

@@ -13,4 +13,7 @@ public interface IUserService extends IService<User> {
JsonResult getUserInfo();

JsonResult resetPwd(ResetPwdDto dto);

JsonResult getList();

}

+ 48
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/DeptServiceImpl.java Zobrazit soubor

@@ -1,13 +1,23 @@
package com.tuoheng.miniprogram.service.impl;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.tuoheng.common.core.utils.JsonResult;
import com.tuoheng.common.core.utils.StringUtils;
import com.tuoheng.miniprogram.dao.DeptMapper;
import com.tuoheng.miniprogram.entity.Dept;
import com.tuoheng.miniprogram.entity.User;
import com.tuoheng.miniprogram.enums.DataPermissionEnum;
import com.tuoheng.miniprogram.enums.MarkEnum;
import com.tuoheng.miniprogram.enums.UserCodeEnum;
import com.tuoheng.miniprogram.service.IDeptService;
import com.tuoheng.miniprogram.utils.CurrentUserUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.xml.crypto.Data;
import java.util.*;
import java.util.stream.Collectors;

@@ -45,6 +55,44 @@ public class DeptServiceImpl implements IDeptService {
return JsonResult.success(list);
}

@Override
public JsonResult list() {
User user = CurrentUserUtil.getUserInfo();
String tenantId = user.getTenantId();
Integer dataPermission = user.getDataPermission();
String deptId = user.getDeptId();
if(StringUtils.isEmpty(deptId)){
return JsonResult.error("当前用户部门为空");
}
List<Dept> deptList = new ArrayList<>();
if(null == dataPermission){
return JsonResult.error(DataPermissionEnum.DATA_PERMISSION_IS_NOT_EXIST.getCode(),
DataPermissionEnum.DATA_PERMISSION_IS_NOT_EXIST.getDescription());
}
if(DataPermissionEnum.ALL.getCode() == dataPermission){
deptList = deptMapper.selectList(Wrappers.<Dept>lambdaQuery()
.eq(Dept::getMark, MarkEnum.VALID.getCode())
.eq(Dept::getTenantId, tenantId));
}
if(DataPermissionEnum.DEPT_AND_SUB_DEPT.getCode() == dataPermission){
//获取当前部门及其子部门
List<String> deptIdList = deptMapper.selectAllChildListById(deptId);
if(CollectionUtil.isNotEmpty(deptIdList)){
for (String id : deptIdList) {
Dept dept = deptMapper.selectById(id);
deptList.add(dept);
}
}
}
if(DataPermissionEnum.DEPT.getCode() == dataPermission){
//查询当前部门
Dept dept = deptMapper.selectById(deptId);
deptList.add(dept);
}

return JsonResult.success(deptList);
}


/**
* 递归获取部门的子集

+ 15
- 0
tuoheng-service/tuoheng-miniprogram/src/main/java/com/tuoheng/miniprogram/service/impl/IUserServiceImpl.java Zobrazit soubor

@@ -29,6 +29,8 @@ import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.client.RestTemplate;

import java.util.List;

/**
* @Author ChengWang
* @Date 2022/11/21
@@ -127,4 +129,17 @@ public class IUserServiceImpl extends ServiceImpl<UserMapper, User> implements I
}
return JsonResult.success(UserCodeEnum.PASSWORD_REVISE_SUCCESS.getCode(), UserCodeEnum.PASSWORD_REVISE_SUCCESS.getMsg());
}

@Override
public JsonResult getList() {
User user = CurrentUserUtil.getUserInfo();
if(StringUtils.isEmpty(user.getDeptId())){
return JsonResult.error("用户部门不存在");
}
List<User> userList = userMapper.selectList(Wrappers.<User>lambdaQuery()
.eq(User::getMark, MarkEnum.VALID.getCode())
.eq(User::getDeptId, user.getDeptId())
.eq(User::getStatus, 1));
return JsonResult.success(userList);
}
}

Načítá se…
Zrušit
Uložit