From ab09210d2847d8442866eed904834630e160528f Mon Sep 17 00:00:00 2001 From: liuyun Date: Thu, 15 Oct 2026 01:00:05 +0800 Subject: [PATCH] =?UTF-8?q?fix(c3):=20=E5=BC=82=E5=B8=B8=E5=88=97=E8=A1=A8?= =?UTF-8?q?=20visitLat/visitLng=20Decimal=20=E8=BD=AC=E5=AD=97=E7=AC=A6?= =?UTF-8?q?=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- src/abnormal/abnormal.service.spec.ts | 18 +++++++++++++++--- src/abnormal/abnormal.service.ts | 12 +++++++++++- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/abnormal/abnormal.service.spec.ts b/src/abnormal/abnormal.service.spec.ts index a9133bd..60b7c9b 100644 --- a/src/abnormal/abnormal.service.spec.ts +++ b/src/abnormal/abnormal.service.spec.ts @@ -176,8 +176,11 @@ describe('AbnormalService', () => { }); it('list 按 abnormal_type/notify_status/handle_status/老人 筛选', async () => { - const recordAbnormalFindMany = vi.fn().mockResolvedValue([{ id: 'a1' }]); - const recordAbnormalCount = vi.fn().mockResolvedValue(1); + const recordAbnormalFindMany = vi.fn().mockResolvedValue([ + { id: 'a1', visitLat: { toString: () => '25.010000' }, visitLng: { toString: () => '102.700000' } }, + { id: 'a2', visitLat: null, visitLng: null }, + ]); + const recordAbnormalCount = vi.fn().mockResolvedValue(2); const { service } = makeService({ recordAbnormalFindMany, recordAbnormalCount }); const res = await runWithRequestContext(ctx, () => @@ -199,6 +202,15 @@ describe('AbnormalService', () => { take: 20, }); expect(recordAbnormalCount).toHaveBeenCalledWith({ where }); - expect(res).toEqual({ list: [{ id: 'a1' }], total: 1, page: 1, pageSize: 20 }); + // Decimal → string(null 保持 null)。 + expect(res).toEqual({ + list: [ + { id: 'a1', visitLat: '25.010000', visitLng: '102.700000' }, + { id: 'a2', visitLat: null, visitLng: null }, + ], + total: 2, + page: 1, + pageSize: 20, + }); }); }); diff --git a/src/abnormal/abnormal.service.ts b/src/abnormal/abnormal.service.ts index 7bc30c5..55a52de 100644 --- a/src/abnormal/abnormal.service.ts +++ b/src/abnormal/abnormal.service.ts @@ -87,7 +87,17 @@ export class AbnormalService { }), this.prisma.client.recordAbnormal.count({ where }), ]); - return { list, total, page: q.page, pageSize: q.pageSize }; + // Prisma Decimal(visit_lat/visit_lng)经 TransformInterceptor 不会转字符串,会泄漏为 {s,e,d};显式序列化。 + return { + list: list.map((r) => ({ + ...r, + visitLat: r.visitLat != null ? r.visitLat.toString() : null, + visitLng: r.visitLng != null ? r.visitLng.toString() : null, + })), + total, + page: q.page, + pageSize: q.pageSize, + }; } /** 扑空证据必留:到访时间、定位(经纬)、原因、关联工单(3003)。 */