Files
X-Financial/web/src/views/scripts/AuditView.js

619 lines
24 KiB
JavaScript
Raw Normal View History

import { computed, ref, watch } from 'vue'
const TYPE_META = {
skills: {
createButtonLabel: '新建 Skill',
hintText: 'Skills 对应报销审查规则 .md 文件,点击任意行查看规则配置与命中产出。',
filters: ['按规则场景筛选', '按风险等级筛选', '按负责人筛选'],
tableColumns: {
name: '规则文件',
category: '规则分类',
owner: '负责人',
scope: '适用范围',
runtime: '执行节点',
version: '版本',
metric: '命中率'
}
},
mcp: {
createButtonLabel: '接入 MCP',
hintText: 'MCP 管理外部服务连接如发票验真、预算、银行流水、OCR 与差旅平台。',
filters: ['按服务类型筛选', '按权限筛选', '按状态筛选'],
tableColumns: {
name: 'MCP 服务',
category: '服务类型',
owner: '维护人',
scope: '服务范围',
runtime: '调用方式',
version: '协议',
metric: '可用率'
}
},
schedules: {
createButtonLabel: '新建定时任务',
hintText: '定时任务用于每日风险检查、知识积累、报销报账和账款信息统计。',
filters: ['按运行频率筛选', '按产出类型筛选', '按告警级别筛选'],
tableColumns: {
name: '任务名称',
category: '任务类型',
owner: '负责人',
scope: '统计范围',
runtime: '运行计划',
version: '调度',
metric: '成功率'
}
}
}
function buildAsset({
type,
typeLabel,
id,
short,
name,
summary,
category,
owner,
reviewer = '待分配',
scope,
model,
version,
status,
statusTone,
hitRate,
updatedAt,
badgeTone,
triggerMode,
spotlight = false,
fields,
sections,
rules,
checks,
triggers,
tools,
history,
titles,
publish,
markdownContent = ''
}) {
return {
type,
typeLabel,
id,
short,
name,
summary,
category,
owner,
reviewer,
scope,
model,
version,
status,
statusTone,
hitRate,
updatedAt,
badgeTone,
triggerMode,
spotlight,
markdownContent,
fields,
promptSections: sections,
outputRules: rules,
tests: checks,
triggers,
tools,
history,
configTitle: titles.configTitle,
configDesc: titles.configDesc,
detailTitle: titles.detailTitle,
detailDesc: titles.detailDesc,
outputTitle: titles.outputTitle,
outputDesc: titles.outputDesc,
ruleListTitle: titles.ruleListTitle,
checkListTitle: titles.checkListTitle,
triggerTitle: titles.triggerTitle,
triggerDesc: titles.triggerDesc,
toolTitle: titles.toolTitle,
toolDesc: titles.toolDesc,
historyTitle: titles.historyTitle,
historyDesc: titles.historyDesc,
publishTitle: titles.publishTitle,
publishDesc: titles.publishDesc,
publishMeta: publish.meta,
publishState: publish.state,
heroStats: [
{ label: type === 'schedules' ? '调度计划' : '版本', value: version },
{ label: '状态', value: status, kind: 'status' },
{ label: type === 'mcp' ? '服务可用率' : type === 'schedules' ? '运行成功率' : '触发命中率', value: hitRate },
{ label: '负责人', value: owner }
]
}
}
const assets = [
buildAsset({
type: 'skills',
typeLabel: 'Skills',
id: 'SKL-001',
short: 'DR',
name: '重复报销识别规则.md',
summary: '识别同一发票号、金额、商户和日期组合下的重复报销风险。',
category: '报销审查规则',
owner: '财务风控组',
reviewer: '周敏',
scope: '发票与费用明细',
model: '提交时 + 夜间复核',
version: 'v1.9',
status: '已上线',
statusTone: 'success',
hitRate: '96.8%',
updatedAt: '2026-05-09 08:10',
badgeTone: 'emerald',
triggerMode: '申请提交 / 财务初审 / 夜间批扫',
spotlight: true,
fields: [
{ label: '规则名称', value: '重复报销识别规则.md' },
{ label: '文件路径', value: 'skills/reimbursement/duplicate-invoice.md' },
{ label: '规则等级', value: '高风险' },
{ label: '执行节点', value: '提交时 + 夜间复核' }
],
markdownContent: `# 重复报销识别规则
## 目标
识别同一发票同一商户金额组合或高度相似附件导致的重复报销风险
## 适用范围
- 费用类型差旅办公采购业务招待供应商报账
- 执行节点申请提交财务初审夜间批扫
- 风险等级高风险
## 输入字段
- invoice_code发票代码
- invoice_number发票号码
- seller_name销售方名称
- seller_tax_no销售方税号
- total_amount价税合计金额
- issue_date开票日期
- attachment_hash附件影像哈希
- applicant_id申请人
- reimbursement_id当前报销单号
## 判断规则
1. 发票代码和发票号码均一致时直接命中高风险
2. 发票号码缺失时销售方金额开票日期和附件哈希相似度超过 0.92进入人工复核
3. 已驳回或已作废单据只作为参考证据不直接判定重复
4. 同一供应商周期性账单需按账期字段排除误报
## 输出
\`\`\`json
{
"risk_code": "duplicate_invoice",
"risk_level": "high",
"matched_reimbursement_ids": [],
"evidence": [],
"suggestion": "人工复核或要求申请人补充说明"
}
\`\`\`
## 管理员备注
- 调整阈值前需要抽样复核最近 7 日误报样例
- 新增排除条件必须补充测试样例`,
sections: [
{ title: '输入字段', intent: '审查依赖', content: '发票号、销售方、金额、开票日期、附件 OCR、历史报销单号、提交人和成本中心。' },
{ title: '判断逻辑', intent: '规则主体', content: '同一发票号直接命中;发票号缺失时按销售方、金额、日期和影像哈希计算相似度。' },
{ title: '输出格式', intent: '风险结果', content: '输出重复风险标签、历史单据编号、相似字段、相似度和建议处置动作。' }
],
rules: ['命中同一发票号时必须标记高风险。', '相似度超过 0.92 时进入人工复核。', '必须返回历史单据证据,不允许只给结论。'],
checks: [
{ name: '同发票号重复', input: '发票号完全一致', result: '通过', tone: 'success' },
{ name: '影像相似重复', input: '发票号模糊但金额日期一致', result: '通过', tone: 'success' },
{ name: '商户简称误报', input: '同商户不同日期', result: '待评审', tone: 'warning' }
],
triggers: ['重复发票', '重复报销', '历史账本比对', '夜间风险扫描'],
tools: [
{ name: '发票 OCR MCP', scope: '票面字段识别', mode: '只读', tone: 'safe' },
{ name: '报销账本', scope: '历史单据检索', mode: '只读', tone: 'safe' },
{ name: '风险标记服务', scope: '写入审查结果', mode: '写入', tone: 'active' }
],
history: [
{ version: 'v1.9', note: '收紧金额差异阈值', time: '05-09 08:10' },
{ version: 'v1.8', note: '加入附件哈希比对', time: '05-06 18:30' },
{ version: 'v1.7', note: '补充同供应商周期账单排除条件', time: '05-02 16:15' },
{ version: 'v1.6', note: '增加历史驳回单据参考证据', time: '04-28 11:20' },
{ version: 'v1.5', note: '上线发票号精确匹配规则', time: '04-22 09:40' }
],
titles: {
configTitle: '规则文件配置',
configDesc: 'Skills 以 .md 文件维护报销审查规则,配置规则路径、等级和执行节点。',
detailTitle: '规则结构',
detailDesc: '按输入字段、判断逻辑和输出格式组织审查规则。',
outputTitle: '产出与校验',
outputDesc: '确保规则能稳定输出风险标签、证据和处置建议。',
ruleListTitle: '输出要求',
checkListTitle: '测试样例',
triggerTitle: '触发规则',
triggerDesc: '当前命中策略',
toolTitle: '依赖能力',
toolDesc: '规则运行时调用',
historyTitle: '版本历史',
historyDesc: '最近变更',
publishTitle: '发布控制',
publishDesc: '规则已通过核心样例,可进入线上审查链路。',
},
publish: { meta: '最近评审2026-05-09 08:10', state: '可发布' }
}),
buildAsset({
type: 'skills',
typeLabel: 'Skills',
id: 'SKL-002',
short: 'TS',
name: '差旅标准超额检查.md',
summary: '按城市、职级和费用类型检查差旅报销是否超过制度标准。',
category: '差旅审查规则',
owner: '制度运营组',
reviewer: '刘佳',
scope: '差旅报销',
model: '提交时触发',
version: 'v2.4',
status: '待评审',
statusTone: 'warning',
hitRate: '91.4%',
updatedAt: '2026-05-08 18:35',
badgeTone: 'amber',
triggerMode: '申请提交 / 审批中心',
fields: [
{ label: '规则名称', value: '差旅标准超额检查.md' },
{ label: '文件路径', value: 'skills/travel/standard-overrun.md' },
{ label: '规则等级', value: '中高风险' },
{ label: '执行节点', value: '提交时触发' }
],
markdownContent: `# 差旅标准超额检查
## 目标
根据公司差旅制度检查住宿交通餐补等费用是否超过员工职级和城市等级对应标准
## 适用范围
- 单据类型差旅报销差旅借款冲销
- 费用类型住宿机票火车票出租车餐补
- 执行节点申请提交审批中心
## 输入字段
- employee_grade员工职级
- destination_city目的地城市
- city_tier城市等级
- expense_type费用类型
- expense_amount费用金额
- travel_days出差天数
- policy_refs制度条款映射
- exception_reason例外说明
## 判断规则
1. 按城市等级和员工职级读取报销标准上限
2. 单项费用超过标准时计算超额金额和超额比例
3. 会议指定酒店客户指定地点等例外原因存在时转人工复核
4. 无例外说明且超额比例超过 20%标记中高风险
## 输出
\`\`\`json
{
"risk_code": "travel_standard_overrun",
"risk_level": "medium_high",
"over_limit_amount": 0,
"policy_refs": [],
"exception_required": true,
"suggestion": "补充例外说明或调整报销金额"
}
\`\`\`
## 管理员备注
- 城市等级表每季度同步一次
- 制度条款更新后必须同步更新 policy_refs`,
sections: [
{ title: '制度映射', intent: '条款来源', content: '关联城市等级、员工职级、住宿/交通/餐补标准和例外审批条款。' },
{ title: '判断逻辑', intent: '标准比对', content: '按目的地城市等级和职级读取上限,逐条计算超额金额。' },
{ title: '输出格式', intent: '审批依据', content: '输出超额金额、制度引用、例外条件和补充说明要求。' }
],
rules: ['必须给出超额金额。', '必须引用制度条款。', '例外审批必须标记人工复核。'],
checks: [
{ name: '住宿超标', input: '一线城市住宿超 18%', result: '通过', tone: 'success' },
{ name: '会议酒店例外', input: '指定会议酒店超标', result: '评审中', tone: 'warning' }
],
triggers: ['差旅标准', '住宿超标', '交通超标', '例外审批'],
tools: [
{ name: '制度知识库', scope: '条款引用', mode: '只读', tone: 'safe' },
{ name: '员工组织服务', scope: '职级与部门', mode: '只读', tone: 'safe' }
],
history: [
{ version: 'v2.4', note: '新增会议酒店例外分支', time: '05-08 18:35' },
{ version: 'v2.3', note: '同步 2026 差旅制度', time: '05-06 10:20' },
{ version: 'v2.2', note: '调整新一线城市住宿上限', time: '05-01 14:05' },
{ version: 'v2.1', note: '增加餐补按天数校验', time: '04-25 17:30' },
{ version: 'v2.0', note: '重构城市等级映射表', time: '04-18 10:10' }
],
titles: {
configTitle: '规则文件配置',
configDesc: '维护差旅制度条款映射、城市等级表和例外审批条件。',
detailTitle: '规则结构',
detailDesc: '按制度映射、判断逻辑和输出格式组织规则。',
outputTitle: '产出与校验',
outputDesc: '超额检查结果进入审批意见和员工补充说明。',
ruleListTitle: '输出要求',
checkListTitle: '测试样例',
triggerTitle: '触发规则',
triggerDesc: '当前命中策略',
toolTitle: '依赖能力',
toolDesc: '规则运行时调用',
historyTitle: '版本历史',
historyDesc: '最近变更',
publishTitle: '评审控制',
publishDesc: '当前规则仍有例外分支待评审。',
},
publish: { meta: '最近评审2026-05-08 18:35', state: '待评审' }
}),
buildAsset({
type: 'mcp',
typeLabel: 'MCP',
id: 'MCP-001',
short: 'IV',
name: '发票验真 MCP',
summary: '连接税务票据验真、OCR 识别和发票状态查询能力。',
category: '票据服务',
owner: '平台集成组',
scope: '发票验真',
model: 'API 调用',
version: 'MCP 1.0',
status: '健康',
statusTone: 'success',
hitRate: '99.3%',
updatedAt: '2026-05-09 07:50',
badgeTone: 'blue',
triggerMode: '规则调用 / 批量任务调用',
fields: [
{ label: '服务名称', value: '发票验真 MCP' },
{ label: '服务地址', value: 'mcp://invoice-verification' },
{ label: '鉴权方式', value: 'API Key + IP 白名单' },
{ label: '降级策略', value: '转 OCR 本地解析并标记待验真' }
],
sections: [
{ title: '输入参数', intent: '服务调用', content: '附件文件、发票代码、发票号码、开票日期、金额和请求来源 trace_id。' },
{ title: '调用链路', intent: '外部服务', content: '先 OCR 识别票面字段,再调用验真接口查询真伪、作废、红冲状态。' },
{ title: '返回结构', intent: '标准输出', content: '返回票据字段、验真状态、异常原因、耗时和外部服务流水号。' }
],
rules: ['超时时间 8 秒。', '只读外部系统,不写入第三方。', '失败时必须返回可降级状态。'],
checks: [
{ name: '健康检查', input: '最近一次探活', result: '通过', tone: 'success' },
{ name: '批量验真', input: '436 张票据', result: '通过', tone: 'success' }
],
triggers: ['发票 OCR', '验真查询', '作废红冲', '重复报销规则'],
tools: [
{ name: '税务票据平台', scope: '验真查询', mode: '外部', tone: 'active' },
{ name: '密钥管理', scope: 'API Key 加密', mode: '安全', tone: 'safe' }
],
history: [
{ version: '07:50', note: '健康检查通过,延迟 580ms', time: '今日' },
{ version: '02:00', note: '夜间任务批量核验 436 张票据', time: '今日' }
],
titles: {
configTitle: 'MCP 连接配置',
configDesc: '配置外部服务地址、鉴权方式、权限范围和失败降级策略。',
detailTitle: '服务协议',
detailDesc: '按输入参数、调用链路和返回结构描述 MCP 能力。',
outputTitle: '返回与检查',
outputDesc: '服务输出会被审查规则、审批中心和定时任务消费。',
ruleListTitle: '调用约束',
checkListTitle: '健康检查',
triggerTitle: '服务场景',
triggerDesc: '当前被哪些能力调用',
toolTitle: '外部依赖',
toolDesc: 'MCP 背后连接',
historyTitle: '调用记录',
historyDesc: '最近运行',
publishTitle: '连接状态',
publishDesc: '服务健康,可供规则与定时任务调用。',
},
publish: { meta: '最近探活2026-05-09 07:50', state: '可用' }
}),
buildAsset({
type: 'schedules',
typeLabel: '定时任务',
id: 'JOB-001',
short: 'RK',
name: '每日风险巡检',
summary: '每天定时检查报销、报账、发票和账款数据,输出待处理风险队列。',
category: '风险巡检',
owner: '财务风控组',
scope: '全量待审与已付单据',
model: '每天 02:00',
version: '0 2 * * *',
status: '已调度',
statusTone: 'success',
hitRate: '100%',
updatedAt: '2026-05-09 02:18',
badgeTone: 'emerald',
triggerMode: 'Cron 定时调度',
fields: [
{ label: '任务名称', value: '每日风险巡检' },
{ label: 'Cron', value: '0 2 * * *' },
{ label: '扫描窗口', value: 'T-1 00:00 至 23:59' },
{ label: '告警阈值', value: '高风险 >= 10 或单笔 >= 50,000' }
],
sections: [
{ title: '数据抽取', intent: '扫描范围', content: '读取昨日新增报销、报账、发票、付款流水和审批反馈。' },
{ title: '规则执行', intent: '风险判断', content: '运行重复报销、超标、作废票、异常付款等 Skills并调用必要 MCP。' },
{ title: '结果写入', intent: '任务产出', content: '生成风险日报、风险工单、审计日志,并通知负责人。' }
],
rules: ['任务失败必须告警。', '每次运行记录规则版本和扫描窗口。', '高风险工单必须进入审批中心。'],
checks: [
{ name: '今日运行', input: '扫描 2146 条记录', result: '成功', tone: 'success' },
{ name: '高风险推送', input: '19 条风险工单', result: '成功', tone: 'success' }
],
triggers: ['每日风险检查', '发票验真', '账款核对', '风险日报'],
tools: [
{ name: '报销审查 Skills', scope: '规则执行', mode: '调用', tone: 'active' },
{ name: '发票验真 MCP', scope: '票据核验', mode: '调用', tone: 'active' },
{ name: '账款流水 MCP', scope: '付款核对', mode: '调用', tone: 'active' }
],
history: [
{ version: '02:18', note: '今日运行成功,生成 19 条高风险工单', time: '今日' },
{ version: '02:00', note: '任务开始,扫描 2026-05-08 数据', time: '今日' }
],
titles: {
configTitle: '定时任务配置',
configDesc: '配置运行频率、扫描范围、依赖能力和告警出口。',
detailTitle: '任务流程',
detailDesc: '从数据抽取、规则执行到结果写入描述调度链路。',
outputTitle: '产出与检查',
outputDesc: '定时任务产出进入风险看板、审批中心和审计留痕。',
ruleListTitle: '运行要求',
checkListTitle: '最近检查',
triggerTitle: '任务场景',
triggerDesc: '当前覆盖的日常运营事项',
toolTitle: '依赖能力',
toolDesc: '任务运行时调用',
historyTitle: '运行记录',
historyDesc: '最近执行',
publishTitle: '调度控制',
publishDesc: '任务已纳入每日自动巡检。',
},
publish: { meta: '最近运行2026-05-09 02:18', state: '已调度' }
}),
buildAsset({
type: 'schedules',
typeLabel: '定时任务',
id: 'JOB-002',
short: 'FN',
name: '每日报销报账与账款统计',
summary: '每天统计报销、报账、付款和账款信息,更新运营总览和财务日报。',
category: '财务统计',
owner: '财务运营组',
scope: '报销、报账、账款',
model: '每天 06:00',
version: '0 6 * * *',
status: '已调度',
statusTone: 'success',
hitRate: '99.1%',
updatedAt: '2026-05-09 06:12',
badgeTone: 'blue',
triggerMode: 'Cron 定时调度',
fields: [
{ label: '任务名称', value: '每日报销报账与账款统计' },
{ label: 'Cron', value: '0 6 * * *' },
{ label: '统计口径', value: '自然日 + 财务月' },
{ label: '刷新对象', value: '运营总览、财务日报、账款看板' }
],
sections: [
{ title: '账款同步', intent: '外部数据', content: '拉取银行流水、付款结果和供应商收款状态。' },
{ title: '指标聚合', intent: '统计口径', content: '按部门、费用类型、报账状态、付款状态和账龄聚合。' },
{ title: '日报刷新', intent: '看板产出', content: '写入财务日报快照,并刷新运营总览。' }
],
rules: ['统计口径必须记录。', '账款同步失败时保留上一版快照并告警。', '日报刷新后写入审计日志。'],
checks: [
{ name: '日报刷新', input: '总览指标更新', result: '成功', tone: 'success' },
{ name: '账款匹配', input: '识别 8 条超期待付款', result: '成功', tone: 'success' }
],
triggers: ['报销统计', '报账统计', '账款统计', '财务日报'],
tools: [
{ name: '账款流水 MCP', scope: '付款与流水', mode: '调用', tone: 'active' },
{ name: '报销报账数据库', scope: '统计读取', mode: '只读', tone: 'safe' }
],
history: [
{ version: '06:12', note: '日报刷新完成,总览看板已更新', time: '今日' },
{ version: '06:04', note: '账款匹配完成,识别 8 条超期待付款', time: '今日' }
],
titles: {
configTitle: '定时任务配置',
configDesc: '配置统计口径、维度、账款数据源和看板刷新策略。',
detailTitle: '任务流程',
detailDesc: '从账款同步、指标聚合到日报刷新描述调度链路。',
outputTitle: '产出与检查',
outputDesc: '统计产出用于总览、日报和账款追踪。',
ruleListTitle: '运行要求',
checkListTitle: '最近检查',
triggerTitle: '任务场景',
triggerDesc: '当前覆盖的日常运营事项',
toolTitle: '依赖能力',
toolDesc: '任务运行时调用',
historyTitle: '运行记录',
historyDesc: '最近执行',
publishTitle: '调度控制',
publishDesc: '任务已纳入每日财务运营统计。',
},
publish: { meta: '最近运行2026-05-09 06:12', state: '已调度' }
})
]
export default {
name: 'AuditView',
emits: ['detail-open-change'],
setup(props, { emit }) {
const tabs = [
{ id: 'skills', label: 'Skills' },
{ id: 'mcp', label: 'MCP' },
{ id: 'schedules', label: '定时任务' }
]
const activeType = ref('skills')
const selectedSkill = ref(null)
const versionSwitchTarget = ref(null)
const activeMeta = computed(() => TYPE_META[activeType.value])
const filters = computed(() => activeMeta.value.filters)
const createButtonLabel = computed(() => activeMeta.value.createButtonLabel)
const hintText = computed(() => activeMeta.value.hintText)
const tableColumns = computed(() => activeMeta.value.tableColumns)
const visibleSkills = computed(() => assets.filter((item) => item.type === activeType.value))
watch(
selectedSkill,
(value) => {
emit('detail-open-change', Boolean(value))
},
{ immediate: true }
)
function openVersionSwitch(version) {
if (!selectedSkill.value || version.version === selectedSkill.value.version) {
return
}
versionSwitchTarget.value = version
}
function cancelVersionSwitch() {
versionSwitchTarget.value = null
}
function confirmVersionSwitch() {
if (!selectedSkill.value || !versionSwitchTarget.value) {
return
}
selectedSkill.value.version = versionSwitchTarget.value.version
selectedSkill.value.updatedAt = versionSwitchTarget.value.time
if (versionSwitchTarget.value.markdownContent) {
selectedSkill.value.markdownContent = versionSwitchTarget.value.markdownContent
} else {
selectedSkill.value.markdownContent = `${selectedSkill.value.markdownContent}\n\n<!-- 已切换到 ${versionSwitchTarget.value.version}${versionSwitchTarget.value.note} -->`
}
versionSwitchTarget.value = null
}
return {
tabs,
filters,
activeType,
createButtonLabel,
hintText,
tableColumns,
selectedSkill,
versionSwitchTarget,
visibleSkills,
openVersionSwitch,
cancelVersionSwitch,
confirmVersionSwitch
}
}
}