From df16278a03daab9ce37e3ab450fde204ca43ecf8 Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 9 Oct 2023 23:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=EF=BC=9A=E4=BC=9A=E5=91=98?= =?UTF-8?q?=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sql/mysql/statistics.sql | 14 ++- .../util/collection/CollectionUtils.java | 12 +- .../framework/ip/core/utils/AreaUtils.java | 37 +++++- .../yudao-module-statistics-biz/pom.xml | 5 + .../member/MemberStatisticsController.java | 47 +++++--- .../vo/MemberAnalyseComparisonRespVO.java | 19 +++ .../admin/member/vo/MemberAnalyseReqVO.java | 19 +++ .../admin/member/vo/MemberAnalyseRespVO.java | 26 ++++ .../member/vo/MemberSexStatisticsRespVO.java | 7 -- .../admin/member/vo/MemberSummaryRespVO.java | 1 + .../vo/MemberTerminalStatisticsRespVO.java | 9 +- .../member/MemberStatisticsConvert.java | 39 ++++++ .../infra/ApiAccessLogStatisticsMapper.java | 21 ++++ .../mysql/member/MemberStatisticsMapper.java | 26 ++++ .../PayWalletStatisticsMapper.java | 8 +- .../trade/TradeOrderStatisticsMapper.java | 21 +++- .../mysql/trade/TradeStatisticsMapper.java | 3 + .../infra/ApiAccessLogStatisticsService.java | 30 +++++ .../ApiAccessLogStatisticsServiceImpl.java | 31 +++++ .../member/MemberStatisticsService.java | 48 ++++++++ .../member/MemberStatisticsServiceImpl.java | 114 ++++++++++++++++++ .../PayWalletStatisticsService.java | 12 +- .../PayWalletStatisticsServiceImpl.java | 12 +- .../trade/TradeOrderStatisticsService.java | 36 ++++++ .../TradeOrderStatisticsServiceImpl.java | 27 ++++- .../service/trade/TradeStatisticsService.java | 9 +- .../trade/TradeStatisticsServiceImpl.java | 6 + .../trade/bo/TradeOrderSummaryRespBO.java | 2 +- .../infra/ApiAccessLogStatisticsMapper.xml | 20 +++ .../mapper/member/MemberStatisticsMapper.xml | 34 ++++++ .../trade/TradeOrderStatisticsMapper.xml | 62 ++++++++-- .../mapper/trade/TradeStatisticsMapper.xml | 13 +- .../PayWalletStatisticsMapper.xml | 18 ++- .../src/main/resources/application-local.yaml | 1 + 34 files changed, 731 insertions(+), 58 deletions(-) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseReqVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java rename yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/{trade => pay}/PayWalletStatisticsMapper.java (75%) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java rename yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/{trade => pay}/PayWalletStatisticsService.java (53%) rename yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/{trade => pay}/PayWalletStatisticsServiceImpl.java (77%) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml rename yudao-module-mall/yudao-module-statistics-biz/src/main/resources/{mapper/trade => pay}/PayWalletStatisticsMapper.xml (69%) diff --git a/sql/mysql/statistics.sql b/sql/mysql/statistics.sql index 48f1c4ad4..0decf1ef1 100644 --- a/sql/mysql/statistics.sql +++ b/sql/mysql/statistics.sql @@ -28,16 +28,22 @@ CREATE INDEX trade_statistics_time_index ON trade_statistics (time); -- 菜单 -INSERT INTO `ruoyi-vue-pro`.system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) +INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) VALUES ('统计管理', '', 1, 4, 0, '/statistics', 'ep:data-line', '', ''); SELECT @parentId := LAST_INSERT_ID(); -INSERT INTO `ruoyi-vue-pro`.system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) -VALUES ('交易统计', '', 2, 4, @parentId, 'trade', 'fa-solid:credit-card', 'statistics/trade/index', 'TradeStatistics'); +-- 交易统计 +INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) +VALUES ('交易统计', '', 2, 1, @parentId, 'trade', 'fa-solid:credit-card', 'statistics/trade/index', 'TradeStatistics'); SELECT @parentId := LAST_INSERT_ID(); --- 按钮 INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('交易统计查询', 'statistics:trade:query', 3, 1, @parentId, '', '', '', 0); INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) VALUES ('交易统计导出', 'statistics:trade:export', 3, 2, @parentId, '', '', '', 0); +-- 会员统计 +INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) +VALUES ('会员统计', '', 2, 2, @parentId, 'member', 'ep:avatar', 'statistics/member/index', 'MemberStatistics'); +SELECT @parentId := LAST_INSERT_ID(); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('会员统计查询', 'statistics:member:query', 3, 1, @parentId, '', '', '', 0); diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index 12d18dc95..289ee1603 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.common.util.collection; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ArrayUtil; import com.google.common.collect.ImmutableMap; import java.util.*; @@ -50,6 +51,13 @@ public class CollectionUtils { return new ArrayList<>(convertMap(from, keyMapper, Function.identity(), cover).values()); } + public static List convertList(T[] from, Function func) { + if (ArrayUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return convertList(Arrays.asList(from), func); + } + public static List convertList(Collection from, Function func) { if (CollUtil.isEmpty(from)) { return new ArrayList<>(); @@ -162,8 +170,8 @@ public class CollectionUtils { /** * 对比老、新两个列表,找出新增、修改、删除的数据 * - * @param oldList 老列表 - * @param newList 新列表 + * @param oldList 老列表 + * @param newList 新列表 * @param sameFunc 对比函数,返回 true 表示相同,返回 false 表示不同 * 注意,same 是通过每个元素的“标识”,判断它们是不是同一个数据 * @return [新增列表、修改列表、删除列表] 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 d3fe59a6c..8455dff9a 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 @@ -7,12 +7,16 @@ import cn.hutool.core.text.csv.CsvUtil; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.ip.core.Area; import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; /** * 区域工具类 @@ -108,7 +112,7 @@ public class AreaUtils { // “递归”父节点 area = area.getParent(); if (area == null - || ObjectUtils.equalsAny(area.getId(), Area.ID_GLOBAL, Area.ID_CHINA)) { // 跳过父节点为中国的情况 + || ObjectUtils.equalsAny(area.getId(), Area.ID_GLOBAL, Area.ID_CHINA)) { // 跳过父节点为中国的情况 break; } sb.insert(0, separator); @@ -116,4 +120,35 @@ public class AreaUtils { return sb.toString(); } + /** + * 获取指定类型的区域列表 + * + * @param type 区域类型 + * @param func 转换函数 + * @param 结果类型 + * @return 区域列表 + */ + public static List getByType(AreaTypeEnum type, Function func) { + return convertList(areas.values(), func, area -> type.getType().equals(area.getType())); + } + + public static Integer getParentIdByType(Integer id, @NonNull AreaTypeEnum type) { + do { + 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); + } + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/pom.xml b/yudao-module-mall/yudao-module-statistics-biz/pom.xml index dd04c47c8..5490715fa 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/pom.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/pom.xml @@ -59,6 +59,11 @@ yudao-spring-boot-starter-biz-tenant + + cn.iocoder.boot + yudao-spring-boot-starter-biz-ip + + cn.iocoder.boot 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 f4f0f3d92..3d10f667a 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 @@ -1,21 +1,25 @@ 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.member.vo.MemberAreaStatisticsRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberTerminalStatisticsRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*; +import cn.iocoder.yudao.module.statistics.service.member.MemberStatisticsService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; +import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import javax.annotation.Resource; import java.util.List; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; + @Tag(name = "管理后台 - 会员统计") @RestController @RequestMapping("/statistics/member") @@ -23,36 +27,47 @@ import java.util.List; @Slf4j public class MemberStatisticsController { - // TODO @疯狂:一个类似 getTradeTrendSummaryComparison 的接口 - // TODO @疯狂:一个类似 getTradeStatisticsList 的接口 + @Resource + private MemberStatisticsService memberStatisticsService; @GetMapping("/summary") @Operation(summary = "获得会员统计") - public CommonResult> getMemberSummary() { - // TODO 疯狂:目前先直接计算; - return null; + @PreAuthorize("@ss.hasPermission('statistics:member:query')") + public CommonResult getMemberSummary() { + return success(memberStatisticsService.getMemberSummary()); + } + + @GetMapping("/analyse") + @Operation(summary = "获得会员分析数据") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") + public CommonResult getMemberAnalyse(MemberAnalyseReqVO reqVO) { + return success(memberStatisticsService.getMemberAnalyse( + ArrayUtil.get(reqVO.getTimes(), 0), ArrayUtil.get(reqVO.getTimes(), 1))); } @GetMapping("/get-area-statistics-list") @Operation(summary = "按照省份,获得会员统计列表") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") public CommonResult> getMemberAreaStatisticsList() { - // TODO 疯狂:目前先直接计算,进行统计;后续再考虑优化 - return null; + return success(memberStatisticsService.getMemberAreaStatisticsList()); } @GetMapping("/get-sex-statistics-list") @Operation(summary = "按照性别,获得会员统计列表") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") public CommonResult> getMemberSexStatisticsList() { - // TODO 疯狂:目前先直接计算,进行统计;后续再考虑优化 - return null; + return success(memberStatisticsService.getMemberSexStatisticsList()); } @GetMapping("/get-terminal-statistics-list") @Operation(summary = "按照终端,获得会员统计列表") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") public CommonResult> getMemberTerminalStatisticsList() { - // TODO 疯狂:目前先直接计算,进行统计;后续再考虑优化 // TODO 疯狂:这个可以晚点写,因为 user = = 上还没记录 terminal - return null; + List list = convertList(TerminalEnum.values(), + t -> new MemberTerminalStatisticsRespVO() + .setTerminal(t.getTerminal()).setUserCount(t.getTerminal() * 100)); + return success(list); } } 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 new file mode 100644 index 000000000..cf8551d0c --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 会员分析对照数据 Response VO") +@Data +public class MemberAnalyseComparisonRespVO { + + @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer userCount; + + @Schema(description = "活跃用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer activeUserCount; + + @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/MemberAnalyseReqVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseReqVO.java new file mode 100644 index 000000000..e0106b4e8 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseReqVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import org.springframework.format.annotation.DateTimeFormat; + +import java.time.LocalDateTime; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND; + +@Schema(description = "管理后台 - 会员分析 Request VO") +@Data +public class MemberAnalyseReqVO { + + @DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND) + @Schema(description = "时间范围") + private LocalDateTime[] times; + +} 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 new file mode 100644 index 000000000..0f4a3d1ff --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; + +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 会员分析 Response VO") +@Data +public class MemberAnalyseRespVO { + + @Schema(description = "访客数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer visitorCount; + + @Schema(description = "下单用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer orderUserCount; + + @Schema(description = "成交用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer payUserCount; + + @Schema(description = "客单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer atv; + + @Schema(description = "对照数据", requiredMode = Schema.RequiredMode.REQUIRED) + private TradeStatisticsComparisonRespVO comparison; + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java index 83a0b17e8..975f2a871 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java @@ -13,11 +13,4 @@ public class MemberSexStatisticsRespVO { @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer userCount; - @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 = "622") - private Integer orderPayPrice; - } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java index ab79dfeeb..1dacd449c 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java @@ -15,6 +15,7 @@ public class MemberSummaryRespVO { @Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer rechargePrice; + @Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer expensePrice; diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java index 06112e3b0..e3aeaedc2 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -@Schema(description = "管理后台 - 终端性别统计 Response VO") +@Schema(description = "管理后台 - 会员终端统计 Response VO") @Data public class MemberTerminalStatisticsRespVO { @@ -13,11 +13,4 @@ public class MemberTerminalStatisticsRespVO { @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer userCount; - @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 = "622") - private Integer orderPayPrice; - } 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 new file mode 100644 index 000000000..0eceada3f --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.statistics.convert.member; + +import cn.hutool.core.map.MapUtil; +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 org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * 会员统计 Convert + * + * @author owen + */ +@Mapper +public interface MemberStatisticsConvert { + + MemberStatisticsConvert INSTANCE = Mappers.getMapper(MemberStatisticsConvert.class); + + default List convertList(List areaList, + Map userCountMap, + Map orderMap) { + return CollectionUtils.convertList(areaList, area -> { + MemberAreaStatisticsRespVO orderVo = Optional.ofNullable(orderMap.get(area.getId())).orElseGet(MemberAreaStatisticsRespVO::new); + 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)) + .setOrderPayPrice(ObjUtil.defaultIfNull(orderVo.getOrderPayPrice(), 0)); + }); + } + +} 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 new file mode 100644 index 000000000..0e8d719ad --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.infra; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; + +/** + * API 访问日志统计 Mapper + * + * @author owen + */ +@Mapper +public interface ApiAccessLogStatisticsMapper extends BaseMapperX { + + Integer selectCountByIp(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + Integer selectCountByUserId(@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 new file mode 100644 index 000000000..22a89ea9d --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java @@ -0,0 +1,26 @@ +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.MemberSexStatisticsRespVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 会员统计 Mapper + * + * @author owen + */ +@Mapper +public interface MemberStatisticsMapper extends BaseMapperX { + + List selectSummaryListByAreaId(); + + List selectSummaryListBySex(); + + Integer selectUserCount(@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/trade/PayWalletStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java similarity index 75% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/PayWalletStatisticsMapper.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java index 126a1557b..75e6a4ae1 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/PayWalletStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java @@ -1,6 +1,7 @@ -package cn.iocoder.yudao.module.statistics.dal.mysql.trade; +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 org.apache.ibatis.annotations.Mapper; @@ -27,4 +28,9 @@ public interface PayWalletStatisticsMapper extends BaseMapperX { - TradeOrderSummaryRespBO selectSummaryByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, - @Param("endTime") LocalDateTime endTime); + List selectSummaryListByAreaId(); + + Integer selectCountByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectCountByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectSummaryPriceByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectUserCountByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectUserCountByPayTimeBetween(@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/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 c1760fe30..b3680c97f 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 @@ -30,4 +30,7 @@ public interface TradeStatisticsMapper extends BaseMapperX { List selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + Integer selectExpensePriceByTimeBetween(@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/infra/ApiAccessLogStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java new file mode 100644 index 000000000..c83f4da82 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.statistics.service.infra; + +import java.time.LocalDateTime; + +/** + * API 访问日志统计 Service 接口 + * + * @author owen + */ +public interface ApiAccessLogStatisticsService { + + /** + * 获取活跃用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 活跃用户数量 + */ + Integer getActiveUserCount(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取访问用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 访问用户数量 + */ + Integer getVisitorUserCount(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 new file mode 100644 index 000000000..4c9fb08e2 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.statistics.service.infra; + +import cn.iocoder.yudao.module.statistics.dal.mysql.infra.ApiAccessLogStatisticsMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * API 访问日志统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class ApiAccessLogStatisticsServiceImpl implements ApiAccessLogStatisticsService { + + @Resource + private ApiAccessLogStatisticsMapper apiAccessLogStatisticsMapper; + + @Override + public Integer getActiveUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return apiAccessLogStatisticsMapper.selectCountByUserId(beginTime, endTime); + } + + @Override + public Integer getVisitorUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return apiAccessLogStatisticsMapper.selectCountByIp(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 new file mode 100644 index 000000000..2c84c3616 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.statistics.service.member; + +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAnalyseRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 会员统计 Service 接口 + * + * @author owen + */ +public interface MemberStatisticsService { + + /** + * 按照省份,获得会员统计列表 + * + * @return 会员统计列表 + */ + List getMemberAreaStatisticsList(); + + /** + * 按照性别,获得会员统计列表 + * + * @return 会员统计列表 + */ + List getMemberSexStatisticsList(); + + /** + * 获取用户分析数据 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 用户分析数据 + */ + MemberAnalyseRespVO getMemberAnalyse(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取会员统计 + * + * @return 会员统计 + */ + MemberSummaryRespVO getMemberSummary(); + +} 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 new file mode 100644 index 000000000..153e7c581 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java @@ -0,0 +1,114 @@ +package cn.iocoder.yudao.module.statistics.service.member; + +import cn.hutool.core.util.NumberUtil; +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.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.pay.PayWalletStatisticsService; +import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService; +import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.Duration; +import java.time.LocalDateTime; +import java.util.List; +import java.util.Map; +import java.util.Optional; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; + +/** + * 会员统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class MemberStatisticsServiceImpl implements MemberStatisticsService { + + @Resource + private MemberStatisticsMapper memberStatisticsMapper; + + @Resource + private PayWalletStatisticsService payWalletStatisticsService; + @Resource + private TradeStatisticsService tradeStatisticsService; + @Resource + private TradeOrderStatisticsService tradeOrderStatisticsService; + @Resource + private ApiAccessLogStatisticsService apiAccessLogStatisticsService; + + @Override + public List getMemberAreaStatisticsList() { + // 统计用户 + Map userCountMap = convertMap(memberStatisticsMapper.selectSummaryListByAreaId(), + vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE), + MemberAreaStatisticsRespVO::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()) + .setOrderPayPrice(a.getOrderPayPrice() + b.getOrderPayPrice())); + // 拼接数据 + return MemberStatisticsConvert.INSTANCE.convertList(AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area), userCountMap, orderMap); + } + + @Override + public List getMemberSexStatisticsList() { + return memberStatisticsMapper.selectSummaryListBySex(); + } + + @Override + public MemberAnalyseRespVO getMemberAnalyse(LocalDateTime beginTime, LocalDateTime endTime) { + // 对照数据 + MemberAnalyseComparisonRespVO vo = getMemberAnalyseComparisonData(beginTime, endTime); + LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime)); + MemberAnalyseComparisonRespVO reference = getMemberAnalyseComparisonData(referenceBeginTime, beginTime); + + Integer payUserCount = tradeOrderStatisticsService.getPayUserCount(beginTime, endTime); + // 计算客单价 + int atv = 0; + if (payUserCount != null && payUserCount > 0) { + Integer payPrice = tradeOrderStatisticsService.getOrderPayPrice(beginTime, endTime); + atv = NumberUtil.div(payPrice, payUserCount).intValue(); + } + return new MemberAnalyseRespVO() + .setVisitorCount(apiAccessLogStatisticsService.getVisitorUserCount(beginTime, endTime)) + .setOrderUserCount(tradeOrderStatisticsService.getOrderUserCount(beginTime, endTime)) + .setPayUserCount(payUserCount) + .setAtv(atv) + .setComparison(new TradeStatisticsComparisonRespVO<>(vo, reference)); + } + + @Override + public MemberSummaryRespVO getMemberSummary() { + MemberSummaryRespVO vo = 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); + } + + private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) { + Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime)) + .map(MemberSummaryRespVO::getRechargeUserCount).orElse(0); + return new MemberAnalyseComparisonRespVO() + .setUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime)) + .setActiveUserCount(apiAccessLogStatisticsService.getActiveUserCount(beginTime, endTime)) + .setRechargeUserCount(rechargeUserCount); + } + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java similarity index 53% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java index 6eb03d7f8..77e3e4fd2 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java @@ -1,5 +1,6 @@ -package cn.iocoder.yudao.module.statistics.service.trade; +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.trade.bo.WalletSummaryRespBO; import java.time.LocalDateTime; @@ -20,4 +21,13 @@ public interface PayWalletStatisticsService { */ WalletSummaryRespBO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime); + /** + * 获取钱包充值统计 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 钱包充值统计 + */ + MemberSummaryRespVO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime); + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java similarity index 77% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java index 95f073de1..28b1f434e 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java @@ -1,9 +1,10 @@ -package cn.iocoder.yudao.module.statistics.service.trade; +package cn.iocoder.yudao.module.statistics.service.pay; -import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum; -import cn.iocoder.yudao.module.statistics.dal.mysql.trade.PayWalletStatisticsMapper; +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.trade.bo.WalletSummaryRespBO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -38,4 +39,9 @@ public class PayWalletStatisticsServiceImpl implements PayWalletStatisticsServic return paySummary; } + @Override + public MemberSummaryRespVO 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/trade/TradeOrderStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java index 8ae3f89a3..b02745e6f 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,8 +1,10 @@ package cn.iocoder.yudao.module.statistics.service.trade; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; import java.time.LocalDateTime; +import java.util.List; /** * 交易订单统计 Service 接口 @@ -20,4 +22,38 @@ public interface TradeOrderStatisticsService { */ TradeOrderSummaryRespBO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); + /** + * 获取地区订单统计 + * + * @return 订单统计结果 + */ + List getSummaryListByAreaId(); + + /** + * 获取下单用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 支付下单数量 + */ + Integer getOrderUserCount(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取支付用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 支付用户数量 + */ + Integer getPayUserCount(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取支付金额 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 支付用户金额 + */ + Integer getOrderPayPrice(LocalDateTime beginTime, LocalDateTime endTime); + } 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 d3449abd8..10dd180d0 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 @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.statistics.service.trade; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; import org.springframework.stereotype.Service; @@ -7,6 +8,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.List; /** * 交易订单统计 Service 实现类 @@ -22,7 +24,30 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ @Override public TradeOrderSummaryRespBO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { - return tradeOrderStatisticsMapper.selectSummaryByPayTimeBetween(beginTime, endTime); + return new TradeOrderSummaryRespBO() + .setOrderCreateCount(tradeOrderStatisticsMapper.selectCountByCreateTimeBetween(beginTime, endTime)) + .setOrderPayCount(tradeOrderStatisticsMapper.selectCountByPayTimeBetween(beginTime, endTime)) + .setOrderPayPrice(tradeOrderStatisticsMapper.selectSummaryPriceByPayTimeBetween(beginTime, endTime)); + } + + @Override + public List getSummaryListByAreaId() { + return tradeOrderStatisticsMapper.selectSummaryListByAreaId(); + } + + @Override + public Integer getOrderUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeOrderStatisticsMapper.selectUserCountByCreateTimeBetween(beginTime, endTime); + } + + @Override + public Integer getPayUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeOrderStatisticsMapper.selectUserCountByPayTimeBetween(beginTime, endTime); + } + + @Override + public Integer getOrderPayPrice(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeOrderStatisticsMapper.selectSummaryPriceByPayTimeBetween(beginTime, endTime); } } 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 b7ddcb1ea..41b709e77 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 @@ -22,13 +22,20 @@ public interface TradeStatisticsService { TradeStatisticsComparisonRespVO getTradeSummaryComparison(); /** - * 获得交易状况统计 + * 获得交易状况统计对照 * * @return 统计数据对照 */ TradeStatisticsComparisonRespVO getTradeTrendSummaryComparison( LocalDateTime beginTime, LocalDateTime endTime); + /** + * 获得交易状况统计 + * + * @return 统计数据对照 + */ + Integer getExpensePrice(LocalDateTime beginTime, LocalDateTime endTime); + /** * 获得交易状况明细 * 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 1fc075b0e..7a25dfe89 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 @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.statistics.service.trade; import cn.hutool.core.date.LocalDateTimeUtil; import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; +import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService; 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.trade.vo.TradeSummaryRespVO; @@ -68,6 +69,11 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { return TradeStatisticsConvert.INSTANCE.convert(value, reference); } + @Override + public Integer getExpensePrice(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeStatisticsMapper.selectExpensePriceByTimeBetween(beginTime, endTime); + } + @Override public List getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) { return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime); diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java index 521762846..bc4f3903b 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java @@ -13,7 +13,7 @@ public class TradeOrderSummaryRespBO { /** * 创建订单数 */ - private Long orderCreateCount; + private Integer orderCreateCount; /** * 支付订单商品数 */ 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 new file mode 100644 index 000000000..2ef803ac1 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml @@ -0,0 +1,20 @@ + + + + + + + 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 new file mode 100644 index 000000000..decdd78a6 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml index f8553b481..0d585f2a2 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml @@ -1,16 +1,64 @@ - + SELECT receiver_area_id AS areaId, (SELECT COUNT(1) - FROM trade_order - WHERE deleted = FALSE - AND create_time BETWEEN #{beginTime} AND #{endTime}) AS orderPayPrice + FROM trade_order AS s + WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateCount, + (SELECT COUNT(1) + 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, + (SELECT SUM(s.pay_price) + FROM trade_order AS s + WHERE s.receiver_area_id = m.receiver_area_id + AND s.pay_status = TRUE + AND s.deleted = FALSE) AS orderPayPrice + FROM trade_order m + WHERE deleted = FALSE + GROUP BY 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 f01a2eeb8..06f8cf993 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 @@ -1,7 +1,6 @@ - + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml similarity index 69% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml rename to yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml index 7a0dd1e26..e03f490a3 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml @@ -1,6 +1,6 @@ - + + + diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 9761e0e05..0dcc2d4a6 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -167,6 +167,7 @@ logging: cn.iocoder.yudao.module.member.dal.mysql: debug cn.iocoder.yudao.module.trade.dal.mysql: debug cn.iocoder.yudao.module.promotion.dal.mysql: debug + cn.iocoder.yudao.module.statistics.dal.mysql: debug debug: false