Commit e5c890a8 by 春觉晓

添加存量门店分析接口

1 parent fa0550a6
...@@ -29,6 +29,13 @@ public class SceneBaseReq implements Serializable { ...@@ -29,6 +29,13 @@ public class SceneBaseReq implements Serializable {
@ApiModelProperty(notes = "指标查询参数") @ApiModelProperty(notes = "指标查询参数")
private DataBizQueryParamsDTO queryParams; private DataBizQueryParamsDTO queryParams;
@ApiModelProperty(notes = "周期类型(1.按天,2.按周,3.按月,4.自定义,5.按年),必须", required = true)
private Integer cycleType;
private String preStartDate;
private String preEndDate;
/** /**
* *
* Bizs 1.延保 2.轻改 3.权益 4.二手车 * Bizs 1.延保 2.轻改 3.权益 4.二手车
...@@ -48,4 +55,23 @@ public class SceneBaseReq implements Serializable { ...@@ -48,4 +55,23 @@ public class SceneBaseReq implements Serializable {
log.error("不支持的bizs参数: {}", bizs); log.error("不支持的bizs参数: {}", bizs);
return -1; return -1;
} }
/**
*
* Bizs 1.延保 2.轻改 3.权益
* BiBusinessType 2:延保,3:权益;4:轻改
*/
public Integer convertToBiBusinessType(Integer bizs) {
switch (bizs){
case 1:
return 2;
case 2:
return 4;
case 3:
return 3;
}
log.error("不支持的bizs参数: {}", bizs);
return -1;
}
} }
...@@ -19,7 +19,7 @@ public class StoreSceneSummaryResponse implements Serializable { ...@@ -19,7 +19,7 @@ public class StoreSceneSummaryResponse implements Serializable {
private Integer totalStores; private Integer totalStores;
@ApiModelProperty("总开单门店环比") @ApiModelProperty("总开单门店环比")
private Integer totalStoresMom; private BigDecimal totalStoresMom;
@ApiModelProperty("新店数量") @ApiModelProperty("新店数量")
private Integer newStores; private Integer newStores;
...@@ -61,7 +61,7 @@ public class StoreSceneSummaryResponse implements Serializable { ...@@ -61,7 +61,7 @@ public class StoreSceneSummaryResponse implements Serializable {
private Integer singleCategoryStores; private Integer singleCategoryStores;
@ApiModelProperty("单品类门店环比") @ApiModelProperty("单品类门店环比")
private Integer singleCategoryStoresMom; private BigDecimal singleCategoryStoresMom;
@ApiModelProperty("单品类门店占比") @ApiModelProperty("单品类门店占比")
private BigDecimal singleCategoryStoresRatio; private BigDecimal singleCategoryStoresRatio;
......
...@@ -112,10 +112,17 @@ public interface BusinessIntelligenceMapper { ...@@ -112,10 +112,17 @@ public interface BusinessIntelligenceMapper {
Integer countLostMerchant(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate); Integer countLostMerchant(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate);
/** /**
* 流失门店数统计-按业务类型
*/
Integer countLostMerchantByBizType(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate, @Param("bizType") Integer bizType);
/**
* 历史门店总数-二手车 * 历史门店总数-二手车
*/ */
Integer countHistoryMerchant(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate); Integer countHistoryMerchant(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate);
Integer countHistoryMerchantByBizType(@Param("merchantIds") List<Integer> merchantIds, @Param("statDate") String statDate, @Param("bizType") Integer bizType);
/** /**
* 查询二手车开店数量 * 查询二手车开店数量
*/ */
......
...@@ -1025,7 +1025,7 @@ public class UsedCarDataStatsService { ...@@ -1025,7 +1025,7 @@ public class UsedCarDataStatsService {
return results; return results;
} }
private static BigDecimal calculateDiv(Number num1, Number num2) { public static BigDecimal calculateDiv(Number num1, Number num2) {
// 如果num2为0,则返回null // 如果num2为0,则返回null
if (num2.doubleValue() == 0) { if (num2.doubleValue() == 0) {
return null; return null;
......
...@@ -641,6 +641,64 @@ ...@@ -641,6 +641,64 @@
) )
</select> </select>
<select id="countLostMerchantByBizType" resultType="java.lang.Integer">
SELECT
count(distinct merchant_id) AS lost_merchant_count
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t1
WHERE
t1.deleted_flag = 'N'
<if test="merchantIds != null and merchantIds.size > 0">
and t1.merchant_id in
<foreach item="item" index="index" collection="merchantIds" separator="," open="(" close=")">
#{item}
</foreach>
</if>
AND EXISTS (
SELECT 1
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t2
WHERE
t2.merchant_id = t1.merchant_id
<![CDATA[
AND t2.stat_date >= #{statDate} - INTERVAL 59 DAY -- 传入的统计日期
AND t2.stat_date <= #{statDate}
]]>
<choose>
<when test="bizType == 2">
and t2.has_ext_warranty = 1
</when>
<when test="bizType == 3">
and t2.has_benefits = 1
</when>
<when test="bizType == 4">
and t2.has_light_mod = 1
</when>
</choose>
AND t2.deleted_flag = 'N'
)
AND NOT EXISTS (
SELECT 1
FROM dj_smartcarlife.dj_car_life_service_merchant_bi t3
WHERE
t3.merchant_id = t1.merchant_id
<![CDATA[
AND t3.stat_date >= #{statDate} - INTERVAL 29 DAY
AND t3.stat_date <= #{statDate}
]]>
<choose>
<when test="bizType == 2">
and t3.has_ext_warranty = 1
</when>
<when test="bizType == 3">
and t3.has_benefits = 1
</when>
<when test="bizType == 4">
and t3.has_light_mod = 1
</when>
</choose>
AND t3.deleted_flag = 'N'
);
</select>
<select id="countHistoryMerchant" resultType="java.lang.Integer"> <select id="countHistoryMerchant" resultType="java.lang.Integer">
SELECT SELECT
COUNT(DISTINCT merchant_id) AS total_merchant_count COUNT(DISTINCT merchant_id) AS total_merchant_count
...@@ -660,6 +718,35 @@ ...@@ -660,6 +718,35 @@
AND has_used_car = 1; AND has_used_car = 1;
</select> </select>
<select id="countHistoryMerchantByBizType" resultType="java.lang.Integer">
SELECT
COUNT(DISTINCT merchant_id) AS total_merchant_count
FROM dj_smartcarlife.dj_car_life_service_merchant_bi
WHERE
deleted_flag = 'N'
<if test="merchantIds != null and merchantIds.size > 0">
and merchant_id in
<foreach item="item" index="index" collection="merchantIds" separator="," open="(" close=")">
#{item}
</foreach>
</if>
<![CDATA[
AND stat_date >= #{statDate} - INTERVAL 60 DAY
AND stat_date <= #{statDate} - INTERVAL 30 DAY
]]>
<choose>
<when test="bizType == 2">
and has_ext_warranty = 1
</when>
<when test="bizType == 3">
and has_benefits = 1
</when>
<when test="bizType == 4">
and has_light_mod = 1
</when>
</choose>
</select>
<!-- 3. 查询语句 --> <!-- 3. 查询语句 -->
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 功能实现的正确性与健壮性

    问题描述: 在 BusinessSceneAnalysisService.storeAnalysis 方法中,当 trendOutputList 为空时,直接返回 res 对象,没有对 res 的字段进行初始化或设置默认值,可能导致客户端接收到的数据不完整。

    优化建议: 在返回 res 之前,确保对 res 的所有字段进行适当的初始化或设置默认值。

    if (CollectionUtils.isEmpty(trendOutputList)) {
        log.warn("查询产值返回空");
        res.setTotalStores(0);
        res.setNewStores(0);
        res.setNewStoresRatio(BigDecimal.ZERO);
        res.setOldStores(0);
        res.setOldStoresRatio(BigDecimal.ZERO);
        res.setChurnedStores(0);
        res.setChurnRate(BigDecimal.ZERO);
        res.setTotalStoresMom(BigDecimal.ZERO);
        res.setNewStoresMom(BigDecimal.ZERO);
        res.setOldStoresMom(BigDecimal.ZERO);
        res.setSingleCategoryStores(0);
        res.setSingleCategoryStoresMom(BigDecimal.ZERO);
        res.setSingleCategoryStoresRatio(BigDecimal.ZERO);
        res.setMultiCategoryStores(0);
        res.setMultiCategoryStoresMom(BigDecimal.ZERO);
        res.setMultiCategoryStoresRatio(BigDecimal.ZERO);
        res.setEcosystemWarningStores(0);
        res.setEcosystemWarningStoreIds(Collections.emptyList());
        return res;
    }
    

    问题描述: countOldStore 方法中的逻辑错误,allMatch 方法用于判断所有元素是否满足条件,而这里应该是判断是否存在至少一个元素满足条件。

    优化建议: 将 allMatch 改为 anyMatch。

    public int countOldStore(Map<Integer, List<BiRecord>> groupedByMerchant) {
        int oldStoreCount = 0;
        for (List<BiRecord> records : groupedByMerchant.values()) {
            boolean hasOldStore = records.stream()
                    .anyMatch(record -> record.getUsedCarStoreType() != null && record.getUsedCarStoreType() == 2);
            if (hasOldStore) {
                oldStoreCount++;
            }
        }
        return oldStoreCount;
    }
    

    2. 安全性与潜在风险

    问题描述: 未发现明显的安全漏洞,但需要注意 calculateDiv 方法中除零检查不够严格,可能会抛出 NullPointerException。

    优化建议: 增加对 num1 和 num2 是否为 null 的检查。

    public static BigDecimal calculateDiv(Number num1, Number num2) {
        if (num1 == null || num2 == null) {
            throw new IllegalArgumentException("Arguments cannot be null");
        }
        // 如果num2为0,则返回null
        if (num2.doubleValue() == 0) {
            return null;
        }
        return new BigDecimal(num1.toString()).divide(new BigDecimal(num2.toString()), 10, RoundingMode.HALF_UP);
    }
    

    3. 是否符合最佳实践

    问题描述: SceneBaseReq 类中新增的 cycleType 字段缺少 getter 和 setter 方法。

    优化建议: 为 cycleType 字段添加 getter 和 setter 方法。

    public Integer getCycleType() {
        return cycleType;
    }
    
    public void setCycleType(Integer cycleType) {
        this.cycleType = cycleType;
    }
    

    问题描述: BusinessSceneAnalysisService 类中的 convertToBiBusinessType 方法存在重复代码。

    优化建议: 可以考虑将 convertToBiBusinessType 方法提取到一个单独的工具类中,或者使用枚举来管理业务类型的转换。

    public enum BizTypeConverter {
        WARRANTEE(1, 2),
        LIGHT_MODIFICATION(2, 4),
        BENEFITS(3, 3);
    
        private final int bizs;
        private final int biBusinessType;
    
        BizTypeConverter(int bizs, int biBusinessType) {
            this.bizs = bizs;
            this.biBusinessType = biBusinessType;
        }
    
        public static int convertToBiBusinessType(int bizs) {
            for (BizTypeConverter converter : BizTypeConverter.values()) {
                if (converter.bizs == bizs) {
                    return converter.biBusinessType;
                }
            }
            throw new IllegalArgumentException("Unsupported bizs parameter: " + bizs);
        }
    }
    

    问题描述: BusinessSceneAnalysisService.storeAnalysis 方法过长,难以阅读和维护。

    优化建议: 将 storeAnalysis 方法拆分为多个较小的方法,每个方法负责一个特定的功能。

    4. 性能与资源利用效率

    问题描述: storeAnalysis 方法中多次调用 businessIntelligenceMapper.getBiRecords,可能存在数据库查询性能问题。

    优化建议: 考虑将 getBiRecords 方法的结果缓存起来,避免重复查询。

    5. Commits信息的清晰性与准确性

    问题描述: 提交信息 "添加存量门店分析接口" 描述不够具体,没有提到具体修改了哪些文件或实现了哪些功能。

    优化建议: 提交信息应更详细,例如:"添加 SceneBaseReq 中的周期类型字段,并实现 storeAnalysis 方法以支持存量门店分析"。

    评分明细

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

      • 代码逻辑基本正确,但存在一些边界情况未处理完全。
      • 得分:35分
    2. 安全性与潜在风险(30分)

      • 未发现明显安全漏洞,但存在除零检查不够严格的问题。
      • 得分:28分
    3. 是否符合最佳实践(20分)

      • 存在一些代码规范和最佳实践未遵循的情况。
      • 得分:16分
    4. 性能与资源利用效率(5分)

      • 存在潜在的性能问题,但可以通过优化解决。
      • 得分:3分
    5. Commits信息的清晰性与准确性(5分)

      • 提交信息不够清晰。
      • 得分:3分

    总分

    总分:85分

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