fix(rpc): 统一 RPC API 返回 CommonResult

- 将 ConfigApi、DeptApi、AdminUserApi 的 RPC 方法返回值改为 CommonResult
- 调整对应 ApiImpl 使用 success 包装响应
- 更新调用方显式 getCheckedData/checkError 处理 RPC 返回
- 补充相关单测 mock 的 CommonResult 包装
master-jdk17
YunaiV 2026-06-14 01:26:41 +08:00
parent af91987460
commit ed87b45dff
54 changed files with 178 additions and 156 deletions

View File

@ -84,7 +84,7 @@ public class UserProfileQueryToolFunction
request.setId(loginUser.getId());
}
return TenantUtils.execute(tenantId, () -> {
AdminUserRespDTO user = adminUserApi.getUser(request.getId());
AdminUserRespDTO user = adminUserApi.getUser(request.getId()).getCheckedData();
return BeanUtils.toBean(user, Response.class);
});
}

View File

@ -143,10 +143,10 @@ public class BpmProcessInstanceController {
processInstance.getProcessDefinitionId());
BpmProcessDefinitionInfoDO processDefinitionInfo = processDefinitionService.getProcessDefinitionInfo(
processInstance.getProcessDefinitionId());
AdminUserRespDTO startUser = adminUserApi.getUser(NumberUtils.parseLong(processInstance.getStartUserId()));
AdminUserRespDTO startUser = adminUserApi.getUser(NumberUtils.parseLong(processInstance.getStartUserId())).getCheckedData();
DeptRespDTO dept = null;
if (startUser != null && startUser.getDeptId() != null) {
dept = deptApi.getDept(startUser.getDeptId());
dept = deptApi.getDept(startUser.getDeptId()).getCheckedData();
}
return success(BpmProcessInstanceConvert.INSTANCE.buildProcessInstance(processInstance,
processDefinition, processDefinitionInfo, startUser, dept));
@ -211,8 +211,8 @@ public class BpmProcessInstanceController {
if (historicProcessInstance == null) {
throw exception(PROCESS_INSTANCE_NOT_EXISTS);
}
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(historicProcessInstance.getStartUserId()));
DeptRespDTO dept = deptApi.getDept(startUser.getDeptId());
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(historicProcessInstance.getStartUserId())).getCheckedData();
DeptRespDTO dept = deptApi.getDept(startUser.getDeptId()).getCheckedData();
List<HistoricTaskInstance> tasks = taskService.getFinishedTaskListByProcessInstanceIdWithoutCancel(processInstanceId);
Map<Long, AdminUserRespDTO> userMap = adminUserApi.getUserMap(
convertSet(tasks, item -> Long.valueOf(item.getAssignee())));

View File

@ -57,7 +57,7 @@ public class BpmTaskAssignLeaderExpression {
return emptySet();
}
} else {
DeptRespDTO parentDept = deptApi.getDept(dept.getParentId());
DeptRespDTO parentDept = deptApi.getDept(dept.getParentId()).getCheckedData();
if (parentDept == null) { // 找不到父级部门,所以只好结束寻找。原因是:例如说,级别比较高的人,所在部门层级比较少
break;
}
@ -68,11 +68,11 @@ public class BpmTaskAssignLeaderExpression {
}
private DeptRespDTO getStartUserDept(Long startUserId) {
AdminUserRespDTO startUser = adminUserApi.getUser(startUserId);
AdminUserRespDTO startUser = adminUserApi.getUser(startUserId).getCheckedData();
if (startUser.getDeptId() == null) { // 找不到部门,所以无法使用该规则
return null;
}
return deptApi.getDept(startUser.getDeptId());
return deptApi.getDept(startUser.getDeptId()).getCheckedData();
}
}

View File

@ -40,7 +40,7 @@ public abstract class AbstractBpmTaskCandidateDeptLeaderStrategy implements BpmT
}
DeptRespDTO currentDept = dept;
for (int i = 1; i < level; i++) {
DeptRespDTO parentDept = deptApi.getDept(currentDept.getParentId());
DeptRespDTO parentDept = deptApi.getDept(currentDept.getParentId()).getCheckedData();
if (parentDept == null) { // 找不到父级部门,到了最高级。返回最高级的部门负责人
break;
}
@ -63,12 +63,12 @@ public abstract class AbstractBpmTaskCandidateDeptLeaderStrategy implements BpmT
}
Set<Long> deptLeaderIds = new LinkedHashSet<>(); // 保证有序
for (Long deptId : deptIds) {
DeptRespDTO dept = deptApi.getDept(deptId);
DeptRespDTO dept = deptApi.getDept(deptId).getCheckedData();
for (int i = 0; i < level; i++) {
if (dept.getLeaderUserId() != null) {
deptLeaderIds.add(dept.getLeaderUserId());
}
DeptRespDTO parentDept = deptApi.getDept(dept.getParentId());
DeptRespDTO parentDept = deptApi.getDept(dept.getParentId()).getCheckedData();
if (parentDept == null) { // 找不到父级部门. 已经到了最高层级了
break;
}
@ -84,11 +84,11 @@ public abstract class AbstractBpmTaskCandidateDeptLeaderStrategy implements BpmT
* @param startUserId Id
*/
protected DeptRespDTO getStartUserDept(Long startUserId) {
AdminUserRespDTO startUser = adminUserApi.getUser(startUserId);
AdminUserRespDTO startUser = adminUserApi.getUser(startUserId).getCheckedData();
if (startUser.getDeptId() == null) { // 找不到部门
return null;
}
return deptApi.getDept(startUser.getDeptId());
return deptApi.getDept(startUser.getDeptId()).getCheckedData();
}
}

View File

@ -30,7 +30,7 @@ public class BpmTaskCandidateDeptLeaderMultiStrategy extends AbstractBpmTaskCand
List<Long> deptIds = StrUtils.splitToLong(params[0], ",");
int level = Integer.parseInt(params[1]);
// 校验部门存在
deptApi.validateDeptList(deptIds);
deptApi.validateDeptList(deptIds).checkError();
Assert.isTrue(level > 0, "部门层级必须大于 0");
}

View File

@ -32,13 +32,13 @@ public class BpmTaskCandidateDeptLeaderStrategy implements BpmTaskCandidateStrat
@Override
public void validateParam(String param) {
Set<Long> deptIds = StrUtils.splitToLongSet(param);
deptApi.validateDeptList(deptIds);
deptApi.validateDeptList(deptIds).checkError();
}
@Override
public Set<Long> calculateUsers(String param) {
Set<Long> deptIds = StrUtils.splitToLongSet(param);
List<DeptRespDTO> depts = deptApi.getDeptList(deptIds);
List<DeptRespDTO> depts = deptApi.getDeptList(deptIds).getCheckedData();
return convertSet(depts, DeptRespDTO::getLeaderUserId);
}

View File

@ -35,13 +35,13 @@ public class BpmTaskCandidateDeptMemberStrategy implements BpmTaskCandidateStrat
@Override
public void validateParam(String param) {
Set<Long> deptIds = StrUtils.splitToLongSet(param);
deptApi.validateDeptList(deptIds);
deptApi.validateDeptList(deptIds).checkError();
}
@Override
public Set<Long> calculateUsers(String param) {
Set<Long> deptIds = StrUtils.splitToLongSet(param);
List<AdminUserRespDTO> users = adminUserApi.getUserListByDeptIds(deptIds);
List<AdminUserRespDTO> users = adminUserApi.getUserListByDeptIds(deptIds).getCheckedData();
return convertSet(users, AdminUserRespDTO::getId);
}

View File

