Commit bf6ac7a5 by 叶立庆

Merge branch 'v5.8.7.1' into 'master'

上线合并

See merge request !57
2 parents d0c8055d 6624e22f
......@@ -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. 严重:长事务与事务内 RPC/HTTP 调用(性能与稳定性风险)

    • 问题描述:sendExtendedWarrantyReportMessageLxJob 方法被 @Transactional 注解修饰,但其内部不仅包含了 Dubbo RPC 调用(merchantRemote2.findMerchantListByBrandIds2),还在后续的 for 循环中通过 ropClient 发起了多次 HTTP 请求获取 Excel。
    • 影响分析:这是非常危险的反模式。网络请求(RPC/HTTP)的耗时是不可控的,将其放在数据库事务中会导致数据库连接被长时间占用。在并发场景或网络波动时,极易引发数据库连接池耗尽,导致整个服务甚至关联服务崩溃。
    • 优化建议:将事务的粒度降到最低。移除外层方法的 @Transactional 注解,仅在真正需要保证原子性的数据库写操作(如 outputValueDailyReportPictureService.insert 和 reportPushRecordService.saveTask)上使用事务,或者将这些写操作封装到一个独立的被 @Transactional 修饰的 Service 方法中进行调用。

    2. 严重:本地临时文件未清理导致资源泄漏(资源利用与健壮性)

    • 问题描述:在 getExcelPicUrlWithHiddenColumnsLx 方法中,通过 FileUtils.getFileToLocal 下载了 Excel 文件到本地,并使用 ImageIO.write 生成了 PNG 图片保存在本地磁盘。但整个流程结束后,并未对这些临时文件进行删除清理。
    • 影响分析:随着定时任务的不断执行,服务器磁盘上的 Excel 和 PNG 文件会不断堆积,最终必然导致服务器磁盘空间耗尽(Disk Full),引发应用宕机或其他不可预知的系统错误。
    • 优化建议:在文件处理完成后,务必使用 finally 块将本地产生的临时 Excel 文件和生成的图片文件删除。如果第三方组件支持,建议优先考虑基于内存流(InputStream/OutputStream)进行转换,避免落盘。 java File excelFile = new File(localFileDir); File imageFile = new File(filePath + fileName); try { // 处理逻辑... } finally { // 清理临时文件 if (excelFile.exists()) excelFile.delete(); if (imageFile.exists()) imageFile.delete(); }

    3. 重要:异常吞没与潜在的空指针异常(功能正确性与健壮性)

    • 问题描述:
      1. StaffDailyReportRemoteImpl 中的 sendAllSceneTypeReportMessageLxJob 方法捕获了 RpcServiceException 后仅做了日志打印,未向上抛出,且接口返回类型为 void。
      2. SendWorkWechatMessageService 中,判断 !merchantRpcResponse.hasResult() 时仅打印了 error 日志,没有中断执行(缺少 return 或 throw)。
    • 影响分析:
      1. RPC 接口吞没异常且返回 void,会导致调用方(如定时任务调度中心)永远认为任务执行成功,失去了重试和告警的能力,掩盖了线上故障。
      2. 当 RPC 响应无结果时继续往下执行,merchantRpcResponse.getResult() 可能返回 null,导致后续的 CollectionUtils.isEmpty(merchantList) 或 for 循环抛出 NullPointerException。
    • 优化建议:
      1. 建议将 Dubbo 接口的返回值改为 RpcResponse<Void> 或 RpcResponse<Boolean>,将执行结果或异常状态明确返回给调用方。
      2. 在处理 RPC 响应时,若判断失败,应立即中断当前流程: java if (!merchantRpcResponse.hasResult()) { log.error("理想品牌门店查询异常:{}", merchantRpcResponse.getMessage()); return; // 或抛出自定义业务异常 }

    二、评分明细

    • 功能实现的正确性与健壮性(32/40分):核心业务逻辑基本完整。但存在明显的健壮性缺陷,包括 RPC 结果校验后未阻断流程导致潜在 NPE,以及 Dubbo 接口吞没异常掩盖真实执行状态,扣 8 分。
    • 安全性与潜在风险(30/30分):未发现 SQL 注入、越权、XSS 等明显安全漏洞,参数解析基本符合规范,得满分。
    • 最佳实践与可维护性(12/20分):滥用 @Transactional 注解(大事务包含网络请求)严重违背工程最佳实践;注入的 Bean 命名不规范(merchantRemote2 带有不明意义的数字);缺少本地资源的释放,扣 8 分。
    • 性能与资源利用(2/5分):在循环中发起 HTTP 请求性能较差;更关键的是产生了本地文件且未清理,存在严重的磁盘资源泄漏隐患,扣 3 分。
    • 提交信息质量(5/5分):Commit 信息格式规范,清晰地分点列出了新增方法的作用和重构的逻辑,便于代码追溯,得满分。

    总分:81分

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