From 171161e6c7fbcbf0a8ff9291cce62901966ed547 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 29 Sep 2023 21:08:15 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=EF=BC=9A=E4=BA=A4=E6=98=93?= =?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 | 43 +++++++++ .../yudao-module-statistics-biz/pom.xml | 4 + .../trade/TradeStatisticsController.java | 71 ++++++++++++++ .../vo/TradeStatisticsComparisonRespVO.java | 20 ++++ .../admin/trade/vo/TradeSummaryRespVO.java | 18 ++++ .../admin/trade/vo/TradeTrendReqVO.java | 18 ++++ .../trade/vo/TradeTrendSummaryExcelVO.java | 44 +++++++++ .../trade/vo/TradeTrendSummaryRespVO.java | 39 ++++++++ .../trade/TradeStatisticsController.java | 36 ------- .../convert/trade/TradeStatisticsConvert.java | 42 ++++++++ .../trade/TradeStatisticsDO.java | 10 +- .../mysql/trade/TradeStatisticsMapper.java | 33 +++++++ .../service/trade/TradeStatisticsService.java | 37 ++++++++ .../trade/TradeStatisticsServiceImpl.java | 95 +++++++++++++++++++ .../service/trade/bo/TradeSummaryRespBO.java | 22 +++++ .../mapper/trade/TradeStatisticsMapper.xml | 38 ++++++++ yudao-server/pom.xml | 5 + 17 files changed, 534 insertions(+), 41 deletions(-) create mode 100644 sql/mysql/statistics.sql create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeStatisticsComparisonRespVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeSummaryRespVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendReqVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryExcelVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryRespVO.java delete mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/trade/TradeStatisticsController.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/trade/TradeStatisticsConvert.java rename yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/{mysql => dataobject}/trade/TradeStatisticsDO.java (90%) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeSummaryRespBO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml diff --git a/sql/mysql/statistics.sql b/sql/mysql/statistics.sql new file mode 100644 index 000000000..48f1c4ad4 --- /dev/null +++ b/sql/mysql/statistics.sql @@ -0,0 +1,43 @@ +-- 交易统计表 +CREATE TABLE trade_statistics +( + id bigint AUTO_INCREMENT COMMENT '编号,主键自增' + PRIMARY KEY, + time datetime NOT NULL COMMENT '统计日期', + order_create_count int DEFAULT 0 NOT NULL COMMENT '创建订单数', + order_pay_count int DEFAULT 0 NOT NULL COMMENT '支付订单商品数', + order_pay_price int DEFAULT 0 NOT NULL COMMENT '总支付金额,单位:分', + order_wallet_pay_price int DEFAULT 0 NOT NULL COMMENT '总支付金额(余额),单位:分', + after_sale_count int DEFAULT 0 NOT NULL COMMENT '退款订单数', + after_sale_refund_price int DEFAULT 0 NOT NULL COMMENT '总退款金额,单位:分', + brokerage_settlement_price int DEFAULT 0 NOT NULL COMMENT '佣金金额(已结算),单位:分', + recharge_pay_count int DEFAULT 0 NOT NULL COMMENT '充值订单数', + recharge_pay_price int DEFAULT 0 NOT NULL COMMENT '充值金额,单位:分', + recharge_refund_count int DEFAULT 0 NOT NULL COMMENT '充值退款订单数', + recharge_refund_price int DEFAULT 0 NOT NULL COMMENT '充值退款金额,单位:分', + creator varchar(64) DEFAULT '' NULL COMMENT '创建者', + create_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL COMMENT '创建时间', + updater varchar(64) DEFAULT '' NULL COMMENT '更新者', + update_time datetime DEFAULT CURRENT_TIMESTAMP NOT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', + deleted bit DEFAULT b'0' NOT NULL COMMENT '是否删除', + tenant_id bigint DEFAULT 0 NOT NULL COMMENT '租户编号' +) + COMMENT '交易统计表'; + +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) +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'); +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); + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/pom.xml b/yudao-module-mall/yudao-module-statistics-biz/pom.xml index 8bd75c39a..3a0343664 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/pom.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/pom.xml @@ -49,6 +49,10 @@ cn.iocoder.boot yudao-spring-boot-starter-biz-operatelog + + cn.iocoder.boot + yudao-spring-boot-starter-biz-tenant + 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 new file mode 100644 index 000000000..aa5b711cb --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/TradeStatisticsController.java @@ -0,0 +1,71 @@ +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.trade.vo.*; +import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert; +import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService; +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 javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; + +@Tag(name = "管理后台 - 交易统计") +@RestController +@RequestMapping("/statistics/trade") +@Validated +@Slf4j +public class TradeStatisticsController { + + @Resource + private TradeStatisticsService tradeStatisticsService; + + @GetMapping("/summary") + @Operation(summary = "获得交易统计") + @PreAuthorize("@ss.hasPermission('statistics:trade:query')") + public CommonResult> getTradeSummaryComparison() { + return success(tradeStatisticsService.getTradeSummaryComparison()); + } + + @GetMapping("/trend/summary") + @Operation(summary = "获得交易状况统计") + @PreAuthorize("@ss.hasPermission('statistics:trade:query')") + public CommonResult> getTradeTrendSummaryComparison( + TradeTrendReqVO reqVO) { + return success(tradeStatisticsService.getTradeTrendSummaryComparison(ArrayUtil.get(reqVO.getTimes(), 0), + ArrayUtil.get(reqVO.getTimes(), 1))); + } + + @GetMapping("/trend/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))); + } + + @GetMapping("/trend/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), + ArrayUtil.get(reqVO.getTimes(), 1)); + // 导出 Excel + List data = TradeStatisticsConvert.INSTANCE.convertList02(list); + ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data); + } + +} 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/trade/vo/TradeStatisticsComparisonRespVO.java new file mode 100644 index 000000000..d8bd29dc6 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeStatisticsComparisonRespVO.java @@ -0,0 +1,20 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +@Schema(description = "管理后台 - 交易统计对照 Response VO") +@Data +@NoArgsConstructor +@AllArgsConstructor +public class TradeStatisticsComparisonRespVO { + + @Schema(description = "当前数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private T value; + + @Schema(description = "参照数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private T reference; + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeSummaryRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeSummaryRespVO.java new file mode 100644 index 000000000..d59461b35 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeSummaryRespVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 交易统计 Response VO") +@Data +public class TradeSummaryRespVO { + @Schema(description = "昨日订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer yesterdayOrderCount; + @Schema(description = "昨日支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer yesterdayPayPrice; + + @Schema(description = "本月订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer monthOrderCount; + @Schema(description = "本月支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer monthPayPrice; +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendReqVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendReqVO.java new file mode 100644 index 000000000..234b7a785 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendReqVO.java @@ -0,0 +1,18 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.trade.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 TradeTrendReqVO { + + @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/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 new file mode 100644 index 000000000..3253df07d --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryExcelVO.java @@ -0,0 +1,44 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; + +import cn.iocoder.yudao.framework.excel.core.convert.MoneyConvert; +import com.alibaba.excel.annotation.ExcelProperty; +import com.alibaba.excel.annotation.format.DateTimeFormat; +import lombok.Data; + +import java.time.LocalDate; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; + +/** + * 交易状况统计 Excel VO + * + * @author owen + */ +@Data +public class TradeTrendSummaryExcelVO { + + @ExcelProperty(value = "日期") + @DateTimeFormat(FORMAT_YEAR_MONTH_DAY) + private LocalDate date; + + @ExcelProperty(value = "营业额", converter = MoneyConvert.class) + private Integer turnover; + + @ExcelProperty(value = "商品支付金额", converter = MoneyConvert.class) + private Integer orderPayPrice; + + @ExcelProperty(value = "充值金额", converter = MoneyConvert.class) + private Integer rechargePrice; + + @ExcelProperty(value = "支出金额", converter = MoneyConvert.class) + private Integer expensePrice; + + @ExcelProperty(value = "余额支付金额", converter = MoneyConvert.class) + private Integer balancePrice; + + @ExcelProperty(value = "支付佣金金额", converter = MoneyConvert.class) + private Integer brokerageSettlementPrice; + + @ExcelProperty(value = "商品退款金额", converter = MoneyConvert.class) + private Integer orderRefundPrice; +} 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 new file mode 100644 index 000000000..6830a0eb4 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/trade/vo/TradeTrendSummaryRespVO.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.trade.vo; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +import java.time.LocalDate; + +import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY; + +@Schema(description = "管理后台 - 交易状况统计 Response VO") +@Data +public class TradeTrendSummaryRespVO { + + @Schema(description = "日期", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY) + private LocalDate date; + + @Schema(description = "营业额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer turnover; + + @Schema(description = "商品支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer orderPayPrice; + + @Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer rechargePrice; + + @Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer expensePrice; + + @Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer balancePrice; + + @Schema(description = "支付佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer brokerageSettlementPrice; + + @Schema(description = "商品退款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer orderRefundPrice; +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/trade/TradeStatisticsController.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/trade/TradeStatisticsController.java deleted file mode 100644 index ee241611d..000000000 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/trade/TradeStatisticsController.java +++ /dev/null @@ -1,36 +0,0 @@ -package cn.iocoder.yudao.module.statistics.controller.trade; - -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsDO; -import io.swagger.v3.oas.annotations.tags.Tag; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import java.time.LocalDateTime; -import java.util.List; - -@Tag(name = "管理后台 - 交易统计") -@RestController -@RequestMapping("/statistics/product") -@Validated -@Slf4j -public class TradeStatisticsController { - - // TODO @疯狂:有个 summary 接口,返回昨日、本月、支付金额、本月订单金额等数据;具体看 ui 哈; - - // TODO @疯狂:返回 ProductStatisticsComparisonResp, 里面有两个字段,一个是选择的时间范围的合计结果,一个是对比的时间范围的合计结果; - // 例如说,选择时间范围是 2023-10-01 ~ 2023-10-02,那么对比就是 2023-09-30,再倒推 2 天; - public CommonResult getTradeStatisticsComparison() { - return null; - } - - // TODO @疯狂:查询指定时间范围内的交易统计数据;DO 到时需要改成 VO 哈 - // 总收入(营业额)= 订单、充值的支付 - 订单、充值的退款 - public CommonResult> getTradeStatisticsList( - LocalDateTime[] times) { - return null; - } - -} 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 new file mode 100644 index 000000000..9ce4b901a --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/trade/TradeStatisticsConvert.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.statistics.convert.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.trade.vo.TradeTrendSummaryExcelVO; +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; + +/** + * 交易统计 Convert + * + * @author owen + */ +@Mapper +public interface TradeStatisticsConvert { + + TradeStatisticsConvert INSTANCE = Mappers.getMapper(TradeStatisticsConvert.class); + + default TradeStatisticsComparisonRespVO convert(TradeSummaryRespBO yesterdayData, + TradeSummaryRespBO beforeYesterdayData, + TradeSummaryRespBO monthData, + TradeSummaryRespBO lastMonthData) { + return convert(convert(yesterdayData, monthData), convert(beforeYesterdayData, lastMonthData)); + } + + + default TradeSummaryRespVO convert(TradeSummaryRespBO yesterdayData, TradeSummaryRespBO monthData) { + return new TradeSummaryRespVO() + .setYesterdayOrderCount(yesterdayData.getCount()).setYesterdayPayPrice(yesterdayData.getSummary()) + .setMonthOrderCount(monthData.getCount()).setMonthPayPrice(monthData.getSummary()); + } + + TradeStatisticsComparisonRespVO convert(TradeSummaryRespVO value, TradeSummaryRespVO reference); + + TradeStatisticsComparisonRespVO convert(TradeTrendSummaryRespVO value, TradeTrendSummaryRespVO reference); + + List convertList02(List list); +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsDO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java similarity index 90% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsDO.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java index 1db6c1063..f2ab1a63d 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsDO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/dataobject/trade/TradeStatisticsDO.java @@ -1,6 +1,6 @@ -package cn.iocoder.yudao.module.statistics.dal.mysql.trade; +package cn.iocoder.yudao.module.statistics.dal.dataobject.trade; -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; +import cn.iocoder.yudao.framework.tenant.core.db.TenantBaseDO; import com.baomidou.mybatisplus.annotation.KeySequence; import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableName; @@ -10,7 +10,7 @@ import java.time.LocalDateTime; /** * 交易统计 DO - * + *

