From 5f060292c67579c12f9fc6ececeb44d399f02cec Mon Sep 17 00:00:00 2001 From: liuyun Date: Thu, 15 Oct 2026 01:07:18 +0800 Subject: [PATCH] =?UTF-8?q?fix(c3):=20=E6=89=91=E7=A9=BA=20not=5Fmet=5Frea?= =?UTF-8?q?son=20=E6=88=AA=E6=96=AD=2050=20+=20report=20=E5=9D=90=E6=A0=87?= =?UTF-8?q?=20Decimal=20=E8=BD=AC=E5=AD=97=E7=AC=A6=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 | 51 ++++++++++++++++++++++++++- src/abnormal/abnormal.service.ts | 11 ++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/src/abnormal/abnormal.service.spec.ts b/src/abnormal/abnormal.service.spec.ts index 60b7c9b..8e49a22 100644 --- a/src/abnormal/abnormal.service.spec.ts +++ b/src/abnormal/abnormal.service.spec.ts @@ -68,7 +68,7 @@ describe('AbnormalService', () => { }), }); expect(orderUpdate).not.toHaveBeenCalled(); - expect(res).toEqual({ id: 'a1' }); + expect(res).toEqual({ id: 'a1', visitLat: null, visitLng: null }); }); it('report 扑空(not_met)→ 工单转 not_met + 写 record_abnormal(到访时间/定位/原因),不产生 ho_record', async () => { @@ -112,6 +112,55 @@ describe('AbnormalService', () => { }); }); + it('report 扑空 reason 超 50 字 → not_met_reason 截断为 50,record_abnormal 保留全文', async () => { + const longReason = 'x'.repeat(80); + const { service, recordAbnormalCreate, orderUpdate } = makeService(); + + await runWithRequestContext(ctx, () => + service.report({ + abnormalType: 'not_met', + elderId: 'e1', + orderId: 'o1', + abnormalDesc: longReason, + visitTime: '2026-10-15T09:30:00', + visitLat: 25.01, + visitLng: 102.7, + }), + ); + + expect(orderUpdate).toHaveBeenCalledWith({ + where: { id: 'o1' }, + data: expect.objectContaining({ notMetReason: 'x'.repeat(50) }), + }); + expect(recordAbnormalCreate).toHaveBeenCalledWith({ + data: expect.objectContaining({ abnormalDesc: longReason }), + }); + }); + + it('report 扑空返回 visitLat/visitLng 为字符串(Decimal 不泄漏)', async () => { + const recordAbnormalCreate = vi.fn().mockResolvedValue({ + id: 'a1', + abnormalType: 'not_met', + visitLat: { toString: () => '25.010000' }, + visitLng: { toString: () => '102.700000' }, + }); + const { service } = makeService({ recordAbnormalCreate }); + + const res = await runWithRequestContext(ctx, () => + service.report({ + abnormalType: 'not_met', + elderId: 'e1', + orderId: 'o1', + abnormalDesc: '老人不在家', + visitTime: '2026-10-15T09:30:00', + visitLat: 25.01, + visitLng: 102.7, + }), + ); + + expect(res).toMatchObject({ id: 'a1', visitLat: '25.010000', visitLng: '102.700000' }); + }); + it('report 扑空缺定位 → 拒(3003),不写工单/异常', async () => { const { service, recordAbnormalCreate, orderUpdate } = makeService(); diff --git a/src/abnormal/abnormal.service.ts b/src/abnormal/abnormal.service.ts index 55a52de..6ad8ccb 100644 --- a/src/abnormal/abnormal.service.ts +++ b/src/abnormal/abnormal.service.ts @@ -43,13 +43,14 @@ export class AbnormalService { where: { id: dto.orderId! }, data: { orderStatus: 'not_met', - notMetReason: dto.abnormalDesc ?? null, + // not_met_reason 为 VarChar(50),abnormalDesc 为 Text,须截断避免超长 500。 + notMetReason: (dto.abnormalDesc ?? '').slice(0, 50), notMetAt: toDateTime(dto.visitTime) ?? new Date(), }, }); } - return this.prisma.client.recordAbnormal.create({ + const created = await this.prisma.client.recordAbnormal.create({ data: { tenantCode, elderId: dto.elderId, @@ -68,6 +69,12 @@ export class AbnormalService { handleStatus: 'open', }, }); + // Prisma Decimal(visit_lat/visit_lng)转字符串,避免经 TransformInterceptor 泄漏为 {s,e,d}。 + return { + ...created, + visitLat: created.visitLat != null ? created.visitLat.toString() : null, + visitLng: created.visitLng != null ? created.visitLng.toString() : null, + }; } /** 异常列表(后台 B4)。 */