@ -41,7 +41,7 @@ public class BpmTaskCandidatePostStrategy implements BpmTaskCandidateStrategy {
@Override
public Set<Long> calculateUsers(String param) {
Set<Long> postIds = StrUtils.splitToLongSet(param);
List<AdminUserRespDTO> users = adminUserApi.getUserListByPostIds(postIds);
List<AdminUserRespDTO> users = adminUserApi.getUserListByPostIds(postIds).getCheckedData();
return convertSet(users, AdminUserRespDTO::getId);
}

View File

@ -28,7 +28,7 @@ public class BpmTaskCandidateUserStrategy implements BpmTaskCandidateStrategy {
@Override
public void validateParam(String param) {
adminUserApi.validateUserList(StrUtils.splitToLongSet(param));
adminUserApi.validateUserList(StrUtils.splitToLongSet(param)).checkError();
}
@Override

View File

@ -101,7 +101,7 @@ public class BpmProcessDefinitionServiceImpl implements BpmProcessDefinitionServ
// 校验用户是否在允许发起的部门列表中
if (CollUtil.isNotEmpty(processDefinition.getStartDeptIds())) {
AdminUserRespDTO user = adminUserApi.getUser(userId);
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
return user != null
&& user.getDeptId() != null
&& processDefinition.getStartDeptIds().contains(user.getDeptId());

View File

@ -872,7 +872,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
if (titleSetting == null || !BooleanUtil.isTrue(titleSetting.getEnable())) {
return definition.getName();
}
AdminUserRespDTO user = adminUserApi.getUser(userId);
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
Map<String, Object> cloneVariables = new HashMap<>(variables);
cloneVariables.put(BpmnVariableConstants.PROCESS_INSTANCE_VARIABLE_START_USER_ID, user.getNickname());
cloneVariables.put(BpmnVariableConstants.PROCESS_START_TIME, DateUtil.now());
@ -920,7 +920,7 @@ public class BpmProcessInstanceServiceImpl implements BpmProcessInstanceService
}
// 2. 取消流程
AdminUserRespDTO user = adminUserApi.getUser(userId);
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
updateProcessInstanceCancel(cancelReqVO.getId(),
BpmReasonEnum.CANCEL_PROCESS_INSTANCE_BY_ADMIN.format(user.getNickname(), cancelReqVO.getReason()));
}

View File

@ -787,8 +787,8 @@ public class BpmTaskServiceImpl implements BpmTaskService {
*/
private void approveDelegateTask(BpmTaskApproveReqVO reqVO, Task task) {
// 1. 添加审批意见
AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId());
AdminUserRespDTO ownerUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())); // 发起委托的用户
AdminUserRespDTO currentUser = adminUserApi.getUser(WebFrameworkUtils.getLoginUserId()).getCheckedData();
AdminUserRespDTO ownerUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())).getCheckedData(); // 发起委托的用户
Assert.notNull(ownerUser, "委派任务找不到原审批人,需要检查数据");
taskService.addComment(reqVO.getId(), task.getProcessInstanceId(), BpmCommentTypeEnum.DELEGATE_END.getType(),
BpmCommentTypeEnum.DELEGATE_END.formatComment(currentUser.getNickname(), ownerUser.getNickname(), reqVO.getReason()));
@ -1015,13 +1015,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
throw exception(TASK_DELEGATE_FAIL_USER_REPEAT);
}
// 1.2 校验目标用户存在
AdminUserRespDTO delegateUser = adminUserApi.getUser(reqVO.getDelegateUserId());
AdminUserRespDTO delegateUser = adminUserApi.getUser(reqVO.getDelegateUserId()).getCheckedData();
if (delegateUser == null) {
throw exception(TASK_DELEGATE_FAIL_USER_NOT_EXISTS);
}
// 2. 添加委托意见
AdminUserRespDTO currentUser = adminUserApi.getUser(userId);
AdminUserRespDTO currentUser = adminUserApi.getUser(userId).getCheckedData();
taskService.addComment(taskId, task.getProcessInstanceId(), BpmCommentTypeEnum.DELEGATE_START.getType(),
BpmCommentTypeEnum.DELEGATE_START.formatComment(currentUser.getNickname(), delegateUser.getNickname(), reqVO.getReason()));
@ -1046,13 +1046,13 @@ public class BpmTaskServiceImpl implements BpmTaskService {
throw exception(TASK_TRANSFER_FAIL_USER_REPEAT);
}
// 1.2 校验目标用户存在
AdminUserRespDTO assigneeUser = adminUserApi.getUser(reqVO.getAssigneeUserId());
AdminUserRespDTO assigneeUser = adminUserApi.getUser(reqVO.getAssigneeUserId()).getCheckedData();
if (assigneeUser == null) {
throw exception(TASK_TRANSFER_FAIL_USER_NOT_EXISTS);
}
// 2. 添加委托意见
AdminUserRespDTO currentUser = adminUserApi.getUser(userId);
AdminUserRespDTO currentUser = adminUserApi.getUser(userId).getCheckedData();
taskService.addComment(taskId, task.getProcessInstanceId(), BpmCommentTypeEnum.TRANSFER.getType(),
BpmCommentTypeEnum.TRANSFER.formatComment(currentUser.getNickname(), assigneeUser.getNickname(), reqVO.getReason()));
@ -1111,7 +1111,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
public void createSignTask(Long userId, BpmTaskSignCreateReqVO reqVO) {
// 1. 获取和校验任务
TaskEntityImpl taskEntity = validateTaskCanCreateSign(userId, reqVO);
List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIds());
List<AdminUserRespDTO> userList = adminUserApi.getUserList(reqVO.getUserIds()).getCheckedData();
if (CollUtil.isEmpty(userList)) {
throw exception(TASK_SIGN_CREATE_USER_NOT_EXIST);
}
@ -1138,7 +1138,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
createSignTaskList(convertList(reqVO.getUserIds(), String::valueOf), taskEntity);
// 4. 记录加签的评论到 task 任务
AdminUserRespDTO currentUser = adminUserApi.getUser(userId);
AdminUserRespDTO currentUser = adminUserApi.getUser(userId).getCheckedData();
String comment = StrUtil.format(BpmCommentTypeEnum.ADD_SIGN.getComment(),
currentUser.getNickname(), BpmTaskSignTypeEnum.nameOfType(reqVO.getType()),
String.join(",", convertList(userList, AdminUserRespDTO::getNickname)), reqVO.getReason());
@ -1170,7 +1170,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
List<Long> currentAssigneeList = convertListByFlatMap(taskList, task -> // 需要考虑 owner 的情况,因为向后加签时,它暂时没 assignee 而是 owner
Stream.of(NumberUtils.parseLong(task.getAssignee()), NumberUtils.parseLong(task.getOwner())));
if (CollUtil.containsAny(currentAssigneeList, reqVO.getUserIds())) {
List<AdminUserRespDTO> userList = adminUserApi.getUserList(CollUtil.intersection(currentAssigneeList, reqVO.getUserIds()));
List<AdminUserRespDTO> userList = adminUserApi.getUserList(CollUtil.intersection(currentAssigneeList, reqVO.getUserIds())).getCheckedData();
throw exception(TASK_SIGN_CREATE_USER_REPEAT, String.join(",", convertList(userList, AdminUserRespDTO::getNickname)));
}
return taskEntity;
@ -1232,10 +1232,10 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 1.2 校验取消人存在
AdminUserRespDTO cancelUser = null;
if (StrUtil.isNotBlank(task.getAssignee())) {
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getAssignee()));
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getAssignee())).getCheckedData();
}
if (cancelUser == null && StrUtil.isNotBlank(task.getOwner())) {
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner()));
cancelUser = adminUserApi.getUser(NumberUtils.parseLong(task.getOwner())).getCheckedData();
}
Assert.notNull(cancelUser, "任务中没有所有者和审批人,数据错误");
@ -1249,7 +1249,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
taskService.deleteTasks(convertList(childTaskList, Task::getId));
// 3. 记录日志到父任务中。先记录日志是因为,通过 handleParentTask 方法之后,任务可能被完成了,并且不存在了,会报异常,所以先记录
AdminUserRespDTO user = adminUserApi.getUser(userId);
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
taskService.addComment(task.getParentTaskId(), task.getProcessInstanceId(), BpmCommentTypeEnum.SUB_SIGN.getType(),
StrUtil.format(BpmCommentTypeEnum.SUB_SIGN.getComment(), user.getNickname(), cancelUser.getNickname()));
@ -1555,9 +1555,9 @@ public class BpmTaskServiceImpl implements BpmTaskService {
// 情况二:转交给部门负责人审批
if (ObjectUtils.equalsAny(assignStartUserHandlerType,
BpmUserTaskAssignStartUserHandlerTypeEnum.TRANSFER_DEPT_LEADER.getType())) {
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId()));
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId())).getCheckedData();
Assert.notNull(startUser, "提交人({})信息为空", processInstance.getStartUserId());
DeptRespDTO dept = startUser.getDeptId() != null ? deptApi.getDept(startUser.getDeptId()) : null;
DeptRespDTO dept = startUser.getDeptId() != null ? deptApi.getDept(startUser.getDeptId()).getCheckedData() : null;
Assert.notNull(dept, "提交人({})部门({})信息为空", processInstance.getStartUserId(), startUser.getDeptId());
// 找不到部门负责人的情况下,自动审批通过
// noinspection DataFlowIssue
@ -1579,7 +1579,7 @@ public class BpmTaskServiceImpl implements BpmTaskService {
}
// 发送消息
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId()));
AdminUserRespDTO startUser = adminUserApi.getUser(Long.valueOf(processInstance.getStartUserId())).getCheckedData();
messageService.sendMessageWhenTaskAssigned(BpmTaskConvert.INSTANCE.convert(processInstance, startUser, task));
});
}

