统计:交易统计

This commit is contained in:
owen 2023-09-29 21:08:15 +08:00
parent b2c608e7a5
commit 171161e6c7
17 changed files with 534 additions and 41 deletions

43
sql/mysql/statistics.sql Normal file
View File

@ -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);

View File

@ -49,6 +49,10 @@
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-operatelog</artifactId>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-spring-boot-starter-biz-tenant</artifactId>
</dependency>
<!-- Web 相关 -->
<dependency>

View File

@ -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<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() {
return success(tradeStatisticsService.getTradeSummaryComparison());
}
@GetMapping("/trend/summary")
@Operation(summary = "获得交易状况统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO>> 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<List<TradeTrendSummaryRespVO>> 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<TradeTrendSummaryRespVO> list = tradeStatisticsService.getTradeStatisticsList(ArrayUtil.get(reqVO.getTimes(), 0),
ArrayUtil.get(reqVO.getTimes(), 1));
// 导出 Excel
List<TradeTrendSummaryExcelVO> data = TradeStatisticsConvert.INSTANCE.convertList02(list);
ExcelUtils.write(response, "交易状况.xls", "数据", TradeTrendSummaryExcelVO.class, data);
}
}

View File

@ -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<T> {
@Schema(description = "当前数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private T value;
@Schema(description = "参照数据", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private T reference;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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<Object> getTradeStatisticsComparison() {
return null;
}
// TODO @疯狂查询指定时间范围内的交易统计数据DO 到时需要改成 VO
// 总收入营业额= 订单充值的支付 - 订单充值的退款
public CommonResult<List<TradeStatisticsDO>> getTradeStatisticsList(
LocalDateTime[] times) {
return null;
}
}

View File

@ -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<TradeSummaryRespVO> 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<TradeSummaryRespVO> convert(TradeSummaryRespVO value, TradeSummaryRespVO reference);
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value, TradeTrendSummaryRespVO reference);
List<TradeTrendSummaryExcelVO> convertList02(List<TradeTrendSummaryRespVO> list);
}

View File

@ -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
*
* <p>
* 以天为维度统计全部的数据
*
* @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 {
/**
* 充值订单数
*
* <p>
* PayWalletRechargeDO 计算
*/
private Integer rechargePayCount;

View File

@ -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<TradeStatisticsDO> {
@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<TradeTrendSummaryRespVO> selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
}

View File

@ -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<TradeSummaryRespVO> getTradeSummaryComparison();
/**
* 获得交易状况统计
*
* @return 统计数据对照
*/
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime, LocalDateTime endTime);
/**
* 获得交易状况明细
*
* @return 统计数据列表
*/
List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -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<TradeSummaryRespVO> 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<TradeTrendSummaryRespVO> 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<TradeTrendSummaryRespVO> 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);
}
}

View File

@ -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;
}

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsMapper">
<select id="selectByTimeBetween"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO">
SELECT
-- 营业额 = 商品支付金额 + 充值金额
SUM(order_pay_price + recharge_pay_price) AS turnover,
SUM(order_pay_price) AS orderPayPrice,
SUM(recharge_pay_price) AS rechargePrice,
-- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice,
SUM(order_wallet_pay_price) AS balancePrice,
SUM(brokerage_settlement_price) AS brokerageSettlementPrice,
SUM(after_sale_refund_price) AS orderRefundPrice
FROM trade_statistics
WHERE time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
</select>
<select id="selectListByTimeBetween"
resultType="cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeTrendSummaryRespVO">
SELECT DATE_FORMAT(time, '%Y-%m-%d') AS date,
-- 营业额 = 商品支付金额 + 充值金额
SUM(order_pay_price + recharge_pay_price) AS turnover,
SUM(order_pay_price) AS orderPayPrice,
SUM(recharge_pay_price) AS rechargePrice,
-- 支出金额 = 余额支付金额 + 支付佣金金额 + 商品退款金额
SUM(order_wallet_pay_price + brokerage_settlement_price + after_sale_refund_price) AS expensePrice,
SUM(order_wallet_pay_price) AS balancePrice,
SUM(brokerage_settlement_price) AS brokerageSettlementPrice,
SUM(after_sale_refund_price) AS orderRefundPrice
FROM trade_statistics
WHERE time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE
GROUP BY date
</select>
</mapper>

View File

@ -83,6 +83,11 @@
<artifactId>yudao-module-trade-biz</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-statistics-biz</artifactId>
<version>${revision}</version>
</dependency>
<!-- spring boot 配置所需依赖 -->
<dependency>