Commit 4be709b815b7cdba1bff7160479ee2757b8c00fb
1 parent
66cdf4ca
统计:Review修改
Showing
11 changed files
with
56 additions
and
31 deletions
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 { |
| 132 | 132 | return convertList(areas.values(), func, area -> type.getType().equals(area.getType())); |
| 133 | 133 | } |
| 134 | 134 | |
| 135 | - // TODO @疯狂:注释写下; | |
| 135 | + /** | |
| 136 | + * 根据区域编号、上级区域类型,获取上级区域编号 | |
| 137 | + * | |
| 138 | + * @param id 区域编号 | |
| 139 | + * @param type 区域类型 | |
| 140 | + * @return 上级区域编号 | |
| 141 | + */ | |
| 136 | 142 | public static Integer getParentIdByType(Integer id, @NonNull AreaTypeEnum type) { |
| 137 | - // TODO @疯狂:这种不要用 while true;因为万一脏数据,可能会死循环;可以转换成 for (int i = 0; i < Byte.MAX; i++) 一般是优先层级; | |
| 138 | - do { | |
| 143 | + for (int i = 0; i < Byte.MAX_VALUE; i++) { | |
| 139 | 144 | Area area = AreaUtils.getArea(id); |
| 140 | 145 | if (area == null) { |
| 141 | 146 | return null; |
| 142 | 147 | } |
| 143 | 148 | |
| 149 | + // 匹配到 | |
| 144 | 150 | if (type.getType().equals(area.getType())) { |
| 145 | 151 | return area.getId(); |
| 146 | 152 | } |
| 147 | 153 | |
| 154 | + // 找到根节点,返回空 | |
| 148 | 155 | if (area.getParent() == null || area.getParent().getId() == null) { |
| 149 | 156 | return null; |
| 150 | 157 | } |
| 151 | 158 | |
| 159 | + // 继续向上查找 | |
| 152 | 160 | id = area.getParent().getId(); |
| 153 | - } while (true); | |
| 161 | + } | |
| 162 | + return null; | |
| 154 | 163 | } |
| 155 | 164 | |
| 156 | 165 | } | ... | ... |
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; |
| 5 | 5 | import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; |
| 6 | 6 | import cn.iocoder.yudao.framework.ip.core.Area; |
| 7 | 7 | import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; |
| 8 | +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; | |
| 9 | +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; | |
| 8 | 10 | import org.mapstruct.Mapper; |
| 9 | 11 | import org.mapstruct.factory.Mappers; |
| 10 | 12 | |
| ... | ... | @@ -36,4 +38,6 @@ public interface MemberStatisticsConvert { |
| 36 | 38 | }); |
| 37 | 39 | } |
| 38 | 40 | |
| 41 | + MemberSummaryRespVO convert(RechargeSummaryRespBO rechargeSummary, Integer expensePrice, Integer userCount); | |
| 42 | + | |
| 39 | 43 | } | ... | ... |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.statistics.dal.mysql.pay; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 4 | -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; | |
| 5 | -import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; | |
| 6 | 4 | import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; |
| 5 | +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; | |
| 6 | +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; | |
| 7 | 7 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 8 | import org.apache.ibatis.annotations.Param; |
| 9 | 9 | |
| ... | ... | @@ -29,9 +29,8 @@ public interface PayWalletStatisticsMapper extends BaseMapperX<TradeStatisticsDO |
| 29 | 29 | @Param("endTime") LocalDateTime endTime, |
| 30 | 30 | @Param("bizType") Integer bizType); |
| 31 | 31 | |
| 32 | - // TODO @疯狂:是不是搞个单独的 BO 呀; | |
| 33 | - MemberSummaryRespVO selectRechargeSummaryGroupByWalletId(@Param("beginTime") LocalDateTime beginTime, | |
| 34 | - @Param("endTime") LocalDateTime endTime, | |
| 35 | - @Param("payStatus") Boolean payStatus); | |
| 32 | + RechargeSummaryRespBO selectRechargeSummaryGroupByWalletId(@Param("beginTime") LocalDateTime beginTime, | |
| 33 | + @Param("endTime") LocalDateTime endTime, | |
| 34 | + @Param("payStatus") Boolean payStatus); | |
| 36 | 35 | |
| 37 | 36 | } | ... | ... |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java
| ... | ... | @@ -6,7 +6,6 @@ import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO |
| 6 | 6 | import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; |
| 7 | 7 | import org.apache.ibatis.annotations.Mapper; |
| 8 | 8 | import org.apache.ibatis.annotations.Param; |
| 9 | -import org.apache.ibatis.annotations.Select; | |
| 10 | 9 | |
| 11 | 10 | import java.time.LocalDateTime; |
| 12 | 11 | import java.util.List; |
| ... | ... | @@ -19,10 +18,6 @@ import java.util.List; |
| 19 | 18 | @Mapper |
| 20 | 19 | public interface TradeStatisticsMapper extends BaseMapperX<TradeStatisticsDO> { |
| 21 | 20 | |
| 22 | - // TODO @疯狂:这个要不要也挪到 xml 里,保持统一? | |
| 23 | - @Select("SELECT IFNULL(SUM(order_create_count), 0) AS count, IFNULL(SUM(order_pay_price), 0) AS summary " + | |
| 24 | - "FROM trade_statistics " + | |
| 25 | - "WHERE time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE") | |
| 26 | 21 | TradeSummaryRespBO selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(@Param("beginTime") LocalDateTime beginTime, |
| 27 | 22 | @Param("endTime") LocalDateTime endTime); |
| 28 | 23 | ... | ... |
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 |
| 9 | 9 | import cn.iocoder.yudao.module.statistics.dal.mysql.member.MemberStatisticsMapper; |
| 10 | 10 | import cn.iocoder.yudao.module.statistics.service.infra.ApiAccessLogStatisticsService; |
| 11 | 11 | import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService; |
| 12 | +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; | |
| 12 | 13 | import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService; |
| 13 | 14 | import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService; |
| 14 | 15 | import org.springframework.stereotype.Service; |
| ... | ... | @@ -91,20 +92,16 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { |
| 91 | 92 | |
| 92 | 93 | @Override |
| 93 | 94 | public MemberSummaryRespVO getMemberSummary() { |
| 94 | - MemberSummaryRespVO vo = payWalletStatisticsService.getUserRechargeSummary(null, null); | |
| 95 | + RechargeSummaryRespBO rechargeSummary = payWalletStatisticsService.getUserRechargeSummary(null, null); | |
| 95 | 96 | Integer expensePrice = tradeStatisticsService.getExpensePrice(null, null); |
| 96 | 97 | Integer userCount = memberStatisticsMapper.selectUserCount(null, null); |
| 97 | 98 | |
| 98 | - if (vo == null) { | |
| 99 | - vo = new MemberSummaryRespVO().setRechargeUserCount(0).setRechargePrice(0); | |
| 100 | - } | |
| 101 | - | |
| 102 | - return vo.setUserCount(userCount).setExpensePrice(expensePrice); | |
| 99 | + return MemberStatisticsConvert.INSTANCE.convert(rechargeSummary, expensePrice, userCount); | |
| 103 | 100 | } |
| 104 | 101 | |
| 105 | 102 | private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) { |
| 106 | 103 | Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime)) |
| 107 | - .map(MemberSummaryRespVO::getRechargeUserCount).orElse(0); | |
| 104 | + .map(RechargeSummaryRespBO::getRechargeUserCount).orElse(0); | |
| 108 | 105 | return new MemberAnalyseComparisonRespVO() |
| 109 | 106 | .setUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime)) |
| 110 | 107 | .setActiveUserCount(apiAccessLogStatisticsService.getActiveUserCount(beginTime, endTime)) | ... | ... |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java
| 1 | 1 | package cn.iocoder.yudao.module.statistics.service.pay; |
| 2 | 2 | |
| 3 | -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; | |
| 3 | +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; | |
| 4 | 4 | import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; |
| 5 | 5 | |
| 6 | 6 | import java.time.LocalDateTime; |
| ... | ... | @@ -28,6 +28,6 @@ public interface PayWalletStatisticsService { |
| 28 | 28 | * @param endTime 截止时间 |
| 29 | 29 | * @return 钱包充值统计 |
| 30 | 30 | */ |
| 31 | - MemberSummaryRespVO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime); | |
| 31 | + RechargeSummaryRespBO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime); | |
| 32 | 32 | |
| 33 | 33 | } | ... | ... |
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; |
| 2 | 2 | |
| 3 | 3 | import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; |
| 4 | 4 | import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum; |
| 5 | -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; | |
| 6 | 5 | import cn.iocoder.yudao.module.statistics.dal.mysql.pay.PayWalletStatisticsMapper; |
| 6 | +import cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO; | |
| 7 | 7 | import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; |
| 8 | 8 | import org.springframework.stereotype.Service; |
| 9 | 9 | import org.springframework.validation.annotation.Validated; |
| ... | ... | @@ -39,7 +39,7 @@ public class PayWalletStatisticsServiceImpl implements PayWalletStatisticsServic |
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | @Override |
| 42 | - public MemberSummaryRespVO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime) { | |
| 42 | + public RechargeSummaryRespBO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime) { | |
| 43 | 43 | return payWalletStatisticsMapper.selectRechargeSummaryGroupByWalletId(beginTime, endTime, true); |
| 44 | 44 | } |
| 45 | 45 | ... | ... |
yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/bo/RechargeSummaryRespBO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.statistics.service.pay.bo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +@Schema(description = "管理后台 - 充值统计 Response VO") | |
| 7 | +@Data | |
| 8 | +public class RechargeSummaryRespBO { | |
| 9 | + | |
| 10 | + @Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221") | |
| 11 | + private Integer rechargeUserCount; | |
| 12 | + | |
| 13 | + @Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") | |
| 14 | + private Integer rechargePrice; | |
| 15 | + | |
| 16 | +} | ... | ... |
yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml
| ... | ... | @@ -8,8 +8,6 @@ |
| 8 | 8 | FROM member_user |
| 9 | 9 | WHERE deleted = FALSE |
| 10 | 10 | GROUP BY area_id |
| 11 | - <!-- TODO @疯狂:order by 是不是交给内存哈 --> | |
| 12 | - ORDER BY userCount DESC | |
| 13 | 11 | </select> |
| 14 | 12 | |
| 15 | 13 | <select id="selectSummaryListBySex" |
| ... | ... | @@ -18,8 +16,6 @@ |
| 18 | 16 | FROM member_user |
| 19 | 17 | WHERE deleted = FALSE |
| 20 | 18 | GROUP BY sex |
| 21 | - <!-- TODO @疯狂:order by 是不是交给内存哈 --> | |
| 22 | - ORDER BY userCount DESC | |
| 23 | 19 | </select> |
| 24 | 20 | |
| 25 | 21 | <select id="selectUserCount" resultType="java.lang.Integer"> | ... | ... |
yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml
| ... | ... | @@ -30,7 +30,7 @@ |
| 30 | 30 | </select> |
| 31 | 31 | |
| 32 | 32 | <select id="selectRechargeSummaryGroupByWalletId" |
| 33 | - resultType="cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO"> | |
| 33 | + resultType="cn.iocoder.yudao.module.statistics.service.pay.bo.RechargeSummaryRespBO"> | |
| 34 | 34 | SELECT COUNT(1) AS rechargeUserCount, |
| 35 | 35 | SUM(pay_price) AS rechargePrice |
| 36 | 36 | FROM pay_wallet_recharge | ... | ... |
yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml
| ... | ... | @@ -2,6 +2,15 @@ |
| 2 | 2 | <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> |
| 3 | 3 | <mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsMapper"> |
| 4 | 4 | |
| 5 | + <select id="selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween" | |
| 6 | + resultType="cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO"> | |
| 7 | + SELECT IFNULL(SUM(order_create_count), 0) AS count, | |
| 8 | + IFNULL(SUM(order_pay_price), 0) AS summary | |
| 9 | + FROM trade_statistics | |
| 10 | + WHERE time BETWEEN #{beginTime} AND #{endTime} | |
| 11 | + AND deleted = FALSE | |
| 12 | + </select> | |
| 13 | + | |
| 5 | 14 | <select id="selectByTimeBetween" |
| 6 | 15 | resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO"> |
| 7 | 16 | SELECT | ... | ... |