fix(接口测试): 修复接口导入定时任务导入失败的缺陷

--bug=1038749 --user=王孝刚 【接口测试】定义-定时导入接口添加报错
https://www.tapd.cn/55049933/s/1490721
This commit is contained in:
wxg0103 2024-04-08 17:38:34 +08:00 committed by 刘瑞斌
parent 50e6ecadae
commit abe1d9624d
2 changed files with 15 additions and 3 deletions

View File

@ -8,7 +8,6 @@ import io.metersphere.api.service.definition.ApiDefinitionScheduleService;
import io.metersphere.sdk.constants.PermissionConstants; import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.system.log.annotation.Log; import io.metersphere.system.log.annotation.Log;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.security.CheckOwner;
import io.metersphere.system.utils.SessionUtils; import io.metersphere.system.utils.SessionUtils;
import io.metersphere.validation.groups.Created; import io.metersphere.validation.groups.Created;
import io.metersphere.validation.groups.Updated; import io.metersphere.validation.groups.Updated;
@ -31,7 +30,6 @@ public class ApiDefinitionScheduleController {
@Operation(summary = "接口测试-接口管理-定时同步-创建") @Operation(summary = "接口测试-接口管理-定时同步-创建")
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT) @RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT)
@Log(type = OperationLogType.ADD, expression = "#msClass.scheduleLog(#request)", msClass = ApiDefinitionLogService.class) @Log(type = OperationLogType.ADD, expression = "#msClass.scheduleLog(#request)", msClass = ApiDefinitionLogService.class)
@CheckOwner(resourceId = "#request.getScenarioId()", resourceType = "api_scenario")
public String createSchedule(@RequestBody @Validated({Created.class}) ApiScheduleRequest request) { public String createSchedule(@RequestBody @Validated({Created.class}) ApiScheduleRequest request) {
return apiDefinitionScheduleService.createSchedule(request, SessionUtils.getUserId()); return apiDefinitionScheduleService.createSchedule(request, SessionUtils.getUserId());
} }

View File

@ -20,6 +20,7 @@ import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.log.constants.OperationLogType; import io.metersphere.system.log.constants.OperationLogType;
import io.metersphere.system.log.dto.LogDTO; import io.metersphere.system.log.dto.LogDTO;
import io.metersphere.system.log.service.OperationLogService; import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.service.UserLoginService;
import io.metersphere.system.uid.IDGenerator; import io.metersphere.system.uid.IDGenerator;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
@ -46,6 +47,8 @@ public class FakeErrorService {
@Resource @Resource
private ExtFakeErrorMapper extFakeErrorMapper; private ExtFakeErrorMapper extFakeErrorMapper;
@Resource
private UserLoginService userLoginService;
private static final String ADD_TYPE = "ADD"; private static final String ADD_TYPE = "ADD";
@ -124,7 +127,18 @@ public class FakeErrorService {
if (StringUtils.isNotBlank(request.getKeyword())) { if (StringUtils.isNotBlank(request.getKeyword())) {
criteria.andNameLike("%" + request.getKeyword() + "%"); criteria.andNameLike("%" + request.getKeyword() + "%");
} }
return fakeErrorMapper.selectByExample(example); List<FakeError> fakeErrors = fakeErrorMapper.selectByExample(example);
//把createUser和updateUser提取出来生成新的set
List<String> userIds = new ArrayList<>();
userIds.addAll(fakeErrors.stream().map(FakeError::getCreateUser).toList());
userIds.addAll(fakeErrors.stream().map(FakeError::getUpdateUser).toList());
Map<String, String> userMap = userLoginService.getUserNameMap(userIds.stream().filter(StringUtils::isNotBlank).distinct().toList());
fakeErrors.forEach(fakeError -> {
fakeError.setCreateUser(userMap.get(fakeError.getCreateUser()));
fakeError.setUpdateUser(userMap.get(fakeError.getUpdateUser()));
});
return fakeErrors;
} }