refactor(缺陷管理): 优化同步缺陷消息通知

This commit is contained in:
song-cc-rock 2024-04-11 13:36:42 +08:00 committed by Craftsman
parent e98109923b
commit 1281f88e57
13 changed files with 44 additions and 23 deletions

View File

@ -116,4 +116,7 @@ bug.export.system.other.columns.comment=评论
bug.export.system.other.columns.platform=所属平台
permission.bug.name=缺陷管理
permission.bug=缺陷
permission.bug=缺陷
# sync mode
sync_mode.manual=手动同步
sync_mode.auto=定时同步

View File

@ -117,4 +117,8 @@ bug.export.system.other.columns.platform=Platform
permission.bug.name=Bug management
test_plan_related=Test plan related
direct_related=Direct related
permission.bug=Bug
permission.bug=Bug
# sync mode
sync_mode.manual=Manual
sync_mode.auto=Auto

View File

@ -117,4 +117,8 @@ bug.export.system.other.columns.platform=所属平台
permission.bug.name=缺陷管理
test_plan_relate=测试计划关联
direct_related=直接关联
permission.bug=缺陷
permission.bug=缺陷
# sync mode
sync_mode.manual=手动同步
sync_mode.auto=定时同步

View File

@ -118,4 +118,8 @@ bug.export.system.other.columns.platform=所屬平台
permission.bug.name=缺陷管理
test_plan_related=測試計劃關聯
direct_related=直接關聯
permission.bug=缺陷
permission.bug=缺陷
# sync mode
sync_mode.manual=手動同步
sync_mode.auto=定時同步

View File

