统计:交易统计定时任务

This commit is contained in:
owen 2023-10-03 21:21:11 +08:00
parent df4716d5a1
commit a9e822762d
33 changed files with 563 additions and 24 deletions

View File

@ -43,6 +43,11 @@
<artifactId>yudao-module-member-api</artifactId>
<version>${revision}</version>
</dependency>
<dependency>
<groupId>cn.iocoder.boot</groupId>
<artifactId>yudao-module-pay-api</artifactId>
<version>${revision}</version>
</dependency>
<!-- 业务组件 -->
<dependency>

View File

@ -1,13 +1,18 @@
package cn.iocoder.yudao.module.statistics.convert.trade;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
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.dal.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;
import java.time.LocalDateTime;
import java.util.List;
/**
@ -36,7 +41,13 @@ public interface TradeStatisticsConvert {
TradeStatisticsComparisonRespVO<TradeSummaryRespVO> convert(TradeSummaryRespVO value, TradeSummaryRespVO reference);
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value, TradeTrendSummaryRespVO reference);
TradeStatisticsComparisonRespVO<TradeTrendSummaryRespVO> convert(TradeTrendSummaryRespVO value,
TradeTrendSummaryRespVO reference);
List<TradeTrendSummaryExcelVO> convertList02(List<TradeTrendSummaryRespVO> list);
TradeStatisticsDO convert(LocalDateTime time, TradeOrderSummaryRespDTO orderSummary,
AfterSaleSummaryRespDTO afterSaleSummary, Integer brokerageSettlementPrice,
WalletSummaryRespDTO walletSummary);
}

View File

@ -0,0 +1,29 @@
package cn.iocoder.yudao.module.statistics.job.trade;
import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler;
import cn.iocoder.yudao.framework.tenant.core.job.TenantJob;
import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService;
import org.springframework.stereotype.Component;
import javax.annotation.Resource;
/**
* 交易统计 Job
*
* @author owen
*/
@Component
public class TradeStatisticsJob implements JobHandler {
@Resource
private TradeStatisticsService tradeStatisticsService;
@Override
@TenantJob
public String execute(String param) {
String times = tradeStatisticsService.statisticsYesterdayTrade();
return StrUtil.format("交易统计耗时: {}", times);
}
}

View File

@ -36,4 +36,11 @@ public interface TradeStatisticsService {
*/
List<TradeTrendSummaryRespVO> getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime);
/**
* 统计昨日交易
*
* @return 耗时
*/
String statisticsYesterdayTrade();
}

View File

