Commit 114d3c0f by zhouhaibao

feat(recruitment): 新增根据手机号查询员工最新业务类型功能

- 在 RecruitmentDemandController 中添加 getLatestBusinessTypeByPhone 接口
- 在 RecruitmentDemandMapper 中新增 selectLatestBusinessTypeByPhone 查询方法
- 在 Mapper XML 中实现根据手机号查询最新业务类型的 SQL 语句
- 在 RecruitmentDemandRemote 中定义远程调用接口
- 在 RecruitmentDemandRemoteImpl 中实现远程调用逻辑
- 在 RecruitmentDemandService 中添加业务处理方法
- 添加异常处理和日志记录机制
1 parent f09b7a80
...@@ -22,6 +22,8 @@ import cn.com.glsx.dj.staff.util.excel.EasyExcelUtil; ...@@ -22,6 +22,8 @@ import cn.com.glsx.dj.staff.util.excel.EasyExcelUtil;
import cn.com.glsx.dj.staff.vo.excel.excel.RecruitmentDemandExportVO; import cn.com.glsx.dj.staff.vo.excel.excel.RecruitmentDemandExportVO;
import cn.com.glsx.framework.core.beans.rpc.RpcPagination; import cn.com.glsx.framework.core.beans.rpc.RpcPagination;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.enums.DefaultErrorEnum;
import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.com.glsx.framework.rop.response.RopResponse; import cn.com.glsx.framework.rop.response.RopResponse;
import cn.hutool.core.bean.BeanUtil; import cn.hutool.core.bean.BeanUtil;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
...@@ -297,4 +299,22 @@ public class RecruitmentDemandController { ...@@ -297,4 +299,22 @@ public class RecruitmentDemandController {
RpcResponse<List<RecruitmentSubSceneDTO>> response = recruitmentDemandRemote.listSubScenes(dto); RpcResponse<List<RecruitmentSubSceneDTO>> response = recruitmentDemandRemote.listSubScenes(dto);
return CommonUtil.convertRopResponse(response); return CommonUtil.convertRopResponse(response);
} }
@ApiOperation("根据手机号查询员工最新业务类型")
@ServiceMethod(method = "dj.staff.api.recruitment.demand.business.type.query", needInSession = NeedInSessionType.YES)
public RopResponse<String> getLatestBusinessTypeByPhone(BusinessTypeQueryRequest request) {
log.info("根据手机号查询员工最新业务类型, phoneNumber:{}", request.getPhoneNumber());
try {
RecruitmentDemandBusinessTypeQueryDTO dto = new RecruitmentDemandBusinessTypeQueryDTO();
dto.setPhoneNumber(request.getPhoneNumber());
RpcResponse<String> response = recruitmentDemandRemote.getLatestBusinessTypeByPhone(dto);
return CommonUtil.convertRopResponse(response);
} catch (RpcServiceException e) {
log.error("根据手机号查询员工最新业务类型异常, phoneNumber:{}, error:{}", request.getPhoneNumber(), e.getMessage(), e);
return RopResponse.error(e);
} catch (Exception e) {
log.error("根据手机号查询员工最新业务类型系统异常, phoneNumber:{}", request.getPhoneNumber(), e);
return RopResponse.result(DefaultErrorEnum.SERVICE_ERROR);
}
}
} }
  • @wangxw1
    commented
    Master

    一、关键问题与优化建议(仅限 Top 3)

    1. 敏感信息(PII)明文日志打印风险(安全性)

    • 问题描述:在 log.info 和 log.error 中直接明文打印了用户的手机号(request.getPhoneNumber())。根据数据安全法及个人信息保护规范,手机号属于敏感个人信息,明文落盘存在极大的安全合规风险。
    • 优化建议:在打印日志前对手机号进行脱敏处理。可以使用项目中已引入的 Hutool 工具类:DesensitizedUtil.mobilePhone(request.getPhoneNumber())。

    2. 潜在的空指针异常(NPE)及日志二次报错风险(健壮性)

    • 问题描述:
      • 方法入口未对入参 request 进行 Null 检查,直接调用 request.getPhoneNumber() 会导致 NullPointerException。
      • 更严重的是,如果 request 为 null 触发了 NPE,代码会进入 catch (Exception e) 块,而在 catch 块的日志打印中再次调用了 request.getPhoneNumber(),这会引发二次 NPE,导致原始异常堆栈丢失,且返回给前端的错误信息不符合预期。
    • 优化建议:在方法开头增加 if (request == null) 的校验;或者在 catch 块中安全地获取参数:String phone = request != null ? request.getPhoneNumber() : "unknown";。

    3. 缺少业务参数的 Fail-Fast 校验(规范与性能)

    • 问题描述:代码未对 phoneNumber 的有效性(如是否为空、格式是否正确)进行校验,就直接组装 DTO 发起底层的 RPC 远程调用。这违反了“防御性编程”和“快速失败(Fail-Fast)”原则,无效请求会白白消耗网络和下游服务资源。
    • 优化建议:建议在 BusinessTypeQueryRequest 类的 phoneNumber 字段上添加 @NotBlank 和 @Pattern(regexp = "^1[3-9]\\d{9}$") 等校验注解,并在 Controller 方法参数前加上 @Valid 或 @Validated 注解进行拦截校验。

    二、评分明细

    评审项 满分 得分 扣分说明
    1. 功能实现的正确性与健壮性 40 32 扣8分。未处理 request 为 null 的情况;catch 块中存在引发二次 NPE 的逻辑缺陷。
    2. 安全性与潜在风险 30 20 扣10分。敏感信息(手机号)未脱敏直接打印到日志中,存在违规风险。
    3. 最佳实践与可维护性 20 17 扣3分。缺少入参的有效性校验(防御性编程不足);捕获顶级 Exception 时的处理逻辑不够严谨。
    4. 性能与资源利用 5 4 扣1分。未在最前置拦截无效参数,可能导致无效的 RPC 调用,浪费系统资源。
    5. 提交信息质量 5 5 不扣分。采用了标准的 Conventional Commits 格式,且清晰列出了具体变更点,质量很高。

    总分:78分

Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!