refactor(消息管理): 优化返回模版

This commit is contained in:
guoyuqi 2023-10-11 18:54:23 +08:00 committed by f2c-ci-robot[bot]
parent 811b9fd533
commit 1ec38afbe3
22 changed files with 921 additions and 176 deletions

View File

@ -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'); 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'); 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 innodb lock wait timeout to default
SET SESSION innodb_lock_wait_timeout = DEFAULT; SET SESSION innodb_lock_wait_timeout = DEFAULT;

View File

@ -131,7 +131,11 @@ message.api_definition_task=接口文档
message.api_scenario_task=接口场景 message.api_scenario_task=接口场景
message.ui_scenario_task=UI自动化 message.ui_scenario_task=UI自动化
message.load_test_task=测试用例 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.test_plan_management=测试计划
message.bug_management=缺陷管理 message.bug_management=缺陷管理
message.case_management=用例管理 message.case_management=用例管理
@ -160,6 +164,9 @@ message.execute_failed=执行失败
message.create_user=创建人 message.create_user=创建人
message.follow_people=关注人 message.follow_people=关注人
message.operator=操作人 message.operator=操作人
message.custom_field=自定义字段
message.case_field=用例字段
message.report_field=报告字段
message.test_plan_task_create=${OPERATOR}创建了测试计划:${name} message.test_plan_task_create=${OPERATOR}创建了测试计划:${name}
message.test_plan_task_update=${OPERATOR}更新了测试计划:${name} message.test_plan_task_update=${OPERATOR}更新了测试计划:${name}
message.test_plan_task_delete=${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_test_task_execute_completed=${OPERATOR}执行了性能用例:${name}
message.load_schedule_task_execute_completed=${OPERATOR}通过定时任务执行了性能用例:${name} message.load_schedule_task_execute_completed=${OPERATOR}通过定时任务执行了性能用例:${name}
message.load_report_task_delete=${OPERATOR}删除了性能报告:${name} message.load_report_task_delete=${OPERATOR}删除了性能报告:${name}
message.jenkins_task_execute_successful=Jenkins执行了场景用例:${name} message.jenkins_api_scenario_task_execute=Jenkins执行了接口场景:${name}
message.jenkins_task_execute_failed=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_create=测试计划创建通知
message.title.test_plan_task_update=测试计划更新通知 message.title.test_plan_task_update=测试计划更新通知
message.title.test_plan_task_delete=测试计划删除通知 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_delete=性能用例删除通知
message.title.load_test_task_execute_completed=性能用例执行完成通知 message.title.load_test_task_execute_completed=性能用例执行完成通知
message.title.load_report_task_delete=性能报告删除通知 message.title.load_report_task_delete=性能报告删除通知
message.title.jenkins_task_execute_successful=Jenkins任务执行成功通知 message.title.jenkins_api_scenario_task_execute_successful=Jenkins执行接口场景成功通知
message.title.jenkins_task_execute_failed=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 management
file_module.not.exist=文件模块不存在 file_module.not.exist=文件模块不存在

View File

@ -164,7 +164,11 @@ message.api_definition_task=API documentation
message.api_scenario_task=API scenario message.api_scenario_task=API scenario
message.ui_scenario_task=UI automation message.ui_scenario_task=UI automation
message.load_test_task=Test case 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.test_plan_management=Test Plan
message.bug_management=Bug management message.bug_management=Bug management
message.case_management=Case management message.case_management=Case management
@ -193,6 +197,9 @@ message.execute_failed=Execution failed
message.create_user=Create user message.create_user=Create user
message.follow_people=Follow people message.follow_people=Follow people
message.operator=Operator 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_create=${OPERATOR}created the test plan: ${name}
message.test_plan_task_update=${OPERATOR}updated 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} 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_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_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.load_report_task_delete=${OPERATOR}deleted load report: ${name}
message.jenkins_task_execute_successful=Jenkins executed the API scenario: ${name} message.jenkins_api_scenario_task_execute=Jenkins executed the API scenario:${name}
message.jenkins_task_execute_failed=Jenkins executed the test plan: ${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_create=Test plan creation notification
message.title.test_plan_task_update=Test plan update notification message.title.test_plan_task_update=Test plan update notification
message.title.test_plan_task_delete=Test plan deletion 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.load_report_task_delete=Load report deletion notification
message.title.jenkins_task_execute_successful=Jenkins task execution success 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_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 resource_pool_not_exist=Resource pool does not exist

View File

@ -164,7 +164,11 @@ message.api_definition_task=接口文档
message.api_scenario_task=接口场景 message.api_scenario_task=接口场景
message.ui_scenario_task=UI自动化 message.ui_scenario_task=UI自动化
message.load_test_task=测试用例 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.test_plan_management=测试计划
message.bug_management=缺陷管理 message.bug_management=缺陷管理
message.case_management=用例管理 message.case_management=用例管理
@ -193,6 +197,9 @@ message.execute_failed=执行失败
message.create_user=创建人 message.create_user=创建人
message.follow_people=关注人 message.follow_people=关注人
message.operator=操作人 message.operator=操作人
message.custom_field=自定义字段
message.case_field=用例字段
message.report_field=报告字段
message.test_plan_task_create=${OPERATOR}创建了测试计划:${name} message.test_plan_task_create=${OPERATOR}创建了测试计划:${name}
message.test_plan_task_update=${OPERATOR}更新了测试计划:${name} message.test_plan_task_update=${OPERATOR}更新了测试计划:${name}
message.test_plan_task_delete=${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_test_task_execute_completed=${OPERATOR}执行了性能用例:${name}
message.load_schedule_task_execute_completed=${OPERATOR}通过定时任务执行了性能用例:${name} message.load_schedule_task_execute_completed=${OPERATOR}通过定时任务执行了性能用例:${name}
message.load_report_task_delete=${OPERATOR}删除了性能报告:${name} message.load_report_task_delete=${OPERATOR}删除了性能报告:${name}
message.jenkins_task_execute_successful=Jenkins执行了场景用例:${name} message.jenkins_api_scenario_task_execute=Jenkins执行了接口场景:${name}
message.jenkins_task_execute_failed=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_create=测试计划创建通知
message.title.test_plan_task_update=测试计划更新通知 message.title.test_plan_task_update=测试计划更新通知
message.title.test_plan_task_delete=测试计划删除通知 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_delete=性能用例删除通知
message.title.load_test_task_execute_completed=性能用例执行完成通知 message.title.load_test_task_execute_completed=性能用例执行完成通知
message.title.load_report_task_delete=性能报告删除通知 message.title.load_report_task_delete=性能报告删除通知
message.title.jenkins_task_execute_successful=Jenkins任务执行成功通知 message.title.jenkins_api_scenario_task_execute_successful=Jenkins执行接口场景成功通知
message.title.jenkins_task_execute_failed=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=资源池不存在 resource_pool_not_exist=资源池不存在
#file management #file management

View File

@ -165,7 +165,11 @@ message.api_definition_task=介面文檔
message.api_scenario_task=介面場景 message.api_scenario_task=介面場景
message.ui_scenario_task=UI自動化 message.ui_scenario_task=UI自動化
message.load_test_task=測試用例 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.test_plan_management=測試計劃
message.bug_management=缺陷管理 message.bug_management=缺陷管理
message.case_management=用例管理 message.case_management=用例管理
@ -194,6 +198,9 @@ message.execute_failed=執行失敗
message.create_user=創建人 message.create_user=創建人
message.follow_people=關注人 message.follow_people=關注人
message.operator=操作人 message.operator=操作人
message.custom_field=自訂字段
message.case_field=用例字段
message.report_field=報告字段
message.test_plan_task_create=${OPERATOR}創建了測試計劃:${name} message.test_plan_task_create=${OPERATOR}創建了測試計劃:${name}
message.test_plan_task_update=${OPERATOR}更新了測試計劃:${name} message.test_plan_task_update=${OPERATOR}更新了測試計劃:${name}
message.test_plan_task_delete=${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_test_task_execute_completed=${OPERATOR}執行了性能用例:${name}
message.load_schedule_task_execute_completed=${OPERATOR}透過定時任務執行了性能用例:${name} message.load_schedule_task_execute_completed=${OPERATOR}透過定時任務執行了性能用例:${name}
message.load_report_task_delete=${OPERATOR}删除了性能報告:${name} message.load_report_task_delete=${OPERATOR}删除了性能報告:${name}
message.jenkins_task_execute_successful=Jenkins執行了场景用例:${name} message.jenkins_api_scenario_task_execute=Jenkins執行了介面場景:${name}
message.jenkins_task_execute_failed=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_create=測試計劃創建通知
message.title.test_plan_task_update=測試計劃更新通知 message.title.test_plan_task_update=測試計劃更新通知
message.title.test_plan_task_delete=測試計劃删除通知 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_delete=性能用例删除通知
message.title.load_test_task_execute_completed=性能用例執行完成通知 message.title.load_test_task_execute_completed=性能用例執行完成通知
message.title.load_report_task_delete=性能報告删除通知 message.title.load_report_task_delete=性能報告删除通知
message.title.jenkins_task_execute_successful=Jenkins任務執行成功通知 message.title.jenkins_api_scenario_task_execute_successful=Jenkins執行介面場景成功通知
message.title.jenkins_task_execute_failed=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=資源池不存在 resource_pool_not_exist=資源池不存在
#file management #file management
file_module.not.exist=文件模塊不存在 file_module.not.exist=文件模塊不存在

View File

@ -1,9 +1,9 @@
package io.metersphere.project.controller; package io.metersphere.project.controller;
import io.metersphere.project.dto.MessageTemplateResultDTO;
import io.metersphere.project.service.NoticeTemplateService; import io.metersphere.project.service.NoticeTemplateService;
import io.metersphere.sdk.constants.PermissionConstants; 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.Operation;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag; import io.swagger.v3.oas.annotations.tags.Tag;
@ -23,7 +23,7 @@ public class NoticeTemplateController {
@GetMapping("get/fields/{projectId}") @GetMapping("get/fields/{projectId}")
@Operation(summary = "项目管理-消息设置-模版设置-获取消息模版字段") @Operation(summary = "项目管理-消息设置-模版设置-获取消息模版字段")
@RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ) @RequiresPermissions(PermissionConstants.PROJECT_MESSAGE_READ)
public List<OptionDTO> getTemplateFields(@PathVariable String projectId, @Schema(description = "消息配置功能类型") public MessageTemplateResultDTO getTemplateFields(@PathVariable String projectId, @Schema(description = "消息配置功能类型")
@RequestParam(value = "taskType") String taskType) { @RequestParam(value = "taskType") String taskType) {
return noticeTemplateService.getTemplateFields(projectId, taskType); return noticeTemplateService.getTemplateFields(projectId, taskType);
} }

View File

@ -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;
}

View File

@ -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<OptionDTO> fieldSourceList;
@Schema(description = "字段列表")
public List<MessageTemplateFieldDTO> fieldList;
}

View File

@ -46,4 +46,10 @@ public class ProjectRobotConfigDTO implements Serializable {
@Schema(description = "机器人是否使用默认标题") @Schema(description = "机器人是否使用默认标题")
public Boolean useDefaultSubject; public Boolean useDefaultSubject;
@Schema(description = "机器人预览标题")
public String previewSubject;
@Schema(description = "机器人预览模版")
public String previewTemplate;
} }

