Commit 69b896a688cfb22d65b5812b98c54bb291ad9c0d

Authored by 芋道源码
Committed by Gitee
2 parents 611ad0d2 bed36f68

!1357 fix:修复"商品统计聚合函数的别名与排序字段不符"导致的SQL异常

Merge pull request !1357 from SuchJack/master-jdk17-dev
yudao-module-mall/yudao-module-promotion/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java
... ... @@ -165,6 +165,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService {
165 165 ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId());
166 166 ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId());
167 167 CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku);
  168 + record.setPicUrl(spu.getPicUrl()); // fix:拼团记录创建时,需要设置拼团商品的图片
168 169 // 2.1. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP
169 170 if (record.getHeadId() == null) {
170 171 record.setStartTime(LocalDateTime.now())
... ...
yudao-module-mall/yudao-module-statistics/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/product/ProductStatisticsMapper.java
1 1 package cn.iocoder.yudao.module.statistics.dal.mysql.product;
2 2  
  3 +import cn.hutool.core.util.StrUtil;
3 4 import cn.iocoder.yudao.framework.common.pojo.PageResult;
4 5 import cn.iocoder.yudao.framework.common.pojo.SortablePageParam;
5 6 import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
6 7 import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
7 8 import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX;
  9 +import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils;
8 10 import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsReqVO;
9 11 import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsRespVO;
10 12 import cn.iocoder.yudao.module.statistics.dal.dataobject.product.ProductStatisticsDO;
11 13 import com.baomidou.mybatisplus.core.metadata.IPage;
  14 +import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
12 15 import org.apache.ibatis.annotations.Mapper;
13 16 import org.apache.ibatis.annotations.Param;
  17 +import org.dromara.hutool.core.func.LambdaUtil;
14 18  
15 19 import java.time.LocalDateTime;
16 20 import java.util.List;
... ... @@ -49,16 +53,31 @@ public interface ProductStatisticsMapper extends BaseMapperX<ProductStatisticsDO
49 53 private static MPJLambdaWrapperX<ProductStatisticsDO> buildWrapper(ProductStatisticsReqVO reqVO) {
50 54 return new MPJLambdaWrapperX<ProductStatisticsDO>()
51 55 .betweenIfPresent(ProductStatisticsDO::getTime, reqVO.getTimes())
52   - .selectSum(ProductStatisticsDO::getBrowseCount)
53   - .selectSum(ProductStatisticsDO::getBrowseUserCount)
54   - .selectSum(ProductStatisticsDO::getFavoriteCount)
55   - .selectSum(ProductStatisticsDO::getCartCount)
56   - .selectSum(ProductStatisticsDO::getOrderCount)
57   - .selectSum(ProductStatisticsDO::getOrderPayCount)
58   - .selectSum(ProductStatisticsDO::getOrderPayPrice)
59   - .selectSum(ProductStatisticsDO::getAfterSaleCount)
60   - .selectSum(ProductStatisticsDO::getAfterSaleRefundPrice)
61   - .selectAvg(ProductStatisticsDO::getBrowseConvertPercent);
  56 + .selectSum(ProductStatisticsDO::getBrowseCount,toUnderlineCase(ProductStatisticsDO::getBrowseCount))
  57 + .selectSum(ProductStatisticsDO::getBrowseUserCount,toUnderlineCase(ProductStatisticsDO::getBrowseUserCount))
  58 + .selectSum(ProductStatisticsDO::getFavoriteCount,toUnderlineCase(ProductStatisticsDO::getFavoriteCount))
  59 + .selectSum(ProductStatisticsDO::getCartCount,toUnderlineCase(ProductStatisticsDO::getCartCount))
  60 + .selectSum(ProductStatisticsDO::getOrderCount,toUnderlineCase(ProductStatisticsDO::getOrderCount))
  61 + .selectSum(ProductStatisticsDO::getOrderPayCount,toUnderlineCase(ProductStatisticsDO::getOrderPayCount))
  62 + .selectSum(ProductStatisticsDO::getOrderPayPrice,toUnderlineCase(ProductStatisticsDO::getOrderPayPrice))
  63 + .selectSum(ProductStatisticsDO::getAfterSaleCount,toUnderlineCase(ProductStatisticsDO::getAfterSaleCount))
  64 + .selectSum(ProductStatisticsDO::getAfterSaleRefundPrice,toUnderlineCase(ProductStatisticsDO::getAfterSaleRefundPrice))
  65 + .selectAvg(ProductStatisticsDO::getBrowseConvertPercent,toUnderlineCase(ProductStatisticsDO::getBrowseConvertPercent));
  66 + }
  67 +
  68 + /**
  69 + * 将驼峰命名转换为下划线命名
  70 + *
  71 + * @param func 字段名函数(驼峰命名)
  72 + * @return 字段名(下划线命名)
  73 + * @param <T> 泛型
  74 + * <p>
  75 + * fix:排序时排序字段被 {@link MyBatisUtils#buildPage} 由驼峰命名被转为下划线命名,
  76 + * 因此聚合函数的别名也做统一,统一为下划线命名,解决排序时找不到字段的问题。
  77 + */
  78 + private static <T> String toUnderlineCase(SFunction<T, ?> func) {
  79 + String fieldName = LambdaUtil.getFieldName(func);
  80 + return StrUtil.toUnderlineCase(fieldName);
62 81 }
63 82  
64 83 /**
... ...