Commit 363a5ddf by 林永健

feat(follow): 新增当前员工关注数查询功能

- 在StoreFollowController中新增countStaffFollows接口,实现当前员工关注数API
- 在MerchantBiFollowMapper接口中添加根据员工UUID和业务类型统计关注数的方法
- 在Mapper XML中新增对应SQL查询语句,支持业务类型条件筛选
- 在MerchantBiFollowRemote及其实现类中新增countStaffFollows远程调用接口
- 在MerchantBiFollowService中实现countStaffFollows具体业务逻辑,包含参数校验和日志记录
- 优化部分日志提示内容,增强代码健壮性和易读性
1 parent 2b26a3d4
...@@ -11,6 +11,7 @@ import cn.com.glsx.dj.response.LoginUserInfoResponse; ...@@ -11,6 +11,7 @@ import cn.com.glsx.dj.response.LoginUserInfoResponse;
import cn.com.glsx.dj.util.CommonUtil; import cn.com.glsx.dj.util.CommonUtil;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse; import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.rop.response.RopResponse; import cn.com.glsx.framework.rop.response.RopResponse;
import com.rop.AbstractRopRequest;
import com.rop.annotation.NeedInSessionType; import com.rop.annotation.NeedInSessionType;
import com.rop.annotation.ServiceMethod; import com.rop.annotation.ServiceMethod;
import com.rop.annotation.ServiceMethodBean; import com.rop.annotation.ServiceMethodBean;
...@@ -99,4 +100,23 @@ public class StoreFollowController { ...@@ -99,4 +100,23 @@ public class StoreFollowController {
return RopResponse.error(e.getMessage()); return RopResponse.error(e.getMessage());
} }
} }
@ApiOperation("当前员工关注数")
@ServiceMethod(method = "dj.api.pe.analysis.staff.follow.count", needInSession = NeedInSessionType.YES)
public RopResponse<Integer> countStaffFollows(AbstractRopRequest request) {
try {
SceneBaseReq req = CommonUtil.convertRequest(SceneBaseReq.class);
LoginUserInfoResponse loginUserInfo = CommonUtil.getLoginUserInfo();
req.setLoginUserUuid(loginUserInfo.getUuid());
RpcResponse<Integer> response = followRemote.countStaffFollows(req);
if (response.isSuccess()) {
return RopResponse.success(response.getResult());
}
return RopResponse.error(response.getMessage());
} catch (Exception e) {
log.error("查询当前员工关注数异常", e);
return RopResponse.error(e.getMessage());
}
}
} }
  • @wangxw1
    commented
    Master

    你好,我是负责本次代码审查的工程师。你提交的代码实现了员工关注数查询的接口功能,整体逻辑清晰,分层结构合理,Commit 信息也非常规范。

    但在安全性处理和代码健壮性方面,有几处关键细节需要优化。以下是本次审查的 Top 3 问题及建议:

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

    1. 安全隐患:直接返回原始异常信息(High)

    • 问题描述:在 catch 代码块中,直接使用 RopResponse.error(e.getMessage()) 将异常堆栈的原始信息返回给了前端/调用方。
    • 影响分析:这是典型的敏感信息泄露风险。如果发生 SQL 异常或空指针异常,原始报错信息可能包含数据库表结构、字段名或内部代码逻辑细节,容易被攻击者利用。
    • 优化建议:应捕获异常后记录详细日志,但向前端返回通用的错误提示(如“系统繁忙,请稍后再试”)或定义好的业务错误码。 java // 建议修改为: catch (Exception e) { log.error("查询当前员工关注数异常", e); // 生产环境严禁直接透传 e.getMessage() return RopResponse.error("系统内部错误,请联系管理员"); }

    2. 健壮性缺陷:存在空指针异常(NPE)风险(Medium)

    • 问题描述:代码通过 CommonUtil.getLoginUserInfo() 获取用户信息后,直接调用了 .getUuid(),未进行判空检查。
    • 影响分析:虽然 @ServiceMethod(needInSession = NeedInSessionType.YES) 通常保证会话存在,但在某些极端情况(如 Session 反序列化失败、ThreadLocal 丢失)下,getLoginUserInfo() 可能返回 null。此时直接调用方法会导致 NPE,且该 NPE 会被外层 catch 捕获并暴露给前端(结合问题 1)。
    • 优化建议:增加防御性编程,对获取的用户对象进行判空。 java LoginUserInfoResponse loginUserInfo = CommonUtil.getLoginUserInfo(); if (loginUserInfo == null) { log.warn("获取登录用户信息失败"); return RopResponse.error("无法获取当前登录用户信息"); } req.setLoginUserUuid(loginUserInfo.getUuid());

    3. 代码质量:方法签名与实现不一致(Low)

    • 问题描述:方法签名定义了参数 AbstractRopRequest request,但在方法体内部却完全忽略该参数,转而使用 CommonUtil.convertRequest(SceneBaseReq.class) 来获取请求数据。
    • 影响分析:
      1. 误导性:阅读代码的人会困惑为什么传进来的 request 没有被使用。
      2. 隐藏依赖:使用 CommonUtil 转换通常依赖于 ThreadLocal 等隐式上下文,使得该方法难以进行单元测试(必须 mock 静态工具类)。
    • 优化建议:如果 ROP 框架支持自动参数绑定,建议直接将方法参数声明为 SceneBaseReq request,并直接使用该参数,移除 CommonUtil 的调用。

    二、评分明细

    评分维度 得分 简要理由
    功能实现的正确性与健壮性 35/40 主体逻辑正确,但缺少对 loginUserInfo 的空值防御,存在 NPE 隐患。
    安全性与潜在风险 20/30 直接透传 e.getMessage() 存在信息泄露风险,扣分较重。
    最佳实践与可维护性 15/20 命名规范,结构清晰。扣分点在于方法参数定义了却不使用,依赖静态工具类获取上下文。
    性能与资源利用 5/5 无明显性能瓶颈,资源使用合理。
    提交信息质量 5/5 Commit Message 非常优秀,清晰地描述了修改范围、涉及的层级和具体逻辑,值得表扬。

    总分:80分

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