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}