✨ 增加 CRM 模块
This commit is contained in:
@@ -43,9 +43,14 @@ public interface DeptApi {
|
||||
* @param ids 部门编号数组
|
||||
* @return 部门 Map
|
||||
*/
|
||||
default Map<Long, DeptRespDTO> getDeptMap(Set<Long> ids) {
|
||||
default Map<Long, DeptRespDTO> getDeptMap(Collection<Long> ids) {
|
||||
List<DeptRespDTO> list = getDeptList(ids).getCheckedData();
|
||||
return CollectionUtils.convertMap(list, DeptRespDTO::getId);
|
||||
}
|
||||
|
||||
@GetMapping(PREFIX + "/list-child")
|
||||
@Operation(summary = "获得指定部门的所有子部门")
|
||||
@Parameter(name = "id", description = "部门编号", example = "1024", required = true)
|
||||
CommonResult<List<DeptRespDTO>> getChildDeptList(@RequestParam("id") Long id);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
package cn.iocoder.yudao.module.system.api.dept;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.map.MapUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
|
||||
import cn.iocoder.yudao.module.system.enums.ApiConstants;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
@@ -10,6 +14,8 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿:fallbackFactory =
|
||||
@Tag(name = "RPC 服务 - 岗位")
|
||||
@@ -22,4 +28,18 @@ public interface PostApi {
|
||||
@Parameter(name = "ids", description = "岗位编号数组", example = "1,2", required = true)
|
||||
CommonResult<Boolean> validPostList(@RequestParam("ids") Collection<Long> ids);
|
||||
|
||||
@GetMapping(PREFIX + "/list")
|
||||
@Operation(summary = "获得岗位列表")
|
||||
@Parameter(name = "ids", description = "岗位编号数组", example = "1,2", required = true)
|
||||
CommonResult<List<PostRespDTO>> getPostList(@RequestParam("ids") Collection<Long> ids);
|
||||
|
||||
default Map<Long, PostRespDTO> getPostMap(Collection<Long> ids) {
|
||||
if (CollUtil.isEmpty(ids)) {
|
||||
return MapUtil.empty();
|
||||
}
|
||||
|
||||
List<PostRespDTO> list = getPostList(ids).getData();
|
||||
return CollectionUtils.convertMap(list, PostRespDTO::getId);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
package cn.iocoder.yudao.module.system.api.dept.dto;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* 岗位 Response DTO
|
||||
*
|
||||
* @author 芋道源码
|
||||
*/
|
||||
@Schema(description = "RPC 服务 - 岗位 Response DTO")
|
||||
@Data
|
||||
public class PostRespDTO {
|
||||
|
||||
@Schema(description = "岗位编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "岗位名称", requiredMode = Schema.RequiredMode.REQUIRED, example = "小土豆")
|
||||
private String name;
|
||||
|
||||
@Schema(description = "岗位编码", requiredMode = Schema.RequiredMode.REQUIRED, example = "yudao")
|
||||
private String code;
|
||||
|
||||
@Schema(description = "岗位排序", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer sort;
|
||||
|
||||
@Schema(description = "状态", requiredMode = Schema.RequiredMode.REQUIRED, example = "1")
|
||||
private Integer status; // 参见 CommonStatusEnum 枚举
|
||||
|
||||
}
|
||||
@@ -24,6 +24,11 @@ public interface AdminUserApi {
|
||||
@Parameter(name = "id", description = "用户编号", example = "1", required = true)
|
||||
CommonResult<AdminUserRespDTO> getUser(@RequestParam("id") Long id);
|
||||
|
||||
@GetMapping(PREFIX + "/list-by-subordinate")
|
||||
@Operation(summary = "通过用户 ID 查询用户下属")
|
||||
@Parameter(name = "id", description = "用户编号", example = "1", required = true)
|
||||
CommonResult<List<AdminUserRespDTO>> getUserListBySubordinate(@RequestParam("id") Long id);
|
||||
|
||||
@GetMapping(PREFIX + "/list")
|
||||
@Operation(summary = "通过用户 ID 查询用户们")
|
||||
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
|
||||
@@ -64,6 +69,6 @@ public interface AdminUserApi {
|
||||
@GetMapping(PREFIX + "/valid")
|
||||
@Operation(summary = "校验用户们是否有效")
|
||||
@Parameter(name = "ids", description = "用户编号数组", example = "3,5", required = true)
|
||||
CommonResult<Boolean> validateUserList(@RequestParam("ids") Set<Long> ids);
|
||||
CommonResult<Boolean> validateUserList(@RequestParam("ids") Collection<Long> ids);
|
||||
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.DeptRespDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@@ -39,4 +40,10 @@ public class DeptApiImpl implements DeptApi {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<DeptRespDTO>> getChildDeptList(Long id) {
|
||||
List<DeptDO> depts = deptService.getChildDeptList(id);
|
||||
return success(BeanUtils.toBean(depts, DeptRespDTO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
package cn.iocoder.yudao.module.system.api.dept;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.dept.dto.PostRespDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.PostDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.PostService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
@@ -23,4 +27,10 @@ public class PostApiImpl implements PostApi {
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<PostRespDTO>> getPostList(Collection<Long> ids) {
|
||||
List<PostDO> list = postService.getPostList(ids);
|
||||
return success(BeanUtils.toBean(list, PostRespDTO.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,19 +1,23 @@
|
||||
package cn.iocoder.yudao.module.system.api.user;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.hutool.core.util.ObjUtil;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
|
||||
import cn.iocoder.yudao.module.system.service.dept.DeptService;
|
||||
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import jakarta.annotation.Resource;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
|
||||
|
||||
@RestController // 提供 RESTful API 接口,给 Feign 调用
|
||||
@Validated
|
||||
@@ -21,6 +25,8 @@ public class AdminUserApiImpl implements AdminUserApi {
|
||||
|
||||
@Resource
|
||||
private AdminUserService userService;
|
||||
@Resource
|
||||
private DeptService deptService;
|
||||
|
||||
@Override
|
||||
public CommonResult<AdminUserRespDTO> getUser(Long id) {
|
||||
@@ -28,6 +34,34 @@ public class AdminUserApiImpl implements AdminUserApi {
|
||||
return success(BeanUtils.toBean(user, AdminUserRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<AdminUserRespDTO>> getUserListBySubordinate(Long id) {
|
||||
// 1.1 获取用户负责的部门
|
||||
AdminUserDO user = userService.getUser(id);
|
||||
if (user == null) {
|
||||
return success(Collections.emptyList());
|
||||
}
|
||||
ArrayList<Long> deptIds = new ArrayList<>();
|
||||
DeptDO dept = deptService.getDept(user.getDeptId());
|
||||
if (dept == null) {
|
||||
return success(Collections.emptyList());
|
||||
}
|
||||
if (ObjUtil.notEqual(dept.getLeaderUserId(), id)) { // 校验为负责人
|
||||
return success(Collections.emptyList());
|
||||
}
|
||||
deptIds.add(dept.getId());
|
||||
// 1.2 获取所有子部门
|
||||
List<DeptDO> childDeptList = deptService.getChildDeptList(dept.getId());
|
||||
if (CollUtil.isNotEmpty(childDeptList)) {
|
||||
deptIds.addAll(convertSet(childDeptList, DeptDO::getId));
|
||||
}
|
||||
|
||||
// 2. 获取部门对应的用户信息
|
||||
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds);
|
||||
users.removeIf(item -> ObjUtil.equal(item.getId(), id)); // 排除自己
|
||||
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<List<AdminUserRespDTO>> getUserList(Collection<Long> ids) {
|
||||
List<AdminUserDO> users = userService.getUserList(ids);
|
||||
@@ -47,7 +81,7 @@ public class AdminUserApiImpl implements AdminUserApi {
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> validateUserList(Set<Long> ids) {
|
||||
public CommonResult<Boolean> validateUserList(Collection<Long> ids) {
|
||||
userService.validateUserList(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user