diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeStatisticsComparisonRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/common/vo/DataComparisonRespVO.java similarity index 60% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeStatisticsComparisonRespVO.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/common/vo/DataComparisonRespVO.java index fee5b4c29..efd889a87 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeStatisticsComparisonRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/common/vo/DataComparisonRespVO.java @@ -1,16 +1,15 @@ -package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; +package cn.iocoder.yudao.module.statistics.controller.admin.common.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; -// TODO @疯狂:是不是搞成公用的哈;类似,controller/admin/common,下面直接放它 -@Schema(description = "管理后台 - 交易统计对照 Response VO") +@Schema(description = "管理后台 - 数据对照 Response VO") @Data @NoArgsConstructor @AllArgsConstructor -public class TradeStatisticsComparisonRespVO { +public class DataComparisonRespVO { @Schema(description = "当前数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private T value; diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java index f68693a6b..b78b207b5 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java @@ -3,8 +3,8 @@ package cn.iocoder.yudao.module.statistics.controller.admin.member; import cn.hutool.core.util.ArrayUtil; import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; import cn.iocoder.yudao.module.statistics.service.member.MemberStatisticsService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; @@ -79,7 +79,7 @@ public class MemberStatisticsController { @GetMapping("/user-count-comparison") @Operation(summary = "获得用户数量对照") @PreAuthorize("@ss.hasPermission('statistics:member:query')") - public CommonResult> getUserCountComparison() { + public CommonResult> getUserCountComparison() { return success(memberStatisticsService.getUserCountComparison()); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java index f36930180..58675f681 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java @@ -7,13 +7,11 @@ import lombok.Data; @Data public class MemberAnalyseComparisonRespVO { - // TODO @疯狂:这个字段,要不改成注册用户量;registerUserCount; @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer userCount; + private Integer registerUserCount; - // TODO @疯狂:这个字段,名字改成 visitUserCount;有访问,就算活跃; @Schema(description = "活跃用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer activeUserCount; + private Integer visitUserCount; @Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221") private Integer rechargeUserCount; diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java index df4e3d9ff..a235f53f8 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; @@ -8,9 +8,8 @@ import lombok.Data; @Data public class MemberAnalyseRespVO { - // TODO @疯狂:这个字段改成 visitUserCount,保持和 userCount 字段统一 @Schema(description = "访客数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer visitorCount; + private Integer visitUserCount; @Schema(description = "下单用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer orderUserCount; @@ -22,6 +21,6 @@ public class MemberAnalyseRespVO { private Integer atv; @Schema(description = "对照数据", requiredMode = Schema.RequiredMode.REQUIRED) - private TradeStatisticsComparisonRespVO comparison; + private DataComparisonRespVO comparison; } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAreaStatisticsRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAreaStatisticsRespVO.java index cd588aa30..1024d04ef 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAreaStatisticsRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAreaStatisticsRespVO.java @@ -15,11 +15,10 @@ public class MemberAreaStatisticsRespVO { @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer userCount; - // TODO @疯狂:要不 orderCreateUserCount 和 orderPayUserCount 貌似更统一一些; - @Schema(description = "订单创建数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer orderCreateCount; - @Schema(description = "订单支付数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512") - private Integer orderPayCount; + @Schema(description = "下单的会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer orderCreateUserCount; + @Schema(description = "支付订单的会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512") + private Integer orderPayUserCount; @Schema(description = "订单支付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "622") private Integer orderPayPrice; diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java index 4ee28e109..087b955d5 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java @@ -3,12 +3,15 @@ package cn.iocoder.yudao.module.statistics.controller.admin.trade; import cn.hutool.core.util.ArrayUtil; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*; import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert; +import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; import cn.iocoder.yudao.module.statistics.service.trade.AfterSaleStatisticsService; import cn.iocoder.yudao.module.statistics.service.trade.BrokerageStatisticsService; import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService; import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService; +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; import cn.iocoder.yudao.module.trade.enums.aftersale.AfterSaleStatusEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; import io.swagger.v3.oas.annotations.Operation; @@ -47,41 +50,47 @@ public class TradeStatisticsController { @GetMapping("/summary") @Operation(summary = "获得交易统计") @PreAuthorize("@ss.hasPermission('statistics:trade:query')") - public CommonResult> getTradeSummaryComparison() { - // TODO @疯狂:这个要不要 tradeStatisticsService 调用里面的多个方法,组合出最终的 TradeSummaryRespVO; - return success(tradeStatisticsService.getTradeSummaryComparison()); + public CommonResult> getTradeSummaryComparison() { + // 1.1 昨天的数据 + TradeSummaryRespBO yesterdayData = tradeStatisticsService.getTradeSummaryByDays(-1); + // 1.2 前天的数据(用于对照昨天的数据) + TradeSummaryRespBO beforeYesterdayData = tradeStatisticsService.getTradeSummaryByDays(-2); + // 2.1 本月数据 + TradeSummaryRespBO monthData = tradeStatisticsService.getTradeSummaryByMonths(0); + // 2.2 上月数据(用于对照本月的数据) + TradeSummaryRespBO lastMonthData = tradeStatisticsService.getTradeSummaryByMonths(-1); + // 拼接数据 + return success(TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData)); } // TODO @疯狂:【晚点再改和讨论;等首页的接口出来】这个要不还是叫 analyse,对比选中的时间段,和上一个时间段;类似 MemberStatisticsController 的 getMemberAnalyse @GetMapping("/trend/summary") @Operation(summary = "获得交易状况统计") @PreAuthorize("@ss.hasPermission('statistics:trade:query')") - public CommonResult> getTradeTrendSummaryComparison( + public CommonResult> getTradeTrendSummaryComparison( TradeTrendReqVO reqVO) { return success(tradeStatisticsService.getTradeTrendSummaryComparison(ArrayUtil.get(reqVO.getTimes(), 0), ArrayUtil.get(reqVO.getTimes(), 1))); } - // TODO 芋艿:已经 review - // TODO @疯狂:这个要不直接叫 list;它即使就是把每条统计拿出来 - @GetMapping("/trend/list") + @GetMapping("/list") @Operation(summary = "获得交易状况明细") @PreAuthorize("@ss.hasPermission('statistics:trade:query')") - public CommonResult> getTradeStatisticsList( - TradeTrendReqVO reqVO) { - return success(tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0), - ArrayUtil.get(reqVO.getTimes(), 1))); + public CommonResult> getTradeStatisticsList(TradeTrendReqVO reqVO) { + List list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0), + ArrayUtil.get(reqVO.getTimes(), 1)); + return success(TradeStatisticsConvert.INSTANCE.convertList(list)); } - // TODO @疯狂:这个要不直接叫 export;它即使就是把每条统计导出 - @GetMapping("/trend/export-excel") + @GetMapping("/export-excel") @Operation(summary = "导出获得交易状况明细 Excel") @PreAuthorize("@ss.hasPermission('statistics:trade:export')") public void exportTradeStatisticsExcel(TradeTrendReqVO reqVO, HttpServletResponse response) throws IOException { - List list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0), + List list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0), ArrayUtil.get(reqVO.getTimes(), 1)); // 导出 Excel - List data = TradeStatisticsConvert.INSTANCE.convertList02(list); + List voList = TradeStatisticsConvert.INSTANCE.convertList(list); + List data = TradeStatisticsConvert.INSTANCE.convertList02(voList); ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data); } @@ -98,14 +107,14 @@ public class TradeStatisticsController { @GetMapping("/order-comparison") @Operation(summary = "获得交易订单数量") @PreAuthorize("@ss.hasPermission('statistics:trade:query')") - public CommonResult> getOrderComparison() { + public CommonResult> getOrderComparison() { return success(tradeOrderStatisticsService.getOrderComparison()); } @GetMapping("/order-count-trend") @Operation(summary = "获得订单量趋势统计") @PreAuthorize("@ss.hasPermission('statistics:trade:query')") - public CommonResult>> getOrderCountTrendComparison(@Valid TradeOrderTrendReqVO reqVO) { + public CommonResult>> getOrderCountTrendComparison(@Valid TradeOrderTrendReqVO reqVO) { return success(tradeOrderStatisticsService.getOrderCountTrendComparison(reqVO)); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryExcelVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryExcelVO.java index 3253df07d..654d75893 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryExcelVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryExcelVO.java @@ -22,7 +22,7 @@ public class TradeTrendSummaryExcelVO { private LocalDate date; @ExcelProperty(value = "营业额", converter = MoneyConvert.class) - private Integer turnover; + private Integer turnoverPrice; @ExcelProperty(value = "商品支付金额", converter = MoneyConvert.class) private Integer orderPayPrice; @@ -34,7 +34,7 @@ public class TradeTrendSummaryExcelVO { private Integer expensePrice; @ExcelProperty(value = "余额支付金额", converter = MoneyConvert.class) - private Integer balancePrice; + private Integer orderWalletPayPrice; @ExcelProperty(value = "支付佣金金额", converter = MoneyConvert.class) private Integer brokerageSettlementPrice; diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryRespVO.java index 79f5583e6..2525a9993 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryRespVO.java @@ -16,13 +16,15 @@ public class TradeTrendSummaryRespVO { @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY) private LocalDate date; - // TODO @疯狂,要不加个 turnoverPrice? @Schema(description = "营业额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer turnover; // 营业额 = 商品支付金额 + 充值金额 + private Integer turnoverPrice; // 营业额 = 商品支付金额 + 充值金额 @Schema(description = "订单支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer orderPayPrice; + @Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer orderWalletPayPrice; + @Schema(description = "订单退款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer orderRefundPrice; @@ -35,7 +37,4 @@ public class TradeTrendSummaryRespVO { @Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer expensePrice; // 余额支付金额 + 支付佣金金额 + 商品退款金额 - @Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer balancePrice; // TODO @疯狂:这个字段要不改成:walletPayPrice - } 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 974edbecd..794a66717 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 @@ -32,8 +32,8 @@ public interface MemberStatisticsConvert { return new MemberAreaStatisticsRespVO() .setAreaId(area.getId()).setAreaName(area.getName()) .setUserCount(MapUtil.getInt(userCountMap, area.getId(), 0)) - .setOrderCreateCount(ObjUtil.defaultIfNull(orderVo.getOrderCreateCount(), 0)) - .setOrderPayCount(ObjUtil.defaultIfNull(orderVo.getOrderPayCount(), 0)) + .setOrderCreateUserCount(ObjUtil.defaultIfNull(orderVo.getOrderCreateUserCount(), 0)) + .setOrderPayUserCount(ObjUtil.defaultIfNull(orderVo.getOrderPayUserCount(), 0)) .setOrderPayPrice(ObjUtil.defaultIfNull(orderVo.getOrderPayPrice(), 0)); }); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/trade/TradeStatisticsConvert.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/trade/TradeStatisticsConvert.java index a2bce34d9..9fe68f96c 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/trade/TradeStatisticsConvert.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/trade/TradeStatisticsConvert.java @@ -1,14 +1,14 @@ package cn.iocoder.yudao.module.statistics.convert.trade; -import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryExcelVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; -import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -25,10 +25,10 @@ public interface TradeStatisticsConvert { TradeStatisticsConvert INSTANCE = Mappers.getMapper(TradeStatisticsConvert.class); - default TradeStatisticsComparisonRespVO convert(TradeSummaryRespBO yesterdayData, - TradeSummaryRespBO beforeYesterdayData, - TradeSummaryRespBO monthData, - TradeSummaryRespBO lastMonthData) { + default DataComparisonRespVO convert(TradeSummaryRespBO yesterdayData, + TradeSummaryRespBO beforeYesterdayData, + TradeSummaryRespBO monthData, + TradeSummaryRespBO lastMonthData) { return convert(convert(yesterdayData, monthData), convert(beforeYesterdayData, lastMonthData)); } @@ -39,10 +39,10 @@ public interface TradeStatisticsConvert { .setMonthOrderCount(monthData.getCount()).setMonthPayPrice(monthData.getSummary()); } - TradeStatisticsComparisonRespVO convert(TradeSummaryRespVO value, TradeSummaryRespVO reference); + DataComparisonRespVO convert(TradeSummaryRespVO value, TradeSummaryRespVO reference); - TradeStatisticsComparisonRespVO convert(TradeTrendSummaryRespVO value, - TradeTrendSummaryRespVO reference); + DataComparisonRespVO convert(TradeTrendSummaryRespVO value, + TradeTrendSummaryRespVO reference); List convertList02(List list); @@ -50,4 +50,20 @@ public interface TradeStatisticsConvert { AfterSaleSummaryRespBO afterSaleSummary, Integer brokerageSettlementPrice, WalletSummaryRespBO walletSummary); + List convertList(List list); + + default TradeTrendSummaryRespVO convert(TradeStatisticsDO tradeStatistics) { + return new TradeTrendSummaryRespVO() + .setDate(tradeStatistics.getTime().toLocalDate()) + // 营业额 = 商品支付金额 + 充值金额 + .setTurnoverPrice(tradeStatistics.getOrderPayPrice() + tradeStatistics.getRechargePayPrice()) + .setOrderPayPrice(tradeStatistics.getOrderPayPrice()) + .setRechargePrice(tradeStatistics.getRechargePayPrice()) + // 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额 + .setExpensePrice(tradeStatistics.getOrderWalletPayPrice() + tradeStatistics.getBrokerageSettlementPrice() + tradeStatistics.getAfterSaleRefundPrice()) + .setOrderWalletPayPrice(tradeStatistics.getOrderWalletPayPrice()) + .setBrokerageSettlementPrice(tradeStatistics.getBrokerageSettlementPrice()) + .setOrderRefundPrice(tradeStatistics.getAfterSaleRefundPrice()); + } + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java index f007aa21b..0cc3ba3f2 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java @@ -48,11 +48,6 @@ public class TradeStatisticsDO extends TenantBaseDO { * 总支付金额,单位:分 */ private Integer orderPayPrice; - // TODO @疯狂:这个字段改成 walletPayPrice,然后挪到 rechargePayCount 前面; - /** - * 总支付金额(余额),单位:分 - */ - private Integer orderWalletPayPrice; /** * 退款订单数 @@ -68,6 +63,10 @@ public class TradeStatisticsDO extends TenantBaseDO { */ private Integer brokerageSettlementPrice; + /** + * 总支付金额(余额),单位:分 + */ + private Integer orderWalletPayPrice; /** * 充值订单数 *

diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java index 020bbf37a..5f76b58fd 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java @@ -16,12 +16,12 @@ import java.time.LocalDateTime; @SuppressWarnings("rawtypes") public interface ApiAccessLogStatisticsMapper extends BaseMapperX { - Integer selectIpCountByCreateTimeBetween(@Param("userType") Integer userType, - @Param("beginTime") LocalDateTime beginTime, - @Param("endTime") LocalDateTime endTime); + Integer selectIpCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType, + @Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); - Integer selectUserCountByCreateTimeBetween(@Param("userType") Integer userType, - @Param("beginTime") LocalDateTime beginTime, - @Param("endTime") LocalDateTime endTime); + Integer selectUserCountByUserTypeAndCreateTimeBetween(@Param("userType") Integer userType, + @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/dal/mysql/member/MemberStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java index c158e9c03..0b3160c5c 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.statistics.dal.mysql.member; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberRegisterCountRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO; +import cn.iocoder.yudao.module.statistics.service.member.bo.MemberAreaStatisticsRespBO; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; @@ -19,9 +19,7 @@ import java.util.List; @SuppressWarnings("rawtypes") public interface MemberStatisticsMapper extends BaseMapperX { - // TODO @芋艿:已经 review - // TODO @疯狂:要不还是搞下 bo?虽然可能冗余了点~~ - List selectSummaryListByAreaId(); + List selectSummaryListByAreaId(); List selectSummaryListBySex(); diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java index d07caa43e..67d2d5007 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.statistics.dal.mysql.trade; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; @@ -21,14 +22,20 @@ public interface TradeStatisticsMapper extends BaseMapperX { TradeSummaryRespBO selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); - TradeTrendSummaryRespVO selectByTimeBetween(@Param("beginTime") LocalDateTime beginTime, - @Param("endTime") LocalDateTime endTime); + TradeTrendSummaryRespVO selectVoByTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); - // TODO @芋艿:已经 review - List selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime, - @Param("endTime") LocalDateTime endTime); + default List selectListByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) { + return selectList(new LambdaQueryWrapperX() + .between(TradeStatisticsDO::getTime, beginTime, endTime)); + } Integer selectExpensePriceByTimeBetween(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + default TradeStatisticsDO selectByTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) { + return selectOne(new LambdaQueryWrapperX() + .between(TradeStatisticsDO::getTime, beginTime, endTime)); + } + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/job/trade/TradeStatisticsJob.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/job/trade/TradeStatisticsJob.java index b97ba2338..2cefe22b5 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/job/trade/TradeStatisticsJob.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/job/trade/TradeStatisticsJob.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.statistics.job.trade; +import cn.hutool.core.convert.Convert; +import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; @@ -19,11 +21,24 @@ public class TradeStatisticsJob implements JobHandler { @Resource private TradeStatisticsService tradeStatisticsService; + /** + * 执行交易统计任务 + * + * @param param 要统计的天数,只能是正整数,1 代表昨日数据 + * @return 统计结果 + */ @Override @TenantJob public String execute(String param) { - String times = tradeStatisticsService.statisticsYesterdayTrade(); - return StrUtil.format("交易统计耗时: {}", times); + if (NumberUtil.isInteger(param)) { + throw new RuntimeException("交易统计任务的参数只能为是正整数"); + } + Integer days = Convert.toInt(param, 0); + if (days < 1) { + throw new RuntimeException("交易统计任务的参数只能为是正整数"); + } + String result = tradeStatisticsService.statisticsTrade(days); + return StrUtil.format("交易统计:\n{}", result); } } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java index 629db5d7f..6c200fdef 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java @@ -9,8 +9,6 @@ import java.time.LocalDateTime; */ public interface ApiAccessLogStatisticsService { - // TODO @疯狂:需要传递 userType;因为访问日志,可能涉及多种用户类型; - // TODO @疯狂:方法名,要不改成 getUserCount;原因:让它更业务无关 /** * 获取活跃用户数量 * @@ -19,10 +17,8 @@ public interface ApiAccessLogStatisticsService { * @param endTime 截止时间 * @return 活跃用户数量 */ - Integer getActiveUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime); + Integer getUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime); - // TODO @疯狂:需要传递 userType;因为访问日志,可能涉及多种用户类型; - // TODO @疯狂:方法名,要不改成 getIpCount;原因:让它更业务无关 /** * 获取访问用户数量 * @@ -31,6 +27,6 @@ public interface ApiAccessLogStatisticsService { * @param endTime 截止时间 * @return 访问用户数量 */ - Integer getVisitorUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime); + Integer getIpCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java index aed124f62..7ad62d00a 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java @@ -20,13 +20,13 @@ public class ApiAccessLogStatisticsServiceImpl implements ApiAccessLogStatistics private ApiAccessLogStatisticsMapper apiAccessLogStatisticsMapper; @Override - public Integer getActiveUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) { - return apiAccessLogStatisticsMapper.selectUserCountByCreateTimeBetween(userType, beginTime, endTime); + public Integer getUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) { + return apiAccessLogStatisticsMapper.selectUserCountByUserTypeAndCreateTimeBetween(userType, beginTime, endTime); } @Override - public Integer getVisitorUserCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) { - return apiAccessLogStatisticsMapper.selectIpCountByCreateTimeBetween(userType, beginTime, endTime); + public Integer getIpCount(Integer userType, LocalDateTime beginTime, LocalDateTime endTime) { + return apiAccessLogStatisticsMapper.selectIpCountByUserTypeAndCreateTimeBetween(userType, beginTime, endTime); } } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java index d5496e975..da9a61ac1 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java @@ -1,7 +1,7 @@ package cn.iocoder.yudao.module.statistics.service.member; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; import java.time.LocalDateTime; import java.util.List; @@ -59,6 +59,6 @@ public interface MemberStatisticsService { * * @return 用户数量量统计对照 */ - TradeStatisticsComparisonRespVO getUserCountComparison(); + DataComparisonRespVO getUserCountComparison(); } 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 628bbccdc..d9789fcb4 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 @@ -5,11 +5,12 @@ import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; 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.member.bo.MemberAreaStatisticsRespBO; 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; @@ -63,14 +64,14 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { // TODO @疯狂:可能得把每个省的用户,都查询出来,然后去 order 那边 in;因为要按照这些人为基础来计算;;用户规模量大可能不太好,但是暂时就先这样搞吧 = = Map userCountMap = convertMap(memberStatisticsMapper.selectSummaryListByAreaId(), vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE), - MemberAreaStatisticsRespVO::getUserCount, Integer::sum); + MemberAreaStatisticsRespBO::getUserCount, Integer::sum); // 统计订单 Map orderMap = convertMap(tradeOrderStatisticsService.getSummaryListByAreaId(), vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE), vo -> vo, (a, b) -> new MemberAreaStatisticsRespVO() - .setOrderCreateCount(a.getOrderCreateCount() + b.getOrderCreateCount()) - .setOrderPayCount(a.getOrderPayCount() + b.getOrderPayCount()) + .setOrderCreateUserCount(a.getOrderCreateUserCount() + b.getOrderCreateUserCount()) + .setOrderPayUserCount(a.getOrderPayUserCount() + b.getOrderPayUserCount()) .setOrderPayPrice(a.getOrderPayPrice() + b.getOrderPayPrice())); // 拼接数据 return MemberStatisticsConvert.INSTANCE.convertList(AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area), userCountMap, orderMap); @@ -96,19 +97,19 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { atv = NumberUtil.div(payPrice, payUserCount).intValue(); } return new MemberAnalyseRespVO() - .setVisitorCount(apiAccessLogStatisticsService.getVisitorUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime)) + .setVisitUserCount(apiAccessLogStatisticsService.getIpCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime)) .setOrderUserCount(tradeOrderStatisticsService.getOrderUserCount(beginTime, endTime)) .setPayUserCount(payUserCount) .setAtv(atv) - .setComparison(new TradeStatisticsComparisonRespVO<>(vo, reference)); + .setComparison(new DataComparisonRespVO<>(vo, reference)); } private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) { Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime)) .map(RechargeSummaryRespBO::getRechargeUserCount).orElse(0); return new MemberAnalyseComparisonRespVO() - .setUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime)) - .setActiveUserCount(apiAccessLogStatisticsService.getActiveUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime)) + .setRegisterUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime)) + .setVisitUserCount(apiAccessLogStatisticsService.getUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime)) .setRechargeUserCount(rechargeUserCount); } @@ -124,14 +125,14 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { } @Override - public TradeStatisticsComparisonRespVO getUserCountComparison() { + public DataComparisonRespVO getUserCountComparison() { // 今日时间范围 LocalDateTime beginOfToday = LocalDateTimeUtil.beginOfDay(LocalDateTime.now()); LocalDateTime endOfToday = LocalDateTimeUtil.endOfDay(beginOfToday); // 昨日时间范围 LocalDateTime beginOfYesterday = LocalDateTimeUtil.beginOfDay(beginOfToday.minusDays(1)); LocalDateTime endOfYesterday = LocalDateTimeUtil.endOfDay(beginOfYesterday); - return new TradeStatisticsComparisonRespVO() + return new DataComparisonRespVO() .setValue(getUserCount(beginOfToday, endOfToday)) .setReference(getUserCount(beginOfYesterday, endOfYesterday)); } @@ -139,7 +140,7 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { private MemberCountRespVO getUserCount(LocalDateTime beginTime, LocalDateTime endTime) { return new MemberCountRespVO() .setCreateUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime)) - .setVisitUserCount(apiAccessLogStatisticsService.getVisitorUserCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime)); + .setVisitUserCount(apiAccessLogStatisticsService.getIpCount(UserTypeEnum.MEMBER.getValue(), beginTime, endTime)); } } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/bo/MemberAreaStatisticsRespBO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/bo/MemberAreaStatisticsRespBO.java new file mode 100644 index 000000000..6b2d9ceab --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/bo/MemberAreaStatisticsRespBO.java @@ -0,0 +1,38 @@ +package cn.iocoder.yudao.module.statistics.service.member.bo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 会员地区统计 Response BO") +@Data +public class MemberAreaStatisticsRespBO { + + /** + * 省份编号 + */ + private Integer areaId; + /** + * 省份名称 + */ + private String areaName; + + /** + * 会员数量 + */ + private Integer userCount; + + /** + * 下单的会员数量 + */ + private Integer orderCreateUserCount; + /** + * 支付订单的会员数量 + */ + private Integer orderPayUserCount; + + /** + * 订单支付金额,单位:分 + */ + private Integer orderPayPrice; + +} 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 index 389ac2e4c..b99c05d44 100644 --- 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 @@ -3,15 +3,21 @@ package cn.iocoder.yudao.module.statistics.service.pay.bo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -// TODO @疯狂:BO 不用写 swagger 注解哈,写注释就好啦; -@Schema(description = "管理后台 - 充值统计 Response VO") +/** + * 充值统计 Response BO + */ +@Schema(description = "管理后台 - ") @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/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java index b40364096..dc92b2660 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.statistics.service.trade; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; @@ -73,7 +74,7 @@ public interface TradeOrderStatisticsService { * * @return 销售额对照 */ - TradeStatisticsComparisonRespVO getOrderComparison(); + DataComparisonRespVO getOrderComparison(); /** * 获得订单量趋势统计 @@ -81,6 +82,6 @@ public interface TradeOrderStatisticsService { * @param reqVO 统计参数 * @return 订单量趋势统计 */ - List> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO); + List> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java index 5daa727c8..2758979f5 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java @@ -4,6 +4,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.util.ObjUtil; import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.*; import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper; @@ -71,8 +72,8 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ } @Override - public TradeStatisticsComparisonRespVO getOrderComparison() { - return new TradeStatisticsComparisonRespVO() + public DataComparisonRespVO getOrderComparison() { + return new DataComparisonRespVO() .setValue(getPayPriceSummary(LocalDateTime.now())) .setReference(getPayPriceSummary(LocalDateTime.now().minusDays(1))); } @@ -85,7 +86,7 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ } @Override - public List> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO) { + public List> getOrderCountTrendComparison(TradeOrderTrendReqVO reqVO) { // 查询当前数据 List value = getOrderCountTrend(reqVO.getType(), reqVO.getBeginTime(), reqVO.getEndTime()); // 查询对照数据 @@ -94,7 +95,7 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ List reference = getOrderCountTrend(reqVO.getType(), referenceBeginTime, referenceEndTime); return IntStream.range(0, value.size()) - .mapToObj(index -> new TradeStatisticsComparisonRespVO() + .mapToObj(index -> new DataComparisonRespVO() .setValue(CollUtil.get(value, index)) .setReference(CollUtil.get(reference, index))) .collect(Collectors.toList()); diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java index 998b96386..949f95ba9 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java @@ -1,8 +1,9 @@ package cn.iocoder.yudao.module.statistics.service.trade; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; +import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; import java.time.LocalDateTime; import java.util.List; @@ -14,19 +15,12 @@ import java.util.List; */ public interface TradeStatisticsService { - /** - * 获得交易统计 - * - * @return 统计数据对照 - */ - TradeStatisticsComparisonRespVO getTradeSummaryComparison(); - /** * 获得交易状况统计对照 * * @return 统计数据对照 */ - TradeStatisticsComparisonRespVO getTradeTrendSummaryComparison( + DataComparisonRespVO getTradeTrendSummaryComparison( LocalDateTime beginTime, LocalDateTime endTime); /** @@ -45,14 +39,30 @@ public interface TradeStatisticsService { * @param endTime 结束时间 * @return 统计数据列表 */ - List getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime); + List getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime); // TODO 芋艿:已经 review; /** - * 统计昨日交易 + * 统计指定天数的交易数据 * - * @return 耗时 + * @return 统计结果 */ - String statisticsYesterdayTrade(); + String statisticsTrade(Integer days); + + /** + * 统计指定日期的交易数据 + * + * @param days 增加的天数 + * @return 交易数据 + */ + TradeSummaryRespBO getTradeSummaryByDays(int days); + + /** + * 统计指定月份的交易数据 + * + * @param months 增加的月数 + * @return 交易数据 + */ + TradeSummaryRespBO getTradeSummaryByMonths(int months); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsServiceImpl.java index 997284abf..43b3fa475 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsServiceImpl.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.statistics.service.trade; +import cn.hutool.core.date.DatePattern; import cn.hutool.core.date.LocalDateTimeUtil; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.common.vo.DataComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert; import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; @@ -21,6 +21,8 @@ import javax.annotation.Resource; import java.time.Duration; import java.time.LocalDateTime; import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.IntStream; /** * 交易统计 Service 实现类 @@ -44,51 +46,27 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { private PayWalletStatisticsService payWalletStatisticsService; @Override - public TradeStatisticsComparisonRespVO getTradeSummaryComparison() { - // 1.1 昨天的数据 - TradeSummaryRespBO yesterdayData = getTradeSummaryByDays(-1); - // 1.2 前天的数据(用于对照昨天的数据) - TradeSummaryRespBO beforeYesterdayData = getTradeSummaryByDays(-2); - // 2.1 本月数据 - TradeSummaryRespBO monthData = getTradeSummaryByMonths(0); - // 2.2 上月数据(用于对照本月的数据) - TradeSummaryRespBO lastMonthData = getTradeSummaryByMonths(-1); - // 转换返回 - return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData); - } - - /** - * 统计指定日期的交易数据 - * - * @param days 增加的天数 - * @return 交易数据 - */ - private TradeSummaryRespBO getTradeSummaryByDays(int days) { + public TradeSummaryRespBO getTradeSummaryByDays(int days) { LocalDateTime date = LocalDateTime.now().plusDays(days); return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween( LocalDateTimeUtil.beginOfDay(date), LocalDateTimeUtil.endOfDay(date)); } - /** - * 统计指定月份的交易数据 - * - * @param months 增加的月数 - * @return 交易数据 - */ - private TradeSummaryRespBO getTradeSummaryByMonths(int months) { + @Override + public TradeSummaryRespBO getTradeSummaryByMonths(int months) { LocalDateTime monthDate = LocalDateTime.now().plusMonths(months); return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween( LocalDateTimeUtils.beginOfMonth(monthDate), LocalDateTimeUtils.endOfMonth(monthDate)); } @Override - public TradeStatisticsComparisonRespVO getTradeTrendSummaryComparison(LocalDateTime beginTime, - LocalDateTime endTime) { + public DataComparisonRespVO getTradeTrendSummaryComparison(LocalDateTime beginTime, + LocalDateTime endTime) { // 统计数据 - TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime); + TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectVoByTimeBetween(beginTime, endTime); // 对照数据 LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime)); - TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectByTimeBetween(referenceBeginTime, beginTime); + TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectVoByTimeBetween(referenceBeginTime, beginTime); return TradeStatisticsConvert.INSTANCE.convert(value, reference); } @@ -97,41 +75,60 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { return tradeStatisticsMapper.selectExpensePriceByTimeBetween(beginTime, endTime); } - // TODO @疯狂:是不是直接返回 TradeStatisticsDO;上层在去聚合? @Override - public List getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) { + public List getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) { return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime); } @Override - public String statisticsYesterdayTrade() { - // TODO @疯狂:如果已经统计,则跳过; - // TODO @疯狂:改成 statisticsTrade,然后传入 days,统计多少天;days 通过 job 传参;方便把历史给统计出来;或者大家有的时候要修复数据(会 fix 业务数据,然后清理统计表),重新统计的时候; - // 1. 从各个数据表,统计对应数据 - LocalDateTime yesterday = LocalDateTime.now().minusDays(1); - LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); - LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); - // 1.1 统计订单 - StopWatch stopWatch = new StopWatch("交易统计"); + public String statisticsTrade(Integer days) { + LocalDateTime today = LocalDateTime.now(); + return IntStream.rangeClosed(1, days) + .parallel() + .mapToObj(day -> statisticsTrade(today.minusDays(day))) + .sorted() + .collect(Collectors.joining("\n")); + } + + /** + * 统计交易数据 + * + * @param date 需要统计的日期 + * @return 统计结果 + */ + private String statisticsTrade(LocalDateTime date) { + // 1. 处理统计时间范围 + LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(date); + LocalDateTime endTime = LocalDateTimeUtil.endOfDay(date); + String dateStr = DatePattern.NORM_DATE_FORMAT.format(date); + // 2. 检查该日是否已经统计过 + TradeStatisticsDO entity = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime); + if (entity != null) { + return dateStr + " 数据已存在,如果需要重新统计,请先删除对应的数据"; + } + + // 3. 从各个数据表,统计对应数据 + StopWatch stopWatch = new StopWatch(dateStr); + // 3.1 统计订单 stopWatch.start("统计订单"); TradeOrderSummaryRespBO orderSummary = tradeOrderStatisticsService.getOrderSummary(beginTime, endTime); stopWatch.stop(); - // 1.2 统计售后 + // 3.2 统计售后 stopWatch.start("统计售后"); AfterSaleSummaryRespBO afterSaleSummary = afterSaleStatisticsService.getAfterSaleSummary(beginTime, endTime); stopWatch.stop(); - // 1.3 统计佣金 + // 3.3 统计佣金 stopWatch.start("统计佣金"); Integer brokerageSettlementPrice = brokerageStatisticsService.getBrokerageSettlementPriceSummary(beginTime, endTime); stopWatch.stop(); - // 1.4 统计充值 + // 3.4 统计充值 stopWatch.start("统计充值"); WalletSummaryRespBO walletSummary = payWalletStatisticsService.getWalletSummary(beginTime, endTime); stopWatch.stop(); - // 2. 插入数据 - TradeStatisticsDO entity = TradeStatisticsConvert.INSTANCE.convert(yesterday, orderSummary, afterSaleSummary, - brokerageSettlementPrice, walletSummary); + // 4. 插入数据 + entity = TradeStatisticsConvert.INSTANCE.convert(date, orderSummary, afterSaleSummary, brokerageSettlementPrice, + walletSummary); tradeStatisticsMapper.insert(entity); return stopWatch.prettyPrint(); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml index ac418927e..e64161597 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml @@ -2,7 +2,7 @@ - SELECT COUNT(DISTINCT user_ip) FROM infra_api_access_log WHERE user_type = #{userType} @@ -10,7 +10,7 @@ AND deleted = FALSE - SELECT COUNT(DISTINCT user_id) FROM infra_api_access_log WHERE user_id > 0 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 c00e2d70e..5c464d926 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 @@ -3,7 +3,7 @@ - - SELECT COUNT(1) AS rechargeUserCount, - SUM(pay_price) AS rechargePrice + SELECT COUNT(DISTINCT wallet_id) AS rechargeUserCount, + SUM(pay_price) AS rechargePrice FROM pay_wallet_recharge WHERE pay_status = #{payStatus} @@ -44,7 +43,6 @@ AND pay_time <= #{endTime} AND deleted = FALSE - GROUP BY wallet_id SELECT receiver_area_id AS areaId, - (SELECT COUNT(1) + (SELECT COUNT(DISTINCT s.user_id) FROM trade_order AS s - WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateCount, - (SELECT COUNT(1) + WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateUserCount, + (SELECT COUNT(DISTINCT s.user_id) FROM trade_order AS s WHERE s.receiver_area_id = m.receiver_area_id AND s.pay_status = TRUE - AND s.deleted = FALSE) AS orderPayCount, + AND s.deleted = FALSE) AS orderPayUserCount, (SELECT SUM(s.pay_price) FROM trade_order AS s WHERE s.receiver_area_id = m.receiver_area_id diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml index 1ef2e2f39..74cc11ac9 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml @@ -11,16 +11,16 @@ AND deleted = FALSE - - -