Files
makemd/server/src/services/TaxIncentivesService.ts

58 lines
1.9 KiB
TypeScript
Raw Normal View History

import db from '../config/database';
import { AuditService } from './AuditService';
import { AIService } from './AIService';
/**
* [BIZ_FIN_16]
* IOSS 退
*/
export class TaxIncentivesService {
/**
*
*/
static async discoverIncentives(tenantId: string, countryCode: string, traceId: string): Promise<void> {
// 1. 获取该地区的最新税务政策 (模拟调用 AI 服务分析全球税法库)
const policies = await AIService.searchTaxPolicies(countryCode);
for (const policy of policies) {
// 检查是否已记录
const existing = await db('cf_tax_incentives')
.where({ tenant_id: tenantId, country_code: countryCode, policy_name: policy.name })
.first();
if (!existing) {
await db.transaction(async (trx) => {
const [id] = await trx('cf_tax_incentives').insert({
tenant_id: tenantId,
country_code: countryCode,
policy_name: policy.name,
description: policy.description,
estimated_savings: policy.estimatedSavings,
status: 'DISCOVERED'
});
// 审计记录
await AuditService.log({
tenant_id: tenantId,
action: 'TAX_INCENTIVE_DISCOVERED',
target_type: 'TAX_INCENTIVE',
target_id: id.toString(),
trace_id: traceId,
new_data: JSON.stringify({ policyName: policy.name, estimatedSavings: policy.estimatedSavings }),
metadata: JSON.stringify({ countryCode })
});
});
}
}
}
/**
*
*/
static async getIncentives(tenantId: string) {
return await db('cf_tax_incentives')
.where({ tenant_id: tenantId })
.orderBy('estimated_savings', 'desc');
}
}