diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dept/vo/dept/SysDeptBaseVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dept/vo/dept/SysDeptBaseVO.java index f3e667a9d..8296a89be 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dept/vo/dept/SysDeptBaseVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/dept/vo/dept/SysDeptBaseVO.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept; +import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; +import cn.iocoder.yudao.framework.common.validation.InEnum; import io.swagger.annotations.ApiModelProperty; import lombok.Data; @@ -28,8 +30,8 @@ public class SysDeptBaseVO { @NotNull(message = "显示顺序不能为空") private Integer sort; - @ApiModelProperty(value = "负责人", example = "芋道") - private String leader; + @ApiModelProperty(value = "负责人的用户编号", example = "2048") + private Long leaderUserId; @ApiModelProperty(value = "联系电话", example = "15601691000") @Size(max = 11, message = "联系电话长度不能超过11个字符") @@ -42,7 +44,7 @@ public class SysDeptBaseVO { @ApiModelProperty(value = "状态", required = true, example = "1", notes = "见 SysCommonStatusEnum 枚举") @NotNull(message = "状态不能为空") -// @InEnum(value = SysCommonStatusEnum.class, message = "修改状态必须是 {value}") +// @InEnum(value = CommonStatusEnum.class, message = "修改状态必须是 {value}") private Integer status; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java index f4e32fb59..ae7628e49 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/SysUserController.java @@ -1,7 +1,10 @@ package cn.iocoder.yudao.adminserver.modules.system.controller.user; import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept.SysDeptListReqVO; +import cn.iocoder.yudao.adminserver.modules.system.controller.dept.vo.dept.SysDeptSimpleRespVO; import cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user.*; +import cn.iocoder.yudao.adminserver.modules.system.convert.dept.SysDeptConvert; import cn.iocoder.yudao.adminserver.modules.system.convert.user.SysUserConvert; import cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept.SysDeptDO; import cn.iocoder.yudao.adminserver.modules.system.service.dept.SysDeptService; @@ -32,6 +35,8 @@ import java.io.IOException; import java.util.*; import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.framework.operatelog.core.enums.OperateTypeEnum.EXPORT; @Api(tags = "用户") @@ -99,7 +104,7 @@ public class SysUserController { } // 获得拼接需要的数据 - Collection deptIds = CollectionUtils.convertList(pageResult.getList(), SysUserDO::getDeptId); + Collection deptIds = convertList(pageResult.getList(), SysUserDO::getDeptId); Map deptMap = deptService.getDeptMap(deptIds); // 拼接结果返回 List userList = new ArrayList<>(pageResult.getList().size()); @@ -111,6 +116,15 @@ public class SysUserController { return success(new PageResult<>(userList, pageResult.getTotal())); } + @GetMapping("/list-all-simple") + @ApiOperation(value = "获取用户精简信息列表", notes = "只包含被开启的用户,主要用于前端的下拉选项") + public CommonResult> getSimpleUsers() { + // 获用户门列表,只要开启状态的 + List list = userService.getUsersByStatus(CommonStatusEnum.ENABLE.getStatus()); + // 排序后,返回给前端 + return success(SysUserConvert.INSTANCE.convertList04(list)); + } + @GetMapping("/get") @ApiOperation("获得用户详情") @ApiImplicitParam(name = "id", value = "编号", required = true, example = "1024", dataTypeClass = Long.class) @@ -129,15 +143,19 @@ public class SysUserController { List users = userService.getUsers(reqVO); // 获得拼接需要的数据 - Collection deptIds = CollectionUtils.convertList(users, SysUserDO::getDeptId); + Collection deptIds = convertList(users, SysUserDO::getDeptId); Map deptMap = deptService.getDeptMap(deptIds); + Map deptLeaderUserMap = userService.getUserMap(convertSet(deptMap.values(), SysDeptDO::getLeaderUserId)); // 拼接数据 List excelUsers = new ArrayList<>(users.size()); users.forEach(user -> { SysUserExcelVO excelVO = SysUserConvert.INSTANCE.convert02(user); + // 设置部门 MapUtils.findAndThen(deptMap, user.getDeptId(), dept -> { excelVO.setDeptName(dept.getName()); - excelVO.setDeptLeader(dept.getLeader()); + // 设置部门负责人的名字 + MapUtils.findAndThen(deptLeaderUserMap, dept.getLeaderUserId(), + deptLeaderUser -> excelVO.setDeptLeaderNickname(deptLeaderUser.getNickname())); }); excelUsers.add(excelVO); }); diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserExcelVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserExcelVO.java index d7013fa40..02712ba86 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserExcelVO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserExcelVO.java @@ -47,6 +47,6 @@ public class SysUserExcelVO { private String deptName; @ExcelProperty("部门负责人") - private String deptLeader; + private String deptLeaderNickname; } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserSimpleRespVO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserSimpleRespVO.java new file mode 100644 index 000000000..cd2b65c88 --- /dev/null +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/controller/user/vo/user/SysUserSimpleRespVO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.adminserver.modules.system.controller.user.vo.user; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@ApiModel("用户精简信息 Response VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class SysUserSimpleRespVO { + + @ApiModelProperty(value = "用户编号", required = true, example = "1024") + private Long id; + + @ApiModelProperty(value = "用户昵称", required = true, example = "芋道") + private String nickname; + +} diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java index d25ce02ad..7567bba08 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/convert/user/SysUserConvert.java @@ -45,4 +45,5 @@ public interface SysUserConvert { List convertList03(List list); + List convertList04(List list); } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java index b10c13b7e..ccc230d2d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/dataobject/dept/SysDeptDO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.adminserver.modules.system.dal.dataobject.dept; +import cn.iocoder.yudao.coreservice.modules.system.dal.dataobject.user.SysUserDO; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.TableId; @@ -38,8 +39,10 @@ public class SysDeptDO extends TenantBaseDO { private Integer sort; /** * 负责人 + * + * 关联 {@link SysUserDO#getId()} */ - private String leader; + private Long leaderUserId; /** * 联系电话 */ diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java index e1426c472..a278b79f3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/dal/mysql/user/SysUserMapper.java @@ -55,7 +55,7 @@ public interface SysUserMapper extends BaseMapperX { return selectList(new QueryWrapperX().like("username", username)); } - + // TODO 芋艿:可废弃该方法 default List selectListByDepartIdAndPostId(Long departId, Long postId) { return selectList(new QueryWrapperX() .eq("status", CommonStatusEnum.ENABLE.getStatus()) @@ -64,5 +64,9 @@ public interface SysUserMapper extends BaseMapperX { .likeIfPresent("post_ids", Optional.ofNullable(postId).map(t -> String.valueOf(postId)).orElse(""))); } + default List selectListByStatus(Integer status) { + return selectList("status", status); + } + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java index e95d102ad..b237bc2c3 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/SysUserService.java @@ -169,4 +169,12 @@ public interface SysUserService { */ SysUserImportRespVO importUsers(List importUsers, boolean isUpdateSupport); + /** + * 获得指定状态的用户们 + * + * @param status 状态 + * @return 用户们 + */ + List getUsersByStatus(Integer status); + } diff --git a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java index 43156f1d5..8b868ce1d 100644 --- a/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java +++ b/yudao-admin-server/src/main/java/cn/iocoder/yudao/adminserver/modules/system/service/user/impl/SysUserServiceImpl.java @@ -379,4 +379,9 @@ public class SysUserServiceImpl implements SysUserService { return respVO; } + @Override + public List getUsersByStatus(Integer status) { + return userMapper.selectListByStatus(status); + } + } diff --git a/yudao-admin-ui/src/api/system/user.js b/yudao-admin-ui/src/api/system/user.js index 0243454d7..ffa08da09 100644 --- a/yudao-admin-ui/src/api/system/user.js +++ b/yudao-admin-ui/src/api/system/user.js @@ -10,6 +10,14 @@ export function listUser(query) { }) } +// 获取用户精简信息列表 +export function listSimpleUsers() { + return request({ + url: '/system/user/list-all-simple', + method: 'get' + }) +} + // 查询用户详细 export function getUser(userId) { return request({ diff --git a/yudao-admin-ui/src/views/system/dept/index.vue b/yudao-admin-ui/src/views/system/dept/index.vue index 8202d2f99..8696b888b 100644 --- a/yudao-admin-ui/src/views/system/dept/index.vue +++ b/yudao-admin-ui/src/views/system/dept/index.vue @@ -25,8 +25,9 @@ + - +