refactor(缺陷管理): 优化同步缺陷消息通知
This commit is contained in:
parent
e98109923b
commit
1281f88e57
|
@ -116,4 +116,7 @@ bug.export.system.other.columns.comment=评论
|
||||||
bug.export.system.other.columns.platform=所属平台
|
bug.export.system.other.columns.platform=所属平台
|
||||||
|
|
||||||
permission.bug.name=缺陷管理
|
permission.bug.name=缺陷管理
|
||||||
permission.bug=缺陷
|
permission.bug=缺陷
|
||||||
|
# sync mode
|
||||||
|
sync_mode.manual=手动同步
|
||||||
|
sync_mode.auto=定时同步
|
|
@ -117,4 +117,8 @@ bug.export.system.other.columns.platform=Platform
|
||||||
permission.bug.name=Bug management
|
permission.bug.name=Bug management
|
||||||
test_plan_related=Test plan related
|
test_plan_related=Test plan related
|
||||||
direct_related=Direct related
|
direct_related=Direct related
|
||||||
permission.bug=Bug
|
permission.bug=Bug
|
||||||
|
|
||||||
|
# sync mode
|
||||||
|
sync_mode.manual=Manual
|
||||||
|
sync_mode.auto=Auto
|
|
@ -117,4 +117,8 @@ bug.export.system.other.columns.platform=所属平台
|
||||||
permission.bug.name=缺陷管理
|
permission.bug.name=缺陷管理
|
||||||
test_plan_relate=测试计划关联
|
test_plan_relate=测试计划关联
|
||||||
direct_related=直接关联
|
direct_related=直接关联
|
||||||
permission.bug=缺陷
|
permission.bug=缺陷
|
||||||
|
|
||||||
|
# sync mode
|
||||||
|
sync_mode.manual=手动同步
|
||||||
|
sync_mode.auto=定时同步
|
|
@ -118,4 +118,8 @@ bug.export.system.other.columns.platform=所屬平台
|
||||||
permission.bug.name=缺陷管理
|
permission.bug.name=缺陷管理
|
||||||
test_plan_related=測試計劃關聯
|
test_plan_related=測試計劃關聯
|
||||||
direct_related=直接關聯
|
direct_related=直接關聯
|
||||||
permission.bug=缺陷
|
permission.bug=缺陷
|
||||||
|
|
||||||
|
# sync mode
|
||||||
|
sync_mode.manual=手動同步
|
||||||
|
sync_mode.auto=定時同步
|
|
@ -18,6 +18,7 @@ import io.metersphere.project.service.ProjectApplicationService;
|
||||||
import io.metersphere.project.service.ProjectTemplateService;
|
import io.metersphere.project.service.ProjectTemplateService;
|
||||||
import io.metersphere.sdk.constants.PermissionConstants;
|
import io.metersphere.sdk.constants.PermissionConstants;
|
||||||
import io.metersphere.sdk.constants.TemplateScene;
|
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.TemplateCustomFieldDTO;
|
||||||
import io.metersphere.system.dto.sdk.TemplateDTO;
|
import io.metersphere.system.dto.sdk.TemplateDTO;
|
||||||
import io.metersphere.system.dto.sdk.request.PosRequest;
|
import io.metersphere.system.dto.sdk.request.PosRequest;
|
||||||
|
@ -146,7 +147,7 @@ public class BugController {
|
||||||
@RequiresPermissions(PermissionConstants.PROJECT_BUG_UPDATE)
|
@RequiresPermissions(PermissionConstants.PROJECT_BUG_UPDATE)
|
||||||
@CheckOwner(resourceId = "#projectId", resourceType = "project")
|
@CheckOwner(resourceId = "#projectId", resourceType = "project")
|
||||||
public void sync(@PathVariable String projectId) {
|
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")
|
@PostMapping("/sync/all")
|
||||||
|
|
|
@ -524,7 +524,7 @@ public class BugService {
|
||||||
try {
|
try {
|
||||||
XpackBugService bugService = CommonBeanFactory.getBean(XpackBugService.class);
|
XpackBugService bugService = CommonBeanFactory.getBean(XpackBugService.class);
|
||||||
if (bugService != null) {
|
if (bugService != null) {
|
||||||
bugService.syncPlatformBugs(project, request, currentUser, language);
|
bugService.syncPlatformBugs(project, request, currentUser, language, Translator.get("sync_mode.manual"));
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtils.error(e);
|
LogUtils.error(e);
|
||||||
|
@ -542,7 +542,7 @@ public class BugService {
|
||||||
* @param project 项目
|
* @param project 项目
|
||||||
*/
|
*/
|
||||||
@Async
|
@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 {
|
try {
|
||||||
// 分页同步
|
// 分页同步
|
||||||
SubListUtils.dealForSubList(remainBugs, 100, (subBugs) -> doSyncPlatformBugs(subBugs, project));
|
SubListUtils.dealForSubList(remainBugs, 100, (subBugs) -> doSyncPlatformBugs(subBugs, project));
|
||||||
|
@ -554,7 +554,7 @@ public class BugService {
|
||||||
// 异常或正常结束都得删除当前项目执行同步的Key
|
// 异常或正常结束都得删除当前项目执行同步的Key
|
||||||
bugSyncExtraService.deleteSyncKey(project.getId());
|
bugSyncExtraService.deleteSyncKey(project.getId());
|
||||||
// 发送同步通知
|
// 发送同步通知
|
||||||
bugSyncNoticeService.sendNotice(remainBugs.size(), currentUser, language, project.getId());
|
bugSyncNoticeService.sendNotice(remainBugs.size(), currentUser, language, triggerMode, project.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,7 +30,7 @@ public class BugSyncNoticeService {
|
||||||
@Resource
|
@Resource
|
||||||
private ProjectApplicationService projectApplicationService;
|
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);
|
String platformName = projectApplicationService.getPlatformName(projectId);
|
||||||
User user = userMapper.selectByPrimaryKey(currentUser);
|
User user = userMapper.selectByPrimaryKey(currentUser);
|
||||||
setLanguage(user.getLanguage());
|
setLanguage(user.getLanguage());
|
||||||
|
@ -45,6 +45,7 @@ public class BugSyncNoticeService {
|
||||||
paramMap.put("projectId", projectId);
|
paramMap.put("projectId", projectId);
|
||||||
paramMap.put("Language", language);
|
paramMap.put("Language", language);
|
||||||
paramMap.put("platform", platformName);
|
paramMap.put("platform", platformName);
|
||||||
|
paramMap.put("triggerMode", triggerMode);
|
||||||
NoticeModel noticeModel = NoticeModel.builder().operator(currentUser).excludeSelf(false)
|
NoticeModel noticeModel = NoticeModel.builder().operator(currentUser).excludeSelf(false)
|
||||||
.context(template).subject(subject).paramMap(paramMap).event(NoticeConstants.Event.EXECUTE_COMPLETED).build();
|
.context(template).subject(subject).paramMap(paramMap).event(NoticeConstants.Event.EXECUTE_COMPLETED).build();
|
||||||
noticeSendService.send(NoticeConstants.TaskType.BUG_SYNC_TASK, noticeModel);
|
noticeSendService.send(NoticeConstants.TaskType.BUG_SYNC_TASK, noticeModel);
|
||||||
|
|
|
@ -12,6 +12,7 @@ import io.metersphere.project.service.ProjectApplicationService;
|
||||||
import io.metersphere.project.service.ProjectTemplateService;
|
import io.metersphere.project.service.ProjectTemplateService;
|
||||||
import io.metersphere.sdk.constants.TemplateScene;
|
import io.metersphere.sdk.constants.TemplateScene;
|
||||||
import io.metersphere.sdk.exception.MSException;
|
import io.metersphere.sdk.exception.MSException;
|
||||||
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.domain.Template;
|
import io.metersphere.system.domain.Template;
|
||||||
import io.metersphere.system.domain.TemplateExample;
|
import io.metersphere.system.domain.TemplateExample;
|
||||||
import io.metersphere.system.mapper.TemplateMapper;
|
import io.metersphere.system.mapper.TemplateMapper;
|
||||||
|
@ -73,7 +74,7 @@ public class BugSyncService {
|
||||||
* 开源用户 (同步存量缺陷)
|
* 开源用户 (同步存量缺陷)
|
||||||
* @param projectId 项目ID
|
* @param projectId 项目ID
|
||||||
*/
|
*/
|
||||||
public void syncBugs(String projectId, String currentUser, String language) {
|
public void syncBugs(String projectId, String currentUser, String language, String triggerMode) {
|
||||||
try {
|
try {
|
||||||
String syncValue = bugSyncExtraService.getSyncKey(projectId);
|
String syncValue = bugSyncExtraService.getSyncKey(projectId);
|
||||||
if (StringUtils.isEmpty(syncValue)) {
|
if (StringUtils.isEmpty(syncValue)) {
|
||||||
|
@ -99,7 +100,7 @@ public class BugSyncService {
|
||||||
Map<String, Template> templateMap = templates.stream().collect(Collectors.toMap(Template::getId, t -> t));
|
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()));
|
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) {
|
} catch (Exception e) {
|
||||||
|
@ -134,7 +135,7 @@ public class BugSyncService {
|
||||||
* 定时任务同步缺陷(存量-默认中文环境通知)
|
* 定时任务同步缺陷(存量-默认中文环境通知)
|
||||||
*/
|
*/
|
||||||
public void syncPlatformBugBySchedule(String projectId, String scheduleUser) {
|
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"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -21,7 +21,8 @@ public interface XpackBugService {
|
||||||
* @param request 同步请求参数
|
* @param request 同步请求参数
|
||||||
* @param currentUser 当前用户
|
* @param currentUser 当前用户
|
||||||
* @param language 语言环境
|
* @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);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import io.metersphere.sdk.exception.MSException;
|
||||||
import io.metersphere.sdk.file.FileRequest;
|
import io.metersphere.sdk.file.FileRequest;
|
||||||
import io.metersphere.sdk.util.FileAssociationSourceUtil;
|
import io.metersphere.sdk.util.FileAssociationSourceUtil;
|
||||||
import io.metersphere.sdk.util.JSON;
|
import io.metersphere.sdk.util.JSON;
|
||||||
|
import io.metersphere.sdk.util.Translator;
|
||||||
import io.metersphere.system.base.BaseTest;
|
import io.metersphere.system.base.BaseTest;
|
||||||
import io.metersphere.system.controller.handler.ResultHolder;
|
import io.metersphere.system.controller.handler.ResultHolder;
|
||||||
import io.metersphere.system.domain.CustomField;
|
import io.metersphere.system.domain.CustomField;
|
||||||
|
@ -634,13 +635,13 @@ public class BugControllerTests extends BaseTest {
|
||||||
List<Bug> remainBugs = bugMapper.selectByExample(example);
|
List<Bug> remainBugs = bugMapper.selectByExample(example);
|
||||||
Project defaultProject = projectMapper.selectByPrimaryKey("default-project-for-bug");
|
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()); // 重命名后, 同步时会删除本地文件
|
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()); // 手动删除关联的文件, 重新同步时会下载平台附件
|
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缺陷
|
// 全选删除所有Jira缺陷
|
||||||
BugBatchRequest request = new BugBatchRequest();
|
BugBatchRequest request = new BugBatchRequest();
|
||||||
|
|
|
@ -14,7 +14,7 @@ public class XpackBugMockServiceImpl implements XpackBugService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@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) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,8 +81,9 @@ public class NoticeTemplateService {
|
||||||
}
|
}
|
||||||
case NoticeConstants.TaskType.BUG_SYNC_TASK -> {
|
case NoticeConstants.TaskType.BUG_SYNC_TASK -> {
|
||||||
Field[] allFields = FieldUtils.getAllFields(BugSyncNoticeDTO.class);
|
Field[] allFields = FieldUtils.getAllFields(BugSyncNoticeDTO.class);
|
||||||
|
// TODO: 待修改, 同步仅需的字段{操作人, 触发方式}
|
||||||
|
// 该方法提供了统一的内置通知模板字段; {操作人, 关注人, 触发方式}
|
||||||
addOptionDto(messageTemplateFieldDTOList, allFields, null);
|
addOptionDto(messageTemplateFieldDTOList, allFields, null);
|
||||||
//TODO:获取报告
|
|
||||||
}
|
}
|
||||||
case NoticeConstants.TaskType.UI_SCENARIO_TASK -> {
|
case NoticeConstants.TaskType.UI_SCENARIO_TASK -> {
|
||||||
Field[] allFields = FieldUtils.getAllFields(UiScenario.class);
|
Field[] allFields = FieldUtils.getAllFields(UiScenario.class);
|
||||||
|
|
|
@ -148,11 +148,11 @@ public abstract class AbstractNoticeSender implements NoticeSender {
|
||||||
}
|
}
|
||||||
|
|
||||||
// 去重复
|
// 去重复
|
||||||
List<String> userIds = toUsers.stream().map(Receiver::getUserId).distinct().toList();
|
// List<String> userIds = toUsers.stream().map(Receiver::getUserId).distinct().toList();
|
||||||
LogUtils.info("userIds: ", JSON.toJSONString(userIds));
|
// LogUtils.info("userIds: ", JSON.toJSONString(userIds));
|
||||||
List<User> users = getUsers(userIds, messageDetail.getProjectId());
|
// List<User> users = getUsers(userIds, messageDetail.getProjectId());
|
||||||
List<String> realUserIds = users.stream().map(User::getId).toList();
|
// List<String> realUserIds = users.stream().map(User::getId).toList();
|
||||||
return toUsers.stream().filter(t -> realUserIds.contains(t.getUserId())).toList();
|
return toUsers;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Receiver> handleFollows(MessageDetail messageDetail, NoticeModel noticeModel) {
|
private List<Receiver> handleFollows(MessageDetail messageDetail, NoticeModel noticeModel) {
|
||||||
|
|
Loading…
Reference in New Issue