feat(任务中心): 增加任务实时统计执行中的数量

This commit is contained in:
fit2-zhao 2021-06-30 17:52:12 +08:00 committed by fit2-zhao
parent 847119fe47
commit 4e81c24c95
11 changed files with 72 additions and 5 deletions

View File

@ -11,4 +11,6 @@ public interface ExtTaskMapper {
void deleteByResourceId(String id);
List<TaskCenterDTO> getTasks (@Param("request") TaskCenterRequest request);
List<TaskCenterDTO> getRunningTasks (@Param("request") TaskCenterRequest request);
}

View File

@ -40,4 +40,25 @@
)tt ORDER BY tt.executionTime DESC;
</select>
<select id="getRunningTasks" resultType="io.metersphere.task.dto.TaskCenterDTO" parameterType="java.lang.String">
SELECT tt.* FROM (
(select t.id,t.create_time as executionTime
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.project_id= #{request.projectId} and t.status not in ("saved","completed","success","error")
)
UNION ALL
(select t.id,t.create_time as executionTime
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
left join api_definition t3 on t.resource_id = t3.id left join api_test_case t4 on t4.id = t.resource_id
where to_days(FROM_UNIXTIME(t.create_time/1000))= to_days(now()) and (t3.project_id =#{request.projectId} OR t4.project_id =#{request.projectId}) and t.status not in ("saved","completed","success","error")
)
UNION ALL
(select t.id,t.create_time as executionTime
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= #{request.projectId} and t.status not in ("saved","completed","success","error")
)
)tt ORDER BY tt.executionTime DESC;
</select>
</mapper>

View File

@ -23,4 +23,11 @@ public class TaskController {
public List<TaskCenterDTO> getTasks(@RequestBody TaskCenterRequest request) {
return taskService.getTasks(request);
}
@PostMapping("/count/running")
@RequiresPermissions("PROJECT_API_SCENARIO:READ")
public int getRunningTasks(@RequestBody TaskCenterRequest request) {
return taskService.getRunningTasks(request).size();
}
}

View File

@ -16,4 +16,9 @@ public class TaskService {
public List<TaskCenterDTO> getTasks(TaskCenterRequest request) {
return extTaskMapper.getTasks(request);
}
public List<TaskCenterDTO> getRunningTasks(TaskCenterRequest request) {
return extTaskMapper.getRunningTasks(request);
}
}

View File

@ -653,7 +653,7 @@ export default {
getReport() {
if (this.batchReportId) {
this.result.loading = false;
this.$success("批量执行成功,请到报告页面查看详情!");
this.$success(this.$t('commons.run_message'));
this.$refs.taskCenter.open();
}
},

View File

@ -10,7 +10,10 @@
<template v-slot:content>
<span>{{ $t('commons.task_center') }}</span>
</template>
<font-awesome-icon @click="showTaskCenter" class="icon global focusing" :icon="['fas', 'tasks']"/>
<el-badge :value="runningTotal" class="item" type="primary" v-if="runningTotal > 0">
<font-awesome-icon @click="showTaskCenter" class="icon global focusing" :icon="['fas', 'tasks']" style="font-size: 18px"/>
</el-badge>
<font-awesome-icon @click="showTaskCenter" class="icon global focusing" :icon="['fas', 'tasks']" v-else/>
</el-tooltip>
</el-menu-item>
</el-menu>
@ -80,6 +83,7 @@ export default {
],
data() {
return {
runningTotal: 0,
taskVisible: false,
result: {},
taskData: [],
@ -109,11 +113,15 @@ export default {
props: {
color: String
},
created() {
this.getTaskRunning();
},
methods: {
format(item) {
return '';
},
showTaskCenter() {
this.getTaskRunning();
this.init();
this.taskVisible = true;
},
@ -192,6 +200,13 @@ export default {
}
return mode;
},
getTaskRunning() {
this.condition.projectId = getCurrentProjectID();
this.$post('/task/center/count/running', this.condition, response => {
this.runningTotal = response.data;
setTimeout(this.getTaskRunning, 5000);
});
},
init() {
this.result.loading = true;
this.condition.projectId = getCurrentProjectID();
@ -281,4 +296,18 @@ export default {
padding-left: 0;
padding-right: 0;
}
/deep/ .el-badge__content.is-fixed {
top: 25px;
}
/deep/ .el-badge__content {
border-radius: 10px;
height: 10px;
line-height: 10px;
}
.item {
margin-right: 10px;
}
</style>

View File

@ -621,7 +621,7 @@ export default {
handleRunBatch(config) {
let obj = {planIds: this.testPlanCaseIds, config: config};
this.$post("/test/plan/api/case/run", obj, response => {
this.$message('任务执行中,请稍后刷新查看结果');
this.$message(this.$t('commons.run_message'));
this.$refs.taskCenter.open();
});
this.search();

View File

@ -364,7 +364,7 @@ export default {
this.buildExecuteParam(param,row);
});
this.$post("/test/case/review/scenario/case/run", param, response => {
this.$message('任务执行中,请稍后刷新查看结果');
this.$message(this.$t('commons.run_message'));
this.$refs.taskCenter.open();
});
}
@ -377,7 +377,7 @@ export default {
param.condition = selectParam.condition;
param.triggerMode = "BATCH";
this.$post("/test/plan/scenario/case/run", param, response => {
this.$message('任务执行中,请稍后刷新查看结果');
this.$message(this.$t('commons.run_message'));
this.$refs.taskCenter.open();
});
}

View File

@ -162,6 +162,7 @@ export default {
task_center: "Task center",
all_module_title: "All module",
create_user: 'Creator',
run_message: "The task is being executed, please go to the task center to view the details",
table: {
select_tip: "Item {0} data is selected"
},

View File

@ -163,6 +163,7 @@ export default {
task_center: "任务中心",
all_module_title: "全部模块",
create_user: '创建人',
run_message: "任务执行中,请到任务中心查看详情",
table: {
select_tip: "已选中 {0} 条数据"
},

View File

@ -163,6 +163,7 @@ export default {
task_center: "任务中心",
all_module_title: "全部模塊",
create_user: "創建人",
run_message: "任務執行中,請到任務中心查看詳情",
table: {
select_tip: "已選中 {0} 條數據"
},