Commit 4796cf1b by zhouhaibao

feat(smartcarlife): 新增理想品牌延保门店产值报表推送到企微群聊

- 新增sendExtendedWarrantyReportMessageLxJob方法,支持按品牌查询理想门店并推送报表
- 新增sendLxExtendedWarrantyReportMessage方法,实现按群聊维度推送报表图片和文本消息
- 新增getExcelPicUrlWithHiddenColumnsLx方法,支持隐藏指定列后生成Excel图片
- 新增getExcelUrlLx方法,通过ROP接口获取理想门店产值Excel下载地址
- 在StaffDailyReportRemote中新增sendAllSceneTypeReportMessageLxJob远程接口
- 在StaffDailyReportService中新增对应服务方法调用消息推送逻辑
- 引入MerchantRemote依赖,通过品牌ID查询理想品牌门店列表
- 升级smartcarlife.api版本至5.8.7.1-SNAPSHOT
1 parent d0c8055d
......@@ -12,7 +12,7 @@
<name>rpc-dj-smartcarlife-api</name>
<properties>
<deploy.scanPackage>cn.com.glsx.dj.smartcarlife.remote</deploy.scanPackage>
<smartcarlife.api.version>5.8.7-SNAPSHOT</smartcarlife.api.version>
<smartcarlife.api.version>5.8.7.1-SNAPSHOT</smartcarlife.api.version>
<shopamll.api.version>5.6.4-SNAPSHOT</shopamll.api.version>
</properties>
<dependencies>
......
......@@ -143,4 +143,10 @@ public interface StaffDailyReportRemote {
@ApiParam(name = "merchantId, yqMerchantId, reportDate, firstBrandId, brandId, sceneType, deliveryCount, updatedBy, updatedDate", notes = "查询条件及更新值", dataType = ApiParam.DataTypeEnum.OBJECT, required = true)
@ApiResponse("返回是否成功")
RpcResponse<Boolean> updateStaffDailyReportHuaweiDeliveryCount(StaffDailyReportHuawei report);
@ApiMethod("推送门店产值报表图片到群聊(理想)")
@ApiParam(name="jobParameter",notes="推送入参",dataType= ApiParam.DataTypeEnum.STRING,required=true)
@ApiResponse("无需返回")
void sendAllSceneTypeReportMessageLxJob(String jobParameter);
}
......@@ -16,7 +16,7 @@
<skipTests>true</skipTests>
<shopmall.api.version>5.8.2-SNAPSHOT</shopmall.api.version>
<stoassistant.api.version>5.6.4-SNAPSHOT</stoassistant.api.version>
<smartcarlife.api.version>5.8.7-SNAPSHOT</smartcarlife.api.version>
<smartcarlife.api.version>5.8.7.1-SNAPSHOT</smartcarlife.api.version>
<sale.api.version>5.8.4-SNAPSHOT</sale.api.version>
<mindworkplate.api.version>5.8.3-SNAPSHOT</mindworkplate.api.version>
</properties>
......
......@@ -363,4 +363,13 @@ public class StaffDailyReportRemoteImpl implements StaffDailyReportRemote{
return RpcResponse.error(e);
}
}
@Override
public void sendAllSceneTypeReportMessageLxJob(String jobParameter) {
try{
staffDailyReportService.sendAllSceneTypeReportMessageLxJob(jobParameter);
}catch(RpcServiceException e){
log.error(e.getMessage(),e);
}
}
}
......@@ -5765,4 +5765,19 @@ public class StaffDailyReportService {
}
return result;
}
/**
* @description: 推送延保权益+轻改门店产值数据到群聊中(理想)
* @param: [jobParameter]
* @date: 2025/8/8 9:58
*/
public void sendAllSceneTypeReportMessageLxJob(String jobParameter) {
try {
sendWorkWechatMessageService.sendExtendedWarrantyReportMessageLxJob(jobParameter);
} catch (Exception e){
log.error("推送延保驻店日报到企微消息异常:{}", e.getMessage(), e);
throw new RpcServiceException(DefaultErrorEnum.SERVICE_ERROR, e.getMessage());
}
}
}
  • @wangxw1
    commented
    Master

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

    1. @Transactional 包含 RPC 与重度文件/网络 I/O(严重稳定性风险)

    • 问题描述:sendExtendedWarrantyReportMessageLxJob 方法被 @Transactional 注解修饰,但其内部不仅包含了 Dubbo RPC 调用(merchantRemote2)、HTTP 网络请求(ropClient),甚至在后续链路中包含了极其耗时的 Excel 文件下载与转图片操作。
    • 影响分析:网络请求和文件 I/O 的耗时是不可控的。在事务中进行这些操作会导致数据库连接被长时间挂起(长事务),极易引发数据库连接池耗尽,进而导致整个服务甚至关联服务不可用。
    • 优化建议:将 @Transactional 从主流程方法上移除。网络请求、数据组装和文件处理应在无事务环境下进行,仅将最终需要落库的写操作(如 insert、saveTask)封装到独立的受事务管理的 Service 方法中。 java // 移除该方法上的 @Transactional 注解 public void sendExtendedWarrantyReportMessageLxJob(String paramStr) { // 1. 进行 RPC 查询和网络请求 (无事务) // 2. 生成图片等耗时操作 (无事务) // 3. 仅对需要保证原子性的落库操作进行事务调用 reportPushTransactionService.saveReportAndPushTasks(...); }

    2. 临时文件未清理导致潜在的磁盘打满风险(资源泄漏风险)

    • 问题描述:在 getExcelPicUrlWithHiddenColumnsLx 方法中,通过 FileUtils.getFileToLocal 下载了 Excel 文件到本地目录,并通过 ImageIO.write 生成了 PNG 图片。但在整个流程结束后,未对这些本地临时文件进行清理。
    • 影响分析:随着定时任务的周期性执行,服务器本地 gop.excel.tem.path 目录下的临时文件会不断堆积,最终必然导致服务器磁盘空间耗尽(Disk Full),引发系统崩溃。
    • 优化建议:使用 try-finally 块确保在文件处理完成后,无论成功与否,都将本地的 Excel 和 PNG 临时文件删除。 java String localFileDir = null; String localImagePath = null; try { localFileDir = FileUtils.getFileToLocal(...); // ... 生成图片的逻辑 localImagePath = filePath + fileName; ImageIO.write(bufferedImage, "PNG", new File(localImagePath)); // 假设上传图片后返回 URL return env.getProperty("gop.excel.tem.url") + fileName; } finally { // 确保清理临时文件 if (localFileDir != null) new File(localFileDir).delete(); // 注意:如果图片是通过静态代理直接读取本地文件,需确认图片的生命周期; // 如果是上传到了 OSS/文件服务器,则本地图片也应立即删除: // if (localImagePath != null) new File(localImagePath).delete(); }

    3. 关键配置缺失时未做阻断(逻辑正确性风险)

    • 问题描述:在 sendExtendedWarrantyReportMessageLxJob 方法中,当 lixiang.brand.ids 配置为空或解析失败时,代码仅打印了 log.error,并没有 return 阻断流程。随后将一个空的 brandIdList 传给了 merchantRemote2.findMerchantListByBrandIds2。
    • 影响分析:根据底层 RPC 的实现,如果传入的品牌 ID 列表为空,极有可能退化为全表扫描,返回系统中所有的门店数据。这不仅会导致内存溢出(OOM)或 RPC 超时,还会导致将非理想品牌的错误数据推送到群聊中,造成严重的业务事故。
    • 优化建议:在检测到 brandIdList 为空时,应立即停止后续流程。 java if (CollectionUtils.isEmpty(brandIdList)) { log.error("理想品牌门店查询失败:配置项 lixiang.brand.ids 解析后为空, 原始值={}", lixiangBrandIds); return; // 必须进行阻断,防止查出全量门店 }

    二、评分明细

    1. 功能实现的正确性与健壮性(32/40分)

      • 理由:整体业务逻辑闭环完整,未违反“Mybatis子查询”及“Dubbo参数变更”的红线规则。但存在参数校验失败后未阻断导致潜在全量查询的风险(如 Top 3);此外 getExcelUrlLx 方法中存在重复添加参数的笔误(paramsMap.add("endDate", endDate); 写了两次)。
    2. 安全性与潜在风险(28/30分)

      • 理由:无明显的 SQL 注入、越权等高危安全漏洞。扣分点在于文件路径依赖环境变量拼接,若环境配置不当可能有路径遍历隐患,但属于内部系统调度,风险可控。
    3. 最佳实践与可维护性(12/20分)

      • 理由:
        • 滥用 @Transactional 包含了 RPC 和文件流处理,严重违反工程最佳实践。
        • 命名不规范:注入的依赖命名为 merchantRemote2,带有无意义的数字后缀,降低了代码可读性。
        • 异常处理欠佳:StaffDailyReportRemoteImpl 中仅捕获了 RpcServiceException,若 Service 层抛出其他 RuntimeException,会导致 Dubbo 消费者收到未序列化的异常堆栈。
    4. 性能与资源利用(2/5分)

      • 理由:文件 I/O 资源未释放,存在严重的磁盘泄漏风险(如 Top 2)。同时,Spire.XLS 转换图片是内存密集型操作,大 Excel 可能导致 OOM,需关注内存使用情况。
    5. 提交信息质量(4/5分)

      • 理由:Commit 信息结构清晰,详细列出了新增的方法和功能点,可追溯性较好。若能附带对应的 Jira 任务号或需求 ID 会更加完美。

    总分:78分

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