From 4be709b815b7cdba1bff7160479ee2757b8c00fb Mon Sep 17 00:00:00 2001 From: owen Date: Wed, 11 Oct 2023 15:26:17 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=EF=BC=9AReview=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/ip/core/utils/AreaUtils.java | 17 +++++++++++++---- .../convert/member/MemberStatisticsConvert.java | 4 ++++ .../mysql/pay/PayWalletStatisticsMapper.java | 11 +++++------ .../dal/mysql/trade/TradeStatisticsMapper.java | 5 ----- .../member/MemberStatisticsServiceImpl.java | 11 ++++------- .../service/pay/PayWalletStatisticsService.java | 4 ++-- .../pay/PayWalletStatisticsServiceImpl.java | 4 ++-- .../service/pay/bo/RechargeSummaryRespBO.java | 16 ++++++++++++++++ .../mapper/member/MemberStatisticsMapper.xml | 4 ---- .../mapper/pay/PayWalletStatisticsMapper.xml | 2 +- .../mapper/trade/TradeStatisticsMapper.xml | 9 +++++++++ 11 files changed, 56 insertions(+), 31 deletions(-) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/bo/RechargeSummaryRespBO.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java b/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java index 552bfc9be4..2fe475c0dc 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java @@ -132,25 +132,34 @@ public class AreaUtils { return convertList(areas.values(), func, area -> type.getType().equals(area.getType())); } - // TODO @疯狂:注释写下; + /** + * 根据区域编号、上级区域类型,获取上级区域编号 + * + * @param id 区域编号 + * @param type 区域类型 + * @return 上级区域编号 + */ public static Integer getParentIdByType(Integer id, @NonNull AreaTypeEnum type) { - // TODO @疯狂:这种不要用 while true;因为万一脏数据,可能会死循环;可以转换成 for (int i = 0; i < Byte.MAX; i++) 一般是优先层级; - do { + for (int i = 0; i < Byte.MAX_VALUE; i++) { Area area = AreaUtils.getArea(id); if (area == null) { return null; } + // 匹配到 if (type.getType().equals(area.getType())) { return area.getId(); } + // 找到根节点,返回空 if (area.getParent() == null || area.getParent().getId() == null) { return null; } + // 继续向上查找 id = area.getParent().getId(); - } while (true); + } + return null; } } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java index 0eceada3fb..974edbecd3 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java @@ -5,6 +5,8 @@ import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.ip.core.Area; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -36,4 +38,6 @@ public interface MemberStatisticsConvert { }); } + MemberSummaryRespVO convert(RechargeSummaryRespBO rechargeSummary, Integer expensePrice, Integer userCount); + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java index 4aff0ab8d6..e83179d1e6 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.statistics.dal.mysql.pay; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; -import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -29,9 +29,8 @@ public interface PayWalletStatisticsMapper extends BaseMapperX { - // TODO @疯狂:这个要不要也挪到 xml 里,保持统一? - @Select("SELECT IFNULL(SUM(order_create_count), 0) AS count, IFNULL(SUM(order_pay_price), 0) AS summary " + - "FROM trade_statistics " + - "WHERE time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE") TradeSummaryRespBO selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java index 02623e7de2..38625ed741 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.statistics.convert.member.MemberStatisticsConvert import cn.iocoder.yudao.module.statistics.dal.mysql.member.MemberStatisticsMapper; import cn.iocoder.yudao.module.statistics.service.infra.ApiAccessLogStatisticsService; import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService; +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService; import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService; import org.springframework.stereotype.Service; @@ -91,20 +92,16 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { @Override public MemberSummaryRespVO getMemberSummary() { - MemberSummaryRespVO vo = payWalletStatisticsService.getUserRechargeSummary(null, null); + RechargeSummaryRespBO rechargeSummary = payWalletStatisticsService.getUserRechargeSummary(null, null); Integer expensePrice = tradeStatisticsService.getExpensePrice(null, null); Integer userCount = memberStatisticsMapper.selectUserCount(null, null); - if (vo == null) { - vo = new MemberSummaryRespVO().setRechargeUserCount(0).setRechargePrice(0); - } - - return vo.setUserCount(userCount).setExpensePrice(expensePrice); + return MemberStatisticsConvert.INSTANCE.convert(rechargeSummary, expensePrice, userCount); } private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) { Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime)) - .map(MemberSummaryRespVO::getRechargeUserCount).orElse(0); + .map(RechargeSummaryRespBO::getRechargeUserCount).orElse(0); return new MemberAnalyseComparisonRespVO() .setUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime)) .setActiveUserCount(apiAccessLogStatisticsService.getActiveUserCount(beginTime, endTime)) diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java index 09285f88fc..b1d3f37738 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.statistics.service.pay; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import java.time.LocalDateTime; @@ -28,6 +28,6 @@ public interface PayWalletStatisticsService { * @param endTime 截止时间 * @return 钱包充值统计 */ - MemberSummaryRespVO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime); + RechargeSummaryRespBO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java index f2cfd5bf77..2ccc84fe13 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.statistics.service.pay; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; import cn.iocoder.yudao.module.statistics.dal.mysql.pay.PayWalletStatisticsMapper; +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -39,7 +39,7 @@ public class PayWalletStatisticsServiceImpl implements PayWalletStatisticsServic } @Override - public MemberSummaryRespVO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime) { + public RechargeSummaryRespBO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime) { return payWalletStatisticsMapper.selectRechargeSummaryGroupByWalletId(beginTime, endTime, true); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/bo/RechargeSummaryRespBO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/bo/RechargeSummaryRespBO.java new file mode 100644 index 0000000000..a3625f8616 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/bo/RechargeSummaryRespBO.java @@ -0,0 +1,16 @@ +package cn.iocoder.yudao.module.statistics.service.pay.bo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 充值统计 Response VO") +@Data +public class RechargeSummaryRespBO { + + @Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221") + private Integer rechargeUserCount; + + @Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer rechargePrice; + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml index f739656d7f..648e93fe86 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml @@ -8,8 +8,6 @@ FROM member_user WHERE deleted = FALSE GROUP BY area_id - - ORDER BY userCount DESC + SELECT IFNULL(SUM(order_create_count), 0) AS count, + IFNULL(SUM(order_pay_price), 0) AS summary + FROM trade_statistics + WHERE time BETWEEN #{beginTime} AND #{endTime} + AND deleted = FALSE + +