Commit d96116bf by 林永健

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

2 parents 46e544df ab322bd5
......@@ -28,7 +28,7 @@ public interface UsedCarDataStatsRemote {
RpcResponse<CycleDataRes> getCycleData(CycleDataReq request);
@ApiOperation("二手车相关趋势图")
RpcResponse<List<TrendChartRes>> getTrendChart(TrendChartReq trendChartReq);
RpcResponse<TrendChartInfoRes> getTrendChart(TrendChartReq trendChartReq);
@ApiOperation("存量门店分析")
RpcResponse<StockStoreAnalysisRes> getStockStoreAnalysis(StockStoreAnalysisReq request);
......
......@@ -75,7 +75,7 @@ public class UsedCarDataStatsRemoteImpl implements UsedCarDataStatsRemote {
* 二手车相关趋势图
*/
@Override
public RpcResponse<List<TrendChartRes>> getTrendChart(TrendChartReq request) {
public RpcResponse<TrendChartInfoRes> getTrendChart(TrendChartReq request) {
try {
return RpcResponse.success(usedCarDataStatsService.getTrendChart(request));
} catch (RpcServiceException e) {
......
......@@ -1661,10 +1661,10 @@ public class BusinessAnalysisService {
.distinct() // 按手机号去重
.count(); // 统计去重后的数量
// 关键:如果 output 为 0,则覆盖为 0
/* // 关键:如果 output 为 0,则覆盖为 0
if (output == null || output.compareTo(BigDecimal.ZERO) == 0) {
distinctTechnicianCount = 0;
}
}*/
result.setTechnicianCount((int) distinctTechnicianCount);
log.info("门店总产值:{}, 门店技师数量:{}, 门店销售人员数量:{}", output, result.getTechnicianCount(), salesCount);
......@@ -1819,6 +1819,16 @@ public class BusinessAnalysisService {
Map<Integer, BigDecimal> quantifiedStaffMap, boolean isLuxury) {
BigDecimal totalOutput = BigDecimal.ZERO;
BigDecimal totalStaffCount = BigDecimal.ZERO;
long technicianCount = stores.stream()
.filter(store -> store.isLuxury() == isLuxury)
.map(StoreInfo::getTechnicianList)
.filter(Objects::nonNull) // 过滤掉 null 的 technicianList
.flatMap(List::stream) // 展平为 Stream<MerchantStaffResponse>
.map(MerchantStaffResponse::getStaffPhone) // 提取手机号
.filter(Objects::nonNull) // 过滤 null 手机号
.filter(phone -> !phone.trim().isEmpty()) // 可选:过滤空字符串
.distinct() // 按手机号去重
.count();
for (StoreInfo store : stores) {
if (store.isLuxury() == isLuxury) { // 根据是否豪华店筛选
......@@ -1829,12 +1839,12 @@ public class BusinessAnalysisService {
BigDecimal staffCount = quantifiedStaffMap.getOrDefault(store.getStoreId(),
BigDecimal.ZERO);
BigDecimal technicianCount = new BigDecimal(store.getTechnicianCount());
totalOutput = totalOutput.add(storeOutput);
totalStaffCount = totalStaffCount.add(staffCount).add(technicianCount);
totalStaffCount = totalStaffCount.add(staffCount);
}
}
totalStaffCount.add(BigDecimal.valueOf(technicianCount));
MetricsResult result = new MetricsResult();
if (totalStaffCount.compareTo(BigDecimal.ZERO) > 0) {
......@@ -1992,11 +2002,7 @@ public class BusinessAnalysisService {
profit = integerBigDecimalMap.get(sceneType) == null ? BigDecimal.ZERO
: integerBigDecimalMap.get(sceneType);
// 毛利率 = 毛利额 / 产值(避免除零)
BigDecimal margin = BigDecimal.ZERO;
if (sceneOutput.compareTo(BigDecimal.ZERO) > 0) {
margin = profit.divide(sceneOutput, 4, RoundingMode.HALF_UP);
}
detail.setProfitMargin(margin);
detail.setProfitMargin(calculatePercent(profit, sceneOutput));
}
......
......@@ -22,6 +22,7 @@ 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.collection.CollUtil;
import cn.hutool.core.date.DateUnit;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.NumberUtil;
......@@ -437,13 +438,13 @@ public class UsedCarDataStatsService {
/**
* 二手车相关趋势图
*/
public List<TrendChartRes> getTrendChart(TrendChartReq request) {
// TrendChartInfoRes result = new TrendChartInfoRes();
public TrendChartInfoRes getTrendChart(TrendChartReq request) {
TrendChartInfoRes result = new TrendChartInfoRes();
List<Pair<String, String>> previousPeriodsIncludingCurrent = DateUtils.getPreviousPeriodsIncludingCurrent(
request.getStartTime(), request.getEndTime(), request.getCycleType(), 8);
List<PeriodDescription> periodDescriptions = DateUtils.formatPeriodDescriptions(previousPeriodsIncludingCurrent, request.getCycleType());
List<TrendChartRes> list = TrendChartResConvert.INSTANCE.toTrendChartResList(periodDescriptions);
// result.setList(list);
result.setList(list);
List<Integer> merchantIds = new ArrayList<>();
if (ObjectUtil.isEmpty(request.getMerchantId())) {
Integer brandId = request.getBrandId();
......@@ -453,7 +454,7 @@ public class UsedCarDataStatsService {
|| ObjectUtil.equals(request.getRole(), LoginRoleEnum.SALE_LEADER.getValue());
if (leaderBoolean) {
if (CollUtil.isEmpty(merchantIds)) {
return list;
return result;
}
}
// 是否通过品牌,区域
......@@ -469,14 +470,14 @@ public class UsedCarDataStatsService {
filterMerchantResponse = filterMerchantIdsResponse.getResult();
// 如果为空则返回空结果
if (CollUtil.isEmpty(filterMerchantResponse)) {
return list;
return result;
}
merchantIdList = filterMerchantResponse.stream().map(MerchantProvinceDTO::getMerchantId).collect(Collectors.toList());
// 如果角色为销售大区经理和区域运营大区经理需要取交集
if (leaderBoolean) {
merchantIds = merchantIds.stream().filter(merchantIdList::contains).collect(Collectors.toList());
if (CollUtil.isEmpty(merchantIds)) {
return list;
return result;
}
} else {
merchantIds = merchantIdList;
......@@ -519,44 +520,47 @@ public class UsedCarDataStatsService {
}
}
}
// result.setList(list);
// // 当周期类型为周或月
// if (ObjectUtil.equals(request.getCycleType(), 1) || ObjectUtil.equals(request.getCycleType(), 2)) {
// // 且今天属于当周或今天属于当月时,需要设置预测数据
// // 判断今天是否大于开始日期
// Date startDate = DateUtil.parse(request.getStartTime(), "yyyy-MM-dd");
// // 结束时间
// Date endDate = DateUtil.parse(request.getEndTime(), "yyyy-MM-dd");
// if (endDate.after(new Date())) {
// List<TrendChartRes> predictList = new ArrayList<>();
// // 把list数据 深拷贝到 predictList
// for (int i = 0; i < list.size(); i++) {
// // 需要修改第一个值为预测值
// TrendChartRes predictItem = new TrendChartRes();
// predictItem.setDateDescription(list.get(i).getDateDescription());
// predictItem.setDatePair(list.get(i).getDatePair());
// BigDecimal value = list.get(i).getValue();
// if (i == 0) {
// // 判断今天时间距离开始时间多少天,这个值除以周数或者月数,然后乘以周数或者月数,得到预测值
// long day = DateUtil.between(new Date(), startDate, DateUnit.DAY) + 1;
// long totalDays = DateUtil.between(endDate, startDate, DateUnit.DAY) + 1;
// // [当前产值 * (结束时间-开始时间+1)] / (当天日期-开始时间+1) 保留2位小数
// // value不大于0则返回0
// if (value.compareTo(BigDecimal.ZERO) <= 0) {
// predictItem.setValue(BigDecimal.ZERO);
// } else {
// BigDecimal predictValue = NumberUtil.div(NumberUtil.mul(value, totalDays), day).setScale(2, RoundingMode.HALF_UP);
// predictItem.setValue(predictValue);
// }
// } else {
// predictItem.setValue(value);
// }
// predictList.add(predictItem);
// }
// result.setPredictList(predictList);
// }
// }
return list;
result.setList(list);
// 当周期类型为周或月
if (ObjectUtil.equals(request.getCycleType(), 1) || ObjectUtil.equals(request.getCycleType(), 2)) {
// 查询类型为当期卖车总产值
if (ObjectUtil.equals(request.getTrendChartType(), 1)) {
// 且今天属于当周或今天属于当月时,需要设置预测数据
// 判断今天是否大于开始日期
Date startDate = DateUtil.parse(request.getStartTime(), "yyyy-MM-dd");
// 结束时间
Date endDate = DateUtil.parse(request.getEndTime(), "yyyy-MM-dd");
if (endDate.after(new Date())) {
List<TrendChartRes> predictList = new ArrayList<>();
// 把list数据 深拷贝到 predictList
for (int i = 0; i < list.size(); i++) {
// 需要修改第一个值为预测值
TrendChartRes predictItem = new TrendChartRes();
predictItem.setDateDescription(list.get(i).getDateDescription());
predictItem.setDatePair(list.get(i).getDatePair());
BigDecimal value = list.get(i).getValue();
if (i == 0) {
// 判断今天时间距离开始时间多少天,这个值除以周数或者月数,然后乘以周数或者月数,得到预测值
long day = DateUtil.between(new Date(), startDate, DateUnit.DAY) + 1;
long totalDays = DateUtil.between(endDate, startDate, DateUnit.DAY) + 1;
// [当前产值 * (结束时间-开始时间+1)] / (当天日期-开始时间+1) 保留2位小数
// value不大于0则返回0
if (value.compareTo(BigDecimal.ZERO) <= 0) {
predictItem.setValue(BigDecimal.ZERO);
} else {
BigDecimal predictValue = NumberUtil.div(NumberUtil.mul(value, totalDays), day).setScale(2, RoundingMode.HALF_UP);
predictItem.setValue(predictValue);
}
} else {
predictItem.setValue(value);
}
predictList.add(predictItem);
}
result.setPredictList(predictList);
}
}
}
return result;
}
......
  • @wangxw1
    commented
    Master

    Auto Review Result:

    代码审查报告

    问题描述和优化建议

    问题描述

    在 BusinessSceneAnalysisService 类中,queryParam 对象的 setSignedTimeEnd 方法被重复调用了两次,而 setSignedTimeStart 方法未被调用。这将导致查询条件不完整,进而影响展业数的统计结果。

    // 原始代码
    queryParam.setCreatedDateStart(null).setCreatedDateEnd(null).setSignedTimeEnd(null).setSignedTimeEnd(null)
    

    影响

    由于 setSignedTimeStart 方法未被调用,时间范围的起始点没有被正确设置,这可能导致查询结果不准确,进而影响展业数的统计。

    优化建议

    修正 queryParam 的设置方法调用,确保 setSignedTimeStart 和 setSignedTimeEnd 方法都被正确调用。

    // 修正后的代码
    queryParam.setCreatedDateStart(null).setCreatedDateEnd(null).setSignedTimeStart(startDate).setSignedTimeEnd(endDate)
    

    评分明细

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

      • 代码存在明显的逻辑错误,需要修正。修正后可以确保功能正确性。
      • 分数:20/40
    2. 安全性与潜在风险 (30分):

      • 当前代码片段没有明显的安全漏洞。
      • 分数:30/30
    3. 是否符合最佳实践 (20分):

      • 代码结构和命名规范基本符合要求。
      • 提交信息清晰,但可以进一步细化,避免不必要的合并信息。
      • 分数:18/20
    4. 性能与资源利用效率 (5分):

      • 当前代码片段对性能没有明显影响。
      • 分数:5/5
    5. Commits信息的清晰性与准确性 (5分):

      • 提交信息较为清晰,但包含了一些不必要的合并信息,可以简化。
      • 分数:3/5

    总分

    总分:76分


    备注: 提交信息可以进一步简化,只保留与当前修改相关的部分,这样可以提高信息的清晰度和准确性。例如:

    fix(service): 修复时间参数设置错误
    
    - 将 queryParam 的 setSignedTimeEnd 重复调用更正为 setSignedTimeStart 和 setSignedTimeEnd
    - 确保时间范围参数正确清除和设置
    - 修复导致展业数统计异常的参数错误问题
    
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!