fix(接口测试): 修复定时导入不生效的缺陷
This commit is contained in:
parent
fbdf3b1be3
commit
b888024dea
|
@ -28,7 +28,7 @@ public class ApiReportShareController {
|
|||
@Operation(summary = "接口测试-接口报告-生成分享链接")
|
||||
@RequiresPermissions(PermissionConstants.PROJECT_API_REPORT_SHARE)
|
||||
public ShareInfoDTO generateShareInfo(@Validated(Created.class) @RequestBody ApiReportShareRequest request) {
|
||||
return apiReportShareService.gen(request, Objects.requireNonNull(SessionUtils.getUser()));
|
||||
return apiReportShareService.gen(request, SessionUtils.getUserId());
|
||||
}
|
||||
|
||||
@GetMapping("/get/{id}")
|
||||
|
|
|
@ -217,7 +217,8 @@ public class ApiDefinitionController {
|
|||
@RequiresPermissions(PermissionConstants.PROJECT_API_DEFINITION_IMPORT)
|
||||
@Operation(summary = "接口测试-接口管理-导入接口定义")
|
||||
public void testCaseImport(@RequestPart(value = "file", required = false) MultipartFile file, @RequestPart("request") ImportRequest request) {
|
||||
apiDefinitionService.apiTestImport(file, request, SessionUtils.getUser(), SessionUtils.getCurrentProjectId());
|
||||
request.setUserId(SessionUtils.getUserId());
|
||||
apiDefinitionService.apiTestImport(file, request, SessionUtils.getCurrentProjectId());
|
||||
}
|
||||
|
||||
@PostMapping("/operation-history")
|
||||
|
|
|
@ -4,6 +4,8 @@ import io.metersphere.api.domain.ApiReport;
|
|||
import io.metersphere.api.domain.ApiScenario;
|
||||
import io.metersphere.api.domain.ApiScenarioReport;
|
||||
import io.metersphere.api.domain.ApiTestCase;
|
||||
import io.metersphere.api.dto.share.ApiReportShareRequest;
|
||||
import io.metersphere.api.dto.share.ShareInfoDTO;
|
||||
import io.metersphere.api.mapper.ApiReportMapper;
|
||||
import io.metersphere.api.mapper.ApiScenarioMapper;
|
||||
import io.metersphere.api.mapper.ApiScenarioReportMapper;
|
||||
|
@ -51,23 +53,32 @@ public class ApiReportSendNoticeService {
|
|||
@Resource
|
||||
private ProjectMapper projectMapper;
|
||||
private static final String API_SCENARIO = "API_SCENARIO";
|
||||
private static final String API_CASE = "API_CASE";
|
||||
|
||||
public void sendNotice(ApiNoticeDTO noticeDTO) {
|
||||
String noticeType;
|
||||
String reportUrl;
|
||||
SystemParameterService systemParameterService = CommonBeanFactory.getBean(SystemParameterService.class);
|
||||
assert systemParameterService != null;
|
||||
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
|
||||
BeanMap beanMap;
|
||||
String event;
|
||||
String status;
|
||||
ApiReportShareService shareService = CommonBeanFactory.getBean(ApiReportShareService.class);
|
||||
ApiReportShareRequest shareRequest = new ApiReportShareRequest();
|
||||
shareRequest.setReportId(noticeDTO.getReportId());
|
||||
shareRequest.setProjectId(noticeDTO.getProjectId());
|
||||
assert shareService != null;
|
||||
ShareInfoDTO url = shareService.gen(shareRequest, noticeDTO.getUserId());
|
||||
Project project = projectMapper.selectByPrimaryKey(noticeDTO.getProjectId());
|
||||
String reportUrl = baseSystemConfigDTO.getUrl() + "/#/api-test/report?orgId=%s&pId=%s&type=%s&reportId=%s";
|
||||
String shareUrl = baseSystemConfigDTO.getUrl() + "/#/share/%s?shareId=" + url.getId();
|
||||
ApiScenarioReport report = new ApiScenarioReport();
|
||||
if (API_SCENARIO.equals(noticeDTO.getResourceType())) {
|
||||
ApiScenario scenario = apiScenarioMapper.selectByPrimaryKey(noticeDTO.getResourceId());
|
||||
beanMap = new BeanMap(scenario);
|
||||
noticeType = NoticeConstants.TaskType.API_SCENARIO_TASK;
|
||||
reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report/view/" + noticeDTO.getReportId();
|
||||
report = apiScenarioReportMapper.selectByPrimaryKey(noticeDTO.getReportId());
|
||||
reportUrl = String.format(reportUrl, project.getOrganizationId(), project.getId(), API_SCENARIO, report.getId());
|
||||
if (StringUtils.endsWithIgnoreCase(noticeDTO.getReportStatus(), ApiReportStatus.SUCCESS.name())) {
|
||||
event = NoticeConstants.Event.SCENARIO_EXECUTE_SUCCESSFUL;
|
||||
status = "成功";
|
||||
|
@ -78,13 +89,14 @@ public class ApiReportSendNoticeService {
|
|||
event = NoticeConstants.Event.SCENARIO_EXECUTE_FAILED;
|
||||
status = "失败";
|
||||
}
|
||||
shareUrl = String.format(shareUrl, "shareReportScenario");
|
||||
} else {
|
||||
ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(noticeDTO.getResourceId());
|
||||
beanMap = new BeanMap(testCase);
|
||||
|
||||
// TODO 是否需要区分场景和用例
|
||||
noticeType = NoticeConstants.TaskType.API_DEFINITION_TASK;
|
||||
reportUrl = baseSystemConfigDTO.getUrl() + "/#/api/automation/report/view/" + noticeDTO.getReportId();
|
||||
reportUrl = String.format(reportUrl, project.getOrganizationId(), project.getId(), API_CASE, report.getId());
|
||||
|
||||
ApiReport apiReport = apiReportMapper.selectByPrimaryKey(noticeDTO.getReportId());
|
||||
BeanUtils.copyBean(report, apiReport);
|
||||
|
@ -98,6 +110,7 @@ public class ApiReportSendNoticeService {
|
|||
event = NoticeConstants.Event.CASE_EXECUTE_FAILED;
|
||||
status = "失败";
|
||||
}
|
||||
shareUrl = String.format(shareUrl, "shareReportCase");
|
||||
}
|
||||
|
||||
String userId = noticeDTO.getUserId();
|
||||
|
@ -137,16 +150,11 @@ public class ApiReportSendNoticeService {
|
|||
}
|
||||
paramMap.put("reportUrl", reportUrl);
|
||||
|
||||
|
||||
// TODO: 缺少生成分享链接
|
||||
String shareUrl = null;
|
||||
paramMap.put("scenarioShareUrl", baseSystemConfigDTO.getUrl() + "/api/share-api-report" + shareUrl);
|
||||
paramMap.put("scenarioShareUrl", shareUrl);
|
||||
String context = "${operator}执行接口测试" + status + ": ${name}";
|
||||
NoticeModel noticeModel = NoticeModel.builder().operator(userId)
|
||||
.context(context).subject("执行通知").paramMap(paramMap).event(event).build();
|
||||
|
||||
Project project = projectMapper.selectByPrimaryKey(noticeDTO.getProjectId());
|
||||
|
||||
noticeSendService.send(project, noticeType, noticeModel);
|
||||
}
|
||||
|
||||
|
|
|
@ -16,7 +16,8 @@ import io.metersphere.sdk.exception.MSException;
|
|||
import io.metersphere.sdk.mapper.ShareInfoMapper;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
import io.metersphere.system.mapper.BaseUserMapper;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -42,6 +43,8 @@ public class ApiReportShareService {
|
|||
private ProjectApplicationMapper projectApplicationMapper;
|
||||
@Resource
|
||||
private ApiScenarioReportMapper apiScenarioReportMapper;
|
||||
@Resource
|
||||
private BaseUserMapper baseUserMapper;
|
||||
|
||||
private static final Long DEFAULT = 1000L * 60 * 60 * 24;
|
||||
|
||||
|
@ -102,12 +105,13 @@ public class ApiReportShareService {
|
|||
return returnDTO;
|
||||
}
|
||||
|
||||
public ShareInfoDTO gen(ApiReportShareRequest shareRequest, SessionUser user) {
|
||||
String lang = user.getLanguage() == null ? LocaleContextHolder.getLocale().toString() : user.getLanguage();
|
||||
public ShareInfoDTO gen(ApiReportShareRequest shareRequest, String userId) {
|
||||
UserDTO userDTO = baseUserMapper.selectById(userId);
|
||||
String lang = userDTO.getLanguage() == null ? LocaleContextHolder.getLocale().toString() : userDTO.getLanguage();
|
||||
ShareInfo request = new ShareInfo();
|
||||
BeanUtils.copyBean(request, shareRequest);
|
||||
request.setLang(lang);
|
||||
request.setCreateUser(user.getId());
|
||||
request.setCreateUser(userId);
|
||||
request.setCustomData(shareRequest.getReportId().getBytes());
|
||||
request.setShareType(ShareInfoType.API_SHARE_REPORT.name());
|
||||
ShareInfo shareInfo = createShareInfo(request);
|
||||
|
|
|
@ -14,8 +14,8 @@ import io.metersphere.api.dto.definition.ApiDefinitionDTO;
|
|||
import io.metersphere.api.dto.definition.ApiDefinitionPageRequest;
|
||||
import io.metersphere.api.dto.definition.ApiModuleRequest;
|
||||
import io.metersphere.api.dto.request.ImportRequest;
|
||||
import io.metersphere.api.dto.request.http.MsHeader;
|
||||
import io.metersphere.api.dto.request.http.MsHTTPElement;
|
||||
import io.metersphere.api.dto.request.http.MsHeader;
|
||||
import io.metersphere.api.dto.request.http.QueryParam;
|
||||
import io.metersphere.api.dto.request.http.RestParam;
|
||||
import io.metersphere.api.dto.request.http.body.*;
|
||||
|
@ -34,13 +34,14 @@ import io.metersphere.sdk.exception.MSException;
|
|||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.JSON;
|
||||
import io.metersphere.sdk.util.Translator;
|
||||
import io.metersphere.system.domain.User;
|
||||
import io.metersphere.system.dto.sdk.ApiDefinitionCaseDTO;
|
||||
import io.metersphere.system.dto.sdk.BaseTreeNode;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
import io.metersphere.system.log.constants.OperationLogModule;
|
||||
import io.metersphere.system.log.constants.OperationLogType;
|
||||
import io.metersphere.system.log.dto.LogDTO;
|
||||
import io.metersphere.system.log.service.OperationLogService;
|
||||
import io.metersphere.system.mapper.UserMapper;
|
||||
import io.metersphere.system.notice.constants.NoticeConstants;
|
||||
import io.metersphere.system.service.CommonNoticeSendService;
|
||||
import io.metersphere.system.uid.IDGenerator;
|
||||
|
@ -88,6 +89,8 @@ public class ApiDefinitionImportUtilService {
|
|||
private OperationLogService operationLogService;
|
||||
@Resource
|
||||
private CommonNoticeSendService commonNoticeSendService;
|
||||
@Resource
|
||||
private UserMapper userMapper;
|
||||
|
||||
private static final String FILE_JMX = "jmx";
|
||||
private static final String FILE_HAR = "har";
|
||||
|
@ -111,7 +114,7 @@ public class ApiDefinitionImportUtilService {
|
|||
}
|
||||
}
|
||||
|
||||
public void importApi(ImportRequest request, ApiDefinitionImport apiImport, SessionUser user) {
|
||||
public void importApi(ImportRequest request, ApiDefinitionImport apiImport) {
|
||||
String defaultVersion = extBaseProjectVersionMapper.getDefaultVersion(request.getProjectId());
|
||||
request.setDefaultVersion(defaultVersion);
|
||||
if (request.getVersionId() == null) {
|
||||
|
@ -133,11 +136,11 @@ public class ApiDefinitionImportUtilService {
|
|||
}
|
||||
|
||||
//处理数据,判断数据是否重复
|
||||
dealWithData(request, filterData, user);
|
||||
dealWithData(request, filterData);
|
||||
|
||||
}
|
||||
|
||||
private void dealWithData(ImportRequest request, List<ApiDefinitionImportDetail> importData, SessionUser user) {
|
||||
private void dealWithData(ImportRequest request, List<ApiDefinitionImportDetail> importData) {
|
||||
//查询数据库中所有的数据, 用于判断是否重复
|
||||
ApiDefinitionPageRequest pageRequest = new ApiDefinitionPageRequest();
|
||||
pageRequest.setProjectId(request.getProjectId());
|
||||
|
@ -176,7 +179,7 @@ public class ApiDefinitionImportUtilService {
|
|||
getNeedUpdateData(request, apiDealWithData, apiDetailWithDataUpdate);
|
||||
|
||||
//数据入库
|
||||
insertData(modulePathMap, idModuleMap, apiDetailWithDataUpdate, request, user);
|
||||
insertData(modulePathMap, idModuleMap, apiDetailWithDataUpdate, request);
|
||||
|
||||
}
|
||||
|
||||
|
@ -219,7 +222,7 @@ public class ApiDefinitionImportUtilService {
|
|||
public void insertData(Map<String, BaseTreeNode> modulePathMap,
|
||||
Map<String, BaseTreeNode> idModuleMap,
|
||||
ApiDetailWithDataUpdate apiDetailWithDataUpdate,
|
||||
ImportRequest request, SessionUser user) {
|
||||
ImportRequest request) {
|
||||
//先判断是否需要新增模块
|
||||
List<ApiDefinitionImportDetail> addModuleData = apiDetailWithDataUpdate.getAddModuleData();
|
||||
List<ApiDefinitionImportDetail> updateModuleData = apiDetailWithDataUpdate.getUpdateModuleData();
|
||||
|
@ -387,11 +390,10 @@ public class ApiDefinitionImportUtilService {
|
|||
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
|
||||
operationLogService.batchAdd(operationLogs);
|
||||
//发送通知
|
||||
List<Map> createResources = new ArrayList<>();
|
||||
createResources.addAll(JSON.parseArray(JSON.toJSONString(createLists), Map.class));
|
||||
List<Map> createResources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(createLists), Map.class));
|
||||
User user = userMapper.selectByPrimaryKey(request.getUserId());
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.Event.CREATE, createResources, user, request.getProjectId());
|
||||
List<Map> updateResources = new ArrayList<>();
|
||||
updateResources.addAll(JSON.parseArray(JSON.toJSONString(updateResources), Map.class));
|
||||
List<Map> updateResources = new ArrayList<>(JSON.parseArray(JSON.toJSONString(updateLists), Map.class));
|
||||
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.Event.UPDATE, updateResources, user, request.getProjectId());
|
||||
}
|
||||
|
||||
|
|
|
@ -952,7 +952,7 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
return apiDefinitionDocDTO;
|
||||
}
|
||||
|
||||
public void apiTestImport(MultipartFile file, ImportRequest request, SessionUser user, String projectId) {
|
||||
public void apiTestImport(MultipartFile file, ImportRequest request, String projectId) {
|
||||
if (file != null) {
|
||||
String originalFilename = file.getOriginalFilename();
|
||||
if (StringUtils.isNotBlank(originalFilename)) {
|
||||
|
@ -977,7 +977,7 @@ public class ApiDefinitionService extends MoveNodeService {
|
|||
}
|
||||
|
||||
try {
|
||||
apiDefinitionImportUtilService.importApi(request, apiImport, user);
|
||||
apiDefinitionImportUtilService.importApi(request, apiImport);
|
||||
} catch (Exception e) {
|
||||
LogUtils.error(e);
|
||||
throw new MSException(Translator.get("user_import_format_wrong"));
|
||||
|
|
|
@ -8,11 +8,8 @@ import io.metersphere.api.service.definition.ApiDefinitionScheduleService;
|
|||
import io.metersphere.api.service.definition.ApiDefinitionService;
|
||||
import io.metersphere.sdk.util.BeanUtils;
|
||||
import io.metersphere.sdk.util.CommonBeanFactory;
|
||||
import io.metersphere.system.dto.sdk.SessionUser;
|
||||
import io.metersphere.system.dto.user.UserDTO;
|
||||
import io.metersphere.system.schedule.BaseScheduleJob;
|
||||
import io.metersphere.system.service.UserService;
|
||||
import io.metersphere.system.utils.SessionUtils;
|
||||
import org.quartz.JobDataMap;
|
||||
import org.quartz.JobExecutionContext;
|
||||
import org.quartz.JobKey;
|
||||
|
@ -40,10 +37,7 @@ public class SwaggerUrlImportJob extends BaseScheduleJob {
|
|||
request.setUserId(jobDataMap.getString("userId"));
|
||||
request.setType("SCHEDULE");
|
||||
request.setResourceId(resourceId);
|
||||
|
||||
UserDTO userDTO = userService.getUserDTOByKeyword(request.getUserId());
|
||||
SessionUser user = SessionUser.fromUser(userDTO, SessionUtils.getSessionId());
|
||||
apiDefinitionService.apiTestImport(null, request, user, request.getProjectId());
|
||||
apiDefinitionService.apiTestImport(null, request, request.getProjectId());
|
||||
}
|
||||
|
||||
public static JobKey getJobKey(String resourceId) {
|
||||
|
|
|
@ -180,6 +180,9 @@
|
|||
local: false,
|
||||
};
|
||||
}
|
||||
if (innerParams.value.binaryBody.file && !innerParams.value.binaryBody.file.fileId) {
|
||||
innerParams.value.binaryBody.file = undefined;
|
||||
}
|
||||
emit('change');
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
|
|
@ -385,6 +385,9 @@
|
|||
local: false,
|
||||
};
|
||||
}
|
||||
if (activeResponse.value.body.binaryBody.file && !activeResponse.value.body.binaryBody.file.fileId) {
|
||||
activeResponse.value.body.binaryBody.file = undefined;
|
||||
}
|
||||
emit('change');
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
|
|
@ -569,6 +569,7 @@
|
|||
(item) => ({
|
||||
...item,
|
||||
operationTime: dayjs(item.operationTime).format('YYYY-MM-DD HH:mm:ss'),
|
||||
nextTime: dayjs(item.nextTime).format('YYYY-MM-DD HH:mm:ss'),
|
||||
})
|
||||
);
|
||||
function loadTaskList() {
|
||||
|
|
Loading…
Reference in New Issue