Commit 16fcc0b8 by zhouhaibao

Merge branch 'v5.5.1' of http://192.168.3.233:8090/dj/rpc-dj-pe-analysis into v5.5.1

2 parents e222a67c 4d9e5ebd
......@@ -9,6 +9,7 @@ import javax.validation.constraints.NotBlank;
import java.io.Serializable;
import java.util.Date;
import java.util.List;
import java.util.Objects;
/**
* BI-事项管理响应对象
......@@ -85,5 +86,18 @@ public class MerchantBiMatterDTO implements Serializable {
*/
@NotBlank(message = "运营人员名称不能为空")
private String username;
@Override
public boolean equals(Object o) {
if (this == o) {return true;}
if (o == null || getClass() != o.getClass()) {return false;}
OperatorDTO that = (OperatorDTO) o;
return Objects.equals(uuid, that.uuid);
}
@Override
public int hashCode() {
return Objects.hash(uuid);
}
}
}
......@@ -772,13 +772,14 @@ public class BiAnalyseBackgroundService {
request.setDirectorTypes(directorTypeEnums.stream().map(ele -> ObjectUtil.toString(ele.getValue())).collect(Collectors.toList()));
List<ShopMerchantDirectorConfig> directorConfigs = merchantBiMatterMapper.selectBiMerchantOperator(request);
Map<Byte, List<MerchantBiMatterDTO.OperatorDTO>> directorTypeMapOperator = directorConfigs.stream()
Map<Byte, Set<MerchantBiMatterDTO.OperatorDTO>> directorTypeMapOperator = directorConfigs.stream()
.collect(Collectors.groupingBy(ShopMerchantDirectorConfig::getDirectorType,
Collectors.mapping(ele -> MerchantBiMatterDTO.OperatorDTO.builder()
.uuid(ele.getDirectorUserId())
.username(ele.getDirectorName())
.build(),
Collectors.toList())));
Collectors.toSet())));
// 处理区域运营和线上运营
MerchantOperatorDetailDTO result = new MerchantOperatorDetailDTO();
......@@ -792,11 +793,24 @@ public class BiAnalyseBackgroundService {
Optional.ofNullable(directorTypeMapOperator.get(DirectorTypeEnum.AREA_SUPERVISION_1_1.getValue()))
.ifPresent(r -> result.getAreaOperator().addAll(r));
// 无关联的线上运营或区域运营,则无法提交并toast:无可跟进的线上运营或区域运营,请确认后重新操作;
if (CollUtil.isEmpty(result.getOnlineOperator()) && CollUtil.isEmpty(result.getAreaOperator())) {
throw new RpcServiceException(BiErrorEnum.NO_ONLINE_AREA_OPERATOR_ERROR);
}
// 去重
List<MerchantBiMatterDTO.OperatorDTO> onlineOperator = result.getOnlineOperator();
if (CollUtil.isNotEmpty(onlineOperator)) {
result.setOnlineOperator(onlineOperator.stream()
.distinct()
.collect(Collectors.toList()));
}
List<MerchantBiMatterDTO.OperatorDTO> areaOperator = result.getAreaOperator();
if (CollUtil.isNotEmpty(areaOperator)) {
result.setAreaOperator(areaOperator.stream().distinct().collect(Collectors.toList()));
}
return result;
}
......
......@@ -31,6 +31,7 @@ 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.core.util.ObjectUtil;
import cn.hutool.json.JSONUtil;
import com.alibaba.fastjson.JSON;
import com.google.common.collect.Lists;
......@@ -202,7 +203,6 @@ public class BusinessSceneAnalysisService {
List<DataBusinessDTO> trendOutputList = businessAnalysisService.getTotalOutputGroupByMerchant(queryParams);
if (CollectionUtils.isEmpty(trendOutputList)) {
log.warn("查询产值趋势及达成率返回空");
return res;
}
// 查询目标产值(周期=月时才展示)
......@@ -251,14 +251,15 @@ public class BusinessSceneAnalysisService {
List<DataBusinessDTO> dateList = dataGroupByStart.get(begin);
DataBusinessDTO data = mergeDataList(dateList);
item.setStoreCount(BigDecimal.valueOf(dateList.size()));
item.setOutput(data.getItemValue());
item.setOutput(ObjectUtil.defaultIfNull(data.getItemValue(), BigDecimal.ZERO));
item.setStartTime(data.getStartDate());
item.setEndTime(data.getEndDate());
Date key = DateUtil.parse(item.getStartTime());
BigDecimal ratio = null;
if (monthTargetOutputMap.containsKey(key)) {
BigDecimal targetOutputConfig = monthTargetOutputMap.get(key);
item.setRatio(computeOutputRatio(item.getOutput(), targetOutputConfig));
ratio = computeOutputRatio(item.getOutput(), monthTargetOutputMap.get(key));
}
item.setRatio(ObjectUtil.defaultIfNull(ratio, BigDecimal.ZERO));
} else {
item.setOutput(BigDecimal.ZERO);
item.setStoreCount(BigDecimal.ZERO);
......@@ -1192,6 +1193,9 @@ public class BusinessSceneAnalysisService {
res.stream()
.filter(item -> ecosystemWarningStoreIds.contains(item.getStoreId()))
.forEach(item -> item.appendStoreStatus("3"));
res.stream()
.filter(item -> CollectionUtils.isEmpty(item.getStoreStatus()))
.forEach(item -> item.setStoreStatus(Lists.newArrayList("1")));
// 事项查询 todo
// merchantBiMatterMapper.selectMyBiMatterCount();
......
......@@ -607,6 +607,7 @@
smdc.deleted_flag = 'N'
and a.scene = #{scene}
<if test="merchantIds != null and merchantIds.size() > 0">
and smdc.merchant_id in
<foreach item="item" index="index" collection="merchantIds" open="(" separator="," close=")">
#{item}
</foreach>
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    问题1:除零错误处理不当

    问题描述: 在BusinessAnalysisService类中,当分母last为null或0时,返回值被更改为null。这可能导致调用该方法的地方出现空指针异常或其他未预期的行为。

    优化建议:

    1. 明确返回值含义: 返回null可能不是最佳选择,因为调用者需要额外处理null的情况。可以考虑返回一个特殊的值(如BigDecimal.ZERO)来表示这种情况。
    2. 抛出异常: 如果返回null是合理的,那么应该确保调用者能够处理这种情况。另一种选择是抛出自定义异常,以便更明确地传达错误信息。
    3. 日志记录: 在这种情况下记录日志可以帮助调试和监控潜在的问题。
    if (last == null || last.compareTo(BigDecimal.ZERO) == 0) {
        // 分母为0:若分子>0,通常视为无穷大;这里按业务常见做法返回 100%
        if (current.compareTo(BigDecimal.ZERO) > 0) {
            logger.warn("Denominator is zero but numerator is greater than zero. Returning 100%.");
            return new BigDecimal("100.00");
        } else {
            logger.warn("Both numerator and denominator are zero or null. Returning 0%.");
            return BigDecimal.ZERO;
        }
    }
    

    问题2:提交信息不够清晰

    问题描述: 提交信息“百分比,如果分母为null或者为0,则返回null;Merge branch 'v5.5.1' of http://192.168.3.233:8090/dj/rpc-dj-pe-analysis into v5.5.1”包含了两个不相关的操作,且格式不清晰。

    优化建议:

    1. 拆分提交: 将合并分支的操作和代码更改分开提交,每个提交只做一件事情。
    2. 清晰的提交信息: 提交信息应该简洁明了,能够清楚地描述所做的更改。例如,“Fix: Return 100% when numerator > 0 and denominator is zero”。

    评分明细

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

      • 得分:20分
      • 说明: 当前代码在分母为null或0时返回null,这可能会导致调用者出现空指针异常。需要改进错误处理机制以提高代码的健壮性。
    2. 安全性与潜在风险(30分):

      • 得分:25分
      • 说明: 当前代码没有明显的安全漏洞,但返回null可能导致潜在的风险,需要改进错误处理机制。
    3. 是否符合最佳实践(20分):

      • 得分:15分
      • 说明: 代码缺少必要的日志记录,且提交信息不够清晰,需要改进以符合最佳实践。
    4. 性能与资源利用效率(5分):

      • 得分:5分
      • 说明: 当前代码没有明显的性能问题。
    5. Commits信息的清晰性与准确性(5分):

      • 得分:1分
      • 说明: 提交信息不够清晰,需要改进以提高可读性和可维护性。

    总分:46分


    希望这些建议对您有所帮助。如果有任何疑问或需要进一步讨论,请随时联系我。

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