chore: 修改类名和参数名,使其更加通用

This commit is contained in:
CaptainB 2024-04-01 17:10:33 +08:00 committed by 刘瑞斌
parent 1f4b8b44e6
commit 7b131c3361
5 changed files with 30 additions and 31 deletions

View File

@ -42,7 +42,7 @@ 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.notice.constants.NoticeConstants;
import io.metersphere.system.notice.sender.AfterReturningNoticeSendService;
import io.metersphere.system.service.CommonNoticeSendService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator;
import jakarta.annotation.Resource;
@ -87,7 +87,7 @@ public class ApiDefinitionImportUtilService {
@Resource
private OperationLogService operationLogService;
@Resource
private AfterReturningNoticeSendService afterReturningNoticeSendService;
private CommonNoticeSendService commonNoticeSendService;
private static final String FILE_JMX = "jmx";
private static final String FILE_HAR = "har";
@ -389,10 +389,10 @@ public class ApiDefinitionImportUtilService {
//发送通知
List<Map> createResources = new ArrayList<>();
createResources.addAll(JSON.parseArray(JSON.toJSONString(createLists), Map.class));
afterReturningNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.Event.CREATE, createResources, user, request.getProjectId());
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));
afterReturningNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.Event.UPDATE, updateResources, user, request.getProjectId());
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.Event.UPDATE, updateResources, user, request.getProjectId());
}
private void getNeedUpdateData(ImportRequest request, ApiDetailWithData apiDetailWithData, ApiDetailWithDataUpdate apiDetailWithDataUpdate) {

View File

@ -46,7 +46,7 @@ import io.metersphere.system.log.service.OperationLogService;
import io.metersphere.system.mapper.OperationHistoryMapper;
import io.metersphere.system.mapper.UserMapper;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.notice.sender.AfterReturningNoticeSendService;
import io.metersphere.system.service.CommonNoticeSendService;
import io.metersphere.system.service.BaseCustomFieldOptionService;
import io.metersphere.system.service.BaseCustomFieldService;
import io.metersphere.system.service.OperationHistoryService;
@ -156,7 +156,7 @@ public class FunctionalCaseService {
@Resource
private FileAssociationMapper fileAssociationMapper;
@Resource
private AfterReturningNoticeSendService afterReturningNoticeSendService;
private CommonNoticeSendService commonNoticeSendService;
@Resource
private OperationHistoryService operationHistoryService;
@Resource
@ -993,7 +993,7 @@ public class FunctionalCaseService {
List<Map> resources = new ArrayList<>();
resources.addAll(JSON.parseArray(JSON.toJSONString(noticeList), Map.class));
afterReturningNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.CREATE, resources, user, request.getProjectId());
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.CREATE, resources, user, request.getProjectId());
}
/**
@ -1158,7 +1158,7 @@ public class FunctionalCaseService {
List<Map> resources = new ArrayList<>();
resources.addAll(JSON.parseArray(JSON.toJSONString(noticeList), Map.class));
afterReturningNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.UPDATE, resources, user, request.getProjectId());
commonNoticeSendService.sendNotice(NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK, NoticeConstants.Event.UPDATE, resources, user, request.getProjectId());
}

View File

@ -6,6 +6,7 @@ import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.notice.annotation.SendNotice;
import io.metersphere.system.service.CommonNoticeSendService;
import io.metersphere.system.utils.SessionUtils;
import jakarta.annotation.Resource;
import org.apache.commons.beanutils.BeanMap;
@ -35,7 +36,7 @@ import java.util.Map;
@Component
public class SendNoticeAspect {
@Resource
private AfterReturningNoticeSendService afterReturningNoticeSendService;
private CommonNoticeSendService commonNoticeSendService;
private ExpressionParser parser = new SpelExpressionParser();
private StandardReflectionParameterNameDiscoverer discoverer = new StandardReflectionParameterNameDiscoverer();
@ -166,7 +167,7 @@ public class SendNoticeAspect {
}
}
}
afterReturningNoticeSendService.sendNotice(taskType, event, resources, sessionUser, currentProjectId);
commonNoticeSendService.sendNotice(taskType, event, resources, sessionUser, currentProjectId);
} catch (Exception e) {
LogUtils.error(e.getMessage(), e);
} finally {

View File

@ -1,13 +1,11 @@
package io.metersphere.system.notice.sender;
package io.metersphere.system.service;
import io.metersphere.system.domain.User;
import io.metersphere.system.dto.sdk.BaseSystemConfigDTO;
import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.notice.NoticeModel;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.notice.utils.MessageTemplateUtils;
import io.metersphere.system.service.NoticeSendService;
import io.metersphere.system.service.SystemParameterService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.i18n.LocaleContextHolder;
@ -17,22 +15,22 @@ import org.springframework.stereotype.Component;
import java.util.*;
@Component
public class AfterReturningNoticeSendService {
public class CommonNoticeSendService {
@Resource
private SystemParameterService systemParameterService;
@Resource
private NoticeSendService noticeSendService;
@Async
public void sendNotice(String taskType, String event, List<Map> resources, SessionUser sessionUser, String currentProjectId) {
setLanguage(sessionUser.getLanguage());
public void sendNotice(String taskType, String event, List<Map> resources, User operator, String currentProjectId) {
setLanguage(operator.getLanguage());
// 有批量操作发送多次
BaseSystemConfigDTO baseSystemConfigDTO = systemParameterService.getBaseInfo();
for (Map resource : resources) {
Map paramMap = new HashMap<>();
paramMap.put("url", baseSystemConfigDTO.getUrl());
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, sessionUser.getName());
paramMap.put("Language",sessionUser.getLanguage());
paramMap.put(NoticeConstants.RelatedUser.OPERATOR, operator.getName());
paramMap.put("Language", operator.getLanguage());
paramMap.putAll(resource);
paramMap.putIfAbsent("projectId", currentProjectId);
//TODO: 加来源处理
@ -47,7 +45,7 @@ public class AfterReturningNoticeSendService {
List<String> relatedUsers = getRelatedUsers(resource.get("relatedUsers"));
NoticeModel noticeModel = NoticeModel.builder()
.operator(sessionUser.getId())
.operator(operator.getId())
.context(context)
.subject(subject)
.paramMap(paramMap)
@ -76,9 +74,9 @@ public class AfterReturningNoticeSendService {
private static void setLanguage(String language) {
Locale locale = Locale.SIMPLIFIED_CHINESE;
if (StringUtils.containsIgnoreCase("US",language)) {
if (StringUtils.containsIgnoreCase("US", language)) {
locale = Locale.US;
} else if (StringUtils.containsIgnoreCase("TW",language)){
} else if (StringUtils.containsIgnoreCase("TW", language)) {
locale = Locale.TAIWAN;
}
LocaleContextHolder.setLocale(locale);

View File

@ -24,7 +24,7 @@ import io.metersphere.system.dto.sdk.SessionUser;
import io.metersphere.system.dto.user.UserDTO;
import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.notice.sender.AfterReturningNoticeSendService;
import io.metersphere.system.service.CommonNoticeSendService;
import jakarta.annotation.Resource;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.MethodOrderer;
@ -44,11 +44,11 @@ import java.util.Map;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT)
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
@AutoConfigureMockMvc
public class AfterReturningNoticeSendServiceTests extends BaseTest {
public class CommonNoticeSendServiceTests extends BaseTest {
@Resource
private AfterReturningNoticeSendService afterReturningNoticeSendService;
private CommonNoticeSendService commonNoticeSendService;
@Resource
private FunctionalCaseMapper functionalCaseMapper;
@Resource
@ -117,7 +117,7 @@ public class AfterReturningNoticeSendServiceTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
user.setLanguage("zh-CN");
for (String event : eventList) {
afterReturningNoticeSendService.sendNotice(functionalCaseTask, event,resources, user, "100001100001");
commonNoticeSendService.sendNotice(functionalCaseTask, event,resources, user, "100001100001");
}
}
@ -156,7 +156,7 @@ public class AfterReturningNoticeSendServiceTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
for (String event : eventList) {
afterReturningNoticeSendService.sendNotice(apiDefinitionTask, event,resources, user, "100001100001");
commonNoticeSendService.sendNotice(apiDefinitionTask, event,resources, user, "100001100001");
}
}
@ -195,7 +195,7 @@ public class AfterReturningNoticeSendServiceTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
for (String event : eventList) {
afterReturningNoticeSendService.sendNotice(apiScenarioTask, event,resources, user, "100001100001");
commonNoticeSendService.sendNotice(apiScenarioTask, event,resources, user, "100001100001");
}
}
@ -234,7 +234,7 @@ public class AfterReturningNoticeSendServiceTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
for (String event : eventList) {
afterReturningNoticeSendService.sendNotice(testPlanTask, event,resources, user, "100001100001");
commonNoticeSendService.sendNotice(testPlanTask, event,resources, user, "100001100001");
}
}
@ -273,7 +273,7 @@ public class AfterReturningNoticeSendServiceTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
for (String event : eventList) {
afterReturningNoticeSendService.sendNotice(caseReviewTask, event,resources, user, "100001100001");
commonNoticeSendService.sendNotice(caseReviewTask, event,resources, user, "100001100001");
}
}
@ -325,7 +325,7 @@ public class AfterReturningNoticeSendServiceTests extends BaseTest {
SessionUser user = SessionUser.fromUser(userDTO, sessionId);
for (String event : eventList) {
afterReturningNoticeSendService.sendNotice(loadTestTask, event,resources, user, "100001100001");
commonNoticeSendService.sendNotice(loadTestTask, event,resources, user, "100001100001");
}
}