wangrong
2026-09-20 dc77841fcc93a5078469bf8dd5d6824d1c63f073
src/modules/report/service/taskservicesite.ts
@@ -58,8 +58,8 @@
        // 映射表:将明细里的 garbageType 映射到你 Entity 里的字段后缀
        const typeKeyMap: Record<string, string> = {
            'SW60': 'Sw60', 'SW61': 'Sw61', 'SW62': 'Sw62', 'SW63': 'Sw63', 'SW64': 'Sw64',
            '900-001-S62': 'Sw62001', '900-002-S62': 'Sw62002', '900-003-S62': 'Sw62003',
            '900-004-S62': 'Sw62004', '900-005-S62': 'Sw62005', '900-006-S62': 'Sw62006', '900-007-S62': 'Sw62007'
            'Sw62001': 'Sw62001', 'Sw62002': 'Sw62002', 'Sw62003': 'Sw62003',
            'Sw62004': 'Sw62004', 'Sw62005': 'Sw62005', 'Sw62006': 'Sw62006', 'Sw62007': 'Sw62007'
        };
@@ -142,12 +142,14 @@
            for (let i = 0; i < finalRecords.length; i += chunkSize) {
                const chunk = finalRecords.slice(i, i + chunkSize);
                await this.reportDailysiteEntity.createQueryBuilder()
                const result = await this.reportDailysiteEntity.createQueryBuilder()
                    .insert()
                    .values(chunk)
                    // 💡 显式声明:当 ['date', 'siteId'] 发生冲突时,强行把 allUpdateFields 里的字段全部更新一遍
                    .orUpdate(allUpdateFields, ['date', 'siteId'])
                    .updateEntity(false)        // ← 加这一行,跳过 ReturningResultsEntityUpdator
                    .execute();
                console.log(`[SITE-UPSERT-OK] date=${targetDate} chunk=${chunk} raw=${JSON.stringify(result?.raw)}`);
            }
        }