🐛 修复司机端档案按脱敏手机号匹配导致本人档案查不到

This commit is contained in:
2026-10-09 20:13:38 +08:00
parent 9f9ce7842e
commit 143c6f99fb
2 changed files with 83 additions and 11 deletions
@@ -186,7 +186,13 @@ public class DriverAppServiceImpl implements IDriverAppService {
String selfPhone = resolveSelfPhone(userId);
String hint = Func.isEmpty(mobileHint) ? null : mobileHint.trim();
if (Func.isNotEmpty(hint)) {
if (Func.isNotEmpty(selfPhone) && !selfPhone.equals(hint)) {
if (Func.isEmpty(selfPhone)) {
// 解析不出本人号码时不能拿前端传的 mobile 去查:
// currentDriver 会直接按 mobile 等值查询,传入他人号码即可读到他人档案。
// 这里返回空让它退回按 user_id 查,宁可查不到也不越权。
return null;
}
if (!selfPhone.equals(hint)) {
throw new ServiceException("只能查询本人司机档案");
}
return hint;
@@ -196,21 +202,30 @@ public class DriverAppServiceImpl implements IDriverAppService {
private String resolveSelfPhone(Long userId) {
String account = AuthUtil.getUserAccount();
if (Func.isNotEmpty(account) && account.matches("^1\\d{10}$")) {
if (isMobileLike(account)) {
return account.trim();
}
// 用户中心的 phone 带 @Sensitive(MOBILE),经 Feign 回来是「175****12082」这类脱敏串,
// 拿它去 eq(mobile) 永远查不到、拿它比对本人的真实号码又必然不等。
// 因此这里只取未脱敏的 account;脱敏的 phone 一律不用。
R<User> result = userClient.userInfoById(userId);
if (result == null || !R.isSuccess(result) || result.getData() == null) {
return Func.isEmpty(account) ? null : account.trim();
}
User user = result.getData();
if (Func.isNotEmpty(user.getPhone())) {
return user.getPhone().trim();
}
if (Func.isNotEmpty(user.getAccount()) && user.getAccount().matches("^1\\d{10}$")) {
return user.getAccount().trim();
if (result != null && R.isSuccess(result) && result.getData() != null) {
String userAccount = result.getData().getAccount();
if (isMobileLike(userAccount)) {
return userAccount.trim();
}
}
return Func.isEmpty(account) ? null : account.trim();
}
/**
* 是否是「可作为司机档案手机号使用」的号码串。
* <p>
* 只判 1 开头的 11~15 位纯数字:库里既有 11 位真实手机号,也有 12 位账号
* (如 175874212082),写死 11 位会让这类账号的司机解析不出本人号码。
*/
private boolean isMobileLike(String value) {
return Func.isNotEmpty(value) && value.trim().matches("^1\\d{10,14}$");
}
}