Commit beb54bdf by zhouhaibao

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

2 parents 06163bd7 964e8575
......@@ -32,7 +32,7 @@ public class GoodsCategorySummaryResponse implements Serializable {
@ApiModelProperty(notes = "整车延保-转化率兜底目标")
private BigDecimal vehicleWarrantyConversionBottomTarget;
@ApiModelProperty(notes = "整车延保-生态系数")
@ApiModelProperty(notes = "整车延保-生态系数(依据渗透率计算)")
private BigDecimal vehicleWarrantyEcoCoefficient;
@ApiModelProperty(notes = "安心包-成交数")
......@@ -152,4 +152,161 @@ public class GoodsCategorySummaryResponse implements Serializable {
@ApiModelProperty(notes = "精品附件-生态系数")
private BigDecimal accessoriesEcoCoefficient;
}
/**
* 计算生态系数的通用方法
*
* @param penetrationRate 渗透率
* @param thresholds 阈值数组,格式为 [threshold1, coefficient1, threshold2, coefficient2, ...]
* @param defaultCoefficient 默认系数(当渗透率小于最小阈值时)
* @return 计算得到的生态系数
*/
private BigDecimal computeEcoCoefficient(BigDecimal penetrationRate, BigDecimal[] thresholds, BigDecimal defaultCoefficient) {
if (penetrationRate == null) {
return null;
}
// 检查渗透率是否大于等于最大阈值
for (int i = 0; i < thresholds.length; i += 2) {
if (penetrationRate.compareTo(thresholds[i]) >= 0) {
return thresholds[i + 1]; // 返回对应的系数
}
}
// 如果渗透率小于所有阈值,返回默认系数
return defaultCoefficient;
}
/**
* 计算整车延保-生态系数
*
* 按照渗透率,匹配对应的生态系数,详细匹配规则如下:
* x>=0.6:1.2
* 0.5<=x<0.6:1
* 0.4<=x<0.5:0.8
* 0.3<=x<0.4:0.6
* x<0.3:0
*/
public void computeVehicleWarrantyEcoCoefficient() {
if (this.vehicleWarrantyPenetrationRate == null) {
return;
}
BigDecimal[] thresholds = {
new BigDecimal("0.6"), new BigDecimal("1.2"), // x>=0.6:1.2
new BigDecimal("0.5"), new BigDecimal("1.0"), // 0.5<=x<0.6:1.0
new BigDecimal("0.4"), new BigDecimal("0.8"), // 0.4<=x<0.5:0.8
new BigDecimal("0.3"), new BigDecimal("0.6") // 0.3<=x<0.4:0.6
};
this.vehicleWarrantyEcoCoefficient = computeEcoCoefficient(this.vehicleWarrantyPenetrationRate, thresholds, BigDecimal.ZERO);
}
/**
* 计算安心包-生态系数
*/
public void computeSafetyPackageEcoCoefficient() {
if (this.safetyPackagePenetrationRate == null) {
return;
}
BigDecimal[] thresholds = {
new BigDecimal("0.2"), new BigDecimal("1.2"), // x>=0.2:1.2
new BigDecimal("0.15"), new BigDecimal("1.0"), // 0.15<=x<0.2:1.0
new BigDecimal("0.1"), new BigDecimal("0.8"), // 0.1<=x<0.15:0.8
new BigDecimal("0.05"), new BigDecimal("0.6") // 0.05<=x<0.1:0.6
};
this.safetyPackageEcoCoefficient = computeEcoCoefficient(this.safetyPackagePenetrationRate, thresholds, BigDecimal.ZERO);
}
/**
* 计算电池延保-生态系数
*/
public void computeBatteryWarrantyEcoCoefficient() {
if (this.batteryWarrantyPenetrationRate == null) {
return;
}
BigDecimal[] thresholds = {
new BigDecimal("0.15"), new BigDecimal("1.2"), // x>=0.15:1.2
new BigDecimal("0.11"), new BigDecimal("1.0"), // 0.11<=x<0.15:1.0
new BigDecimal("0.08"), new BigDecimal("0.8"), // 0.08<=x<0.11:0.8
new BigDecimal("0.05"), new BigDecimal("0.6") // 0.05<=x<0.08:0.6
};
this.batteryWarrantyEcoCoefficient = computeEcoCoefficient(this.batteryWarrantyPenetrationRate, thresholds, BigDecimal.ZERO);
}
/**
* 计算轮胎延保-生态系数
*/
public void computeTireWarrantyEcoCoefficient() {
if (this.tireWarrantyPenetrationRate == null) {
return;
}
BigDecimal[] thresholds = {
new BigDecimal("0.15"), new BigDecimal("1.2"), // x>=0.15:1.2
new BigDecimal("0.11"), new BigDecimal("1.0"), // 0.11<=x<0.15:1.0
new BigDecimal("0.08"), new BigDecimal("0.8"), // 0.08<=x<0.11:0.8
new BigDecimal("0.05"), new BigDecimal("0.6") // 0.05<=x<0.08:0.6
};
this.tireWarrantyEcoCoefficient = computeEcoCoefficient(this.tireWarrantyPenetrationRate, thresholds, BigDecimal.ZERO);
}
/**
* 计算车窗膜-生态系数
*/
public void computeWindowFilmEcoCoefficient() {
if (this.windowFilmPenetrationRate == null) {
return;
}
BigDecimal[] thresholds = {
new BigDecimal("500"), new BigDecimal("1.2"),
new BigDecimal("400"), new BigDecimal("1.0"),
new BigDecimal("300"), new BigDecimal("0.8"),
new BigDecimal("200"), new BigDecimal("0.6")
};
this.windowFilmEcoCoefficient = computeEcoCoefficient(this.windowFilmPenetrationRate, thresholds, BigDecimal.ZERO);
}
/**
* 计算车身膜-生态系数
*/
public void computeCarBodyFilmEcoCoefficient() {
if (this.carBodyFilmPenetrationRate == null) {
return;
}
BigDecimal[] thresholds = {
new BigDecimal("1200"), new BigDecimal("1.2"),
new BigDecimal("1000"), new BigDecimal("1.0"),
new BigDecimal("700"), new BigDecimal("0.8"),
new BigDecimal("400"), new BigDecimal("0.6")
};
this.carBodyFilmEcoCoefficient = computeEcoCoefficient(this.carBodyFilmPenetrationRate, thresholds, BigDecimal.ZERO);
}
/**
* 计算精品附件-生态系数
*/
public void computeAccessoriesEcoCoefficient() {
if (this.accessoriesPenetrationRate == null) {
return;
}
BigDecimal[] thresholds = {
new BigDecimal("3600"), new BigDecimal("1.2"),
new BigDecimal("3400"), new BigDecimal("1.0"),
new BigDecimal("3200"), new BigDecimal("0.8"),
new BigDecimal("3000"), new BigDecimal("0.6")
};
this.accessoriesEcoCoefficient = computeEcoCoefficient(this.accessoriesPenetrationRate, thresholds, BigDecimal.ZERO);
}
}
\ No newline at end of file
......@@ -32,7 +32,7 @@ public class StoreEmployeeRankResponse implements Serializable {
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public static class EmployeeAnalysisItem {
public static class EmployeeAnalysisItem implements Serializable{
@ApiModelProperty(notes = "员工ID")
private String employeeId;
......
package cn.com.glsx.dj.peanalysis.config;
import cn.com.glsx.dj.mindworkplate.remote.BiAnalysisRemote;
import cn.com.glsx.dj.mindworkplate.remote.WarningMsgRemote;
import lombok.RequiredArgsConstructor;
import org.oreframework.boot.autoconfigure.dubbo.reference.ReferenceBuilderFactory;
import org.springframework.context.annotation.Bean;
......@@ -27,5 +28,14 @@ public class MindWorkPlateDubboConfig {
.build();
}
@Bean
public WarningMsgRemote warningMsgRemote(){
return factory
.builder(WarningMsgRemote.class)
.check(false)
.timeout(30000)
.build();
}
}
......@@ -463,11 +463,15 @@ public class BusinessAnalysisService {
* @return 环比
*/
private BigDecimal calculateMom(BigDecimal current, BigDecimal last) {
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
// 上期为0,环比无穷大?通常业务定义为 0 或 100%
// 这里按“无法计算”返回 null,或根据需求返回 0 / 100
if (current == null) {
return null;
}
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
// 上期为0:若本期>0,通常视为 +100% 或无穷大;这里按业务常见做法返回 100%
return current.compareTo(BigDecimal.ZERO) > 0
? new BigDecimal("100.00")
: BigDecimal.ZERO;
}
return current.subtract(last)
.divide(last, 6, RoundingMode.HALF_UP) // 高精度中间计算
.multiply(BigDecimal.valueOf(100))
......@@ -482,11 +486,15 @@ public class BusinessAnalysisService {
* @return
*/
private BigDecimal calculatePercent(BigDecimal current, BigDecimal last) {
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
// 上期为0,环比无穷大?通常业务定义为 0 或 100%
// 这里按“无法计算”返回 null
if (current == null) {
return null;
}
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
// 分母为0:若分子>0,通常视为无穷大;这里按业务常见做法返回 100%
return current.compareTo(BigDecimal.ZERO) > 0
? new BigDecimal("100.00")
: BigDecimal.ZERO;
}
return current.divide(last, 10, RoundingMode.HALF_UP) // 先用较高精度做除法
.multiply(BigDecimal.valueOf(100))
.setScale(2, RoundingMode.HALF_UP);
......@@ -500,11 +508,15 @@ public class BusinessAnalysisService {
* @return
*/
private BigDecimal calculateAvg(BigDecimal current, BigDecimal last) {
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
// 上期为0,环比无穷大?通常业务定义为 0 或 100%
// 这里按“无法计算”返回 null
if (current == null) {
return null;
}
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
// 分母为0:若分子>0,通常视为无穷大;这里按业务常见做法返回较大值
return current.compareTo(BigDecimal.ZERO) > 0
? new BigDecimal("999999.00")
: BigDecimal.ZERO;
}
return current.divide(last, 10, RoundingMode.HALF_UP) // 先用较高精度做除法
.setScale(2, RoundingMode.HALF_UP);
}
......
package cn.com.glsx.dj.peanalysis.service;
import cn.com.glsx.dj.mindworkplate.model.EarlyWarningThresholdConfig;
import cn.com.glsx.dj.mindworkplate.remote.WarningMsgRemote;
import cn.com.glsx.dj.peanalysis.config.DataStatsConfig;
import cn.com.glsx.dj.peanalysis.config.DataStatsConstants;
import cn.com.glsx.dj.peanalysis.dto.DataBizQueryParamsDTO;
......@@ -24,7 +26,10 @@ import cn.com.glsx.merchants.model.response.MerchantProvinceDTO;
import cn.com.glsx.merchants.model.response.MerchantStaffResponse;
import cn.com.glsx.merchants.remote.MerchantRemote;
import cn.com.glsx.merchants.remote.MerchantStaffRemote;
import cn.hutool.core.date.*;
import cn.hutool.core.date.DateField;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
......@@ -92,6 +97,9 @@ public class BusinessSceneAnalysisService {
@Resource
private MerchantBiMatterMapper merchantBiMatterMapper;
@Resource
private WarningMsgRemote warningMsgRemote;
/**
* 总产值、目标产值、达成率
......@@ -973,9 +981,15 @@ public class BusinessSceneAnalysisService {
* 计算环比
*/
public BigDecimal computeMon(BigDecimal current, BigDecimal last) {
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
if (current == null) {
return null;
}
if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
// 上期为0:若本期>0,通常视为 +100% 或无穷大;这里按业务常见做法返回 100%
return current.compareTo(BigDecimal.ZERO) > 0
? new BigDecimal("100.00")
: BigDecimal.ZERO;
}
return current.subtract(last).divide(last, 4, RoundingMode.HALF_UP);
}
......@@ -1497,6 +1511,7 @@ public class BusinessSceneAnalysisService {
log.error("品类分析指标查询失败,参数:{}", queryParams);
return res;
}
// 还需要计算生态系数
dataMap.forEach((code, dataList) -> {
DataBusinessDTO data = mergeDataList(dataList);
switch (code) {
......@@ -1510,6 +1525,7 @@ public class BusinessSceneAnalysisService {
break;
case DataStatsConstants.ITEM_CODE_A067: // 整车延保-渗透率
res.setVehicleWarrantyPenetrationRate(data.getItemValue());
res.computeVehicleWarrantyEcoCoefficient(); // 整车延保-生态系数
break;
case DataStatsConstants.ITEM_CODE_A099: // 整车延保-转化率
res.setVehicleWarrantyConversionRate(data.getItemValue());
......@@ -1520,6 +1536,7 @@ public class BusinessSceneAnalysisService {
break;
case DataStatsConstants.ITEM_CODE_A092: // 安心包-渗透率
res.setSafetyPackagePenetrationRate(data.getItemValue());
res.computeSafetyPackageEcoCoefficient(); // 安心包-生态系数
break;
case DataStatsConstants.ITEM_CODE_A089: // 安心包-转化率
res.setSafetyPackageConversionRate(data.getItemValue());
......@@ -1530,6 +1547,7 @@ public class BusinessSceneAnalysisService {
break;
case DataStatsConstants.ITEM_CODE_A094: // 电池延保-渗透率
res.setBatteryWarrantyPenetrationRate(data.getItemValue());
res.computeBatteryWarrantyEcoCoefficient(); // 电池延保-生态系数
break;
case DataStatsConstants.ITEM_CODE_A091: // 电池延保-转化率
res.setBatteryWarrantyConversionRate(data.getItemValue());
......@@ -1540,6 +1558,7 @@ public class BusinessSceneAnalysisService {
break;
case DataStatsConstants.ITEM_CODE_A093: // 轮胎延保-渗透率
res.setTireWarrantyPenetrationRate(data.getItemValue());
res.computeTireWarrantyEcoCoefficient();
break;
case DataStatsConstants.ITEM_CODE_A090: // 轮胎延保-转化率
res.setTireWarrantyConversionRate(data.getItemValue());
......@@ -1550,6 +1569,7 @@ public class BusinessSceneAnalysisService {
break;
case DataStatsConstants.ITEM_CODE_A0108: // 车窗膜-渗透率
res.setWindowFilmPenetrationRate(data.getItemValue());
res.computeWindowFilmEcoCoefficient();
break;
case DataStatsConstants.ITEM_CODE_A0109: // 车窗膜-转化率
res.setWindowFilmConversionRate(data.getItemValue());
......@@ -1563,6 +1583,7 @@ public class BusinessSceneAnalysisService {
break;
case DataStatsConstants.ITEM_CODE_A0113: // 车身膜-渗透率
res.setCarBodyFilmPenetrationRate(data.getItemValue());
res.computeCarBodyFilmEcoCoefficient(); // 车身膜-生态系数
break;
case DataStatsConstants.ITEM_CODE_A0114: // 车身膜-转化率
res.setCarBodyFilmConversionRate(data.getItemValue());
......@@ -1576,6 +1597,7 @@ public class BusinessSceneAnalysisService {
break;
case DataStatsConstants.ITEM_CODE_A0118: // 精品附件-渗透率
res.setAccessoriesPenetrationRate(data.getItemValue());
res.computeAccessoriesEcoCoefficient(); // 精品附件-生态系数
break;
case DataStatsConstants.ITEM_CODE_A0119: // 精品附件-转化率
res.setAccessoriesConversionRate(data.getItemValue());
......@@ -1592,8 +1614,26 @@ public class BusinessSceneAnalysisService {
res.setAccessoriesPerCarOutput(computeSingleVehiclePurchaseOutput(res.getAccessoriesPerCarOutput(), res.getNewCarDeliveryCount(), rate));
res.setWindowFilmPerCarOutput(computeSingleVehiclePurchaseOutput(res.getWindowFilmPerCarOutput(), res.getNewCarDeliveryCount(), rate));
// 兜底目标和生态系数计算
// todo
// 查询兜底目标(非轻改场景)
if (req.getBizs() != 2) {
return res;
}
Integer merchantId = req.getMerchantIds().get(0); // 只取一个门店查询
RpcResponse<EarlyWarningThresholdConfig> warningConfigRes = warningMsgRemote.findByMerchantNo(merchantId + "");
if (!warningConfigRes.hasResult()) {
log.error("兜底预警目标配置查询异常: {}", warningConfigRes);
return res;
}
EarlyWarningThresholdConfig result = warningConfigRes.getResult();
res.setBatteryWarrantyConversionBottomTarget(result.getBatteryConversionRate()); // 电池转化率
res.setBatteryWarrantyPenetrationBottomTarget(result.getBatteryPenetrationRate()); // 电池渗透率
res.setVehicleWarrantyConversionBottomTarget(result.getEwConRate()); // 延保转化率
res.setVehicleWarrantyPenetrationBottomTarget(result.getEwPenetrationRate()); // 延保渗透率
res.setSafetyPackageConversionBottomTarget(result.getEwAxbConRate()); // 延保安心包转化率
res.setSafetyPackagePenetrationBottomTarget(result.getEwAxbPenetrationRate()); // 安心包渗透率
res.setTireWarrantyConversionBottomTarget(result.getEwLtConRate()); // 延保轮胎转化率
res.setTireWarrantyPenetrationBottomTarget(result.getEwLtPenetrationRate()); // 轮胎渗透率
// res.setVehicleWarrantyConversionBottomTarget(result.getRiConRate()); // 权益转化率
return res;
}
......@@ -1603,10 +1643,15 @@ public class BusinessSceneAnalysisService {
* 产值*比例/新车交付数
*/
private BigDecimal computeSingleVehiclePurchaseOutput(BigDecimal value, BigDecimal count, BigDecimal rate) {
if (value == null || count == null || BigDecimal.ZERO.compareTo(count) == 0) {
if (value == null || count == null || rate == null || BigDecimal.ZERO.compareTo(count) == 0) {
return null;
}
try {
return value.multiply(rate).divide(count, 2, RoundingMode.HALF_UP);
} catch (ArithmeticException e) {
log.error("计算单车采购产值时发生除法异常,value={}, count={}, rate={}", value, count, rate);
return null;
}
return value.multiply(rate).divide(count, 2, RoundingMode.HALF_UP);
}
public List<BiRecord> getBiRecords(Integer businessType, List<Integer> merchantIds, String startDate, String endDate) {
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. 变量命名不一致:

      • 问题描述:在方法中引入了新的变量startTime,但未明确其用途。同时,proviceId拼写错误,应为provinceId。
      • 优化建议:修正拼写错误,并确保变量命名一致且具有描述性。
    2. 返回值逻辑不清晰:

      • 问题描述:在循环结束后,如果未找到目标省份的排名,则返回0。这与之前的逻辑不符,可能导致调用者对返回值的误解。
      • 优化建议:建议返回一个更具描述性的值,例如-1表示未找到,或者保持之前逻辑不变。
    3. 缺少日志记录:

      • 问题描述:在关键步骤(如查找排名)缺少必要的日志记录,不利于调试和维护。
      • 优化建议:添加适当的日志记录,以便于跟踪代码执行过程中的重要信息。
    4. 代码重复:

      • 问题描述:在计算排名时,存在重复的逻辑(如currentValue.equals(lastValue)),可以进行重构以提高代码的可读性和可维护性。
      • 优化建议:将重复逻辑提取到单独的方法中,或者使用更简洁的数据结构和算法。

    评分明细

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

      • 得分:30分
      • 说明:代码逻辑基本正确,但在返回值和变量命名上存在一些问题,需要改进。
    2. 安全性与潜在风险(30分):

      • 得分:30分
      • 说明:代码中没有明显的安全漏洞,但如果req对象的参数来自外部输入,需要进一步验证输入的有效性。
    3. 是否符合最佳实践(20分):

      • 得分:15分
      • 说明:代码结构较为清晰,但变量命名不一致,缺少日志记录,需要改进。
    4. 性能与资源利用效率(5分):

      • 得分:5分
      • 说明:当前代码段没有明显的性能问题,但如果数据量较大,可能需要考虑优化算法。
    5. Commits信息的清晰性与准确性(5分):

      • 得分:3分
      • 说明:提交信息不够清晰,建议详细描述所做的修改及其原因。

    总分:83分


    以上是本次代码审查的详细报告,希望对开发者有所帮助。如有任何疑问或需要进一步讨论的地方,请随时联系。

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