* 以天为维度,统计全部的数据 * * @author 芋道源码 @@ -23,7 +23,7 @@ import java.time.LocalDateTime; @Builder @NoArgsConstructor @AllArgsConstructor -public class TradeStatisticsDO extends BaseDO { +public class TradeStatisticsDO extends TenantBaseDO { /** * 编号,主键自增 @@ -69,7 +69,7 @@ public class TradeStatisticsDO extends BaseDO { /** * 充值订单数 - * + *

* 从 PayWalletRechargeDO 计算 */ private Integer rechargePayCount; 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 new file mode 100644 index 000000000..c1760fe30 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeStatisticsMapper.java @@ -0,0 +1,33 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.trade; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +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 org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; +import org.apache.ibatis.annotations.Select; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 交易统计 Mapper + * + * @author owen + */ +@Mapper +public interface TradeStatisticsMapper extends BaseMapperX { + + @Select("SELECT IFNULL(SUM(order_create_count), 0) AS count, IFNULL(SUM(order_pay_price), 0) AS summary " + + "FROM trade_statistics " + + "WHERE time BETWEEN #{beginTime} AND #{endTime} AND deleted = FALSE") + TradeSummaryRespBO selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + TradeTrendSummaryRespVO selectByTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + List selectListByTimeBetween(@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/trade/TradeStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java new file mode 100644 index 000000000..cb28042d6 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsService.java @@ -0,0 +1,37 @@ +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.trade.vo.TradeTrendSummaryRespVO; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 交易统计 Service 接口 + * + * @author owen + */ +public interface TradeStatisticsService { + + /** + * 获得交易统计 + * + * @return 统计数据对照 + */ + TradeStatisticsComparisonRespVO getTradeSummaryComparison(); + + /** + * 获得交易状况统计 + * + * @return 统计数据对照 + */ + TradeStatisticsComparisonRespVO getTradeTrendSummaryComparison(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获得交易状况明细 + * + * @return 统计数据列表 + */ + List getTradeStatisticsList(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 new file mode 100644 index 000000000..60b2a1918 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeStatisticsServiceImpl.java @@ -0,0 +1,95 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.hutool.core.date.LocalDateTimeUtil; +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.trade.vo.TradeTrendSummaryRespVO; +import cn.iocoder.yudao.module.statistics.convert.trade.TradeStatisticsConvert; +import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsMapper; +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO; +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.time.LocalTime; +import java.time.temporal.TemporalAdjusters; +import java.util.List; + +/** + * 交易统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class TradeStatisticsServiceImpl implements TradeStatisticsService { + + @Resource + private TradeStatisticsMapper tradeStatisticsMapper; + + @Override + public TradeStatisticsComparisonRespVO getTradeSummaryComparison() { + // 昨天的数据 + TradeSummaryRespBO yesterdayData = getTradeSummaryByDays(-1); + // 前天的数据(用于对照昨天的数据) + TradeSummaryRespBO beforeYesterdayData = getTradeSummaryByDays(-2); + + // 本月数据; + TradeSummaryRespBO monthData = getTradeSummaryByMonths(0); + // 上月数据(用于对照本月的数据) + TradeSummaryRespBO lastMonthData = getTradeSummaryByMonths(-1); + + return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData); + } + + @Override + public TradeStatisticsComparisonRespVO getTradeTrendSummaryComparison(LocalDateTime beginTime, + LocalDateTime endTime) { + // 统计数据 + TradeTrendSummaryRespVO value = tradeStatisticsMapper.selectByTimeBetween(beginTime, endTime); + // 对照数据 + LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime)); + TradeTrendSummaryRespVO reference = tradeStatisticsMapper.selectByTimeBetween(referenceBeginTime, beginTime); + return TradeStatisticsConvert.INSTANCE.convert(value, reference); + } + + @Override + public List getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime); + } + + /** + * 统计指定日期的交易数据 + * + * @param days 增加的天数 + * @return 交易数据 + */ + private 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) { + // 月份开始时间 + LocalDateTime beginOfMonth = LocalDateTime.now() + .plusMonths(months) + .with(TemporalAdjusters.firstDayOfMonth()) + .with(LocalTime.MIN); + // 月份截止时间 + LocalDateTime endOfToday = LocalDateTime.now() + .plusMonths(months) + .with(TemporalAdjusters.lastDayOfMonth()) + .with(LocalTime.MAX); + return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(beginOfMonth, endOfToday); + } + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeSummaryRespBO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeSummaryRespBO.java new file mode 100644 index 000000000..10888e482 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeSummaryRespBO.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.statistics.service.trade.bo; + +import lombok.Data; + +/** + * 交易统计 Resp BO + * + * @author owen + */ +@Data +public class TradeSummaryRespBO { + + /** + * 数量 + */ + private Integer count; + + /** + * 合计 + */ + private Integer summary; +} 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 new file mode 100644 index 000000000..1d9776a33 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeStatisticsMapper.xml @@ -0,0 +1,38 @@ + + + + + + + diff --git a/yudao-server/pom.xml b/yudao-server/pom.xml index a20f27098..3659d4131 100644 --- a/yudao-server/pom.xml +++ b/yudao-server/pom.xml @@ -83,6 +83,11 @@ yudao-module-trade-biz ${revision} + + cn.iocoder.boot + yudao-module-statistics-biz + ${revision} +