Commit 3b5953fd by 林永健

refactor(service): 优化产值权限及指标数据处理逻辑

- 移除未使用的导入,简化代码依赖
- 扩展产值门店权限查询,添加异常处理防止空返回
- 调整日志打印,提升过滤条件及权限日志清晰度
- 优化指标查询逻辑,支持多指标并行调用及空结果处理
- 修正多个指标计算中母店数量的计算错误,保证精度
- 调整百分比转换逻辑,保证指标格式一致性
- 更新店铺产值、触客率等多个方法中权限校验调用方式
- 调整部分时间计算代码,避免日期差计算错误
- 修正API请求参数组装,保证请求ID排序及过滤正确
- 更新若干生态系数计算阈值,优化业务规则匹配
- 调整测试代码时间及数据,反映逻辑变更需求
1 parent baa1c7db
...@@ -115,7 +115,10 @@ public class SceneBaseReq implements Serializable { ...@@ -115,7 +115,10 @@ public class SceneBaseReq implements Serializable {
res.setExts(exts); res.setExts(exts);
} }
if (!CollectionUtils.isEmpty(merchantIds)) { if (!CollectionUtils.isEmpty(merchantIds)) {
res.setMerchantIds(merchantIds.stream().sorted().map(String::valueOf).collect(Collectors.joining(","))); res.setMerchantIds(merchantIds.stream().map(String::valueOf).filter(StringUtils::hasLength).sorted().collect(Collectors.joining(",")));
}
if (!CollectionUtils.isEmpty(staffUuids)) {
res.setStaffIds(staffUuids.stream().map(String::valueOf).filter(StringUtils::hasLength).sorted().collect(Collectors.joining(",")));
} }
return res; return res;
} }
......
...@@ -180,11 +180,6 @@ public class GoodsCategorySummaryResponse implements Serializable { ...@@ -180,11 +180,6 @@ public class GoodsCategorySummaryResponse implements Serializable {
* 计算整车延保-生态系数 * 计算整车延保-生态系数
* *
* 按照渗透率,匹配对应的生态系数,详细匹配规则如下: * 按照渗透率,匹配对应的生态系数,详细匹配规则如下:
* 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() { public void computeVehicleWarrantyEcoCoefficient() {
if (this.vehicleWarrantyPenetrationRate == null) { if (this.vehicleWarrantyPenetrationRate == null) {
...@@ -194,8 +189,9 @@ public class GoodsCategorySummaryResponse implements Serializable { ...@@ -194,8 +189,9 @@ public class GoodsCategorySummaryResponse implements Serializable {
BigDecimal[] thresholds = { BigDecimal[] thresholds = {
new BigDecimal("60"), new BigDecimal("1.2"), // x>=0.6:1.2 new BigDecimal("60"), new BigDecimal("1.2"), // x>=0.6:1.2
new BigDecimal("50"), new BigDecimal("1.0"), // 0.5<=x<0.6:1.0 new BigDecimal("50"), new BigDecimal("1.0"), // 0.5<=x<0.6:1.0
new BigDecimal("40"), new BigDecimal("0.8"), // 0.4<=x<0.5:0.8 new BigDecimal("45"), new BigDecimal("0.8"), // 0.45<=x<0.5:0.8
new BigDecimal("30"), new BigDecimal("0.6") // 0.3<=x<0.4:0.6 new BigDecimal("40"), new BigDecimal("0.6") // 0.4<=x<0.45:0.6
// x<0.4:0
}; };
this.vehicleWarrantyEcoCoefficient = computeEcoCoefficient(this.vehicleWarrantyPenetrationRate, thresholds, BigDecimal.ZERO); this.vehicleWarrantyEcoCoefficient = computeEcoCoefficient(this.vehicleWarrantyPenetrationRate, thresholds, BigDecimal.ZERO);
...@@ -210,10 +206,10 @@ public class GoodsCategorySummaryResponse implements Serializable { ...@@ -210,10 +206,10 @@ public class GoodsCategorySummaryResponse implements Serializable {
} }
BigDecimal[] thresholds = { BigDecimal[] thresholds = {
new BigDecimal("20"), new BigDecimal("1.2"), // x>=0.2:1.2 new BigDecimal("22"), new BigDecimal("1.2"),
new BigDecimal("15"), new BigDecimal("1.0"), // 0.15<=x<0.2:1.0 new BigDecimal("17"), new BigDecimal("1.0"),
new BigDecimal("10"), new BigDecimal("0.8"), // 0.1<=x<0.15:0.8 new BigDecimal("12"), new BigDecimal("0.8"),
new BigDecimal("5"), new BigDecimal("0.6") // 0.05<=x<0.1:0.6 new BigDecimal("7"), new BigDecimal("0.6")
}; };
this.safetyPackageEcoCoefficient = computeEcoCoefficient(this.safetyPackagePenetrationRate, thresholds, BigDecimal.ZERO); this.safetyPackageEcoCoefficient = computeEcoCoefficient(this.safetyPackagePenetrationRate, thresholds, BigDecimal.ZERO);
...@@ -228,10 +224,10 @@ public class GoodsCategorySummaryResponse implements Serializable { ...@@ -228,10 +224,10 @@ public class GoodsCategorySummaryResponse implements Serializable {
} }
BigDecimal[] thresholds = { BigDecimal[] thresholds = {
new BigDecimal("15"), new BigDecimal("1.2"), // x>=0.15:1.2 new BigDecimal("16"), new BigDecimal("1.2"),
new BigDecimal("11"), new BigDecimal("1.0"), // 0.11<=x<0.15:1.0 new BigDecimal("13"), new BigDecimal("1.0"),
new BigDecimal("8"), new BigDecimal("0.8"), // 0.08<=x<0.11:0.8 new BigDecimal("10"), new BigDecimal("0.8"),
new BigDecimal("5"), new BigDecimal("0.6") // 0.05<=x<0.08:0.6 new BigDecimal("7"), new BigDecimal("0.6")
}; };
this.batteryWarrantyEcoCoefficient = computeEcoCoefficient(this.batteryWarrantyPenetrationRate, thresholds, BigDecimal.ZERO); this.batteryWarrantyEcoCoefficient = computeEcoCoefficient(this.batteryWarrantyPenetrationRate, thresholds, BigDecimal.ZERO);
...@@ -247,10 +243,10 @@ public class GoodsCategorySummaryResponse implements Serializable { ...@@ -247,10 +243,10 @@ public class GoodsCategorySummaryResponse implements Serializable {
} }
BigDecimal[] thresholds = { BigDecimal[] thresholds = {
new BigDecimal("15"), new BigDecimal("1.2"), // x>=0.15:1.2 new BigDecimal("16"), new BigDecimal("1.2"),
new BigDecimal("11"), new BigDecimal("1.0"), // 0.11<=x<0.15:1.0 new BigDecimal("13"), new BigDecimal("1.0"),
new BigDecimal("8"), new BigDecimal("0.8"), // 0.08<=x<0.11:0.8 new BigDecimal("10"), new BigDecimal("0.8"),
new BigDecimal("5"), new BigDecimal("0.6") // 0.05<=x<0.08:0.6 new BigDecimal("7"), new BigDecimal("0.6")
}; };
this.tireWarrantyEcoCoefficient = computeEcoCoefficient(this.tireWarrantyPenetrationRate, thresholds, BigDecimal.ZERO); this.tireWarrantyEcoCoefficient = computeEcoCoefficient(this.tireWarrantyPenetrationRate, thresholds, BigDecimal.ZERO);
...@@ -265,10 +261,10 @@ public class GoodsCategorySummaryResponse implements Serializable { ...@@ -265,10 +261,10 @@ public class GoodsCategorySummaryResponse implements Serializable {
} }
BigDecimal[] thresholds = { BigDecimal[] thresholds = {
new BigDecimal("500"), new BigDecimal("1.2"), new BigDecimal("600"), new BigDecimal("1.2"),
new BigDecimal("400"), new BigDecimal("1.0"), new BigDecimal("500"), new BigDecimal("1.0"),
new BigDecimal("300"), new BigDecimal("0.8"), new BigDecimal("400"), new BigDecimal("0.8"),
new BigDecimal("200"), new BigDecimal("0.6") new BigDecimal("300"), new BigDecimal("0.6")
}; };
this.windowFilmEcoCoefficient = computeEcoCoefficient(this.windowFilmPerCarOutput, thresholds, BigDecimal.ZERO); this.windowFilmEcoCoefficient = computeEcoCoefficient(this.windowFilmPerCarOutput, thresholds, BigDecimal.ZERO);
...@@ -301,10 +297,10 @@ public class GoodsCategorySummaryResponse implements Serializable { ...@@ -301,10 +297,10 @@ public class GoodsCategorySummaryResponse implements Serializable {
} }
BigDecimal[] thresholds = { BigDecimal[] thresholds = {
new BigDecimal("3600"), new BigDecimal("1.2"), new BigDecimal("3800"), new BigDecimal("1.2"),
new BigDecimal("3400"), new BigDecimal("1.0"), new BigDecimal("3600"), new BigDecimal("1.0"),
new BigDecimal("3200"), new BigDecimal("0.8"), new BigDecimal("3400"), new BigDecimal("0.8"),
new BigDecimal("3000"), new BigDecimal("0.6") new BigDecimal("3200"), new BigDecimal("0.6")
}; };
this.accessoriesEcoCoefficient = computeEcoCoefficient(this.accessoriesPerCarOutput, thresholds, BigDecimal.ZERO); this.accessoriesEcoCoefficient = computeEcoCoefficient(this.accessoriesPerCarOutput, thresholds, BigDecimal.ZERO);
......
...@@ -19,11 +19,11 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest { ...@@ -19,11 +19,11 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
@Test @Test
public void sceneOutput() { public void sceneOutput() {
SceneBaseReq req = new SceneBaseReq(); SceneBaseReq req = new SceneBaseReq();
req.setBizs(1); req.setBizs(3);
req.setCycleType(3); req.setCycleType(2);
req.setStartTime("2025-11-01"); req.setStartTime("2025-12-29");
req.setEndTime("2025-11-30"); req.setEndTime("2026-01-04");
req.setMerchantIds(Lists.newArrayList(44210894,44210895,44212556,44218055,44218080,44218108,44218339,4421835,44218401)); req.setMerchantIds(Lists.newArrayList());
Object res = service.sceneOutput(req); Object res = service.sceneOutput(req);
System.out.println(res); System.out.println(res);
req.setCycleType(4); req.setCycleType(4);
...@@ -67,11 +67,12 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest { ...@@ -67,11 +67,12 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
@Test @Test
public void regionalDistribution() { public void regionalDistribution() {
SceneBaseReq req = new SceneBaseReq(); SceneBaseReq req = new SceneBaseReq();
req.setBizs(1); req.setBizs(3);
req.setCycleType(3); req.setCycleType(3);
req.setStartTime("2025-09-01"); req.setStartTime("2025-12-01");
req.setEndTime("2025-09-30"); req.setEndTime("2025-12-31");
req.setMerchantIds(Lists.newArrayList()); req.setMerchantIds(
Arrays.stream("44210823,44210895,44212556,44218030,44218105,44218339,44218395,44218401,44218402".split(",")).map(Integer::parseInt).collect(Collectors.toList()));
Object res = service.regionalDistribution(req); Object res = service.regionalDistribution(req);
System.out.println(res); System.out.println(res);
} }
...@@ -95,10 +96,10 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest { ...@@ -95,10 +96,10 @@ public class BusinessSceneAnalysisServiceTest extends BaseRemoteTest {
req.setBizs(1); req.setBizs(1);
req.setCycleType(3); req.setCycleType(3);
req.setStartTime("2025-11-01"); req.setStartTime("2025-11-01");
req.setEndTime("2025-11-31"); req.setEndTime("2025-11-30");
req.setOrderBy("contactRate"); req.setOrderBy("contactRate");
req.setOrderType(1); req.setOrderType(1);
req.setMerchantIds(Lists.newArrayList(44210894,44210895,44212556,44218055,44218080,44218108,44218339,44218395,44218401)); req.setMerchantIds(Lists.newArrayList());
Object res = service.touchRateSummary(req); Object res = service.touchRateSummary(req);
System.out.println(res); System.out.println(res);
req.setCycleType(4); req.setCycleType(4);
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    1. SceneBaseReq.java

    问题描述:

    • 在处理 merchantIds 和 staffUuids 时,增加了对元素长度的过滤,但没有明确说明为什么这样做。
    • 新增了对 staffUuids 的处理逻辑,但缺少相应的单元测试。

    优化建议:

    • 增加对 staffUuids 的单元测试,确保其功能正确。
    • 说明过滤掉长度为零的元素的原因,增强代码的可读性和可维护性。

    2. GoodsCategorySummaryResponse.java

    问题描述:

    • 生态系数计算阈值被修改,但没有提供修改的原因或背景信息。
    • 删除了旧的阈值注释,但没有在新注释中解释新的阈值选择依据。

    优化建议:

    • 提供修改阈值的理由或业务背景,以便于后续的维护人员理解。
    • 如果删除了旧注释,应确保在其他地方记录这些变化,例如在版本控制系统的提交信息中。

    3. BusinessSceneAnalysisService.java

    问题描述:

    • 在多个地方添加了异常处理,但捕获的异常类型过于宽泛 (Exception),可能会掩盖潜在的问题。
    • 在某些情况下,异常被捕获后直接返回空的结果,这可能导致调用者无法得知发生了错误。
    • 一些日志信息可以更加详细,以便更好地调试和监控。

    优化建议:

    • 使用具体的异常类型而不是 Exception,例如 RpcServiceException。
    • 在捕获异常后,考虑记录详细的日志信息,以便于排查问题。
    • 对于返回空结果的情况,可以考虑抛出自定义异常或设置特定的状态码,以便调用者知道发生了什么。

    4. BusinessSceneAnalysisServiceTest.java

    问题描述:

    • 测试用例中的参数设置与实际业务场景可能不符,例如 startTime 和 endTime 设置为未来日期。
    • 缺少对新增功能的测试,特别是对 staffUuids 的处理逻辑。

    优化建议:

    • 根据实际业务场景调整测试用例中的参数设置。
    • 添加对新增功能的测试用例,确保代码的完整性和正确性。

    评分明细

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

      • 代码逻辑基本正确,但存在一些细节上的问题,如异常处理过于宽泛,缺乏对新增功能的测试。
      • 得分:35分
    2. 安全性与潜在风险(30分):

      • 代码中没有明显的安全漏洞,但异常处理不当可能会导致潜在的风险。
      • 得分:25分
    3. 是否符合最佳实践(20分):

      • 代码结构合理,但存在一些可以改进的地方,如增加详细的日志信息和注释。
      • 得分:16分
    4. 性能与资源利用效率(5分):

      • 代码中没有明显的性能瓶颈,但有一些地方可以通过更精细的异常处理来提高性能。
      • 得分:4分
    5. Commits信息的清晰性与准确性(5分):

      • 提交信息详细且准确,易于理解。
      • 得分:5分

    总分: 85分


    通过以上审查,可以看出代码整体上是合理的,但在细节上有改进的空间,特别是在异常处理、日志记录和测试覆盖方面。希望这些建议能帮助改进代码的质量。

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