View File

@ -98,7 +98,7 @@ public class CreateRobotResourceService implements CreateProjectResourceService
List<MessageTaskTypeDTO> messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList(); List<MessageTaskTypeDTO> messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList();
for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) { for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) {
String taskType = messageTaskTypeDTO.getTaskType(); 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; continue;
} }
List<MessageTaskDetailDTO> messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList(); List<MessageTaskDetailDTO> messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList();

View File

@ -170,6 +170,7 @@ public class NoticeMessageTaskService {
messageTaskExample.createCriteria().andReceiverIn(existUserIds).andProjectIdEqualTo(messageTaskRequest.getProjectId()) messageTaskExample.createCriteria().andReceiverIn(existUserIds).andProjectIdEqualTo(messageTaskRequest.getProjectId())
.andProjectRobotIdEqualTo(messageTaskRequest.getRobotId()).andTaskTypeEqualTo(messageTaskRequest.getTaskType()).andEventEqualTo(messageTaskRequest.getEvent()); .andProjectRobotIdEqualTo(messageTaskRequest.getRobotId()).andTaskTypeEqualTo(messageTaskRequest.getTaskType()).andEventEqualTo(messageTaskRequest.getEvent());
List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample); List<MessageTask> messageTasks = messageTaskMapper.selectByExample(messageTaskExample);
List<String> messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList();
if (CollectionUtils.isEmpty(messageTasks)) { if (CollectionUtils.isEmpty(messageTasks)) {
return new ArrayList<>(); return new ArrayList<>();
} }
@ -184,7 +185,6 @@ public class NoticeMessageTaskService {
} }
mapper.updateByPrimaryKeySelective(messageTask); mapper.updateByPrimaryKeySelective(messageTask);
} }
List<String> messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList();
MessageTaskBlobExample messageTaskBlobExample = new MessageTaskBlobExample(); MessageTaskBlobExample messageTaskBlobExample = new MessageTaskBlobExample();
messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds); messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds);
List<MessageTaskBlob> messageTaskBlobs = messageTaskBlobMapper.selectByExample(messageTaskBlobExample); List<MessageTaskBlob> messageTaskBlobs = messageTaskBlobMapper.selectByExample(messageTaskBlobExample);
@ -302,7 +302,7 @@ public class NoticeMessageTaskService {
List<String> messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList(); List<String> messageTaskIds = messageTasks.stream().map(MessageTask::getId).toList();
MessageTaskBlobExample messageTaskBlobExample = new MessageTaskBlobExample(); MessageTaskBlobExample messageTaskBlobExample = new MessageTaskBlobExample();
messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds); messageTaskBlobExample.createCriteria().andIdIn(messageTaskIds);
List<MessageTaskBlob> messageTaskBlobs = messageTaskBlobMapper.selectByExample(messageTaskBlobExample); List<MessageTaskBlob> messageTaskBlobs = messageTaskBlobMapper.selectByExampleWithBLOBs(messageTaskBlobExample);
List<String> robotIds = messageTasks.stream().map(MessageTask::getProjectRobotId).toList(); List<String> robotIds = messageTasks.stream().map(MessageTask::getProjectRobotId).toList();
ProjectRobotExample projectRobotExample = new ProjectRobotExample(); ProjectRobotExample projectRobotExample = new ProjectRobotExample();
projectRobotExample.createCriteria().andIdIn(robotIds); projectRobotExample.createCriteria().andIdIn(robotIds);
@ -343,7 +343,7 @@ public class NoticeMessageTaskService {
String defaultTemplate = defaultTemplateMap.get(messageTaskTypeDTO.getTaskType() + "_" + messageTaskDetailDTO.getEvent()); String defaultTemplate = defaultTemplateMap.get(messageTaskTypeDTO.getTaskType() + "_" + messageTaskDetailDTO.getEvent());
if (CollectionUtils.isEmpty(messageTaskList)) { if (CollectionUtils.isEmpty(messageTaskList)) {
String defaultSubject = defaultTemplateSubjectMap.get(messageTaskTypeDTO.getTaskType() + "_" + messageTaskDetailDTO.getEvent()); 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); projectRobotConfigMap.put(projectRobot.getId(), projectRobotConfigDTO);
} else { } else {
for (MessageTask messageTask : messageTaskList) { for (MessageTask messageTask : messageTaskList) {
@ -379,33 +379,57 @@ public class NoticeMessageTaskService {
projectRobotConfigDTO.setPlatform(projectRobot.getPlatform()); projectRobotConfigDTO.setPlatform(projectRobot.getPlatform());
projectRobotConfigDTO.setDingType(projectRobot.getType()); projectRobotConfigDTO.setDingType(projectRobot.getType());
projectRobotConfigDTO.setEnable(messageTask.getEnable()); 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.setDefaultTemplate(defaultTemplate);
projectRobotConfigDTO.setSubject(messageTask.getSubject());
projectRobotConfigDTO.setDefaultSubject(defaultSubject); projectRobotConfigDTO.setDefaultSubject(defaultSubject);
projectRobotConfigDTO.setUseDefaultSubject(messageTask.getUseDefaultSubject()); projectRobotConfigDTO.setUseDefaultSubject(messageTask.getUseDefaultSubject());
projectRobotConfigDTO.setUseDefaultTemplate(messageTask.getUseDefaultTemplate()); projectRobotConfigDTO.setUseDefaultTemplate(messageTask.getUseDefaultTemplate());
return projectRobotConfigDTO; 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 projectRobotConfigDTO = new ProjectRobotConfigDTO();
projectRobotConfigDTO.setRobotId(projectRobot.getId()); projectRobotConfigDTO.setRobotId(projectRobot.getId());
projectRobotConfigDTO.setRobotName(projectRobot.getName()); projectRobotConfigDTO.setRobotName(projectRobot.getName());
projectRobotConfigDTO.setPlatform(ProjectRobotPlatform.IN_SITE.toString()); projectRobotConfigDTO.setPlatform(ProjectRobotPlatform.IN_SITE.toString());
projectRobotConfigDTO.setDingType(projectRobot.getType()); projectRobotConfigDTO.setDingType(projectRobot.getType());
projectRobotConfigDTO.setEnable(false); projectRobotConfigDTO.setEnable(false);
projectRobotConfigDTO.setTemplate(""); projectRobotConfigDTO.setTemplate(defaultTemplate);
projectRobotConfigDTO.setDefaultTemplate(defaultTemplate); projectRobotConfigDTO.setDefaultTemplate(defaultTemplate);
projectRobotConfigDTO.setSubject(""); projectRobotConfigDTO.setSubject(defaultSubject);
projectRobotConfigDTO.setDefaultSubject(defaultSubject); projectRobotConfigDTO.setDefaultSubject(defaultSubject);
projectRobotConfigDTO.setUseDefaultSubject(true); projectRobotConfigDTO.setUseDefaultSubject(true);
projectRobotConfigDTO.setUseDefaultTemplate(true); projectRobotConfigDTO.setUseDefaultTemplate(true);
String translateTemplate = MessageTemplateUtils.getTranslateTemplate(taskType, defaultTemplate);
String translateSubject = MessageTemplateUtils.getTranslateTemplate(taskType, defaultSubject);
projectRobotConfigDTO.setPreviewTemplate(translateTemplate);
projectRobotConfigDTO.setPreviewSubject(translateSubject);
return projectRobotConfigDTO; return projectRobotConfigDTO;
} }
public List<OptionDTO> getUserList(String projectId, String keyword) { public List<OptionDTO> getUserList(String projectId, String keyword) {
return extProjectUserRoleMapper.getProjectUserSelectList(projectId, keyword); List<OptionDTO> projectUserSelectList = extProjectUserRoleMapper.getProjectUserSelectList(projectId, keyword);
Map<String, String> 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) { 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); ProjectRobotConfigDTO projectRobotConfigDTO = getProjectRobotConfigDTO(defaultTemplate, defaultSubject, projectRobot, messageTask, messageTaskBlob);
MessageTemplateConfigDTO messageTemplateConfigDTO = new MessageTemplateConfigDTO(); MessageTemplateConfigDTO messageTemplateConfigDTO = new MessageTemplateConfigDTO();
BeanUtils.copyBean(messageTemplateConfigDTO,projectRobotConfigDTO); BeanUtils.copyBean(messageTemplateConfigDTO, projectRobotConfigDTO);
Map<String, String> taskTypeMap = MessageTemplateUtils.getTaskTypeMap(); Map<String, String> taskTypeMap = MessageTemplateUtils.getTaskTypeMap();
Map<String, String> eventMap = MessageTemplateUtils.getEventMap(); Map<String, String> eventMap = MessageTemplateUtils.getEventMap();
messageTemplateConfigDTO.setTaskTypeName(taskTypeMap.get(messageTask.getTaskType())); messageTemplateConfigDTO.setTaskTypeName(taskTypeMap.get(messageTask.getTaskType()));

View File

@ -2,17 +2,22 @@ package io.metersphere.project.service;
import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.domain.ApiDefinition;
import io.metersphere.api.domain.ApiScenario; import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.bug.domain.Bug; import io.metersphere.bug.domain.Bug;
import io.metersphere.functional.domain.CaseReview; import io.metersphere.functional.domain.CaseReview;
import io.metersphere.functional.domain.FunctionalCase; import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.load.domain.LoadTest; import io.metersphere.load.domain.LoadTest;
import io.metersphere.plan.domain.TestPlan; 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.constants.TemplateScene;
import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.util.Translator;
import io.metersphere.system.domain.CustomField; import io.metersphere.system.domain.CustomField;
import io.metersphere.system.domain.CustomFieldExample; import io.metersphere.system.domain.CustomFieldExample;
import io.metersphere.system.mapper.CustomFieldMapper; import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.notice.utils.MessageTemplateUtils;
import io.metersphere.ui.domain.UiScenario; import io.metersphere.ui.domain.UiScenario;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
@ -25,6 +30,7 @@ import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.Map;
@Service @Service
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
@ -33,100 +39,133 @@ public class NoticeTemplateService {
@Resource @Resource
protected CustomFieldMapper customFieldMapper; protected CustomFieldMapper customFieldMapper;
public List<OptionDTO> getTemplateFields(String projectId, String taskType) { public List<MessageTemplateFieldDTO> getDomainTemplateFields(String projectId, String taskType) {
List<OptionDTO> optionDTOList = new ArrayList<>(); List<MessageTemplateFieldDTO> messageTemplateFieldDTOList = new ArrayList<>();
switch (taskType) { 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); Field[] allFields = FieldUtils.getAllFields(ApiDefinition.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
addCustomFiled(optionDTOList, projectId, TemplateScene.API.toString()); Field[] allCaseFields = FieldUtils.getAllFields(ApiTestCase.class);
addOptionDto(messageTemplateFieldDTOList, allCaseFields);
addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.API.toString());
//TODO获取报告 //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); Field[] allFields = FieldUtils.getAllFields(ApiScenario.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
//TODO获取报告 //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); Field[] allFields = FieldUtils.getAllFields(TestPlan.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
addCustomFiled(optionDTOList, projectId, TemplateScene.TEST_PLAN.toString()); addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.TEST_PLAN.toString());
//TODO获取报告 //TODO获取报告
} }
case NoticeConstants.TaskType.CASE_REVIEW_TASK -> { case NoticeConstants.TaskType.CASE_REVIEW_TASK -> {
Field[] allFields = FieldUtils.getAllFields(CaseReview.class); Field[] allFields = FieldUtils.getAllFields(CaseReview.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
//TODO获取报告 //TODO获取报告
} }
case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> { case NoticeConstants.TaskType.FUNCTIONAL_CASE_TASK -> {
Field[] allFields = FieldUtils.getAllFields(FunctionalCase.class); Field[] allFields = FieldUtils.getAllFields(FunctionalCase.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
addCustomFiled(optionDTOList, projectId, TemplateScene.FUNCTIONAL.toString()); addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.FUNCTIONAL.toString());
//TODO获取报告 //TODO获取报告
} }
case NoticeConstants.TaskType.BUG_TASK -> { case NoticeConstants.TaskType.BUG_TASK -> {
Field[] allFields = FieldUtils.getAllFields(Bug.class); Field[] allFields = FieldUtils.getAllFields(Bug.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
addCustomFiled(optionDTOList, projectId, TemplateScene.BUG.toString()); addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.BUG.toString());
//TODO获取报告 //TODO获取报告
} }
case NoticeConstants.TaskType.UI_SCENARIO_TASK -> { case NoticeConstants.TaskType.UI_SCENARIO_TASK, NoticeConstants.TaskType.JENKINS_UI_TASK -> {
Field[] allFields = FieldUtils.getAllFields(UiScenario.class); Field[] allFields = FieldUtils.getAllFields(UiScenario.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
addCustomFiled(optionDTOList, projectId, TemplateScene.UI.toString()); addCustomFiled(messageTemplateFieldDTOList, projectId, TemplateScene.UI.toString());
//TODO获取报告 //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); Field[] allFields = FieldUtils.getAllFields(LoadTest.class);
addOptionDto(optionDTOList, allFields); addOptionDto(messageTemplateFieldDTOList, allFields);
//TODO获取报告 //TODO获取报告
} }
default -> optionDTOList = new ArrayList<>(); default -> messageTemplateFieldDTOList = new ArrayList<>();
} }
return optionDTOList;
return messageTemplateFieldDTOList;
} }
/** /**
* 添加自定义字段 * 添加自定义字段
* @param optionDTOList optionDTOList *
* @param projectId projectId * @param messageTemplateFieldDTOS messageTemplateFieldDTOS
* @param scene 对应场景 * @param projectId projectId
* @param scene 对应场景
*/ */
private void addCustomFiled(List<OptionDTO> optionDTOList, String projectId, String scene) { private void addCustomFiled(List<MessageTemplateFieldDTO> messageTemplateFieldDTOS, String projectId, String scene) {
CustomFieldExample example = new CustomFieldExample(); CustomFieldExample example = new CustomFieldExample();
example.createCriteria().andScopeIdEqualTo(projectId).andSceneEqualTo(scene); example.createCriteria().andScopeIdEqualTo(projectId).andSceneEqualTo(scene);
List<CustomField> customFields = customFieldMapper.selectByExample(example); List<CustomField> customFields = customFieldMapper.selectByExample(example);
for (CustomField customField : customFields) { for (CustomField customField : customFields) {
OptionDTO optionDTO = new OptionDTO(); MessageTemplateFieldDTO messageTemplateFieldDTO = new MessageTemplateFieldDTO();
optionDTO.setId(customField.getName()); messageTemplateFieldDTO.setId(customField.getName());
optionDTO.setName(StringUtils.isBlank(customField.getRemark()) ? "-" : customField.getRemark()); messageTemplateFieldDTO.setName(StringUtils.isBlank(customField.getRemark()) ? "-" : customField.getRemark());
optionDTOList.add(optionDTO); 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<OptionDTO> optionDTOList, Field[] allFields) { private static void addOptionDto(List<MessageTemplateFieldDTO> messageTemplateFieldDTOS, Field[] allFields) {
Field[] sensitiveFields = FieldUtils.getAllFields(NoticeConstants.SensitiveField.class); Field[] sensitiveFields = FieldUtils.getAllFields(NoticeConstants.SensitiveField.class);
ArrayList<Field> sensitiveFieldList = new ArrayList<>(sensitiveFields.length); ArrayList<Field> sensitiveFieldList = new ArrayList<>(sensitiveFields.length);
Collections.addAll(sensitiveFieldList, sensitiveFields); Collections.addAll(sensitiveFieldList, sensitiveFields);
List<String> nameList = sensitiveFieldList.stream().map(Field::getName).toList(); List<String> nameList = sensitiveFieldList.stream().map(Field::getName).toList();
for (Field allField : allFields) { for (Field allField : allFields) {
OptionDTO optionDTO = new OptionDTO(); MessageTemplateFieldDTO messageTemplateFieldDTO = new MessageTemplateFieldDTO();
if (nameList.contains(allField.getName())) { if (nameList.contains(allField.getName())) {
continue; continue;
} }
optionDTO.setId(allField.getName());
Schema annotation = allField.getAnnotation(Schema.class); Schema annotation = allField.getAnnotation(Schema.class);
if (annotation != null) { if (annotation != null) {
messageTemplateFieldDTO.setId(allField.getName());
String description = annotation.description(); String description = annotation.description();
optionDTO.setName(description); messageTemplateFieldDTO.setName(description);
optionDTOList.add(optionDTO); 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<MessageTemplateFieldDTO> domainTemplateFields = getDomainTemplateFields(projectId, taskType);
messageTemplateResultDTO.setFieldList(domainTemplateFields);
Map<String, String> fieldSourceMap = MessageTemplateUtils.getFieldSourceMap();
List<OptionDTO> 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;
}
} }

View File

@ -985,32 +985,32 @@
"useDefaultSubject":true "useDefaultSubject":true
} }
] ]
}, }
]
},
{
"taskType":"UI_REPORT_TASK",
"taskTypeName":"",
"messageTaskDetailDTOList":[
{ {
"taskType":"UI_REPORT_TASK", "event":"DELETE",
"taskTypeName":"", "eventName":"",
"messageTaskDetailDTOList":[ "receivers":[
{ {
"event":"DELETE", "id": "CREATE_USER",
"eventName":"", "name": ""
"receivers":[ }
{ ],
"id": "CREATE_USER", "projectRobotConfigList":[
"name": "" {
} "robotId":"",
], "enable":"",
"projectRobotConfigList":[ "template":"",
{ "defaultTemplate":"",
"robotId":"", "useDefaultTemplate":true,
"enable":"", "subject":"",
"template":"", "defaultSubject":"",
"defaultTemplate":"", "useDefaultSubject":true
"useDefaultTemplate":true,
"subject":"",
"defaultSubject":"",
"useDefaultSubject":true
}
]
} }
] ]
} }
@ -1153,7 +1153,7 @@
"name":"", "name":"",
"messageTaskTypeDTOList":[ "messageTaskTypeDTOList":[
{ {
"taskType":"JENKINS_TASK", "taskType":"JENKINS_UI_TASK",
"taskTypeName":"", "taskTypeName":"",
"messageTaskDetailDTOList":[ "messageTaskDetailDTOList":[
{ {
@ -1161,8 +1161,8 @@
"eventName":"", "eventName":"",
"receivers":[ "receivers":[
{ {
"id": "", "id":"",
"name": "" "name":""
} }
], ],
"projectRobotConfigList":[ "projectRobotConfigList":[
@ -1183,8 +1183,208 @@
"eventName":"", "eventName":"",
"receivers":[ "receivers":[
{ {
"id": "", "id":"",
"name": "" "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":[ "projectRobotConfigList":[

View File

@ -4,11 +4,7 @@ package io.metersphere.project.controller;
import io.metersphere.project.domain.MessageTask; import io.metersphere.project.domain.MessageTask;
import io.metersphere.project.domain.MessageTaskBlob; import io.metersphere.project.domain.MessageTaskBlob;
import io.metersphere.project.domain.MessageTaskExample; import io.metersphere.project.domain.MessageTaskExample;
import io.metersphere.project.dto.MessageTaskDTO; import io.metersphere.project.dto.*;
import io.metersphere.project.dto.MessageTaskDetailDTO;
import io.metersphere.project.dto.MessageTemplateConfigDTO;
import io.metersphere.project.dto.ProjectRobotConfigDTO;
import io.metersphere.project.mapper.MessageTaskBlobMapper; import io.metersphere.project.mapper.MessageTaskBlobMapper;
import io.metersphere.project.mapper.MessageTaskMapper; import io.metersphere.project.mapper.MessageTaskMapper;
import io.metersphere.sdk.constants.SessionConstants; 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.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder; import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.system.uid.UUID;
import jakarta.annotation.Resource; import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils; 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.junit.jupiter.api.*;
import org.mybatis.spring.SqlSessionUtils;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType; 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.MvcResult;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; 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.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.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@SpringBootTest(webEnvironment= SpringBootTest.WebEnvironment.RANDOM_PORT) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureMockMvc @AutoConfigureMockMvc
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class NoticeMessageTaskControllerTests extends BaseTest { public class NoticeMessageTaskControllerTests extends BaseTest {
@ -47,6 +55,9 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
@Resource @Resource
private MessageTaskBlobMapper messageTaskBlobMapper; private MessageTaskBlobMapper messageTaskBlobMapper;
@Resource
private SqlSessionFactory sqlSessionFactory;
@Test @Test
@Order(1) @Order(1)
@Sql(scripts = {"/dml/init_project_message.sql"}, config = @SqlConfig(encoding = "utf-8", transactionMode = SqlConfig.TransactionMode.ISOLATED)) @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.setUseDefaultTemplate(false);
messageTaskRequest.setSubject("测试新加数据模版标题生效"); messageTaskRequest.setSubject("测试新加数据模版标题生效");
messageTaskRequest.setUseDefaultSubject(false); 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.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
.content(JSON.toJSONString(messageTaskRequest)) .content(JSON.toJSONString(messageTaskRequest))
@ -239,7 +250,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
public void addMessageTaskCheckProjectExistFail() throws Exception { public void addMessageTaskCheckProjectExistFail() throws Exception {
//项目不存在 //项目不存在
MessageTaskRequest messageTaskRequest = new MessageTaskRequest(); MessageTaskRequest messageTaskRequest = new MessageTaskRequest();
messageTaskRequest.setProjectId("project-message-test-3"); messageTaskRequest.setProjectId("project-message-test-x");
messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK); messageTaskRequest.setTaskType(NoticeConstants.TaskType.API_DEFINITION_TASK);
messageTaskRequest.setEvent(NoticeConstants.Event.CREATE); messageTaskRequest.setEvent(NoticeConstants.Event.CREATE);
List<String> userIds = new ArrayList<>(); List<String> userIds = new ArrayList<>();
@ -260,7 +271,8 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
@Test @Test
@Order(8) @Order(8)
public void getMessageListSuccess() throws Exception { 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.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)) .header(SessionConstants.CSRF_TOKEN, csrfToken))
.andExpect(status().isOk()) .andExpect(status().isOk())
@ -270,12 +282,13 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
List<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class); List<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class);
System.out.println(messageTaskDetailDTOList); System.out.println(messageTaskDetailDTOList);
Assertions.assertTrue(CollectionUtils.isNotEmpty(messageTaskDetailDTOList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(messageTaskDetailDTOList));
System.out.println(messageTaskDetailDTOList);
} }
@Test @Test
@Order(9) @Order(9)
public void getMessageListProjectFail() throws Exception { 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.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken)) .header(SessionConstants.CSRF_TOKEN, csrfToken))
.andExpect(status().is5xxServerError()) .andExpect(status().is5xxServerError())
@ -296,7 +309,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
MessageTaskDetailDTO messageTaskDetailDTO = messageTaskDetailDTOList.get(0).getMessageTaskTypeDTOList().get(0).getMessageTaskDetailDTOList().get(0); MessageTaskDetailDTO messageTaskDetailDTO = messageTaskDetailDTOList.get(0).getMessageTaskTypeDTOList().get(0).getMessageTaskDetailDTOList().get(0);
Map<String, ProjectRobotConfigDTO> projectRobotConfigMap = messageTaskDetailDTO.getProjectRobotConfigMap(); Map<String, ProjectRobotConfigDTO> projectRobotConfigMap = messageTaskDetailDTO.getProjectRobotConfigMap();
System.out.println(projectRobotConfigMap); 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.setReceiverIds(userIds);
messageTaskRequest.setRobotId("test_message_robot2"); messageTaskRequest.setRobotId("test_message_robot2");
messageTaskRequest.setEnable(true); messageTaskRequest.setEnable(true);
// messageTaskRequest.setDefaultTemplate("发送消息测试"); // messageTaskRequest.setDefaultTemplate("发送消息测试");
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.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
@ -414,6 +427,31 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
@Test @Test
@Order(15) @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<MessageTaskDTO> messageTaskDetailDTOList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), MessageTaskDTO.class);
System.out.println(messageTaskDetailDTOList);
Assertions.assertTrue(CollectionUtils.isNotEmpty(messageTaskDetailDTOList));
System.out.println(messageTaskDetailDTOList);
List<MessageTaskDTO> collect = messageTaskDetailDTOList.stream().filter(t -> t.type.equals(NoticeConstants.Module.API_TEST_MANAGEMENT)).toList();
List<MessageTaskTypeDTO> messageTaskTypeDTOList = collect.get(0).getMessageTaskTypeDTOList();
List<MessageTaskTypeDTO> collect1 = messageTaskTypeDTOList.stream().filter(t -> t.getTaskType().equals(NoticeConstants.TaskType.API_DEFINITION_TASK)).toList();
List<MessageTaskDetailDTO> messageTaskDetailDTOList1 = collect1.get(0).getMessageTaskDetailDTOList();
List<MessageTaskDetailDTO> collect2 = messageTaskDetailDTOList1.stream().filter(t -> t.event.equals(NoticeConstants.Event.CREATE)).toList();
Map<String, ProjectRobotConfigDTO> 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 { public void closeMessageTaskSuccess() throws Exception {
MessageTaskRequest messageTaskRequest = new MessageTaskRequest(); MessageTaskRequest messageTaskRequest = new MessageTaskRequest();
messageTaskRequest.setProjectId("project-message-test"); messageTaskRequest.setProjectId("project-message-test");
@ -439,7 +477,7 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
} }
@Test @Test
@Order(16) @Order(17)
public void getUserSuccess() throws Exception { public void getUserSuccess() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -451,11 +489,11 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(userDtoList.size()>0); Assertions.assertTrue(userDtoList.size() > 0);
} }
@Test @Test
@Order(17) @Order(18)
public void getUserSuccessAll() throws Exception { public void getUserSuccessAll() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -466,12 +504,12 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertTrue(userDtoList.size()>0); Assertions.assertTrue(userDtoList.size() > 0);
} }
@Test @Test
@Order(18) @Order(19)
public void getUserSuccessEmpty() throws Exception { public void getUserSuccessEmpty() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test-x") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/task/get/user/project-message-test-x")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -482,11 +520,11 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); List<OptionDTO> userDtoList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class);
Assertions.assertEquals(0, userDtoList.size()); Assertions.assertEquals(3, userDtoList.size());
} }
@Test @Test
@Order(19) @Order(20)
public void getTemplateDetailWithRobot() throws Exception { public void getTemplateDetailWithRobot() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -500,11 +538,11 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
MessageTemplateConfigDTO messageTemplateConfigDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateConfigDTO.class); MessageTemplateConfigDTO messageTemplateConfigDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateConfigDTO.class);
Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size()>0); Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size() > 0);
} }
@Test @Test
@Order(20) @Order(21)
public void getTemplateDetailWithOutRobot() throws Exception { public void getTemplateDetailWithOutRobot() throws Exception {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/message/template/detail/project-message-test")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -518,13 +556,13 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
MessageTemplateConfigDTO messageTemplateConfigDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateConfigDTO.class); MessageTemplateConfigDTO messageTemplateConfigDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateConfigDTO.class);
Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size()>0); Assertions.assertTrue(messageTemplateConfigDTO.getReceiverIds().size() > 0);
} }
@Test @Test
@Order(21) @Order(22)
public void getTemplateDetailNotExistRobot() throws Exception { 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.HEADER_TOKEN, sessionId)
.header(SessionConstants.CSRF_TOKEN, csrfToken) .header(SessionConstants.CSRF_TOKEN, csrfToken)
.param("taskType", NoticeConstants.TaskType.API_DEFINITION_TASK) .param("taskType", NoticeConstants.TaskType.API_DEFINITION_TASK)
@ -534,4 +572,69 @@ public class NoticeMessageTaskControllerTests extends BaseTest {
.andExpect(status().is5xxServerError()) .andExpect(status().is5xxServerError())
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .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<MessageTaskDTO> messageTaskDTOList = JSON.parseArray(jsonStr.toString(), MessageTaskDTO.class);
for (MessageTaskDTO messageTaskDTO : messageTaskDTOList) {
List<MessageTaskTypeDTO> messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList();
for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) {
String taskType = messageTaskTypeDTO.getTaskType();
if (taskType.contains(NoticeConstants.Mode.SCHEDULE) || taskType.contains("AT")) {
continue;
}
List<MessageTaskDetailDTO> messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList();
for (MessageTaskDetailDTO messageTaskDetailDTO : messageTaskDetailDTOList) {
String event = messageTaskDetailDTO.getEvent();
List<OptionDTO> 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);
}
} }