@ -2,13 +2,22 @@ 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.pay.api.wallet.PayWalletApi;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
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.dataobject.trade.TradeStatisticsDO;
import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeStatisticsMapper;
import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeSummaryRespBO;
import cn.iocoder.yudao.module.trade.api.aftersale.TradeAfterSaleApi;
import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO;
import cn.iocoder.yudao.module.trade.api.brokerage.TradeBrokerageApi;
import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import org.springframework.stereotype.Service;
import org.springframework.util.StopWatch;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
@ -28,6 +37,15 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
@Resource
private TradeStatisticsMapper tradeStatisticsMapper;
@Resource
private TradeOrderApi tradeOrderApi;
@Resource
private TradeAfterSaleApi tradeAfterSaleApi;
@Resource
private TradeBrokerageApi tradeBrokerageApi;
@Resource
private PayWalletApi payWalletApi;
@Override
public TradeStatisticsComparisonRespVO<TradeSummaryRespVO> getTradeSummaryComparison() {
// 昨天的数据
@ -59,6 +77,36 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService {
return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime);
}
@Override
public String statisticsYesterdayTrade() {
// 处理统计参数
LocalDateTime yesterday = LocalDateTime.now().minusDays(1);
LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday);
LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday);
// 统计
StopWatch stopWatch = new StopWatch("交易统计");
stopWatch.start("统计订单");
TradeOrderSummaryRespDTO orderSummary = tradeOrderApi.getOrderSummary(beginTime, endTime);
stopWatch.stop();
stopWatch.start("统计售后");
AfterSaleSummaryRespDTO afterSaleSummary = tradeAfterSaleApi.getAfterSaleSummary(beginTime, endTime);
stopWatch.stop();
stopWatch.start("统计佣金");
Integer brokerageSettlementPrice = tradeBrokerageApi.getBrokerageSettlementPriceSummary(beginTime, endTime);
stopWatch.stop();
stopWatch.start("统计充值");
WalletSummaryRespDTO walletSummary = payWalletApi.getWalletSummary(beginTime, endTime);
stopWatch.stop();
// 插入数据
TradeStatisticsDO entity = TradeStatisticsConvert.INSTANCE.convert(yesterday, orderSummary, afterSaleSummary, brokerageSettlementPrice, walletSummary);
tradeStatisticsMapper.insert(entity);
// 返回计时结果
return stopWatch.prettyPrint();
}
/**
* 统计指定日期的交易数据
*

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.trade.api.aftersale;
import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO;
import java.time.LocalDateTime;
/**
* 售后 API 接口
*
* @author owen
*/
public interface TradeAfterSaleApi {
/**
* 获取售后单统计
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 售后统计结果
*/
AfterSaleSummaryRespDTO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -0,0 +1,22 @@
package cn.iocoder.yudao.module.trade.api.aftersale.dto;
import lombok.Data;
/**
* 售后统计 Response DTO
*
* @author owen
*/
@Data
public class AfterSaleSummaryRespDTO {
/**
* 退款订单数
*/
private Integer afterSaleCount;
/**
* 总退款金额单位
*/
private Integer afterSaleRefundPrice;
}

View File

@ -0,0 +1,21 @@
package cn.iocoder.yudao.module.trade.api.brokerage;
import java.time.LocalDateTime;
/**
* 分销 API 接口
*
* @author owen
*/
public interface TradeBrokerageApi {
/**
* 获取已结算的佣金金额
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 已结算的佣金金额
*/
Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -1,5 +1,9 @@
package cn.iocoder.yudao.module.trade.api.order;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import java.time.LocalDateTime;
/**
* 订单 API 接口
*
@ -15,4 +19,13 @@ public interface TradeOrderApi {
*/
Integer getOrderStatus(Long id);
/**
* 获取订单统计
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 订单统计结果
*/
TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -0,0 +1,26 @@
package cn.iocoder.yudao.module.trade.api.order.dto;
import lombok.Data;
/**
* 订单统计 Response DTO
*
* @author owen
*/
@Data
public class TradeOrderSummaryRespDTO {
/**
* 创建订单数
*/
private Long orderCreateCount;
/**
* 支付订单商品数
*/
private Integer orderPayCount;
/**
* 总支付金额单位
*/
private Integer orderPayPrice;
}

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.trade.api.aftersale;
import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO;
import cn.iocoder.yudao.module.trade.service.aftersale.AfterSaleService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
/**
* 售后 API 接口实现类
*
* @author owen
*/
@Service
@Validated
public class TradeAfterSaleApiImpl implements TradeAfterSaleApi {
@Resource
private AfterSaleService afterSaleService;
@Override
public AfterSaleSummaryRespDTO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime) {
return afterSaleService.getAfterSaleSummary(beginTime, endTime);
}
}

View File

@ -0,0 +1,27 @@
package cn.iocoder.yudao.module.trade.api.brokerage;
import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
/**
* 订单 API 接口实现类
*
* @author HUIHUI
*/
@Service
@Validated
public class TradeBrokerageApiImpl implements TradeBrokerageApi {
@Resource
private BrokerageRecordService brokerageRecordService;
@Override
public Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime) {
return brokerageRecordService.getBrokerageSettlementPriceSummary(beginTime, endTime);
}
}