View File

@ -14,6 +14,7 @@ import org.mockito.Mock;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString;
@ -40,9 +41,9 @@ public class BpmTaskAssignLeaderExpressionTest extends BaseMockitoUnitTest {
DelegateExecution execution = mockDelegateExecution(1L);
// mock 方法(startUser)
AdminUserRespDTO startUser = randomPojo(AdminUserRespDTO.class, o -> o.setDeptId(10L));
when(adminUserApi.getUser(eq(1L))).thenReturn(startUser);
when(adminUserApi.getUser(eq(1L))).thenReturn(success(startUser));
// mock 方法(getStartUserDept)没有部门
when(deptApi.getDept(eq(10L))).thenReturn(null);
when(deptApi.getDept(eq(10L))).thenReturn(success(null));
// 调用
Set<Long> result = expression.calculateUsers(execution, 1);
@ -56,12 +57,12 @@ public class BpmTaskAssignLeaderExpressionTest extends BaseMockitoUnitTest {
DelegateExecution execution = mockDelegateExecution(1L);
// mock 方法(startUser)
AdminUserRespDTO startUser = randomPojo(AdminUserRespDTO.class, o -> o.setDeptId(10L));
when(adminUserApi.getUser(eq(1L))).thenReturn(startUser);
when(adminUserApi.getUser(eq(1L))).thenReturn(success(startUser));
DeptRespDTO startUserDept = randomPojo(DeptRespDTO.class, o -> o.setId(10L).setParentId(100L)
.setLeaderUserId(20L));
// mock 方法getDept
when(deptApi.getDept(eq(10L))).thenReturn(startUserDept);
when(deptApi.getDept(eq(100L))).thenReturn(null);
when(deptApi.getDept(eq(10L))).thenReturn(success(startUserDept));
when(deptApi.getDept(eq(100L))).thenReturn(success(null));
// 调用
Set<Long> result = expression.calculateUsers(execution, 2);
@ -75,14 +76,14 @@ public class BpmTaskAssignLeaderExpressionTest extends BaseMockitoUnitTest {
DelegateExecution execution = mockDelegateExecution(1L);
// mock 方法(startUser)
AdminUserRespDTO startUser = randomPojo(AdminUserRespDTO.class, o -> o.setDeptId(10L));
when(adminUserApi.getUser(eq(1L))).thenReturn(startUser);
when(adminUserApi.getUser(eq(1L))).thenReturn(success(startUser));
DeptRespDTO startUserDept = randomPojo(DeptRespDTO.class, o -> o.setId(10L).setParentId(100L)
.setLeaderUserId(20L));
when(deptApi.getDept(eq(10L))).thenReturn(startUserDept);
when(deptApi.getDept(eq(10L))).thenReturn(success(startUserDept));
// mock 方法(父 dept
DeptRespDTO parentDept = randomPojo(DeptRespDTO.class, o -> o.setId(100L).setParentId(1000L)
.setLeaderUserId(200L));
when(deptApi.getDept(eq(100L))).thenReturn(parentDept);
when(deptApi.getDept(eq(100L))).thenReturn(success(parentDept));
// 调用
Set<Long> result = expression.calculateUsers(execution, 2);

View File

@ -7,10 +7,10 @@ import org.assertj.core.util.Sets;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
@ -29,9 +29,10 @@ public class BpmTaskCandidateDeptLeaderMultiStrategyTest extends BaseMockitoUnit
// 准备参数
String param = "10,20|2";
// mock 方法
when(deptApi.getDept(any())).thenAnswer((Answer<DeptRespDTO>) invocationOnMock -> {
when(deptApi.getDept(any())).thenAnswer(invocationOnMock -> {
Long deptId = invocationOnMock.getArgument(0);
return randomPojo(DeptRespDTO.class, o -> o.setId(deptId).setParentId(deptId * 100).setLeaderUserId(deptId + 1));
return success(randomPojo(DeptRespDTO.class,
o -> o.setId(deptId).setParentId(deptId * 100).setLeaderUserId(deptId + 1)));
});
// 调用

View File

@ -11,6 +11,7 @@ import org.mockito.Mock;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -30,9 +31,9 @@ public class BpmTaskCandidateDeptLeaderStrategyTest extends BaseMockitoUnitTest
// 准备参数
String param = "10,20";
// mock 方法
when(deptApi.getDeptList(eq(SetUtils.asSet(10L, 20L)))).thenReturn(asList(
when(deptApi.getDeptList(eq(SetUtils.asSet(10L, 20L)))).thenReturn(success(asList(
randomPojo(DeptRespDTO.class, o -> o.setId(10L).setParentId(10L).setLeaderUserId(11L)),
randomPojo(DeptRespDTO.class, o -> o.setId(20L).setParentId(20L).setLeaderUserId(21L))));
randomPojo(DeptRespDTO.class, o -> o.setId(20L).setParentId(20L).setLeaderUserId(21L)))));
// 调用
Set<Long> userIds = strategy.calculateUsers(param);

View File

@ -12,6 +12,7 @@ import org.mockito.Mock;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -33,9 +34,9 @@ public class BpmTaskCandidateDeptMemberStrategyTest extends BaseMockitoUnitTest
// 准备参数
String param = "10,20";
// mock 方法
when(adminUserApi.getUserListByDeptIds(eq(SetUtils.asSet(10L, 20L)))).thenReturn(asList(
when(adminUserApi.getUserListByDeptIds(eq(SetUtils.asSet(10L, 20L)))).thenReturn(success(asList(
randomPojo(AdminUserRespDTO.class, o -> o.setId(11L)),
randomPojo(AdminUserRespDTO.class, o -> o.setId(21L))));
randomPojo(AdminUserRespDTO.class, o -> o.setId(21L)))));
// 调用
Set<Long> userIds = strategy.calculateUsers(param);

View File

@ -12,10 +12,10 @@ import org.flowable.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
@ -72,10 +72,11 @@ public class BpmTaskCandidateStartUserDeptLeaderMultiStrategyTest extends BaseMo
private void mockGetStartUserDept(Long startUserId) {
when(adminUserApi.getUser(eq(startUserId))).thenReturn(
randomPojo(AdminUserRespDTO.class, o -> o.setId(startUserId).setDeptId(10L)));
when(deptApi.getDept(any())).thenAnswer((Answer<DeptRespDTO>) invocationOnMock -> {
success(randomPojo(AdminUserRespDTO.class, o -> o.setId(startUserId).setDeptId(10L))));
when(deptApi.getDept(any())).thenAnswer(invocationOnMock -> {
Long deptId = invocationOnMock.getArgument(0);
return randomPojo(DeptRespDTO.class, o -> o.setId(deptId).setParentId(deptId * 100).setLeaderUserId(deptId + 1));
return success(randomPojo(DeptRespDTO.class,
o -> o.setId(deptId).setParentId(deptId * 100).setLeaderUserId(deptId + 1)));
});
}

View File

@ -12,10 +12,10 @@ import org.flowable.engine.runtime.ProcessInstance;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.stubbing.Answer;
import java.util.Set;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
@ -72,10 +72,11 @@ public class BpmTaskCandidateStartUserDeptLeaderStrategyTest extends BaseMockito
private void mockGetStartUserDeptLeader(Long startUserId) {
when(adminUserApi.getUser(eq(startUserId))).thenReturn(
randomPojo(AdminUserRespDTO.class, o -> o.setId(startUserId).setDeptId(10L)));
when(deptApi.getDept(any())).thenAnswer((Answer<DeptRespDTO>) invocationOnMock -> {
success(randomPojo(AdminUserRespDTO.class, o -> o.setId(startUserId).setDeptId(10L))));
when(deptApi.getDept(any())).thenAnswer(invocationOnMock -> {
Long deptId = invocationOnMock.getArgument(0);
return randomPojo(DeptRespDTO.class, o -> o.setId(deptId).setParentId(deptId * 100).setLeaderUserId(deptId + 1));
return success(randomPojo(DeptRespDTO.class,
o -> o.setId(deptId).setParentId(deptId * 100).setLeaderUserId(deptId + 1)));
});
}

View File

@ -12,6 +12,7 @@ import org.mockito.Mock;
import java.util.List;
import java.util.Set;
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.SetUtils.asSet;
import static org.junit.jupiter.api.Assertions.assertEquals;
@ -36,7 +37,7 @@ public class BpmTaskCandidatePostStrategyTest extends BaseMockitoUnitTest {
// mock 方法
List<AdminUserRespDTO> users = convertList(asSet(11L, 22L),
id -> new AdminUserRespDTO().setId(id));
when(adminUserApi.getUserListByPostIds(eq(asSet(1L, 2L)))).thenReturn(users);
when(adminUserApi.getUserListByPostIds(eq(asSet(1L, 2L)))).thenReturn(success(users));
// 调用
Set<Long> userIds = strategy.calculateUsersByTask(null, param);

View File

@ -110,7 +110,7 @@ public class CrmBusinessStatusController {
public CommonResult<List<CrmBusinessStatusRespVO>> getBusinessStatusTypeSimpleList() {
List<CrmBusinessStatusTypeDO> list = businessStatusTypeService.getBusinessStatusTypeList();
// 过滤掉部门不匹配的
Long deptId = adminUserApi.getUser(getLoginUserId()).getDeptId();
Long deptId = adminUserApi.getUser(getLoginUserId()).getCheckedData().getDeptId();
list.removeIf(statusType -> CollUtil.isNotEmpty(statusType.getDeptIds()) && !statusType.getDeptIds().contains(deptId));
return success(BeanUtils.toBean(list, CrmBusinessStatusRespVO.class));
}

View File

@ -34,7 +34,7 @@ public class SysAdminUserParseFunction implements IParseFunction {
}
// 获取用户信息
AdminUserRespDTO user = adminUserApi.getUser(Long.parseLong(value.toString()));
AdminUserRespDTO user = adminUserApi.getUser(Long.parseLong(value.toString())).getCheckedData();
if (user == null) {
log.warn("[apply][获取用户{{}}为空", value);
return "";

View File

@ -34,7 +34,7 @@ public class SysDeptParseFunction implements IParseFunction {
}
// 获取部门信息
DeptRespDTO dept = deptApi.getDept(Long.parseLong(value.toString()));
DeptRespDTO dept = deptApi.getDept(Long.parseLong(value.toString())).getCheckedData();
if (dept == null) {
log.warn("[apply][获取部门{{}}为空", value);
return "";

View File

@ -95,7 +95,7 @@ public class CrmPermissionAspect {
}
// 3. 考虑下级的权限
List<AdminUserRespDTO> subordinateUserIds = adminUserApi.getUserListBySubordinate(userId);
List<AdminUserRespDTO> subordinateUserIds = adminUserApi.getUserListBySubordinate(userId).getCheckedData();
for (Long subordinateUserId : convertSet(subordinateUserIds, AdminUserRespDTO::getId)) {
CrmPermissionDO subordinatePermission = CollUtil.findOne(bizPermissions,
permission -> ObjUtil.equal(permission.getUserId(), subordinateUserId));

View File

@ -112,7 +112,7 @@ public class CrmClueServiceImpl implements CrmClueService {
private void validateRelationDataExists(CrmClueSaveReqVO reqVO) {
// 校验负责人
if (Objects.nonNull(reqVO.getOwnerUserId()) &&
Objects.isNull(adminUserApi.getUser(reqVO.getOwnerUserId()))) {
Objects.isNull(adminUserApi.getUser(reqVO.getOwnerUserId()).getCheckedData())) {
throw exception(USER_NOT_EXISTS);
}
}

View File

@ -110,13 +110,13 @@ public class CrmCustomerLimitConfigServiceImpl implements CrmCustomerLimitConfig
* @param deptIds ids
*/
private void validateUserAndDept(Collection<Long> userIds, Collection<Long> deptIds) {
deptApi.validateDeptList(deptIds);
adminUserApi.validateUserList(userIds);
deptApi.validateDeptList(deptIds).checkError();
adminUserApi.validateUserList(userIds).checkError();
}
@Override
public List<CrmCustomerLimitConfigDO> getCustomerLimitConfigListByUserId(Integer type, Long userId) {
AdminUserRespDTO user = adminUserApi.getUser(userId);
AdminUserRespDTO user = adminUserApi.getUser(userId).getCheckedData();
Assert.notNull(user, "用户({})不存在", userId);
return customerLimitConfigMapper.selectListByTypeAndUserIdAndDeptId(type, userId, user.getDeptId());
}

View File

@ -391,7 +391,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
throw exception(CUSTOMER_NOT_EXISTS);
}
// 1.2 校验负责人是否存在
adminUserApi.validateUserList(singletonList(ownerUserId));
adminUserApi.validateUserList(singletonList(ownerUserId)).checkError();
// 1.3 校验状态
customers.forEach(customer -> {
// 校验是否已有负责人
@ -424,7 +424,7 @@ public class CrmCustomerServiceImpl implements CrmCustomerService {
// 3. 记录操作日志
AdminUserRespDTO user = null;
if (!isReceive) {
user = adminUserApi.getUser(ownerUserId);
user = adminUserApi.getUser(ownerUserId).getCheckedData();
}
for (CrmCustomerDO customer : customers) {
getSelf().receiveCustomerLog(customer, user == null ? null : user.getNickname());

View File

@ -136,7 +136,7 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
private void createBizTypePermissions(CrmPermissionSaveReqVO reqVO, Integer type, Long bizId, String name,
List<CrmPermissionCreateReqBO> createPermissions) {
AdminUserRespDTO user = adminUserApi.getUser(reqVO.getUserId());
AdminUserRespDTO user = adminUserApi.getUser(reqVO.getUserId()).getCheckedData();
// 1. 需要考虑,被添加人,是不是应该有对应的权限了;
CrmPermissionDO permission = hasAnyPermission(type, bizId, reqVO.getUserId());
if (ObjUtil.isNotNull(permission)) {
@ -157,7 +157,7 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
private Long createPermission0(CrmPermissionCreateReqBO createReqBO) {
validatePermissionNotExists(Collections.singletonList(createReqBO));
// 1. 校验用户是否存在
adminUserApi.validateUserList(Collections.singletonList(createReqBO.getUserId()));
adminUserApi.validateUserList(Collections.singletonList(createReqBO.getUserId())).checkError();
// 2. 插入权限
CrmPermissionDO permission = BeanUtils.toBean(createReqBO, CrmPermissionDO.class);
permissionMapper.insert(permission);
@ -168,7 +168,7 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
public void createPermissionBatch(List<CrmPermissionCreateReqBO> createReqBOs) {
validatePermissionNotExists(createReqBOs);
// 1. 校验用户是否存在
adminUserApi.validateUserList(convertSet(createReqBOs, CrmPermissionCreateReqBO::getUserId));
adminUserApi.validateUserList(convertSet(createReqBOs, CrmPermissionCreateReqBO::getUserId)).checkError();
// 2. 创建
List<CrmPermissionDO> permissions = BeanUtils.toBean(createReqBOs, CrmPermissionDO.class);
@ -219,7 +219,7 @@ public class CrmPermissionServiceImpl implements CrmPermissionService {
throw exception(CRM_PERMISSION_MODEL_TRANSFER_FAIL_OWNER_USER_EXISTS, bizTypeName);
}
// 1.2 校验新负责人是否存在
adminUserApi.validateUserList(Collections.singletonList(transferReqBO.getNewOwnerUserId()));
adminUserApi.validateUserList(Collections.singletonList(transferReqBO.getNewOwnerUserId())).checkError();
// 2. 修改新负责人的权限
List<CrmPermissionDO> permissions = permissionMapper.selectByBizTypeAndBizId(

View File

@ -60,7 +60,7 @@ public class CrmProductServiceImpl implements CrmProductService {
success = CRM_PRODUCT_CREATE_SUCCESS)
public Long createProduct(CrmProductSaveReqVO createReqVO) {
// 1. 校验产品
adminUserApi.validateUserList(Collections.singleton(createReqVO.getOwnerUserId()));
adminUserApi.validateUserList(Collections.singleton(createReqVO.getOwnerUserId())).checkError();
validateProductNoDuplicate(null, createReqVO.getNo());
validateProductCategoryExists(createReqVO.getCategoryId());

View File

@ -359,10 +359,10 @@ public class CrmStatisticsCustomerServiceImpl implements CrmStatisticsCustomerSe
}
// 情况二:选中某个部门
// 2.1 获得部门列表
List<Long> deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()), DeptRespDTO::getId);
List<Long> deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()).getCheckedData(), DeptRespDTO::getId);
deptIds.add(reqVO.getDeptId());
// 2.2 获得用户编号
return convertList(adminUserApi.getUserListByDeptIds(deptIds), AdminUserRespDTO::getId);
return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId);
}
}

View File

@ -145,10 +145,10 @@ public class CrmStatisticsFunnelServiceImpl implements CrmStatisticsFunnelServic
}
// 情况二:选中某个部门
// 2.1 获得部门列表
List<Long> deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()), DeptRespDTO::getId);
List<Long> deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()).getCheckedData(), DeptRespDTO::getId);
deptIds.add(reqVO.getDeptId());
// 2.2 获得用户编号
return convertList(adminUserApi.getUserListByDeptIds(deptIds), AdminUserRespDTO::getId);
return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId);
}
}

View File

@ -111,10 +111,10 @@ public class CrmStatisticsPerformanceServiceImpl implements CrmStatisticsPerform
// 情况二:选中某个部门
// 2.1 获得部门列表
final Long deptId = reqVO.getDeptId();
List<Long> deptIds = convertList(deptApi.getChildDeptList(deptId), DeptRespDTO::getId);
List<Long> deptIds = convertList(deptApi.getChildDeptList(deptId).getCheckedData(), DeptRespDTO::getId);
deptIds.add(deptId);
// 2.2 获得用户编号
return convertList(adminUserApi.getUserListByDeptIds(deptIds), AdminUserRespDTO::getId);
return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId);
}
}

View File

@ -122,10 +122,10 @@ public class CrmStatisticsPortraitServiceImpl implements CrmStatisticsPortraitSe
}
// 情况二:选中某个部门
// 2.1 获得部门列表
List<Long> deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()), DeptRespDTO::getId);
List<Long> deptIds = convertList(deptApi.getChildDeptList(reqVO.getDeptId()).getCheckedData(), DeptRespDTO::getId);
deptIds.add(reqVO.getDeptId());
// 2.2 获得用户编号
return convertList(adminUserApi.getUserListByDeptIds(deptIds), AdminUserRespDTO::getId);
return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId);
}
}

