Commit a2eebcd8 by 张富康

Merge remote-tracking branch 'origin/v5.5.1' into v5.5.1

2 parents 4d406ba5 2940e30b
......@@ -13,7 +13,7 @@ public class StoreBusinessDetail implements Serializable {
private static final long serialVersionUID = -1;
@ApiModelProperty(notes = "业务类型:1-延保,2-权益,3-轻改,4-二手车", example = "1")
@ApiModelProperty(notes = "业务类型:1-延保,3-权益,2-轻改,4-二手车", example = "1")
private Integer sceneType;
@ApiModelProperty(notes = "该业务产值", example = "5000.00")
......@@ -22,6 +22,8 @@ public class StoreBusinessDetail implements Serializable {
@ApiModelProperty(notes = "该业务占门店总产值的比例(小数形式,如 0.625 表示 62.5%)", example = "0.6250")
private BigDecimal ratio;
private BigDecimal profit;
@ApiModelProperty(notes = "该业务毛利率(小数形式,如 0.3 表示 30%)", example = "0.3000")
private BigDecimal profitMargin;
}
\ No newline at end of file
......@@ -18,5 +18,6 @@ public interface GoodsOrderMapper extends OreMapper<GoodsOrder> {
@Param("staffUuids") List<String> staffUuids,
@Param("startDate") Date startDate,
@Param("endDate") Date endDate,
@Param("businessType") Byte businessType,
@Param("scene") Integer sceneType);
}
\ No newline at end of file
......@@ -528,7 +528,7 @@ public class BusinessAnalysisService {
*/
public static BigDecimal stringToPercent(String str) {
if (str == null || str.trim().isEmpty()) {
return BigDecimal.ZERO; // 或抛异常,根据业务需求
return null; // 或抛异常,根据业务需求
}
try {
......@@ -1062,7 +1062,7 @@ public class BusinessAnalysisService {
return rank;
}
}
return 0;
return rank+1;
}
......@@ -1950,9 +1950,9 @@ public class BusinessAnalysisService {
resp.setStoreName(merchantNameResponses.stream()
.filter(dto -> dto.getMerchantId().equals(entry.getKey())).findFirst()
.map(MerchantNameResponse::getMerchantName).orElse(""));
BigDecimal reduce = disConfigByMerchant.get(entry.getKey()) == null ? BigDecimal.ZERO
: disConfigByMerchant.get(entry.getKey());
resp.setGrossProfitMargin(calculatePercent(reduce, entry.getValue()));
/* BigDecimal reduce = disConfigByMerchant.get(entry.getKey()) == null ? BigDecimal.ZERO
: disConfigByMerchant.get(entry.getKey());*/
// 处理每个场景的明细
Map<Integer, BigDecimal> integerBigDecimalMap = disConfigByStoreAndScene.get(
......@@ -2002,6 +2002,8 @@ public class BusinessAnalysisService {
profit = integerBigDecimalMap.get(sceneType) == null ? BigDecimal.ZERO
: integerBigDecimalMap.get(sceneType);
// 毛利率 = 毛利额 / 产值(避免除零)
detail.setProfit(profit); // 如果需要,可暂存 profit 到对象中
detail.setProfitMargin(calculatePercent(profit, sceneOutput));
}
......@@ -2009,7 +2011,15 @@ public class BusinessAnalysisService {
return detail;
})
.collect(Collectors.toList());
BigDecimal reduce = BigDecimal.ZERO;
if (checkSearchType(cycleType)) {
reduce = businessDetails.stream()
.map(StoreBusinessDetail::getProfit) // 假设你加了 getProfit()
.filter(Objects::nonNull)
.reduce(BigDecimal.ZERO, BigDecimal::add);
resp.setGrossProfitMargin(calculatePercent(reduce, storeTotalOutput));
}
resp.setBusinessDetails(businessDetails);
resp.setBussinessSize(businessDetails.size());
}
......
......@@ -788,7 +788,6 @@
AND t2.deleted_flag = 'N'
WHERE t3.partner_merchant_id =#{property}
AND t1.sub_merchant_type IN (6, 8)
AND t1.scene = 1
AND t1.deleted_flag = 'N'
</select>
......
......@@ -170,6 +170,9 @@
</if>
<if test="scene != null">
and o.scene_type = #{scene}
<if test="scene == 0">
and o.business_type = #{businessType}
</if>
</if>
<if test="startDate != null">
<![CDATA[ and (
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 日期处理逻辑错误

    问题描述: 在 HandlerSelfDailyDataJob 类中,日期处理逻辑被修改为从昨天开始到前一个月结束,这与业务需求不符。根据代码中的注释,预期的行为是从前一个月开始到昨天结束。

    优化建议: 恢复原来的日期处理逻辑,确保 startDateStr 和 endDateStr 分别代表前一个月和昨天的日期。

    String startDateStr = DateUtil.format(DateUtil.offsetMonth(DateUtil.yesterday(), -1), "yyyy-MM-dd");
    String endDateStr = DateUtil.format(DateUtil.yesterday(), "yyyy-MM-dd");
    

    2. 日志打印不准确

    问题描述: 在 BusinessIntelligenceService 类的 selfDailyDataHandle 方法中,日志打印信息中使用了 format(DateUtil.yesterday()),这与实际传入的参数 startDate 和 endDate 不一致。

    优化建议: 修正日志打印语句,确保日志信息与实际处理的日期范围一致。

    log.info("开始处理日期范围 {} 至 {}", startDate, endDate);
    

    3. 参数校验缺失

    问题描述: 在 selfDailyDataHandle 方法中,虽然移除了对 startDate 和 endDate 的空值检查,但没有提供默认行为或其他错误处理机制。

    优化建议: 重新引入参数校验逻辑,确保在参数为空或无效时能够进行适当的处理。

    if (StrUtil.isBlank(startDate) || StrUtil.isBlank(endDate)) {
        log.error("开始日期或结束日期为空");
        return; // 或者抛出异常
    }
    

    评分明细

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

      • 代码逻辑存在错误,需要修正日期处理逻辑(-10)
      • 日志打印信息不准确,需要修正(-5)
      • 参数校验缺失,需要重新引入(-5)
      • 得分:20分
    2. 安全性与潜在风险(30分):

      • 代码中未发现明显的安全漏洞(如SQL注入、XSS攻击等)
      • 得分:30分
    3. 是否符合最佳实践(20分):

      • 代码结构和命名规范基本符合标准
      • 日志打印信息不够明确,需要改进(-5)
      • 得分:15分
    4. 性能与资源利用效率(5分):

      • 代码中未发现明显的性能瓶颈或资源浪费
      • 得分:5分
    5. Commits信息的清晰性与准确性(5分):

      • 提交信息不够清晰,建议详细描述具体的修改内容
      • 得分:3分

    总分: 73分

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