NAC_Blockchain/nac-ai-compliance/src/compliance_layer.rs

174 lines
4.9 KiB
Rust
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//! 七层合规验证框架
//!
//! 基于NAC七层合规验证体系
use serde::{Deserialize, Serialize};
use chrono::{DateTime, Utc};
/// 合规层级
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ComplianceLayer {
/// 第一层基础身份验证KYC/AML
IdentityVerification,
/// 第二层:资产真实性验证
AssetAuthenticity,
/// 第三层:法律合规性验证
LegalCompliance,
/// 第四层:财务合规性验证
FinancialCompliance,
/// 第五层:税务合规性验证
TaxCompliance,
/// 第六层环境社会治理ESG合规
ESGCompliance,
/// 第七层:持续监控与审计
ContinuousMonitoring,
}
impl ComplianceLayer {
/// 获取层级编号
pub fn level(&self) -> u8 {
match self {
Self::IdentityVerification => 1,
Self::AssetAuthenticity => 2,
Self::LegalCompliance => 3,
Self::FinancialCompliance => 4,
Self::TaxCompliance => 5,
Self::ESGCompliance => 6,
Self::ContinuousMonitoring => 7,
}
}
/// 获取层级名称
pub fn name(&self) -> &'static str {
match self {
Self::IdentityVerification => "基础身份验证",
Self::AssetAuthenticity => "资产真实性验证",
Self::LegalCompliance => "法律合规性验证",
Self::FinancialCompliance => "财务合规性验证",
Self::TaxCompliance => "税务合规性验证",
Self::ESGCompliance => "ESG合规验证",
Self::ContinuousMonitoring => "持续监控与审计",
}
}
/// 获取层级描述
pub fn description(&self) -> &'static str {
match self {
Self::IdentityVerification => "验证用户身份、反洗钱AML、了解你的客户KYC",
Self::AssetAuthenticity => "验证资产真实性、所有权、估值合理性",
Self::LegalCompliance => "验证资产合法性、产权清晰、无法律纠纷",
Self::FinancialCompliance => "验证财务报表、审计报告、资金来源",
Self::TaxCompliance => "验证税务合规、纳税记录、税务筹划合法性",
Self::ESGCompliance => "验证环境保护、社会责任、公司治理",
Self::ContinuousMonitoring => "持续监控资产状态、市场变化、风险预警",
}
}
/// 获取所有层级
pub fn all() -> Vec<Self> {
vec![
Self::IdentityVerification,
Self::AssetAuthenticity,
Self::LegalCompliance,
Self::FinancialCompliance,
Self::TaxCompliance,
Self::ESGCompliance,
Self::ContinuousMonitoring,
]
}
}
/// 合规验证结果
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComplianceResult {
/// 合规层级
pub layer: ComplianceLayer,
/// 验证状态
pub status: ComplianceStatus,
/// 置信度 [0.0, 1.0]
pub confidence: f64,
/// 风险等级
pub risk_level: RiskLevel,
/// 验证详情
pub details: String,
/// 发现的问题
pub issues: Vec<ComplianceIssue>,
/// 建议措施
pub recommendations: Vec<String>,
/// 验证时间
pub timestamp: DateTime<Utc>,
}
/// 合规状态
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ComplianceStatus {
/// 通过
Passed,
/// 有条件通过
ConditionalPass,
/// 需要人工审核
ManualReview,
/// 失败
Failed,
/// 待验证
Pending,
}
/// 风险等级
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum RiskLevel {
/// 低风险
Low,
/// 中风险
Medium,
/// 高风险
High,
/// 极高风险
Critical,
}
/// 合规问题
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComplianceIssue {
/// 问题代码
pub code: String,
/// 问题描述
pub description: String,
/// 严重程度
pub severity: IssueSeverity,
/// 相关法规
pub regulations: Vec<String>,
}
/// 问题严重程度
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Serialize, Deserialize)]
pub enum IssueSeverity {
/// 信息
Info,
/// 警告
Warning,
/// 错误
Error,
/// 严重错误
Critical,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_compliance_layer() {
assert_eq!(ComplianceLayer::IdentityVerification.level(), 1);
assert_eq!(ComplianceLayer::ContinuousMonitoring.level(), 7);
assert_eq!(ComplianceLayer::all().len(), 7);
}
#[test]
fn test_risk_level_ordering() {
assert!(RiskLevel::Low < RiskLevel::Medium);
assert!(RiskLevel::Medium < RiskLevel::High);
assert!(RiskLevel::High < RiskLevel::Critical);
}
}