View File

@ -125,10 +125,10 @@ public class CrmStatisticsRankServiceImpl implements CrmStatisticsRankService {
*/
public List<Long> getUserIds(Long deptId) {
// 1. 获得部门列表
List<Long> deptIds = convertList(deptApi.getChildDeptList(deptId), DeptRespDTO::getId);
List<Long> deptIds = convertList(deptApi.getChildDeptList(deptId).getCheckedData(), DeptRespDTO::getId);
deptIds.add(deptId);
// 2. 获得用户编号
return convertList(adminUserApi.getUserListByDeptIds(deptIds), AdminUserRespDTO::getId);
return convertList(adminUserApi.getUserListByDeptIds(deptIds).getCheckedData(), AdminUserRespDTO::getId);
}
}

View File

@ -67,7 +67,7 @@ public class CrmPermissionUtils {
// 场景三:下属负责的数据(下属是负责人)
if (CrmSceneTypeEnum.isSubordinate(sceneType)) {
AdminUserApi adminUserApi = SpringUtil.getBean(AdminUserApi.class);
List<AdminUserRespDTO> subordinateUsers = adminUserApi.getUserListBySubordinate(userId);
List<AdminUserRespDTO> subordinateUsers = adminUserApi.getUserListBySubordinate(userId).getCheckedData();
if (CollUtil.isEmpty(subordinateUsers)) {
query.eq(ownerUserIdField, -1); // 不返回任何结果
} else {

View File

@ -79,7 +79,7 @@ public class ImGroupMemberController {
// 3. 转化 VO
ImGroupMemberRespVO memberVO = BeanUtils.toBean(member, ImGroupMemberRespVO.class);
AdminUserRespDTO user = adminUserApi.getUser(member.getUserId());
AdminUserRespDTO user = adminUserApi.getUser(member.getUserId()).getCheckedData();
if (user != null) {
memberVO.setNickname(user.getNickname()).setAvatar(user.getAvatar());
}

View File

@ -97,7 +97,7 @@ public class ImFriendRequestServiceImpl implements ImFriendRequestService {
ImFriendRequestDO request = createOrResetRequest(fromUserId, reqVO);
// 3. 推送 FRIEND_REQUEST_RECEIVED 给 toUser 多端payload 携带申请方昵称 / 头像,前端按 requestId 直推 push 进列表
AdminUserRespDTO fromUser = adminUserApi.getUser(fromUserId);
AdminUserRespDTO fromUser = adminUserApi.getUser(fromUserId).getCheckedData();
FriendRequestNotification payload = (FriendRequestNotification) new FriendRequestNotification()
.setRequestId(request.getId()).setApplyContent(request.getApplyContent()).setAddSource(request.getAddSource())
.setOperatorUserId(fromUserId).setFriendUserId(fromUserId);
@ -172,7 +172,7 @@ public class ImFriendRequestServiceImpl implements ImFriendRequestService {
// 1.1 校验申请存在、未处理、操作人是接收方
ImFriendRequestDO request = validateRequestForHandle(userId, requestId);
// 1.2 复验双方用户有效
adminUserApi.validateUserList(List.of(request.getFromUserId(), request.getToUserId()));
adminUserApi.validateUserList(List.of(request.getFromUserId(), request.getToUserId())).checkError();
// 2. 乐观锁更新申请处理结果
ImFriendRequestDO updateObj = new ImFriendRequestDO()

View File

@ -98,7 +98,7 @@ public class ImGroupRequestServiceImpl implements ImGroupRequestService {
ImGroupRequestDO request = createOrResetApplyRequest(groupId, userId, reqVO);
// 4. 1503 私聊定向推群主 + 全部管理员多端同步payload 携带申请方昵称 / 头像
AdminUserRespDTO applyUser = adminUserApi.getUser(userId);
AdminUserRespDTO applyUser = adminUserApi.getUser(userId).getCheckedData();
GroupRequestReceivedNotification payload = buildRequestNotification(group, request, applyUser);
for (Long receiverUserId : getGroupMemberListByOwnerAndAdminUserIds(group)) {
websocketService.sendPrivateMessageAsync(receiverUserId, ImPrivateMessageDTO.ofGroupNotification(

View File

@ -235,7 +235,7 @@ public class ImRtcCallServiceImpl implements ImRtcCallService {
rtcParticipantMapper.insertBatch(participants);
// 3.1 推送通知RTC_CALL(INVITE) 给每个被邀请人
AdminUserRespDTO inviterUser = adminUserApi.getUser(inviterId);
AdminUserRespDTO inviterUser = adminUserApi.getUser(inviterId).getCheckedData();
Map<Long, AdminUserRespDTO> inviteeMap = adminUserApi.getUserMap(invitees);
for (Long inviteeId : invitees) {
pushCallInviteNotification(call, inviterUser, inviteeId, inviteeMap.get(inviteeId), invitees);
@ -303,7 +303,7 @@ public class ImRtcCallServiceImpl implements ImRtcCallService {
rtcParticipantMapper.insertBatch(participants);
// 3. 推送通知RTC_CALL(INVITE) 给每个新邀请人
AdminUserRespDTO inviter = adminUserApi.getUser(inviterId);
AdminUserRespDTO inviter = adminUserApi.getUser(inviterId).getCheckedData();
Map<Long, AdminUserRespDTO> inviteeMap = adminUserApi.getUserMap(incomingUserIds);
for (Long inviteeId : incomingUserIds) {
pushCallInviteNotification(call, inviter, inviteeId, inviteeMap.get(inviteeId), incomingUserIds);
@ -491,7 +491,7 @@ public class ImRtcCallServiceImpl implements ImRtcCallService {
if (!ImRtcParticipantStatusEnum.isJoined(participant.getStatus())) {
throw exception(RTC_NOT_PARTICIPANT);
}
return signToken(userId, resolveDisplayName(adminUserApi.getUser(userId), userId), room);
return signToken(userId, resolveDisplayName(adminUserApi.getUser(userId).getCheckedData(), userId), room);
}
@Override
@ -1016,7 +1016,7 @@ public class ImRtcCallServiceImpl implements ImRtcCallService {
* @param operatorUserId
*/
private void pushCallRejectNotification(ImRtcCallDO call, Long operatorUserId) {
AdminUserRespDTO operator = operatorUserId != null ? adminUserApi.getUser(operatorUserId) : null;
AdminUserRespDTO operator = operatorUserId != null ? adminUserApi.getUser(operatorUserId).getCheckedData() : null;
ImRtcCallNotification payload = ImRtcCallNotification.ofReject(call, operatorUserId, operator);
for (Long receiverUserId : getCallAudienceUserIdList(call)) {
webSocketService.sendPrivateMessageAsync(receiverUserId, ImPrivateMessageDTO.ofRtcNotification(
@ -1107,7 +1107,7 @@ public class ImRtcCallServiceImpl implements ImRtcCallService {
*/
private void pushCallEndNotification(ImRtcCallDO call, Long operatorId, ImRtcCallEndReasonEnum reason,
Long durationSeconds) {
AdminUserRespDTO operator = operatorId != null ? adminUserApi.getUser(operatorId) : null;
AdminUserRespDTO operator = operatorId != null ? adminUserApi.getUser(operatorId).getCheckedData() : null;
ImRtcCallEndNotification payload = ImRtcCallEndNotification.of(call, reason, durationSeconds, operatorId, operator);
Long peerUserId = null;
if (!ImConversationTypeEnum.isGroup(call.getConversationType())) {

View File

@ -24,6 +24,7 @@ import org.springframework.dao.DuplicateKeyException;
import java.time.LocalDateTime;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
@ -142,7 +143,7 @@ public class ImFriendRequestServiceImplTest extends BaseMockitoUnitTest {
when(friendService.getFriendState(1L, 2L)).thenReturn(ImFriendStateEnum.NONE.getState());
when(friendService.getFriend(2L, 1L)).thenReturn(null);
when(friendRequestMapper.selectByFromUserIdAndToUserId(1L, 2L)).thenReturn(null);
when(adminUserApi.getUser(1L)).thenReturn(new AdminUserRespDTO().setNickname("张三").setAvatar("a.png"));
when(adminUserApi.getUser(1L)).thenReturn(success(new AdminUserRespDTO().setNickname("张三").setAvatar("a.png")));
when(imProperties.getFriend()).thenReturn(new ImProperties.Friend());
// 调用
@ -172,7 +173,7 @@ public class ImFriendRequestServiceImplTest extends BaseMockitoUnitTest {
.setHandleResult(ImFriendRequestHandleResultEnum.REFUSED.getResult())
.setHandleContent("旧拒绝").setApplyContent("旧内容");
when(friendRequestMapper.selectByFromUserIdAndToUserId(1L, 2L)).thenReturn(old);
when(adminUserApi.getUser(1L)).thenReturn(null);
when(adminUserApi.getUser(1L)).thenReturn(success(null));
when(imProperties.getFriend()).thenReturn(new ImProperties.Friend());
// 调用
@ -200,7 +201,7 @@ public class ImFriendRequestServiceImplTest extends BaseMockitoUnitTest {
.setHandleResult(ImFriendRequestHandleResultEnum.REFUSED.getResult());
when(friendRequestMapper.selectByFromUserIdAndToUserId(1L, 2L)).thenReturn(null, old);
when(friendRequestMapper.insert(any(ImFriendRequestDO.class))).thenThrow(new DuplicateKeyException("dup"));
when(adminUserApi.getUser(1L)).thenReturn(null);
when(adminUserApi.getUser(1L)).thenReturn(success(null));
when(imProperties.getFriend()).thenReturn(new ImProperties.Friend());
// 调用

View File

@ -29,6 +29,7 @@ import org.springframework.dao.DuplicateKeyException;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.module.im.enums.ErrorCodeConstants.*;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.*;
@ -102,7 +103,7 @@ public class ImGroupRequestServiceImplTest extends BaseMockitoUnitTest {
ImGroupMemberDO.builder().groupId(10L).userId(98L)
.role(ImGroupMemberRoleEnum.ADMIN.getRole())
.status(CommonStatusEnum.ENABLE.getStatus()).build()));
when(adminUserApi.getUser(1L)).thenReturn(buildUser(1L, "申请人"));
when(adminUserApi.getUser(1L)).thenReturn(success(buildUser(1L, "申请人")));
ImGroupRequestApplyReqVO reqVO = new ImGroupRequestApplyReqVO();
reqVO.setGroupId(10L);
@ -131,7 +132,7 @@ public class ImGroupRequestServiceImplTest extends BaseMockitoUnitTest {
ImGroupMemberDO.builder().groupId(10L).userId(99L)
.role(ImGroupMemberRoleEnum.OWNER.getRole())
.status(CommonStatusEnum.ENABLE.getStatus()).build()));
when(adminUserApi.getUser(1L)).thenReturn(buildUser(1L, "申请人"));
when(adminUserApi.getUser(1L)).thenReturn(success(buildUser(1L, "申请人")));
ImGroupRequestDO old = new ImGroupRequestDO().setId(50L).setGroupId(10L).setUserId(1L)
.setHandleResult(ImGroupRequestHandleResultEnum.REFUSED.getResult());
when(groupRequestMapper.selectByGroupIdAndUserId(10L, 1L)).thenReturn(null, old);

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.infra.api.config;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.infra.enums.ApiConstants;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
@ -15,6 +16,6 @@ public interface ConfigApi {
@GetMapping(PREFIX + "/get-value-by-key")
@Operation(summary = "根据参数键查询参数值")
String getConfigValueByKey(@RequestParam("key") String key);
CommonResult<String> getConfigValueByKey(@RequestParam("key") String key);
}

View File

@ -1,11 +1,14 @@
package cn.iocoder.yudao.module.infra.api.config;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.infra.dal.dataobject.config.ConfigDO;
import cn.iocoder.yudao.module.infra.service.config.ConfigService;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RestController;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RestController // 提供 RESTful API 接口,给 Feign 调用
@Validated
public class ConfigApiImpl implements ConfigApi {
@ -14,9 +17,9 @@ public class ConfigApiImpl implements ConfigApi {
private ConfigService configService;
@Override
public String getConfigValueByKey(String key) {
public CommonResult<String> getConfigValueByKey(String key) {
ConfigDO config = configService.getConfigByKey(key);
return config != null ? config.getValue() : null;
return success(config != null ? config.getValue() : null);
}
}

View File

@ -47,7 +47,7 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService {
public Long createAlertConfig(IotAlertConfigSaveReqVO createReqVO) {
// 校验关联数据是否存在
sceneRuleService.validateSceneRuleList(createReqVO.getSceneRuleIds());
adminUserApi.validateUserList(createReqVO.getReceiveUserIds());
adminUserApi.validateUserList(createReqVO.getReceiveUserIds()).checkError();
validateReceiveTemplates(createReqVO);
// 插入
@ -62,7 +62,7 @@ public class IotAlertConfigServiceImpl implements IotAlertConfigService {
validateAlertConfigExists(updateReqVO.getId());
// 校验关联数据是否存在
sceneRuleService.validateSceneRuleList(updateReqVO.getSceneRuleIds());
adminUserApi.validateUserList(updateReqVO.getReceiveUserIds());
adminUserApi.validateUserList(updateReqVO.getReceiveUserIds()).checkError();
validateReceiveTemplates(updateReqVO);
// 更新

View File

@ -69,7 +69,7 @@ public class KeFuMessageServiceImpl implements KeFuMessageService {
conversationService.updateConversationLastMessage(kefuMessage);
// 3.1 发送消息给会员
AdminUserRespDTO user = adminUserApi.getUser(kefuMessage.getSenderId());
AdminUserRespDTO user = adminUserApi.getUser(kefuMessage.getSenderId()).getCheckedData();
KeFuMessageRespVO message = BeanUtils.toBean(kefuMessage, KeFuMessageRespVO.class).setSenderAvatar(user.getAvatar());
getSelf().sendAsyncMessageToMember(conversation.getUserId(), KEFU_MESSAGE_TYPE, message);
// 3.2 通知所有管理员更新对话

View File

@ -72,7 +72,7 @@ public class DeliveryPickUpStoreController {
return success(null);
}
List<AdminUserRespDTO> verifyUsers = CollUtil.isNotEmpty(deliveryPickUpStore.getVerifyUserIds()) ?
adminUserApi.getUserList(deliveryPickUpStore.getVerifyUserIds()) : null;
adminUserApi.getUserList(deliveryPickUpStore.getVerifyUserIds()).getCheckedData() : null;
return success(BeanUtils.toBean(deliveryPickUpStore, DeliveryPickUpStoreRespVO.class)
.setVerifyUsers(BeanUtils.toBean(verifyUsers, UserSimpleBaseVO.class)));
}

View File

@ -93,7 +93,7 @@ public class DeliveryPickUpStoreServiceImpl implements DeliveryPickUpStoreServic
// 1.1 校验门店存在
validateDeliveryPickUpStoreExists(bindReqVO.getId());
// 1.2 校验用户存在
adminUserApi.validateUserList(bindReqVO.getVerifyUserIds());
adminUserApi.validateUserList(bindReqVO.getVerifyUserIds()).checkError();
// 2. 更新
DeliveryPickUpStoreDO updateObj = BeanUtils.toBean(bindReqVO, DeliveryPickUpStoreDO.class);

View File

@ -143,7 +143,7 @@ public class MesProWorkRecordController {
vo.setWorkstationCode(ws.getCode()).setWorkstationName(ws.getName());
}
// 拼接用户信息
AdminUserRespDTO user = adminUserApi.getUser(record.getUserId());
AdminUserRespDTO user = adminUserApi.getUser(record.getUserId()).getCheckedData();
if (user != null) {
vo.setUserNickname(user.getNickname());
}

View File

@ -95,7 +95,7 @@ public class MesCalTeamMemberServiceImpl implements MesCalTeamMemberService {
}
private void validateUserExists(Long userId) {
if (adminUserApi.getUser(userId) == null) {
if (adminUserApi.getUser(userId).getCheckedData() == null) {
throw exception(CAL_TEAM_MEMBER_USER_NOT_EXISTS);
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.system.api.dept;
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.DeptRespDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
@ -13,7 +14,6 @@ import org.springframework.web.bind.annotation.RequestParam;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;
@FeignClient(name = ApiConstants.NAME) // TODO 芋艿fallbackFactory =
@Tag(name = "RPC 服务 - 部门")
@ -24,17 +24,17 @@ public interface DeptApi {
@GetMapping(PREFIX + "/get")
@Operation(summary = "获得部门信息")
@Parameter(name = "id", description = "部门编号", example = "1024", required = true)
DeptRespDTO getDept(@RequestParam("id") Long id);
CommonResult<DeptRespDTO> getDept(@RequestParam("id") Long id);
@GetMapping(PREFIX + "/list")
@Operation(summary = "获得部门信息数组")
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
List<DeptRespDTO> getDeptList(@RequestParam("ids") Collection<Long> ids);
CommonResult<List<DeptRespDTO>> getDeptList(@RequestParam("ids") Collection<Long> ids);
@GetMapping(PREFIX + "/valid")
@Operation(summary = "校验部门是否合法")
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
void validateDeptList(@RequestParam("ids") Collection<Long> ids);
CommonResult<Boolean> validateDeptList(@RequestParam("ids") Collection<Long> ids);
/**
* Map
@ -43,13 +43,13 @@ public interface DeptApi {
* @return Map
*/
default Map<Long, DeptRespDTO> getDeptMap(Collection<Long> ids) {
List<DeptRespDTO> list = getDeptList(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)
List<DeptRespDTO> getChildDeptList(@RequestParam("id") Long id);
CommonResult<List<DeptRespDTO>> getChildDeptList(@RequestParam("id") Long id);
}

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.system.api.user;
import cn.hutool.core.convert.Convert;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.enums.ApiConstants;
@ -31,32 +32,32 @@ public interface AdminUserApi extends AutoTransable<AdminUserRespDTO> {
@GetMapping(PREFIX + "/get")
@Operation(summary = "通过用户 ID 查询用户")
@Parameter(name = "id", description = "用户编号", example = "1", required = true)
AdminUserRespDTO getUser(@RequestParam("id") Long id);
CommonResult<AdminUserRespDTO> getUser(@RequestParam("id") Long id);
@GetMapping(PREFIX + "/list-by-subordinate")
@Operation(summary = "通过用户 ID 查询用户下属")
@Parameter(name = "id", description = "用户编号", example = "1", required = true)
List<AdminUserRespDTO> getUserListBySubordinate(@RequestParam("id") Long id);
CommonResult<List<AdminUserRespDTO>> getUserListBySubordinate(@RequestParam("id") Long id);
@GetMapping(PREFIX + "/list")
@Operation(summary = "通过用户 ID 查询用户们")
@Parameter(name = "ids", description = "部门编号数组", example = "1,2", required = true)
List<AdminUserRespDTO> getUserList(@RequestParam("ids") Collection<Long> ids);
CommonResult<List<AdminUserRespDTO>> getUserList(@RequestParam("ids") Collection<Long> ids);
@GetMapping(PREFIX + "/list-by-dept-id")
@Operation(summary = "获得指定部门的用户数组")
@Parameter(name = "deptIds", description = "部门编号数组", example = "1,2", required = true)
List<AdminUserRespDTO> getUserListByDeptIds(@RequestParam("deptIds") Collection<Long> deptIds);
CommonResult<List<AdminUserRespDTO>> getUserListByDeptIds(@RequestParam("deptIds") Collection<Long> deptIds);
@GetMapping(PREFIX + "/list-by-post-id")
@Operation(summary = "获得指定岗位的用户数组")
@Parameter(name = "postIds", description = "岗位编号数组", example = "2,3", required = true)
List<AdminUserRespDTO> getUserListByPostIds(@RequestParam("postIds") Collection<Long> postIds);
CommonResult<List<AdminUserRespDTO>> getUserListByPostIds(@RequestParam("postIds") Collection<Long> postIds);
@GetMapping(PREFIX + "/list-by-nickname")
@Operation(summary = "根据昵称模糊搜索用户")
@Parameter(name = "nickname", description = "昵称关键词", example = "芋道", required = true)
List<AdminUserRespDTO> getUserListByNickname(@RequestParam("nickname") String nickname);
CommonResult<List<AdminUserRespDTO>> getUserListByNickname(@RequestParam("nickname") String nickname);
/**
* Map
@ -65,7 +66,7 @@ public interface AdminUserApi extends AutoTransable<AdminUserRespDTO> {
* @return Map
*/
default Map<Long, AdminUserRespDTO> getUserMap(Collection<Long> ids) {
List<AdminUserRespDTO> users = getUserList(ids);
List<AdminUserRespDTO> users = getUserList(ids).getCheckedData();
return CollectionUtils.convertMap(users, AdminUserRespDTO::getId);
}
@ -77,24 +78,24 @@ public interface AdminUserApi extends AutoTransable<AdminUserRespDTO> {
* @param id
*/
default void validateUser(Long id) {
validateUserList(Collections.singleton(id));
validateUserList(Collections.singleton(id)).checkError();
}
@GetMapping(PREFIX + "/valid")
@Operation(summary = "校验用户们是否有效")
@Parameter(name = "ids", description = "用户编号数组", example = "3,5", required = true)
void validateUserList(@RequestParam("ids") Collection<Long> ids);
CommonResult<Boolean> validateUserList(@RequestParam("ids") Collection<Long> ids);
@Override
@FeignIgnore
default List<AdminUserRespDTO> selectByIds(List<?> ids) {
return getUserList(Convert.toList(Long.class, ids));
return getUserList(Convert.toList(Long.class, ids)).getCheckedData();
}
@Override
@FeignIgnore
default AdminUserRespDTO selectById(Object id) {
return getUser(Convert.toLong(id));
return getUser(Convert.toLong(id)).getCheckedData();
}
}

View File

@ -1,5 +1,6 @@
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.DeptRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
@ -11,6 +12,8 @@ import jakarta.annotation.Resource;
import java.util.Collection;
import java.util.List;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
@RestController // 提供 RESTful API 接口,给 Feign 调用
@Validated
public class DeptApiImpl implements DeptApi {
@ -19,26 +22,27 @@ public class DeptApiImpl implements DeptApi {
private DeptService deptService;
@Override
public DeptRespDTO getDept(Long id) {
public CommonResult<DeptRespDTO> getDept(Long id) {
DeptDO dept = deptService.getDept(id);
return BeanUtils.toBean(dept, DeptRespDTO.class);
return success(BeanUtils.toBean(dept, DeptRespDTO.class));
}
@Override
public List<DeptRespDTO> getDeptList(Collection<Long> ids) {
public CommonResult<List<DeptRespDTO>> getDeptList(Collection<Long> ids) {
List<DeptDO> depts = deptService.getDeptList(ids);
return BeanUtils.toBean(depts, DeptRespDTO.class);
return success(BeanUtils.toBean(depts, DeptRespDTO.class));
}
@Override
public void validateDeptList(Collection<Long> ids) {
public CommonResult<Boolean> validateDeptList(Collection<Long> ids) {
deptService.validateDeptList(ids);
return success(true);
}
@Override
public List<DeptRespDTO> getChildDeptList(Long id) {
public CommonResult<List<DeptRespDTO>> getChildDeptList(Long id) {
List<DeptDO> depts = deptService.getChildDeptList(id);
return BeanUtils.toBean(depts, DeptRespDTO.class);
return success(BeanUtils.toBean(depts, DeptRespDTO.class));
}
}

View File

@ -2,6 +2,7 @@ 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.framework.datapermission.core.annotation.DataPermission;
import cn.iocoder.yudao.framework.datapermission.core.util.DataPermissionUtils;
@ -19,6 +20,7 @@ import java.util.Collection;
import java.util.Collections;
import java.util.List;
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 调用
@ -32,25 +34,25 @@ public class AdminUserApiImpl implements AdminUserApi {
@Override
@DataPermission(enable = false) // 忽略数据权限避免因为过滤导致无法查询用户。类似https://github.com/YunaiV/ruoyi-vue-pro/issues/1051
public AdminUserRespDTO getUser(Long id) {
public CommonResult<AdminUserRespDTO> getUser(Long id) {
AdminUserDO user = userService.getUser(id);
return BeanUtils.toBean(user, AdminUserRespDTO.class);
return success(BeanUtils.toBean(user, AdminUserRespDTO.class));
}
@Override
public List<AdminUserRespDTO> getUserListBySubordinate(Long id) {
public CommonResult<List<AdminUserRespDTO>> getUserListBySubordinate(Long id) {
// 1.1 获取用户负责的部门
AdminUserDO user = userService.getUser(id);
if (user == null) {
return Collections.emptyList();
return success(Collections.emptyList());
}
ArrayList<Long> deptIds = new ArrayList<>();
DeptDO dept = deptService.getDept(user.getDeptId());
if (dept == null) {
return Collections.emptyList();
return success(Collections.emptyList());
}
if (ObjUtil.notEqual(dept.getLeaderUserId(), id)) { // 校验为负责人
return Collections.emptyList();
return success(Collections.emptyList());
}
deptIds.add(dept.getId());
// 1.2 获取所有子部门
@ -62,38 +64,39 @@ public class AdminUserApiImpl implements AdminUserApi {
// 2. 获取部门对应的用户信息
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds);
users.removeIf(item -> ObjUtil.equal(item.getId(), id)); // 排除自己
return BeanUtils.toBean(users, AdminUserRespDTO.class);
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
}
@Override
public List<AdminUserRespDTO> getUserList(Collection<Long> ids) {
return DataPermissionUtils.executeIgnore(() -> { // 禁用数据权限。原因是,一般基于指定 id 的 API 查询,都是数据拼接为主
public CommonResult<List<AdminUserRespDTO>> getUserList(Collection<Long> ids) {
return success(DataPermissionUtils.executeIgnore(() -> { // 禁用数据权限。原因是,一般基于指定 id 的 API 查询,都是数据拼接为主
List<AdminUserDO> users = userService.getUserList(ids);
return BeanUtils.toBean(users, AdminUserRespDTO.class);
});
}));
}
@Override
public List<AdminUserRespDTO> getUserListByDeptIds(Collection<Long> deptIds) {
public CommonResult<List<AdminUserRespDTO>> getUserListByDeptIds(Collection<Long> deptIds) {
List<AdminUserDO> users = userService.getUserListByDeptIds(deptIds);
return BeanUtils.toBean(users, AdminUserRespDTO.class);
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
}
@Override
public List<AdminUserRespDTO> getUserListByPostIds(Collection<Long> postIds) {
public CommonResult<List<AdminUserRespDTO>> getUserListByPostIds(Collection<Long> postIds) {
List<AdminUserDO> users = userService.getUserListByPostIds(postIds);
return BeanUtils.toBean(users, AdminUserRespDTO.class);
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
}
@Override
public List<AdminUserRespDTO> getUserListByNickname(String nickname) {
public CommonResult<List<AdminUserRespDTO>> getUserListByNickname(String nickname) {
List<AdminUserDO> users = userService.getUserListByNickname(nickname);
return BeanUtils.toBean(users, AdminUserRespDTO.class);
return success(BeanUtils.toBean(users, AdminUserRespDTO.class));
}
@Override
public void validateUserList(Collection<Long> ids) {
public CommonResult<Boolean> validateUserList(Collection<Long> ids) {
userService.validateUserList(ids);
return success(true);
}
}

View File

@ -126,7 +126,7 @@ public class AdminUserServiceImpl implements AdminUserService {
@Override
public Long registerUser(AuthRegisterReqVO registerReqVO) {
// 1.1 校验是否开启注册
if (ObjUtil.notEqual(configApi.getConfigValueByKey(USER_REGISTER_ENABLED_KEY), "true")) {
if (ObjUtil.notEqual(configApi.getConfigValueByKey(USER_REGISTER_ENABLED_KEY).getCheckedData(), "true")) {
throw exception(USER_REGISTER_DISABLED);
}
// 1.2 校验账户配合
@ -509,7 +509,7 @@ public class AdminUserServiceImpl implements AdminUserService {
throw exception(USER_IMPORT_LIST_IS_EMPTY);
}
// 1.2 初始化密码不能为空
String initPassword = configApi.getConfigValueByKey(USER_INIT_PASSWORD_KEY);
String initPassword = configApi.getConfigValueByKey(USER_INIT_PASSWORD_KEY).getCheckedData();
if (StrUtil.isEmpty(initPassword)) {
throw exception(USER_IMPORT_INIT_PASSWORD);
}

View File

@ -43,6 +43,7 @@ import java.util.Map;
import java.util.function.Consumer;
import static cn.hutool.core.util.RandomUtil.randomEle;
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
import static cn.iocoder.yudao.framework.common.util.collection.SetUtils.asSet;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildBetweenTime;
import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.buildTime;
@ -92,7 +93,7 @@ public class AdminUserServiceImplTest extends BaseDbUnitTest {
@BeforeEach
public void before() {
// mock 初始化密码
when(configApi.getConfigValueByKey(USER_INIT_PASSWORD_KEY)).thenReturn("yudaoyuanma");
when(configApi.getConfigValueByKey(USER_INIT_PASSWORD_KEY)).thenReturn(success("yudaoyuanma"));
}
@Test