code review:交易统计

This commit is contained in:
YunaiV 2023-10-14 13:15:14 +08:00
parent 1ac2f2b5c2
commit 970e524088
15 changed files with 60 additions and 34 deletions

View File

@ -36,9 +36,11 @@ public class TradeStatisticsController {
@Operation(summary = "获得交易统计") @Operation(summary = "获得交易统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')") @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
public CommonResult<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() { public CommonResult<TradeStatisticsComparisonRespVO<TradeSummaryRespVO>> getTradeSummaryComparison() {
// TODO @疯狂这个要不要 tradeStatisticsService 调用里面的多个方法组合出最终的 TradeSummaryRespVO
return success(tradeStatisticsService.getTradeSummaryComparison()); return success(tradeStatisticsService.getTradeSummaryComparison());
} }
// TODO @疯狂晚点再改和讨论等首页的接口出来这个要不还是叫 analyse对比选中的时间段和上一个时间段类似 MemberStatisticsController getMemberAnalyse
@GetMapping("/trend/summary") @GetMapping("/trend/summary")
@Operation(summary = "获得交易状况统计") @Operation(summary = "获得交易状况统计")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')") @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
@ -48,6 +50,8 @@ public class TradeStatisticsController {
ArrayUtil.get(reqVO.getTimes(), 1))); ArrayUtil.get(reqVO.getTimes(), 1)));
} }
// TODO 芋艿已经 review
// TODO @疯狂这个要不直接叫 list它即使就是把每条统计拿出来
@GetMapping("/trend/list") @GetMapping("/trend/list")
@Operation(summary = "获得交易状况明细") @Operation(summary = "获得交易状况明细")
@PreAuthorize("@ss.hasPermission('statistics:trade:query')") @PreAuthorize("@ss.hasPermission('statistics:trade:query')")
@ -57,6 +61,7 @@ public class TradeStatisticsController {
ArrayUtil.get(reqVO.getTimes(), 1))); ArrayUtil.get(reqVO.getTimes(), 1)));
} }
// TODO @疯狂这个要不直接叫 export它即使就是把每条统计导出
@GetMapping("/trend/export-excel") @GetMapping("/trend/export-excel")
@Operation(summary = "导出获得交易状况明细 Excel") @Operation(summary = "导出获得交易状况明细 Excel")
@PreAuthorize("@ss.hasPermission('statistics:trade:export')") @PreAuthorize("@ss.hasPermission('statistics:trade:export')")

View File

