优化 AdminUserApi 的实现,和 Cloud 保持一致

This commit is contained in:
YunaiV 2022-06-09 08:57:57 +08:00
parent bdf579a20b
commit 1895a9e809
3 changed files with 19 additions and 11 deletions

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.api.user;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import java.util.Collection;
@ -22,6 +23,14 @@ public interface AdminUserApi {
*/
AdminUserRespDTO getUser(Long id);
/**
* 通过用户 ID 查询用户们
*
* @param ids 用户 ID
* @return 用户对象信息
*/
List<AdminUserRespDTO> getUsers(Collection<Long> ids);
/**
* 获得指定部门的用户数组
*
@ -44,7 +53,10 @@ public interface AdminUserApi {
* @param ids 用户编号数组
* @return 用户 Map
*/
Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids);
default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) {
List<AdminUserRespDTO> users = getUsers(ids);
return CollectionUtils.convertMap(users, AdminUserRespDTO::getId);
}
/**
* 校验用户们是否有效如下情况视为无效

View File

@ -9,7 +9,6 @@ import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
/**
@ -29,6 +28,12 @@ public class AdminUserApiImpl implements AdminUserApi {
return UserConvert.INSTANCE.convert4(user);
}
@Override
public List<AdminUserRespDTO> getUsers(Collection<Long> ids) {
List<AdminUserDO> users = userService.getUsers(ids);
return UserConvert.INSTANCE.convertList4(users);
}
@Override
public List<AdminUserRespDTO> getUsersByDeptIds(Collection<Long> deptIds) {
List<AdminUserDO> users = userService.getUsersByDeptIds(deptIds);
@ -41,12 +46,6 @@ public class AdminUserApiImpl implements AdminUserApi {
return UserConvert.INSTANCE.convertList4(users);
}
@Override
public Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) {
Map<Long, AdminUserDO> userMap = userService.getUserMap(ids);
return UserConvert.INSTANCE.convertMap4(userMap);
}
@Override
public void validUsers(Set<Long> ids) {
userService.validUsers(ids);

View File

@ -14,7 +14,6 @@ import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.util.List;
import java.util.Map;
@Mapper
public interface UserConvert {
@ -53,6 +52,4 @@ public interface UserConvert {
List<AdminUserRespDTO> convertList4(List<AdminUserDO> users);
Map<Long, AdminUserRespDTO> convertMap4(Map<Long, AdminUserDO> map);
}