fix(c3): 扑空 not_met_reason 截断 50 + report 坐标 Decimal 转字符串

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
liuyun 2026-10-15 01:07:18 +08:00
parent c00c4ee007
commit 5f060292c6
2 changed files with 59 additions and 3 deletions

View File

@ -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();

View File

@ -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)。 */