View File

@ -1,5 +1,6 @@
package cn.iocoder.yudao.module.trade.api.order;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService;
import org.springframework.stereotype.Service;
@ -7,6 +8,8 @@ import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND;
@ -31,4 +34,9 @@ public class TradeOrderApiImpl implements TradeOrderApi {
return order.getStatus();
}
@Override
public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) {
return tradeOrderQueryService.getOrderSummary(beginTime, endTime);
}
}

View File

@ -1,14 +1,19 @@
package cn.iocoder.yudao.module.trade.dal.mysql.aftersale;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.yulichang.toolkit.MPJWrappers;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.Collection;
@Mapper
@ -48,4 +53,12 @@ public interface AfterSaleMapper extends BaseMapperX<AfterSaleDO> {
.in(AfterSaleDO::getStatus, statuses));
}
default AfterSaleSummaryRespDTO selectSummaryByRefundTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return BeanUtil.copyProperties(CollUtil.get(selectMaps(MPJWrappers.<AfterSaleDO>lambdaJoin()
.selectCount(AfterSaleDO::getId, AfterSaleSummaryRespDTO::getAfterSaleCount)
.selectSum(AfterSaleDO::getRefundPrice, AfterSaleSummaryRespDTO::getAfterSaleRefundPrice)
.between(AfterSaleDO::getRefundTime, beginTime, endTime)), 0),
AfterSaleSummaryRespDTO.class);
}
}

View File

@ -1,6 +1,8 @@
package cn.iocoder.yudao.module.trade.dal.mysql.brokerage;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.convert.Convert;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
@ -108,4 +110,14 @@ public interface BrokerageRecordMapper extends BaseMapperX<BrokerageRecordDO> {
@Param("status") Integer status,
@Param("beginTime") LocalDateTime beginTime,
@Param("endTime") LocalDateTime endTime);
default Integer selectSummaryPriceByStatusAndUnfreezeTimeBetween(Integer bizType, Integer status,
LocalDateTime beginTime, LocalDateTime endTime) {
return Convert.toInt(CollUtil.getFirst(selectObjs(MPJWrappers.<BrokerageRecordDO>lambdaJoin()
.selectSum(BrokerageRecordDO::getPrice)
.eq(BrokerageRecordDO::getBizType, bizType)
.eq(BrokerageRecordDO::getStatus, status)
.between(BrokerageRecordDO::getUnfreezeTime, beginTime, endTime))), 0);
}
}

View File

@ -1,12 +1,16 @@
package cn.iocoder.yudao.module.trade.dal.mysql.order;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.github.yulichang.toolkit.MPJWrappers;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
@ -82,4 +86,17 @@ public interface TradeOrderMapper extends BaseMapperX<TradeOrderDO> {
.eq(TradeOrderDO::getCommentStatus, commentStatus));
}
default TradeOrderSummaryRespDTO selectSummaryByPayTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return BeanUtil.copyProperties(CollUtil.get(selectMaps(MPJWrappers.<TradeOrderDO>lambdaJoin()
.selectCount(TradeOrderDO::getId, TradeOrderSummaryRespDTO::getOrderPayCount)
.selectSum(TradeOrderDO::getPayPrice, TradeOrderSummaryRespDTO::getOrderPayPrice)
.between(TradeOrderDO::getPayTime, beginTime, endTime)), 0),
TradeOrderSummaryRespDTO.class);
}
default Long selectCountByCreateTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return selectCount(new LambdaQueryWrapperX<TradeOrderDO>()
.between(TradeOrderDO::getCreateTime, beginTime, endTime));
}
}

View File

