fix(项目设置): 修复消息通知接口定义API更新事件一些模版字段获取不到值问题

https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001018771
--user=郭雨琦
This commit is contained in:
guoyuqi 2022-10-28 19:00:18 +08:00 committed by xiaomeinvG
parent 1c0c5caf89
commit ef295739bb
1 changed files with 25 additions and 46 deletions

View File

@ -62,6 +62,7 @@ import io.metersphere.xpack.api.service.ApiCaseBatchSyncService;
import io.metersphere.xpack.api.service.ApiDefinitionSyncService; import io.metersphere.xpack.api.service.ApiDefinitionSyncService;
import io.metersphere.xpack.quota.service.QuotaService; import io.metersphere.xpack.quota.service.QuotaService;
import org.apache.commons.beanutils.BeanComparator; import org.apache.commons.beanutils.BeanComparator;
import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils; import org.apache.commons.collections.MapUtils;
import org.apache.commons.collections4.comparators.FixedOrderComparator; import org.apache.commons.collections4.comparators.FixedOrderComparator;
@ -466,9 +467,9 @@ public class ApiDefinitionService {
mockConfigService.updateMockReturnMsgByApi(returnModel); mockConfigService.updateMockReturnMsgByApi(returnModel);
FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles); FileUtils.createBodyFiles(request.getRequest().getId(), bodyFiles);
String context = SessionUtils.getUserId().concat(Translator.get("update_api")).concat(":").concat(returnModel.getName()); String context = SessionUtils.getUserId().concat(Translator.get("update_api")).concat(":").concat(returnModel.getName());
Map<String, Object> paramMap = new HashMap<>(); BeanMap beanMap = new BeanMap(returnModel);
getParamMap(paramMap, returnModel.getProjectId(), SessionUtils.getUserId(), returnModel.getId(), returnModel.getName(), returnModel.getCreateUser()); Map paramMap = new HashMap<>(beanMap);
paramMap.put("userId", returnModel.getUserId()); paramMap.put("operator", SessionUtils.getUserId());
// 发送通知 // 发送通知
ApiCaseBatchSyncService apiCaseBatchSyncService = CommonBeanFactory.getBean(ApiCaseBatchSyncService.class); ApiCaseBatchSyncService apiCaseBatchSyncService = CommonBeanFactory.getBean(ApiCaseBatchSyncService.class);
if (apiCaseBatchSyncService != null) { if (apiCaseBatchSyncService != null) {
@ -1213,49 +1214,22 @@ public class ApiDefinitionService {
return caseList; return caseList;
} }
public void sendImportApiNotice(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs, String context, String event, String tip) {
public void sendImportApiCreateNotice(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) { BeanMap beanMap = new BeanMap(apiDefinitionWithBLOBs);
String context = SessionUtils.getUserId().concat("新建了接口定义").concat(":").concat(apiDefinitionWithBLOBs.getName()); Map paramMap = new HashMap<>(beanMap);
Map<String, Object> paramMap = new HashMap<>(); paramMap.put("operator", SessionUtils.getUserId());
getParamMap(paramMap, apiDefinitionWithBLOBs.getProjectId(), SessionUtils.getUserId(), apiDefinitionWithBLOBs.getId(), apiDefinitionWithBLOBs.getName(), apiDefinitionWithBLOBs.getCreateUser()); NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiDefinitionWithBLOBs.getId()).subject(Translator.get(tip)).paramMap(paramMap).excludeSelf(true).event(event).build();
paramMap.put("userId", apiDefinitionWithBLOBs.getUserId());
NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiDefinitionWithBLOBs.getId()).subject(Translator.get("api_create_notice")).paramMap(paramMap).excludeSelf(true).event(NoticeConstants.Event.CREATE).build();
noticeSendService.send(NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel); noticeSendService.send(NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel);
} }
public void sendImportApiUpdateNotice(ApiDefinitionWithBLOBs apiDefinitionWithBLOBs) { public void sendImportCaseNotice(ApiTestCase apiTestCase, String context, String event, String tip) {
String context = SessionUtils.getUserId().concat("更新了接口定义").concat(":").concat(apiDefinitionWithBLOBs.getName()); BeanMap beanMap = new BeanMap(apiTestCase);
Map<String, Object> paramMap = new HashMap<>(); Map paramMap = new HashMap<>(beanMap);
getParamMap(paramMap, apiDefinitionWithBLOBs.getProjectId(), SessionUtils.getUserId(), apiDefinitionWithBLOBs.getId(), apiDefinitionWithBLOBs.getName(), apiDefinitionWithBLOBs.getCreateUser()); paramMap.put("operator", SessionUtils.getUserId());
paramMap.put("userId", apiDefinitionWithBLOBs.getUserId()); NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiTestCase.getId()).subject(Translator.get(tip)).paramMap(paramMap).excludeSelf(true).event(event).build();
NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiDefinitionWithBLOBs.getId()).subject(Translator.get("api_update_notice")).paramMap(paramMap).excludeSelf(true).event(NoticeConstants.Event.UPDATE).build();
noticeSendService.send(NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel); noticeSendService.send(NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel);
} }
public void sendImportCaseUpdateNotice(ApiTestCase apiTestCase) {
String context = SessionUtils.getUserId().concat("更新了接口用例").concat(":").concat(apiTestCase.getName());
Map<String, Object> paramMap = new HashMap<>();
getParamMap(paramMap, apiTestCase.getProjectId(), SessionUtils.getUserId(), apiTestCase.getId(), apiTestCase.getName(), apiTestCase.getCreateUserId());
NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiTestCase.getId()).subject(Translator.get("api_case_update_notice")).paramMap(paramMap).excludeSelf(true).event(NoticeConstants.Event.CASE_UPDATE).build();
noticeSendService.send(NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel);
}
public void sendImportCaseCreateNotice(ApiTestCase apiTestCase) {
String context = SessionUtils.getUserId().concat("新建了接口用例").concat(":").concat(apiTestCase.getName());
Map<String, Object> paramMap = new HashMap<>();
getParamMap(paramMap, apiTestCase.getProjectId(), SessionUtils.getUserId(), apiTestCase.getId(), apiTestCase.getName(), apiTestCase.getCreateUserId());
NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiTestCase.getId()).subject(Translator.get("api_case_create_notice")).paramMap(paramMap).excludeSelf(true).event(NoticeConstants.Event.CASE_CREATE).build();
noticeSendService.send(NoticeConstants.TaskType.API_DEFINITION_TASK, noticeModel);
}
private void getParamMap(Map<String, Object> paramMap, String projectId, String userId, String id, String name, String createUser) {
paramMap.put("projectId", projectId);
paramMap.put("operator", userId);
paramMap.put("id", id);
paramMap.put("name", name);
paramMap.put("createUser", createUser);
}
public Boolean checkIsSynchronize(ApiDefinitionWithBLOBs existApi, ApiDefinitionWithBLOBs apiDefinition) { public Boolean checkIsSynchronize(ApiDefinitionWithBLOBs existApi, ApiDefinitionWithBLOBs apiDefinition) {
ObjectMapper objectMapper = new ObjectMapper(); ObjectMapper objectMapper = new ObjectMapper();
@ -1760,18 +1734,23 @@ public class ApiDefinitionService {
} }
if (!StringUtils.equals(request.getType(), SCHEDULE) && CollectionUtils.isNotEmpty(apiImportSendNoticeDTOS)) { if (!StringUtils.equals(request.getType(), SCHEDULE) && CollectionUtils.isNotEmpty(apiImportSendNoticeDTOS)) {
for (ApiImportSendNoticeDTO apiImportSendNoticeDTO : apiImportSendNoticeDTOS) { for (ApiImportSendNoticeDTO apiImportSendNoticeDTO : apiImportSendNoticeDTOS) {
if (apiImportSendNoticeDTO.getApiDefinitionResult() != null && !apiImportSendNoticeDTO.getApiDefinitionResult().isUpdated()) { ApiDefinitionResult apiDefinitionResult = apiImportSendNoticeDTO.getApiDefinitionResult();
sendImportApiCreateNotice(apiImportSendNoticeDTO.getApiDefinitionResult()); if (apiDefinitionResult != null && !apiDefinitionResult.isUpdated()) {
String context = SessionUtils.getUserId().concat("新建了接口定义").concat(":").concat(apiDefinitionResult.getName());
sendImportApiNotice(apiDefinitionResult, context, NoticeConstants.Event.CREATE, "api_create_notice");
} }
if (apiImportSendNoticeDTO.getApiDefinitionResult() != null && apiImportSendNoticeDTO.getApiDefinitionResult().isUpdated()) { if (apiDefinitionResult != null && apiDefinitionResult.isUpdated()) {
sendImportApiUpdateNotice(apiImportSendNoticeDTO.getApiDefinitionResult()); String context = SessionUtils.getUserId().concat("更新了接口定义").concat(":").concat(apiDefinitionResult.getName());
sendImportApiNotice(apiDefinitionResult, context, NoticeConstants.Event.UPDATE, "api_update_notice");
} }
if (CollectionUtils.isNotEmpty(apiImportSendNoticeDTO.getCaseDTOList())) { if (CollectionUtils.isNotEmpty(apiImportSendNoticeDTO.getCaseDTOList())) {
for (ApiTestCaseDTO apiTestCaseDTO : apiImportSendNoticeDTO.getCaseDTOList()) { for (ApiTestCaseDTO apiTestCaseDTO : apiImportSendNoticeDTO.getCaseDTOList()) {
if (apiTestCaseDTO.isUpdated()) { if (apiTestCaseDTO.isUpdated()) {
sendImportCaseUpdateNotice(apiTestCaseDTO); String context = SessionUtils.getUserId().concat("更新了接口用例").concat(":").concat(apiTestCaseDTO.getName());
sendImportCaseNotice(apiTestCaseDTO, context, NoticeConstants.Event.CASE_UPDATE, "api_case_update_notice");
} else { } else {
sendImportCaseCreateNotice(apiTestCaseDTO); String context = SessionUtils.getUserId().concat("新建了接口用例").concat(":").concat(apiTestCaseDTO.getName());
sendImportCaseNotice(apiTestCaseDTO, context, NoticeConstants.Event.CASE_CREATE, "api_case_create_notice");
} }
} }
} }