From 20241b8bcc221db9cd62cacd3c064c78a1826370 Mon Sep 17 00:00:00 2001 From: SuchJack <2640808535@qq.com> Date: Sat, 24 May 2025 20:04:07 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D"=E5=95=86=E5=93=81?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1=E8=81=9A=E5=90=88=E5=87=BD=E6=95=B0=E7=9A=84?= =?UTF-8?q?=E5=88=AB=E5=90=8D=E4=B8=8E=E6=8E=92=E5=BA=8F=E5=AD=97=E6=AE=B5?= =?UTF-8?q?=E4=B8=8D=E7=AC=A6"=E5=AF=BC=E8=87=B4=E7=9A=84SQL=E5=BC=82?= =?UTF-8?q?=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../product/ProductStatisticsMapper.java | 39 ++++++++++++++----- 1 file changed, 29 insertions(+), 10 deletions(-) diff --git a/yudao-module-mall/yudao-module-statistics/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/product/ProductStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/product/ProductStatisticsMapper.java index 4cf10f102d..56029131d8 100644 --- a/yudao-module-mall/yudao-module-statistics/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/product/ProductStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/product/ProductStatisticsMapper.java @@ -1,16 +1,20 @@ package cn.iocoder.yudao.module.statistics.dal.mysql.product; +import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.pojo.SortablePageParam; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.framework.mybatis.core.query.MPJLambdaWrapperX; +import cn.iocoder.yudao.framework.mybatis.core.util.MyBatisUtils; import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsReqVO; import cn.iocoder.yudao.module.statistics.controller.admin.product.vo.ProductStatisticsRespVO; import cn.iocoder.yudao.module.statistics.dal.dataobject.product.ProductStatisticsDO; import com.baomidou.mybatisplus.core.metadata.IPage; +import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import org.dromara.hutool.core.func.LambdaUtil; import java.time.LocalDateTime; import java.util.List; @@ -49,16 +53,31 @@ public interface ProductStatisticsMapper extends BaseMapperX buildWrapper(ProductStatisticsReqVO reqVO) { return new MPJLambdaWrapperX() .betweenIfPresent(ProductStatisticsDO::getTime, reqVO.getTimes()) - .selectSum(ProductStatisticsDO::getBrowseCount) - .selectSum(ProductStatisticsDO::getBrowseUserCount) - .selectSum(ProductStatisticsDO::getFavoriteCount) - .selectSum(ProductStatisticsDO::getCartCount) - .selectSum(ProductStatisticsDO::getOrderCount) - .selectSum(ProductStatisticsDO::getOrderPayCount) - .selectSum(ProductStatisticsDO::getOrderPayPrice) - .selectSum(ProductStatisticsDO::getAfterSaleCount) - .selectSum(ProductStatisticsDO::getAfterSaleRefundPrice) - .selectAvg(ProductStatisticsDO::getBrowseConvertPercent); + .selectSum(ProductStatisticsDO::getBrowseCount,toUnderlineCase(ProductStatisticsDO::getBrowseCount)) + .selectSum(ProductStatisticsDO::getBrowseUserCount,toUnderlineCase(ProductStatisticsDO::getBrowseUserCount)) + .selectSum(ProductStatisticsDO::getFavoriteCount,toUnderlineCase(ProductStatisticsDO::getFavoriteCount)) + .selectSum(ProductStatisticsDO::getCartCount,toUnderlineCase(ProductStatisticsDO::getCartCount)) + .selectSum(ProductStatisticsDO::getOrderCount,toUnderlineCase(ProductStatisticsDO::getOrderCount)) + .selectSum(ProductStatisticsDO::getOrderPayCount,toUnderlineCase(ProductStatisticsDO::getOrderPayCount)) + .selectSum(ProductStatisticsDO::getOrderPayPrice,toUnderlineCase(ProductStatisticsDO::getOrderPayPrice)) + .selectSum(ProductStatisticsDO::getAfterSaleCount,toUnderlineCase(ProductStatisticsDO::getAfterSaleCount)) + .selectSum(ProductStatisticsDO::getAfterSaleRefundPrice,toUnderlineCase(ProductStatisticsDO::getAfterSaleRefundPrice)) + .selectAvg(ProductStatisticsDO::getBrowseConvertPercent,toUnderlineCase(ProductStatisticsDO::getBrowseConvertPercent)); + } + + /** + * 将驼峰命名转换为下划线命名 + * + * @param func 字段名函数(驼峰命名) + * @return 字段名(下划线命名) + * @param 泛型 + *

+ * fix:排序时排序字段被 {@link MyBatisUtils#buildPage} 由驼峰命名被转为下划线命名, + * 因此聚合函数的别名也做统一,统一为下划线命名,解决排序时找不到字段的问题。 + */ + private static String toUnderlineCase(SFunction func) { + String fieldName = LambdaUtil.getFieldName(func); + return StrUtil.toUnderlineCase(fieldName); } /**