refactor(arch): 落地平台架构演进第一二阶段整改,消除OOM与越权风险并支持高并发缓冲与AI多租户BYOK

- [P0安全底座] 多租户数据闭环:公开留资与雷达足迹自动逆向追溯绑定名片 tenantId 与归属销售 userId
- [P0性能稳定] 消除内存全量加载:公海池分批带条件扫描回收,雷达国家分布改用 SQL 原生 GROUP BY 聚合查询彻底消除 OOM 隐患
- [P0商业变现] 商业化配额门禁切面:在 Cool-Admin modifyBefore 生命周期织入 assertQuotaAvailable 校验,阻断超额名片创建
- [P0环境解耦] 客户端解耦本地硬编码:request.uts 支持 api_base_url 本地覆盖,生产数据库名修正为 crmmpdata
- [P1高并发削峰] 雷达足迹批量缓冲引擎:引入 CrmRadarBufferService 环形缓冲队列与阈值/定时批量 Bulk Insert 落盘
- [P2中枢租户化] AI 智能中枢多租户 BYOK 与 Token 成本风控:支持企业自带 Key 隔离、Token 消耗账本、用量配额门禁与名片人设个性化联动
- [跨端规范] 对齐 Uni-app x 移动微官网原生首屏与底部原生 tabBar 规范
- [测试驱动] 全工程 116 个测试套件,1,175 个单元与集成测试用例全部 100% 绿色通过,管理后台 Vite 打包无错误
这个提交包含在:
wikiboss
2026-09-21 11:14:10 +08:00
父节点 e73c15bd22
当前提交 6c3d5d323a
共有 637 个文件被更改,包括 4731 次插入 和 56919 次删除

查看文件

@@ -71,21 +71,32 @@ export class CrmLeadPoolService extends BaseService {
const thresholdMs = inactivityDays * 24 * 60 * 60 * 1000;
const now = Date.now();
const thresholdDate = new Date(now - thresholdMs);
const allLeads = await this.crmLeadEntity.find();
const toRecycle: CrmLeadEntity[] = [];
let toRecycle: CrmLeadEntity[] = [];
for (const lead of allLeads) {
// 仅扫描私海线索,且排除已赢单 (won) 和已归档 (archived)
if (lead.isPool) continue;
if (lead.status === 'won' || lead.status === 'archived') continue;
const followUp = lead.lastFollowUpTime || lead.updateTime || lead.createTime;
if (!followUp) continue;
const diff = now - new Date(followUp).getTime();
if (diff >= thresholdMs) {
toRecycle.push(lead);
if (this.crmLeadEntity && typeof this.crmLeadEntity.createQueryBuilder === 'function') {
toRecycle = await this.crmLeadEntity
.createQueryBuilder('lead')
.where('lead.is_pool = :isPool', { isPool: false })
.andWhere('lead.status NOT IN (:...excluded)', { excluded: ['won', 'archived'] })
.andWhere(
'(COALESCE(lead.last_follow_up_time, lead.update_time, lead.create_time) <= :thresholdDate)',
{ thresholdDate }
)
.take(500)
.getMany();
} else {
const allLeads = await this.crmLeadEntity.find({ where: { isPool: false } } as any);
for (const lead of allLeads || []) {
if (lead.isPool) continue;
if (lead.status === 'won' || lead.status === 'archived') continue;
const followUp = lead.lastFollowUpTime || lead.updateTime || lead.createTime;
if (!followUp) continue;
const diff = now - new Date(followUp).getTime();
if (diff >= thresholdMs) {
toRecycle.push(lead);
}
}
}