@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.trade.service.aftersale;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleDisagreeReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
@ -9,6 +10,8 @@ import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleCre
import cn.iocoder.yudao.module.trade.controller.app.aftersale.vo.AppAfterSaleDeliveryReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO;
import java.time.LocalDateTime;
/**
* 售后订单 Service 接口
*
@ -124,4 +127,13 @@ public interface AfterSaleService {
*/
Long getApplyingAfterSaleCount(Long userId);
/**
* 获取售后单统计
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 售后统计结果
*/
AfterSaleSummaryRespDTO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.util.object.ObjectUtils;
import cn.iocoder.yudao.module.pay.api.refund.PayRefundApi;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleDisagreeReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSalePageReqVO;
import cn.iocoder.yudao.module.trade.controller.admin.aftersale.vo.AfterSaleRefuseReqVO;
@ -410,4 +411,9 @@ public class AfterSaleServiceImpl implements AfterSaleService {
return tradeAfterSaleMapper.selectCountByUserIdAndStatus(userId, AfterSaleStatusEnum.APPLYING_STATUSES);
}
@Override
public AfterSaleSummaryRespDTO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime) {
return tradeAfterSaleMapper.selectSummaryByRefundTimeBetween(beginTime,endTime);
}
}

View File

@ -156,4 +156,13 @@ public interface BrokerageRecordService {
*/
AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long userId, Long spuId);
/**
* 获取已结算的佣金金额
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 已结算的佣金金额
*/
Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -356,6 +356,13 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService {
return respVO;
}
@Override
public Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime) {
return brokerageRecordMapper.selectSummaryPriceByStatusAndUnfreezeTimeBetween(
BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(),
beginTime, endTime);
}
/**
* 获得自身的代理对象解决 AOP 生效问题
*

View File

@ -1,12 +1,14 @@
package cn.iocoder.yudao.module.trade.service.order;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO;
import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO;
import cn.iocoder.yudao.module.trade.framework.delivery.core.client.dto.ExpressTrackRespDTO;
import java.time.LocalDateTime;
import java.util.Collection;
import java.util.List;
@ -119,4 +121,13 @@ public interface TradeOrderQueryService {
*/
List<TradeOrderItemDO> getOrderItemListByOrderId(Collection<Long> orderIds);
/**
* 获取订单统计
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 订单统计结果
*/
TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -6,6 +6,7 @@ import cn.hutool.core.util.StrUtil;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.member.api.user.MemberUserApi;
import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO;
import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO;
import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderPageReqVO;
import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO;
@ -20,6 +21,7 @@ import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
import java.util.*;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
@ -143,6 +145,14 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService {
.setPhone(order.getReceiverMobile()));
}
@Override
public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) {
TradeOrderSummaryRespDTO dto = tradeOrderMapper.selectSummaryByPayTimeBetween(beginTime, endTime);
dto.setOrderCreateCount(tradeOrderMapper.selectCountByCreateTimeBetween(beginTime, endTime));
return dto;
}
// =================== Order Item ===================
@Override

View File

@ -0,0 +1,23 @@
package cn.iocoder.yudao.module.pay.api.wallet;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
import java.time.LocalDateTime;
/**
* 钱包 API 接口
*
* @author owen
*/
public interface PayWalletApi {
/**
* 获取钱包统计
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 钱包统计
*/
WalletSummaryRespDTO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.pay.api.wallet.dto;
import lombok.Data;
/**
* 钱包统计 Response DTO
*
* @author owen
*/
@Data
public class WalletSummaryRespDTO {
/**
* 总支付金额余额单位
*/
private Integer orderWalletPayPrice;
/**
* 充值订单数
*/
private Integer rechargePayCount;
/**
* 充值金额单位
*/
private Integer rechargePayPrice;
/**
* 充值退款订单数
*/
private Integer rechargeRefundCount;
/**
* 充值退款金额单位
*/
private Integer rechargeRefundPrice;
}

View File

@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.pay.api.wallet;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletRechargeService;
import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import javax.annotation.Resource;
import java.time.LocalDateTime;
/**
* 钱包 API 接口实现类
*
* @author owen
*/
@Service
@Validated
public class PayWalletApiImpl implements PayWalletApi {
@Resource
private PayWalletRechargeService payWalletRechargeService;
@Resource
private PayWalletTransactionService payWalletTransactionService;
@Override
public WalletSummaryRespDTO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime) {
WalletSummaryRespDTO walletSummary = payWalletRechargeService.getWalletSummary(beginTime, endTime);
walletSummary.setOrderWalletPayPrice(payWalletTransactionService.getPriceSummary(PayWalletBizTypeEnum.PAYMENT, beginTime, endTime));
return walletSummary;
}
}

