🐛 审核未命中目标档案时整体回滚,不再静默置为已通过
审核通过时对司机/车辆档案的 updateById 命中 0 行只返回 false、不抛异常,而这个返回值原先被丢弃,于是「认证记录已通过、档案一个字没变」能静默成立:生效快照指针没写进去,对象下次接单仍被判未认证,审核页却显示已通过。现在命中 0 行即抛异常并回滚整次审核,宁可报错也不留下状态与档案互相矛盾的数据。
This commit is contained in:
+21
-2
@@ -206,7 +206,7 @@ public class CertAuditServiceImpl implements ICertAuditService {
|
||||
// 与指针合并成同一次 UPDATE,不额外多写一次同一行。
|
||||
applySnapshotToVehicle(vehicle, record.getSnapshotJson());
|
||||
}
|
||||
transportVehicleService.updateById(vehicle);
|
||||
requireTargetUpdated(transportVehicleService.updateById(vehicle), "车辆", record.getBizId());
|
||||
return;
|
||||
}
|
||||
Driver driver = new Driver();
|
||||
@@ -225,7 +225,26 @@ public class CertAuditServiceImpl implements ICertAuditService {
|
||||
// 与指针合并成同一次 UPDATE,不额外多写一次同一行。
|
||||
applySnapshotToDriver(driver, record.getSnapshotJson());
|
||||
}
|
||||
driverService.updateById(driver);
|
||||
requireTargetUpdated(driverService.updateById(driver), "司机", record.getBizId());
|
||||
}
|
||||
|
||||
/**
|
||||
* 目标对象的写入必须命中一行,否则整体失败
|
||||
* <p>
|
||||
* {@code updateById} 命中 0 行时**不抛异常、只返回 false**。原先丢弃这个返回值,
|
||||
* 于是「审核记录已通过、司机/车辆档案一个字没变」能静默成立:生效快照指针没写进去,
|
||||
* 对象下次接单仍被判未认证,而审核页显示的是已通过。此处让事务整体回滚,
|
||||
* 宁可报错也不留下状态与档案互相矛盾的数据。
|
||||
*
|
||||
* @param updated 更新结果
|
||||
* @param target 对象名称,用于提示
|
||||
* @param id 对象主键
|
||||
*/
|
||||
private void requireTargetUpdated(boolean updated, String target, Long id) {
|
||||
if (!updated) {
|
||||
throw new ServiceException("未能更新" + target + "档案(ID:" + id
|
||||
+ "),本次审核已回滚、未生效;请核对该对象是否存在、未被删除,且与认证记录属于同一租户");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user