后端新增规则资产版本管理和规则文件 CRUD 接口,优化风险 规则生成模板执行和员工数据模型字段,知识库 RAG 增强本 地回退和文档提取能力,清理旧风险规则文件统一由生成引擎 管理,前端审计页面增加运行时调试面板和规则资产编辑交互, 补充单元测试覆盖。
128 lines
3.8 KiB
JavaScript
128 lines
3.8 KiB
JavaScript
import { normalizeText, readConfigJson, resolveRuleTemplateLabel } from './auditViewModel.js'
|
|
|
|
export function incrementVersion(version) {
|
|
const normalized = normalizeText(version).replace(/^v/i, '')
|
|
const match = normalized.match(/^(\d+)\.(\d+)\.(\d+)$/)
|
|
|
|
if (!match) {
|
|
return 'v1.0.0'
|
|
}
|
|
|
|
const major = Number(match[1])
|
|
const minor = Number(match[2])
|
|
const patch = Number(match[3]) + 1
|
|
return `v${major}.${minor}.${patch}`
|
|
}
|
|
|
|
export function buildReviewNote(status) {
|
|
if (status === 'approved') {
|
|
return '通过任务规则中心审核。'
|
|
}
|
|
if (status === 'rejected') {
|
|
return '在任务规则中心驳回当前版本。'
|
|
}
|
|
return '提交任务规则中心待审核。'
|
|
}
|
|
|
|
export function buildRuleConfigPayload(asset, runtimeRule) {
|
|
const configJson = {
|
|
...readConfigJson(asset),
|
|
runtime_kind: normalizeText(runtimeRule?.kind) || asset.runtimeKind || 'policy_rule_draft',
|
|
runtime_rule: runtimeRule
|
|
}
|
|
const templateKey = normalizeText(runtimeRule?.template_key) || asset.ruleTemplateKey
|
|
if (templateKey) {
|
|
configJson.rule_template_key = templateKey
|
|
configJson.rule_template_label = resolveRuleTemplateLabel(templateKey)
|
|
}
|
|
return configJson
|
|
}
|
|
|
|
export function buildSpreadsheetChangeRecordKey(records = []) {
|
|
const latest = records.find((item) => item?.changed_at)
|
|
if (!latest) {
|
|
return ''
|
|
}
|
|
const previewSignature = Array.isArray(latest.cell_changes)
|
|
? latest.cell_changes
|
|
.slice(0, 8)
|
|
.map((item) =>
|
|
[
|
|
item?.sheet_name,
|
|
item?.cell,
|
|
item?.change_type,
|
|
item?.before_value,
|
|
item?.after_value
|
|
]
|
|
.map((value) => normalizeText(value))
|
|
.join(':')
|
|
)
|
|
.join('|')
|
|
: ''
|
|
const sheetSignature = Array.isArray(latest.sheet_changes)
|
|
? latest.sheet_changes
|
|
.map((item) =>
|
|
[item?.sheet_name, item?.change_type]
|
|
.map((value) => normalizeText(value))
|
|
.join(':')
|
|
)
|
|
.join('|')
|
|
: ''
|
|
return [
|
|
latest.id,
|
|
latest.changed_at,
|
|
latest.actor,
|
|
latest.summary,
|
|
latest.changed_sheet_count,
|
|
latest.changed_cell_count,
|
|
sheetSignature,
|
|
previewSignature
|
|
]
|
|
.map((value) => normalizeText(value))
|
|
.join('-')
|
|
}
|
|
|
|
export function filterAuditAssets(assets = [], filters = {}) {
|
|
const normalizedKeyword = normalizeText(filters.keyword).toLowerCase()
|
|
|
|
return assets.filter((item) => {
|
|
const matchesKeyword = normalizedKeyword
|
|
? [item.name, item.code, item.summary, item.owner, item.scope]
|
|
.filter(Boolean)
|
|
.some((value) => String(value).toLowerCase().includes(normalizedKeyword))
|
|
: true
|
|
const matchesDomain = filters.selectedDomain ? item.domainValue === filters.selectedDomain : true
|
|
const matchesOwner = filters.selectedOwner ? item.owner === filters.selectedOwner : true
|
|
const matchesStatus = filters.showStatusFilter
|
|
? filters.selectedStatus
|
|
? item.statusValue === filters.selectedStatus
|
|
: true
|
|
: true
|
|
const matchesRiskScenario = filters.showRiskScenarioFilter
|
|
? filters.selectedRiskScenario
|
|
? item.riskCategory === filters.selectedRiskScenario
|
|
: true
|
|
: true
|
|
const matchesOnline = filters.showOnlineFilter
|
|
? filters.selectedOnlineState
|
|
? (filters.selectedOnlineState === 'online') === Boolean(item.isOnlineValue)
|
|
: true
|
|
: true
|
|
const matchesEnabled = filters.showEnabledFilter
|
|
? filters.selectedEnabledState
|
|
? (filters.selectedEnabledState === 'enabled') === Boolean(item.isEnabledValue)
|
|
: true
|
|
: true
|
|
|
|
return (
|
|
matchesKeyword &&
|
|
matchesDomain &&
|
|
matchesOwner &&
|
|
matchesStatus &&
|
|
matchesRiskScenario &&
|
|
matchesOnline &&
|
|
matchesEnabled
|
|
)
|
|
})
|
|
}
|