@ -18,6 +18,7 @@ import io.metersphere.project.service.ProjectApplicationService;
import io.metersphere.project.service.ProjectTemplateService;
import io.metersphere.sdk.constants.PermissionConstants;
import io.metersphere.sdk.constants.TemplateScene;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.dto.sdk.TemplateCustomFieldDTO;
import io.metersphere.system.dto.sdk.TemplateDTO;
import io.metersphere.system.dto.sdk.request.PosRequest;
@ -146,7 +147,7 @@ public class BugController {
@RequiresPermissions(PermissionConstants.PROJECT_BUG_UPDATE)
@CheckOwner(resourceId = "#projectId", resourceType = "project")
public void sync(@PathVariable String projectId) {
bugSyncService.syncBugs(projectId, SessionUtils.getUserId(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage());
bugSyncService.syncBugs(projectId, SessionUtils.getUserId(), Objects.requireNonNull(SessionUtils.getUser()).getLanguage(), Translator.get("sync_mode.manual"));
}
@PostMapping("/sync/all")

View File

@ -524,7 +524,7 @@ public class BugService {
try {
XpackBugService bugService = CommonBeanFactory.getBean(XpackBugService.class);
if (bugService != null) {
bugService.syncPlatformBugs(project, request, currentUser, language);
bugService.syncPlatformBugs(project, request, currentUser, language, Translator.get("sync_mode.manual"));
}
} catch (Exception e) {
LogUtils.error(e);
@ -542,7 +542,7 @@ public class BugService {
* @param project 项目
*/
@Async
public void syncPlatformBugs(List<Bug> remainBugs, Project project, String currentUser, String language) {
public void syncPlatformBugs(List<Bug> remainBugs, Project project, String currentUser, String language, String triggerMode) {
try {
// 分页同步
SubListUtils.dealForSubList(remainBugs, 100, (subBugs) -> doSyncPlatformBugs(subBugs, project));
@ -554,7 +554,7 @@ public class BugService {
// 异常或正常结束都得删除当前项目执行同步的Key
bugSyncExtraService.deleteSyncKey(project.getId());
// 发送同步通知
bugSyncNoticeService.sendNotice(remainBugs.size(), currentUser, language, project.getId());
bugSyncNoticeService.sendNotice(remainBugs.size(), currentUser, language, triggerMode, project.getId());
}
}

View File

@ -30,7 +30,7 @@ public class BugSyncNoticeService {
@Resource
private ProjectApplicationService projectApplicationService;
public void sendNotice(int total, String currentUser, String language, String projectId) {
public void sendNotice(int total, String currentUser, String language, String triggerMode, String projectId) {
String platformName = projectApplicationService.getPlatformName(projectId);
User user = userMapper.selectByPrimaryKey(currentUser);
setLanguage(user.getLanguage());
@ -45,6 +45,7 @@ public class BugSyncNoticeService {
paramMap.put("projectId", projectId);
paramMap.put("Language", language);
paramMap.put("platform", platformName);
paramMap.put("triggerMode", triggerMode);
NoticeModel noticeModel = NoticeModel.builder().operator(currentUser).excludeSelf(false)
.context(template).subject(subject).paramMap(paramMap).event(NoticeConstants.Event.EXECUTE_COMPLETED).build();
noticeSendService.send(NoticeConstants.TaskType.BUG_SYNC_TASK, noticeModel);

View File

@ -12,6 +12,7 @@ import io.metersphere.project.service.ProjectApplicationService;
import io.metersphere.project.service.ProjectTemplateService;
import io.metersphere.sdk.constants.TemplateScene;
import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.Template;
import io.metersphere.system.domain.TemplateExample;
import io.metersphere.system.mapper.TemplateMapper;
@ -73,7 +74,7 @@ public class BugSyncService {
* 开源用户 (同步存量缺陷)
* @param projectId 项目ID
*/
public void syncBugs(String projectId, String currentUser, String language) {
public void syncBugs(String projectId, String currentUser, String language, String triggerMode) {
try {
String syncValue = bugSyncExtraService.getSyncKey(projectId);
if (StringUtils.isEmpty(syncValue)) {
@ -99,7 +100,7 @@ public class BugSyncService {
Map<String, Template> templateMap = templates.stream().collect(Collectors.toMap(Template::getId, t -> t));
// 非插件默认模板且模板不存在, 无需同步
bugs.removeIf(bug -> !templateMap.containsKey(bug.getTemplateId()) && !StringUtils.equals(bug.getTemplateId(), pluginTemplate.getId()));
bugService.syncPlatformBugs(bugs, project, currentUser, language);
bugService.syncPlatformBugs(bugs, project, currentUser, language, triggerMode);
}
}
} catch (Exception e) {
@ -134,7 +135,7 @@ public class BugSyncService {
* 定时任务同步缺陷(存量-默认中文环境通知)
*/
public void syncPlatformBugBySchedule(String projectId, String scheduleUser) {
syncBugs(projectId, scheduleUser, Locale.SIMPLIFIED_CHINESE.getLanguage());
syncBugs(projectId, scheduleUser, Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.auto"));
}
/**

View File

@ -21,7 +21,8 @@ public interface XpackBugService {
* @param request 同步请求参数
* @param currentUser 当前用户
* @param language 语言环境
* @param triggerMode 同步触发方式
*/
void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language);
void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language, String triggerMode);
}

View File

@ -28,6 +28,7 @@ import io.metersphere.sdk.exception.MSException;
import io.metersphere.sdk.file.FileRequest;
import io.metersphere.sdk.util.FileAssociationSourceUtil;
import io.metersphere.sdk.util.JSON;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.domain.CustomField;
@ -634,13 +635,13 @@ public class BugControllerTests extends BaseTest {
List<Bug> remainBugs = bugMapper.selectByExample(example);
Project defaultProject = projectMapper.selectByPrimaryKey("default-project-for-bug");
// 同步第一次
bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage());
bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.manual"));
// 同步第二次
renameLocalFile(updateRequest2.getId()); // 重命名后, 同步时会删除本地文件
bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage());
bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.manual"));
// 同步第三次
deleteLocalFile(updateRequest2.getId()); // 手动删除关联的文件, 重新同步时会下载平台附件
bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage());
bugService.syncPlatformBugs(remainBugs, defaultProject, "admin", Locale.SIMPLIFIED_CHINESE.getLanguage(), Translator.get("sync_mode.manual"));
// 全选删除所有Jira缺陷
BugBatchRequest request = new BugBatchRequest();

View File

@ -14,7 +14,7 @@ public class XpackBugMockServiceImpl implements XpackBugService {
}
@Override
public void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language) {
public void syncPlatformBugs(Project project, BugSyncRequest request, String currentUser, String language, String triggerMode) {
}
}

View File

@ -81,8 +81,9 @@ public class NoticeTemplateService {
}
case NoticeConstants.TaskType.BUG_SYNC_TASK -> {
Field[] allFields = FieldUtils.getAllFields(BugSyncNoticeDTO.class);
// TODO: 待修改, 同步仅需的字段{操作人, 触发方式}
// 该方法提供了统一的内置通知模板字段; {操作人, 关注人, 触发方式}
addOptionDto(messageTemplateFieldDTOList, allFields, null);
//TODO获取报告
}
case NoticeConstants.TaskType.UI_SCENARIO_TASK -> {
Field[] allFields = FieldUtils.getAllFields(UiScenario.class);

View File

@ -148,11 +148,11 @@ public abstract class AbstractNoticeSender implements NoticeSender {
}
// 去重复
List<String> userIds = toUsers.stream().map(Receiver::getUserId).distinct().toList();
LogUtils.info("userIds: ", JSON.toJSONString(userIds));
List<User> users = getUsers(userIds, messageDetail.getProjectId());
List<String> realUserIds = users.stream().map(User::getId).toList();
return toUsers.stream().filter(t -> realUserIds.contains(t.getUserId())).toList();
// List<String> userIds = toUsers.stream().map(Receiver::getUserId).distinct().toList();
// LogUtils.info("userIds: ", JSON.toJSONString(userIds));
// List<User> users = getUsers(userIds, messageDetail.getProjectId());
// List<String> realUserIds = users.stream().map(User::getId).toList();
return toUsers;
}
private List<Receiver> handleFollows(MessageDetail messageDetail, NoticeModel noticeModel) {