feat: 新增银行卡检查插件及相关依赖与配置文件

This commit is contained in:
2026-10-29 14:21:30 +08:00
parent 259369953f
commit 526116af83
494 changed files with 66923 additions and 2714 deletions
@@ -216,7 +216,7 @@ onMounted(() => {
</el-select>
</el-form-item>
<el-form-item label="关键字">
<el-input v-model="runQuery.q" placeholder="账号 / 设备 / 插件 / 名称 / 错误摘要" clearable style="width: 260px" @keyup.enter="searchRuns" />
<el-input v-model="runQuery.q" placeholder="账号 / 设备 / 插件 / 名称 / 备注 / 错误摘要" clearable style="width: 260px" @keyup.enter="searchRuns" />
</el-form-item>
<el-form-item>
<el-button type="primary" @click="searchRuns">查询</el-button>
@@ -254,6 +254,11 @@ onMounted(() => {
<el-table-column label="日志" width="80" align="center">
<template #default="{ row }">{{ row.log_count || 0 }} 条</template>
</el-table-column>
<el-table-column label="备注" min-width="140" show-overflow-tooltip>
<template #default="{ row }">
<span :class="row.note ? '' : 'text-gray-400'">{{ row.note || '-' }}</span>
</template>
</el-table-column>
<el-table-column label="摘要 / 错误" min-width="180" show-overflow-tooltip>
<template #default="{ row }">
<span :class="row.error ? 'text-red-600' : 'text-gray-400'">{{ row.error || row.summary || '-' }}</span>
@@ -0,0 +1,23 @@
-- 2026-10-29 插件备注(账号 × 插件 唯一)+ 运行备注快照
-- 背景:客户端插件页新增「运行备注」,壳子采集 → 回传中心机。
-- plugin_notes.note = 当前最新备注(可改可清空,账号×插件唯一)
-- run_logs.note = 每次执行时的备注快照(改备注不影响历史追溯)
-- 部署:在中心机 MySQL(库名见 server/.env 的 MYSQL_DATABASE)执行本文件,然后重启
-- systemctl restart 37du-controlplane-next.service
-- ⚠️ 重复执行时 ADD COLUMN 会报 "Duplicate column name",属正常(列已存在即跳过)。
ALTER TABLE `run_logs`
ADD COLUMN `note` varchar(500) NOT NULL DEFAULT '' COMMENT '本次运行备注快照(执行时插件页的备注)' AFTER `summary`;
CREATE TABLE IF NOT EXISTS `plugin_notes` (
`id` bigint(20) unsigned NOT NULL AUTO_INCREMENT COMMENT '记录自增ID',
`account` varchar(64) NOT NULL DEFAULT '' COMMENT '账号(工号)',
`plugin_id` varchar(64) NOT NULL DEFAULT '' COMMENT '插件ID',
`note` varchar(500) NOT NULL DEFAULT '' COMMENT '备注内容(账号对该插件的说明)',
`device_id` varchar(64) NOT NULL DEFAULT '' COMMENT '最后修改设备ID',
`created_at` datetime NOT NULL DEFAULT current_timestamp() COMMENT '创建时间',
`updated_at` datetime NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp() COMMENT '更新时间',
PRIMARY KEY (`id`),
UNIQUE KEY `uk_account_plugin` (`account`,`plugin_id`),
KEY `idx_plugin_id` (`plugin_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='插件备注(账号×插件唯一)';
@@ -88,6 +88,7 @@ export * from './modules/center/controller/admin/account';
export * from './modules/center/controller/admin/auth';
export * from './modules/center/controller/admin/dict';
export * from './modules/center/controller/admin/menu';
export * from './modules/center/controller/admin/notes';
export * from './modules/center/controller/admin/ops';
export * from './modules/center/controller/admin/plugin';
export * from './modules/center/controller/admin/sys';
@@ -98,6 +99,7 @@ export * from './modules/center/controller/api/fileserver';
export * from './modules/center/controller/api/log';
export * from './modules/center/controller/api/me';
export * from './modules/center/controller/api/misc';
export * from './modules/center/controller/api/notes';
export * from './modules/center/controller/api/ping';
export * from './modules/center/controller/api/plugins';
export * from './modules/center/controller/api/shell';
@@ -0,0 +1,86 @@
import { CoolController, BaseController } from '@cool-midway/core';
import { Get, Headers, Inject, Provide, Query } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { PluginNoteEntity } from '../../entity/runtime';
import { CenterAuthService } from '../../service/auth';
import { pageBounds } from '../../comm/util';
/**
* 插件备注管理端(账号 × 插件 唯一):
* - GET /api/admin/plugin-notes 分页 + 账号/插件/关键字筛选,供管理台查看「谁给哪个插件写了什么备注」
* 注:每次执行时的备注快照看 run_logs.note(运行日志页),这里是当前最新值。
*/
@Provide()
@CoolController('/api/admin')
export class AdminPluginNotesController extends BaseController {
@Inject()
centerAuthService: CenterAuthService;
@InjectEntityModel(PluginNoteEntity)
noteRepo: Repository<PluginNoteEntity>;
/** GET /api/admin/plugin-notes */
@Get('/plugin-notes')
async notesList(
@Query('page') page: number = 1,
@Query('page_size') pageSize: number = 20,
@Query('account') account: string = '',
@Query('plugin') plugin: string = '',
@Query('q') q: string = '',
@Headers('X-Admin-Token') xAdminToken: string = '',
@Headers('X-API-Token') xApiToken: string = ''
) {
await this.centerAuthService.requirePerms(
['center:plugin:list', 'center:log:list'], xAdminToken, xApiToken
);
const [limit, offset] = pageBounds(page, pageSize);
const cond: string[] = [];
const args: any[] = [];
if ((account || '').trim()) { cond.push('n.account LIKE ?'); args.push(`%${account.trim()}%`); }
if ((plugin || '').trim()) { cond.push('n.plugin_id LIKE ?'); args.push(`%${plugin.trim()}%`); }
if ((q || '').trim()) {
cond.push('(n.note LIKE ? OR n.account LIKE ? OR n.plugin_id LIKE ? OR p.name LIKE ?)');
const kw = `%${q.trim()}%`;
args.push(kw, kw, kw, kw);
}
const where = cond.length ? ' WHERE ' + cond.join(' AND ') : '';
const m = this.noteRepo.manager;
const totalRow: any = (await m.query(
`SELECT COUNT(*) AS c FROM plugin_notes n LEFT JOIN plugins p ON p.id = n.plugin_id${where}`,
args
))[0];
const rows: any[] = await m.query(
`SELECT n.id, n.account, a.nickname, n.plugin_id, p.name AS plugin_name,
n.note, n.device_id, n.created_at, n.updated_at
FROM plugin_notes n
LEFT JOIN accounts a ON a.account = n.account
LEFT JOIN plugins p ON p.id = n.plugin_id
${where} ORDER BY n.updated_at DESC LIMIT ? OFFSET ?`,
[...args, limit, offset]
);
return {
items: rows.map((r: any) => ({
id: Number(r.id),
account: r.account || '',
nickname: r.nickname || '',
plugin_id: r.plugin_id || '',
plugin_name: r.plugin_name || '',
note: r.note || '',
device_id: r.device_id || '',
created_at: fmtStr(r.created_at),
updated_at: fmtStr(r.updated_at),
})),
total: Number(totalRow.c || 0),
};
}
}
function fmtStr(d: any): string {
if (!d) return '';
if (d instanceof Date) {
const p = (n: number) => String(n).padStart(2, '0');
return `${d.getFullYear()}-${p(d.getMonth() + 1)}-${p(d.getDate())} ${p(d.getHours())}:${p(d.getMinutes())}:${p(d.getSeconds())}`;
}
return String(d).replace('T', ' ').slice(0, 19);
}
@@ -0,0 +1,81 @@
import { CoolController, BaseController } from '@cool-midway/core';
import { Body, Get, Headers, Inject, Post, Provide, Query } from '@midwayjs/core';
import { InjectEntityModel } from '@midwayjs/typeorm';
import { Repository } from 'typeorm';
import { PluginNoteEntity } from '../../entity/runtime';
import { CenterAuthService, ApiError } from '../../service/auth';
/**
* 客户端插件备注(账号 × 插件 唯一):
* - GET /api/plugin-notes?account= 取该账号全部备注(客户端打开/切换插件时合并到本机缓存)
* - POST /api/plugin-notes 保存备注(note 为空 = 清空云端记录)
* 身份口径与 /api/plugins 一致:Bearer cloud_token 优先,兜底 account + X-API-Token。
* 备注是「当前最新值」,每次执行时的快照另存 run_logs.note(改备注不影响历史追溯)。
*/
@Provide()
@CoolController('/api')
export class ApiPluginNotesController extends BaseController {
@Inject()
centerAuthService: CenterAuthService;
@InjectEntityModel(PluginNoteEntity)
noteRepo: Repository<PluginNoteEntity>;
/** 解析账号身份;无有效身份抛 400 */
private async resolveAcct(
account: string,
xApiToken: string,
authorization: string
): Promise<string> {
let acct = await this.centerAuthService.cloudAccount(authorization);
if (!acct) {
this.centerAuthService.checkApiToken(xApiToken);
acct = (account || '').trim();
}
if (!acct) throw new ApiError(400, '缺少有效会话或 account');
return acct;
}
/** GET /api/plugin-notes?account= — 该账号全部备注 { plugin_id: {note, at} } */
@Get('/plugin-notes')
async notesOfAccount(
@Query('account') account: string = '',
@Headers('X-API-Token') xApiToken: string = '',
@Headers('Authorization') authorization: string = ''
) {
const acct = await this.resolveAcct(account, xApiToken, authorization);
const rows = await this.noteRepo.findBy({ account: acct });
const notes: Record<string, { note: string; at: number }> = {};
for (const r of rows) {
const note = String(r.note || '').trim();
if (!note) continue;
const t = r.updatedAt ? new Date(r.updatedAt).getTime() : 0;
notes[r.pluginId] = { note, at: t ? Math.floor(t / 1000) : 0 };
}
return { ok: true, account: acct, notes };
}
/** POST /api/plugin-notes — 保存/清空备注 */
@Post('/plugin-notes')
async save(
@Body() b: any,
@Headers('X-API-Token') xApiToken: string = '',
@Headers('Authorization') authorization: string = ''
) {
const acct = await this.resolveAcct(b?.account, xApiToken, authorization);
const pid = String(b?.plugin_id || '').trim();
if (!pid) throw new ApiError(400, 'plugin_id 不能为空');
const note = String(b?.note === undefined || b?.note === null ? '' : b.note).trim().slice(0, 500);
if (!note) {
await this.noteRepo.delete({ account: acct, pluginId: pid });
return { ok: true, plugin_id: pid, note: '' };
}
await this.noteRepo.manager.query(
`INSERT INTO plugin_notes(account, plugin_id, note, device_id, created_at, updated_at)
VALUES (?,?,?,?,NOW(),NOW())
ON DUPLICATE KEY UPDATE note = VALUES(note), device_id = VALUES(device_id), updated_at = NOW()`,
[acct, pid, note, String(b?.device_id || '')]
);
return { ok: true, plugin_id: pid, note };
}
}
@@ -194,6 +194,9 @@ export class RunLogEntity {
@Column({ name: 'summary', type: 'text', comment: '运行结论摘要' })
summary: string;
@Column({ name: 'note', type: 'varchar', length: 500, default: '', comment: '本次运行备注快照(执行时插件页的备注)' })
note: string;
@Column({ name: 'started', type: 'bigint', unsigned: true, default: 0, comment: '开始时间(epoch 秒)' })
started: number;
@@ -214,6 +217,35 @@ export class RunLogEntity {
uploadedAt: Date;
}
/**
* 插件备注(账号 × 插件 唯一):客户端插件页填写的长期备注,回传中心机留档。
* 与 run_logs.note 的区别:这里是「当前最新备注」(可改可清空),run_logs.note 是「那次执行时的快照」。
*/
@Entity('plugin_notes')
@Index('uk_account_plugin', ['account', 'pluginId'], { unique: true })
export class PluginNoteEntity {
@PrimaryGeneratedColumn({ name: 'id', type: 'bigint', unsigned: true, comment: '记录自增ID' })
id: number;
@Column({ name: 'account', type: 'varchar', length: 64, default: '', comment: '账号(工号)' })
account: string;
@Column({ name: 'plugin_id', type: 'varchar', length: 64, default: '', comment: '插件ID' })
pluginId: string;
@Column({ name: 'note', type: 'varchar', length: 500, default: '', comment: '备注内容(账号对该插件的说明)' })
note: string;
@Column({ name: 'device_id', type: 'varchar', length: 64, default: '', comment: '最后修改设备ID' })
deviceId: string;
@Column({ name: 'created_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP', comment: '创建时间' })
createdAt: Date;
@Column({ name: 'updated_at', type: 'datetime', default: () => 'CURRENT_TIMESTAMP', onUpdate: 'CURRENT_TIMESTAMP', comment: '更新时间' })
updatedAt: Date;
}
/**
* 客户端壳日志元数据(内容存 logs/shell/<device_id>.log,增量追加)
*/
@@ -74,14 +74,15 @@ export class CenterLogService {
const logJson = JSON.stringify(logs);
await this.runRepo.manager.query(
`INSERT INTO run_logs(run_id, account, device_id, plugin_id, name, version, trigger_by,
schedule_id, status, ok, error, summary, started, finished, duration_sec, log_count,
schedule_id, status, ok, error, summary, note, started, finished, duration_sec, log_count,
logs, uploaded_at)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)
ON DUPLICATE KEY UPDATE
account = VALUES(account), device_id = VALUES(device_id), plugin_id = VALUES(plugin_id),
name = VALUES(name), version = VALUES(version), trigger_by = VALUES(trigger_by),
schedule_id = VALUES(schedule_id), status = VALUES(status), ok = VALUES(ok),
error = VALUES(error), summary = VALUES(summary), started = VALUES(started),
error = VALUES(error), summary = VALUES(summary), note = VALUES(note),
started = VALUES(started),
finished = VALUES(finished), duration_sec = VALUES(duration_sec),
log_count = VALUES(log_count), logs = VALUES(logs), uploaded_at = NOW()`,
[
@@ -97,6 +98,7 @@ export class CenterLogService {
Number(!!payload?.ok),
String(payload?.error || ''),
String(payload?.summary || ''),
String(payload?.note || '').slice(0, 500),
Number(payload?.started || 0),
Number(payload?.finished || 0),
Number(payload?.duration_sec || 0),
@@ -126,9 +128,9 @@ export class CenterLogService {
else if (vals.length > 1) { cond.push(`status IN (${vals.map(() => '?').join(',')})`); args.push(...vals); }
}
if ((opts?.q || '').trim()) {
cond.push('(name LIKE ? OR plugin_id LIKE ? OR account LIKE ? OR device_id LIKE ? OR error LIKE ? OR summary LIKE ?)');
cond.push('(name LIKE ? OR plugin_id LIKE ? OR account LIKE ? OR device_id LIKE ? OR error LIKE ? OR summary LIKE ? OR note LIKE ?)');
const kw = `%${opts.q.trim()}%`;
args.push(kw, kw, kw, kw, kw, kw);
args.push(kw, kw, kw, kw, kw, kw, kw);
}
if (Number(opts?.days || 0) > 0) { cond.push('uploaded_at >= DATE_SUB(NOW(), INTERVAL ? DAY)'); args.push(Number(opts.days)); }
const where = cond.length ? ' WHERE ' + cond.join(' AND ') : '';
@@ -136,7 +138,7 @@ export class CenterLogService {
const totalRow: any = (await m.query(`SELECT COUNT(*) AS c FROM run_logs${where}`, args))[0];
const rows: any[] = await m.query(
`SELECT id, run_id, account, device_id, plugin_id, name, version,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary, note,
started, finished, duration_sec, log_count, uploaded_at
FROM run_logs${where} ORDER BY id DESC LIMIT ? OFFSET ?`,
[...args, pageSize, offset]
@@ -158,7 +160,7 @@ export class CenterLogService {
if (!rid) return null;
const rows: any[] = await this.runRepo.manager.query(
`SELECT id, run_id, account, device_id, plugin_id, name, version,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary,
trigger_by AS \`trigger\`, schedule_id, status, ok, error, summary, note,
started, finished, duration_sec, log_count, logs, uploaded_at
FROM run_logs WHERE run_id = ?`,
[rid]
@@ -171,7 +173,7 @@ export class CenterLogService {
id: Number(r.id), run_id: r.run_id, account: r.account || '', device_id: r.device_id || '',
plugin_id: r.plugin_id || '', name: r.name || '', version: r.version || '',
trigger: r.trigger || '', schedule_id: r.schedule_id || '', status: r.status || '',
ok: Number(r.ok || 0), error: r.error || '', summary: r.summary || '',
ok: Number(r.ok || 0), error: r.error || '', summary: r.summary || '', note: r.note || '',
started: Number(r.started || 0), finished: Number(r.finished || 0),
duration_sec: Number(r.duration_sec || 0), log_count: Number(r.log_count || 0),
logs: Array.isArray(logsArr) ? logsArr : [],