feat: 初始化项目结构并添加核心功能模块

- 新增文档模板和导航结构
- 实现服务器基础API路由和控制器
- 添加扩展插件配置和前端框架
- 引入多租户和权限管理模块
- 集成日志和数据库配置
- 添加核心业务模型和类型定义
This commit is contained in:
2026-03-17 22:07:19 +08:00
parent c0870dce50
commit 136c2fa579
728 changed files with 107690 additions and 5614 deletions

View File

@@ -0,0 +1,72 @@
import db from '../config/database';
import { AuditService } from './AuditService';
import { AIService } from './AIService';
import { FeatureGovernanceService } from '../core/governance/FeatureGovernanceService';
/**
* [BIZ_ECO_02] 基于博弈论的供应商价值共享模型 (Eco Value Sharing)
* 负责在租户与供应商之间,基于历史表现、利润贡献与风险承担,利用博弈论模型自动分配额外增值收益
*/
export class EcoValueSharingService {
/**
* 计算并执行价值分配
*/
static async calculateAndShare(
tenantId: string,
supplierId: string,
totalIncrementalProfit: number,
traceId: string
): Promise<number> {
// Feature Flag Check
if (!(await FeatureGovernanceService.isEnabled('BIZ_ECO_VALUE_SHARING', tenantId))) {
return 0;
}
// 1. 获取博弈因子 (租户忠诚度、供应商交期稳定性、质量分)
const gameFactors = await AIService.getEcoGameFactors(tenantId, supplierId);
// 2. 运行博弈论分配模型 (Shapley Value 或 Nash Equilibrium 模拟)
const sharingLogic = await AIService.runValueSharingGame(totalIncrementalProfit, gameFactors);
const supplierShare = sharingLogic.supplierAmount;
await db.transaction(async (trx) => {
// 3. 记录分配快照
const [id] = await trx('cf_eco_value_sharing').insert({
tenant_id: tenantId,
supplier_id: supplierId,
shared_profit_amount: supplierShare,
sharing_logic: JSON.stringify(sharingLogic),
status: 'CALCULATED'
});
// 4. 执行资金拨付 (模拟)
await trx('cf_eco_value_sharing')
.where({ id })
.update({
status: 'TRANSFERRED',
updated_at: db.fn.now()
});
// 5. 审计记录
await AuditService.log({
tenant_id: tenantId,
action: 'ECO_VALUE_SHARED',
target_type: 'SUPPLIER_RELATION',
target_id: supplierId,
trace_id: traceId,
new_data: JSON.stringify({ sharedAmount: supplierShare, totalProfit: totalIncrementalProfit }),
metadata: JSON.stringify({ model: 'Nash Equilibrium' })
});
});
return supplierShare;
}
/**
* 获取租户所有价值共享记录
*/
static async getSharingHistory(tenantId: string) {
return await db('cf_eco_value_sharing')
.where({ tenant_id: tenantId })
.orderBy('created_at', 'desc');
}
}