Commit 7a3165ee by zhouhaibao

[+]区域运营经理权限查询问题

1 parent 83935bf7
...@@ -782,6 +782,24 @@ public class BusinessAnalysisService { ...@@ -782,6 +782,24 @@ public class BusinessAnalysisService {
.divide(BigDecimal.valueOf(total), scale, RoundingMode.HALF_UP); .divide(BigDecimal.valueOf(total), scale, RoundingMode.HALF_UP);
} }
private BaseReq copyReq(BaseReq source) {
return BaseReq.builder()
.loginRole(source.getLoginRole())
.regionId(source.getRegionId())
.cycleType(source.getCycleType())
.startTime(source.getStartTime())
.endTime(source.getEndTime())
.provinceId(source.getProvinceId())
.searchAllFlag(source.getSearchAllFlag())
.merchantIds(new ArrayList<>(source.getMerchantIds()))
.exts(source.getExts())
.biz(source.getBiz())
.merchantIds0(new ArrayList<>(source.getMerchantIds0())) // 拷贝集合
.merchantIds1(new ArrayList<>(source.getMerchantIds1()))
// ... 其他字段
.build();
}
/** /**
* 全业务-区域分析-总产值、毛利率 * 全业务-区域分析-总产值、毛利率
* *
...@@ -796,25 +814,29 @@ public class BusinessAnalysisService { ...@@ -796,25 +814,29 @@ public class BusinessAnalysisService {
if (checkSup(req.getLoginRole())) { if (checkSup(req.getLoginRole())) {
// 获取当前所有区域产值 // 获取当前所有区域产值
BaseReq baseReq = copyReq(req);
futures.add( futures.add(
CompletableFuture.supplyAsync(() -> getOutputGroupByBiz(req), executor)); CompletableFuture.supplyAsync(() -> getOutputGroupByBiz(baseReq), executor));
} }
// 过滤区域门店产值 // 过滤区域门店产值
setMerchantIdsPerssionIds(req); BaseReq baseReq1 = copyReq(req);
setMerchantIdsPerssionIds(baseReq1);
// 本期的区域门店产值 // 本期的区域门店产值
futures.add(CompletableFuture.supplyAsync(() -> getOutputGroupByBiz(req), executor)); futures.add(CompletableFuture.supplyAsync(() -> getOutputGroupByBiz(baseReq1), executor));
// 获取上期的产值 // 获取上期的产值
Pair<String, String> lastPeriod = DateUtils.getLastPeriodDates( Pair<String, String> lastPeriod = DateUtils.getLastPeriodDates(
req.getStartTime(), req.getEndTime(), req.getCycleType() req.getStartTime(), req.getEndTime(), req.getCycleType()
); );
String startTime = req.getStartTime(); // 过滤区域门店产值
req.setStartTime(lastPeriod.getKey()); BaseReq baseReq2 = copyReq(req);
req.setEndTime(lastPeriod.getValue()); setMerchantIdsPerssionIds(baseReq2);
baseReq2.setStartTime(lastPeriod.getKey());
baseReq2.setEndTime(lastPeriod.getValue());
futures.add(CompletableFuture.supplyAsync(() -> getOutputGroupByBiz(req), executor)); futures.add(CompletableFuture.supplyAsync(() -> getOutputGroupByBiz(baseReq2), executor));
// 等待全部完成 // 等待全部完成
CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join(); CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).join();
...@@ -872,7 +894,7 @@ public class BusinessAnalysisService { ...@@ -872,7 +894,7 @@ public class BusinessAnalysisService {
Collectors.toList()); Collectors.toList());
List<DistributioncConfigResponse> currentlist = findDisConfigByMerchantIdsAndMonth( List<DistributioncConfigResponse> currentlist = findDisConfigByMerchantIdsAndMonth(
currentMerchantIds, startTime); currentMerchantIds, req.getStartTime());
List<DistributioncConfigResponse> lastlist = findDisConfigByMerchantIdsAndMonth( List<DistributioncConfigResponse> lastlist = findDisConfigByMerchantIdsAndMonth(
lastMerchantIds, lastPeriod.getKey()); lastMerchantIds, lastPeriod.getKey());
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

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

    问题描述: 在getOutputGroupByBiz方法调用时,直接修改了原始请求对象req的startTime和endTime属性,这可能会影响其他依赖该请求对象的操作,导致潜在的逻辑错误或数据不一致。

    优化建议: 使用深拷贝的方式创建新的请求对象,而不是直接修改原始对象。在上述代码中,已经引入了copyReq方法来解决这个问题,但在某些情况下,exts和biz字段如果包含可变对象,仍需进一步深拷贝以确保完全独立。

    2. 安全性与潜在风险

    问题描述: 目前代码中没有明显的安全漏洞,但需要关注BaseReq对象中的exts和biz字段是否包含敏感信息,以及这些字段在后续处理过程中是否存在潜在的安全风险。

    优化建议: 对exts和biz字段进行必要的验证和清理,确保其内容的安全性。如果这些字段包含用户输入,应进行严格的输入验证和过滤。

    3. 是否符合最佳实践

    问题描述: 代码整体结构合理,但存在一些细节上的改进空间,例如copyReq方法的注释不够详细,缺少对每个字段拷贝的解释。

    优化建议: 增加对copyReq方法中每个字段拷贝的注释,说明为什么需要拷贝这些字段,提高代码的可读性和可维护性。此外,可以考虑将copyReq方法抽取到一个单独的工具类中,以提高代码的复用性。

    4. 性能与资源利用效率

    问题描述: 目前代码中创建了多个BaseReq对象的副本,虽然保证了数据的一致性,但可能会增加一定的内存开销。

    优化建议: 如果BaseReq对象的大小和数量可控,当前的实现方式是可以接受的。但如果对象较大或数量较多,可以考虑使用对象池技术来减少对象创建的开销。另外,对于merchantIds等集合类型的字段,可以考虑使用不可变集合(如Collections.unmodifiableList)来避免不必要的拷贝。

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

    问题描述: 提交信息“[+]区域运营经理权限查询问题”过于笼统,没有明确指出具体的修复内容或改动范围。

    优化建议: 提交信息应更加具体,例如“修复区域运营经理权限查询时请求对象被意外修改的问题”。这样可以更清晰地传达改动的目的,便于后续的代码审计和维护。

    评分明细

    1. 功能实现的正确性与健壮性:38/40
    2. 安全性与潜在风险:28/30
    3. 是否符合最佳实践:18/20
    4. 性能与资源利用效率:4/5
    5. Commits信息的清晰性与准确性:4/5

    总分: 92分

    通过以上审查,代码的整体质量较高,但仍有一些细节上的改进空间,建议开发者根据上述建议进行相应的调整。

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