Commit afe5559e by 林永健

feat(supervisor): 集成督导小程序任务推送功能

- 在Dubbo配置中新增SupervisorTaskInfoRemote的Bean定义
- MerchantBiCommentService中注入SupervisorTaskInfoRemote接口
- 处理留言策略时,构建督导任务创建DTO列表
- 支持将留言处理人信息同步推送到督导小程序
- 异常捕获并记录推送过程中的错误日志
- 添加rpc-dj-supervisor-api依赖模块及版本管理配置
1 parent ef946740
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<mindworkplate.api.version>5.7.0-SNAPSHOT</mindworkplate.api.version> <mindworkplate.api.version>5.7.0-SNAPSHOT</mindworkplate.api.version>
<pe-analysis.api.version>5.7.0-SNAPSHOT</pe-analysis.api.version> <pe-analysis.api.version>5.7.0-SNAPSHOT</pe-analysis.api.version>
<strategy.api.version>5.7.0-SNAPSHOT</strategy.api.version> <strategy.api.version>5.7.0-SNAPSHOT</strategy.api.version>
<supervisor.api.version>1.0.0-SNAPSHOT</supervisor.api.version>
</properties> </properties>
<dependencies> <dependencies>
...@@ -81,5 +82,10 @@ ...@@ -81,5 +82,10 @@
<artifactId>hutool-all</artifactId> <artifactId>hutool-all</artifactId>
<version>5.8.38</version> <version>5.8.38</version>
</dependency> </dependency>
<dependency>
<groupId>cn.com.glsx.dj</groupId>
<artifactId>rpc-dj-supervisor-api</artifactId>
<version>${supervisor.api.version}</version>
</dependency>
</dependencies> </dependencies>
</project> </project>
\ No newline at end of file \ No newline at end of file
package cn.com.glsx.dj.peanalysis.config; package cn.com.glsx.dj.peanalysis.config;
import cn.com.glsx.dj.smartcarlife.remote.StaffInfoRemote;
import cn.com.glsx.dj.supervisor.remote.SupervisorTaskInfoRemote;
import org.oreframework.boot.autoconfigure.dubbo.reference.ReferenceBuilderFactory; import org.oreframework.boot.autoconfigure.dubbo.reference.ReferenceBuilderFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
...@@ -33,4 +35,9 @@ public class DubboConfig { ...@@ -33,4 +35,9 @@ public class DubboConfig {
return factory.builder(RpcRemote.class).check(false).timeout(30000).build(); return factory.builder(RpcRemote.class).check(false).timeout(30000).build();
}*/ }*/
@Bean
public SupervisorTaskInfoRemote supervisorTaskInfoRemote(){
return factory.builder(SupervisorTaskInfoRemote.class).check(check).timeout(timeout).build();
}
} }
...@@ -6,6 +6,9 @@ import cn.com.glsx.dj.peanalysis.mapper.StrategyInfoMapper; ...@@ -6,6 +6,9 @@ import cn.com.glsx.dj.peanalysis.mapper.StrategyInfoMapper;
import cn.com.glsx.dj.peanalysis.mapper.StrategyStaffRelMapper; import cn.com.glsx.dj.peanalysis.mapper.StrategyStaffRelMapper;
import cn.com.glsx.dj.strategy.model.StrategyInfo; import cn.com.glsx.dj.strategy.model.StrategyInfo;
import cn.com.glsx.dj.strategy.model.StrategyStaffRel; import cn.com.glsx.dj.strategy.model.StrategyStaffRel;
import cn.com.glsx.dj.supervisor.dto.CreateSpecialTaskDTO;
import cn.com.glsx.dj.supervisor.remote.SupervisorTaskInfoRemote;
import cn.com.glsx.framework.core.beans.rpc.RpcResponse;
import cn.com.glsx.framework.core.exception.RpcServiceException; import cn.com.glsx.framework.core.exception.RpcServiceException;
import cn.hutool.core.date.DateUtil; import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
...@@ -37,6 +40,9 @@ public class MerchantBiCommentService { ...@@ -37,6 +40,9 @@ public class MerchantBiCommentService {
@Autowired @Autowired
private WechatPushService wechatPushService; private WechatPushService wechatPushService;
@Autowired
private SupervisorTaskInfoRemote supervisorTaskInfoRemote;
private static final Integer STRATEGY_TYPE_COMMENT = 7; private static final Integer STRATEGY_TYPE_COMMENT = 7;
/** /**
...@@ -65,6 +71,8 @@ public class MerchantBiCommentService { ...@@ -65,6 +71,8 @@ public class MerchantBiCommentService {
boolean success = strategyInfoMapper.insertSelective(strategy) > 0; boolean success = strategyInfoMapper.insertSelective(strategy) > 0;
if (success && CollectionUtils.isNotEmpty(request.getHandlerStaffList())) { if (success && CollectionUtils.isNotEmpty(request.getHandlerStaffList())) {
// 推送督导小程序任务
List<CreateSpecialTaskDTO> pushSupervisorTaskList = new ArrayList<>();
// 2. 插入处理人关联表 (@ 提醒) // 2. 插入处理人关联表 (@ 提醒)
List<String> uuids = new ArrayList<>(); List<String> uuids = new ArrayList<>();
for (HandlerStaffInfo handler : request.getHandlerStaffList()) { for (HandlerStaffInfo handler : request.getHandlerStaffList()) {
...@@ -72,12 +80,22 @@ public class MerchantBiCommentService { ...@@ -72,12 +80,22 @@ public class MerchantBiCommentService {
rel.setStrategyId(strategy.getId()); rel.setStrategyId(strategy.getId());
rel.setUserUuid(handler.getStaffUuid()); rel.setUserUuid(handler.getStaffUuid());
rel.setUserName(handler.getStaffName() != null ? handler.getStaffName() : ""); rel.setUserName(handler.getStaffName() != null ? handler.getStaffName() : "");
rel.setUserPhone(handler.getStaffPhone() != null ? handler.getStaffPhone() : "");
rel.setCreatedBy(request.getStaffName()); rel.setCreatedBy(request.getStaffName());
rel.setCreatedDate(new Date()); rel.setCreatedDate(new Date());
rel.setDeletedFlag("N"); rel.setDeletedFlag("N");
strategyStaffRelMapper.insertSelective(rel); strategyStaffRelMapper.insertSelective(rel);
uuids.add(handler.getStaffUuid()); uuids.add(handler.getStaffUuid());
CreateSpecialTaskDTO pushItem = new CreateSpecialTaskDTO();
pushItem.setMerchantId(strategy.getMerchantId());
pushItem.setMerchantName(strategy.getMerchantName());
pushItem.setTaskDesc(request.getContent());
pushItem.setSupervisorName(rel.getUserName());
pushItem.setSupervisorPhone(rel.getUserPhone());
pushItem.setCreatedBy(rel.getCreatedBy());
pushSupervisorTaskList.add(pushItem);
} }
// 3. 企微推送 (@ 提醒) // 3. 企微推送 (@ 提醒)
...@@ -87,6 +105,16 @@ public class MerchantBiCommentService { ...@@ -87,6 +105,16 @@ public class MerchantBiCommentService {
} catch (Exception e) { } catch (Exception e) {
log.error("触发留言 @ 推送异常", e); log.error("触发留言 @ 推送异常", e);
} }
// 4. 推送到督导小程序
pushSupervisorTaskList.forEach(p -> {
try {
RpcResponse<Long> pushResp = supervisorTaskInfoRemote.createSpecialTask(p);
log.info("推送到督导小程序,结果:{}", pushResp);
} catch (Exception e) {
log.error("推送到督导小程序异常, req:{}", p, e);
}
});
} }
return success; return success;
......
  • @wangxw1
    commented
    Master

    你好,我是负责此次代码审查的软件开发工程师。你提交的代码涵盖了 RPC 接口扩展、MyBatis 查询优化以及业务逻辑的增强。代码整体结构清晰,提交信息规范,但在远程调用处理和数据库查询方面存在值得优化的点。

    以下是我的审查结果:

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

    1. 循环内同步调用 RPC 接口,存在严重性能与稳定性风险

    • 问题描述:在 MerchantBiCommentService.java 的 addStrategy 方法中,代码在一个 forEach 循环内同步调用 supervisorTaskInfoRemote.createSpecialTask(p)。
    • 影响分析:
      • 性能瓶颈:这是典型的 "N+1" 远程调用问题。如果 handlerStaffList 有 10 人,主线程将串行阻塞等待 10 次 RPC 返回。假设单次 RPC 耗时 200ms,接口响应将增加 2 秒,严重影响用户体验。
      • 事务/稳定性:虽然加了 try-catch,但若 RPC 响应超时,会长时间占用数据库连接(因为该逻辑在 Service 方法内,虽未显式开启大事务,但通常此类 Service 方法会被 Spring 事务切面包裹)。
    • 优化建议:
      • 异步处理:建议使用线程池异步执行推送逻辑,或者发送 MQ 消息解耦,将耗时操作移出主业务流程。
      • 批量接口:如果必须同步且实时性要求高,建议在 Provider 端提供 batchCreateSpecialTask 接口,一次 RPC 传输所有任务。
    // 优化示例:使用 CompletableFuture 异步执行(简单版)
    // 建议配合自定义线程池使用,避免占用公共 ForkJoinPool
    CompletableFuture.runAsync(() -> {
        pushSupervisorTaskList.forEach(p -> {
            try {
                supervisorTaskInfoRemote.createSpecialTask(p);
            } catch (Exception e) {
                log.error("异步推送督导任务失败", e);
            }
        });
    });
    

    2. MyBatis 映射文件中使用 SELECT *,违反工程最佳实践

    • 问题描述:在 MerchantBiFollowDetailMapper.xml 中,findFollowersByFollowIds 方法的查询字段从明确的 follow_id, staff_name 修改为了 SELECT *。
    • 影响分析:
      • 性能消耗:获取了不需要的字段(如 created_date, updated_date 等),增加了网络 I/O 和内存开销。
      • 维护性:如果表结构变更(如增加大字段),可能导致隐性的性能骤降。
      • 意图不明:修改原因推测是为了获取 staff_uuid 用于 Service 层的过滤,但应显式添加该字段。
    • 优化建议:显式列出所需字段。
    <!-- 优化建议 -->
    <select id="findFollowersByFollowIds" resultMap="BaseResultMap">
        SELECT follow_id, staff_name, staff_uuid
        FROM dj_merchant_bi_follow_detail
        WHERE follow_id IN ...
    </select>
    

    3. 模糊查询使用前置通配符,导致索引失效

    • 问题描述:在 MerchantBiFollowMapper.xml 中,新增的 merchantName 查询使用了 LIKE CONCAT('%', #{merchantName}, '%')。
    • 影响分析:
      • 全表/全索引扫描:% 在最左侧会导致数据库无法利用 merchant_name 字段的 B-Tree 索引(即使有索引)。 -虽然该查询有 staff_uuid 作为前置过滤条件,但在用户关注列表非常庞大(例如超级管理员或测试账号)的极端场景下,性能会明显下降。
    • 优化建议:
      • 确认业务是否必须支持“包含”搜索。如果支持“前缀”搜索(CONCAT(#{merchantName}, '%'))性能会更好。
      • 如果必须全模糊,且数据量预期较大,建议接入搜索引擎(ES);若维持现状,需评估单用户关注上限是否可控。

    二、评分明细

    维度 评分 理由
    功能实现的正确性与健壮性 35/40 核心逻辑实现正确,MyBatis 动态 SQL 逻辑无误。扣分点在于 RPC 调用的异常处理虽有 try-catch,但在循环中同步调用对于高并发场景不够健壮。
    安全性与潜在风险 30/30 使用了 MyBatis 的 #{} 预编译参数,有效防止 SQL 注入;权限校验依赖现有的 loginUserUuid,未见明显越权风险。
    最佳实践与可维护性 12/20 扣分项:Mapper 中使用了 SELECT *;Service 层混合了核心业务与第三方 RPC 推送逻辑(且在循环中),违反单一职责原则,耦合度较高。
    性能与资源利用 2/5 扣分项:循环 RPC 调用是严重的性能隐患;前置 % 模糊查询在数据量增长后存在风险。
    提交信息质量 5/5 提交信息非常清晰,采用了 Angular 规范(feat/refactor),详细描述了修改内容和对应的业务价值,值得表扬。

    总分:84分

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