Commit 6cf2e48b by 张富康

feat(notification): 添加企微通知消息的agentId参数支持

- 在EffectiveReferralReviewQwService中增加agentId配置属性
- 调用企微发送消息时设置requestDTO的agentId字段
- 在PerfQwNotificationService中增加agentId配置属性
- 发送绩效评分通知时设置agentId,确保消息来源标识正确
- 统一多个通知方法中企微消息的agentId设置逻辑
1 parent 6ce8d8c0
......@@ -33,6 +33,7 @@ public class EffectiveReferralReviewQwService {
private PerformanceTimeCycleMapper performanceTimeCycleMapper;
@Resource
private EffectiveReferralReviewMapper effectiveReferralReviewMapper;
String agentId = OrePropertyConfigurer.getProperty("staff.effective.send.qw.notice.agentId", String.class, "");
/**
* 通知区域经理
......@@ -92,6 +93,7 @@ public class EffectiveReferralReviewQwService {
textCard.setBtnTxt(btnTxt);
textCard.setUrl(url);
requestDTO.setTextCard(textCard);
requestDTO.setAgentId(agentId);
try {
log.info("通知区域经理-调用企微通知接口:{}", JSONUtil.toJsonStr(requestDTO));
qWManager.sendMessage(requestDTO);
......@@ -157,6 +159,7 @@ public class EffectiveReferralReviewQwService {
// textCard.setBtnTxt(btnTxt);
// textCard.setUrl(url);
requestDTO.setTextCard(textCard);
requestDTO.setAgentId(agentId);
try {
log.info("通知总部运营-调用企微通知接口:{}", JSONUtil.toJsonStr(requestDTO));
qWManager.sendMessage(requestDTO);
......@@ -211,6 +214,7 @@ public class EffectiveReferralReviewQwService {
// textCard.setBtnTxt(btnTxt);
// textCard.setUrl(url);
requestDTO.setTextCard(textCard);
requestDTO.setAgentId(agentId);
try {
log.info("通知线上运营符合有效引荐数-调用企微通知接口:{}", JSONUtil.toJsonStr(requestDTO));
qWManager.sendMessage(requestDTO);
......@@ -260,6 +264,7 @@ public class EffectiveReferralReviewQwService {
textCard.setBtnTxt(btnTxt);
textCard.setUrl(url);
requestDTO.setTextCard(textCard);
requestDTO.setAgentId(agentId);
try {
log.info("通知区域运营已确认有效引荐数-调用企微通知接口:{}", JSONUtil.toJsonStr(requestDTO));
qWManager.sendMessage(requestDTO);
......
......@@ -33,6 +33,8 @@ public class PerfQwNotificationService {
private PerformanceTimeCycleMapper performanceTimeCycleMapper;
@Resource
private PerformanceEvaluationMapper performanceEvaluationMapper;
String agentId = OrePropertyConfigurer.getProperty("staff.perf.salary.send.qw.notice.agentId", String.class, "");
public void perfQwNotification() {
// 判断当前时间是否在T1范围内 如果不在则return
......@@ -83,6 +85,7 @@ public class PerfQwNotificationService {
textCard.setBtnTxt(btnTxt);
textCard.setUrl(url);
requestDTO.setTextCard(textCard);
requestDTO.setAgentId(agentId);
try {
log.info("绩效评分开始-通知区域运营-发送企微应用消息:{}", JSONUtil.toJsonStr(requestDTO));
qWManager.sendMessage(requestDTO);
......
  • @wangxw1
    commented
    Master

    你好,我是负责本次代码审查的工程师。你提交的代码主要涉及在两个服务类中引入企微 agentId 的配置和使用。代码逻辑清晰,Commit 信息规范,但在与 Spring 框架的集成方式及 Java 编码规范上存在改进空间。

    以下是具体的审查意见:

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

    1. 违反 Spring 依赖注入原则与测试困难(最佳实践 & 可维护性)

    • 问题描述:在 Service 类中,直接使用静态方法 OrePropertyConfigurer.getProperty(...) 在字段声明处进行初始化。 java // 当前代码 String agentId = OrePropertyConfigurer.getProperty("...", String.class, "");
    • 影响分析:
      1. 强耦合:类紧密耦合于静态配置工具,脱离了 Spring IOC 容器的管理。
      2. 可测试性差:编写单元测试时,必须 Mock 静态方法或加载完整的配置环境,无法轻松注入不同的 agentId 进行测试。
      3. 生命周期风险:字段初始化发生在对象实例化阶段。如果 OrePropertyConfigurer 依赖于 Spring 上下文初始化完成,而该 Service 被过早实例化,可能导致获取不到配置值。
    • 优化建议:使用 Spring 原生的 @Value 注解进行注入,符合标准 IOC 模式。

    2. 成员变量可见性与不可变性缺失(最佳实践 & 安全性)

    • 问题描述:新增的 agentId 变量使用了默认访问权限(package-private),且未声明为 private。
    • 影响分析:
      1. 封装破坏:同包下的其他类可以直接修改该 Service 的 agentId,这在单例模式(Singleton)的 Bean 中是非常危险的,可能导致线程安全问题或逻辑污染。
      2. 规范性:Service 内部的配置属性应当对外部不可见。
    • 优化建议:将变量声明为 private。

    3. 配置缺失时的容错处理不足(功能正确性)

    • 问题描述:配置获取使用了空字符串 "" 作为默认值。 java getProperty(..., String.class, "")
    • 影响分析:如果生产环境漏配了该 key,agentId 为空串。后续调用 qWManager.sendMessage(requestDTO) 时,虽然代码不会报错,但企微接口大概率会调用失败(无效的 agentId)。这种“静默失败”会让排查问题变得困难。
    • 优化建议:
      1. 如果该配置是必须的,建议在注入时若缺失则抛出异常(@Value 默认行为)。
      2. 或者在发送消息前校验 agentId 是否有效。

    优化后的代码示例(综合上述建议):

    public class EffectiveReferralReviewQwService {
    
        // 建议 1 & 2: 使用 @Value 注入,并修饰为 private
        // 如果配置项必须存在,不写默认值,启动时若缺失会直接报错,避免运行时错误
        @Value("${staff.effective.send.qw.notice.agentId}")
        private String agentId; 
    
        // 或者保持原有宽容策略,但要在业务逻辑中校验
        // @Value("${staff.effective.send.qw.notice.agentId:}")
        // private String agentId;
    
        public void someMethod() {
            // 建议 3: 简单的防御性编程
            if (StringUtils.isBlank(agentId)) {
                log.warn("企微 AgentId 未配置,跳过消息发送或使用默认逻辑");
                // return; 或 throw exception
            }
    
            requestDTO.setAgentId(agentId);
            // ...
        }
    }
    

    二、评分明细

    1. 功能实现的正确性与健壮性(35/40分)
      • 扣分项:配置缺失时默认为空字符串,且后续未做校验,可能导致无效的 API 调用。
    2. 安全性与潜在风险(28/30分)
      • 扣分项:成员变量可见性控制不严(缺少 private),存在理论上的被篡改风险。
    3. 最佳实践与可维护性(12/20分)
      • 扣分项:严重违反 Spring DI 最佳实践,使用了静态方法初始化字段;变量缺少访问修饰符。
    4. 性能与资源利用(5/5分)
      • 无明显性能问题。
    5. 提交信息质量(5/5分)
      • Commit message 格式规范(feat),描述清晰,涵盖了具体的修改点,非常好。

    三、总分

    总分:85分

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