View File

@ -1,23 +1,48 @@
package cn.iocoder.yudao.module.pay.dal.mysql.wallet;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum;
import com.github.yulichang.toolkit.MPJWrappers;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
@Mapper
public interface PayWalletRechargeMapper extends BaseMapperX<PayWalletRechargeDO> {
default int updateByIdAndPaid(Long id, boolean wherePayStatus, PayWalletRechargeDO updateObj){
default int updateByIdAndPaid(Long id, boolean wherePayStatus, PayWalletRechargeDO updateObj) {
return update(updateObj, new LambdaQueryWrapperX<PayWalletRechargeDO>()
.eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getPayStatus, wherePayStatus));
}
default int updateByIdAndRefunded(Long id, Integer whereRefundStatus, PayWalletRechargeDO updateObj){
default int updateByIdAndRefunded(Long id, Integer whereRefundStatus, PayWalletRechargeDO updateObj) {
return update(updateObj, new LambdaQueryWrapperX<PayWalletRechargeDO>()
.eq(PayWalletRechargeDO::getId, id).eq(PayWalletRechargeDO::getRefundStatus, whereRefundStatus));
}
default WalletSummaryRespDTO selectRechargeSummaryByPayTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return BeanUtil.copyProperties(CollUtil.get(selectMaps(MPJWrappers.<PayWalletRechargeDO>lambdaJoin()
.selectCount(PayWalletRechargeDO::getId, WalletSummaryRespDTO::getRechargePayCount)
.selectSum(PayWalletRechargeDO::getPayPrice, WalletSummaryRespDTO::getRechargePayPrice)
.eq(PayWalletRechargeDO::getPayStatus, true)
.between(PayWalletRechargeDO::getPayTime, beginTime, endTime)), 0),
WalletSummaryRespDTO.class);
}
default WalletSummaryRespDTO selectRechargeSummaryByRefundTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) {
return BeanUtil.copyProperties(CollUtil.get(selectMaps(MPJWrappers.<PayWalletRechargeDO>lambdaJoin()
.selectCount(PayWalletRechargeDO::getId, WalletSummaryRespDTO::getRechargeRefundCount)
.selectSum(PayWalletRechargeDO::getRefundPayPrice, WalletSummaryRespDTO::getRechargeRefundPrice)
.eq(PayWalletRechargeDO::getRefundStatus, PayRefundStatusEnum.SUCCESS.getStatus())
.between(PayWalletRechargeDO::getRefundTime, beginTime, endTime)), 0),
WalletSummaryRespDTO.class);
}
}

View File

@ -6,9 +6,12 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.transaction.AppPayWalletTransactionPageReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import com.github.yulichang.toolkit.MPJWrappers;
import org.apache.ibatis.annotations.Mapper;
import java.time.LocalDateTime;
import java.util.Objects;
import java.util.Optional;
@Mapper
public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> {
@ -35,6 +38,15 @@ public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransac
PayWalletTransactionDO::getBizType, bizType);
}
default Integer selectSummaryByBizTypeAndCreateTimeBetween(Integer type, LocalDateTime beginTime, LocalDateTime endTime) {
return Optional.ofNullable(selectOne(MPJWrappers.<PayWalletTransactionDO>lambdaJoin()
.selectSum(PayWalletTransactionDO::getPrice)
.eq(PayWalletTransactionDO::getBizType, type)
.between(PayWalletTransactionDO::getCreateTime, beginTime, endTime)))
.map(PayWalletTransactionDO::getPrice)
.orElse(0);
}
}