View File

@ -1,5 +1,7 @@
package io.metersphere.project.controller; 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.constants.SessionConstants;
import io.metersphere.sdk.dto.OptionDTO; import io.metersphere.sdk.dto.OptionDTO;
import io.metersphere.sdk.util.JSON; 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.BUG_TASK);
typeList.add(NoticeConstants.TaskType.UI_SCENARIO_TASK); typeList.add(NoticeConstants.TaskType.UI_SCENARIO_TASK);
typeList.add(NoticeConstants.TaskType.LOAD_TEST_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) { for (String s : typeList) {
MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/project-template-test-1") MvcResult mvcResult = mockMvc.perform(MockMvcRequestBuilders.get("/notice/template/get/fields/project-template-test-1")
.header(SessionConstants.HEADER_TOKEN, sessionId) .header(SessionConstants.HEADER_TOKEN, sessionId)
@ -52,8 +59,9 @@ public class NoticeTemplateControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); MessageTemplateResultDTO messageTemplateResultDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateResultDTO.class);
if (s.equals(NoticeConstants.TaskType.JENKINS_TASK)) { List<MessageTemplateFieldDTO> projectList = messageTemplateResultDTO.getFieldList();
if (s.equals(NoticeConstants.TaskType.BUG_TASK_AT)) {
Assertions.assertTrue(CollectionUtils.isEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isEmpty(projectList));
} else { } else {
Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList)); Assertions.assertTrue(CollectionUtils.isNotEmpty(projectList));
@ -82,7 +90,8 @@ public class NoticeTemplateControllerTests extends BaseTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn(); .andExpect(content().contentType(MediaType.APPLICATION_JSON)).andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8); String contentAsString = mvcResult.getResponse().getContentAsString(StandardCharsets.UTF_8);
ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class); ResultHolder resultHolder = JSON.parseObject(contentAsString, ResultHolder.class);
List<OptionDTO> projectList = JSON.parseArray(JSON.toJSONString(resultHolder.getData()), OptionDTO.class); MessageTemplateResultDTO messageTemplateResultDTO = JSON.parseObject(JSON.toJSONString(resultHolder.getData()), MessageTemplateResultDTO.class);
List<MessageTemplateFieldDTO> projectList = messageTemplateResultDTO.getFieldList();
if (s.equals(NoticeConstants.TaskType.API_DEFINITION_TASK)) { if (s.equals(NoticeConstants.TaskType.API_DEFINITION_TASK)) {
List<String> collect = projectList.stream().map(OptionDTO::getId).toList(); List<String> collect = projectList.stream().map(OptionDTO::getId).toList();
Assertions.assertFalse(collect.contains("grade")); Assertions.assertFalse(collect.contains("grade"));

View File

@ -459,7 +459,7 @@ public class ProjectRobotControllerTests extends BaseTest {
List<MessageTaskTypeDTO> messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList(); List<MessageTaskTypeDTO> messageTaskTypeDTOList = messageTaskDTO.getMessageTaskTypeDTOList();
for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) { for (MessageTaskTypeDTO messageTaskTypeDTO : messageTaskTypeDTOList) {
String taskType = messageTaskTypeDTO.getTaskType(); 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; continue;
} }
List<MessageTaskDetailDTO> messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList(); List<MessageTaskDetailDTO> messageTaskDetailDTOList = messageTaskTypeDTO.getMessageTaskDetailDTOList();

View File

@ -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 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', 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-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 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), 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_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);

View File

@ -58,8 +58,17 @@ public interface NoticeConstants {
String LOAD_SCHEDULE_TASK = "LOAD_SCHEDULE_TASK"; String LOAD_SCHEDULE_TASK = "LOAD_SCHEDULE_TASK";
//jenkins任务 //jenkins任务
@Schema(description = "message.jenkins_task") @Schema(description = "message.jenkins_ui_task")
String JENKINS_TASK = "JENKINS_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 { interface Mode {
@ -158,6 +167,7 @@ public interface NoticeConstants {
interface RelatedUser { interface RelatedUser {
@Schema(description = "message.create_user") @Schema(description = "message.create_user")
//TODO:// 和实体类创建人应该保持一致还需再改
String CREATE_USER = "CREATE_USER";//创建人 String CREATE_USER = "CREATE_USER";//创建人
@Schema(description = "message.follow_people") @Schema(description = "message.follow_people")
String FOLLOW_PEOPLE = "FOLLOW_PEOPLE";//关注人 String FOLLOW_PEOPLE = "FOLLOW_PEOPLE";//关注人
@ -165,6 +175,15 @@ public interface NoticeConstants {
String OPERATOR = "OPERATOR"; //操作人 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 { interface TemplateText {
@Schema(description = "message.test_plan_task_create") @Schema(description = "message.test_plan_task_create")
String TEST_PLAN_TASK_CREATE = "TEST_PLAN_TASK_CREATE"; // ${OPERATOR}创建了测试计划:${name} 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") @Schema(description = "message.load_report_task_delete")
String LOAD_REPORT_TASK_DELETE = "LOAD_REPORT_TASK_DELETE";//${OPERATOR}删除了性能报告:${name} String LOAD_REPORT_TASK_DELETE = "LOAD_REPORT_TASK_DELETE";//${OPERATOR}删除了性能报告:${name}
@Schema(description = "message.jenkins_task_execute_successful") @Schema(description = "message.jenkins_api_scenario_task_execute")
String JENKINS_TASK_EXECUTE_SUCCESSFUL = "JENKINS_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了场景用例:${name} String JENKINS_API_SCENARIO_TASK_EXECUTE_SUCCESSFUL = "JENKINS_API_SCENARIO_TASK_EXECUTE_SUCCESSFUL";//Jenkins执行了接口场景:${name}
@Schema(description = "message.jenkins_task_execute_failed") @Schema(description = "message.jenkins_api_scenario_task_execute")
String JENKINS_TASK_EXECUTE_FAILED = "JENKINS_TASK_EXECUTE_FAILED";//Jenkins执行了测试计划:${name} 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 { interface TemplateSubject {
@ -409,6 +445,27 @@ public interface NoticeConstants {
String JENKINS_TASK_EXECUTE_SUCCESSFUL = "JENKINS_TASK_EXECUTE_SUCCESSFUL"; String JENKINS_TASK_EXECUTE_SUCCESSFUL = "JENKINS_TASK_EXECUTE_SUCCESSFUL";
@Schema(description = "message.title.jenkins_task_execute_failed")//Jenkins任务执行失败通知 @Schema(description = "message.title.jenkins_task_execute_failed")//Jenkins任务执行失败通知
String JENKINS_TASK_EXECUTE_FAILED = "JENKINS_TASK_EXECUTE_FAILED"; 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 { interface SensitiveField {

View File

@ -1,10 +1,16 @@
package io.metersphere.system.notice.sender; 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.ApiDefinitionFollowerMapper;
import io.metersphere.api.mapper.ApiScenarioFollowerMapper; 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.CaseReviewFollowerMapper;
import io.metersphere.functional.mapper.FunctionalCaseFollowerMapper; import io.metersphere.functional.mapper.FunctionalCaseFollowerMapper;
import io.metersphere.load.domain.LoadTestFollower; 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.TestPlanFollower;
import io.metersphere.plan.domain.TestPlanFollowerExample; import io.metersphere.plan.domain.TestPlanFollowerExample;
import io.metersphere.plan.mapper.TestPlanFollowerMapper; 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.JSON;
import io.metersphere.sdk.util.LogUtils; import io.metersphere.sdk.util.LogUtils;
import io.metersphere.system.domain.CustomField; 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.domain.UserExample;
import io.metersphere.system.mapper.CustomFieldMapper; import io.metersphere.system.mapper.CustomFieldMapper;
import io.metersphere.system.mapper.UserMapper; 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 jakarta.annotation.Resource;
import org.apache.commons.beanutils.BeanMap; import org.apache.commons.beanutils.BeanMap;
import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils; 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.ArrayList;
import java.util.List; import java.util.List;
@ -63,13 +68,13 @@ public abstract class AbstractNoticeSender implements NoticeSender {
noticeModel.setReceivers(getRealUserIds(messageDetail, noticeModel, messageDetail.getEvent())); noticeModel.setReceivers(getRealUserIds(messageDetail, noticeModel, messageDetail.getEvent()));
// 如果配置了模版就直接使用模版 // 如果配置了模版就直接使用模版
if (StringUtils.isNotBlank(messageDetail.getTemplate())) { if (StringUtils.isNotBlank(messageDetail.getTemplate())) {
return getContent(messageDetail.getTemplate(), noticeModel.getParamMap()); return MessageTemplateUtils.getContent(messageDetail.getTemplate(), noticeModel.getParamMap());
} }
String context = StringUtils.EMPTY; String context = StringUtils.EMPTY;
if (StringUtils.isBlank(context)) { if (StringUtils.isBlank(context)) {
context = noticeModel.getContext(); context = noticeModel.getContext();
} }
return getContent(context, noticeModel.getParamMap()); return MessageTemplateUtils.getContent(context, noticeModel.getParamMap());
} }
private void handleCustomFields(NoticeModel noticeModel) { private void handleCustomFields(NoticeModel noticeModel) {
@ -104,34 +109,6 @@ public abstract class AbstractNoticeSender implements NoticeSender {
} }
} }
protected String getContent(String template, Map<String, Object> 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<String, Object> 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<Receiver> getRealUserIds(MessageDetail messageDetail, NoticeModel noticeModel, String event) { private List<Receiver> getRealUserIds(MessageDetail messageDetail, NoticeModel noticeModel, String event) {
List<Receiver> toUsers = new ArrayList<>(); List<Receiver> toUsers = new ArrayList<>();
Map<String, Object> paramMap = noticeModel.getParamMap(); Map<String, Object> paramMap = noticeModel.getParamMap();

View File

@ -1,9 +1,20 @@
package io.metersphere.system.notice.utils; 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.sdk.util.Translator;
import io.metersphere.system.notice.constants.NoticeConstants; import io.metersphere.system.notice.constants.NoticeConstants;
import io.metersphere.ui.domain.UiScenario;
import io.swagger.v3.oas.annotations.media.Schema; 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.reflect.FieldUtils;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.text.StringSubstitutor;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.util.ArrayList; import java.util.ArrayList;
@ -86,6 +97,7 @@ public class MessageTemplateUtils {
/** /**
* 获取接收人的特殊值 * 获取接收人的特殊值
*
* @return List<String> defaultRelatedUsers * @return List<String> defaultRelatedUsers
*/ */
public static List<String> getDefaultRelatedUser() { public static List<String> getDefaultRelatedUser() {
@ -99,6 +111,7 @@ public class MessageTemplateUtils {
/** /**
* 获取接收人的特殊值 * 获取接收人的特殊值
*
* @return List<String> defaultRelatedUsers * @return List<String> defaultRelatedUsers
*/ */
public static Map<String, String> getDefaultRelatedUserMap() { public static Map<String, String> getDefaultRelatedUserMap() {
@ -108,4 +121,99 @@ public class MessageTemplateUtils {
return defaultRelatedUserMap; return defaultRelatedUserMap;
} }
/**
* 获取字段来源
* @return FieldSourceMap
*/
public static Map<String, String> getFieldSourceMap() {
Map<String, String> 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<String, Object> 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<String, Object> 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<String, Object> 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}", "<n>");
}
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);
}
} }

View File

@ -88,7 +88,7 @@ public class NoticeSendService {
messageDetails = messageDetailService.searchMessageByTestId(noticeModel.getTestId()); messageDetails = messageDetailService.searchMessageByTestId(noticeModel.getTestId());
} else { } else {
String projectId = (String) noticeModel.getParamMap().get("projectId"); String projectId = (String) noticeModel.getParamMap().get("projectId");
messageDetails = messageDetailService.searchMessageByTypeAndProjectId(NoticeConstants.TaskType.JENKINS_TASK, projectId); messageDetails = messageDetailService.searchMessageByTypeAndProjectId(triggerMode, projectId);
} }
// 异步发送通知 // 异步发送通知

View File

@ -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<String, String> taskTypeMap = MessageTemplateUtils.getTaskTypeMap();
Map<String, String> eventMap = MessageTemplateUtils.getEventMap();
Set<String> typeList = taskTypeMap.keySet();
Map<String, String> defaultTemplateSubjectMap = MessageTemplateUtils.getDefaultTemplateSubjectMap();
Assertions.assertTrue(MapUtils.isNotEmpty(defaultTemplateSubjectMap));
Map<String, String> moduleMap = MessageTemplateUtils.getModuleMap();
Assertions.assertTrue(MapUtils.isNotEmpty(moduleMap));
List<String> defaultRelatedUser = MessageTemplateUtils.getDefaultRelatedUser();
Assertions.assertTrue(CollectionUtils.isNotEmpty(defaultRelatedUser));
Map<String, String> defaultRelatedUserMap = MessageTemplateUtils.getDefaultRelatedUserMap();
Assertions.assertTrue(MapUtils.isNotEmpty(defaultRelatedUserMap));
for (String type : typeList) {
Field[] domainTemplateFields = MessageTemplateUtils.getDomainTemplateFields(type);
Assertions.assertNotNull(domainTemplateFields);
Map<String, String> 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));
}
});
}
}
}