@ -16,25 +16,26 @@ public class TradeTrendSummaryRespVO {
@JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY) @JsonFormat(pattern = FORMAT_YEAR_MONTH_DAY)
private LocalDate date; private LocalDate date;
// TODO @疯狂要不加个 turnoverPrice
@Schema(description = "营业额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "营业额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer turnover; private Integer turnover; // 营业额 = 商品支付金额 + 充值金额
@Schema(description = "商品支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "订单支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderPayPrice; private Integer orderPayPrice;
@Schema(description = "订单退款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderRefundPrice;
@Schema(description = "支付佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer brokerageSettlementPrice;
@Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer rechargePrice; private Integer rechargePrice;
@Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer expensePrice; private Integer expensePrice; // 余额支付金额 + 支付佣金金额 + 商品退款金额
@Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") @Schema(description = "余额支付金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer balancePrice; private Integer balancePrice; // TODO @疯狂这个字段要不改成walletPayPrice
@Schema(description = "支付佣金金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer brokerageSettlementPrice;
@Schema(description = "商品退款金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024")
private Integer orderRefundPrice;
} }

View File

@ -48,6 +48,7 @@ public class TradeStatisticsDO extends TenantBaseDO {
* 总支付金额单位 * 总支付金额单位
*/ */
private Integer orderPayPrice; private Integer orderPayPrice;
// TODO @疯狂这个字段改成 walletPayPrice然后挪到 rechargePayCount 前面
/** /**
* 总支付金额余额单位 * 总支付金额余额单位
*/ */

View File

@ -6,6 +6,7 @@ import org.apache.ibatis.annotations.Param;
import java.time.LocalDateTime; import java.time.LocalDateTime;
// TODO @芋艿api 访问日志现在会清理可能要单独有个偏业务的访问表
/** /**
* API 访问日志的统计 Mapper * API 访问日志的统计 Mapper
* *

View File

@ -17,14 +17,17 @@ import java.time.LocalDateTime;
@Mapper @Mapper
public interface PayWalletStatisticsMapper extends BaseMapperX<TradeStatisticsDO> { public interface PayWalletStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
// TODO 芋艿已经 review
WalletSummaryRespBO selectRechargeSummaryByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, WalletSummaryRespBO selectRechargeSummaryByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime, @Param("endTime") LocalDateTime endTime,
@Param("payStatus") Boolean payStatus); @Param("payStatus") Boolean payStatus);
// TODO 芋艿已经 review
WalletSummaryRespBO selectRechargeSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime, WalletSummaryRespBO selectRechargeSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime, @Param("endTime") LocalDateTime endTime,
@Param("refundStatus") Integer refundStatus); @Param("refundStatus") Integer refundStatus);
// TODO 芋艿已经 review
Integer selectPriceSummaryByBizTypeAndCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime, Integer selectPriceSummaryByBizTypeAndCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime, @Param("endTime") LocalDateTime endTime,
@Param("bizType") Integer bizType); @Param("bizType") Integer bizType);

View File

@ -16,6 +16,7 @@ import java.time.LocalDateTime;
@Mapper @Mapper
public interface AfterSaleStatisticsMapper extends BaseMapperX<TradeStatisticsDO> { public interface AfterSaleStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
// TODO 芋艿 review
AfterSaleSummaryRespBO selectSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime, AfterSaleSummaryRespBO selectSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime); @Param("endTime") LocalDateTime endTime);

View File

@ -20,9 +20,11 @@ public interface TradeOrderStatisticsMapper extends BaseMapperX<TradeStatisticsD
// TODO 芋艿已经 review // TODO 芋艿已经 review
List<MemberAreaStatisticsRespVO> selectSummaryListByAreaId(); List<MemberAreaStatisticsRespVO> selectSummaryListByAreaId();
// TODO 芋艿已经 review
Integer selectCountByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime, Integer selectCountByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime); @Param("endTime") LocalDateTime endTime);
// TODO 芋艿已经 review
Integer selectCountByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, Integer selectCountByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime); @Param("endTime") LocalDateTime endTime);

View File

@ -24,6 +24,7 @@ public interface TradeStatisticsMapper extends BaseMapperX<TradeStatisticsDO> {
TradeTrendSummaryRespVO selectByTimeBetween(@Param("beginTime") LocalDateTime beginTime, TradeTrendSummaryRespVO selectByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime); @Param("endTime") LocalDateTime endTime);
// TODO @芋艿已经 review
List<TradeTrendSummaryRespVO> selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime, List<TradeTrendSummaryRespVO> selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime); @Param("endTime") LocalDateTime endTime);

View File

@ -12,6 +12,7 @@ import java.time.LocalDateTime;
*/ */
public interface PayWalletStatisticsService { public interface PayWalletStatisticsService {
// TODO 芋艿已经 review
/** /**
* 获取钱包统计 * 获取钱包统计
* *
@ -21,6 +22,7 @@ public interface PayWalletStatisticsService {
*/ */
WalletSummaryRespBO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime); WalletSummaryRespBO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/** /**
* 获取钱包充值统计 * 获取钱包充值统计
* *

View File

@ -11,6 +11,7 @@ import java.time.LocalDateTime;
*/ */
public interface AfterSaleStatisticsService { public interface AfterSaleStatisticsService {
// TODO 芋艿已经 review
/** /**
* 获取售后单统计 * 获取售后单统计
* *

View File

@ -9,6 +9,7 @@ import java.time.LocalDateTime;
*/ */
public interface BrokerageStatisticsService { public interface BrokerageStatisticsService {
// TODO 芋艿已经 review
/** /**
* 获取已结算的佣金金额 * 获取已结算的佣金金额
* *

View File

@ -45,6 +45,7 @@ public interface TradeStatisticsService {
*/ */
List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime); List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime);
// TODO 芋艿已经 review
/** /**
* 统计昨日交易 * 统计昨日交易
* *

View File

@ -57,6 +57,30 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData); return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData);
} }
/**
* 统计指定日期的交易数据
*
* @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 monthDate = LocalDateTime.now().plusMonths(months);
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(
LocalDateTimeUtils.beginOfMonth(monthDate), LocalDateTimeUtils.endOfMonth(monthDate));
}
@Override @Override
public TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime, public TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> getTradeTrendSummaryComparison(LocalDateTime beginTime,
LocalDateTime endTime) { LocalDateTime endTime) {
@ -73,6 +97,7 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
return tradeStatisticsMapper.selectExpensePriceByTimeBetween(beginTime, endTime); return tradeStatisticsMapper.selectExpensePriceByTimeBetween(beginTime, endTime);
} }
// TODO @疯狂是不是直接返回 TradeStatisticsDO上层在去聚合
@Override @Override
public List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) { public List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) {
return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime); return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime);
@ -80,6 +105,9 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
@Override @Override
public String statisticsYesterdayTrade() { public String statisticsYesterdayTrade() {
// TODO @疯狂如果已经统计则跳过
// TODO @疯狂改成 statisticsTrade然后传入 days统计多少天days 通过 job 传参方便把历史给统计出来或者大家有的时候要修复数据 fix 业务数据然后清理统计表重新统计的时候
// 1. 从各个数据表统计对应数据
LocalDateTime yesterday = LocalDateTime.now().minusDays(1); LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
@ -108,28 +136,4 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
return stopWatch.prettyPrint(); return stopWatch.prettyPrint();
} }
/**
* 统计指定日期的交易数据
*
* @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 monthDate = LocalDateTime.now().plusMonths(months);
return tradeStatisticsMapper.selectOrderCreateCountSumAndOrderPayPriceSumByTimeBetween(
LocalDateTimeUtils.beginOfMonth(monthDate), LocalDateTimeUtils.endOfMonth(monthDate));
}
} }

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <!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.pay.PayWalletStatisticsMapper"> <mapper namespace="cn.iocoder.yudao.module.statistics.dal.mysql.pay.PayWalletStatisticsMapper">
<select id="selectRechargeSummaryByPayTimeBetween" <select id="selectRechargeSummaryByPayTimeBetween"
resultType="cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO"> resultType="cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO">
SELECT COUNT(1) AS rechargePayCount, SELECT COUNT(1) AS rechargePayCount,

View File

@ -43,6 +43,7 @@
FROM trade_statistics FROM trade_statistics
WHERE time BETWEEN #{beginTime} AND #{endTime} WHERE time BETWEEN #{beginTime} AND #{endTime}
AND deleted = FALSE AND deleted = FALSE
<!-- TODO @疯狂:已经不用 group by它就是每天统计一条 -->
GROUP BY date GROUP BY date
</select> </select>