Commit a9a840df by zhouhaibao

feat(business-scene-analysis): 添加业务场景分析中的归属周期日期功能

- 在商户交付目标配置查询方法中新增bizs参数支持
- 添加归属周期开始日期和结束日期字段到门店详情汇总响应中
- 实现周期日期格式化处理(截取至月份级别)
- 更新数据传输对象以支持新的日期范围显示需求
1 parent fb2c98cb
...@@ -149,4 +149,15 @@ public class StoreDetailSummaryResponse implements Serializable { ...@@ -149,4 +149,15 @@ public class StoreDetailSummaryResponse implements Serializable {
@ApiModelProperty(notes = "触客转化率环比") @ApiModelProperty(notes = "触客转化率环比")
private String contactConversionRateMom; private String contactConversionRateMom;
/**
* 归属周期-开始日期(yyyy-MM-dd)
*/
private String periodStartDate;
/**
* 归属周期-结束日期(yyyy-MM-dd)
*/
private String periodEndDate;
} }
...@@ -27,10 +27,12 @@ public interface MerchantDeliverTargetConfigMapper { ...@@ -27,10 +27,12 @@ public interface MerchantDeliverTargetConfigMapper {
* *
* @param merchantId 商户号 * @param merchantId 商户号
* @param targetMonth 目标月份(yyyy-MM) * @param targetMonth 目标月份(yyyy-MM)
* @param bizs
* @return 最大周期配置 * @return 最大周期配置
*/ */
MerchantDeliverTargetConfigDTO selectMaxPeriodByMerchantAndMonth(@Param("merchantId") Integer merchantId, MerchantDeliverTargetConfigDTO selectMaxPeriodByMerchantAndMonth(@Param("merchantId") Integer merchantId,
@Param("targetMonth") String targetMonth); @Param("targetMonth") String targetMonth,
@Param("bizs") Integer bizs);
/** /**
* 查询门店的所有交付目标配置(按周期结束日期降序) * 查询门店的所有交付目标配置(按周期结束日期降序)
......
...@@ -2584,12 +2584,17 @@ public class BusinessSceneAnalysisService { ...@@ -2584,12 +2584,17 @@ public class BusinessSceneAnalysisService {
DateUtil.format(DateUtil.date(), "yyyy-MM"); DateUtil.format(DateUtil.date(), "yyyy-MM");
// 查询门店最大归属周期配置 // 查询门店最大归属周期配置
MerchantDeliverTargetConfigDTO config = merchantDeliverTargetConfigMapper.selectMaxPeriodByMerchantAndMonth(merchantId, targetMonth); MerchantDeliverTargetConfigDTO config = merchantDeliverTargetConfigMapper.selectMaxPeriodByMerchantAndMonth(merchantId, targetMonth,req.getBizs());
if (config != null && config.getTargetValue() != null) { if (config != null && config.getTargetValue() != null) {
// 使用目标配置表中的交付数 // 使用目标配置表中的交付数
res.setNewCarDeliveryCount(config.getTargetValue()); res.setNewCarDeliveryCount(config.getTargetValue());
res.setNewCarDeliveryCountMom(null); // 主机厂版不计算环比 res.setNewCarDeliveryCountMom(null); // 主机厂版不计算环比
String periodStartDate = config.getPeriodStartDate();
res.setPeriodStartDate(periodStartDate.substring(0, periodStartDate.length() - 2));
String periodEndDate = config.getPeriodEndDate();
res.setPeriodEndDate(periodEndDate.substring(0, periodEndDate.length() - 2));
}else{ }else{
res.setNewCarDeliveryCount(null); res.setNewCarDeliveryCount(null);
res.setNewCarDeliveryCountMom(null); res.setNewCarDeliveryCountMom(null);
...@@ -2625,7 +2630,8 @@ public class BusinessSceneAnalysisService { ...@@ -2625,7 +2630,8 @@ public class BusinessSceneAnalysisService {
DateUtil.format(DateUtil.date(), "yyyy-MM"); DateUtil.format(DateUtil.date(), "yyyy-MM");
// 查询门店最大归属周期配置 // 查询门店最大归属周期配置
MerchantDeliverTargetConfigDTO config = merchantDeliverTargetConfigMapper.selectMaxPeriodByMerchantAndMonth(merchantId, targetMonth); MerchantDeliverTargetConfigDTO config = merchantDeliverTargetConfigMapper.selectMaxPeriodByMerchantAndMonth(merchantId, targetMonth,
req.getBizs());
if (config != null && config.getTargetValue() != null && config.getTargetValue().compareTo(BigDecimal.ZERO) > 0) { if (config != null && config.getTargetValue() != null && config.getTargetValue().compareTo(BigDecimal.ZERO) > 0) {
// 使用目标配置表中的交付数 // 使用目标配置表中的交付数
......
  • @wangxw1
    commented
    Master

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

    1. 严重:脆弱的字符串截取逻辑存在极高的空指针与越界异常风险

    • 问题描述:在 BusinessSceneAnalysisService.java 中,对 periodStartDate 和 periodEndDate 直接使用了 .substring(0, length - 2)。如果 config.getPeriodStartDate() 返回值为 null,将直接抛出 NullPointerException;如果字符串长度小于 2,将抛出 StringIndexOutOfBoundsException。此外,通过硬编码减 2 来“截取至月份级别”逻辑极不可靠(例如,针对 2023-10-15 截取后会变成 2023-10-,并不符合标准日期格式)。
    • 影响分析:一旦数据库中该字段为空或格式不符预期,将导致该核心业务接口直接崩溃(HTTP 500),严重影响功能健壮性与可用性。
    • 优化建议:增加非空校验;废弃基于字符串长度截取的做法,改用标准的日期解析与格式化工具(如 Hutool 的 DateUtil 或 Java 8 的 LocalDate)。
    • 代码示例: java // 建议使用安全的日期处理方式,或至少增加非空与长度校验 String periodStartDate = config.getPeriodStartDate(); if (StrUtil.isNotBlank(periodStartDate) && periodStartDate.length() >= 7) { // 假设原始格式为 yyyy-MM-dd,截取前7位即可得到 yyyy-MM res.setPeriodStartDate(periodStartDate.substring(0, 7)); }

    2. 高风险:Mapper 接口变更但未见对应的 XML SQL 更新

    • 问题描述:在 MerchantDeliverTargetConfigMapper.java 中,selectMaxPeriodByMerchantAndMonth 方法新增了 @Param("bizs") Integer bizs 参数。但在本次代码变更中,并未看到对应的 MerchantDeliverTargetConfigMapper.xml 文件的修改。
    • 影响分析:如果确实遗漏了 XML 文件的更新,在运行时调用该方法时,会导致 MyBatis 抛出 BindingException 或无法正确过滤新增的 bizs 业务逻辑,导致功能失效。
    • 优化建议:请确认对应的 Mapper XML 文件是否已经同步更新,并在 SQL 中正确且安全地使用了 #{bizs} 参数。同时注意,根据审查规则,MyBatis 的 SQL 语句中严禁使用子查询,请在更新 XML 时严格遵守。

    3. 一般:DTO 缺失 Swagger/API 文档注解

    • 问题描述:在 StoreDetailSummaryResponse.java 中,原有的字段(如 contactConversionRateMom)都配置了 @ApiModelProperty 注解,但新增的 periodStartDate 和 periodEndDate 字段只写了单行注释,未添加 API 文档注解。
    • 影响分析:导致前端或调用方在查看 Swagger/Knife4j 接口文档时,无法看到这两个新字段的说明,增加了沟通成本,不符合团队工程最佳实践。
    • 优化建议:保持代码风格一致性,为新字段补充 @ApiModelProperty 注解。
    • 代码示例: ```java @ApiModelProperty(value = "归属周期-开始日期(yyyy-MM-dd)") private String periodStartDate;

    @ApiModelProperty(value = "归属周期-结束日期(yyyy-MM-dd)") private String periodEndDate;

    
    ---
    
    #### 二、评分明细
    
    - **功能实现的正确性与健壮性(22/40分)**:扣分主要因为 Service 层中直接调用 `substring` 处理未经非空校验的字符串,存在极大的 `NullPointerException` 和越界崩溃风险;且截取逻辑的正确性存疑。此外,Mapper 接口变更缺失 XML 对应修改也是重大隐患。(注:本次变更的 Mapper 属于 DAO 层,非 Dubbo Remote 接口,未触犯参数变更红线)。
    - **安全性与潜在风险(30/30分)**:Java 代码层面未发现 SQL 注入、越权等明显安全漏洞(假设未提供的 XML 中使用的是安全的 `#{}` 预编译参数)。
    - **最佳实践与可维护性(14/20分)**:DTO 实体类新增字段遗漏了与上下文一致的 `@ApiModelProperty` 注解;使用字符串截取来处理日期格式转换不符合最佳实践,应使用专业的日期格式化工具。
    - **性能与资源利用(5/5分)**:代码变更较小,未发现明显的性能瓶颈或资源浪费(如循环内查库等现象)。
    - **提交信息质量(5/5分)**:Commit 信息采用了 `feat(scope): subject` 的标准格式,且详细列出了修改点,清晰、准确、可追溯。
    
    总分:76分
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!