fix(c4): 异常处理返回坐标 Decimal 转 string,防泄漏 {s,e,d}

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
liuyun 2026-10-15 01:58:47 +08:00
parent 00c258dda5
commit a808581e60
2 changed files with 20 additions and 5 deletions

View File

@ -658,12 +658,16 @@ describe('QcService.handleAbnormal', () => {
expect(recordAbnormalUpdate).not.toHaveBeenCalled();
});
it('处理 → 更新 handle_status/handle_result', async () => {
it('处理 → 更新 handle_status/handle_result + 坐标 Decimal → string', async () => {
const recordAbnormalFindUnique = vi.fn().mockResolvedValue({ id: 'a1', handleStatus: 'open' });
const recordAbnormalUpdate = vi.fn().mockResolvedValue({ id: 'a1' });
const recordAbnormalUpdate = vi.fn().mockResolvedValue({
id: 'a1',
visitLat: { toString: () => '25.010000' },
visitLng: null,
});
const { service } = makeService({ recordAbnormalFindUnique, recordAbnormalUpdate });
await runWithRequestContext(ctx, () =>
const res = await runWithRequestContext(ctx, () =>
service.handleAbnormal('a1', { handleStatus: 'closed', handleResult: '已通知家属' }),
);
@ -672,6 +676,7 @@ describe('QcService.handleAbnormal', () => {
where: { id: 'a1' },
data: { handleStatus: 'closed', handleResult: '已通知家属' },
});
expect(res).toMatchObject({ id: 'a1', visitLat: '25.010000', visitLng: null });
});
it('handleResult 缺省 → 更新为 null', async () => {

View File

@ -241,16 +241,17 @@ export class QcService {
});
}
/** 异常处理:质控员更新 handle_status/handle_result。 */
/** 异常处理:质控员更新 handle_status/handle_result;返回前坐标 Decimal → string。 */
async handleAbnormal(id: string, dto: HandleAbnormalDto) {
const abnormal = await this.prisma.client.recordAbnormal.findUnique({ where: { id } });
if (!abnormal) {
throw new BusinessException(ErrorCodes.ABNORMAL_NOT_FOUND, '异常上报不存在', HttpStatus.NOT_FOUND);
}
return this.prisma.client.recordAbnormal.update({
const updated = await this.prisma.client.recordAbnormal.update({
where: { id },
data: { handleStatus: dto.handleStatus, handleResult: dto.handleResult ?? null },
});
return this.serializeAbnormal(updated);
}
/** 批量放行:安全边界(异常/未执行/加项/时长过短/已补正)任一命中 → QC_BATCH_UNSAFE;否则逐条 pass。 */
@ -334,6 +335,15 @@ export class QcService {
}
}
/** 异常到访坐标 Decimal → string(null 保持 null),复用 abnormal 模块 list/report 口径。 */
private serializeAbnormal(abnormal: Record<string, any>): Record<string, any> {
return {
...abnormal,
visitLat: abnormal.visitLat != null ? abnormal.visitLat.toString() : null,
visitLng: abnormal.visitLng != null ? abnormal.visitLng.toString() : null,
};
}
/** Prisma Decimal 坐标转字符串(null 保持 null),复用 C3 口径,含异常到访坐标。 */
private serializeRecord(record: Record<string, any>): Record<string, any> {
const serialized: Record<string, any> = {