View File

@ -1,8 +1,11 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletRechargeDO;
import java.time.LocalDateTime;
/**
* 钱包充值 Service 接口
*
@ -42,4 +45,14 @@ public interface PayWalletRechargeService {
* @param payRefundId 退款单id
*/
void updateWalletRechargeRefunded(Long id, Long payRefundId);
/**
* 获取钱包统计
*
* @param beginTime 起始时间
* @param endTime 截止时间
* @return 钱包统计
*/
WalletSummaryRespDTO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -4,6 +4,7 @@ import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.framework.pay.core.enums.refund.PayRefundStatusRespEnum;
import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.refund.dto.PayRefundCreateReqDTO;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.recharge.AppPayWalletRechargeCreateReqVO;
import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletRechargeConvert;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO;
@ -94,7 +95,7 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
PayOrderDO payOrderDO = validateWalletRechargerCanPaid(walletRecharge, payOrderId);
// 2. 更新钱包充值的支付状态
int updateCount = walletRechargeMapper.updateByIdAndPaid(id,false,
int updateCount = walletRechargeMapper.updateByIdAndPaid(id, false,
new PayWalletRechargeDO().setId(id).setPayStatus(true).setPayTime(LocalDateTime.now())
.setPayChannelCode(payOrderDO.getChannelCode()));
if (updateCount == 0) {
@ -257,4 +258,15 @@ public class PayWalletRechargeServiceImpl implements PayWalletRechargeService {
return payOrder;
}
@Override
public WalletSummaryRespDTO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime) {
WalletSummaryRespDTO paySummary = walletRechargeMapper.selectRechargeSummaryByPayTimeBetween(beginTime, endTime);
WalletSummaryRespDTO refundSummary = walletRechargeMapper.selectRechargeSummaryByRefundTimeBetween(beginTime, endTime);
paySummary.setRechargeRefundCount(refundSummary.getRechargeRefundCount());
paySummary.setRechargeRefundPrice(refundSummary.getRechargeRefundPrice());
return paySummary;
}
}

View File

@ -1,9 +1,12 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO;
import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
import java.time.LocalDateTime;
/**
* 钱包 Service 接口
*

View File

@ -1,6 +1,7 @@
package cn.iocoder.yudao.module.pay.service.wallet;
import cn.hutool.core.lang.Assert;
import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO;
import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.refund.PayRefundDO;
import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO;

View File

@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum;
import cn.iocoder.yudao.module.pay.service.wallet.bo.WalletTransactionCreateReqBO;
import javax.validation.Valid;
import java.time.LocalDateTime;
/**
* 钱包余额流水 Service 接口
@ -49,4 +50,14 @@ public interface PayWalletTransactionService {
*/
PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type);
/**
* 获取支付金额合计
*
* @param bizType 业务类型
* @param beginTime 开始时间
* @param endTime 结束时间
* @return 支付金额合计
*/
Integer getPriceSummary(PayWalletBizTypeEnum bizType, LocalDateTime beginTime, LocalDateTime endTime);
}

View File

@ -13,6 +13,7 @@ import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.time.LocalDateTime;
/**
* 钱包流水 Service 实现类
@ -60,4 +61,9 @@ public class PayWalletTransactionServiceImpl implements PayWalletTransactionServ
return payWalletTransactionMapper.selectByBiz(bizId, type.getType());
}
@Override
public Integer getPriceSummary(PayWalletBizTypeEnum bizType, LocalDateTime beginTime, LocalDateTime endTime) {
return payWalletTransactionMapper.selectSummaryByBizTypeAndCreateTimeBetween(bizType.getType(), beginTime, endTime);
}
}