1
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -357,20 +357,40 @@
|
|||||||
</div>
|
</div>
|
||||||
<TabPane name="tasks" label="任务列表">
|
<TabPane name="tasks" label="任务列表">
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-body" v-if="tasksLoading">
|
<div class="tab-body">
|
||||||
<tables :columns="taskColumns" :value="tasksData"
|
<Table :columns="taskColumns" :data="tasksData" :loading="tasksLoading" border>
|
||||||
:pageOption="tasksPageOption" @changePage="queryTasks">
|
</Table>
|
||||||
</tables>
|
<Page
|
||||||
|
:current="tasksPageOption.page"
|
||||||
|
:total="tasksPageOption.total"
|
||||||
|
:page-size="tasksPageOption.pageSize"
|
||||||
|
show-total
|
||||||
|
show-elevator
|
||||||
|
show-sizer
|
||||||
|
@on-change="queryTasks"
|
||||||
|
@on-page-size-change="handleTasksPageSizeChange"
|
||||||
|
style="margin-top: 16px; text-align: right;">
|
||||||
|
</Page>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
|
|
||||||
<TabPane name="commands" label="指令列表">
|
<TabPane name="commands" label="指令列表">
|
||||||
<div class="tab-content">
|
<div class="tab-content">
|
||||||
<div class="tab-body" v-if="commandsLoading">
|
<div class="tab-body">
|
||||||
<tables :columns="commandColumns" :value="commandsData"
|
<Table :columns="commandColumns" :data="commandsData" :loading="commandsLoading" border>
|
||||||
:pageOption="commandsPageOption" @changePage="queryCommands">
|
</Table>
|
||||||
</tables>
|
<Page
|
||||||
|
:current="commandsPageOption.page"
|
||||||
|
:total="commandsPageOption.total"
|
||||||
|
:page-size="commandsPageOption.pageSize"
|
||||||
|
show-total
|
||||||
|
show-elevator
|
||||||
|
show-sizer
|
||||||
|
@on-change="queryCommands"
|
||||||
|
@on-page-size-change="handleCommandsPageSizeChange"
|
||||||
|
style="margin-top: 16px; text-align: right;">
|
||||||
|
</Page>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</TabPane>
|
</TabPane>
|
||||||
@@ -996,15 +1016,11 @@ export default {
|
|||||||
}
|
}
|
||||||
const res = await plaAccountServer.getTasks(this.accountId, param)
|
const res = await plaAccountServer.getTasks(this.accountId, param)
|
||||||
|
|
||||||
|
console.log('res', res);
|
||||||
|
|
||||||
this.tasksData = res.data.rows || []
|
this.tasksData = res.data.rows || []
|
||||||
this.tasksPageOption.total = res.data.count || 0
|
this.tasksPageOption.total = res.data.count || 0
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
this.$forceUpdate()
|
|
||||||
}, 0)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$Message.error('加载任务列表失败')
|
this.$Message.error('加载任务列表失败')
|
||||||
this.tasksData = []
|
this.tasksData = []
|
||||||
@@ -1030,9 +1046,6 @@ export default {
|
|||||||
this.commandsData = res.data.rows || []
|
this.commandsData = res.data.rows || []
|
||||||
this.commandsPageOption.total = res.data.count || 0
|
this.commandsPageOption.total = res.data.count || 0
|
||||||
|
|
||||||
setTimeout(() => {
|
|
||||||
this.$forceUpdate()
|
|
||||||
}, 0)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
this.$Message.error('加载指令列表失败')
|
this.$Message.error('加载指令列表失败')
|
||||||
this.commandsData = []
|
this.commandsData = []
|
||||||
@@ -1064,9 +1077,7 @@ export default {
|
|||||||
await plaAccountServer.retryCommand(command.id)
|
await plaAccountServer.retryCommand(command.id)
|
||||||
this.$Message.success('重试指令成功')
|
this.$Message.success('重试指令成功')
|
||||||
// 刷新指令列表
|
// 刷新指令列表
|
||||||
setTimeout(() => {
|
|
||||||
this.queryCommands(this.commandsPageOption.page)
|
|
||||||
}, 1000)
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('重试指令失败:', error)
|
console.error('重试指令失败:', error)
|
||||||
this.$Message.error(error.message || '重试指令失败')
|
this.$Message.error(error.message || '重试指令失败')
|
||||||
@@ -1113,6 +1124,20 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
// 任务列表分页大小改变
|
||||||
|
handleTasksPageSizeChange(pageSize) {
|
||||||
|
this.tasksPageOption.pageSize = pageSize
|
||||||
|
this.tasksPageOption.page = 1
|
||||||
|
this.queryTasks(1)
|
||||||
|
},
|
||||||
|
|
||||||
|
// 指令列表分页大小改变
|
||||||
|
handleCommandsPageSizeChange(pageSize) {
|
||||||
|
this.commandsPageOption.pageSize = pageSize
|
||||||
|
this.commandsPageOption.page = 1
|
||||||
|
this.queryCommands(1)
|
||||||
|
},
|
||||||
|
|
||||||
// 处理刷新
|
// 处理刷新
|
||||||
handleRefresh() {
|
handleRefresh() {
|
||||||
if (this.activeTab === 'tasks') {
|
if (this.activeTab === 'tasks') {
|
||||||
@@ -1673,13 +1698,23 @@ export default {
|
|||||||
.tab-content {
|
.tab-content {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
min-height: 400px;
|
min-height: 500px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.tab-body {
|
.tab-body {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
overflow: visible;
|
overflow: visible;
|
||||||
|
min-height: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* TabPane 最小高度 */
|
||||||
|
.tabs-card>>>.ivu-tabs-content {
|
||||||
|
min-height: 500px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.tabs-card>>>.ivu-tabs-tabpane {
|
||||||
|
min-height: 500px;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Tab右侧按钮 */
|
/* Tab右侧按钮 */
|
||||||
|
|||||||
@@ -243,13 +243,18 @@ class PlaAccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 通过 sn_code 查询任务列表
|
// 通过 sn_code 查询任务列表
|
||||||
|
// 使用 attributes 只查询需要的字段,提升性能
|
||||||
const result = await task_status.findAndCountAll({
|
const result = await task_status.findAndCountAll({
|
||||||
where: {
|
where: {
|
||||||
sn_code: account.sn_code
|
sn_code: account.sn_code
|
||||||
},
|
},
|
||||||
limit,
|
limit,
|
||||||
offset,
|
offset,
|
||||||
order: [['id', 'DESC']]
|
order: [['id', 'DESC']],
|
||||||
|
// 不查询大字段以提升性能
|
||||||
|
attributes: {
|
||||||
|
exclude: ['taskParams', 'result', 'errorMessage', 'errorStack']
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// 将 Sequelize 模型实例转换为普通对象
|
// 将 Sequelize 模型实例转换为普通对象
|
||||||
@@ -271,7 +276,6 @@ class PlaAccountService {
|
|||||||
const task_commands = db.getModel('task_commands');
|
const task_commands = db.getModel('task_commands');
|
||||||
const task_status = db.getModel('task_status');
|
const task_status = db.getModel('task_status');
|
||||||
const Sequelize = require('sequelize');
|
const Sequelize = require('sequelize');
|
||||||
const Op = Sequelize.Op;
|
|
||||||
|
|
||||||
const { id, limit, offset } = params;
|
const { id, limit, offset } = params;
|
||||||
|
|
||||||
@@ -285,44 +289,50 @@ class PlaAccountService {
|
|||||||
throw new Error('账号不存在');
|
throw new Error('账号不存在');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 先查询所有匹配 sn_code 的任务 ID
|
// 使用子查询优化性能,避免先查询所有任务ID
|
||||||
const tasks = await task_status.findAll({
|
const sequelize = task_commands.sequelize;
|
||||||
where: {
|
|
||||||
sn_code: account.sn_code
|
// 使用子查询一次性完成查询和计数
|
||||||
|
const countSql = `
|
||||||
|
SELECT COUNT(*) as count
|
||||||
|
FROM task_commands tc
|
||||||
|
WHERE tc.task_id IN (
|
||||||
|
SELECT id FROM task_status WHERE sn_code = :sn_code
|
||||||
|
)
|
||||||
|
`;
|
||||||
|
|
||||||
|
const dataSql = `
|
||||||
|
SELECT tc.*,
|
||||||
|
tc.create_time
|
||||||
|
FROM task_commands tc
|
||||||
|
WHERE tc.task_id IN (
|
||||||
|
SELECT id FROM task_status WHERE sn_code = :sn_code
|
||||||
|
)
|
||||||
|
ORDER BY tc.id DESC
|
||||||
|
LIMIT :limit OFFSET :offset
|
||||||
|
`;
|
||||||
|
|
||||||
|
// 并行执行查询和计数
|
||||||
|
const [countResult, dataResult] = await Promise.all([
|
||||||
|
sequelize.query(countSql, {
|
||||||
|
replacements: { sn_code: account.sn_code },
|
||||||
|
type: Sequelize.QueryTypes.SELECT
|
||||||
|
}),
|
||||||
|
sequelize.query(dataSql, {
|
||||||
|
replacements: {
|
||||||
|
sn_code: account.sn_code,
|
||||||
|
limit: limit,
|
||||||
|
offset: offset
|
||||||
},
|
},
|
||||||
attributes: ['id']
|
type: Sequelize.QueryTypes.SELECT
|
||||||
});
|
})
|
||||||
|
]);
|
||||||
|
|
||||||
const taskIds = tasks.map(task => task.id);
|
const count = countResult[0]?.count || 0;
|
||||||
|
|
||||||
// 如果没有任务,直接返回空结果
|
// 将原始数据转换为普通对象
|
||||||
if (taskIds.length === 0) {
|
const rows = dataResult.map(row => {
|
||||||
return {
|
const plainRow = { ...row };
|
||||||
count: 0,
|
|
||||||
rows: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
// 使用 Sequelize 模型查询指令列表
|
|
||||||
const result = await task_commands.findAndCountAll({
|
|
||||||
where: {
|
|
||||||
task_id: {
|
|
||||||
[Op.in]: taskIds
|
|
||||||
}
|
|
||||||
},
|
|
||||||
limit,
|
|
||||||
offset,
|
|
||||||
order: [['id', 'DESC']]
|
|
||||||
});
|
|
||||||
|
|
||||||
// 将 Sequelize 模型实例转换为普通对象
|
|
||||||
const rows = result.rows.map(row => {
|
|
||||||
const plainRow = row.get({ plain: true });
|
|
||||||
|
|
||||||
// 添加 create_time 字段(使用 start_time 或 createdAt)
|
|
||||||
if (!plainRow.create_time) {
|
|
||||||
plainRow.create_time = plainRow.start_time || plainRow.createdAt || null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// 解析 JSON 字段
|
// 解析 JSON 字段
|
||||||
if (plainRow.command_params && typeof plainRow.command_params === 'string') {
|
if (plainRow.command_params && typeof plainRow.command_params === 'string') {
|
||||||
@@ -344,7 +354,7 @@ class PlaAccountService {
|
|||||||
});
|
});
|
||||||
|
|
||||||
return {
|
return {
|
||||||
count: result.count,
|
count: parseInt(count),
|
||||||
rows: rows
|
rows: rows
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user