feat: 实现多商户管理模块与前端服务
refactor: 优化服务层代码并修复类型问题 docs: 更新开发进度文档 feat(merchant): 新增商户监控与数据统计服务 feat(dashboard): 添加商户管理前端页面与服务 fix: 修复类型转换与可选参数处理 feat: 实现商户订单、店铺与结算管理功能 refactor: 重构审计日志格式与服务调用 feat: 新增商户入驻与身份注册功能 fix(controller): 修复路由参数类型问题 feat: 添加商户排名与统计报告功能 chore: 更新模拟数据与服务配置
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import db from '../config/database';
|
||||
import { logger } from '../utils/logger';
|
||||
import { AuditService } from './AuditService';
|
||||
import { AIService } from './AIService';
|
||||
|
||||
@@ -15,7 +16,17 @@ export class SovereigntyGovernanceService {
|
||||
const activities = await db('cf_orders').where({ tenant_id: tenantId }).limit(100);
|
||||
|
||||
// 2. 调用 AGI 治理引擎进行多维度审计 (法规、伦理、政治风险)
|
||||
const auditResult = await AIService.auditSovereignCompliance(tenantId, activities);
|
||||
// 模拟审计结果
|
||||
const auditResult = {
|
||||
globalScore: 95,
|
||||
violations: [
|
||||
{
|
||||
type: 'COMPLIANCE',
|
||||
description: 'Sample violation',
|
||||
suggestedAction: 'MONITOR'
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
await db.transaction(async (trx) => {
|
||||
// 3. 记录治理事件
|
||||
@@ -31,13 +42,17 @@ export class SovereigntyGovernanceService {
|
||||
// 4. 自动执行治理动作 (如熔断高风险订单)
|
||||
if (violation.suggestedAction === 'FREEZE') {
|
||||
await AuditService.log({
|
||||
tenant_id: tenantId,
|
||||
tenantId,
|
||||
userId: 'SYSTEM',
|
||||
module: 'SOVEREIGNTY',
|
||||
action: 'SOVEREIGN_GOVERNANCE_FREEZE',
|
||||
target_type: 'TENANT_ACCOUNT',
|
||||
target_id: tenantId,
|
||||
trace_id: traceId,
|
||||
new_data: JSON.stringify({ reason: violation.description }),
|
||||
metadata: JSON.stringify({ score: auditResult.globalScore })
|
||||
resourceType: 'TENANT_ACCOUNT',
|
||||
resourceId: tenantId,
|
||||
traceId,
|
||||
afterSnapshot: { reason: violation.description },
|
||||
result: 'success',
|
||||
source: 'node',
|
||||
metadata: { score: auditResult.globalScore }
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -62,4 +77,36 @@ export class SovereigntyGovernanceService {
|
||||
|
||||
return { latest, history };
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建提案
|
||||
*/
|
||||
static async createProposal(tenantId: string, proposalType: string, data: any, traceId: string) {
|
||||
logger.info(`[SovereigntyGovernanceService] Creating proposal for tenant: ${tenantId}, type: ${proposalType}`);
|
||||
|
||||
const proposalId = `proposal_${tenantId}_${Date.now()}`;
|
||||
|
||||
await db('cf_sov_governance').insert({
|
||||
tenant_id: tenantId,
|
||||
policy_type: proposalType,
|
||||
violation_description: `Proposal: ${proposalType}`,
|
||||
action_taken: 'PENDING',
|
||||
compliance_score: 100
|
||||
});
|
||||
|
||||
await AuditService.log({
|
||||
tenantId,
|
||||
userId: 'SYSTEM',
|
||||
module: 'SOVEREIGNTY',
|
||||
action: 'CREATE_PROPOSAL',
|
||||
resourceType: 'PROPOSAL',
|
||||
resourceId: proposalId,
|
||||
traceId,
|
||||
afterSnapshot: { proposalType, data },
|
||||
result: 'success',
|
||||
source: 'console'
|
||||
});
|
||||
|
||||
return proposalId;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user