fix(接口测试): 修复消息通知人错误问题

--bug=1021753 --user=赵勇 【项目设置】站内消息通知用户名显示错误 https://www.tapd.cn/55049933/s/1324990
This commit is contained in:
fit2-zhao 2023-01-10 13:18:04 +08:00 committed by fit2-zhao
parent 1df1817063
commit 32d335c6fd
2 changed files with 27 additions and 16 deletions

View File

@ -11,4 +11,7 @@ public class CommonConstants {
public static final String USER_ID = "userId";
public static final String METHODS_KEY = "methods";
public static final String CASE = "CASE";
public static final String USER = "user";
public static final String USER_NAME = "userName";
}

View File

@ -95,18 +95,7 @@ public class ApiDefinitionExecResultService {
if (result != null) {
result.setResourceId(dto.getTestId());
apiExecutionInfoService.insertExecutionInfo(result);
User user = null;
if (MapUtils.isNotEmpty(dto.getExtendedParameters())) {
if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID) && dto.getExtendedParameters().containsKey("userName")) {
user = new User() {{
this.setId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString());
this.setName(dto.getExtendedParameters().get("userName").toString());
}};
result.setUserId(user.getId());
} else if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID)) {
result.setUserId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString());
}
}
User user = getUser(dto, result);
//如果是测试计划用例更新接口用例的上次执行结果
TestPlanApiCase testPlanApiCase = testPlanApiCaseMapper.selectByPrimaryKey(dto.getTestId());
if (testPlanApiCase != null) {
@ -147,10 +136,12 @@ public class ApiDefinitionExecResultService {
// 批量更新关联关系状态
batchEditStatus(dto.getRunMode(), result.getStatus(), result.getId(), dto.getTestId(), planApiCaseMapper, batchApiTestCaseMapper);
}
if (result != null && !StringUtils.startsWithAny(dto.getRunMode(), "SCHEDULE")) {
User user = null;
if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey("user") && dto.getExtendedParameters().get("user") instanceof User) {
user = (User) dto.getExtendedParameters().get("user");
if (result != null && !StringUtils.startsWithAny(dto.getRunMode(), NoticeConstants.Mode.SCHEDULE)) {
User user = getUser(dto, result);
if (MapUtils.isNotEmpty(dto.getExtendedParameters())
&& dto.getExtendedParameters().containsKey(CommonConstants.USER)
&& dto.getExtendedParameters().get(CommonConstants.USER) instanceof User) {
user = (User) dto.getExtendedParameters().get(CommonConstants.USER);
}
// 发送通知
result.setResourceId(dto.getTestId());
@ -166,6 +157,23 @@ public class ApiDefinitionExecResultService {
}
}
private User getUser(ResultDTO dto, ApiDefinitionExecResult result) {
User user = null;
if (MapUtils.isNotEmpty(dto.getExtendedParameters())) {
if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID)
&& dto.getExtendedParameters().containsKey(CommonConstants.USER_NAME)) {
user = new User() {{
this.setId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString());
this.setName(dto.getExtendedParameters().get(CommonConstants.USER_NAME).toString());
}};
result.setUserId(user.getId());
} else if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID)) {
result.setUserId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString());
}
}
return user;
}
private void sendNotice(ApiDefinitionExecResult result, User user) {
try {
String resourceId = result.getResourceId();