diff --git a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql index 4c6a90f1cc..41a3ae9fa3 100644 --- a/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql +++ b/backend/framework/domain/src/main/resources/migration/3.0.0/dml/V3.0.0_11_1__data.sql @@ -447,5 +447,56 @@ Insert into message_task(id, event, receiver, project_robot_id, task_type, test_ VALUES (@load_report_id, 'DELETE', 'CREATE_USER', @robot_in_site_id, 'LOAD_REPORT_TASK', 'NONE', '100001100001', true, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.load_report_task_delete'); INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.load_report_task_delete'); +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_SUCCESSFUL', 'CREATE_USER', @robot_in_site_id, 'JENKINS_UI_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_ui_task_execute_successful'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_ui_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_FAILED', 'CREATE_USER', @robot_in_site_id, 'JENKINS_UI_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_ui_task_execute_failed'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_ui_task_execute'); + + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_SUCCESSFUL', 'CREATE_USER', @robot_in_site_id, 'JENKINS_API_SCENARIO_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_api_scenario_task_execute_successful'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_api_scenario_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_FAILED', 'CREATE_USER', @robot_in_site_id, 'JENKINS_API_SCENARIO_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_api_scenario_task_execute_failed'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_api_scenario_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_SUCCESSFUL', 'CREATE_USER', @robot_in_site_id, 'JENKINS_API_CASE_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_api_case_task_execute_successful'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_api_case_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_FAILED', 'CREATE_USER', @robot_in_site_id, 'JENKINS_API_CASE_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_api_case_task_execute_failed'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_api_case_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_SUCCESSFUL', 'CREATE_USER', @robot_in_site_id, 'JENKINS_LOAD_CASE_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_load_case_task_execute_successful'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_load_case_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_FAILED', 'CREATE_USER', @robot_in_site_id, 'JENKINS_LOAD_CASE_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_load_case_task_execute_failed'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_load_case_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_SUCCESSFUL', 'CREATE_USER', @robot_in_site_id, 'JENKINS_TEST_PLAN_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_test_plan_task_execute_successful'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_test_plan_task_execute'); + +SET @load_report_id = UUID_SHORT(); +Insert into message_task(id, event, receiver, project_robot_id, task_type, test_id, project_id, enable, create_user, create_time, update_user, update_time, use_default_template, use_default_subject, subject) +VALUES (@load_report_id, 'EXECUTE_FAILED', 'CREATE_USER', @robot_in_site_id, 'JENKINS_TEST_PLAN_TASK', 'NONE', '100001100001', false, 'admin', unix_timestamp() * 1000, 'admin', unix_timestamp() * 1000, true, true, 'message.title.jenkins_test_plan_task_execute_failed'); +INSERT INTO message_task_blob(id, template) VALUES (@load_report_id, 'message.jenkins_test_plan_task_execute'); + -- set innodb lock wait timeout to default SET SESSION innodb_lock_wait_timeout = DEFAULT; diff --git a/backend/framework/sdk/src/main/resources/i18n/project.properties b/backend/framework/sdk/src/main/resources/i18n/project.properties index c6c9dbf145..27dd03b5ed 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project.properties @@ -131,7 +131,11 @@ message.api_definition_task=接口文档 message.api_scenario_task=接口场景 message.ui_scenario_task=UI自动化 message.load_test_task=测试用例 -message.jenkins_task=Jenkins任务 +message.jenkins_ui_task=Jenkins的UI用例任务 +message.jenkins_api_scenario_task=Jenkins的接口场景任务 +message.jenkins_api_case_task=Jenkins的接口用例任务 +message.jenkins_load_case_task=Jenkins的性能用例任务 +message.jenkins_test_plan_task=Jenkins的测试计划任务 message.test_plan_management=测试计划 message.bug_management=缺陷管理 message.case_management=用例管理 @@ -160,6 +164,9 @@ message.execute_failed=执行失败 message.create_user=创建人 message.follow_people=关注人 message.operator=操作人 +message.custom_field=自定义字段 +message.case_field=用例字段 +message.report_field=报告字段 message.test_plan_task_create=${OPERATOR}创建了测试计划:${name} message.test_plan_task_update=${OPERATOR}更新了测试计划:${name} message.test_plan_task_delete=${OPERATOR}删除了测试计划:${name} @@ -210,8 +217,12 @@ message.load_test_task_delete=${OPERATOR}删除了性能用例:${name} message.load_test_task_execute_completed=${OPERATOR}执行了性能用例:${name} message.load_schedule_task_execute_completed=${OPERATOR}通过定时任务执行了性能用例:${name} message.load_report_task_delete=${OPERATOR}删除了性能报告:${name} -message.jenkins_task_execute_successful=Jenkins执行了场景用例:${name} -message.jenkins_task_execute_failed=Jenkins执行了测试计划:${name} +message.jenkins_api_scenario_task_execute=Jenkins执行了接口场景:${name} +message.jenkins_api_case_task_execute=Jenkins执行了接口用例:${name} +message.jenkins_load_case_task_execute=Jenkins执行了性能用例:${name} +message.jenkins_test_plan_task_execute=Jenkins执行了测试计划:${name} +message.jenkins_ui_task_execute=Jenkins执行了UI用例:${name} + message.title.test_plan_task_create=测试计划创建通知 message.title.test_plan_task_update=测试计划更新通知 message.title.test_plan_task_delete=测试计划删除通知 @@ -259,8 +270,17 @@ message.title.load_test_task_update=性能用例更新通知 message.title.load_test_task_delete=性能用例删除通知 message.title.load_test_task_execute_completed=性能用例执行完成通知 message.title.load_report_task_delete=性能报告删除通知 -message.title.jenkins_task_execute_successful=Jenkins任务执行成功通知 -message.title.jenkins_task_execute_failed=Jenkins任务执行失败通知 +message.title.jenkins_api_scenario_task_execute_successful=Jenkins执行接口场景成功通知 +message.title.jenkins_api_scenario_task_execute_failed=Jenkins执行接口场景失败通知 +message.title.jenkins_api_case_task_execute_successful=Jenkins执行接口用例成功通知 +message.title.jenkins_api_case_task_execute_failed=Jenkins执行接口用例失败通知 +message.title.jenkins_load_case_task_execute_successful=Jenkins执行性能用例成功通知 +message.title.jenkins_load_case_task_execute_failed=Jenkins执行性能用例失败通知 +message.title.jenkins_test_plan_task_execute_successful=Jenkins执行测试计划成功通知 +message.title.jenkins_test_plan_task_execute_failed=Jenkins执行测试计划失败通知 +message.title.jenkins_ui_task_execute_successful=Jenkins执行UI用例成功通知 +message.title.jenkins_ui_task_execute_failed=Jenkins执行UI用例失败通知 +resource_pool_not_exist=资源池不存在 #file management file_module.not.exist=文件模块不存在 diff --git a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties index 3c7db009a2..7bccf08509 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_en_US.properties @@ -164,7 +164,11 @@ message.api_definition_task=API documentation message.api_scenario_task=API scenario message.ui_scenario_task=UI automation message.load_test_task=Test case -message.jenkins_task=Jenkins tasks +message.jenkins_ui_task=Jenkins tasks about UI +message.jenkins_api_scenario_task=Jenkins tasks about API scenario +message.jenkins_api_case_task=Jenkins tasks about an API case +message.jenkins_load_case_task=Jenkins tasks about a Load case +message.jenkins_test_plan_task=Jenkins tasks about test plan message.test_plan_management=Test Plan message.bug_management=Bug management message.case_management=Case management @@ -193,6 +197,9 @@ message.execute_failed=Execution failed message.create_user=Create user message.follow_people=Follow people message.operator=Operator +message.custom_field=Custom fields +message.case_field=Case field +message.report_field=Report fields message.test_plan_task_create=${OPERATOR}created the test plan: ${name} message.test_plan_task_update=${OPERATOR}updated the test plan: ${name} message.test_plan_task_delete=${OPERATOR}deleted the test plan: ${name} @@ -243,8 +250,11 @@ message.load_test_task_delete=${OPERATOR}deleted the load case: ${name} message.load_test_task_execute_completed=${OPERATOR}executed the load case: ${name} message.load_schedule_task_execute_completed=${OPERATOR}executed the load case through a scheduled task: ${name} message.load_report_task_delete=${OPERATOR}deleted load report: ${name} -message.jenkins_task_execute_successful=Jenkins executed the API scenario: ${name} -message.jenkins_task_execute_failed=Jenkins executed the test plan: ${name} +message.jenkins_api_scenario_task_execute=Jenkins executed the API scenario:${name} +message.jenkins_api_case_task_execute=Jenkins executed the API case:${name} +message.jenkins_load_case_task_execute=Jenkins executed the Load case:${name} +message.jenkins_test_plan_task_execute=Jenkins executed the test plan:${name} +message.jenkins_ui_task_execute=Jenkins executed the UI:${name} message.title.test_plan_task_create=Test plan creation notification message.title.test_plan_task_update=Test plan update notification message.title.test_plan_task_delete=Test plan deletion notification @@ -294,6 +304,16 @@ message.title.load_test_task_execute_completed=Load case execution completion no message.title.load_report_task_delete=Load report deletion notification message.title.jenkins_task_execute_successful=Jenkins task execution success notification message.title.jenkins_task_execute_failed=Jenkins task execution failure notification +message.title.jenkins_api_scenario_task_execute_successful=Jenkins執行介面場景成功通知 +message.title.jenkins_api_scenario_task_execute_failed=Jenkins執行介面場景失敗通知 +message.title.jenkins_api_case_task_execute_successful=Jenkins執行介面用例成功通知 +message.title.jenkins_api_case_task_execute_failed=Jenkins執行介面用例失敗通知 +message.title.jenkins_load_case_task_execute_successful=Jenkins執行性能用例成功通知 +message.title.jenkins_load_case_task_execute_failed=Jenkins執行性能用例失敗通知 +message.title.jenkins_test_plan_task_execute_successful=Jenkins執行測試計劃删成功通知 +message.title.jenkins_test_plan_task_execute_failed=Jenkins執行測試計劃删失敗通知 +message.title.jenkins_ui_task_execute_successful=Jenkins執行UI用例成功通知 +message.title.jenkins_ui_task_execute_failed=Jenkins execution UI use case success notification resource_pool_not_exist=Resource pool does not exist diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties index 40b2e476f1..1c15d21ca2 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_CN.properties @@ -164,7 +164,11 @@ message.api_definition_task=接口文档 message.api_scenario_task=接口场景 message.ui_scenario_task=UI自动化 message.load_test_task=测试用例 -message.jenkins_task=Jenkins任务 +message.jenkins_ui_task=Jenkins的UI用例任务 +message.jenkins_api_scenario_task=Jenkins的接口场景任务 +message.jenkins_api_case_task=Jenkins的接口用例任务 +message.jenkins_load_case_task=Jenkins的性能用例任务 +message.jenkins_test_plan_task=Jenkins的测试计划任务 message.test_plan_management=测试计划 message.bug_management=缺陷管理 message.case_management=用例管理 @@ -193,6 +197,9 @@ message.execute_failed=执行失败 message.create_user=创建人 message.follow_people=关注人 message.operator=操作人 +message.custom_field=自定义字段 +message.case_field=用例字段 +message.report_field=报告字段 message.test_plan_task_create=${OPERATOR}创建了测试计划:${name} message.test_plan_task_update=${OPERATOR}更新了测试计划:${name} message.test_plan_task_delete=${OPERATOR}删除了测试计划:${name} @@ -243,8 +250,11 @@ message.load_test_task_delete=${OPERATOR}删除了性能用例:${name} message.load_test_task_execute_completed=${OPERATOR}执行了性能用例:${name} message.load_schedule_task_execute_completed=${OPERATOR}通过定时任务执行了性能用例:${name} message.load_report_task_delete=${OPERATOR}删除了性能报告:${name} -message.jenkins_task_execute_successful=Jenkins执行了场景用例:${name} -message.jenkins_task_execute_failed=Jenkins执行了测试计划:${name} +message.jenkins_api_scenario_task_execute=Jenkins执行了接口场景:${name} +message.jenkins_api_case_task_execute=Jenkins执行了接口用例:${name} +message.jenkins_load_case_task_execute=Jenkins执行了性能用例:${name} +message.jenkins_test_plan_task_execute=Jenkins执行了测试计划:${name} +message.jenkins_ui_task_execute=Jenkins执行了UI用例:${name} message.title.test_plan_task_create=测试计划创建通知 message.title.test_plan_task_update=测试计划更新通知 message.title.test_plan_task_delete=测试计划删除通知 @@ -292,8 +302,16 @@ message.title.load_test_task_update=性能用例更新通知 message.title.load_test_task_delete=性能用例删除通知 message.title.load_test_task_execute_completed=性能用例执行完成通知 message.title.load_report_task_delete=性能报告删除通知 -message.title.jenkins_task_execute_successful=Jenkins任务执行成功通知 -message.title.jenkins_task_execute_failed=Jenkins任务执行失败通知 +message.title.jenkins_api_scenario_task_execute_successful=Jenkins执行接口场景成功通知 +message.title.jenkins_api_scenario_task_execute_failed=Jenkins执行接口场景失败通知 +message.title.jenkins_api_case_task_execute_successful=Jenkins执行接口用例成功通知 +message.title.jenkins_api_case_task_execute_failed=Jenkins执行接口用例失败通知 +message.title.jenkins_load_case_task_execute_successful=Jenkins执行性能用例成功通知 +message.title.jenkins_load_case_task_execute_failed=Jenkins执行性能用例失败通知 +message.title.jenkins_test_plan_task_execute_successful=Jenkins执行测试计划成功通知 +message.title.jenkins_test_plan_task_execute_failed=Jenkins执行测试计划失败通知 +message.title.jenkins_ui_task_execute_successful=Jenkins执行UI用例成功通知 +message.title.jenkins_ui_task_execute_failed=Jenkins执行UI用例失败通知 resource_pool_not_exist=资源池不存在 #file management diff --git a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties index 9ea580df8f..87b440e3b0 100644 --- a/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties +++ b/backend/framework/sdk/src/main/resources/i18n/project_zh_TW.properties @@ -165,7 +165,11 @@ message.api_definition_task=介面文檔 message.api_scenario_task=介面場景 message.ui_scenario_task=UI自動化 message.load_test_task=測試用例 -message.jenkins_task=Jenkins任務 +message.jenkins_ui_task=Jenkins的UI用例任務 +message.jenkins_api_scenario_task=Jenkins的介面場景任務 +message.jenkins_api_case_task=Jenkins的介面用例任務 +message.jenkins_load_case_task=Jenkins的效能用例任務 +message.jenkins_test_plan_task=Jenkins的測試計劃任務 message.test_plan_management=測試計劃 message.bug_management=缺陷管理 message.case_management=用例管理 @@ -194,6 +198,9 @@ message.execute_failed=執行失敗 message.create_user=創建人 message.follow_people=關注人 message.operator=操作人 +message.custom_field=自訂字段 +message.case_field=用例字段 +message.report_field=報告字段 message.test_plan_task_create=${OPERATOR}創建了測試計劃:${name} message.test_plan_task_update=${OPERATOR}更新了測試計劃:${name} message.test_plan_task_delete=${OPERATOR}删除了測試計劃:${name} @@ -244,8 +251,11 @@ message.load_test_task_delete=${OPERATOR}删除了性能用例:${name} message.load_test_task_execute_completed=${OPERATOR}執行了性能用例:${name} message.load_schedule_task_execute_completed=${OPERATOR}透過定時任務執行了性能用例:${name} message.load_report_task_delete=${OPERATOR}删除了性能報告:${name} -message.jenkins_task_execute_successful=Jenkins執行了场景用例:${name} -message.jenkins_task_execute_failed=Jenkins執行了測試計劃:${name} +message.jenkins_api_scenario_task_execute=Jenkins執行了介面場景:${name} +message.jenkins_api_case_task_execute=Jenkins執行了介面用例:${name} +message.jenkins_load_case_task_execute=Jenkins執行了性能用例:${name} +message.jenkins_test_plan_task_execute=Jenkins執行了測試計劃:${name} +message.jenkins_ui_task_execute=Jenkins執行了UI用例:${name} message.title.test_plan_task_create=測試計劃創建通知 message.title.test_plan_task_update=測試計劃更新通知 message.title.test_plan_task_delete=測試計劃删除通知 @@ -293,9 +303,16 @@ message.title.load_test_task_update=性能用例更新通知 message.title.load_test_task_delete=性能用例删除通知 message.title.load_test_task_execute_completed=性能用例執行完成通知 message.title.load_report_task_delete=性能報告删除通知 -message.title.jenkins_task_execute_successful=Jenkins任務執行成功通知 -message.title.jenkins_task_execute_failed=Jenkins任務執行失敗通知 - +message.title.jenkins_api_scenario_task_execute_successful=Jenkins執行介面場景成功通知 +message.title.jenkins_api_scenario_task_execute_failed=Jenkins執行介面場景失敗通知 +message.title.jenkins_api_case_task_execute_successful=Jenkins執行介面用例成功通知 +message.title.jenkins_api_case_task_execute_failed=Jenkins執行介面用例失敗通知 +message.title.jenkins_load_case_task_execute_successful=Jenkins執行性能用例成功通知 +message.title.jenkins_load_case_task_execute_failed=Jenkins執行性能用例失敗通知 +message.title.jenkins_test_plan_task_execute_successful=Jenkins執行測試計劃删成功通知 +message.title.jenkins_test_plan_task_execute_failed=Jenkins執行測試計劃删失敗通知 +message.title.jenkins_ui_task_execute_successful=Jenkins執行UI用例成功通知 +message.title.jenkins_ui_task_execute_failed=Jenkins執行UI用例失敗通知 resource_pool_not_exist=資源池不存在 #file management file_module.not.exist=文件模塊不存在 diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeTemplateController.java b/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeTemplateController.java index 0ee945283b..6c9423f649 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeTemplateController.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/controller/NoticeTemplateController.java @@ -1,9 +1,9 @@ package io.metersphere.project.controller; +import io.metersphere.project.dto.MessageTemplateResultDTO; import io.metersphere.project.service.NoticeTemplateService; import io.metersphere.sdk.constants.PermissionConstants; -import io.metersphere.sdk.dto.OptionDTO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.tags.Tag; @@ -23,7 +23,7 @@ public class NoticeTemplateController { @GetMapping("get/fields/{projectId}") @Operation(summary = "项目管理-消息设置-模版设置-获取消息模版字段") @RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ) - public List getTemplateFields(@PathVariable String projectId, @Schema(description = "消息配置功能类型") + public MessageTemplateResultDTO getTemplateFields(@PathVariable String projectId, @Schema(description = "消息配置功能类型") @RequestParam(value = "taskType") String taskType) { return noticeTemplateService.getTemplateFields(projectId, taskType); } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTemplateFieldDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTemplateFieldDTO.java new file mode 100644 index 0000000000..320eb326d1 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTemplateFieldDTO.java @@ -0,0 +1,21 @@ +package io.metersphere.project.dto; + +import io.metersphere.sdk.dto.OptionDTO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +/** + * 加载选项时,标记字段来自哪里,表字段,自定义字段,报告定义字段 + * + * @author guoyuqi + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class MessageTemplateFieldDTO extends OptionDTO { + + @Schema(description = "字段来源") + private String fieldSource; +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTemplateResultDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTemplateResultDTO.java new file mode 100644 index 0000000000..c97b30c708 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/MessageTemplateResultDTO.java @@ -0,0 +1,20 @@ +package io.metersphere.project.dto; + +import io.metersphere.sdk.dto.OptionDTO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; + +import java.io.Serializable; +import java.util.List; + +@Data +@EqualsAndHashCode(callSuper = false) +public class MessageTemplateResultDTO implements Serializable { + + @Schema(description = "字段来源列表") + public List fieldSourceList; + + @Schema(description = "字段列表") + public List fieldList; +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java b/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java index ce2b1f53ce..26cdcc5b9b 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/dto/ProjectRobotConfigDTO.java @@ -46,4 +46,10 @@ public class ProjectRobotConfigDTO implements Serializable { @Schema(description = "机器人是否使用默认标题") public Boolean useDefaultSubject; + @Schema(description = "机器人预览标题") + public String previewSubject; + + @Schema(description = "机器人预览模版") + public String previewTemplate; + } diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateRobotResourceService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateRobotResourceService.java index 462eb55582..8f5a43d655 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateRobotResourceService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/CreateRobotResourceService.java @@ -98,7 +98,7 @@ public class CreateRobotResourceService implements CreateProjectResourceService List messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList(); for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) { String taskType = messageTaskTypeDTO.getTaskType(); - if (taskType.contains(NoticeConstants.Mode.SCHEDULE) || taskType.contains("AT") || taskType.contains("JENKINS")) { + if (taskType.contains(NoticeConstants.Mode.SCHEDULE) || taskType.contains("AT")) { continue; } List messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList(); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java index c76cf79fa0..77e8657e49 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeMessageTaskService.java @@ -170,6 +170,7 @@ public class NoticeMessageTaskService { messageTaskExample.createCriteria().andReceiverIn(existUserIds).andProjectIdEqualTo(messageTaskRequest.getProjectId()) .andProjectRobotIdEqualTo(messageTaskRequest.getRobotId()).andTaskTypeEqualTo(messageTaskRequest.getTaskType()).andEventEqualTo(messageTaskRequest.getEvent()); List messageTasks = messageTaskMapper.selectByExample(messageTaskExample); + List messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList(); if (CollectionUtils.isEmpty(messageTasks)) { return new ArrayList<>(); } @@ -184,7 +185,6 @@ public class NoticeMessageTaskService { } mapper.updateByPrimaryKeySelective(messageTask); } - List messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList(); MessageTaskBlobExample messageTaskBlobExample = new MessageTaskBlobExample(); messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds); List messageTaskBlobs = messageTaskBlobMapper.selectByExample(messageTaskBlobExample); @@ -302,7 +302,7 @@ public class NoticeMessageTaskService { List messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList(); MessageTaskBlobExample messageTaskBlobExample = new MessageTaskBlobExample(); messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds); - List messageTaskBlobs = messageTaskBlobMapper.selectByExample(messageTaskBlobExample); + List messageTaskBlobs = messageTaskBlobMapper.selectByExampleWithBLOBs(messageTaskBlobExample); List robotIds = messageTasks.stream().map(MessageTask::getProjectRobotId).toList(); ProjectRobotExample projectRobotExample = new ProjectRobotExample(); projectRobotExample.createCriteria().andIdIn(robotIds); @@ -343,7 +343,7 @@ public class NoticeMessageTaskService { String defaultTemplate = defaultTemplateMap.get(messageTaskTypeDTO.getTaskType() + "_" + messageTaskDetailDTO.getEvent()); if (CollectionUtils.isEmpty(messageTaskList)) { String defaultSubject = defaultTemplateSubjectMap.get(messageTaskTypeDTO.getTaskType() + "_" + messageTaskDetailDTO.getEvent()); - ProjectRobotConfigDTO projectRobotConfigDTO = getDefaultProjectRobotConfigDTO(defaultTemplate, defaultSubject, projectRobot); + ProjectRobotConfigDTO projectRobotConfigDTO = getDefaultProjectRobotConfigDTO(messageTaskTypeDTO.getTaskType(), defaultTemplate, defaultSubject, projectRobot); projectRobotConfigMap.put(projectRobot.getId(), projectRobotConfigDTO); } else { for (MessageTask messageTask : messageTaskList) { @@ -379,33 +379,57 @@ public class NoticeMessageTaskService { projectRobotConfigDTO.setPlatform(projectRobot.getPlatform()); projectRobotConfigDTO.setDingType(projectRobot.getType()); projectRobotConfigDTO.setEnable(messageTask.getEnable()); - projectRobotConfigDTO.setTemplate(messageTaskBlob.getTemplate()); + if (messageTask.getUseDefaultSubject()) { + projectRobotConfigDTO.setSubject(defaultSubject); + } else { + projectRobotConfigDTO.setSubject(messageTask.getSubject()); + } + if (messageTask.getUseDefaultTemplate()) { + projectRobotConfigDTO.setTemplate(defaultTemplate); + } else { + projectRobotConfigDTO.setTemplate(messageTaskBlob.getTemplate()); + } + String translateTemplate = MessageTemplateUtils.getTranslateTemplate(messageTask.getTaskType(), projectRobotConfigDTO.getTemplate()); + String translateSubject = MessageTemplateUtils.getTranslateTemplate(messageTask.getTaskType(), projectRobotConfigDTO.getSubject()); + projectRobotConfigDTO.setPreviewTemplate(translateTemplate); + projectRobotConfigDTO.setPreviewSubject(translateSubject); projectRobotConfigDTO.setDefaultTemplate(defaultTemplate); - projectRobotConfigDTO.setSubject(messageTask.getSubject()); projectRobotConfigDTO.setDefaultSubject(defaultSubject); projectRobotConfigDTO.setUseDefaultSubject(messageTask.getUseDefaultSubject()); projectRobotConfigDTO.setUseDefaultTemplate(messageTask.getUseDefaultTemplate()); return projectRobotConfigDTO; } - private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String defaultTemplate, String defaultSubject, ProjectRobot projectRobot) { + private static ProjectRobotConfigDTO getDefaultProjectRobotConfigDTO(String taskType, String defaultTemplate, String defaultSubject, ProjectRobot projectRobot) { ProjectRobotConfigDTO projectRobotConfigDTO = new ProjectRobotConfigDTO(); projectRobotConfigDTO.setRobotId(projectRobot.getId()); projectRobotConfigDTO.setRobotName(projectRobot.getName()); projectRobotConfigDTO.setPlatform(ProjectRobotPlatform.IN_SITE.toString()); projectRobotConfigDTO.setDingType(projectRobot.getType()); projectRobotConfigDTO.setEnable(false); - projectRobotConfigDTO.setTemplate(""); + projectRobotConfigDTO.setTemplate(defaultTemplate); projectRobotConfigDTO.setDefaultTemplate(defaultTemplate); - projectRobotConfigDTO.setSubject(""); + projectRobotConfigDTO.setSubject(defaultSubject); projectRobotConfigDTO.setDefaultSubject(defaultSubject); projectRobotConfigDTO.setUseDefaultSubject(true); projectRobotConfigDTO.setUseDefaultTemplate(true); + String translateTemplate = MessageTemplateUtils.getTranslateTemplate(taskType, defaultTemplate); + String translateSubject = MessageTemplateUtils.getTranslateTemplate(taskType, defaultSubject); + projectRobotConfigDTO.setPreviewTemplate(translateTemplate); + projectRobotConfigDTO.setPreviewSubject(translateSubject); return projectRobotConfigDTO; } public List getUserList(String projectId, String keyword) { - return extProjectUserRoleMapper.getProjectUserSelectList(projectId, keyword); + List projectUserSelectList = extProjectUserRoleMapper.getProjectUserSelectList(projectId, keyword); + Map defaultRelatedUserMap = MessageTemplateUtils.getDefaultRelatedUserMap(); + defaultRelatedUserMap.forEach((k, v) -> { + OptionDTO optionDTO = new OptionDTO(); + optionDTO.setId(k); + optionDTO.setName(v); + projectUserSelectList.add(optionDTO); + }); + return projectUserSelectList; } public MessageTemplateConfigDTO getTemplateDetail(String projectId, String taskType, String event, String robotId) { @@ -434,7 +458,7 @@ public class NoticeMessageTaskService { } ProjectRobotConfigDTO projectRobotConfigDTO = getProjectRobotConfigDTO(defaultTemplate, defaultSubject, projectRobot, messageTask, messageTaskBlob); MessageTemplateConfigDTO messageTemplateConfigDTO = new MessageTemplateConfigDTO(); - BeanUtils.copyBean(messageTemplateConfigDTO,projectRobotConfigDTO); + BeanUtils.copyBean(messageTemplateConfigDTO, projectRobotConfigDTO); Map taskTypeMap = MessageTemplateUtils.getTaskTypeMap(); Map eventMap = MessageTemplateUtils.getEventMap(); messageTemplateConfigDTO.setTaskTypeName(taskTypeMap.get(messageTask.getTaskType())); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java index 8d111e81ec..02644055f7 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/service/NoticeTemplateService.java @@ -2,17 +2,22 @@ package io.metersphere.project.service; import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.domain.ApiScenario; +import io.metersphere.api.domain.ApiTestCase; import io.metersphere.bug.domain.Bug; import io.metersphere.functional.domain.CaseReview; import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.load.domain.LoadTest; import io.metersphere.plan.domain.TestPlan; +import io.metersphere.project.dto.MessageTemplateFieldDTO; +import io.metersphere.project.dto.MessageTemplateResultDTO; import io.metersphere.sdk.constants.TemplateScene; import io.metersphere.sdk.dto.OptionDTO; +import io.metersphere.sdk.util.Translator; import io.metersphere.system.domain.CustomField; import io.metersphere.system.domain.CustomFieldExample; import io.metersphere.system.mapper.CustomFieldMapper; import io.metersphere.system.notice.constants.NoticeConstants; +import io.metersphere.system.notice.utils.MessageTemplateUtils; import io.metersphere.ui.domain.UiScenario; import io.swagger.v3.oas.annotations.media.Schema; import jakarta.annotation.Resource; @@ -25,6 +30,7 @@ import java.lang.reflect.Field; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Map; @Service @Transactional(rollbackFor = Exception.class) @@ -33,100 +39,133 @@ public class NoticeTemplateService { @Resource protected CustomFieldMapper customFieldMapper; - public List getTemplateFields(String projectId, String taskType) { - List optionDTOList = new ArrayList<>(); + public List getDomainTemplateFields(String projectId, String taskType) { + List messageTemplateFieldDTOList = new ArrayList<>(); switch (taskType) { - case NoticeConstants.TaskType.API_DEFINITION_TASK -> { + case NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.TaskType.JENKINS_API_CASE_TASK -> { Field[] allFields = FieldUtils.getAllFields(ApiDefinition.class); - addOptionDto(optionDTOList, allFields); - addCustomFiled(optionDTOList, projectId, TemplateScene.API.toString()); + addOptionDto(messageTemplateFieldDTOList, allFields); + Field[] allCaseFields = FieldUtils.getAllFields(ApiTestCase.class); + addOptionDto(messageTemplateFieldDTOList, allCaseFields); + addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.API.toString()); //TODO:获取报告 } - case NoticeConstants.TaskType.API_SCENARIO_TASK, NoticeConstants.TaskType.API_SCHEDULE_TASK -> { + case NoticeConstants.TaskType.API_SCENARIO_TASK, NoticeConstants.TaskType.API_SCHEDULE_TASK, NoticeConstants.TaskType.JENKINS_API_SCENARIO_TASK -> { Field[] allFields = FieldUtils.getAllFields(ApiScenario.class); - addOptionDto(optionDTOList, allFields); + addOptionDto(messageTemplateFieldDTOList, allFields); //TODO:获取报告 } - case NoticeConstants.TaskType.TEST_PLAN_TASK -> { + case NoticeConstants.TaskType.TEST_PLAN_TASK, NoticeConstants.TaskType.JENKINS_TEST_PLAN_TASK -> { Field[] allFields = FieldUtils.getAllFields(TestPlan.class); - addOptionDto(optionDTOList, allFields); - addCustomFiled(optionDTOList, projectId, TemplateScene.TEST_PLAN.toString()); + addOptionDto(messageTemplateFieldDTOList, allFields); + addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.TEST_PLAN.toString()); //TODO:获取报告 } case NoticeConstants.TaskType.CASE_REVIEW_TASK -> { Field[] allFields = FieldUtils.getAllFields(CaseReview.class); - addOptionDto(optionDTOList, allFields); + addOptionDto(messageTemplateFieldDTOList, allFields); //TODO:获取报告 } case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> { Field[] allFields = FieldUtils.getAllFields(FunctionalCase.class); - addOptionDto(optionDTOList, allFields); - addCustomFiled(optionDTOList, projectId, TemplateScene.FUNCTIONAL.toString()); + addOptionDto(messageTemplateFieldDTOList, allFields); + addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.FUNCTIONAL.toString()); //TODO:获取报告 } case NoticeConstants.TaskType.BUG_TASK -> { Field[] allFields = FieldUtils.getAllFields(Bug.class); - addOptionDto(optionDTOList, allFields); - addCustomFiled(optionDTOList, projectId, TemplateScene.BUG.toString()); + addOptionDto(messageTemplateFieldDTOList, allFields); + addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.BUG.toString()); //TODO:获取报告 } - case NoticeConstants.TaskType.UI_SCENARIO_TASK -> { + case NoticeConstants.TaskType.UI_SCENARIO_TASK, NoticeConstants.TaskType.JENKINS_UI_TASK -> { Field[] allFields = FieldUtils.getAllFields(UiScenario.class); - addOptionDto(optionDTOList, allFields); - addCustomFiled(optionDTOList, projectId, TemplateScene.UI.toString()); + addOptionDto(messageTemplateFieldDTOList, allFields); + addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.UI.toString()); //TODO:获取报告 } - case NoticeConstants.TaskType.LOAD_TEST_TASK -> { + case NoticeConstants.TaskType.LOAD_TEST_TASK, NoticeConstants.TaskType.JENKINS_LOAD_CASE_TASK -> { Field[] allFields = FieldUtils.getAllFields(LoadTest.class); - addOptionDto(optionDTOList, allFields); + addOptionDto(messageTemplateFieldDTOList, allFields); //TODO:获取报告 } - default -> optionDTOList = new ArrayList<>(); + default -> messageTemplateFieldDTOList = new ArrayList<>(); } - return optionDTOList; + + return messageTemplateFieldDTOList; } /** * 添加自定义字段 - * @param optionDTOList optionDTOList - * @param projectId projectId - * @param scene 对应场景 + * + * @param messageTemplateFieldDTOS messageTemplateFieldDTOS + * @param projectId projectId + * @param scene 对应场景 */ - private void addCustomFiled(List optionDTOList, String projectId, String scene) { + private void addCustomFiled(List messageTemplateFieldDTOS, String projectId, String scene) { CustomFieldExample example = new CustomFieldExample(); example.createCriteria().andScopeIdEqualTo(projectId).andSceneEqualTo(scene); List customFields = customFieldMapper.selectByExample(example); for (CustomField customField : customFields) { - OptionDTO optionDTO = new OptionDTO(); - optionDTO.setId(customField.getName()); - optionDTO.setName(StringUtils.isBlank(customField.getRemark()) ? "-" : customField.getRemark()); - optionDTOList.add(optionDTO); + MessageTemplateFieldDTO messageTemplateFieldDTO = new MessageTemplateFieldDTO(); + messageTemplateFieldDTO.setId(customField.getName()); + messageTemplateFieldDTO.setName(StringUtils.isBlank(customField.getRemark()) ? "-" : customField.getRemark()); + messageTemplateFieldDTO.setFieldSource(NoticeConstants.FieldSource.CUSTOM_FIELD); + messageTemplateFieldDTOS.add(messageTemplateFieldDTO); } } /** * 添加数据库字段 - * @param optionDTOList optionDTOList - * @param allFields allFields + * + * @param messageTemplateFieldDTOS messageTemplateFieldDTOS + * @param allFields allFields */ - private static void addOptionDto(List optionDTOList, Field[] allFields) { + private static void addOptionDto(List messageTemplateFieldDTOS, Field[] allFields) { Field[] sensitiveFields = FieldUtils.getAllFields(NoticeConstants.SensitiveField.class); ArrayList sensitiveFieldList = new ArrayList<>(sensitiveFields.length); Collections.addAll(sensitiveFieldList, sensitiveFields); List nameList = sensitiveFieldList.stream().map(Field::getName).toList(); for (Field allField : allFields) { - OptionDTO optionDTO = new OptionDTO(); + MessageTemplateFieldDTO messageTemplateFieldDTO = new MessageTemplateFieldDTO(); if (nameList.contains(allField.getName())) { continue; } - optionDTO.setId(allField.getName()); + Schema annotation = allField.getAnnotation(Schema.class); if (annotation != null) { + messageTemplateFieldDTO.setId(allField.getName()); String description = annotation.description(); - optionDTO.setName(description); - optionDTOList.add(optionDTO); + messageTemplateFieldDTO.setName(description); + messageTemplateFieldDTO.setFieldSource(NoticeConstants.FieldSource.CASE_FIELD); + messageTemplateFieldDTOS.add(messageTemplateFieldDTO); } } + MessageTemplateFieldDTO messageTemplateFieldOperator = new MessageTemplateFieldDTO(); + messageTemplateFieldOperator.setId(NoticeConstants.RelatedUser.OPERATOR); + messageTemplateFieldOperator.setFieldSource(NoticeConstants.FieldSource.CASE_FIELD); + messageTemplateFieldOperator.setName(Translator.get("message.operator")); + messageTemplateFieldDTOS.add(messageTemplateFieldOperator); + MessageTemplateFieldDTO messageTemplateFieldFollow = new MessageTemplateFieldDTO(); + messageTemplateFieldFollow.setId(NoticeConstants.RelatedUser.FOLLOW_PEOPLE); + messageTemplateFieldFollow.setFieldSource(NoticeConstants.FieldSource.CASE_FIELD); + messageTemplateFieldFollow.setName(Translator.get("message.follow_people")); + messageTemplateFieldDTOS.add(messageTemplateFieldFollow); } + public MessageTemplateResultDTO getTemplateFields(String projectId, String taskType) { + MessageTemplateResultDTO messageTemplateResultDTO = new MessageTemplateResultDTO(); + List domainTemplateFields = getDomainTemplateFields(projectId, taskType); + messageTemplateResultDTO.setFieldList(domainTemplateFields); + Map fieldSourceMap = MessageTemplateUtils.getFieldSourceMap(); + List optionDTOList = new ArrayList<>(); + fieldSourceMap.forEach((k, v) -> { + OptionDTO optionDTO = new OptionDTO(); + optionDTO.setId(k); + optionDTO.setName(v); + optionDTOList.add(optionDTO); + }); + messageTemplateResultDTO.setFieldSourceList(optionDTOList); + return messageTemplateResultDTO; + } } diff --git a/backend/services/project-management/src/main/resources/message_task.json b/backend/services/project-management/src/main/resources/message_task.json index 7fe22a49d1..8f49bd5d8c 100644 --- a/backend/services/project-management/src/main/resources/message_task.json +++ b/backend/services/project-management/src/main/resources/message_task.json @@ -985,32 +985,32 @@ "useDefaultSubject":true } ] - }, + } + ] + }, + { + "taskType":"UI_REPORT_TASK", + "taskTypeName":"", + "messageTaskDetailDTOList":[ { - "taskType":"UI_REPORT_TASK", - "taskTypeName":"", - "messageTaskDetailDTOList":[ + "event":"DELETE", + "eventName":"", + "receivers":[ { - "event":"DELETE", - "eventName":"", - "receivers":[ - { - "id": "CREATE_USER", - "name": "" - } - ], - "projectRobotConfigList":[ - { - "robotId":"", - "enable":"", - "template":"", - "defaultTemplate":"", - "useDefaultTemplate":true, - "subject":"", - "defaultSubject":"", - "useDefaultSubject":true - } - ] + "id": "CREATE_USER", + "name": "" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true } ] } @@ -1153,7 +1153,7 @@ "name":"", "messageTaskTypeDTOList":[ { - "taskType":"JENKINS_TASK", + "taskType":"JENKINS_UI_TASK", "taskTypeName":"", "messageTaskDetailDTOList":[ { @@ -1161,8 +1161,8 @@ "eventName":"", "receivers":[ { - "id": "", - "name": "" + "id":"", + "name":"" } ], "projectRobotConfigList":[ @@ -1183,8 +1183,208 @@ "eventName":"", "receivers":[ { - "id": "", - "name": "" + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + } + ] + }, + { + "taskType":"JENKINS_API_SCENARIO_TASK", + "taskTypeName":"", + "messageTaskDetailDTOList":[ + { + "event":"EXECUTE_SUCCESSFUL", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + }, + { + "event":"EXECUTE_FAILED", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + } + ] + }, + { + "taskType":"JENKINS_API_CASE_TASK", + "taskTypeName":"", + "messageTaskDetailDTOList":[ + { + "event":"EXECUTE_SUCCESSFUL", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + }, + { + "event":"EXECUTE_FAILED", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + } + ] + }, + { + "taskType":"JENKINS_LOAD_CASE_TASK", + "taskTypeName":"", + "messageTaskDetailDTOList":[ + { + "event":"EXECUTE_SUCCESSFUL", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + }, + { + "event":"EXECUTE_FAILED", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + } + ] + }, + { + "taskType":"JENKINS_UI_TASK", + "taskTypeName":"", + "messageTaskDetailDTOList":[ + { + "event":"EXECUTE_SUCCESSFUL", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" + } + ], + "projectRobotConfigList":[ + { + "robotId":"", + "enable":"", + "template":"", + "defaultTemplate":"", + "useDefaultTemplate":true, + "subject":"", + "defaultSubject":"", + "useDefaultSubject":true + } + ] + }, + { + "event":"EXECUTE_FAILED", + "eventName":"", + "receivers":[ + { + "id":"", + "name":"" } ], "projectRobotConfigList":[ diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java index 45842cd49a..598fec140f 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeMessageTaskControllerTests.java @@ -4,11 +4,7 @@ package io.metersphere.project.controller; import io.metersphere.project.domain.MessageTask; import io.metersphere.project.domain.MessageTaskBlob; import io.metersphere.project.domain.MessageTaskExample; -import io.metersphere.project.dto.MessageTaskDTO; - -import io.metersphere.project.dto.MessageTaskDetailDTO; -import io.metersphere.project.dto.MessageTemplateConfigDTO; -import io.metersphere.project.dto.ProjectRobotConfigDTO; +import io.metersphere.project.dto.*; import io.metersphere.project.mapper.MessageTaskBlobMapper; import io.metersphere.project.mapper.MessageTaskMapper; import io.metersphere.sdk.constants.SessionConstants; @@ -18,9 +14,15 @@ import io.metersphere.sdk.util.JSON; import io.metersphere.system.base.BaseTest; import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.notice.constants.NoticeConstants; +import io.metersphere.system.uid.UUID; import jakarta.annotation.Resource; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.ibatis.session.ExecutorType; +import org.apache.ibatis.session.SqlSession; +import org.apache.ibatis.session.SqlSessionFactory; import org.junit.jupiter.api.*; +import org.mybatis.spring.SqlSessionUtils; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.http.MediaType; @@ -29,14 +31,20 @@ import org.springframework.test.context.jdbc.SqlConfig; import org.springframework.test.web.servlet.MvcResult; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; import java.nio.charset.StandardCharsets; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @AutoConfigureMockMvc @TestMethodOrder(MethodOrderer.OrderAnnotation.class) public class NoticeMessageTaskControllerTests extends BaseTest { @@ -47,6 +55,9 @@ public class NoticeMessageTaskControllerTests extends BaseTest { @Resource private MessageTaskBlobMapper messageTaskBlobMapper; + @Resource + private SqlSessionFactory sqlSessionFactory; + @Test @Order(1) @Sql(scripts = {"/dml/init_project_message.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) @@ -215,7 +226,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest { messageTaskRequest.setUseDefaultTemplate(false); messageTaskRequest.setSubject("测试新加数据模版标题生效"); messageTaskRequest.setUseDefaultSubject(false); - MvcResult mvcResult =mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save") + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save") .header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken) .content(JSON.toJSONString(messageTaskRequest)) @@ -239,7 +250,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest { public void addMessageTaskCheckProjectExistFail() throws Exception { //项目不存在 MessageTaskRequest messageTaskRequest = new MessageTaskRequest(); - messageTaskRequest.setProjectId("project-message-test-3"); + messageTaskRequest.setProjectId("project-message-test-x"); messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); List userIds = new ArrayList<>(); @@ -260,7 +271,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest { @Test @Order(8) public void getMessageListSuccess() throws Exception { - MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/project-message-test-1") + setMessageTask("project-message-test-3", "test_message_robot4"); + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/project-message-test-3") .header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken)) .andExpect(status().isOk()) @@ -270,12 +282,13 @@ public class NoticeMessageTaskControllerTests extends BaseTest { List messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class); System.out.println(messageTaskDetailDTOList); Assertions.assertTrue(CollectionUtils.isNotEmpty(messageTaskDetailDTOList)); + System.out.println(messageTaskDetailDTOList); } @Test @Order(9) public void getMessageListProjectFail() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/project-message-test-3") + mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/project-message-test-x") .header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken)) .andExpect(status().is5xxServerError()) @@ -296,7 +309,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest { MessageTaskDetailDTO messageTaskDetailDTO = messageTaskDetailDTOList.get(0).getMessageTaskTypeDTOList().get(0).getMessageTaskDetailDTOList().get(0); Map projectRobotConfigMap = messageTaskDetailDTO.getProjectRobotConfigMap(); System.out.println(projectRobotConfigMap); - // Assertions.assertTrue(StringUtils.isBlank(robotId)); + // Assertions.assertTrue(StringUtils.isBlank(robotId)); } @@ -341,7 +354,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest { messageTaskRequest.setReceiverIds(userIds); messageTaskRequest.setRobotId("test_message_robot2"); messageTaskRequest.setEnable(true); - // messageTaskRequest.setDefaultTemplate("发送消息测试"); + // messageTaskRequest.setDefaultTemplate("发送消息测试"); MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.post("/notice/message/task/save") .header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken) @@ -414,6 +427,31 @@ public class NoticeMessageTaskControllerTests extends BaseTest { @Test @Order(15) + public void getMessageListUpdate() throws Exception { + MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/project-message-test") + .header(SessionConstants.HEADER_TOKEN, sessionId) + .header(SessionConstants.CSRF_TOKEN, csrfToken)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); + String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); + ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); + List messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class); + System.out.println(messageTaskDetailDTOList); + Assertions.assertTrue(CollectionUtils.isNotEmpty(messageTaskDetailDTOList)); + System.out.println(messageTaskDetailDTOList); + List collect = messageTaskDetailDTOList.stream().filter(t -> t.type.equals(NoticeConstants.Module.API_TEST_MANAGEMENT)).toList(); + List messageTaskTypeDTOList = collect.get(0).getMessageTaskTypeDTOList(); + List collect1 = messageTaskTypeDTOList.stream().filter(t -> t.getTaskType().equals(NoticeConstants.TaskType.API_DEFINITION_TASK)).toList(); + List messageTaskDetailDTOList1 = collect1.get(0).getMessageTaskDetailDTOList(); + List collect2 = messageTaskDetailDTOList1.stream().filter(t -> t.event.equals(NoticeConstants.Event.CREATE)).toList(); + Map projectRobotConfigMap = collect2.get(0).getProjectRobotConfigMap(); + ProjectRobotConfigDTO projectRobotConfigDTO = projectRobotConfigMap.get("test_message_robot2"); + Assertions.assertTrue(StringUtils.equals(projectRobotConfigDTO.getTemplate(),"发送消息测试")); + } + + + @Test + @Order(16) public void closeMessageTaskSuccess() throws Exception { MessageTaskRequest messageTaskRequest = new MessageTaskRequest(); messageTaskRequest.setProjectId("project-message-test"); @@ -439,7 +477,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest { } @Test - @Order(16) + @Order(17) public void getUserSuccess() throws Exception { MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -451,11 +489,11 @@ public class NoticeMessageTaskControllerTests extends BaseTest { String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); List userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); - Assertions.assertTrue(userDtoList.size()>0); + Assertions.assertTrue(userDtoList.size() > 0); } @Test - @Order(17) + @Order(18) public void getUserSuccessAll() throws Exception { MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -466,12 +504,12 @@ public class NoticeMessageTaskControllerTests extends BaseTest { String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); List userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); - Assertions.assertTrue(userDtoList.size()>0); + Assertions.assertTrue(userDtoList.size() > 0); } @Test - @Order(18) + @Order(19) public void getUserSuccessEmpty() throws Exception { MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test-x") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -482,11 +520,11 @@ public class NoticeMessageTaskControllerTests extends BaseTest { String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); List userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); - Assertions.assertEquals(0, userDtoList.size()); + Assertions.assertEquals(3, userDtoList.size()); } @Test - @Order(19) + @Order(20) public void getTemplateDetailWithRobot() throws Exception { MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -500,11 +538,11 @@ public class NoticeMessageTaskControllerTests extends BaseTest { String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); MessageTemplateConfigDTO messageTemplateConfigDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateConfigDTO.class); - Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size()>0); + Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size() > 0); } @Test - @Order(20) + @Order(21) public void getTemplateDetailWithOutRobot() throws Exception { MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -518,13 +556,13 @@ public class NoticeMessageTaskControllerTests extends BaseTest { String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); MessageTemplateConfigDTO messageTemplateConfigDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateConfigDTO.class); - Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size()>0); + Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size() > 0); } @Test - @Order(21) + @Order(22) public void getTemplateDetailNotExistRobot() throws Exception { - mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test") + mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test") .header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.CSRF_TOKEN, csrfToken) .param("taskType", NoticeConstants.TaskType.API_DEFINITION_TASK) @@ -534,4 +572,69 @@ public class NoticeMessageTaskControllerTests extends BaseTest { .andExpect(status().is5xxServerError()) .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); } + + public void setMessageTask(String projectId, String defaultRobotId) { + StringBuilder jsonStr = new StringBuilder(); + InputStream inputStream = getClass().getResourceAsStream("/message_task.json"); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream)); + String line; + try { + while ((line = reader.readLine()) != null) { + jsonStr.append(line); + } + reader.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + + SqlSession sqlSession = sqlSessionFactory.openSession(ExecutorType.BATCH); + MessageTaskMapper mapper = sqlSession.getMapper(MessageTaskMapper.class); + MessageTaskBlobMapper blobMapper = sqlSession.getMapper(MessageTaskBlobMapper.class); + + List messageTaskDTOList = JSON.parseArray(jsonStr.toString(), MessageTaskDTO.class); + for (MessageTaskDTO messageTaskDTO : messageTaskDTOList) { + List messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList(); + for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) { + String taskType = messageTaskTypeDTO.getTaskType(); + if (taskType.contains(NoticeConstants.Mode.SCHEDULE) || taskType.contains("AT")) { + continue; + } + List messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList(); + for (MessageTaskDetailDTO messageTaskDetailDTO : messageTaskDetailDTOList) { + String event = messageTaskDetailDTO.getEvent(); + List receivers = messageTaskDetailDTO.getReceivers(); + if (StringUtils.equalsIgnoreCase(event, NoticeConstants.Event.CREATE) || StringUtils.equalsIgnoreCase(event, NoticeConstants.Event.CASE_CREATE) || CollectionUtils.isEmpty(receivers)) { + continue; + } + for (OptionDTO receiver : receivers) { + String id = UUID.randomUUID().toString(); + MessageTask messageTask = new MessageTask(); + messageTask.setId(id); + messageTask.setEvent(event); + messageTask.setTaskType(taskType); + messageTask.setReceiver(receiver.getId()); + messageTask.setProjectId(projectId); + messageTask.setProjectRobotId(defaultRobotId); + messageTask.setEnable(true); + messageTask.setTestId("NONE"); + messageTask.setCreateUser("admin"); + messageTask.setCreateTime(System.currentTimeMillis()); + messageTask.setUpdateUser("admin"); + messageTask.setUpdateTime(System.currentTimeMillis()); + messageTask.setSubject(""); + messageTask.setUseDefaultSubject(true); + messageTask.setUseDefaultTemplate(true); + MessageTaskBlob messageTaskBlob = new MessageTaskBlob(); + messageTaskBlob.setId(id); + messageTaskBlob.setTemplate(""); + mapper.insert(messageTask); + blobMapper.insert(messageTaskBlob); + } + } + } + } + + sqlSession.flushStatements(); + SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory); + } } diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeTemplateControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeTemplateControllerTests.java index 865a4946e6..9925fdec74 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeTemplateControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/NoticeTemplateControllerTests.java @@ -1,5 +1,7 @@ package io.metersphere.project.controller; +import io.metersphere.project.dto.MessageTemplateFieldDTO; +import io.metersphere.project.dto.MessageTemplateResultDTO; import io.metersphere.sdk.constants.SessionConstants; import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.util.JSON; @@ -42,7 +44,12 @@ public class NoticeTemplateControllerTests extends BaseTest { typeList.add(NoticeConstants.TaskType.BUG_TASK); typeList.add(NoticeConstants.TaskType.UI_SCENARIO_TASK); typeList.add(NoticeConstants.TaskType.LOAD_TEST_TASK); - typeList.add(NoticeConstants.TaskType.JENKINS_TASK); + typeList.add(NoticeConstants.TaskType.JENKINS_UI_TASK); + typeList.add(NoticeConstants.TaskType.JENKINS_API_SCENARIO_TASK); + typeList.add(NoticeConstants.TaskType.JENKINS_API_CASE_TASK); + typeList.add(NoticeConstants.TaskType.JENKINS_LOAD_CASE_TASK); + typeList.add(NoticeConstants.TaskType.JENKINS_TEST_PLAN_TASK); + typeList.add(NoticeConstants.TaskType.BUG_TASK_AT); for (String s : typeList) { MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/project-template-test-1") .header(SessionConstants.HEADER_TOKEN, sessionId) @@ -52,8 +59,9 @@ public class NoticeTemplateControllerTests extends BaseTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - List projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); - if (s.equals(NoticeConstants.TaskType.JENKINS_TASK)) { + MessageTemplateResultDTO messageTemplateResultDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateResultDTO.class); + List projectList = messageTemplateResultDTO.getFieldList(); + if (s.equals(NoticeConstants.TaskType.BUG_TASK_AT)) { Assertions.assertTrue(CollectionUtils.isEmpty(projectList)); } else { Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList)); @@ -82,7 +90,8 @@ public class NoticeTemplateControllerTests extends BaseTest { .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); - List projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); + MessageTemplateResultDTO messageTemplateResultDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateResultDTO.class); + List projectList = messageTemplateResultDTO.getFieldList(); if (s.equals(NoticeConstants.TaskType.API_DEFINITION_TASK)) { List collect = projectList.stream().map(OptionDTO::getId).toList(); Assertions.assertFalse(collect.contains("grade")); diff --git a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java index c7ba3784da..2f610fb44d 100644 --- a/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java +++ b/backend/services/project-management/src/test/java/io/metersphere/project/controller/ProjectRobotControllerTests.java @@ -459,7 +459,7 @@ public class ProjectRobotControllerTests extends BaseTest { List messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList(); for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) { String taskType = messageTaskTypeDTO.getTaskType(); - if (taskType.contains(NoticeConstants.Mode.SCHEDULE) || taskType.contains("AT") || taskType.contains("JENKINS")) { + if (taskType.contains(NoticeConstants.Mode.SCHEDULE) || taskType.contains("AT")) { continue; } List messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList(); diff --git a/backend/services/project-management/src/test/resources/dml/init_project_message.sql b/backend/services/project-management/src/test/resources/dml/init_project_message.sql index b2904f4ae6..031eab0182 100644 --- a/backend/services/project-management/src/test/resources/dml/init_project_message.sql +++ b/backend/services/project-management/src/test/resources/dml/init_project_message.sql @@ -4,7 +4,8 @@ INSERT INTO organization(id, num, name, description, create_time, update_time, c INSERT INTO project (id, num, organization_id, name, description, create_user, update_user, create_time, update_time) VALUES ('project-message-test', null, 'organization-message-test', '默认项目', '系统默认创建的项目', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), ('project-message-test-1', null, 'organization-message-test-1', '默认项目1', '系统默认创建的项目1', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), - ('project-message-test-2', null, 'organization-message-test-2', '默认项目2', '系统默认创建的项目1', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000); + ('project-message-test-2', null, 'organization-message-test-2', '默认项目2', '系统默认创建的项目2', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000), + ('project-message-test-3', null, 'organization-message-test-3', '默认项目3', '系统默认创建的项目3', 'admin', 'admin', UNIX_TIMESTAMP() * 1000, UNIX_TIMESTAMP() * 1000); INSERT INTO user(id, name, email, password, create_time, update_time, language, last_organization_id, phone, source, last_project_id, create_user, update_user, deleted) VALUES @@ -36,7 +37,10 @@ INSERT INTO user_role_relation (id, user_id, role_id, source_id, organization_id INSERT INTO project_robot(id, project_id, name, platform, webhook, type, app_key, app_secret, enable, create_user, create_time, update_user, update_time, description) VALUES ('test_message_robot1', 'project-message-test-1', '测试机器人1', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null), ('test_message_robot2', 'project-message-test-1', '测试机器人2', 'MAIL', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null), - ('test_message_robot3', 'project-message-test-1', '测试机器人3', 'WE_COM', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null); + ('test_message_robot3', 'project-message-test-1', '测试机器人3', 'WE_COM', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null), + ('test_message_robot4', 'project-message-test-3', '测试机器人1', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null), + ('test_message_robot5', 'project-message-test', '测试机器人6', 'IN_SITE', 'NONE', null, null, null, true, 'admin', unix_timestamp() * 1000,'admin', unix_timestamp() * 1000, null); + diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/constants/NoticeConstants.java b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/constants/NoticeConstants.java index 32cf1a57de..94aa89abbd 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/constants/NoticeConstants.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/constants/NoticeConstants.java @@ -58,8 +58,17 @@ public interface NoticeConstants { String LOAD_SCHEDULE_TASK = "LOAD_SCHEDULE_TASK"; //jenkins任务 - @Schema(description = "message.jenkins_task") - String JENKINS_TASK = "JENKINS_TASK"; + @Schema(description = "message.jenkins_ui_task") + String JENKINS_UI_TASK = "JENKINS_UI_TASK"; + @Schema(description = "message.jenkins_api_scenario_task") + String JENKINS_API_SCENARIO_TASK = "JENKINS_API_SCENARIO_TASK"; + @Schema(description = "message.jenkins_api_case_task") + String JENKINS_API_CASE_TASK = "JENKINS_API_CASE_TASK"; + @Schema(description = "message.jenkins_load_case_task") + String JENKINS_LOAD_CASE_TASK = "JENKINS_LOAD_CASE_TASK"; + @Schema(description = "message.jenkins_test_plan_task") + String JENKINS_TEST_PLAN_TASK = "JENKINS_TEST_PLAN_TASK"; + } interface Mode { @@ -158,6 +167,7 @@ public interface NoticeConstants { interface RelatedUser { @Schema(description = "message.create_user") + //TODO:// 和实体类创建人应该保持一致,还需再改 String CREATE_USER = "CREATE_USER";//创建人 @Schema(description = "message.follow_people") String FOLLOW_PEOPLE = "FOLLOW_PEOPLE";//关注人 @@ -165,6 +175,15 @@ public interface NoticeConstants { String OPERATOR = "OPERATOR"; //操作人 } + interface FieldSource { + @Schema(description = "message.custom_field") + String CUSTOM_FIELD = "CUSTOM_FIELD";//自定义字段 + @Schema(description = "message.case_field") + String CASE_FIELD = "CASE_FIELD";//用例字段 + @Schema(description = "message.report_field") + String REPORT_FIELD = "REPORT_FIELD"; //报告字段 + } + interface TemplateText { @Schema(description = "message.test_plan_task_create") String TEST_PLAN_TASK_CREATE = "TEST_PLAN_TASK_CREATE"; // ${OPERATOR}创建了测试计划:${name} @@ -284,10 +303,27 @@ public interface NoticeConstants { @Schema(description = "message.load_report_task_delete") String LOAD_REPORT_TASK_DELETE = "LOAD_REPORT_TASK_DELETE";//${OPERATOR}删除了性能报告:${name} - @Schema(description = "message.jenkins_task_execute_successful") - String JENKINS_TASK_EXECUTE_SUCCESSFUL = "JENKINS_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了场景用例:${name} - @Schema(description = "message.jenkins_task_execute_failed") - String JENKINS_TASK_EXECUTE_FAILED = "JENKINS_TASK_EXECUTE_FAILED";//Jenkins执行了测试计划:${name} + @Schema(description = "message.jenkins_api_scenario_task_execute") + String JENKINS_API_SCENARIO_TASK_EXECUTE_SUCCESSFUL = "JENKINS_API_SCENARIO_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了接口场景:${name} + @Schema(description = "message.jenkins_api_scenario_task_execute") + String JENKINS_API_SCENARIO_TASK_EXECUTE_FAILED = "JENKINS_API_SCENARIO_TASK_EXECUTE_FAILED";//Jenkins执行了接口场景:${name} + @Schema(description = "message.jenkins_api_case_task_execute") + String JENKINS_API_CASE_TASK_EXECUTE_SUCCESSFUL = "JENKINS_API_CASE_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了接口用例:${name} + @Schema(description = "message.jenkins_api_case_task_execute") + String JENKINS_API_CASE_TASK_EXECUTE_FAILED = "JENKINS_API_CASE_TASK_EXECUTE_FAILED";//Jenkins执行了接口用例:${name} + @Schema(description = "message.jenkins_load_case_task_execute") + String JENKINS_LOAD_CASE_TASK_EXECUTE_SUCCESSFUL = "JENKINS_LOAD_CASE_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了性能用例:${name} + @Schema(description = "message.jenkins_load_case_task_execute") + String JENKINS_LOAD_CASE_TASK_EXECUTE_FAILED = "JENKINS_LOAD_CASE_TASK_EXECUTE_FAILED";//Jenkins执行了性能用例:${name} + @Schema(description = "message.jenkins_test_plan_task_execute") + String JENKINS_TEST_PLAN_TASK_EXECUTE_SUCCESSFUL = "JENKINS_TEST_PLAN_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了测试计划:${name} + @Schema(description = "message.jenkins_test_plan_task_execute") + String JENKINS_TEST_PLAN_TASK_EXECUTE_FAILED = "JENKINS_TEST_PLAN_TASK_EXECUTE_FAILED";//Jenkins执行了测试计划:${name} + @Schema(description = "message.jenkins_ui_task_execute") + String JENKINS_UI_TASK_EXECUTE_SUCCESSFUL = "JENKINS_UI_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了UI用例:${name} + @Schema(description = "message.jenkins_ui_task_execute") + String JENKINS_UI_TASK_EXECUTE_FAILED = "JENKINS_UI_TASK_EXECUTE_FAILED";//Jenkins执行了UI用例:${name} + } interface TemplateSubject { @@ -409,6 +445,27 @@ public interface NoticeConstants { String JENKINS_TASK_EXECUTE_SUCCESSFUL = "JENKINS_TASK_EXECUTE_SUCCESSFUL"; @Schema(description = "message.title.jenkins_task_execute_failed")//Jenkins任务执行失败通知 String JENKINS_TASK_EXECUTE_FAILED = "JENKINS_TASK_EXECUTE_FAILED"; + + @Schema(description = "message.title.jenkins_api_scenario_task_execute_successful") + String JENKINS_API_SCENARIO_TASK_EXECUTE_SUCCESSFUL = "JENKINS_API_SCENARIO_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行接口场景成功通知 + @Schema(description = "message.title.jenkins_api_scenario_task_execute_failed") + String JENKINS_API_SCENARIO_TASK_EXECUTE_FAILED = "JENKINS_API_SCENARIO_TASK_EXECUTE_FAILED";//Jenkins执行接口场景失败通知 + @Schema(description = "message.title.jenkins_api_case_task_execute_successful") + String JENKINS_API_CASE_TASK_EXECUTE_SUCCESSFUL = "JENKINS_API_CASE_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行接口用例成功通知 + @Schema(description = "message.title.jenkins_api_case_task_execute_failed") + String JENKINS_API_CASE_TASK_EXECUTE_FAILED = "JENKINS_API_CASE_TASK_EXECUTE_FAILED";//Jenkins执行接口用例失败通知 + @Schema(description = "message.title.jenkins_load_case_task_execute_successful") + String JENKINS_LOAD_CASE_TASK_EXECUTE_SUCCESSFUL = "JENKINS_LOAD_CASE_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行性能用例成功通知 + @Schema(description = "message.title.jenkins_load_case_task_execute_failed") + String JENKINS_LOAD_CASE_TASK_EXECUTE_FAILED = "JENKINS_LOAD_CASE_TASK_EXECUTE_FAILED";//Jenkins执行性能用例失败通知 + @Schema(description = "message.title.jenkins_test_plan_task_execute_successful") + String JENKINS_TEST_PLAN_TASK_EXECUTE_SUCCESSFUL = "JENKINS_TEST_PLAN_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行测试计划成功通知 + @Schema(description = "message.title.jenkins_test_plan_task_execute_failed") + String JENKINS_TEST_PLAN_TASK_EXECUTE_FAILED = "JENKINS_TEST_PLAN_TASK_EXECUTE_FAILED";//Jenkins执行测试计划失败通知 + @Schema(description = "message.title.jenkins_ui_task_execute_successful") + String JENKINS_UI_TASK_EXECUTE_SUCCESSFUL = "JENKINS_UI_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行UI用例成功通知 + @Schema(description = "message.title.jenkins_ui_task_execute_failed") + String JENKINS_UI_TASK_EXECUTE_FAILED = "JENKINS_UI_TASK_EXECUTE_FAILED";//Jenkins执行UI用例失败通知 } interface SensitiveField { diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java index b52e3e7829..6d92dc0de4 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/sender/AbstractNoticeSender.java @@ -1,10 +1,16 @@ package io.metersphere.system.notice.sender; -import io.metersphere.api.domain.*; +import io.metersphere.api.domain.ApiDefinitionFollower; +import io.metersphere.api.domain.ApiDefinitionFollowerExample; +import io.metersphere.api.domain.ApiScenarioFollower; +import io.metersphere.api.domain.ApiScenarioFollowerExample; import io.metersphere.api.mapper.ApiDefinitionFollowerMapper; import io.metersphere.api.mapper.ApiScenarioFollowerMapper; -import io.metersphere.functional.domain.*; +import io.metersphere.functional.domain.CaseReviewFollower; +import io.metersphere.functional.domain.CaseReviewFollowerExample; +import io.metersphere.functional.domain.FunctionalCaseFollower; +import io.metersphere.functional.domain.FunctionalCaseFollowerExample; import io.metersphere.functional.mapper.CaseReviewFollowerMapper; import io.metersphere.functional.mapper.FunctionalCaseFollowerMapper; import io.metersphere.load.domain.LoadTestFollower; @@ -13,11 +19,6 @@ import io.metersphere.load.mapper.LoadTestFollowerMapper; import io.metersphere.plan.domain.TestPlanFollower; import io.metersphere.plan.domain.TestPlanFollowerExample; import io.metersphere.plan.mapper.TestPlanFollowerMapper; -import io.metersphere.system.notice.MessageDetail; -import io.metersphere.system.notice.NoticeModel; -import io.metersphere.system.notice.Receiver; -import io.metersphere.system.notice.constants.NoticeConstants; -import io.metersphere.system.notice.constants.NotificationConstants; import io.metersphere.sdk.util.JSON; import io.metersphere.sdk.util.LogUtils; import io.metersphere.system.domain.CustomField; @@ -25,12 +26,16 @@ import io.metersphere.system.domain.User; import io.metersphere.system.domain.UserExample; import io.metersphere.system.mapper.CustomFieldMapper; import io.metersphere.system.mapper.UserMapper; +import io.metersphere.system.notice.MessageDetail; +import io.metersphere.system.notice.NoticeModel; +import io.metersphere.system.notice.Receiver; +import io.metersphere.system.notice.constants.NoticeConstants; +import io.metersphere.system.notice.constants.NotificationConstants; +import io.metersphere.system.notice.utils.MessageTemplateUtils; import jakarta.annotation.Resource; import org.apache.commons.beanutils.BeanMap; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.time.DateFormatUtils; -import org.apache.commons.text.StringSubstitutor; import java.util.ArrayList; import java.util.List; @@ -63,13 +68,13 @@ public abstract class AbstractNoticeSender implements NoticeSender { noticeModel.setReceivers(getRealUserIds(messageDetail, noticeModel, messageDetail.getEvent())); // 如果配置了模版就直接使用模版 if (StringUtils.isNotBlank(messageDetail.getTemplate())) { - return getContent(messageDetail.getTemplate(), noticeModel.getParamMap()); + return MessageTemplateUtils.getContent(messageDetail.getTemplate(), noticeModel.getParamMap()); } String context = StringUtils.EMPTY; if (StringUtils.isBlank(context)) { context = noticeModel.getContext(); } - return getContent(context, noticeModel.getParamMap()); + return MessageTemplateUtils.getContent(context, noticeModel.getParamMap()); } private void handleCustomFields(NoticeModel noticeModel) { @@ -104,34 +109,6 @@ public abstract class AbstractNoticeSender implements NoticeSender { } } - protected String getContent(String template, Map context) { - // 处理 null - context.forEach((k, v) -> { - if (v == null) { - context.put(k, StringUtils.EMPTY); - } - }); - // 处理时间格式的数据 - handleTime(context); - StringSubstitutor sub = new StringSubstitutor(context); - return sub.replace(template); - } - - private void handleTime(Map context) { - context.forEach((k, v) -> { - if (StringUtils.endsWithIgnoreCase(k, "Time")) { - try { - String value = v.toString(); - long time = Long.parseLong(value); - v = DateFormatUtils.format(time, "yyyy-MM-dd HH:mm:ss"); - context.put(k, v); - } catch (Exception ignore) { - } - } - }); - } - - private List getRealUserIds(MessageDetail messageDetail, NoticeModel noticeModel, String event) { List toUsers = new ArrayList<>(); Map paramMap = noticeModel.getParamMap(); diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java index 819e7bfc12..680793a155 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/notice/utils/MessageTemplateUtils.java @@ -1,9 +1,20 @@ package io.metersphere.system.notice.utils; +import io.metersphere.api.domain.ApiDefinition; +import io.metersphere.api.domain.ApiScenario; +import io.metersphere.bug.domain.Bug; +import io.metersphere.functional.domain.CaseReview; +import io.metersphere.functional.domain.FunctionalCase; +import io.metersphere.load.domain.LoadTest; +import io.metersphere.plan.domain.TestPlan; import io.metersphere.sdk.util.Translator; import io.metersphere.system.notice.constants.NoticeConstants; +import io.metersphere.ui.domain.UiScenario; import io.swagger.v3.oas.annotations.media.Schema; +import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.reflect.FieldUtils; +import org.apache.commons.lang3.time.DateFormatUtils; +import org.apache.commons.text.StringSubstitutor; import java.lang.reflect.Field; import java.util.ArrayList; @@ -86,6 +97,7 @@ public class MessageTemplateUtils { /** * 获取接收人的特殊值 + * * @return List defaultRelatedUsers */ public static List getDefaultRelatedUser() { @@ -99,6 +111,7 @@ public class MessageTemplateUtils { /** * 获取接收人的特殊值 + * * @return List defaultRelatedUsers */ public static Map getDefaultRelatedUserMap() { @@ -108,4 +121,99 @@ public class MessageTemplateUtils { return defaultRelatedUserMap; } + /** + * 获取字段来源 + * @return FieldSourceMap + */ + public static Map getFieldSourceMap() { + Map fieldSourceMap = new HashMap<>(); + Field[] defaultRelatedUserFields = FieldUtils.getAllFields(NoticeConstants.FieldSource.class); + MessageTemplateUtils.setFieldNameMap(defaultRelatedUserFields, fieldSourceMap); + return fieldSourceMap; + } + + public static Field[] getDomainTemplateFields(String taskType) { + Field[] allFields; + switch (taskType) { + case NoticeConstants.TaskType.API_DEFINITION_TASK, NoticeConstants.TaskType.JENKINS_API_CASE_TASK -> { + allFields = FieldUtils.getAllFields(ApiDefinition.class); + + } + case NoticeConstants.TaskType.API_SCENARIO_TASK, NoticeConstants.TaskType.API_SCHEDULE_TASK, NoticeConstants.TaskType.JENKINS_API_SCENARIO_TASK -> { + allFields = FieldUtils.getAllFields(ApiScenario.class); + + } + case NoticeConstants.TaskType.TEST_PLAN_TASK, NoticeConstants.TaskType.JENKINS_TEST_PLAN_TASK -> { + allFields = FieldUtils.getAllFields(TestPlan.class); + + } + case NoticeConstants.TaskType.CASE_REVIEW_TASK -> { + allFields = FieldUtils.getAllFields(CaseReview.class); + } + case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> { + allFields = FieldUtils.getAllFields(FunctionalCase.class); + } + case NoticeConstants.TaskType.BUG_TASK -> { + allFields = FieldUtils.getAllFields(Bug.class); + } + case NoticeConstants.TaskType.UI_SCENARIO_TASK, NoticeConstants.TaskType.JENKINS_UI_TASK -> { + allFields = FieldUtils.getAllFields(UiScenario.class); + } + case NoticeConstants.TaskType.LOAD_TEST_TASK, NoticeConstants.TaskType.JENKINS_LOAD_CASE_TASK -> { + allFields = FieldUtils.getAllFields(LoadTest.class); + } + default -> allFields = new Field[0]; + } + + return allFields; + } + + public static String getContent(String template, Map context) { + // 处理 null + context.forEach((k, v) -> { + if (v == null) { + context.put(k, StringUtils.EMPTY); + } + }); + // 处理时间格式的数据 + handleTime(context); + StringSubstitutor sub = new StringSubstitutor(context); + return sub.replace(template); + } + + public static void handleTime(Map context) { + context.forEach((k, v) -> { + if (StringUtils.endsWithIgnoreCase(k, "Time")) { + try { + String value = v.toString(); + long time = Long.parseLong(value); + v = DateFormatUtils.format(time, "yyyy-MM-dd HH:mm:ss"); + context.put(k, v); + } catch (Exception ignore) { + } + } + }); + } + + public static String getTranslateTemplate(String taskType, String template) { + Field[] domainTemplateFields = getDomainTemplateFields(taskType); + Map map = new HashMap<>(); + if (StringUtils.isNotBlank(template) && template.contains("${OPERATOR}")) { + template = template.replace("${OPERATOR}", "<"+Translator.get("message.operator")+">"); + } + if (StringUtils.isNotBlank(template) && template.contains("${total}")) { + template = template.replace("${total}", ""); + } + for (Field allField : domainTemplateFields) { + Schema annotation = allField.getAnnotation(Schema.class); + if (annotation != null) { + String description = annotation.description(); + if (StringUtils.equals(allField.getName(), "name") || StringUtils.equals(allField.getName(), "title")) { + description = "{{" + description + "}}"; + } + map.put(allField.getName(), description); + } + } + return getContent(template, map); + } } diff --git a/backend/services/system-setting/src/main/java/io/metersphere/system/service/NoticeSendService.java b/backend/services/system-setting/src/main/java/io/metersphere/system/service/NoticeSendService.java index e6d2642b5b..6a72ed2b04 100644 --- a/backend/services/system-setting/src/main/java/io/metersphere/system/service/NoticeSendService.java +++ b/backend/services/system-setting/src/main/java/io/metersphere/system/service/NoticeSendService.java @@ -88,7 +88,7 @@ public class NoticeSendService { messageDetails = messageDetailService.searchMessageByTestId(noticeModel.getTestId()); } else { String projectId = (String) noticeModel.getParamMap().get("projectId"); - messageDetails = messageDetailService.searchMessageByTypeAndProjectId(NoticeConstants.TaskType.JENKINS_TASK, projectId); + messageDetails = messageDetailService.searchMessageByTypeAndProjectId(triggerMode, projectId); } // 异步发送通知 diff --git a/backend/services/system-setting/src/test/java/io/metersphere/system/controller/MessageTemplateUtilsTests.java b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/MessageTemplateUtilsTests.java new file mode 100644 index 0000000000..ff5e0b74e4 --- /dev/null +++ b/backend/services/system-setting/src/test/java/io/metersphere/system/controller/MessageTemplateUtilsTests.java @@ -0,0 +1,51 @@ +package io.metersphere.system.controller; + +import io.metersphere.system.notice.utils.MessageTemplateUtils; +import org.apache.commons.collections.CollectionUtils; +import org.apache.commons.collections.MapUtils; +import org.junit.jupiter.api.*; +import org.junit.platform.commons.util.StringUtils; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; + +import java.lang.reflect.Field; +import java.util.List; +import java.util.Map; +import java.util.Set; + +@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@AutoConfigureMockMvc +@TestMethodOrder(MethodOrderer.OrderAnnotation.class) +public class MessageTemplateUtilsTests { + + @Test + @Order(1) + void getDomainTemplateFieldSuccess() { + Map taskTypeMap = MessageTemplateUtils.getTaskTypeMap(); + Map eventMap = MessageTemplateUtils.getEventMap(); + Set typeList = taskTypeMap.keySet(); + Map defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap(); + Assertions.assertTrue(MapUtils.isNotEmpty(defaultTemplateSubjectMap)); + Map moduleMap = MessageTemplateUtils.getModuleMap(); + Assertions.assertTrue(MapUtils.isNotEmpty(moduleMap)); + List defaultRelatedUser = MessageTemplateUtils.getDefaultRelatedUser(); + Assertions.assertTrue(CollectionUtils.isNotEmpty(defaultRelatedUser)); + Map defaultRelatedUserMap = MessageTemplateUtils.getDefaultRelatedUserMap(); + Assertions.assertTrue(MapUtils.isNotEmpty(defaultRelatedUserMap)); + + for (String type : typeList) { + Field[] domainTemplateFields = MessageTemplateUtils.getDomainTemplateFields(type); + Assertions.assertNotNull(domainTemplateFields); + Map defaultTemplateMap = MessageTemplateUtils.getDefaultTemplateMap(); + eventMap.forEach((event, name) -> { + String template = defaultTemplateMap.get(type + "_" + event); + if (StringUtils.isNotBlank(template)) { + String translateTemplate = MessageTemplateUtils.getTranslateTemplate(type, template); + Assertions.assertTrue(StringUtils.isNotBlank(translateTemplate)); + } + }); + + } + + } +}