From 45ee9be7733bec840ed364635b6e61ed49a3e64d Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 1 Nov 2022 19:16:17 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83):?= =?UTF-8?q?=20=E4=BC=98=E5=8C=96=E4=BB=BB=E5=8A=A1=E4=B8=AD=E5=BF=83?= =?UTF-8?q?=E6=8C=89=E7=85=A7=E4=BB=BB=E5=8A=A1=E7=B1=BB=E5=9E=8B=E5=8A=A0?= =?UTF-8?q?=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../automation/scenario/ApiScenarioList.vue | 4 +- .../automation/scenario/EditApiScenario.vue | 2 +- .../src/business/definition/ApiDefinition.vue | 4 - .../components/case/EditApiCase.vue | 2 +- .../components/list/ApiCaseSimpleList.vue | 4 +- .../business/history/task/ApiTaskCenter.vue | 544 ------------------ .../history/task/ApiTaskPagination.vue | 62 -- framework/sdk-parent/frontend/src/api/task.js | 4 +- .../src/components/task/TaskCenter.vue | 170 +++--- .../src/components/task/TaskCenterItem.vue | 303 ++++++++++ .../frontend/src/i18n/lang/en-US.js | 6 + .../frontend/src/i18n/lang/zh-CN.js | 6 + .../frontend/src/i18n/lang/zh-TW.js | 6 + .../base/mapper/ext/BaseTaskMapper.java | 8 +- .../base/mapper/ext/BaseTaskMapper.xml | 218 +++---- .../commons/constants/TaskCenterType.java | 5 + .../task/controller/TaskController.java | 9 +- .../task/dto/TaskCenterRequest.java | 4 + .../task/dto/TaskStatisticsDTO.java | 17 + .../metersphere/task/service/TaskService.java | 58 +- .../websocket/TaskCenterWebSocket.java | 22 +- 21 files changed, 645 insertions(+), 813 deletions(-) delete mode 100644 api-test/frontend/src/business/history/task/ApiTaskCenter.vue delete mode 100644 api-test/frontend/src/business/history/task/ApiTaskPagination.vue create mode 100644 framework/sdk-parent/frontend/src/components/task/TaskCenterItem.vue create mode 100644 framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/TaskCenterType.java create mode 100644 framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskStatisticsDTO.java diff --git a/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue b/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue index 18ac536f05..483475ba3c 100644 --- a/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue +++ b/api-test/frontend/src/business/automation/scenario/ApiScenarioList.vue @@ -408,7 +408,7 @@ export default { MsTestPlanList: () => import("./testplan/TestPlanList"), MsTableOperatorButton: () => import("metersphere-frontend/src/components/MsTableOperatorButton"), MsRunMode: () => import("./common/RunMode"), - MsTaskCenter: () => import("@/business/history/task/ApiTaskCenter"), + MsTaskCenter: () => import("metersphere-frontend/src/components/task/TaskCenter"), MsRun: () => import("./DebugRun"), MxRelationshipGraphDrawer: () => import("metersphere-frontend/src/components/graph/MxRelationshipGraphDrawer") }, @@ -985,7 +985,7 @@ export default { if (this.batchReportId) { this.result = false; this.$success(this.$t('commons.run_message')); - this.$refs.taskCenter.open(); + this.$refs.taskCenter.open("SCENARIO"); } }, buildBatchParam(param) { diff --git a/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue b/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue index 9d27b73e10..567a88f69b 100644 --- a/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue +++ b/api-test/frontend/src/business/automation/scenario/EditApiScenario.vue @@ -457,7 +457,7 @@ export default { MsDrawer: () => import("metersphere-frontend/src/components/MsDrawer"), MsSelectTree: () => import("metersphere-frontend/src/components/select-tree/SelectTree"), MsChangeHistory: () => import("@/business/history/ApiHistory"), - MsTaskCenter: () => import("@/business/history/task/ApiTaskCenter"), + MsTaskCenter: () => import("metersphere-frontend/src/components/task/TaskCenter"), MsApiVariableAdvance: () => import("./../../definition/components/ApiVariableAdvance"), MsMainContainer: () => import("metersphere-frontend/src/components/MsMainContainer"), MsAsideContainer: () => import("metersphere-frontend/src/components/MsAsideContainer"), diff --git a/api-test/frontend/src/business/definition/ApiDefinition.vue b/api-test/frontend/src/business/definition/ApiDefinition.vue index ac4c27a626..d92db94f94 100644 --- a/api-test/frontend/src/business/definition/ApiDefinition.vue +++ b/api-test/frontend/src/business/definition/ApiDefinition.vue @@ -1066,10 +1066,6 @@ export default { margin: 0 0 0px; } -:deep(.el-tabs__nav-scroll) { - width: calc(100% - 200px); -} - :deep( .el-card) { /*border: 1px solid #EBEEF5;*/ /*border-style: none;*/ diff --git a/api-test/frontend/src/business/definition/components/case/EditApiCase.vue b/api-test/frontend/src/business/definition/components/case/EditApiCase.vue index 8aebe9bfe5..c601c2f1d7 100644 --- a/api-test/frontend/src/business/definition/components/case/EditApiCase.vue +++ b/api-test/frontend/src/business/definition/components/case/EditApiCase.vue @@ -78,7 +78,7 @@ export default { ApiCaseHeader, MsRun: () => import("../Run"), ApiCaseItem: () => import("./ApiCaseItem"), - MsTaskCenter: () => import("@/business/history/task/ApiTaskCenter"), + MsTaskCenter: () => import("metersphere-frontend/src/components/task/TaskCenter"), }, props: { createCase: String, diff --git a/api-test/frontend/src/business/definition/components/list/ApiCaseSimpleList.vue b/api-test/frontend/src/business/definition/components/list/ApiCaseSimpleList.vue index 88a94e62ea..34a0e0dfa7 100644 --- a/api-test/frontend/src/business/definition/components/list/ApiCaseSimpleList.vue +++ b/api-test/frontend/src/business/definition/components/list/ApiCaseSimpleList.vue @@ -374,7 +374,7 @@ export default { SyncSetting, MsApiReportStatus: () => import("../../../automation/report/ApiReportStatus"), PlanStatusTableItem: () => import("@/business/commons/PlanStatusTableItem"), - MsTaskCenter: () => import("@/business/history/task/ApiTaskCenter"), + MsTaskCenter: () => import("metersphere-frontend/src/components/task/TaskCenter"), }, data() { return { @@ -701,7 +701,7 @@ export default { } else { store.currentApiCase = {case: true}; } - this.$refs.taskCenter.open(); + this.$refs.taskCenter.open("API"); }); }, customHeader() { diff --git a/api-test/frontend/src/business/history/task/ApiTaskCenter.vue b/api-test/frontend/src/business/history/task/ApiTaskCenter.vue deleted file mode 100644 index 991e84c53f..0000000000 --- a/api-test/frontend/src/business/history/task/ApiTaskCenter.vue +++ /dev/null @@ -1,544 +0,0 @@ - - - - - - diff --git a/api-test/frontend/src/business/history/task/ApiTaskPagination.vue b/api-test/frontend/src/business/history/task/ApiTaskPagination.vue deleted file mode 100644 index 90e3c731e3..0000000000 --- a/api-test/frontend/src/business/history/task/ApiTaskPagination.vue +++ /dev/null @@ -1,62 +0,0 @@ - - - - - diff --git a/framework/sdk-parent/frontend/src/api/task.js b/framework/sdk-parent/frontend/src/api/task.js index d8c452e944..3d970bd66a 100644 --- a/framework/sdk-parent/frontend/src/api/task.js +++ b/framework/sdk-parent/frontend/src/api/task.js @@ -5,8 +5,8 @@ import packageInfo from '@/../package.json' const currentModuleName = packageInfo.name; -export function getTaskSocket() { - return socket("/websocket/task/running/" + getCurrentProjectID() + "/" + getCurrentUser().id) +export function getTaskSocket(hasLicense) { + return socket("/websocket/task/running/" + getCurrentProjectID() + "/" + getCurrentUser().id + "/" + hasLicense) } export function getCaseData(id) { diff --git a/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue b/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue index 4e366192e2..f81d41bfde 100644 --- a/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue +++ b/framework/sdk-parent/frontend/src/components/task/TaskCenter.vue @@ -22,7 +22,7 @@ :title="$t('commons.task_center')" :size="size.toString()" custom-class="ms-drawer-task"> - +
{{ $t('commons.task_close') }}
- - -
+ +
- @@ -52,7 +51,7 @@ - @@ -62,7 +61,7 @@ - - + {{ $t('report.stop_btn_all') }} @@ -82,45 +81,27 @@
- -
-
- - - {{ getModeName(item.executionModule) }} : {{ - item.name - }} - - - {{ $t('report.stop_btn') }} - -
- - {{ $t('commons.actuator') }}:{{ item.actuator }} {{ $t('commons.from') }} {{ item.executor }} {{ - item.executionTime | datetimeFormat - }} {{ getMode(item.triggerMode) }} - -
- - - - - - - - -
-
-
-
- - {{ $t('commons.task_center_remark') }} -
+ + + + + {{ tab.label }} + + {{ tab.label }} + + + +
-
@@ -128,17 +109,19 @@ + + + diff --git a/framework/sdk-parent/frontend/src/i18n/lang/en-US.js b/framework/sdk-parent/frontend/src/i18n/lang/en-US.js index eefc79050e..babd8034d2 100644 --- a/framework/sdk-parent/frontend/src/i18n/lang/en-US.js +++ b/framework/sdk-parent/frontend/src/i18n/lang/en-US.js @@ -3003,6 +3003,12 @@ const message = { go_to_case_message: 'CASE update message notification', update_case_tip: 'When the CASE changes, the creator of the automation scene referring to the CASE will receive an in-site message reminder' } + }, + task: { + api_title: "Api testing tasks", + scenario_title: "Scenario testing tasks", + ui_title: "UI testing tasks", + perf_title: "Perf testing tasks" } } diff --git a/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js b/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js index 90091273cd..8f4e9e7da1 100644 --- a/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js +++ b/framework/sdk-parent/frontend/src/i18n/lang/zh-CN.js @@ -3016,6 +3016,12 @@ const message = { go_to_case_message: 'CASE更新消息通知', update_case_tip: '当CASE发生变化时,引用CASE的自动化场景创建人会收到站内消息提醒' } + }, + task: { + api_title: "接口测试任务", + scenario_title: "场景测试任务", + ui_title: "UI测试任务", + perf_title: "性能测试任务" } } diff --git a/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js b/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js index b9e6b3945b..1d4caaf221 100644 --- a/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js +++ b/framework/sdk-parent/frontend/src/i18n/lang/zh-TW.js @@ -2994,6 +2994,12 @@ const message = { go_to_case_message: 'CASE更新消息通知', update_case_tip: '當CASE發生變化時,引用CASE的自動化場景創建人會收到站內消息提醒' } + }, + task: { + api_title: "接口測試任務", + scenario_title: "場景測試任務", + ui_title: "UI測試任務", + perf_title: "性能測試任務" } } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.java index fa20d608b8..b47c981d05 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.java @@ -2,15 +2,19 @@ package io.metersphere.base.mapper.ext; import io.metersphere.task.dto.TaskCenterDTO; import io.metersphere.task.dto.TaskCenterRequest; +import io.metersphere.task.dto.TaskStatisticsDTO; import org.apache.ibatis.annotations.Param; import java.util.List; public interface BaseTaskMapper { - List getTasks(@Param("request") TaskCenterRequest request, @Param("uiPermission") Boolean uiPermission); + List getApiTasks(@Param("request") TaskCenterRequest request); + List getScenarioTasks(@Param("request") TaskCenterRequest request); + List getPerfTasks(@Param("request") TaskCenterRequest request); + List getUiTasks(@Param("request") TaskCenterRequest request, @Param("uiPermission") Boolean uiPermission); - int getRunningTasks(@Param("request") TaskCenterRequest request); + TaskStatisticsDTO getRunningTasks(@Param("request") TaskCenterRequest request); List getCases(@Param("id") String id); diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.xml b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.xml index aaee059fac..68c3655d91 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.xml +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/base/mapper/ext/BaseTaskMapper.xml @@ -1,38 +1,8 @@ - + SELECT t.id,t.name,'API' AS executionModule, t.report_type, ifnull(t2.name,'LOCAL') AS actuator, t1.`name` AS executor,t.create_time AS executionTime, ifnull(t.trigger_mode,'MANUAL') AS triggerMode ,ifnull(t.status,'Saved') AS executionStatus FROM api_definition_exec_result t INNER JOIN `user` t1 ON t.user_id = t1.id LEFT JOIN test_resource_pool t2 ON @@ -59,9 +29,41 @@ AND t.user_id = #{request.executor} AND (t.integrated_report_id IS NULL OR t.integrated_report_id = 'null') - ) - UNION ALL - (SELECT t.id,t.name,'PERFORMANCE' AS executionModule,'PERFORMANCE' AS report_type, ifnull(t2.name,'LOCAL') AS + ORDER BY t.create_time DESC + + + + + + + - + SELECT ( + SELECT + count( t.id ) + FROM + api_scenario_report t + LEFT JOIN `user` t1 ON t.user_id = t1.id + LEFT JOIN test_resource_pool t2 ON t.actuator = t2.id + WHERE + to_days(FROM_UNIXTIME( t.create_time / 1000 ))= to_days(now()) + AND t.execute_type != 'Debug' + AND t.execute_type != 'Marge' + AND t.project_id IN #{id} @@ -157,43 +165,52 @@ AND t.user_id = #{request.executor} - AND t.status IN ("running","starting","waiting") - ) - UNION ALL - (SELECT t.id,'SCENARIO' AS executionModule,t.report_type, ifnull(t2.name,'LOCAL') AS actuator, t1.`name` AS - executor,t.create_time AS executionTime, t.trigger_mode AS triggerMode ,t.status AS executionStatus - FROM ui_scenario_report t LEFT JOIN `user` t1 ON t.user_id = t1.id LEFT JOIN test_resource_pool t2 ON - t.actuator = t2.id - WHERE to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) AND t.execute_type !='Debug' AND t.execute_type - !='Marge' AND t.project_id IN - - #{id} - - - - - AND t.trigger_mode in ('JENKINS_API_PLAN', 'JENKINS_SCENARIO_PLAN', 'JENKINS_PERFORMANCE_TEST', 'JENKINS') - - - AND t.trigger_mode = #{request.triggerMode} - - + AND t.status IN ("running","starting","pending") + ) as scenarioTotal , + + (SELECT + count( t.id ) + FROM + ui_scenario_report t + LEFT JOIN `user` t1 ON t.user_id = t1.id + LEFT JOIN test_resource_pool t2 ON t.actuator = t2.id + WHERE + to_days( FROM_UNIXTIME( t.create_time / 1000 ))= to_days(now()) + AND t.execute_type != 'Debug' + AND t.execute_type != 'Marge' + AND t.project_id IN + + #{id} + + + + + AND t.trigger_mode in ('JENKINS_API_PLAN', 'JENKINS_SCENARIO_PLAN', 'JENKINS_PERFORMANCE_TEST', + 'JENKINS') + + + AND t.trigger_mode = #{request.triggerMode} + + + + + AND t.status = #{request.executionStatus} + + + AND t.user_id = #{request.executor} + + AND t.status IN ("running","starting","pending") + ), - - AND t.status = #{request.executionStatus} - - - AND t.user_id = #{request.executor} - - AND t.status IN ("running","starting","waiting") - ) - UNION ALL - (SELECT t.id,'API' AS executionModule, t.report_type, ifnull(t2.name,'LOCAL') AS actuator, t1.`name` AS - executor,t.create_time AS executionTime, ifnull(t.trigger_mode,'MANUAL') AS triggerMode - ,ifnull(t.status,'Saved') AS executionStatus - FROM api_definition_exec_result t LEFT JOIN `user` t1 ON t.user_id = t1.id LEFT JOIN test_resource_pool t2 ON - t.actuator = t2.id - WHERE to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) AND t.project_id IN + (SELECT + count( t.id ) + FROM + api_definition_exec_result t + LEFT JOIN `user` t1 ON t.user_id = t1.id + LEFT JOIN test_resource_pool t2 ON t.actuator = t2.id + WHERE + to_days( FROM_UNIXTIME( t.create_time / 1000 ))= to_days(now()) + AND t.project_id IN #{id} @@ -215,15 +232,17 @@ AND t.user_id = #{request.executor} AND (t.integrated_report_id IS NULL OR t.integrated_report_id = 'null') - AND t.status IN ("running","starting","waiting") - ) - UNION ALL - (SELECT t.id,'PERFORMANCE' AS executionModule,'PERFORMANCE' AS report_type, ifnull(t2.name,'LOCAL') AS actuator, - t1.`name` AS executor,t.create_time AS executionTime, t.trigger_mode AS triggerMode ,t.`status` AS - executionStatus - FROM load_test_report t LEFT JOIN `user` t1 ON t.user_id = t1.id LEFT JOIN test_resource_pool t2 ON - t.test_resource_pool_id = t2.id - WHERE to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) AND t.project_id IN + AND t.status IN ("running","starting","pending") + ) as apiTotal , + (SELECT + count( t.id ) + FROM + load_test_report t + LEFT JOIN `user` t1 ON t.user_id = t1.id + LEFT JOIN test_resource_pool t2 ON t.test_resource_pool_id = t2.id + WHERE + to_days(FROM_UNIXTIME( t.create_time / 1000 ))= to_days(now()) + AND t.project_id IN #{id} @@ -243,9 +262,8 @@ AND t.user_id = #{request.executor} - AND t.status IN ("running","starting","waiting") - ) - )tt; + AND t.status IN ("running","starting","pending") + ) as perfTotal - UPDATE api_scenario_report SET status ='STOPPED' WHERE status IN ("running","starting","waiting") AND + UPDATE api_scenario_report SET status ='STOPPED' WHERE status IN ("running","starting","pending") AND project_id IN #{id} @@ -278,7 +296,7 @@ - UPDATE api_definition_exec_result SET status ='STOPPED' WHERE status IN ("running","starting","waiting") AND + UPDATE api_definition_exec_result SET status ='STOPPED' WHERE status IN ("running","starting","pending") AND project_id IN #{id} diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/TaskCenterType.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/TaskCenterType.java new file mode 100644 index 0000000000..c81b64bc46 --- /dev/null +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/commons/constants/TaskCenterType.java @@ -0,0 +1,5 @@ +package io.metersphere.commons.constants; + +public enum TaskCenterType { + API, SCENARIO, UI, PERF +} diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/controller/TaskController.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/controller/TaskController.java index f215ce834c..d7230373f7 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/controller/TaskController.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/controller/TaskController.java @@ -1,15 +1,13 @@ package io.metersphere.task.controller; -import com.github.pagehelper.Page; -import com.github.pagehelper.PageHelper; import io.metersphere.commons.utils.CronUtils; -import io.metersphere.commons.utils.PageUtils; import io.metersphere.commons.utils.Pager; import io.metersphere.dto.TaskInfoResult; import io.metersphere.request.BaseQueryRequest; import io.metersphere.task.dto.TaskCenterDTO; import io.metersphere.task.dto.TaskCenterRequest; import io.metersphere.task.dto.TaskRequestDTO; +import io.metersphere.task.dto.TaskStatisticsDTO; import io.metersphere.task.service.TaskService; import org.springframework.web.bind.annotation.*; @@ -28,8 +26,7 @@ public class TaskController { request.setProjects(taskService.getOwnerProjectIds(request.getUserId())); request.setGoPage(goPage); request.setPageSize(pageSize); - Page page = PageHelper.startPage(goPage, pageSize, true); - return PageUtils.setPageInfo(page, taskService.getTasks(request)); + return taskService.getTasks(request); } @GetMapping("/case/{id}") @@ -43,7 +40,7 @@ public class TaskController { } @PostMapping("/count/running") - public int getRunningTasks(@RequestBody TaskCenterRequest request) { + public TaskStatisticsDTO getRunningTasks(@RequestBody TaskCenterRequest request) { return taskService.getRunningTasks(request); } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskCenterRequest.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskCenterRequest.java index 393aa92529..b47027e401 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskCenterRequest.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskCenterRequest.java @@ -28,5 +28,9 @@ public class TaskCenterRequest { private int pageSize; + private String activeName; + + private boolean hasLicense; + List projects; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskStatisticsDTO.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskStatisticsDTO.java new file mode 100644 index 0000000000..f7257caa15 --- /dev/null +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/dto/TaskStatisticsDTO.java @@ -0,0 +1,17 @@ +package io.metersphere.task.dto; + +import lombok.Data; + +@Data +public class TaskStatisticsDTO { + private int apiTotal; + private int scenarioTotal; + private int perfTotal; + private int uiTotal; + // 总量 + private int total; + + public int getTotal() { + return apiTotal + scenarioTotal + perfTotal + uiTotal; + } +} diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/service/TaskService.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/service/TaskService.java index f276a19958..411958a169 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/service/TaskService.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/task/service/TaskService.java @@ -1,9 +1,15 @@ package io.metersphere.task.service; +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; import io.metersphere.base.mapper.ext.BaseInformationSchemaTableMapper; import io.metersphere.base.mapper.ext.BaseScheduleMapper; import io.metersphere.base.mapper.ext.BaseTaskMapper; import io.metersphere.commons.constants.MicroServiceName; +import io.metersphere.commons.constants.TaskCenterType; +import io.metersphere.commons.utils.LogUtil; +import io.metersphere.commons.utils.PageUtils; +import io.metersphere.commons.utils.Pager; import io.metersphere.dto.TaskInfoResult; import io.metersphere.request.BaseQueryRequest; import io.metersphere.service.BaseCheckPermissionService; @@ -11,6 +17,7 @@ import io.metersphere.service.MicroService; import io.metersphere.task.dto.TaskCenterDTO; import io.metersphere.task.dto.TaskCenterRequest; import io.metersphere.task.dto.TaskRequestDTO; +import io.metersphere.task.dto.TaskStatisticsDTO; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; @@ -56,17 +63,51 @@ public class TaskService { return new ArrayList<>(userRelatedProjectIds); } - public List getTasks(TaskCenterRequest request) { + public Pager> getTasks(TaskCenterRequest request) { + Page page = PageHelper.startPage(request.getGoPage(), request.getPageSize(), true); + if (StringUtils.equals(request.getActiveName(), TaskCenterType.UI.name())) { + return PageUtils.setPageInfo(page, getUiTasks(request)); + } else if (StringUtils.equals(request.getActiveName(), TaskCenterType.SCENARIO.name())) { + return PageUtils.setPageInfo(page, getScenarioTasks(request)); + } else if (StringUtils.equals(request.getActiveName(), TaskCenterType.PERF.name())) { + return PageUtils.setPageInfo(page, getPerfTasks(request)); + } else { + return PageUtils.setPageInfo(page, getApiTasks(request)); + } + } + + public List getApiTasks(TaskCenterRequest request) { if (CollectionUtils.isEmpty(request.getProjects())) { return new ArrayList<>(); } - return baseTaskMapper.getTasks(request,checkUiPermission()); + return baseTaskMapper.getApiTasks(request); } - public int getRunningTasks(TaskCenterRequest request) { + public List getUiTasks(TaskCenterRequest request) { + if (CollectionUtils.isEmpty(request.getProjects())) { + return new ArrayList<>(); + } + return baseTaskMapper.getUiTasks(request, checkUiPermission()); + } + + public List getPerfTasks(TaskCenterRequest request) { + if (CollectionUtils.isEmpty(request.getProjects())) { + return new ArrayList<>(); + } + return baseTaskMapper.getPerfTasks(request); + } + + public List getScenarioTasks(TaskCenterRequest request) { + if (CollectionUtils.isEmpty(request.getProjects())) { + return new ArrayList<>(); + } + return baseTaskMapper.getScenarioTasks(request); + } + + public TaskStatisticsDTO getRunningTasks(TaskCenterRequest request) { request.setProjects(this.getOwnerProjectIds(request.getUserId())); if (CollectionUtils.isEmpty(request.getProjects())) { - return 0; + return new TaskStatisticsDTO(); } return baseTaskMapper.getRunningTasks(request); } @@ -95,7 +136,7 @@ public class TaskService { if (taskRequestMap.containsKey(PERF)) { microService.postForData(MicroServiceName.PERFORMANCE_TEST, "/performance/stop/batch", taskRequestMap.get(PERF)); } - if(taskRequestMap.containsKey(UI)){ + if (taskRequestMap.containsKey(UI)) { microService.postForData(MicroServiceName.UI_TEST, "/ui/automation/stop/batch", reportIds); } } @@ -115,13 +156,14 @@ public class TaskService { } } - private boolean checkUiPermission(){ + private boolean checkUiPermission() { try { String uiScenarioReport = baseInformationSchemaTableMapper.checkExist(UI_SCENARIO_REPORT); - if(StringUtils.isNotEmpty(uiScenarioReport)){ + if (StringUtils.isNotEmpty(uiScenarioReport)) { return true; } - }catch (Exception e){ + } catch (Exception e) { + LogUtil.error(e); } return false; } diff --git a/framework/sdk-parent/sdk/src/main/java/io/metersphere/websocket/TaskCenterWebSocket.java b/framework/sdk-parent/sdk/src/main/java/io/metersphere/websocket/TaskCenterWebSocket.java index 26e5ed64e4..7f2becbe27 100644 --- a/framework/sdk-parent/sdk/src/main/java/io/metersphere/websocket/TaskCenterWebSocket.java +++ b/framework/sdk-parent/sdk/src/main/java/io/metersphere/websocket/TaskCenterWebSocket.java @@ -1,9 +1,10 @@ package io.metersphere.websocket; +import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.LogUtil; import io.metersphere.task.dto.TaskCenterRequest; +import io.metersphere.task.dto.TaskStatisticsDTO; import io.metersphere.task.service.TaskService; -import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -14,7 +15,7 @@ import java.util.Timer; import java.util.TimerTask; import java.util.concurrent.ConcurrentHashMap; -@ServerEndpoint("/websocket/task/running/{projectId}/{userId}") +@ServerEndpoint("/websocket/task/running/{projectId}/{userId}/{hasLicense}") @Component public class TaskCenterWebSocket { private static TaskService taskService; @@ -29,9 +30,9 @@ public class TaskCenterWebSocket { * 开启连接的操作 */ @OnOpen - public void onOpen(@PathParam("projectId") String projectId, @PathParam("userId") String userId, Session session) { + public void onOpen(@PathParam("projectId") String projectId, @PathParam("userId") String userId, @PathParam("hasLicense") boolean hasLicense, Session session) { Timer timer = new Timer(true); - TaskCenter task = new TaskCenter(session, projectId, userId); + TaskCenter task = new TaskCenter(session, projectId, userId, hasLicense); timer.schedule(task, 0, 10 * 1000); refreshTasks.putIfAbsent(session, timer); } @@ -52,7 +53,7 @@ public class TaskCenterWebSocket { * 推送消息 */ @OnMessage - public void onMessage(@PathParam("projectId") String projectId, @PathParam("userId") String userId, Session session, String message) { + public void onMessage(@PathParam("projectId") String projectId, @PathParam("userId") String userId, @PathParam("hasLicense") boolean hasLicense, Session session, String message) { int refreshTime = 10; try { refreshTime = Integer.parseInt(message); @@ -63,7 +64,7 @@ public class TaskCenterWebSocket { timer.cancel(); Timer newTimer = new Timer(true); - newTimer.schedule(new TaskCenter(session, projectId, userId), 0, refreshTime * 1000L); + newTimer.schedule(new TaskCenter(session, projectId, userId, hasLicense), 0, refreshTime * 1000L); refreshTasks.put(session, newTimer); } catch (Exception e) { LogUtil.error(e.getMessage(), e); @@ -83,23 +84,24 @@ public class TaskCenterWebSocket { private Session session; private TaskCenterRequest request; - TaskCenter(Session session, String projectId, String userId) { + TaskCenter(Session session, String projectId, String userId, boolean hasLicense) { this.session = session; TaskCenterRequest request = new TaskCenterRequest(); request.setProjectId(projectId); request.setUserId(userId); + request.setHasLicense(hasLicense); this.request = request; } @Override public void run() { try { - int taskTotal = taskService.getRunningTasks(request); + TaskStatisticsDTO task = taskService.getRunningTasks(request); if (!session.isOpen()) { return; } - session.getBasicRemote().sendText(taskTotal + StringUtils.EMPTY); - if (taskTotal == 0) { + session.getBasicRemote().sendText(JSON.toJSONString(task)); + if (task.getTotal() == 0) { session.close(); } } catch (Exception e) {