From 4f33a0c9c00b8c352eeb98e01babbdb8ed360216 Mon Sep 17 00:00:00 2001 From: owen Date: Fri, 6 Oct 2023 14:15:59 +0800 Subject: [PATCH 01/21] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=EF=BC=9A=E4=BA=A4?= =?UTF-8?q?=E6=98=93=E7=BB=9F=E8=AE=A1Review=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../convert/trade/TradeStatisticsConvert.java | 12 +++--- .../trade/AfterSaleStatisticsMapper.java | 22 ++++++++++ .../trade/BrokerageStatisticsMapper.java | 23 +++++++++++ .../trade/PayWalletStatisticsMapper.java | 30 ++++++++++++++ .../trade/TradeOrderStatisticsMapper.java | 22 ++++++++++ .../trade/AfterSaleStatisticsService.java | 23 +++++++++++ .../trade/AfterSaleStatisticsServiceImpl.java | 28 +++++++++++++ .../trade/BrokerageStatisticsService.java | 21 ++++++++++ .../trade/BrokerageStatisticsServiceImpl.java | 31 ++++++++++++++ .../trade/PayWalletStatisticsService.java | 23 +++++++++++ .../trade/PayWalletStatisticsServiceImpl.java | 41 +++++++++++++++++++ .../trade/TradeOrderStatisticsService.java | 23 +++++++++++ .../TradeOrderStatisticsServiceImpl.java | 28 +++++++++++++ .../trade/TradeStatisticsServiceImpl.java | 30 +++++--------- .../trade/bo/AfterSaleSummaryRespBO.java} | 4 +- .../trade/bo/TradeOrderSummaryRespBO.java} | 6 +-- .../service/trade/bo/WalletSummaryRespBO.java | 4 +- .../trade/AfterSaleStatisticsMapper.xml | 12 ++++++ .../trade/BrokerageStatisticsMapper.xml | 12 ++++++ .../trade/PayWalletStatisticsMapper.xml | 31 ++++++++++++++ .../trade/TradeOrderStatisticsMapper.xml | 16 ++++++++ .../api/aftersale/TradeAfterSaleApi.java | 13 ------ .../api/brokerage/TradeBrokerageApi.java | 11 ----- .../module/trade/api/order/TradeOrderApi.java | 11 ----- .../api/aftersale/TradeAfterSaleApiImpl.java | 7 ---- .../api/brokerage/TradeBrokerageApiImpl.java | 6 --- .../trade/api/order/TradeOrderApiImpl.java | 8 ---- .../dal/mysql/aftersale/AfterSaleMapper.java | 13 ------ .../brokerage/BrokerageRecordMapper.java | 11 ----- .../dal/mysql/order/TradeOrderMapper.java | 17 -------- .../service/aftersale/AfterSaleService.java | 12 ------ .../aftersale/AfterSaleServiceImpl.java | 6 --- .../brokerage/BrokerageRecordService.java | 9 ---- .../brokerage/BrokerageRecordServiceImpl.java | 7 ---- .../service/order/TradeOrderQueryService.java | 13 +----- .../order/TradeOrderQueryServiceImpl.java | 9 ---- .../module/pay/api/wallet/PayWalletApi.java | 13 ------ .../pay/api/wallet/PayWalletApiImpl.java | 10 ----- .../mysql/wallet/PayWalletRechargeMapper.java | 25 ----------- .../wallet/PayWalletTransactionMapper.java | 12 ------ .../wallet/PayWalletRechargeService.java | 24 ++++------- .../wallet/PayWalletRechargeServiceImpl.java | 12 ------ .../pay/service/wallet/PayWalletService.java | 3 -- .../service/wallet/PayWalletServiceImpl.java | 1 - .../wallet/PayWalletTransactionService.java | 11 ----- .../PayWalletTransactionServiceImpl.java | 6 --- 46 files changed, 418 insertions(+), 294 deletions(-) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/AfterSaleStatisticsMapper.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/BrokerageStatisticsMapper.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/PayWalletStatisticsMapper.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeOrderStatisticsMapper.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/AfterSaleStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/AfterSaleStatisticsServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java rename yudao-module-mall/{yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/dto/AfterSaleSummaryRespDTO.java => yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/AfterSaleSummaryRespBO.java} (72%) rename yudao-module-mall/{yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/dto/TradeOrderSummaryRespDTO.java => yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java} (70%) rename yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/WalletSummaryRespDTO.java => yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java (85%) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml 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 index 1f36f26b9..a2bce34d9 100644 --- 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 @@ -1,14 +1,14 @@ package cn.iocoder.yudao.module.statistics.convert.trade; -import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; 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.TradeOrderSummaryRespBO; 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 cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO; import org.mapstruct.Mapper; import org.mapstruct.factory.Mappers; @@ -46,8 +46,8 @@ public interface TradeStatisticsConvert { List convertList02(List list); - TradeStatisticsDO convert(LocalDateTime time, TradeOrderSummaryRespDTO orderSummary, - AfterSaleSummaryRespDTO afterSaleSummary, Integer brokerageSettlementPrice, - WalletSummaryRespDTO walletSummary); + TradeStatisticsDO convert(LocalDateTime time, TradeOrderSummaryRespBO orderSummary, + AfterSaleSummaryRespBO afterSaleSummary, Integer brokerageSettlementPrice, + WalletSummaryRespBO walletSummary); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/AfterSaleStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/AfterSaleStatisticsMapper.java new file mode 100644 index 000000000..17e9b1be3 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/AfterSaleStatisticsMapper.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.trade; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; + +/** + * 交易统计 Mapper + * + * @author owen + */ +@Mapper +public interface AfterSaleStatisticsMapper extends BaseMapperX { + + AfterSaleSummaryRespBO selectSummaryByRefundTimeBetween(@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/dal/mysql/trade/BrokerageStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/BrokerageStatisticsMapper.java new file mode 100644 index 000000000..cf109846f --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/BrokerageStatisticsMapper.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.trade; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; + +/** + * 交易统计 Mapper + * + * @author owen + */ +@Mapper +public interface BrokerageStatisticsMapper extends BaseMapperX { + + Integer selectSummaryPriceByStatusAndUnfreezeTimeBetween(@Param("bizType") Integer bizType, + @Param("status") Integer status, + @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/dal/mysql/trade/PayWalletStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/PayWalletStatisticsMapper.java new file mode 100644 index 000000000..126a1557b --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/PayWalletStatisticsMapper.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.trade; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; +import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; + +/** + * 交易统计 Mapper + * + * @author owen + */ +@Mapper +public interface PayWalletStatisticsMapper extends BaseMapperX { + + WalletSummaryRespBO selectRechargeSummaryByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime, + @Param("payStatus") Boolean payStatus); + + WalletSummaryRespBO selectRechargeSummaryByRefundTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime, + @Param("refundStatus") Integer refundStatus); + + Integer selectPriceSummaryByBizTypeAndCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime, + @Param("bizType") Integer bizType); +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeOrderStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeOrderStatisticsMapper.java new file mode 100644 index 000000000..068ea8598 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/TradeOrderStatisticsMapper.java @@ -0,0 +1,22 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.trade; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; + +/** + * 交易统计 Mapper + * + * @author owen + */ +@Mapper +public interface TradeOrderStatisticsMapper extends BaseMapperX { + + TradeOrderSummaryRespBO selectSummaryByPayTimeBetween(@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/AfterSaleStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/AfterSaleStatisticsService.java new file mode 100644 index 000000000..ea805967b --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/AfterSaleStatisticsService.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO; + +import java.time.LocalDateTime; + +/** + * 售后统计 Service 接口 + * + * @author owen + */ +public interface AfterSaleStatisticsService { + + /** + * 获取售后单统计 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 售后统计结果 + */ + AfterSaleSummaryRespBO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime); + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/AfterSaleStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/AfterSaleStatisticsServiceImpl.java new file mode 100644 index 000000000..cc2ec4af9 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/AfterSaleStatisticsServiceImpl.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.iocoder.yudao.module.statistics.dal.mysql.trade.AfterSaleStatisticsMapper; +import cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * 售后统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class AfterSaleStatisticsServiceImpl implements AfterSaleStatisticsService { + + @Resource + private AfterSaleStatisticsMapper afterSaleStatisticsMapper; + + @Override + public AfterSaleSummaryRespBO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime) { + return afterSaleStatisticsMapper.selectSummaryByRefundTimeBetween(beginTime, endTime); + } + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsService.java new file mode 100644 index 000000000..7d1bfa347 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsService.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import java.time.LocalDateTime; + +/** + * 分销统计 Service 接口 + * + * @author owen + */ +public interface BrokerageStatisticsService { + + /** + * 获取已结算的佣金金额 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 已结算的佣金金额 + */ + Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime); + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsServiceImpl.java new file mode 100644 index 000000000..8c29166e5 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/BrokerageStatisticsServiceImpl.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.iocoder.yudao.module.statistics.dal.mysql.trade.BrokerageStatisticsMapper; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * 分销统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class BrokerageStatisticsServiceImpl implements BrokerageStatisticsService { + + @Resource + private BrokerageStatisticsMapper brokerageStatisticsMapper; + + @Override + public Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime) { + return brokerageStatisticsMapper.selectSummaryPriceByStatusAndUnfreezeTimeBetween( + BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), + beginTime, endTime); + } + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java new file mode 100644 index 000000000..6eb03d7f8 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; + +import java.time.LocalDateTime; + +/** + * 钱包统计 Service 接口 + * + * @author owen + */ +public interface PayWalletStatisticsService { + + /** + * 获取钱包统计 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 钱包统计 + */ + WalletSummaryRespBO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime); + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java new file mode 100644 index 000000000..95f073de1 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; +import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; +import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum; +import cn.iocoder.yudao.module.statistics.dal.mysql.trade.PayWalletStatisticsMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * 钱包统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class PayWalletStatisticsServiceImpl implements PayWalletStatisticsService { + + @Resource + private PayWalletStatisticsMapper payWalletStatisticsMapper; + + @Override + public WalletSummaryRespBO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime) { + WalletSummaryRespBO paySummary = payWalletStatisticsMapper.selectRechargeSummaryByPayTimeBetween( + beginTime, endTime, true); + WalletSummaryRespBO refundSummary = payWalletStatisticsMapper.selectRechargeSummaryByRefundTimeBetween( + beginTime, endTime, PayRefundStatusEnum.SUCCESS.getStatus()); + Integer walletPayPrice = payWalletStatisticsMapper.selectPriceSummaryByBizTypeAndCreateTimeBetween( + beginTime, endTime, PayWalletBizTypeEnum.PAYMENT.getType()); + + paySummary.setOrderWalletPayPrice(walletPayPrice); + paySummary.setRechargeRefundCount(refundSummary.getRechargeRefundCount()); + paySummary.setRechargeRefundPrice(refundSummary.getRechargeRefundPrice()); + + return paySummary; + } + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java new file mode 100644 index 000000000..8ae3f89a3 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; + +import java.time.LocalDateTime; + +/** + * 交易订单统计 Service 接口 + * + * @author owen + */ +public interface TradeOrderStatisticsService { + + /** + * 获取订单统计 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 订单统计结果 + */ + TradeOrderSummaryRespBO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java new file mode 100644 index 000000000..d3449abd8 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java @@ -0,0 +1,28 @@ +package cn.iocoder.yudao.module.statistics.service.trade; + +import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper; +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * 交易订单统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsService { + + @Resource + private TradeOrderStatisticsMapper tradeOrderStatisticsMapper; + + @Override + public TradeOrderSummaryRespBO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeOrderStatisticsMapper.selectSummaryByPayTimeBetween(beginTime, 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 index fdaf50f1d..1fc075b0e 100644 --- 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 @@ -2,8 +2,7 @@ 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.service.trade.bo.WalletSummaryRespBO; 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; @@ -11,11 +10,8 @@ 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 cn.iocoder.yudao.module.statistics.service.trade.bo.AfterSaleSummaryRespBO; +import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; import org.springframework.stereotype.Service; import org.springframework.util.StopWatch; import org.springframework.validation.annotation.Validated; @@ -37,18 +33,14 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { @Resource private TradeStatisticsMapper tradeStatisticsMapper; - // TODO @疯狂:统计逻辑,自己服务 mapper 去统计,不要调用其它服务 API; - // 主要的考虑点,其它服务是在线的业务,统计是离线业务,尽量不占用他们的 db 资源; - // 统计服务,从建议使用从库,或者从 mysql 抽取到单独的 clickhouse 或者其它的大数据组件; - @Resource - private TradeOrderApi tradeOrderApi; + private TradeOrderStatisticsService tradeOrderStatisticsService; @Resource - private TradeAfterSaleApi tradeAfterSaleApi; + private AfterSaleStatisticsService afterSaleStatisticsService; @Resource - private TradeBrokerageApi tradeBrokerageApi; + private BrokerageStatisticsService brokerageStatisticsService; @Resource - private PayWalletApi payWalletApi; + private PayWalletStatisticsService payWalletStatisticsService; @Override public TradeStatisticsComparisonRespVO getTradeSummaryComparison() { @@ -90,19 +82,19 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { // 统计 StopWatch stopWatch = new StopWatch("交易统计"); stopWatch.start("统计订单"); - TradeOrderSummaryRespDTO orderSummary = tradeOrderApi.getOrderSummary(beginTime, endTime); + TradeOrderSummaryRespBO orderSummary = tradeOrderStatisticsService.getOrderSummary(beginTime, endTime); stopWatch.stop(); stopWatch.start("统计售后"); - AfterSaleSummaryRespDTO afterSaleSummary = tradeAfterSaleApi.getAfterSaleSummary(beginTime, endTime); + AfterSaleSummaryRespBO afterSaleSummary = afterSaleStatisticsService.getAfterSaleSummary(beginTime, endTime); stopWatch.stop(); stopWatch.start("统计佣金"); - Integer brokerageSettlementPrice = tradeBrokerageApi.getBrokerageSettlementPriceSummary(beginTime, endTime); + Integer brokerageSettlementPrice = brokerageStatisticsService.getBrokerageSettlementPriceSummary(beginTime, endTime); stopWatch.stop(); stopWatch.start("统计充值"); - WalletSummaryRespDTO walletSummary = payWalletApi.getWalletSummary(beginTime, endTime); + WalletSummaryRespBO walletSummary = payWalletStatisticsService.getWalletSummary(beginTime, endTime); stopWatch.stop(); // 插入数据 TradeStatisticsDO entity = TradeStatisticsConvert.INSTANCE.convert(yesterday, orderSummary, afterSaleSummary, brokerageSettlementPrice, walletSummary); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/dto/AfterSaleSummaryRespDTO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/AfterSaleSummaryRespBO.java similarity index 72% rename from yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/dto/AfterSaleSummaryRespDTO.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/AfterSaleSummaryRespBO.java index ab70019b0..985643636 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/dto/AfterSaleSummaryRespDTO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/AfterSaleSummaryRespBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.trade.api.aftersale.dto; +package cn.iocoder.yudao.module.statistics.service.trade.bo; import lombok.Data; @@ -8,7 +8,7 @@ import lombok.Data; * @author owen */ @Data -public class AfterSaleSummaryRespDTO { +public class AfterSaleSummaryRespBO { /** * 退款订单数 diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/dto/TradeOrderSummaryRespDTO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java similarity index 70% rename from yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/dto/TradeOrderSummaryRespDTO.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java index a10d43596..521762846 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/dto/TradeOrderSummaryRespDTO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java @@ -1,14 +1,14 @@ -package cn.iocoder.yudao.module.trade.api.order.dto; +package cn.iocoder.yudao.module.statistics.service.trade.bo; import lombok.Data; /** - * 订单统计 Response DTO + * 订单统计 Response BO * * @author owen */ @Data -public class TradeOrderSummaryRespDTO { +public class TradeOrderSummaryRespBO { /** * 创建订单数 diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/WalletSummaryRespDTO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java similarity index 85% rename from yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/WalletSummaryRespDTO.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java index c72a5de63..97e319722 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/dto/WalletSummaryRespDTO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java @@ -1,4 +1,4 @@ -package cn.iocoder.yudao.module.pay.api.wallet.dto; +package cn.iocoder.yudao.module.statistics.service.trade.bo; import lombok.Data; @@ -8,7 +8,7 @@ import lombok.Data; * @author owen */ @Data -public class WalletSummaryRespDTO { +public class WalletSummaryRespBO { /** * 总支付金额(余额),单位:分 */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml new file mode 100644 index 000000000..c89fe9ed4 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml new file mode 100644 index 000000000..ae19fcef4 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml new file mode 100644 index 000000000..7a0dd1e26 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml @@ -0,0 +1,31 @@ + + + + + + + + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml new file mode 100644 index 000000000..f8553b481 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java index c3fd3f67b..5f58b5393 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java @@ -1,9 +1,5 @@ package cn.iocoder.yudao.module.trade.api.aftersale; -import cn.iocoder.yudao.module.trade.api.aftersale.dto.AfterSaleSummaryRespDTO; - -import java.time.LocalDateTime; - /** * 售后 API 接口 * @@ -11,13 +7,4 @@ import java.time.LocalDateTime; */ public interface TradeAfterSaleApi { - /** - * 获取售后单统计 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 售后统计结果 - */ - AfterSaleSummaryRespDTO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java index 3fa51159c..8628098a3 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java @@ -1,7 +1,5 @@ package cn.iocoder.yudao.module.trade.api.brokerage; -import java.time.LocalDateTime; - /** * 分销 API 接口 * @@ -9,13 +7,4 @@ import java.time.LocalDateTime; */ public interface TradeBrokerageApi { - /** - * 获取已结算的佣金金额 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 已结算的佣金金额 - */ - Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java index 5b7594d40..7727c3b37 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java @@ -1,9 +1,7 @@ package cn.iocoder.yudao.module.trade.api.order; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; -import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -31,13 +29,4 @@ public interface TradeOrderApi { */ Integer getOrderStatus(Long id); - /** - * 获取订单统计 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 订单统计结果 - */ - TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java index 297e8f1ad..474943e38 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java @@ -1,12 +1,10 @@ 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 接口实现类 @@ -20,9 +18,4 @@ public class TradeAfterSaleApiImpl implements TradeAfterSaleApi { @Resource private AfterSaleService afterSaleService; - @Override - public AfterSaleSummaryRespDTO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime) { - return afterSaleService.getAfterSaleSummary(beginTime, endTime); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java index c93d33ef2..c860d4b7f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java @@ -5,7 +5,6 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; -import java.time.LocalDateTime; /** * 订单 API 接口实现类 @@ -19,9 +18,4 @@ public class TradeBrokerageApiImpl implements TradeBrokerageApi { @Resource private BrokerageRecordService brokerageRecordService; - @Override - public Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime) { - return brokerageRecordService.getBrokerageSettlementPriceSummary(beginTime, endTime); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 5ad0cb107..cb5b13949 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -1,7 +1,6 @@ package cn.iocoder.yudao.module.trade.api.order; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; -import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; @@ -9,8 +8,6 @@ import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; - -import java.time.LocalDateTime; import java.util.Collection; import java.util.List; @@ -43,9 +40,4 @@ public class TradeOrderApiImpl implements TradeOrderApi { return order.getStatus(); } - @Override - public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { - return tradeOrderQueryService.getOrderSummary(beginTime, endTime); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/aftersale/AfterSaleMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/aftersale/AfterSaleMapper.java index 5b9a22280..68a09a82a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/aftersale/AfterSaleMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/aftersale/AfterSaleMapper.java @@ -1,19 +1,14 @@ 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 @@ -53,12 +48,4 @@ public interface AfterSaleMapper extends BaseMapperX { .in(AfterSaleDO::getStatus, statuses)); } - default AfterSaleSummaryRespDTO selectSummaryByRefundTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) { - return BeanUtil.copyProperties(CollUtil.get(selectMaps(MPJWrappers.lambdaJoin() - .selectCount(AfterSaleDO::getId, AfterSaleSummaryRespDTO::getAfterSaleCount) - .selectSum(AfterSaleDO::getRefundPrice, AfterSaleSummaryRespDTO::getAfterSaleRefundPrice) - .between(AfterSaleDO::getRefundTime, beginTime, endTime)), 0), - AfterSaleSummaryRespDTO.class); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java index b65eb6ff0..e7a85868b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageRecordMapper.java @@ -1,8 +1,6 @@ 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; @@ -111,13 +109,4 @@ public interface BrokerageRecordMapper extends BaseMapperX { @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.lambdaJoin() - .selectSum(BrokerageRecordDO::getPrice) - .eq(BrokerageRecordDO::getBizType, bizType) - .eq(BrokerageRecordDO::getStatus, status) - .between(BrokerageRecordDO::getUnfreezeTime, beginTime, endTime))), 0); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java index d68f81c61..8dc29e8cd 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java @@ -1,16 +1,12 @@ 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; @@ -93,19 +89,6 @@ public interface TradeOrderMapper extends BaseMapperX { .eq(TradeOrderDO::getSeckillActivityId, seckillActivityId)); } - default TradeOrderSummaryRespDTO selectSummaryByPayTimeBetween(LocalDateTime beginTime, LocalDateTime endTime) { - return BeanUtil.copyProperties(CollUtil.get(selectMaps(MPJWrappers.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() - .between(TradeOrderDO::getCreateTime, beginTime, endTime)); - } - default TradeOrderDO selectOneByPickUpVerifyCode(String pickUpVerifyCode) { return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleService.java index 76c331847..1a0c1e95d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleService.java @@ -2,7 +2,6 @@ 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; @@ -10,8 +9,6 @@ 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 接口 * @@ -127,13 +124,4 @@ public interface AfterSaleService { */ Long getApplyingAfterSaleCount(Long userId); - /** - * 获取售后单统计 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 售后统计结果 - */ - AfterSaleSummaryRespDTO getAfterSaleSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleServiceImpl.java index 20f93841b..19248d1a1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/aftersale/AfterSaleServiceImpl.java @@ -7,7 +7,6 @@ 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; @@ -411,9 +410,4 @@ 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); - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java index 22c2c67ac..1cf1e2443 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordService.java @@ -156,13 +156,4 @@ public interface BrokerageRecordService { */ AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long userId, Long spuId); - /** - * 获取已结算的佣金金额 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 已结算的佣金金额 - */ - Integer getBrokerageSettlementPriceSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java index ace734913..8b60c4f6a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageRecordServiceImpl.java @@ -356,13 +356,6 @@ 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 生效问题 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java index c2a7933e0..1cbe025ec 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java @@ -1,14 +1,12 @@ 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; @@ -95,7 +93,7 @@ public interface TradeOrderQueryService { /** * 【会员】在指定秒杀活动下,用户购买的商品数量 * - * @param userId 用户编号 + * @param userId 用户编号 * @param activityId 活动编号 * @return 秒杀商品数量 */ @@ -138,13 +136,4 @@ public interface TradeOrderQueryService { */ List getOrderItemListByOrderId(Collection orderIds); - /** - * 获取订单统计 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 订单统计结果 - */ - TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java index 4f4fd4f68..75e0911f6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java @@ -6,7 +6,6 @@ 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; @@ -22,7 +21,6 @@ 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; @@ -166,13 +164,6 @@ 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 =================== diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java index bc6215f10..5bb50bf6d 100644 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java +++ b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java @@ -1,9 +1,5 @@ package cn.iocoder.yudao.module.pay.api.wallet; -import cn.iocoder.yudao.module.pay.api.wallet.dto.WalletSummaryRespDTO; - -import java.time.LocalDateTime; - /** * 钱包 API 接口 * @@ -11,13 +7,4 @@ import java.time.LocalDateTime; */ public interface PayWalletApi { - /** - * 获取钱包统计 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 钱包统计 - */ - WalletSummaryRespDTO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java index 3157d1338..89be2a25e 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java @@ -1,14 +1,11 @@ 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 接口实现类 @@ -24,11 +21,4 @@ public class PayWalletApiImpl implements PayWalletApi { @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; - } - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java index 7c422a1cd..606f61484 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletRechargeMapper.java @@ -1,17 +1,10 @@ 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 { @@ -25,24 +18,6 @@ public interface PayWalletRechargeMapper extends BaseMapperXlambdaJoin() - .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.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); - } - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java index bcb9464d6..7831e77bd 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java @@ -6,12 +6,9 @@ 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 { @@ -38,15 +35,6 @@ public interface PayWalletTransactionMapper extends BaseMapperXlambdaJoin() - .selectSum(PayWalletTransactionDO::getPrice) - .eq(PayWalletTransactionDO::getBizType, type) - .between(PayWalletTransactionDO::getCreateTime, beginTime, endTime))) - .map(PayWalletTransactionDO::getPrice) - .orElse(0); - } - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java index 975e881a6..3101d3ecf 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeService.java @@ -1,11 +1,8 @@ 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 接口 * @@ -16,8 +13,8 @@ public interface PayWalletRechargeService { /** * 创建钱包充值记录(发起充值) * - * @param userId 用户 id - * @param userType 用户类型 + * @param userId 用户 id + * @param userType 用户类型 * @param createReqVO 钱包充值请求 VO * @return 钱包充值记录 */ @@ -27,32 +24,25 @@ public interface PayWalletRechargeService { /** * 更新钱包充值成功 * - * @param id 钱包充值记录 id + * @param id 钱包充值记录 id * @param payOrderId 支付订单 id */ void updateWalletRechargerPaid(Long id, Long payOrderId); /** * 发起钱包充值退款 - * @param id 钱包充值编号 + * + * @param id 钱包充值编号 * @param userIp 用户 ip 地址 */ void refundWalletRecharge(Long id, String userIp); /** * 更新钱包充值记录为已退款 - * @param id 钱包充值 id + * + * @param id 钱包充值 id * @param payRefundId 退款单id */ void updateWalletRechargeRefunded(Long id, Long payRefundId); - /** - * 获取钱包统计 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 钱包统计 - */ - WalletSummaryRespDTO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java index 71c03df67..e34fa69e2 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletRechargeServiceImpl.java @@ -4,7 +4,6 @@ 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; @@ -258,15 +257,4 @@ 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; - } - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java index 96a623bb2..508822551 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java @@ -1,12 +1,9 @@ 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 接口 * diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java index d98c9c9f9..c14d20cfa 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java @@ -1,7 +1,6 @@ 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; diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java index c970de189..8a112b6c6 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java @@ -7,7 +7,6 @@ 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 接口 @@ -50,14 +49,4 @@ public interface PayWalletTransactionService { */ PayWalletTransactionDO getWalletTransaction(String bizId, PayWalletBizTypeEnum type); - /** - * 获取支付金额合计 - * - * @param bizType 业务类型 - * @param beginTime 开始时间 - * @param endTime 结束时间 - * @return 支付金额合计 - */ - Integer getPriceSummary(PayWalletBizTypeEnum bizType, LocalDateTime beginTime, LocalDateTime endTime); - } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java index 85e8f6c87..ad802be41 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java @@ -13,7 +13,6 @@ import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import javax.annotation.Resource; -import java.time.LocalDateTime; /** * 钱包流水 Service 实现类 @@ -61,9 +60,4 @@ 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); - } - } From 53e67c0437a634407322c1f6dc98a4fd5bda0f54 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 9 Oct 2023 11:53:02 +0800 Subject: [PATCH 02/21] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E5=96=84=20review=20=E6=8F=90=E5=88=B0?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationRecordApi.java | 5 +-- .../combination/CombinationRecordApiImpl.java | 3 +- .../CombinationRecordController.java | 7 ++-- .../AppCombinationRecordController.java | 4 +-- .../CombinationActivityConvert.java | 4 --- .../combination/CombinationRecordMapper.java | 22 ++++++++---- .../combination/CombinationRecordService.java | 7 ++-- .../CombinationRecordServiceImpl.java | 34 ++++++++++--------- .../trade/enums/ErrorCodeConstants.java | 3 +- .../dal/mysql/order/TradeOrderMapper.java | 12 +++++++ .../service/order/TradeOrderQueryService.java | 12 ++++++- .../order/TradeOrderQueryServiceImpl.java | 5 +++ .../order/TradeOrderUpdateServiceImpl.java | 5 ++- .../handler/TradeCombinationHandler.java | 31 ++++++++++++++--- 14 files changed, 106 insertions(+), 48 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index 0bb767423..f45b0be1f 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.api.combination; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; @@ -29,9 +30,9 @@ public interface CombinationRecordApi { * 创建开团记录 * * @param reqDTO 请求 DTO - * @return 开团记录编号 + * @return key 开团记录编号 value 团长编号 */ - Long createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); + KeyValue createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); /** * 查询拼团记录是否成功 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java index d4acba1c3..4a3f1dbd5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.api.combination; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; @@ -29,7 +30,7 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { } @Override - public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + public KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { return recordService.createCombinationRecord(reqDTO); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index 88a026fe2..45ddf755a 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -54,10 +54,11 @@ public class CombinationRecordController { @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") public CommonResult getCombinationRecordSummary() { CombinationRecordSummaryVO summaryVO = new CombinationRecordSummaryVO(); - summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null)); // 获取所有拼团记录 + summaryVO.setUserCount(combinationRecordService.getCombinationRecordCount(null, null, null)); // 获取拼团用户参与数量 summaryVO.setSuccessCount(combinationRecordService.getCombinationRecordCount( // 获取成团记录 - CombinationRecordStatusEnum.SUCCESS.getStatus(), null)); - summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(null, Boolean.TRUE));// 获取虚拟成团记录 + CombinationRecordStatusEnum.SUCCESS.getStatus(), null, CombinationRecordDO.HEAD_ID_GROUP)); + summaryVO.setVirtualGroupCount(combinationRecordService.getCombinationRecordCount(// 获取虚拟成团记录 + null, Boolean.TRUE, CombinationRecordDO.HEAD_ID_GROUP)); return success(summaryVO); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java index 1c8004d35..684c7ce9b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/combination/AppCombinationRecordController.java @@ -46,8 +46,8 @@ public class AppCombinationRecordController { @Operation(summary = "获得拼团记录的概要信息", description = "用于小程序首页") public CommonResult getCombinationRecordSummary() { AppCombinationRecordSummaryRespVO summary = new AppCombinationRecordSummaryRespVO(); - // 1. 获得拼团记录数量 - Long count = combinationRecordService.getCombinationRecordCount(null, null); + // 1. 获得拼团参与用户数量 + Long count = combinationRecordService.getCombinationRecordCount(null, null, null); if (count == 0) { summary.setAvatars(Collections.emptyList()); summary.setUserCount(count); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index a344b48fc..067669a00 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -28,7 +28,6 @@ import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; -import java.time.LocalDateTime; import java.util.List; import java.util.Map; @@ -114,9 +113,6 @@ public interface CombinationActivityConvert { ProductSpuRespDTO spu, ProductSkuRespDTO sku) { return convert(reqDTO).setVirtualGroup(false) .setStatus(CombinationRecordStatusEnum.IN_PROGRESS.getStatus()) // 创建后默认状态为进行中 - .setStartTime(LocalDateTime.now()) // TODO @puhui999:想了下,这个 startTime 应该是团长的; - // TODO @puhui999:有团长的情况下,expireTime 应该是团长的; - .setExpireTime(activity.getStartTime().plusHours(activity.getLimitDuration())) .setUserSize(activity.getUserSize()).setUserCount(1) // 默认就是 1 插入后会接着更新一次所有的拼团记录 // 用户信息 .setNickname(user.getNickname()).setAvatar(user.getAvatar()) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index 31eb7f827..dd8747677 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -100,13 +100,21 @@ public interface CombinationRecordMapper extends BaseMapperX() - .eq(status != null || virtualGroup != null, - CombinationRecordDO::getHeadId, CombinationRecordDO.HEAD_ID_GROUP) // 统计团信息则指定团长 - .eqIfPresent(CombinationRecordDO::getStatus, status) - .eqIfPresent(CombinationRecordDO::getVirtualGroup, virtualGroup)); + /** + * 查询指定条件的记录数 + * 如果参数都为 null 时则查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次 + * + * @param status 状态,可为 null + * @param virtualGroup 是否虚拟成团,可为 null + * @param headId 团长编号,可为 null + * @return 记录数 + */ + default Long selectCountByHeadAndStatusAndVirtualGroup(Integer status, Boolean virtualGroup, Long headId) { + return selectCount(new QueryWrapper() + .select(status == null && virtualGroup == null && headId == null, "COUNT(DISTINCT(user_id))") + .eq(status != null, "status", status) + .eq(virtualGroup != null, "virtual_group", virtualGroup) + .eq(headId != null, "head_id", headId)); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index dd07a8b93..309047470 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -49,9 +49,9 @@ public interface CombinationRecordService { * 创建拼团记录 * * @param reqDTO 创建信息 - * @return 开团记录编号 + * @return key 开团记录编号 value 团长编号 */ - Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); + KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO); /** * 获得拼团记录 @@ -90,9 +90,10 @@ public interface CombinationRecordService { * * @param status 状态-允许为空 * @param virtualGroup 是否虚拟成团-允许为空 + * @param headId 团长编号,允许空。目的 headId 设置为 {@link CombinationRecordDO#HEAD_ID_GROUP} 时,可以设置 * @return 记录数 */ - Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup); + Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup, @Nullable Long headId); /** * 获取最近的 count 条拼团记录 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index e0548e7e1..0033d143b 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -20,7 +20,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; -import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -28,6 +27,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Nullable; import javax.annotation.Resource; +import java.time.LocalDateTime; import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; @@ -62,8 +62,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Resource @Lazy private ProductSkuApi productSkuApi; - @Resource - private TradeOrderApi tradeOrderApi; // TODO @芋艿:在详细预览下; @Override @@ -164,32 +162,36 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override @Transactional(rollbackFor = Exception.class) - public Long createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { - // 1. 校验拼团活动 + public KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { + // 1.校验拼团活动 KeyValue keyValue = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); - // 2.1 组合数据创建拼团记录 + // 2.组合数据创建拼团记录 MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); - // 2.2 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP + // 2.1.如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP if (record.getHeadId() == null) { - record.setHeadId(CombinationRecordDO.HEAD_ID_GROUP); + record.setStartTime(LocalDateTime.now()) + .setExpireTime(keyValue.getKey().getStartTime().plusHours(keyValue.getKey().getLimitDuration())) + .setHeadId(CombinationRecordDO.HEAD_ID_GROUP); + } else { + // 2.2.有团长的情况下需要设置开始时间和过期时间为团长的 + CombinationRecordDO headRecord = recordMapper.selectByHeadId(record.getHeadId(), + CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); // 查询进行中的父拼团 + record.setStartTime(headRecord.getStartTime()).setExpireTime(headRecord.getExpireTime()); } recordMapper.insert(record); if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { - return record.getId(); + return new KeyValue<>(record.getId(), record.getHeadId()); } - // TODO @puhui:是不是这里的更新,放到 order 模块那;支付完成后; - // 4、更新拼团相关信息到订单 - tradeOrderApi.updateOrderCombinationInfo(record.getOrderId(), record.getActivityId(), record.getId(), record.getHeadId()); - // 4、更新拼团记录 + // 3、更新拼团记录 updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey()); - return record.getId(); + return new KeyValue<>(record.getId(), record.getHeadId()); } /** @@ -241,8 +243,8 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } @Override - public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup) { - return recordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup); + public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup, @Nullable Long headId) { + return recordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup, headId); } @Override diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java index 9c11aa9ad..33081d461 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/ErrorCodeConstants.java @@ -33,7 +33,8 @@ public interface ErrorCodeConstants { ErrorCode ORDER_UPDATE_PRICE_FAIL_PRICE_ERROR = new ErrorCode(1_011_000_028, "支付订单调价失败,原因:调整后支付价格不能小于 0.01 元"); ErrorCode ORDER_DELETE_FAIL_STATUS_NOT_CANCEL = new ErrorCode(1_011_000_029, "交易订单删除失败,订单不是【已取消】状态"); ErrorCode ORDER_RECEIVE_FAIL_DELIVERY_TYPE_NOT_PICK_UP = new ErrorCode(1_011_000_030, "交易订单自提失败,收货方式不是【用户自提】"); - ErrorCode ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1_011_000_031, "交易订单修改收货地址失败,原因:订单已发货"); + ErrorCode ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED = new ErrorCode(1_011_000_031, "交易订单修改收货地址失败,原因:订单不是【待发货】状态"); + ErrorCode ORDER_CREATE_FAIL_EXIST_UNPAID = new ErrorCode(1_011_000_032, "交易订单创建失败,原因:存在未付款订单"); // ========== After Sale 模块 1-011-000-100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1_011_000_100, "售后单不存在"); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java index d68f81c61..72d05336e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java @@ -110,4 +110,16 @@ public interface TradeOrderMapper extends BaseMapperX { return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode); } + default TradeOrderDO selectByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status) { + return selectOne(new LambdaQueryWrapperX() + .and(q -> q.eq(TradeOrderDO::getUserId, userId) + .eq(TradeOrderDO::getStatus, status)) + .and(q -> q.eq(TradeOrderDO::getCombinationActivityId, activityId) + .or() + .eq(TradeOrderDO::getSeckillActivityId, activityId) + .or() + .eq(TradeOrderDO::getBargainActivityId, activityId)) + ); + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java index c2a7933e0..26b59f521 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryService.java @@ -40,6 +40,16 @@ public interface TradeOrderQueryService { */ TradeOrderDO getOrder(Long userId, Long id); + /** + * 获得指定用户,指定活动,指定状态的交易订单 + * + * @param userId 用户编号 + * @param activityId 活动编号 + * @param status 订单状态 + * @return 交易订单 + */ + TradeOrderDO getActivityOrderByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status); + /** * 获得订单列表 * @@ -95,7 +105,7 @@ public interface TradeOrderQueryService { /** * 【会员】在指定秒杀活动下,用户购买的商品数量 * - * @param userId 用户编号 + * @param userId 用户编号 * @param activityId 活动编号 * @return 秒杀商品数量 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java index eb8a0a244..547ff4603 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderQueryServiceImpl.java @@ -72,6 +72,11 @@ public class TradeOrderQueryServiceImpl implements TradeOrderQueryService { return order; } + @Override + public TradeOrderDO getActivityOrderByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status) { + return tradeOrderMapper.selectByUserIdAndActivityIdAndStatus(userId, activityId, status); + } + @Override public List getOrderList(Collection ids) { if (CollUtil.isEmpty(ids)) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 74a23ff26..ec57b1af9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -742,9 +742,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) { // 校验交易订单 TradeOrderDO order = validateOrderExists(reqVO.getId()); - // 发货后,不允许修改; - // TODO @puhui999:只有待发货,可以执行 update - if (TradeOrderStatusEnum.isDelivered(order.getStatus())) { + // 只有待发货状态才可以修改订单收货地址; + if (!TradeOrderStatusEnum.isUndelivered(order.getStatus())) { throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index 17b01ca0e..5ed8f0977 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -1,16 +1,23 @@ package cn.iocoder.yudao.module.trade.service.order.handler; import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; 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.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; +import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_CREATE_FAIL_EXIST_UNPAID; + /** * 拼团订单 handler 接口实现类 * @@ -19,6 +26,11 @@ import java.util.List; @Component public class TradeCombinationHandler implements TradeOrderHandler { + @Resource + private TradeOrderQueryService orderQueryService; + @Resource + private TradeOrderUpdateService orderUpdateService; + @Resource private CombinationRecordApi combinationRecordApi; @@ -34,21 +46,30 @@ public class TradeCombinationHandler implements TradeOrderHandler { TradeOrderItemDO item = orderItems.get(0); combinationRecordApi.validateCombinationRecord(order.getUserId(), order.getCombinationActivityId(), order.getCombinationHeadId(), item.getSkuId(), item.getCount()); - // TODO @puhui999:这里还要限制下,是不是已经 createOrder;就是还没支付的时候,重复下单了;需要校验下;不然的话,一个拼团可以下多个单子了; + // 校验该用户是否存在未支付的拼团活动订单;就是还没支付的时候,重复下单了;需要校验下;不然的话,一个拼团可以下多个单子了; + TradeOrderDO activityOrder = orderQueryService.getActivityOrderByUserIdAndActivityIdAndStatus( + order.getUserId(), order.getCombinationActivityId(), TradeOrderStatusEnum.UNPAID.getStatus()); + if (activityOrder != null) { + throw exception(ORDER_CREATE_FAIL_EXIST_UNPAID); + } } @Override public void afterPayOrder(TradeOrderDO order, List orderItems) { - // 如果不是拼团订单则结束 + // 1.如果不是拼团订单则结束 if (TradeOrderTypeEnum.isCombination(order.getType())) { return; } Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); - // 获取商品信息 + // 2.获取商品信息 TradeOrderItemDO item = orderItems.get(0); - // 创建拼团记录 - combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); + // 2.1.创建拼团记录 + KeyValue recordIdAndHeadId = combinationRecordApi.createCombinationRecord( + TradeOrderConvert.INSTANCE.convert(order, item)); + // 3.更新拼团相关信息到订单 + orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(), + recordIdAndHeadId.getKey(), recordIdAndHeadId.getValue()); } @Override From e09f07475a9d02590bd51ae57229c7f17d624fb9 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 9 Oct 2023 16:11:02 +0800 Subject: [PATCH 03/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E4=BF=9D=E5=AD=98-=E5=BE=AA=E7=8E=AF=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/bargain/AppBargainRecordController.java | 14 ++++++++++---- .../module/trade/api/order/TradeOrderApiImpl.java | 6 ++++-- .../order/handler/TradeCombinationHandler.java | 8 ++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java index d37163356..e09e9fdb8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java @@ -27,6 +27,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.context.annotation.Lazy; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -46,18 +47,23 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti public class AppBargainRecordController { @Resource + private BargainHelpService bargainHelpService; + @Resource + @Lazy private BargainRecordService bargainRecordService; @Resource + @Lazy private BargainActivityService bargainActivityService; - @Resource - private BargainHelpService bargainHelpService; + @Resource + private TradeOrderApi tradeOrderApi; + @Resource + @Lazy private MemberUserApi memberUserApi; @Resource + @Lazy private ProductSpuApi productSpuApi; - @Resource - private TradeOrderApi tradeOrderApi; @GetMapping("/get-summary") @Operation(summary = "获得砍价记录的概要信息", description = "用于小程序首页") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 1013ae71f..e872b5507 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -22,10 +23,11 @@ import java.util.List; @Validated public class TradeOrderApiImpl implements TradeOrderApi { - @Resource - private TradeOrderQueryService tradeOrderQueryService; @Resource private TradeOrderUpdateService tradeOrderUpdateService; + @Resource + @Lazy + private TradeOrderQueryService tradeOrderQueryService; @Override public List getOrderList(Collection ids) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index 5ed8f0977..c83615bda 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -27,11 +28,14 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_CREAT public class TradeCombinationHandler implements TradeOrderHandler { @Resource - private TradeOrderQueryService orderQueryService; - @Resource + @Lazy private TradeOrderUpdateService orderUpdateService; + @Resource + @Lazy + private TradeOrderQueryService orderQueryService; @Resource + @Lazy private CombinationRecordApi combinationRecordApi; @Override From cd887511d8d36878cca0ae98eca548fdda7ebae3 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 9 Oct 2023 16:18:00 +0800 Subject: [PATCH 04/21] =?UTF-8?q?=E8=90=A5=E9=94=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E4=BF=AE=E6=AD=A3=20selectListBySpuIdsAndStatus=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=20sql=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/activity/AppActivityController.http | 5 +++++ .../dal/mysql/bargain/BargainActivityMapper.java | 16 +++++++++++----- .../combination/CombinationActivityMapper.java | 16 +++++++++++----- .../seckillactivity/SeckillActivityMapper.java | 16 +++++++++++----- .../bargain/BargainActivityServiceImpl.java | 2 +- .../CombinationActivityServiceImpl.java | 2 +- .../seckill/SeckillActivityServiceImpl.java | 2 +- 7 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http new file mode 100644 index 000000000..0dda88c7d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http @@ -0,0 +1,5 @@ +### /promotion/activity/list-by-spu-ids 获得多个商品,近期参与的每个活动 +GET {{appApi}}/promotion/activity/list-by-spu-ids?spuIds=222&spuIds=633 +Authorization: Bearer {{appToken}} +Content-Type: application/json +tenant-id: {{appTenentId}} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index d12056d56..bfaed212e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.time.LocalDateTime; @@ -87,6 +88,7 @@ public interface BargainActivityMapper extends BaseMapperX { // TODO @puhui999:一个商品,在统一时间,不会参与多个活动;so 是不是不用 inner join 哈? // PS:如果可以参与多个,其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC;通过 group 来过滤 + /** * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * @@ -94,16 +96,20 @@ public interface BargainActivityMapper extends BaseMapperX { * @param status 状态 * @return 砍价活动列表 */ - @Select("SELECT p1.* " + + @Select("") + List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 1af92b538..14dfcb395 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -44,6 +44,7 @@ public interface CombinationActivityMapper extends BaseMapperX " + "SELECT p1.* " + "FROM promotion_combination_activity p1 " + "INNER JOIN ( " + - " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + + " SELECT spu_id, MAX(DISTINCT create_time) AS max_create_time " + " FROM promotion_combination_activity " + - " WHERE spu_id IN #{spuIds} " + + " WHERE spu_id IN " + + "" + + " #{spuId}" + + "" + " GROUP BY spu_id " + ") p2 " + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + - "ORDER BY p1.create_time DESC;") - List selectListBySpuIds(@Param("spuIds") Collection spuIds, @Param("status") Integer status); + "ORDER BY p1.create_time DESC;" + + " ") + List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index b3b75d36b..b82e4e3d5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppS import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.Collection; @@ -59,6 +60,7 @@ public interface SeckillActivityMapper extends BaseMapperX { } // TODO @puhui999:类似 BargainActivityMapper + /** * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * @@ -66,16 +68,20 @@ public interface SeckillActivityMapper extends BaseMapperX { * @param status 状态 * @return 秒杀活动列表 */ - @Select("SELECT p1.* " + + @Select("") + List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 0905a09a7..5cf387956 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -178,7 +178,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public List getBargainActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return bargainActivityMapper.selectListBySpuIds(spuIds, status); + return bargainActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index db907ba36..c488bdc03 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -228,7 +228,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Override public List getCombinationActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return combinationActivityMapper.selectListBySpuIds(spuIds, status); + return combinationActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index d2bbc7466..425610a50 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -312,7 +312,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override public List getSeckillActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return seckillActivityMapper.selectListBySpuIds(spuIds, status); + return seckillActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); } } From c869d99a0fe99835cacd6cff5931391687892b12 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 9 Oct 2023 16:11:02 +0800 Subject: [PATCH 05/21] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=8A=A5=E9=94=99-=E5=BE=AA=E7=8E=AF=E4=BE=9D?= =?UTF-8?q?=E8=B5=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/bargain/AppBargainRecordController.java | 14 ++++++++++---- .../module/trade/api/order/TradeOrderApiImpl.java | 6 ++++-- .../order/handler/TradeCombinationHandler.java | 8 ++++++-- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java index d37163356..e09e9fdb8 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java @@ -27,6 +27,7 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; +import org.springframework.context.annotation.Lazy; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -46,18 +47,23 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti public class AppBargainRecordController { @Resource + private BargainHelpService bargainHelpService; + @Resource + @Lazy private BargainRecordService bargainRecordService; @Resource + @Lazy private BargainActivityService bargainActivityService; - @Resource - private BargainHelpService bargainHelpService; + @Resource + private TradeOrderApi tradeOrderApi; + @Resource + @Lazy private MemberUserApi memberUserApi; @Resource + @Lazy private ProductSpuApi productSpuApi; - @Resource - private TradeOrderApi tradeOrderApi; @GetMapping("/get-summary") @Operation(summary = "获得砍价记录的概要信息", description = "用于小程序首页") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 1013ae71f..e872b5507 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -22,10 +23,11 @@ import java.util.List; @Validated public class TradeOrderApiImpl implements TradeOrderApi { - @Resource - private TradeOrderQueryService tradeOrderQueryService; @Resource private TradeOrderUpdateService tradeOrderUpdateService; + @Resource + @Lazy + private TradeOrderQueryService tradeOrderQueryService; @Override public List getOrderList(Collection ids) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index 5ed8f0977..c83615bda 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -10,6 +10,7 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; +import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -27,11 +28,14 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_CREAT public class TradeCombinationHandler implements TradeOrderHandler { @Resource - private TradeOrderQueryService orderQueryService; - @Resource + @Lazy private TradeOrderUpdateService orderUpdateService; + @Resource + @Lazy + private TradeOrderQueryService orderQueryService; @Resource + @Lazy private CombinationRecordApi combinationRecordApi; @Override From 57407a39d22b38b9e6631a7d061c65c92db575ca Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 9 Oct 2023 16:18:00 +0800 Subject: [PATCH 06/21] =?UTF-8?q?=E8=90=A5=E9=94=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E4=BF=AE=E6=AD=A3=20selectListBySpuIdsAndStatus=20?= =?UTF-8?q?=E6=9F=A5=E8=AF=A2=20sql=EF=BC=8C=E6=B7=BB=E5=8A=A0=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E6=B5=8B=E8=AF=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/activity/AppActivityController.http | 5 +++++ .../dal/mysql/bargain/BargainActivityMapper.java | 16 +++++++++++----- .../combination/CombinationActivityMapper.java | 16 +++++++++++----- .../seckillactivity/SeckillActivityMapper.java | 16 +++++++++++----- .../bargain/BargainActivityServiceImpl.java | 2 +- .../CombinationActivityServiceImpl.java | 2 +- .../seckill/SeckillActivityServiceImpl.java | 2 +- 7 files changed, 41 insertions(+), 18 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http new file mode 100644 index 000000000..0dda88c7d --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/activity/AppActivityController.http @@ -0,0 +1,5 @@ +### /promotion/activity/list-by-spu-ids 获得多个商品,近期参与的每个活动 +GET {{appApi}}/promotion/activity/list-by-spu-ids?spuIds=222&spuIds=633 +Authorization: Bearer {{appToken}} +Content-Type: application/json +tenant-id: {{appTenentId}} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index d12056d56..bfaed212e 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -8,6 +8,7 @@ import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.Ba import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.time.LocalDateTime; @@ -87,6 +88,7 @@ public interface BargainActivityMapper extends BaseMapperX { // TODO @puhui999:一个商品,在统一时间,不会参与多个活动;so 是不是不用 inner join 哈? // PS:如果可以参与多个,其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC;通过 group 来过滤 + /** * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * @@ -94,16 +96,20 @@ public interface BargainActivityMapper extends BaseMapperX { * @param status 状态 * @return 砍价活动列表 */ - @Select("SELECT p1.* " + + @Select("") + List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 1af92b538..14dfcb395 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -44,6 +44,7 @@ public interface CombinationActivityMapper extends BaseMapperX " + "SELECT p1.* " + "FROM promotion_combination_activity p1 " + "INNER JOIN ( " + - " SELECT spu_id, MAX(DISTINCT(create_time)) AS max_create_time " + + " SELECT spu_id, MAX(DISTINCT create_time) AS max_create_time " + " FROM promotion_combination_activity " + - " WHERE spu_id IN #{spuIds} " + + " WHERE spu_id IN " + + "" + + " #{spuId}" + + "" + " GROUP BY spu_id " + ") p2 " + "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + - "ORDER BY p1.create_time DESC;") - List selectListBySpuIds(@Param("spuIds") Collection spuIds, @Param("status") Integer status); + "ORDER BY p1.create_time DESC;" + + " ") + List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index b3b75d36b..b82e4e3d5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -9,6 +9,7 @@ import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppS import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Select; import java.util.Collection; @@ -59,6 +60,7 @@ public interface SeckillActivityMapper extends BaseMapperX { } // TODO @puhui999:类似 BargainActivityMapper + /** * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 * @@ -66,16 +68,20 @@ public interface SeckillActivityMapper extends BaseMapperX { * @param status 状态 * @return 秒杀活动列表 */ - @Select("SELECT p1.* " + + @Select("") + List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 0905a09a7..5cf387956 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -178,7 +178,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public List getBargainActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return bargainActivityMapper.selectListBySpuIds(spuIds, status); + return bargainActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index db907ba36..c488bdc03 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -228,7 +228,7 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Override public List getCombinationActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return combinationActivityMapper.selectListBySpuIds(spuIds, status); + return combinationActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index d2bbc7466..425610a50 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -312,7 +312,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override public List getSeckillActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return seckillActivityMapper.selectListBySpuIds(spuIds, status); + return seckillActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); } } From 831983e31430b9807ca4a7f7a12d12bf9edda1ba Mon Sep 17 00:00:00 2001 From: puhui999 Date: Mon, 9 Oct 2023 18:17:20 +0800 Subject: [PATCH 07/21] =?UTF-8?q?=E8=90=A5=E9=94=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E9=87=8D=E6=9E=84=20getCombinationActivityBySpuIdsAnd?= =?UTF-8?q?Status=20=E6=96=B9=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mysql/bargain/BargainActivityMapper.java | 38 +++++++++---------- .../CombinationActivityMapper.java | 37 ++++++++---------- .../SeckillActivityMapper.java | 38 +++++++++---------- .../bargain/BargainActivityServiceImpl.java | 15 ++++++-- .../CombinationActivityServiceImpl.java | 13 +++++-- .../seckill/SeckillActivityServiceImpl.java | 11 +++++- 6 files changed, 81 insertions(+), 71 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index bfaed212e..ea62b2005 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -6,14 +6,15 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.bargain.vo.activity.BargainActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; 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.Collection; import java.util.List; +import java.util.Map; /** * 砍价活动 Mapper @@ -86,30 +87,25 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } - // TODO @puhui999:一个商品,在统一时间,不会参与多个活动;so 是不是不用 inner join 哈? - // PS:如果可以参与多个,其实可以这样写 select * from promotion_bargain_activity group by spu_id ORDER BY create_time DESC;通过 group 来过滤 - /** - * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 + * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 * * @param spuIds spu 编号 * @param status 状态 - * @return 砍价活动列表 + * @return 包含 spuId 和 activityId 的 map 对象列表 */ - @Select("") - List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); + default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status) { + return selectMaps(new QueryWrapper() + .select("spu_id AS spuId, MAX(DISTINCT(id)) AS activityId") // 时间越大 id 也越大 直接用 id + .in("spu_id", spuIds) + .eq("status", status) + .groupBy("spu_id")); + } + + default List selectListByIds(Collection ids) { + return selectList(new LambdaQueryWrapperX() + .in(BargainActivityDO::getId, ids) + .orderByDesc(BargainActivityDO::getCreateTime)); + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java index 14dfcb395..a2d15e7f3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationActivityMapper.java @@ -6,12 +6,13 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.activity.CombinationActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; import java.util.Collection; import java.util.List; +import java.util.Map; /** * 拼团活动 Mapper @@ -43,30 +44,24 @@ public interface CombinationActivityMapper extends BaseMapperX " + "SELECT p1.* " + - "FROM promotion_combination_activity p1 " + - "INNER JOIN ( " + - " SELECT spu_id, MAX(DISTINCT create_time) AS max_create_time " + - " FROM promotion_combination_activity " + - " WHERE spu_id IN " + - "" + - " #{spuId}" + - "" + - " GROUP BY spu_id " + - ") p2 " + - "ON p1.spu_id = p2.spu_id AND p1.create_time = p2.max_create_time AND p1.status = #{status} " + - "ORDER BY p1.create_time DESC;" + - " ") - List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); + default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status) { + return selectMaps(new QueryWrapper() + .select("spu_id AS spuId, MAX(DISTINCT(id)) AS activityId") // 时间越大 id 也越大 直接用 id + .in("spu_id", spuIds) + .eq("status", status) + .groupBy("spu_id")); + } + default List selectListByIds(Collection ids) { + return selectList(new LambdaQueryWrapperX() + .in(CombinationActivityDO::getId, ids) + .orderByDesc(CombinationActivityDO::getCreateTime)); + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index b82e4e3d5..75c26119f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -7,13 +7,14 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.promotion.controller.admin.seckill.vo.activity.SeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.controller.app.seckill.vo.activity.AppSeckillActivityPageReqVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillActivityDO; +import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; -import org.apache.ibatis.annotations.Select; import java.util.Collection; import java.util.List; +import java.util.Map; /** * 秒杀活动 Mapper @@ -59,29 +60,24 @@ public interface SeckillActivityMapper extends BaseMapperX { .apply(ObjectUtil.isNotNull(pageReqVO.getConfigId()), "FIND_IN_SET(" + pageReqVO.getConfigId() + ",config_ids) > 0")); } - // TODO @puhui999:类似 BargainActivityMapper - /** - * 获取指定 spu 编号最近参加的活动,每个 spuId 只返回一条记录 - * + * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 * @param spuIds spu 编号 * @param status 状态 - * @return 秒杀活动列表 + * @return 包含 spuId 和 activityId 的 map 对象列表 */ - @Select("") - List selectListBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status); + default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status) { + return selectMaps(new QueryWrapper() + .select("spu_id AS spuId, MAX(DISTINCT(id)) AS activityId") // 时间越大 id 也越大 直接用 id + .in("spu_id", spuIds) + .eq("status", status) + .groupBy("spu_id")); + } + + default List selectListByIds(Collection ids) { + return selectList(new LambdaQueryWrapperX() + .in(SeckillActivityDO::getId, ids) + .orderByDesc(SeckillActivityDO::getCreateTime)); + } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 5cf387956..8d10f0247 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -1,5 +1,7 @@ package cn.iocoder.yudao.module.promotion.service.bargain; +import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; @@ -20,12 +22,11 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.Collection; -import java.util.List; -import java.util.Set; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.anyMatch; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -178,7 +179,13 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public List getBargainActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return bargainActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); + // 1.查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 + List> spuIdAndActivityIdMaps = bargainActivityMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); + if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { + return Collections.emptyList(); + } + // 2.查询活动详情 + return bargainActivityMapper.selectListByIds(convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId"))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java index c488bdc03..dae388410 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationActivityServiceImpl.java @@ -1,6 +1,7 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageParam; @@ -25,12 +26,12 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.filterList; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SKU_NOT_EXISTS; import static cn.iocoder.yudao.module.product.enums.ErrorCodeConstants.SPU_NOT_EXISTS; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -228,7 +229,13 @@ public class CombinationActivityServiceImpl implements CombinationActivityServic @Override public List getCombinationActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return combinationActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); + // 1.查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 + List> spuIdAndActivityIdMaps = combinationActivityMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); + if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { + return Collections.emptyList(); + } + // 2.查询活动详情 + return combinationActivityMapper.selectListByIds(convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId"))); } } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 425610a50..4b35161a5 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -1,6 +1,8 @@ package cn.iocoder.yudao.module.promotion.service.seckill; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -27,6 +29,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -312,7 +315,13 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override public List getSeckillActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - return seckillActivityMapper.selectListBySpuIdsAndStatus(spuIds, status); + // 1.查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 + List> spuIdAndActivityIdMaps = seckillActivityMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); + if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { + return Collections.emptyList(); + } + // 2.查询活动详情 + return seckillActivityMapper.selectListByIds(convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId"))); } } From df16278a03daab9ce37e3ab450fde204ca43ecf8 Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 9 Oct 2023 23:27:10 +0800 Subject: [PATCH 08/21] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=EF=BC=9A=E4=BC=9A?= =?UTF-8?q?=E5=91=98=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 | 14 ++- .../util/collection/CollectionUtils.java | 12 +- .../framework/ip/core/utils/AreaUtils.java | 37 +++++- .../yudao-module-statistics-biz/pom.xml | 5 + .../member/MemberStatisticsController.java | 47 +++++--- .../vo/MemberAnalyseComparisonRespVO.java | 19 +++ .../admin/member/vo/MemberAnalyseReqVO.java | 19 +++ .../admin/member/vo/MemberAnalyseRespVO.java | 26 ++++ .../member/vo/MemberSexStatisticsRespVO.java | 7 -- .../admin/member/vo/MemberSummaryRespVO.java | 1 + .../vo/MemberTerminalStatisticsRespVO.java | 9 +- .../member/MemberStatisticsConvert.java | 39 ++++++ .../infra/ApiAccessLogStatisticsMapper.java | 21 ++++ .../mysql/member/MemberStatisticsMapper.java | 26 ++++ .../PayWalletStatisticsMapper.java | 8 +- .../trade/TradeOrderStatisticsMapper.java | 21 +++- .../mysql/trade/TradeStatisticsMapper.java | 3 + .../infra/ApiAccessLogStatisticsService.java | 30 +++++ .../ApiAccessLogStatisticsServiceImpl.java | 31 +++++ .../member/MemberStatisticsService.java | 48 ++++++++ .../member/MemberStatisticsServiceImpl.java | 114 ++++++++++++++++++ .../PayWalletStatisticsService.java | 12 +- .../PayWalletStatisticsServiceImpl.java | 12 +- .../trade/TradeOrderStatisticsService.java | 36 ++++++ .../TradeOrderStatisticsServiceImpl.java | 27 ++++- .../service/trade/TradeStatisticsService.java | 9 +- .../trade/TradeStatisticsServiceImpl.java | 6 + .../trade/bo/TradeOrderSummaryRespBO.java | 2 +- .../infra/ApiAccessLogStatisticsMapper.xml | 20 +++ .../mapper/member/MemberStatisticsMapper.xml | 34 ++++++ .../trade/TradeOrderStatisticsMapper.xml | 62 ++++++++-- .../mapper/trade/TradeStatisticsMapper.xml | 13 +- .../PayWalletStatisticsMapper.xml | 18 ++- .../src/main/resources/application-local.yaml | 1 + 34 files changed, 731 insertions(+), 58 deletions(-) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseReqVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java rename yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/{trade => pay}/PayWalletStatisticsMapper.java (75%) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java rename yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/{trade => pay}/PayWalletStatisticsService.java (53%) rename yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/{trade => pay}/PayWalletStatisticsServiceImpl.java (77%) create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml create mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml rename yudao-module-mall/yudao-module-statistics-biz/src/main/resources/{mapper/trade => pay}/PayWalletStatisticsMapper.xml (69%) diff --git a/sql/mysql/statistics.sql b/sql/mysql/statistics.sql index 48f1c4ad4..0decf1ef1 100644 --- a/sql/mysql/statistics.sql +++ b/sql/mysql/statistics.sql @@ -28,16 +28,22 @@ 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) +INSERT INTO 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'); +-- 交易统计 +INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) +VALUES ('交易统计', '', 2, 1, @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); +-- 会员统计 +INSERT INTO system_menu (name, permission, type, sort, parent_id, path, icon, component, component_name) +VALUES ('会员统计', '', 2, 2, @parentId, 'member', 'ep:avatar', 'statistics/member/index', 'MemberStatistics'); +SELECT @parentId := LAST_INSERT_ID(); +INSERT INTO system_menu(name, permission, type, sort, parent_id, path, icon, component, status) +VALUES ('会员统计查询', 'statistics:member:query', 3, 1, @parentId, '', '', '', 0); diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index 12d18dc95..289ee1603 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.framework.common.util.collection; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.collection.CollectionUtil; +import cn.hutool.core.util.ArrayUtil; import com.google.common.collect.ImmutableMap; import java.util.*; @@ -50,6 +51,13 @@ public class CollectionUtils { return new ArrayList<>(convertMap(from, keyMapper, Function.identity(), cover).values()); } + public static List convertList(T[] from, Function func) { + if (ArrayUtil.isEmpty(from)) { + return new ArrayList<>(); + } + return convertList(Arrays.asList(from), func); + } + public static List convertList(Collection from, Function func) { if (CollUtil.isEmpty(from)) { return new ArrayList<>(); @@ -162,8 +170,8 @@ public class CollectionUtils { /** * 对比老、新两个列表,找出新增、修改、删除的数据 * - * @param oldList 老列表 - * @param newList 新列表 + * @param oldList 老列表 + * @param newList 新列表 * @param sameFunc 对比函数,返回 true 表示相同,返回 false 表示不同 * 注意,same 是通过每个元素的“标识”,判断它们是不是同一个数据 * @return [新增列表、修改列表、删除列表] diff --git a/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java b/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java index d3fe59a6c..8455dff9a 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java @@ -7,12 +7,16 @@ import cn.hutool.core.text.csv.CsvUtil; import cn.iocoder.yudao.framework.common.util.object.ObjectUtils; import cn.iocoder.yudao.framework.ip.core.Area; import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; +import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.function.Function; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; /** * 区域工具类 @@ -108,7 +112,7 @@ public class AreaUtils { // “递归”父节点 area = area.getParent(); if (area == null - || ObjectUtils.equalsAny(area.getId(), Area.ID_GLOBAL, Area.ID_CHINA)) { // 跳过父节点为中国的情况 + || ObjectUtils.equalsAny(area.getId(), Area.ID_GLOBAL, Area.ID_CHINA)) { // 跳过父节点为中国的情况 break; } sb.insert(0, separator); @@ -116,4 +120,35 @@ public class AreaUtils { return sb.toString(); } + /** + * 获取指定类型的区域列表 + * + * @param type 区域类型 + * @param func 转换函数 + * @param 结果类型 + * @return 区域列表 + */ + public static List getByType(AreaTypeEnum type, Function func) { + return convertList(areas.values(), func, area -> type.getType().equals(area.getType())); + } + + public static Integer getParentIdByType(Integer id, @NonNull AreaTypeEnum type) { + do { + Area area = AreaUtils.getArea(id); + if (area == null) { + return null; + } + + if (type.getType().equals(area.getType())) { + return area.getId(); + } + + if (area.getParent() == null || area.getParent().getId() == null) { + return null; + } + + id = area.getParent().getId(); + } while (true); + } + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/pom.xml b/yudao-module-mall/yudao-module-statistics-biz/pom.xml index dd04c47c8..5490715fa 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/pom.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/pom.xml @@ -59,6 +59,11 @@ yudao-spring-boot-starter-biz-tenant + + cn.iocoder.boot + yudao-spring-boot-starter-biz-ip + + cn.iocoder.boot diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java index f4f0f3d92..3d10f667a 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/MemberStatisticsController.java @@ -1,21 +1,25 @@ package cn.iocoder.yudao.module.statistics.controller.admin.member; +import cn.hutool.core.util.ArrayUtil; +import cn.iocoder.yudao.framework.common.enums.TerminalEnum; import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberTerminalStatisticsRespVO; -import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*; +import cn.iocoder.yudao.module.statistics.service.member.MemberStatisticsService; 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 java.util.List; +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; + @Tag(name = "管理后台 - 会员统计") @RestController @RequestMapping("/statistics/member") @@ -23,36 +27,47 @@ import java.util.List; @Slf4j public class MemberStatisticsController { - // TODO @疯狂:一个类似 getTradeTrendSummaryComparison 的接口 - // TODO @疯狂:一个类似 getTradeStatisticsList 的接口 + @Resource + private MemberStatisticsService memberStatisticsService; @GetMapping("/summary") @Operation(summary = "获得会员统计") - public CommonResult> getMemberSummary() { - // TODO 疯狂:目前先直接计算; - return null; + @PreAuthorize("@ss.hasPermission('statistics:member:query')") + public CommonResult getMemberSummary() { + return success(memberStatisticsService.getMemberSummary()); + } + + @GetMapping("/analyse") + @Operation(summary = "获得会员分析数据") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") + public CommonResult getMemberAnalyse(MemberAnalyseReqVO reqVO) { + return success(memberStatisticsService.getMemberAnalyse( + ArrayUtil.get(reqVO.getTimes(), 0), ArrayUtil.get(reqVO.getTimes(), 1))); } @GetMapping("/get-area-statistics-list") @Operation(summary = "按照省份,获得会员统计列表") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") public CommonResult> getMemberAreaStatisticsList() { - // TODO 疯狂:目前先直接计算,进行统计;后续再考虑优化 - return null; + return success(memberStatisticsService.getMemberAreaStatisticsList()); } @GetMapping("/get-sex-statistics-list") @Operation(summary = "按照性别,获得会员统计列表") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") public CommonResult> getMemberSexStatisticsList() { - // TODO 疯狂:目前先直接计算,进行统计;后续再考虑优化 - return null; + return success(memberStatisticsService.getMemberSexStatisticsList()); } @GetMapping("/get-terminal-statistics-list") @Operation(summary = "按照终端,获得会员统计列表") + @PreAuthorize("@ss.hasPermission('statistics:member:query')") public CommonResult> getMemberTerminalStatisticsList() { - // TODO 疯狂:目前先直接计算,进行统计;后续再考虑优化 // TODO 疯狂:这个可以晚点写,因为 user = = 上还没记录 terminal - return null; + List list = convertList(TerminalEnum.values(), + t -> new MemberTerminalStatisticsRespVO() + .setTerminal(t.getTerminal()).setUserCount(t.getTerminal() * 100)); + return success(list); } } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java new file mode 100644 index 000000000..cf8551d0c --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseComparisonRespVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 会员分析对照数据 Response VO") +@Data +public class MemberAnalyseComparisonRespVO { + + @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer userCount; + + @Schema(description = "活跃用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer activeUserCount; + + @Schema(description = "充值会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "221") + private Integer rechargeUserCount; + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseReqVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseReqVO.java new file mode 100644 index 000000000..e0106b4e8 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseReqVO.java @@ -0,0 +1,19 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.member.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 MemberAnalyseReqVO { + + @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/member/vo/MemberAnalyseRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java new file mode 100644 index 000000000..0f4a3d1ff --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberAnalyseRespVO.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; + +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; + +@Schema(description = "管理后台 - 会员分析 Response VO") +@Data +public class MemberAnalyseRespVO { + + @Schema(description = "访客数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer visitorCount; + + @Schema(description = "下单用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer orderUserCount; + + @Schema(description = "成交用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer payUserCount; + + @Schema(description = "客单价", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + private Integer atv; + + @Schema(description = "对照数据", requiredMode = Schema.RequiredMode.REQUIRED) + private TradeStatisticsComparisonRespVO comparison; + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java index 83a0b17e8..975f2a871 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSexStatisticsRespVO.java @@ -13,11 +13,4 @@ public class MemberSexStatisticsRespVO { @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer userCount; - @Schema(description = "订单创建数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer orderCreateCount; - @Schema(description = "订单支付数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512") - private Integer orderPayCount; - @Schema(description = "订单支付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "622") - private Integer orderPayPrice; - } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java index ab79dfeeb..1dacd449c 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberSummaryRespVO.java @@ -15,6 +15,7 @@ public class MemberSummaryRespVO { @Schema(description = "充值金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer rechargePrice; + @Schema(description = "支出金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer expensePrice; diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java index 06112e3b0..e3aeaedc2 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/vo/MemberTerminalStatisticsRespVO.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.statistics.controller.admin.member.vo; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; -@Schema(description = "管理后台 - 终端性别统计 Response VO") +@Schema(description = "管理后台 - 会员终端统计 Response VO") @Data public class MemberTerminalStatisticsRespVO { @@ -13,11 +13,4 @@ public class MemberTerminalStatisticsRespVO { @Schema(description = "会员数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Integer userCount; - @Schema(description = "订单创建数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") - private Integer orderCreateCount; - @Schema(description = "订单支付数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "512") - private Integer orderPayCount; - @Schema(description = "订单支付金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "622") - private Integer orderPayPrice; - } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java new file mode 100644 index 000000000..0eceada3f --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/convert/member/MemberStatisticsConvert.java @@ -0,0 +1,39 @@ +package cn.iocoder.yudao.module.statistics.convert.member; + +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjUtil; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.ip.core.Area; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; +import org.mapstruct.Mapper; +import org.mapstruct.factory.Mappers; + +import java.util.List; +import java.util.Map; +import java.util.Optional; + +/** + * 会员统计 Convert + * + * @author owen + */ +@Mapper +public interface MemberStatisticsConvert { + + MemberStatisticsConvert INSTANCE = Mappers.getMapper(MemberStatisticsConvert.class); + + default List convertList(List areaList, + Map userCountMap, + Map orderMap) { + return CollectionUtils.convertList(areaList, area -> { + MemberAreaStatisticsRespVO orderVo = Optional.ofNullable(orderMap.get(area.getId())).orElseGet(MemberAreaStatisticsRespVO::new); + return new MemberAreaStatisticsRespVO() + .setAreaId(area.getId()).setAreaName(area.getName()) + .setUserCount(MapUtil.getInt(userCountMap, area.getId(), 0)) + .setOrderCreateCount(ObjUtil.defaultIfNull(orderVo.getOrderCreateCount(), 0)) + .setOrderPayCount(ObjUtil.defaultIfNull(orderVo.getOrderPayCount(), 0)) + .setOrderPayPrice(ObjUtil.defaultIfNull(orderVo.getOrderPayPrice(), 0)); + }); + } + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java new file mode 100644 index 000000000..0e8d719ad --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.infra; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; + +/** + * API 访问日志统计 Mapper + * + * @author owen + */ +@Mapper +public interface ApiAccessLogStatisticsMapper extends BaseMapperX { + + Integer selectCountByIp(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + Integer selectCountByUserId(@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/dal/mysql/member/MemberStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java new file mode 100644 index 000000000..22a89ea9d --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.statistics.dal.mysql.member; + +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Param; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 会员统计 Mapper + * + * @author owen + */ +@Mapper +public interface MemberStatisticsMapper extends BaseMapperX { + + List selectSummaryListByAreaId(); + + List selectSummaryListBySex(); + + Integer selectUserCount(@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/dal/mysql/trade/PayWalletStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java similarity index 75% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/PayWalletStatisticsMapper.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java index 126a1557b..75e6a4ae1 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/trade/PayWalletStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java @@ -1,6 +1,7 @@ -package cn.iocoder.yudao.module.statistics.dal.mysql.trade; +package cn.iocoder.yudao.module.statistics.dal.mysql.pay; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import cn.iocoder.yudao.module.statistics.dal.dataobject.trade.TradeStatisticsDO; import org.apache.ibatis.annotations.Mapper; @@ -27,4 +28,9 @@ public interface PayWalletStatisticsMapper extends BaseMapperX { - TradeOrderSummaryRespBO selectSummaryByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, - @Param("endTime") LocalDateTime endTime); + List selectSummaryListByAreaId(); + + Integer selectCountByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectCountByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectSummaryPriceByPayTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectUserCountByCreateTimeBetween(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); + + Integer selectUserCountByPayTimeBetween(@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/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 index c1760fe30..b3680c97f 100644 --- 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 @@ -30,4 +30,7 @@ public interface TradeStatisticsMapper extends BaseMapperX { List selectListByTimeBetween(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + + Integer selectExpensePriceByTimeBetween(@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/infra/ApiAccessLogStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java new file mode 100644 index 000000000..c83f4da82 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.statistics.service.infra; + +import java.time.LocalDateTime; + +/** + * API 访问日志统计 Service 接口 + * + * @author owen + */ +public interface ApiAccessLogStatisticsService { + + /** + * 获取活跃用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 活跃用户数量 + */ + Integer getActiveUserCount(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取访问用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 访问用户数量 + */ + Integer getVisitorUserCount(LocalDateTime beginTime, LocalDateTime endTime); + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java new file mode 100644 index 000000000..4c9fb08e2 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java @@ -0,0 +1,31 @@ +package cn.iocoder.yudao.module.statistics.service.infra; + +import cn.iocoder.yudao.module.statistics.dal.mysql.infra.ApiAccessLogStatisticsMapper; +import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; + +import javax.annotation.Resource; +import java.time.LocalDateTime; + +/** + * API 访问日志统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class ApiAccessLogStatisticsServiceImpl implements ApiAccessLogStatisticsService { + + @Resource + private ApiAccessLogStatisticsMapper apiAccessLogStatisticsMapper; + + @Override + public Integer getActiveUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return apiAccessLogStatisticsMapper.selectCountByUserId(beginTime, endTime); + } + + @Override + public Integer getVisitorUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return apiAccessLogStatisticsMapper.selectCountByIp(beginTime, endTime); + } +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java new file mode 100644 index 000000000..2c84c3616 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java @@ -0,0 +1,48 @@ +package cn.iocoder.yudao.module.statistics.service.member; + +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAnalyseRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSexStatisticsRespVO; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 会员统计 Service 接口 + * + * @author owen + */ +public interface MemberStatisticsService { + + /** + * 按照省份,获得会员统计列表 + * + * @return 会员统计列表 + */ + List getMemberAreaStatisticsList(); + + /** + * 按照性别,获得会员统计列表 + * + * @return 会员统计列表 + */ + List getMemberSexStatisticsList(); + + /** + * 获取用户分析数据 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 用户分析数据 + */ + MemberAnalyseRespVO getMemberAnalyse(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取会员统计 + * + * @return 会员统计 + */ + MemberSummaryRespVO getMemberSummary(); + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java new file mode 100644 index 000000000..153e7c581 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java @@ -0,0 +1,114 @@ +package cn.iocoder.yudao.module.statistics.service.member; + +import cn.hutool.core.util.NumberUtil; +import cn.iocoder.yudao.framework.ip.core.enums.AreaTypeEnum; +import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.*; +import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; +import cn.iocoder.yudao.module.statistics.convert.member.MemberStatisticsConvert; +import cn.iocoder.yudao.module.statistics.dal.mysql.member.MemberStatisticsMapper; +import cn.iocoder.yudao.module.statistics.service.infra.ApiAccessLogStatisticsService; +import cn.iocoder.yudao.module.statistics.service.pay.PayWalletStatisticsService; +import cn.iocoder.yudao.module.statistics.service.trade.TradeOrderStatisticsService; +import cn.iocoder.yudao.module.statistics.service.trade.TradeStatisticsService; +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.util.List; +import java.util.Map; +import java.util.Optional; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; + +/** + * 会员统计 Service 实现类 + * + * @author owen + */ +@Service +@Validated +public class MemberStatisticsServiceImpl implements MemberStatisticsService { + + @Resource + private MemberStatisticsMapper memberStatisticsMapper; + + @Resource + private PayWalletStatisticsService payWalletStatisticsService; + @Resource + private TradeStatisticsService tradeStatisticsService; + @Resource + private TradeOrderStatisticsService tradeOrderStatisticsService; + @Resource + private ApiAccessLogStatisticsService apiAccessLogStatisticsService; + + @Override + public List getMemberAreaStatisticsList() { + // 统计用户 + Map userCountMap = convertMap(memberStatisticsMapper.selectSummaryListByAreaId(), + vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE), + MemberAreaStatisticsRespVO::getUserCount, Integer::sum); + // 统计订单 + Map orderMap = convertMap(tradeOrderStatisticsService.getSummaryListByAreaId(), + vo -> AreaUtils.getParentIdByType(vo.getAreaId(), AreaTypeEnum.PROVINCE), + vo -> vo, + (a, b) -> new MemberAreaStatisticsRespVO() + .setOrderCreateCount(a.getOrderCreateCount() + b.getOrderCreateCount()) + .setOrderPayCount(a.getOrderPayCount() + b.getOrderPayCount()) + .setOrderPayPrice(a.getOrderPayPrice() + b.getOrderPayPrice())); + // 拼接数据 + return MemberStatisticsConvert.INSTANCE.convertList(AreaUtils.getByType(AreaTypeEnum.PROVINCE, area -> area), userCountMap, orderMap); + } + + @Override + public List getMemberSexStatisticsList() { + return memberStatisticsMapper.selectSummaryListBySex(); + } + + @Override + public MemberAnalyseRespVO getMemberAnalyse(LocalDateTime beginTime, LocalDateTime endTime) { + // 对照数据 + MemberAnalyseComparisonRespVO vo = getMemberAnalyseComparisonData(beginTime, endTime); + LocalDateTime referenceBeginTime = beginTime.minus(Duration.between(beginTime, endTime)); + MemberAnalyseComparisonRespVO reference = getMemberAnalyseComparisonData(referenceBeginTime, beginTime); + + Integer payUserCount = tradeOrderStatisticsService.getPayUserCount(beginTime, endTime); + // 计算客单价 + int atv = 0; + if (payUserCount != null && payUserCount > 0) { + Integer payPrice = tradeOrderStatisticsService.getOrderPayPrice(beginTime, endTime); + atv = NumberUtil.div(payPrice, payUserCount).intValue(); + } + return new MemberAnalyseRespVO() + .setVisitorCount(apiAccessLogStatisticsService.getVisitorUserCount(beginTime, endTime)) + .setOrderUserCount(tradeOrderStatisticsService.getOrderUserCount(beginTime, endTime)) + .setPayUserCount(payUserCount) + .setAtv(atv) + .setComparison(new TradeStatisticsComparisonRespVO<>(vo, reference)); + } + + @Override + public MemberSummaryRespVO getMemberSummary() { + MemberSummaryRespVO vo = payWalletStatisticsService.getUserRechargeSummary(null, null); + Integer expensePrice = tradeStatisticsService.getExpensePrice(null, null); + Integer userCount = memberStatisticsMapper.selectUserCount(null, null); + + if (vo == null) { + vo = new MemberSummaryRespVO().setRechargeUserCount(0).setRechargePrice(0); + } + + return vo.setUserCount(userCount).setExpensePrice(expensePrice); + } + + private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) { + Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime)) + .map(MemberSummaryRespVO::getRechargeUserCount).orElse(0); + return new MemberAnalyseComparisonRespVO() + .setUserCount(memberStatisticsMapper.selectUserCount(beginTime, endTime)) + .setActiveUserCount(apiAccessLogStatisticsService.getActiveUserCount(beginTime, endTime)) + .setRechargeUserCount(rechargeUserCount); + } + +} diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java similarity index 53% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java index 6eb03d7f8..77e3e4fd2 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java @@ -1,5 +1,6 @@ -package cn.iocoder.yudao.module.statistics.service.trade; +package cn.iocoder.yudao.module.statistics.service.pay; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import java.time.LocalDateTime; @@ -20,4 +21,13 @@ public interface PayWalletStatisticsService { */ WalletSummaryRespBO getWalletSummary(LocalDateTime beginTime, LocalDateTime endTime); + /** + * 获取钱包充值统计 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 钱包充值统计 + */ + MemberSummaryRespVO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime); + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java similarity index 77% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java rename to yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java index 95f073de1..28b1f434e 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/PayWalletStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java @@ -1,9 +1,10 @@ -package cn.iocoder.yudao.module.statistics.service.trade; +package cn.iocoder.yudao.module.statistics.service.pay; -import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import cn.iocoder.yudao.module.pay.enums.member.PayWalletBizTypeEnum; import cn.iocoder.yudao.module.pay.enums.refund.PayRefundStatusEnum; -import cn.iocoder.yudao.module.statistics.dal.mysql.trade.PayWalletStatisticsMapper; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberSummaryRespVO; +import cn.iocoder.yudao.module.statistics.dal.mysql.pay.PayWalletStatisticsMapper; +import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -38,4 +39,9 @@ public class PayWalletStatisticsServiceImpl implements PayWalletStatisticsServic return paySummary; } + @Override + public MemberSummaryRespVO getUserRechargeSummary(LocalDateTime beginTime, LocalDateTime endTime) { + return payWalletStatisticsMapper.selectRechargeSummaryGroupByWalletId(beginTime, endTime, true); + } + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java index 8ae3f89a3..b02745e6f 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java @@ -1,8 +1,10 @@ package cn.iocoder.yudao.module.statistics.service.trade; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; import java.time.LocalDateTime; +import java.util.List; /** * 交易订单统计 Service 接口 @@ -20,4 +22,38 @@ public interface TradeOrderStatisticsService { */ TradeOrderSummaryRespBO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); + /** + * 获取地区订单统计 + * + * @return 订单统计结果 + */ + List getSummaryListByAreaId(); + + /** + * 获取下单用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 支付下单数量 + */ + Integer getOrderUserCount(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取支付用户数量 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 支付用户数量 + */ + Integer getPayUserCount(LocalDateTime beginTime, LocalDateTime endTime); + + /** + * 获取支付金额 + * + * @param beginTime 起始时间 + * @param endTime 截止时间 + * @return 支付用户金额 + */ + Integer getOrderPayPrice(LocalDateTime beginTime, LocalDateTime endTime); + } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java index d3449abd8..10dd180d0 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.statistics.service.trade; +import cn.iocoder.yudao.module.statistics.controller.admin.member.vo.MemberAreaStatisticsRespVO; import cn.iocoder.yudao.module.statistics.dal.mysql.trade.TradeOrderStatisticsMapper; import cn.iocoder.yudao.module.statistics.service.trade.bo.TradeOrderSummaryRespBO; import org.springframework.stereotype.Service; @@ -7,6 +8,7 @@ import org.springframework.validation.annotation.Validated; import javax.annotation.Resource; import java.time.LocalDateTime; +import java.util.List; /** * 交易订单统计 Service 实现类 @@ -22,7 +24,30 @@ public class TradeOrderStatisticsServiceImpl implements TradeOrderStatisticsServ @Override public TradeOrderSummaryRespBO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { - return tradeOrderStatisticsMapper.selectSummaryByPayTimeBetween(beginTime, endTime); + return new TradeOrderSummaryRespBO() + .setOrderCreateCount(tradeOrderStatisticsMapper.selectCountByCreateTimeBetween(beginTime, endTime)) + .setOrderPayCount(tradeOrderStatisticsMapper.selectCountByPayTimeBetween(beginTime, endTime)) + .setOrderPayPrice(tradeOrderStatisticsMapper.selectSummaryPriceByPayTimeBetween(beginTime, endTime)); + } + + @Override + public List getSummaryListByAreaId() { + return tradeOrderStatisticsMapper.selectSummaryListByAreaId(); + } + + @Override + public Integer getOrderUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeOrderStatisticsMapper.selectUserCountByCreateTimeBetween(beginTime, endTime); + } + + @Override + public Integer getPayUserCount(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeOrderStatisticsMapper.selectUserCountByPayTimeBetween(beginTime, endTime); + } + + @Override + public Integer getOrderPayPrice(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeOrderStatisticsMapper.selectSummaryPriceByPayTimeBetween(beginTime, 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 index b7ddcb1ea..41b709e77 100644 --- 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 @@ -22,13 +22,20 @@ public interface TradeStatisticsService { TradeStatisticsComparisonRespVO getTradeSummaryComparison(); /** - * 获得交易状况统计 + * 获得交易状况统计对照 * * @return 统计数据对照 */ TradeStatisticsComparisonRespVO getTradeTrendSummaryComparison( LocalDateTime beginTime, LocalDateTime endTime); + /** + * 获得交易状况统计 + * + * @return 统计数据对照 + */ + Integer getExpensePrice(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 index 1fc075b0e..7a25dfe89 100644 --- 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 @@ -2,6 +2,7 @@ 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.statistics.service.pay.PayWalletStatisticsService; import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeStatisticsComparisonRespVO; import cn.iocoder.yudao.module.statistics.controller.admin.trade.vo.TradeSummaryRespVO; @@ -68,6 +69,11 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { return TradeStatisticsConvert.INSTANCE.convert(value, reference); } + @Override + public Integer getExpensePrice(LocalDateTime beginTime, LocalDateTime endTime) { + return tradeStatisticsMapper.selectExpensePriceByTimeBetween(beginTime, endTime); + } + @Override public List getTradeStatisticsList(LocalDateTime beginTime, LocalDateTime endTime) { return tradeStatisticsMapper.selectListByTimeBetween(beginTime, endTime); diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java index 521762846..bc4f3903b 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/TradeOrderSummaryRespBO.java @@ -13,7 +13,7 @@ public class TradeOrderSummaryRespBO { /** * 创建订单数 */ - private Long orderCreateCount; + private Integer orderCreateCount; /** * 支付订单商品数 */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml new file mode 100644 index 000000000..2ef803ac1 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml @@ -0,0 +1,20 @@ + + + + + + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml new file mode 100644 index 000000000..decdd78a6 --- /dev/null +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml @@ -0,0 +1,34 @@ + + + + + + + + + + \ No newline at end of file diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml index f8553b481..0d585f2a2 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml @@ -1,16 +1,64 @@ - + SELECT receiver_area_id AS areaId, (SELECT COUNT(1) - FROM trade_order - WHERE deleted = FALSE - AND create_time BETWEEN #{beginTime} AND #{endTime}) AS orderPayPrice + FROM trade_order AS s + WHERE s.receiver_area_id = m.receiver_area_id) AS orderCreateCount, + (SELECT COUNT(1) + FROM trade_order AS s + WHERE s.receiver_area_id = m.receiver_area_id + AND s.pay_status = TRUE + AND s.deleted = FALSE) AS orderPayCount, + (SELECT SUM(s.pay_price) + FROM trade_order AS s + WHERE s.receiver_area_id = m.receiver_area_id + AND s.pay_status = TRUE + AND s.deleted = FALSE) AS orderPayPrice + FROM trade_order m + WHERE deleted = FALSE + GROUP BY receiver_area_id + + + + + + + + + + + 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 index f01a2eeb8..06f8cf993 100644 --- 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 @@ -1,7 +1,6 @@ - + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml similarity index 69% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml rename to yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml index 7a0dd1e26..e03f490a3 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/PayWalletStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml @@ -1,6 +1,6 @@ - + + + diff --git a/yudao-server/src/main/resources/application-local.yaml b/yudao-server/src/main/resources/application-local.yaml index 9761e0e05..0dcc2d4a6 100644 --- a/yudao-server/src/main/resources/application-local.yaml +++ b/yudao-server/src/main/resources/application-local.yaml @@ -167,6 +167,7 @@ logging: cn.iocoder.yudao.module.member.dal.mysql: debug cn.iocoder.yudao.module.trade.dal.mysql: debug cn.iocoder.yudao.module.promotion.dal.mysql: debug + cn.iocoder.yudao.module.statistics.dal.mysql: debug debug: false From 91d0bbf8b1a056e735ac49ccf0290ea9dd480b55 Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 9 Oct 2023 23:40:11 +0800 Subject: [PATCH 09/21] =?UTF-8?q?=E5=90=88=E5=B9=B6=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../yudao/module/trade/api/order/TradeOrderApiImpl.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 28b420f60..a4c7f1447 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -49,13 +49,4 @@ public class TradeOrderApiImpl implements TradeOrderApi { tradeOrderUpdateService.cancelPaidOrder(userId, orderId); } - @Override - public Integer getOrderStatus(Long id) { - TradeOrderDO order = tradeOrderQueryService.getOrder(id); - if (order == null) { - throw exception(ORDER_NOT_FOUND); - } - return order.getStatus(); - } - } From 2c10dde19514c1189d17faeada3e2c7cdf30e5bf Mon Sep 17 00:00:00 2001 From: owen Date: Mon, 9 Oct 2023 23:53:50 +0800 Subject: [PATCH 10/21] =?UTF-8?q?=E7=BB=9F=E8=AE=A1=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E5=A4=8D=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/resources/{ => mapper}/pay/PayWalletStatisticsMapper.xml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename yudao-module-mall/yudao-module-statistics-biz/src/main/resources/{ => mapper}/pay/PayWalletStatisticsMapper.xml (100%) diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml similarity index 100% rename from yudao-module-mall/yudao-module-statistics-biz/src/main/resources/pay/PayWalletStatisticsMapper.xml rename to yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml From 245f14b8f1f4e6b5f1cf38db55a6f81505da11c7 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 10 Oct 2023 10:25:57 +0800 Subject: [PATCH 11/21] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E6=88=90=E8=AE=A2=E5=8D=95=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=97=B6=E6=81=A2=E5=A4=8D=E6=B4=BB=E5=8A=A8=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=92=8C=E5=95=86=E5=93=81=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/seckill/SeckillActivityApi.java | 23 ++++++++++++------ .../api/seckill/SeckillActivityApiImpl.java | 9 +++++-- .../dataobject/seckill/SeckillActivityDO.java | 3 ++- .../SeckillActivityMapper.java | 24 ++++++++++++++++--- .../seckillactivity/SeckillProductMapper.java | 22 ++++++++++++++--- .../seckill/SeckillActivityService.java | 19 +++++++++++---- .../seckill/SeckillActivityServiceImpl.java | 16 ++++++++++--- .../order/handler/TradeSeckillHandler.java | 10 +++++++- 8 files changed, 101 insertions(+), 25 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java index 11b75e03c..0d65919d1 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApi.java @@ -10,13 +10,22 @@ import cn.iocoder.yudao.module.promotion.api.seckill.dto.SeckillValidateJoinResp public interface SeckillActivityApi { /** - * 更新秒杀库存 + * 更新秒杀库存(减少) * - * @param id 活动编号 - * @param skuId sku 编号 - * @param count 数量 + * @param id 活动编号 + * @param skuId sku 编号 + * @param count 数量(正数) */ - void updateSeckillStock(Long id, Long skuId, Integer count); + void updateSeckillStockDecr(Long id, Long skuId, Integer count); + + /** + * 更新秒杀库存(增加) + * + * @param id 活动编号 + * @param skuId sku 编号 + * @param count 数量(正数) + */ + void updateSeckillStockIncr(Long id, Long skuId, Integer count); /** * 【下单前】校验是否参与秒杀活动 @@ -24,8 +33,8 @@ public interface SeckillActivityApi { * 如果校验失败,则抛出业务异常 * * @param activityId 活动编号 - * @param skuId SKU 编号 - * @param count 数量 + * @param skuId SKU 编号 + * @param count 数量 * @return 秒杀信息 */ SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java index 239cdf4ba..45e2d4698 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/seckill/SeckillActivityApiImpl.java @@ -18,8 +18,13 @@ public class SeckillActivityApiImpl implements SeckillActivityApi { private SeckillActivityService activityService; @Override - public void updateSeckillStock(Long id, Long skuId, Integer count) { - activityService.updateSeckillStock(id, skuId, count); + public void updateSeckillStockDecr(Long id, Long skuId, Integer count) { + activityService.updateSeckillStockDecr(id, skuId, count); + } + + @Override + public void updateSeckillStockIncr(Long id, Long skuId, Integer count) { + activityService.updateSeckillStockIncr(id, skuId, count); } @Override diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java index 76a08ac70..67d074903 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java @@ -77,7 +77,8 @@ public class SeckillActivityDO extends BaseDO { private Integer singleLimitCount; /** - * 秒杀库存(剩余库存秒杀时扣减) + * 秒杀库存-秒杀下单时怎加,恢复库存是减少 + * 也就是说这个是记录当前秒杀活动用户购买的商品数量和 */ private Integer stock; /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index 75c26119f..e2d33991c 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity; +import cn.hutool.core.lang.Assert; import cn.hutool.core.util.ObjectUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; @@ -39,13 +40,14 @@ public interface SeckillActivityMapper extends BaseMapperX { } /** - * 更新活动库存 + * 更新活动库存(减少) * * @param id 活动编号 - * @param count 扣减的库存数量 + * @param count 扣减的库存数量(正数) * @return 影响的行数 */ - default int updateStock(Long id, int count) { + default int updateStockDecr(Long id, int count) { + Assert.isTrue(count > 0); return update(null, new LambdaUpdateWrapper() .eq(SeckillActivityDO::getId, id) .gt(SeckillActivityDO::getTotalStock, 0) @@ -53,6 +55,21 @@ public interface SeckillActivityMapper extends BaseMapperX { .setSql("total_stock = total_stock - " + count)); } + /** + * 更新活动库存(增加) + * + * @param id 活动编号 + * @param count 增加的库存数量(正数) + * @return 影响的行数 + */ + default int updateStockIncr(Long id, int count) { + Assert.isTrue(count > 0); + return update(null, new LambdaUpdateWrapper() + .eq(SeckillActivityDO::getId, id) + .setSql("stock = stock - " + count) + .setSql("total_stock = total_stock + " + count)); + } + default PageResult selectPage(AppSeckillActivityPageReqVO pageReqVO, Integer status) { return selectPage(pageReqVO, new LambdaQueryWrapperX() .eqIfPresent(SeckillActivityDO::getStatus, status) @@ -62,6 +79,7 @@ public interface SeckillActivityMapper extends BaseMapperX { /** * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 + * * @param spuIds spu 编号 * @param status 状态 * @return 包含 spuId 和 activityId 的 map 对象列表 diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index 35ea110ce..8e1692415 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.promotion.dal.mysql.seckill.seckillactivity; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.module.promotion.dal.dataobject.seckill.SeckillProductDO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; @@ -30,17 +31,32 @@ public interface SeckillProductMapper extends BaseMapperX { } /** - * 更新活动库存 + * 更新活动库存(减少) * * @param id 活动编号 - * @param count 扣减的库存数量 + * @param count 扣减的库存数量(减少库存) * @return 影响的行数 */ - default int updateStock(Long id, int count) { + default int updateStockDecr(Long id, int count) { + Assert.isTrue(count > 0); return update(null, new LambdaUpdateWrapper() .eq(SeckillProductDO::getId, id) .gt(SeckillProductDO::getStock, count) .setSql("stock = stock - " + count)); } + /** + * 更新活动库存(增加) + * + * @param id 活动编号 + * @param count 需要增加的库存(增加库存) + * @return 影响的行数 + */ + default int updateStockIncr(Long id, int count) { + Assert.isTrue(count > 0); + return update(null, new LambdaUpdateWrapper() + .eq(SeckillProductDO::getId, id) + .setSql("stock = stock + " + count)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java index f71c538a8..36074fd56 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityService.java @@ -36,13 +36,22 @@ public interface SeckillActivityService { void updateSeckillActivity(@Valid SeckillActivityUpdateReqVO updateReqVO); /** - * 更新秒杀库存 + * 更新秒杀库存(减少) * * @param id 活动编号 * @param skuId sku 编号 - * @param count 数量 + * @param count 数量(正数) */ - void updateSeckillStock(Long id, Long skuId, Integer count); + void updateSeckillStockDecr(Long id, Long skuId, Integer count); + + /** + * 更新秒杀库存(增加) + * + * @param id 活动编号 + * @param skuId sku 编号 + * @param count 数量(正数) + */ + void updateSeckillStockIncr(Long id, Long skuId, Integer count); /** * 关闭秒杀活动 @@ -113,8 +122,8 @@ public interface SeckillActivityService { * 如果校验失败,则抛出业务异常 * * @param activityId 活动编号 - * @param skuId SKU 编号 - * @param count 数量 + * @param skuId SKU 编号 + * @param count 数量 * @return 秒杀信息 */ SeckillValidateJoinRespDTO validateJoinSeckill(Long activityId, Long skuId, Integer count); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java index 4b35161a5..6d86bd517 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/seckill/SeckillActivityServiceImpl.java @@ -157,7 +157,7 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { @Override @Transactional(rollbackFor = Exception.class) - public void updateSeckillStock(Long id, Long skuId, Integer count) { + public void updateSeckillStockDecr(Long id, Long skuId, Integer count) { // 1.1 校验活动库存是否充足 SeckillActivityDO seckillActivity = validateSeckillActivityExists(id); if (count > seckillActivity.getTotalStock()) { @@ -170,18 +170,28 @@ public class SeckillActivityServiceImpl implements SeckillActivityService { } // 2.1 更新活动商品库存 - int updateCount = seckillProductMapper.updateStock(product.getId(), count); + int updateCount = seckillProductMapper.updateStockDecr(product.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } // 2.2 更新活动库存 - updateCount = seckillActivityMapper.updateStock(seckillActivity.getId(), count); + updateCount = seckillActivityMapper.updateStockDecr(seckillActivity.getId(), count); if (updateCount == 0) { throw exception(SECKILL_ACTIVITY_UPDATE_STOCK_FAIL); } } + @Override + @Transactional(rollbackFor = Exception.class) + public void updateSeckillStockIncr(Long id, Long skuId, Integer count) { + SeckillProductDO product = seckillProductMapper.selectByActivityIdAndSkuId(id, skuId); + // 更新活动商品库存 + seckillProductMapper.updateStockIncr(product.getId(), count); + // 更新活动库存 + seckillActivityMapper.updateStockIncr(id, count); + } + /** * 更新秒杀商品 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java index b9bd3e4bd..77934cb17 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; @@ -25,9 +26,11 @@ public class TradeSeckillHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isSeckill(order.getType())) { return; } + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "秒杀时,只允许选择一个商品"); // 扣减秒杀活动的库存 - seckillActivityApi.updateSeckillStock(order.getSeckillActivityId(), + seckillActivityApi.updateSeckillStockDecr(order.getSeckillActivityId(), orderItems.get(0).getSkuId(), orderItems.get(0).getCount()); } @@ -36,7 +39,12 @@ public class TradeSeckillHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isSeckill(order.getType())) { return; } + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "秒杀时,只允许选择一个商品"); + // 恢复秒杀活动的库存 + seckillActivityApi.updateSeckillStockIncr(order.getSeckillActivityId(), + orderItems.get(0).getSkuId(), orderItems.get(0).getCount()); } } From 42fcbe0501eb61a7e10f74061f4bb729679bad3f Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 10 Oct 2023 10:47:25 +0800 Subject: [PATCH 12/21] =?UTF-8?q?=E7=A0=8D=E4=BB=B7=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E6=88=90=E8=AE=A2=E5=8D=95=E5=8F=96=E6=B6=88?= =?UTF-8?q?=E6=97=B6=E6=81=A2=E5=A4=8D=E6=B4=BB=E5=8A=A8=E5=BA=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bargain/BargainActivityServiceImpl.java | 15 ++++++++++----- .../order/handler/TradeBargainHandler.java | 12 +++++++++++- .../order/handler/TradeCombinationHandler.java | 7 ------- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 8d10f0247..364cdf9ee 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -85,11 +85,16 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public void updateBargainActivityStock(Long id, Integer count) { - // 更新库存。如果更新失败,则抛出异常 - int updateCount = bargainActivityMapper.updateStock(id, count); - if (updateCount == 0) { - throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); + if (count < 0) { + // 更新库存。如果更新失败,则抛出异常 + int updateCount = bargainActivityMapper.updateStock(id, count); + if (updateCount == 0) { + throw exception(BARGAIN_ACTIVITY_STOCK_NOT_ENOUGH); + } + } else if (count > 0) { + bargainActivityMapper.updateStock(id, count); } + } private void validateBargainConflict(Long spuId, Long activityId) { @@ -140,7 +145,7 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public List getBargainActivityList(Set ids) { - return bargainActivityMapper.selectBatchIds(ids); + return bargainActivityMapper.selectBatchIds(ids); } @Override diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java index b83d2771b..e856621dc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -28,6 +29,8 @@ public class TradeBargainHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "砍价时,只允许选择一个商品"); // 扣减砍价活动的库存 bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), @@ -39,6 +42,8 @@ public class TradeBargainHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "砍价时,只允许选择一个商品"); // 记录砍价记录对应的订单编号 bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId()); @@ -49,7 +54,12 @@ public class TradeBargainHandler implements TradeOrderHandler { if (TradeOrderTypeEnum.isBargain(order.getType())) { return; } - // TODO 芋艿:取消订单时,需要增加库存 + // 明确校验一下 + Assert.isTrue(orderItems.size() == 1, "砍价时,只允许选择一个商品"); + + // 恢复砍价活动的库存 + bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), + orderItems.get(0).getCount()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java index c83615bda..05d87fa46 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java @@ -76,11 +76,4 @@ public class TradeCombinationHandler implements TradeOrderHandler { recordIdAndHeadId.getKey(), recordIdAndHeadId.getValue()); } - @Override - public void cancelOrder(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isCombination(order.getType())) { - return; - } - } - } From fdbebc406cb9d593e4c9fffc4c136eedc85270af Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 10 Oct 2023 10:57:17 +0800 Subject: [PATCH 13/21] =?UTF-8?q?=E7=A7=92=E6=9D=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E7=BA=A0=E6=AD=A3=E7=A7=92=E6=9D=80=E5=BA=93=E5=AD=98?= =?UTF-8?q?=E5=92=8C=E7=A7=92=E6=9D=80=E6=80=BB=E5=BA=93=E5=AD=98=E6=89=A3?= =?UTF-8?q?=E5=87=8F=E9=94=99=E8=AF=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dal/dataobject/seckill/SeckillActivityDO.java | 3 +-- .../seckill/seckillactivity/SeckillActivityMapper.java | 8 +++----- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java index 67d074903..76a08ac70 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/dataobject/seckill/SeckillActivityDO.java @@ -77,8 +77,7 @@ public class SeckillActivityDO extends BaseDO { private Integer singleLimitCount; /** - * 秒杀库存-秒杀下单时怎加,恢复库存是减少 - * 也就是说这个是记录当前秒杀活动用户购买的商品数量和 + * 秒杀库存(剩余库存秒杀时扣减) */ private Integer stock; /** diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java index e2d33991c..528ea07f9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillActivityMapper.java @@ -50,9 +50,8 @@ public interface SeckillActivityMapper extends BaseMapperX { Assert.isTrue(count > 0); return update(null, new LambdaUpdateWrapper() .eq(SeckillActivityDO::getId, id) - .gt(SeckillActivityDO::getTotalStock, 0) - .setSql("stock = stock + " + count) - .setSql("total_stock = total_stock - " + count)); + .gt(SeckillActivityDO::getStock, count) + .setSql("stock = stock - " + count)); } /** @@ -66,8 +65,7 @@ public interface SeckillActivityMapper extends BaseMapperX { Assert.isTrue(count > 0); return update(null, new LambdaUpdateWrapper() .eq(SeckillActivityDO::getId, id) - .setSql("stock = stock - " + count) - .setSql("total_stock = total_stock + " + count)); + .setSql("stock = stock + " + count)); } default PageResult selectPage(AppSeckillActivityPageReqVO pageReqVO, Integer status) { From bccd270fc77176a9138ae643c9309633264d3c83 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 10 Oct 2023 15:30:58 +0800 Subject: [PATCH 14/21] =?UTF-8?q?=E8=90=A5=E9=94=80=E6=B4=BB=E5=8A=A8?= =?UTF-8?q?=EF=BC=9A=E5=AE=8C=E6=88=90=E7=A0=8D=E4=BB=B7=E3=80=81=E7=A7=92?= =?UTF-8?q?=E6=9D=80=E5=BA=93=E5=AD=98=E5=9B=9E=E6=BB=9A=E3=80=82=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E6=8B=BC=E5=9B=A2=E8=BF=87=E6=9C=9F=E5=92=8C=E8=99=9A?= =?UTF-8?q?=E6=8B=9F=E6=88=90=E5=9B=A2=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../util/collection/CollectionUtils.java | 7 + .../CombinationActivityConvert.java | 32 ++++ .../combination/CombinationRecordMapper.java | 12 ++ .../CombinationRecordExpireJob.java | 30 ++++ .../combination/CombinationRecordService.java | 6 + .../CombinationRecordServiceImpl.java | 160 +++++++++++++++--- 6 files changed, 223 insertions(+), 24 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java diff --git a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java index 0a89482c4..7da5cb9c7 100644 --- a/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java +++ b/yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/collection/CollectionUtils.java @@ -64,6 +64,13 @@ public class CollectionUtils { return from.stream().filter(filter).map(func).filter(Objects::nonNull).collect(Collectors.toList()); } + public static List mergeValuesFromMap(Map> map) { + return map.values() + .stream() + .flatMap(List::stream) + .collect(Collectors.toList()); + } + public static Set convertSet(Collection from, Function func) { if (CollUtil.isEmpty(from)) { return new HashSet<>(); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java index 067669a00..03cac269f 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/convert/combination/CombinationActivityConvert.java @@ -28,6 +28,7 @@ import org.mapstruct.Mapping; import org.mapstruct.Mappings; import org.mapstruct.factory.Mappers; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -196,4 +197,35 @@ public interface CombinationActivityConvert { return respVO; } + /** + * 转换生成虚拟成团虚拟记录 + * + * @param virtualGroupHeadRecords 虚拟成团团长记录列表 + * @return 虚拟记录列表 + */ + default List convertVirtualGroupList(List virtualGroupHeadRecords) { + List createRecords = new ArrayList<>(); + virtualGroupHeadRecords.forEach(headRecord -> { + // 计算需要创建的虚拟成团记录数量 + int count = headRecord.getUserSize() - headRecord.getUserCount(); + for (int i = 0; i < count; i++) { + // 基础信息和团长保持一致 + CombinationRecordDO newRecord = new CombinationRecordDO().setActivityId(headRecord.getActivityId()) + .setCombinationPrice(headRecord.getCombinationPrice()).setSpuId(headRecord.getSpuId()).setSpuName(headRecord.getSpuName()) + .setPicUrl(headRecord.getPicUrl()).setSkuId(headRecord.getSkuId()).setHeadId(headRecord.getId()) + .setStatus(headRecord.getStatus()) // 状态保持和创建时一致,创建完成后会接着处理 + .setVirtualGroup(headRecord.getVirtualGroup()).setExpireTime(headRecord.getExpireTime()) + .setStartTime(headRecord.getStartTime()).setUserSize(headRecord.getUserSize()).setUserCount(headRecord.getUserCount()); + // 虚拟信息 + newRecord.setCount(0); + newRecord.setUserId(0L); + newRecord.setNickname(""); + newRecord.setAvatar(""); + newRecord.setOrderId(0L); + createRecords.add(newRecord); + } + }); + return createRecords; + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index dd8747677..bb97054e4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -11,6 +11,7 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import org.apache.ibatis.annotations.Mapper; +import java.time.LocalDateTime; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -117,4 +118,15 @@ public interface CombinationRecordMapper extends BaseMapperX selectListByHeadIdAndStatusAndExpireTimeLt(Long headId, Integer status, LocalDateTime dateTime) { + return selectList(new LambdaQueryWrapperX() + .eq(CombinationRecordDO::getHeadId, headId) + .eq(CombinationRecordDO::getStatus, status) + .lt(CombinationRecordDO::getExpireTime, dateTime)); + } + + default List selectListByHeadIds(Collection headIds) { + return selectList(new LambdaQueryWrapperX().in(CombinationRecordDO::getHeadId, headIds)); + } + } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java new file mode 100644 index 000000000..2ee6e8b63 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java @@ -0,0 +1,30 @@ +package cn.iocoder.yudao.module.promotion.job.combination; + +import cn.hutool.core.util.StrUtil; +import cn.iocoder.yudao.framework.common.core.KeyValue; +import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; +import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; +import cn.iocoder.yudao.module.promotion.service.combination.CombinationRecordService; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; + +/** + * 拼团过期 Job + * + * @author HUIHUI + */ +@Component +public class CombinationRecordExpireJob implements JobHandler { + + @Resource + private CombinationRecordService combinationRecordService; + + @Override + @TenantJob + public String execute(String param) throws Exception { + KeyValue keyValue = combinationRecordService.expireCombinationRecord(); + return StrUtil.format("过期拼团 {} 个, 虚拟成团 {} 个", keyValue.getKey(), keyValue.getValue()); + } + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index 309047470..12d51d338 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -168,5 +168,11 @@ public interface CombinationRecordService { */ void cancelCombinationRecord(Long userId, Long id, Long headId); + /** + * 处理过期拼团 + * + * @return key 过期拼团数量, value 虚拟成团数量 + */ + KeyValue expireCombinationRecord(); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 0033d143b..c1cb539ac 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -2,6 +2,7 @@ package cn.iocoder.yudao.module.promotion.service.combination; import cn.hutool.core.collection.CollUtil; import cn.hutool.core.util.ObjUtil; +import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.enums.CommonStatusEnum; import cn.iocoder.yudao.framework.common.pojo.PageResult; @@ -20,7 +21,9 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationP import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; +import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import org.springframework.context.annotation.Lazy; +import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.validation.annotation.Validated; @@ -31,8 +34,7 @@ import java.time.LocalDateTime; import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.findFirst; -import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.afterNow; import static cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils.beforeNow; import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; @@ -52,7 +54,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Lazy private CombinationActivityService combinationActivityService; @Resource - private CombinationRecordMapper recordMapper; + private CombinationRecordMapper combinationRecordMapper; @Resource private MemberUserApi memberUserApi; @@ -63,6 +65,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Lazy private ProductSkuApi productSkuApi; + @Resource + private TradeOrderApi tradeOrderApi; + // TODO @芋艿:在详细预览下; @Override @Transactional(rollbackFor = Exception.class) @@ -72,12 +77,12 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { // 更新状态 record.setStatus(status); - recordMapper.updateById(record); + combinationRecordMapper.updateById(record); } private CombinationRecordDO validateCombinationRecord(Long userId, Long orderId) { // 校验拼团是否存在 - CombinationRecordDO recordDO = recordMapper.selectByUserIdAndOrderId(userId, orderId); + CombinationRecordDO recordDO = combinationRecordMapper.selectByUserIdAndOrderId(userId, orderId); if (recordDO == null) { throw exception(COMBINATION_RECORD_NOT_EXISTS); } @@ -106,7 +111,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { // 2. 父拼团是否存在,是否已经满了 if (headId != null) { // 2.1. 查询进行中的父拼团 - CombinationRecordDO record = recordMapper.selectByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); + CombinationRecordDO record = combinationRecordMapper.selectByHeadId(headId, CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); if (record == null) { throw exception(COMBINATION_RECORD_HEAD_NOT_EXISTS); } @@ -141,7 +146,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } // 6.1 校验是否有拼团记录 - List recordList = recordMapper.selectListByUserIdAndActivityId(userId, activityId); + List recordList = combinationRecordMapper.selectListByUserIdAndActivityId(userId, activityId); recordList.removeIf(record -> CombinationRecordStatusEnum.isFailed(record.getStatus())); // 取消的订单,不算数 if (CollUtil.isEmpty(recordList)) { // 如果为空,说明可以参与,直接返回 return new KeyValue<>(activity, product); @@ -179,11 +184,11 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { .setHeadId(CombinationRecordDO.HEAD_ID_GROUP); } else { // 2.2.有团长的情况下需要设置开始时间和过期时间为团长的 - CombinationRecordDO headRecord = recordMapper.selectByHeadId(record.getHeadId(), + CombinationRecordDO headRecord = combinationRecordMapper.selectByHeadId(record.getHeadId(), CombinationRecordStatusEnum.IN_PROGRESS.getStatus()); // 查询进行中的父拼团 record.setStartTime(headRecord.getStartTime()).setExpireTime(headRecord.getExpireTime()); } - recordMapper.insert(record); + combinationRecordMapper.insert(record); if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { return new KeyValue<>(record.getId(), record.getHeadId()); @@ -206,31 +211,33 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { if (CollUtil.isEmpty(records)) { return; } - CombinationRecordDO headRecord = recordMapper.selectById(headId); + CombinationRecordDO headRecord = combinationRecordMapper.selectById(headId); // 2. 批量更新记录 List updateRecords = new ArrayList<>(); records.add(headRecord); // 加入团长,团长也需要更新 boolean isFull = records.size() >= activity.getUserSize(); + LocalDateTime now = LocalDateTime.now(); records.forEach(item -> { CombinationRecordDO updateRecord = new CombinationRecordDO(); updateRecord.setId(item.getId()).setUserCount(records.size()); if (isFull) { updateRecord.setStatus(CombinationRecordStatusEnum.SUCCESS.getStatus()); + updateRecord.setEndTime(now); } updateRecords.add(updateRecord); }); - recordMapper.updateBatch(updateRecords); + combinationRecordMapper.updateBatch(updateRecords); } @Override public CombinationRecordDO getCombinationRecord(Long userId, Long orderId) { - return recordMapper.selectByUserIdAndOrderId(userId, orderId); + return combinationRecordMapper.selectByUserIdAndOrderId(userId, orderId); } @Override public List getCombinationRecordListByUserIdAndActivityId(Long userId, Long activityId) { - return recordMapper.selectListByUserIdAndActivityId(userId, activityId); + return combinationRecordMapper.selectListByUserIdAndActivityId(userId, activityId); } @Override @@ -244,51 +251,51 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public Long getCombinationRecordCount(@Nullable Integer status, @Nullable Boolean virtualGroup, @Nullable Long headId) { - return recordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup, headId); + return combinationRecordMapper.selectCountByHeadAndStatusAndVirtualGroup(status, virtualGroup, headId); } @Override public List getLatestCombinationRecordList(int count) { - return recordMapper.selectLatestList(count); + return combinationRecordMapper.selectLatestList(count); } @Override public List getHeadCombinationRecordList(Long activityId, Integer status, Integer count) { - return recordMapper.selectListByActivityIdAndStatusAndHeadId(activityId, status, + return combinationRecordMapper.selectListByActivityIdAndStatusAndHeadId(activityId, status, CombinationRecordDO.HEAD_ID_GROUP, count); } @Override public CombinationRecordDO getCombinationRecordById(Long id) { - return recordMapper.selectById(id); + return combinationRecordMapper.selectById(id); } @Override public List getCombinationRecordListByHeadId(Long headId) { - return recordMapper.selectList(CombinationRecordDO::getHeadId, headId); + return combinationRecordMapper.selectList(CombinationRecordDO::getHeadId, headId); } @Override public PageResult getCombinationRecordPage(CombinationRecordReqPageVO pageVO) { - return recordMapper.selectPage(pageVO); + return combinationRecordMapper.selectPage(pageVO); } @Override public Map getCombinationRecordCountMapByActivity(Collection activityIds, @Nullable Integer status, @Nullable Long headId) { - return recordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); + return combinationRecordMapper.selectCombinationRecordCountMapByActivityIdAndStatusAndHeadId(activityIds, status, headId); } @Override public CombinationRecordDO getCombinationRecordByIdAndUser(Long userId, Long id) { - return recordMapper.selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getId, id); + return combinationRecordMapper.selectOne(CombinationRecordDO::getUserId, userId, CombinationRecordDO::getId, id); } @Override @Transactional(rollbackFor = Exception.class) public void cancelCombinationRecord(Long userId, Long id, Long headId) { // 删除记录 - recordMapper.deleteById(id); + combinationRecordMapper.deleteById(id); // 需要更新的记录 List updateRecords = new ArrayList<>(); @@ -315,7 +322,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { }); } else { // 情况二:团员 // 团长 - CombinationRecordDO recordHead = recordMapper.selectById(headId); + CombinationRecordDO recordHead = combinationRecordMapper.selectById(headId); // 团员 List records = getCombinationRecordListByHeadId(headId); if (CollUtil.isEmpty(records)) { @@ -331,7 +338,112 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } // 更新拼团记录 - recordMapper.updateBatch(updateRecords); + combinationRecordMapper.updateBatch(updateRecords); + } + + @Override + public KeyValue expireCombinationRecord() { + // 1。获取所有正在进行中的过期的父拼团 + List headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt( + CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now()); + if (CollUtil.isEmpty(headExpireRecords)) { + return new KeyValue<>(0, 0); + } + + // 2.获取拼团活动 + List combinationActivities = combinationActivityService.getCombinationActivityListByIds( + convertSet(headExpireRecords, CombinationRecordDO::getActivityId)); + Map activityMap = convertMap(combinationActivities, CombinationActivityDO::getId); + + // 3.校验是否虚拟成团 + List virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团 + for (Iterator iterator = headExpireRecords.iterator(); iterator.hasNext(); ) { + CombinationRecordDO record = iterator.next(); + // 3.1 不匹配,则直接跳过 + CombinationActivityDO activityDO = activityMap.get(record.getActivityId()); + if (activityDO == null || !activityDO.getVirtualGroup()) { // 取不到活动的或者不是虚拟拼团的 + continue; + } + // 3.2 匹配,则移除,添加到虚拟成团中,并结束寻找 + virtualGroupHeadRecords.add(record); + iterator.remove(); + break; + } + + // 4.处理过期的拼团 + getSelf().handleExpireRecord(headExpireRecords); + // 5.虚拟成团 + getSelf().handleVirtualGroupRecord(virtualGroupHeadRecords); + + return new KeyValue<>(headExpireRecords.size(), virtualGroupHeadRecords.size()); + } + + @Async + protected void handleExpireRecord(List headExpireRecords) { + if (CollUtil.isEmpty(headExpireRecords)) { + return; + } + + // 1.更新拼团记录 + List headsAndRecords = updateBatchCombinationRecords(headExpireRecords, + CombinationRecordStatusEnum.FAILED); + if (headsAndRecords == null) { + return; + } + + // 2.订单取消 TODO 以现在的取消回滚逻辑好像只能循环了 + headsAndRecords.forEach(item -> { + tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId()); + }); + + } + + @Async + protected void handleVirtualGroupRecord(List virtualGroupHeadRecords) { + if (CollUtil.isEmpty(virtualGroupHeadRecords)) { + return; + } + + // 1.团员补齐 + combinationRecordMapper.insertBatch(CombinationActivityConvert.INSTANCE.convertVirtualGroupList(virtualGroupHeadRecords)); + // 2.更新拼团记录 + updateBatchCombinationRecords(virtualGroupHeadRecords, CombinationRecordStatusEnum.SUCCESS); + } + + private List updateBatchCombinationRecords(List headRecords, CombinationRecordStatusEnum status) { + // 1. 查询团成员 + List records = combinationRecordMapper.selectListByHeadIds( + convertSet(headRecords, CombinationRecordDO::getId)); + if (CollUtil.isEmpty(records)) { + return null; + } + Map> recordsMap = convertMultiMap(records, CombinationRecordDO::getHeadId); + headRecords.forEach(item -> { + recordsMap.get(item.getId()).add(item); // 把团长加进团里 + }); + // 2.批量更新拼团记录 status 和 失败/成团时间 + List headsAndRecords = mergeValuesFromMap(recordsMap); + List updateRecords = new ArrayList<>(headsAndRecords.size()); + LocalDateTime now = LocalDateTime.now(); + headsAndRecords.forEach(item -> { + CombinationRecordDO record = new CombinationRecordDO().setId(item.getId()) + .setStatus(status.getStatus()).setEndTime(now); + if (CombinationRecordStatusEnum.isSuccess(status.getStatus())) { // 虚拟成团完事更改状态成功后还需要把参与人数修改为成团需要人数 + record.setUserCount(record.getUserSize()); + } + updateRecords.add(record); + }); + combinationRecordMapper.updateBatch(updateRecords); + return headsAndRecords; + } + + /** + * 获得自身的代理对象,解决 AOP 生效问题 + * + * @return 自己 + */ + private CombinationRecordServiceImpl getSelf() { + return SpringUtil.getBean(getClass()); } } From cfbc8b48494e6c6563336de9f54a2d9a660c3f19 Mon Sep 17 00:00:00 2001 From: puhui999 Date: Tue, 10 Oct 2023 17:21:37 +0800 Subject: [PATCH 15/21] =?UTF-8?q?=E6=8B=BC=E5=9B=A2=E8=AE=B0=E5=BD=95?= =?UTF-8?q?=EF=BC=88admin-api=EF=BC=89=EF=BC=9A=E5=A2=9E=E5=8A=A0=20page-b?= =?UTF-8?q?y-headId=20=E6=8E=A5=E5=8F=A3=E8=8E=B7=E5=8F=96=E6=8C=87?= =?UTF-8?q?=E5=AE=9A=20headId=20=E5=AE=8C=E6=95=B4=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E5=88=86=E9=A1=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CombinationRecordController.java | 12 +++++++++++ .../recrod/CombinationRecordReqPage2VO.java | 21 +++++++++++++++++++ .../combination/CombinationRecordMapper.java | 13 ++++++++++-- .../combination/CombinationRecordService.java | 10 +++++++++ .../CombinationRecordServiceImpl.java | 6 ++++++ 5 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPage2VO.java diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index 45ddf755a..98a4f3cdd 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -3,6 +3,7 @@ package cn.iocoder.yudao.module.promotion.controller.admin.combination; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordPageItemRespVO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordSummaryVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; @@ -49,6 +50,17 @@ public class CombinationRecordController { return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities)); } + @GetMapping("/page-by-headId") + @Operation(summary = "获得拼团记录分页") + @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") + public CommonResult> getBargainRecordPage(@Valid CombinationRecordReqPage2VO pageVO) { + // 包含团长和团员的分页记录 + PageResult recordPage = combinationRecordService.getCombinationRecordPage2(pageVO); + List activities = combinationActivityService.getCombinationActivityListByIds( + convertSet(recordPage.getList(), CombinationRecordDO::getActivityId)); + return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities)); + } + @GetMapping("/get-summary") @Operation(summary = "获得拼团记录的概要信息", description = "用于拼团记录页面展示") @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPage2VO.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPage2VO.java new file mode 100644 index 000000000..9e6fe9159 --- /dev/null +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/vo/recrod/CombinationRecordReqPage2VO.java @@ -0,0 +1,21 @@ +package cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod; + +import cn.iocoder.yudao.framework.common.pojo.PageParam; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.ToString; + +import javax.validation.constraints.NotNull; + +@Schema(description = "管理后台 - 拼团记录分页 Request VO") +@Data +@EqualsAndHashCode(callSuper = true) +@ToString(callSuper = true) +public class CombinationRecordReqPage2VO extends PageParam { + + @Schema(description = "团长编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") + @NotNull(message = "团长编号不能为空") + private Long headId; + +} diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index bb97054e4..c232fb9d9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -6,6 +6,7 @@ import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationRecordDO; import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; @@ -101,6 +102,13 @@ public interface CombinationRecordMapper extends BaseMapperX selectPage(CombinationRecordReqPage2VO pageVO) { + return selectPage(pageVO, new LambdaQueryWrapperX() + .eq(CombinationRecordDO::getId, pageVO.getHeadId()) + .or() + .eq(CombinationRecordDO::getHeadId, pageVO.getHeadId())); + } + /** * 查询指定条件的记录数 * 如果参数都为 null 时则查询用户拼团记录(DISTINCT 去重),也就是说查询会员表中的用户有多少人参与过拼团活动每个人只统计一次 @@ -112,10 +120,11 @@ public interface CombinationRecordMapper extends BaseMapperX() - .select(status == null && virtualGroup == null && headId == null, "COUNT(DISTINCT(user_id))") + .select(status == null && virtualGroup == null && headId == null, "DISTINCT (user_id)") .eq(status != null, "status", status) .eq(virtualGroup != null, "virtual_group", virtualGroup) - .eq(headId != null, "head_id", headId)); + .eq(headId != null, "head_id", headId) + .groupBy("user_id")); } default List selectListByHeadIdAndStatusAndExpireTimeLt(Long headId, Integer status, LocalDateTime dateTime) { diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index 12d51d338..68cdde760 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -4,6 +4,7 @@ import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationProductDO; @@ -137,6 +138,15 @@ public interface CombinationRecordService { */ PageResult getCombinationRecordPage(CombinationRecordReqPageVO pageVO); + /** + * 获取拼团记录分页数据(通过团长查询) + * + * @param pageVO 分页请求 + * @return 拼团记录分页数据(包括团长的) + */ + PageResult getCombinationRecordPage2(CombinationRecordReqPage2VO pageVO); + + /** * 【拼团活动】获得拼团记录数量 Map * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index c1cb539ac..76122fa39 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -14,6 +14,7 @@ import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationRecordCreateReqDTO; import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidateJoinRespDTO; +import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPage2VO; import cn.iocoder.yudao.module.promotion.controller.admin.combination.vo.recrod.CombinationRecordReqPageVO; import cn.iocoder.yudao.module.promotion.convert.combination.CombinationActivityConvert; import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationActivityDO; @@ -280,6 +281,11 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return combinationRecordMapper.selectPage(pageVO); } + @Override + public PageResult getCombinationRecordPage2(CombinationRecordReqPage2VO pageVO) { + return combinationRecordMapper.selectPage(pageVO); + } + @Override public Map getCombinationRecordCountMapByActivity(Collection activityIds, @Nullable Integer status, @Nullable Long headId) { From 2e5cc0537b8002e174a695bc0e2d79bbebda8aba Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 10 Oct 2023 19:20:12 +0800 Subject: [PATCH 16/21] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E5=B0=86?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=9A=84=E5=88=86=E6=94=AF=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E6=8A=BD=E5=88=B0=20TradeOrderHandler=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=B1=BB=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../order/TradeOrderUpdateServiceImpl.java | 227 +++--------------- ...ler.java => TradeBargainOrderHandler.java} | 16 +- .../handler/TradeBrokerageOrderHandler.java | 102 ++++++++ ...java => TradeCombinationOrderHandler.java} | 23 +- .../handler/TradeCouponOrderHandler.java | 42 ++++ .../handler/TradeMemberPointOrderHandler.java | 98 ++++++++ .../order/handler/TradeOrderHandler.java | 23 +- .../handler/TradeProductSkuOrderHandler.java | 41 ++++ ...ler.java => TradeSeckillOrderHandler.java} | 14 +- .../member/api/level/MemberLevelApi.java | 1 + 10 files changed, 355 insertions(+), 232 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/{TradeBargainHandler.java => TradeBargainOrderHandler.java} (73%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/{TradeCombinationHandler.java => TradeCombinationOrderHandler.java} (69%) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCouponOrderHandler.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/{TradeSeckillHandler.java => TradeSeckillOrderHandler.java} (71%) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 74a23ff26..78b1796c7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -14,23 +14,12 @@ import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.common.util.number.MoneyUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; -import cn.iocoder.yudao.module.member.api.point.MemberPointApi; -import cn.iocoder.yudao.module.member.api.user.MemberUserApi; -import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; -import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; -import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; import cn.iocoder.yudao.module.pay.api.order.PayOrderApi; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; import cn.iocoder.yudao.module.pay.enums.order.PayOrderStatusEnum; import cn.iocoder.yudao.module.product.api.comment.ProductCommentApi; import cn.iocoder.yudao.module.product.api.comment.dto.ProductCommentCreateReqDTO; -import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; -import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; -import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; -import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; -import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderDeliveryReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderRemarkReqVO; import cn.iocoder.yudao.module.trade.controller.admin.order.vo.TradeOrderUpdateAddressReqVO; @@ -40,7 +29,6 @@ import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettle import cn.iocoder.yudao.module.trade.controller.app.order.vo.AppTradeOrderSettlementRespVO; import cn.iocoder.yudao.module.trade.controller.app.order.vo.item.AppTradeOrderItemCommentCreateReqVO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.cart.CartDO; import cn.iocoder.yudao.module.trade.dal.dataobject.delivery.DeliveryExpressDO; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -48,15 +36,11 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderItemMapper; import cn.iocoder.yudao.module.trade.dal.mysql.order.TradeOrderMapper; import cn.iocoder.yudao.module.trade.dal.redis.no.TradeNoRedisDAO; -import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.delivery.DeliveryTypeEnum; import cn.iocoder.yudao.module.trade.enums.order.*; import cn.iocoder.yudao.module.trade.framework.order.config.TradeOrderProperties; import cn.iocoder.yudao.module.trade.framework.order.core.annotations.TradeOrderLog; import cn.iocoder.yudao.module.trade.framework.order.core.utils.TradeOrderLogUtils; -import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.cart.CartService; import cn.iocoder.yudao.module.trade.service.delivery.DeliveryExpressService; import cn.iocoder.yudao.module.trade.service.message.TradeMessageService; @@ -68,13 +52,15 @@ import cn.iocoder.yudao.module.trade.service.price.bo.TradePriceCalculateRespBO; import cn.iocoder.yudao.module.trade.service.price.calculator.TradePriceCalculatorHelper; import lombok.extern.slf4j.Slf4j; import org.jetbrains.annotations.NotNull; -import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import javax.annotation.Resource; import java.time.LocalDateTime; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.Set; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.*; @@ -109,30 +95,12 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { private DeliveryExpressService deliveryExpressService; @Resource private TradeMessageService tradeMessageService; - @Resource - private BrokerageUserService brokerageUserService; - @Resource - private BrokerageRecordService brokerageRecordService; - @Resource - private ProductSpuApi productSpuApi; - @Resource - private ProductSkuApi productSkuApi; @Resource private PayOrderApi payOrderApi; @Resource private AddressApi addressApi; @Resource - private CouponApi couponApi; - @Resource - private CombinationRecordApi combinationRecordApi; - @Resource - private MemberUserApi memberUserApi; - @Resource - private MemberLevelApi memberLevelApi; - @Resource - private MemberPointApi memberPointApi; - @Resource private ProductCommentApi productCommentApi; @Resource @@ -199,7 +167,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { List orderItems = buildTradeOrderItems(order, calculateRespBO); // 2. 订单创建前的逻辑 - beforeCreateTradeOrder(order, orderItems); + tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(order, orderItems)); // 3. 保存订单 tradeOrderMapper.insert(order); @@ -234,11 +202,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { order.setReceiverName(createReqVO.getReceiverName()).setReceiverMobile(createReqVO.getReceiverMobile()); order.setPickUpVerifyCode(RandomUtil.randomNumbers(8)); // 随机一个核销码,长度为 8 位 } - // 设置订单推广人 - BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(order.getUserId()); - if (brokerageUser != null && brokerageUser.getBindUserId() != null) { - order.setBrokerageUserId(brokerageUser.getBindUserId()); - } return order; } @@ -247,21 +210,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { return TradeOrderConvert.INSTANCE.convertList(tradeOrderDO, calculateRespBO); } - /** - * 订单创建前,执行前置逻辑 - * - * @param order 订单 - * @param orderItems 订单项 - */ - private void beforeCreateTradeOrder(TradeOrderDO order, List orderItems) { - // 1. 执行订单创建前置处理器 - // TODO @puhui999:这里有个纠结点;handler 的定义是只处理指定类型的订单的拓展逻辑;还是通用的 handler,类似可以处理优惠劵等等 - tradeOrderHandlers.forEach(handler -> handler.beforeOrderCreate(order, orderItems)); - - // 2. 下单时扣减商品库存 - productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convertNegative(orderItems)); - } - /** * 订单创建后,执行后置逻辑 *

@@ -276,27 +224,16 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // 1. 执行订单创建后置处理器 tradeOrderHandlers.forEach(handler -> handler.afterOrderCreate(order, orderItems)); - // 2. 有使用优惠券时更新 - // 不在前置扣减的原因,是因为优惠劵要记录使用的订单号 - if (order.getCouponId() != null) { - couponApi.useCoupon(new CouponUseReqDTO().setId(order.getCouponId()).setUserId(order.getUserId()) - .setOrderId(order.getId())); - } - - // 3. 扣减积分(抵扣) - // 不在前置扣减的原因,是因为积分扣减时,需要记录关联业务 - reduceUserPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_USE, order.getId()); - - // 4. 删除购物车商品 + // 2. 删除购物车商品 Set cartIds = convertSet(createReqVO.getItems(), AppTradeOrderSettlementReqVO.Item::getCartId); if (CollUtil.isNotEmpty(cartIds)) { cartService.deleteCart(order.getUserId(), cartIds); } - // 5. 生成预支付 + // 3. 生成预支付 createPayOrder(order, orderItems); - // 6. 插入订单日志 + // 4. 插入订单日志 TradeOrderLogUtils.setOrderInfo(order.getId(), null, order.getStatus()); // TODO @LeeYan9: 是可以思考下, 订单的营销优惠记录, 应该记录在哪里, 微信讨论起来! @@ -330,18 +267,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { throw exception(ORDER_UPDATE_PAID_STATUS_NOT_UNPAID); } - // 3、订单支付成功后 + // 3. 执行 TradeOrderHandler 的后置处理 List orderItems = tradeOrderItemMapper.selectListByOrderId(id); tradeOrderHandlers.forEach(handler -> handler.afterPayOrder(order, orderItems)); - // 4.1 增加用户积分(赠送) - addUserPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, order.getId()); - // 4.2 增加用户经验 - getSelf().addUserExperienceAsync(order.getUserId(), order.getPayPrice(), order.getId()); - // 4.3 增加用户佣金 - getSelf().addBrokerageAsync(order.getUserId(), order.getId()); - - // 5. 记录订单日志 + // 4. 记录订单日志 TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.UNDELIVERED.getStatus()); TradeOrderLogUtils.setUserInfo(order.getUserId(), UserTypeEnum.MEMBER.getValue()); } @@ -434,8 +364,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .put("logisticsNo", express != null ? deliveryReqVO.getLogisticsNo() : "").build()); // 4. 发送站内信 - tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO().setOrderId(order.getId()) - .setUserId(order.getUserId()).setMessage(null)); + tradeMessageService.sendMessageWhenDeliveryOrder(new TradeOrderMessageWhenDeliveryOrderReqBO() + .setOrderId(order.getId()).setUserId(order.getUserId()).setMessage(null)); } /** @@ -448,18 +378,13 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { */ private TradeOrderDO validateOrderDeliverable(Long id) { TradeOrderDO order = validateOrderExists(id); - // 校验订单是否退款 + // 1. 校验订单是否未发货 if (ObjectUtil.notEqual(TradeOrderRefundStatusEnum.NONE.getStatus(), order.getRefundStatus())) { throw exception(ORDER_DELIVERY_FAIL_REFUND_STATUS_NOT_NONE); } - // 订单类型:拼团 - if (Objects.equals(TradeOrderTypeEnum.COMBINATION.getType(), order.getType())) { - // 校验订单拼团是否成功 - if (!combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { - throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); - } - } + // 2. 执行 TradeOrderHandler 前置处理 + tradeOrderHandlers.forEach(handler -> handler.beforeDeliveryOrder(order)); return order; } @@ -616,30 +541,19 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { * @param cancelType 取消类型 */ private void cancelOrder0(TradeOrderDO order, TradeOrderCancelTypeEnum cancelType) { - Long id = order.getId(); // 1. 更新 TradeOrderDO 状态为已取消 - int updateCount = tradeOrderMapper.updateByIdAndStatus(id, order.getStatus(), + int updateCount = tradeOrderMapper.updateByIdAndStatus(order.getId(), order.getStatus(), new TradeOrderDO().setStatus(TradeOrderStatusEnum.CANCELED.getStatus()) .setCancelType(cancelType.getType()).setCancelTime(LocalDateTime.now())); if (updateCount == 0) { throw exception(ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID); } - List orderItems = tradeOrderItemMapper.selectListByOrderId(id); - // 3. 回滚库存 - productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); - // 3.1、 活动相关的回滚 - tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, orderItems)); + // 2. 执行 TradeOrderHandler 的后置处理 + List orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); + tradeOrderHandlers.forEach(handler -> handler.afterCancelOrder(order, orderItems)); - // 4. 回滚优惠券 - if (order.getCouponId() != null && order.getCouponId() > 0) { - couponApi.returnUsedCoupon(order.getCouponId()); - } - - // 5. 回滚积分(抵扣的) - addUserPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_CANCEL, order.getId()); - - // 6. 增加订单日志 + // 3. 增加订单日志 TradeOrderLogUtils.setOrderInfo(order.getId(), order.getStatus(), TradeOrderStatusEnum.CANCELED.getStatus()); } @@ -660,8 +574,9 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .setStatus(TradeOrderStatusEnum.CANCELED.getStatus()) .setCancelType(TradeOrderCancelTypeEnum.AFTER_SALE_CLOSE.getType()).setCancelTime(LocalDateTime.now())); - // 2. 退还优惠券 - couponApi.returnUsedCoupon(order.getCouponId()); + // 2. 执行 TradeOrderHandler 的后置处理 + List orderItems = tradeOrderItemMapper.selectListByOrderId(order.getId()); + tradeOrderHandlers.forEach(handler -> handler.afterCancelOrder(order, orderItems)); } @Override @@ -790,13 +705,15 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) public void updateOrderItemWhenAfterSaleSuccess(Long id, Integer refundPrice) { - // 1. 更新订单项 + // 1.1 更新订单项 updateOrderItemAfterSaleStatus(id, TradeOrderItemAfterSaleStatusEnum.APPLY.getStatus(), TradeOrderItemAfterSaleStatusEnum.SUCCESS.getStatus(), null); - - // 2.1 更新订单的退款金额、积分 + // 1.2 执行 TradeOrderHandler 的后置处理 TradeOrderItemDO orderItem = tradeOrderItemMapper.selectById(id); TradeOrderDO order = tradeOrderMapper.selectById(orderItem.getOrderId()); + tradeOrderHandlers.forEach(handler -> handler.afterCancelOrderItem(order, orderItem)); + + // 2.1 更新订单的退款金额、积分 Integer orderRefundPrice = order.getRefundPrice() + refundPrice; Integer orderRefundPoint = order.getRefundPoint() + orderItem.getUsePoint(); Integer refundStatus = isAllOrderItemAfterSaleSuccess(order.getId()) ? @@ -807,23 +724,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { .setRefundPrice(orderRefundPrice).setRefundPoint(orderRefundPoint)); // 2.2 如果全部退款,则进行取消订单 getSelf().cancelOrderByAfterSale(order, orderRefundPrice); - - - // 3. 回滚库存 - productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(Collections.singletonList(orderItem))); - // 3.1、 活动相关的回滚 - tradeOrderHandlers.forEach(handler -> handler.cancelOrder(order, Collections.singletonList(orderItem))); - - // 4.1 回滚积分:扣减用户积分(赠送的) - reduceUserPoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, orderItem.getAfterSaleId()); - // 4.2 回滚积分:增加用户积分(返还抵扣) - addUserPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED, orderItem.getAfterSaleId()); - - // 5. 回滚经验:扣减用户经验 - getSelf().reduceUserExperienceAsync(order.getUserId(), refundPrice, orderItem.getAfterSaleId()); - - // 6. 回滚佣金:更新分佣记录为已失效 - getSelf().cancelBrokerageAsync(order.getUserId(), id); } @Override @@ -840,6 +740,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { if (updateCount <= 0) { throw exception(ORDER_ITEM_UPDATE_AFTER_SALE_STATUS_FAIL); } + } /** @@ -940,7 +841,8 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @TradeOrderLog(operateType = TradeOrderOperateTypeEnum.SYSTEM_COMMENT) public void createOrderItemCommentBySystemBySystem(TradeOrderDO order) { // 1. 查询未评论的订单项 - List orderItems = tradeOrderItemMapper.selectListByOrderIdAndCommentStatus(order.getId(), Boolean.FALSE); + List orderItems = tradeOrderItemMapper.selectListByOrderIdAndCommentStatus( + order.getId(), Boolean.FALSE); if (CollUtil.isEmpty(orderItems)) { return; } @@ -983,73 +885,6 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { // =================== 营销相关的操作 =================== - @Async - protected void addUserExperienceAsync(Long userId, Integer payPrice, Long orderId) { - int bizType = MemberExperienceBizTypeEnum.ORDER.getType(); - memberLevelApi.addExperience(userId, payPrice, bizType, String.valueOf(orderId)); - } - - @Async - protected void reduceUserExperienceAsync(Long userId, Integer refundPrice, Long afterSaleId) { - int bizType = MemberExperienceBizTypeEnum.REFUND.getType(); - memberLevelApi.addExperience(userId, -refundPrice, bizType, String.valueOf(afterSaleId)); - } - - /** - * 添加用户积分 - *

- * 目前是支付成功后,就会创建积分记录。 - *

- * 业内还有两种做法,可以根据自己的业务调整: - * 1. 确认收货后,才创建积分记录 - * 2. 支付 or 下单成功时,创建积分记录(冻结),确认收货解冻或者 n 天后解冻 - * - * @param userId 用户编号 - * @param point 增加积分数量 - * @param bizType 业务编号 - * @param bizId 业务编号 - */ - protected void addUserPoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) { - if (point != null && point > 0) { - memberPointApi.addPoint(userId, point, bizType.getType(), String.valueOf(bizId)); - } - } - - protected void reduceUserPoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) { - if (point != null && point > 0) { - memberPointApi.reducePoint(userId, point, bizType.getType(), String.valueOf(bizId)); - } - } - - /** - * 创建分销记录 - *

- * 目前是支付成功后,就会创建分销记录。 - *

- * 业内还有两种做法,可以根据自己的业务调整: - * 1. 确认收货后,才创建分销记录 - * 2. 支付 or 下单成功时,创建分销记录(冻结),确认收货解冻或者 n 天后解冻 - * - * @param userId 用户编号 - * @param orderId 订单编号 - */ - @Async - protected void addBrokerageAsync(Long userId, Long orderId) { - MemberUserRespDTO user = memberUserApi.getUser(userId); - Assert.notNull(user); - // 每一个订单项,都会去生成分销记录 - List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); - List addList = convertList(orderItems, - item -> TradeOrderConvert.INSTANCE.convert(user, item, - productSpuApi.getSpu(item.getSpuId()), productSkuApi.getSku(item.getSkuId()))); - brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList); - } - - @Async - protected void cancelBrokerageAsync(Long userId, Long orderItemId) { - brokerageRecordService.cancelBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, String.valueOf(orderItemId)); - } - /** * 获得自身的代理对象,解决 AOP 生效问题 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainOrderHandler.java similarity index 73% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainOrderHandler.java index b83d2771b..7977981fa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainOrderHandler.java @@ -11,12 +11,12 @@ import javax.annotation.Resource; import java.util.List; /** - * 砍价订单 handler 实现类 + * 砍价订单的 {@link TradeOrderHandler} 实现类 * * @author HUIHUI */ @Component -public class TradeBargainHandler implements TradeOrderHandler { +public class TradeBargainOrderHandler implements TradeOrderHandler { @Resource private BargainActivityApi bargainActivityApi; @@ -25,7 +25,7 @@ public class TradeBargainHandler implements TradeOrderHandler { @Override public void beforeOrderCreate(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isBargain(order.getType())) { + if (!TradeOrderTypeEnum.isBargain(order.getType())) { return; } @@ -36,7 +36,7 @@ public class TradeBargainHandler implements TradeOrderHandler { @Override public void afterOrderCreate(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isBargain(order.getType())) { + if (!TradeOrderTypeEnum.isBargain(order.getType())) { return; } @@ -44,12 +44,4 @@ public class TradeBargainHandler implements TradeOrderHandler { bargainRecordApi.updateBargainRecordOrderId(order.getBargainRecordId(), order.getId()); } - @Override - public void cancelOrder(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isBargain(order.getType())) { - return; - } - // TODO 芋艿:取消订单时,需要增加库存 - } - } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java new file mode 100644 index 000000000..994dd1d20 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java @@ -0,0 +1,102 @@ +package cn.iocoder.yudao.module.trade.service.order.handler; + +import cn.hutool.core.lang.Assert; +import cn.iocoder.yudao.module.member.api.user.MemberUserApi; +import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; +import cn.iocoder.yudao.module.product.api.sku.dto.ProductSkuRespDTO; +import cn.iocoder.yudao.module.product.api.spu.ProductSpuApi; +import cn.iocoder.yudao.module.product.api.spu.dto.ProductSpuRespDTO; +import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; +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.enums.brokerage.BrokerageRecordBizTypeEnum; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.BrokerageUserService; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; + +/** + * 订单分销的 {@link TradeOrderHandler} 实现类 + * + * @author 芋道源码 + */ +@Component +public class TradeBrokerageOrderHandler implements TradeOrderHandler { + + @Resource + private MemberUserApi memberUserApi; + @Resource + private ProductSpuApi productSpuApi; + @Resource + private ProductSkuApi productSkuApi; + + @Resource + private BrokerageRecordService brokerageRecordService; + @Resource + private BrokerageUserService brokerageUserService; + + @Override + public void beforeOrderCreate(TradeOrderDO order, List orderItems) { + // 设置订单推广人 + BrokerageUserDO brokerageUser = brokerageUserService.getBrokerageUser(order.getUserId()); + if (brokerageUser != null && brokerageUser.getBindUserId() != null) { + order.setBrokerageUserId(brokerageUser.getBindUserId()); + } + } + + @Override + public void afterPayOrder(TradeOrderDO order, List orderItems) { + if (order.getBrokerageUserId() != null) { + addBrokerage(order.getUserId(), orderItems); + } + } + + @Override + public void afterCancelOrder(TradeOrderDO order, List orderItems) { + // TODO 芋艿:取消支付时,需要处理下; + } + + @Override + public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) { + if (order.getBrokerageUserId() != null) { + cancelBrokerage(order.getId(), orderItem.getOrderId()); + } + } + + /** + * 创建分销记录 + *

+ * 目前是支付成功后,就会创建分销记录。 + *

+ * 业内还有两种做法,可以根据自己的业务调整: + * 1. 确认收货后,才创建分销记录 + * 2. 支付 or 下单成功时,创建分销记录(冻结),确认收货解冻或者 n 天后解冻 + * + * @param userId 用户编号 + * @param orderItems 订单项 + */ + protected void addBrokerage(Long userId, List orderItems) { + MemberUserRespDTO user = memberUserApi.getUser(userId); + Assert.notNull(user); + ProductSpuRespDTO spu = productSpuApi.getSpu(orderItems.get(0).getSpuId()); + Assert.notNull(spu); + ProductSkuRespDTO sku = productSkuApi.getSku(orderItems.get(0).getSkuId()); + + // 每一个订单项,都会去生成分销记录 + List addList = convertList(orderItems, + item -> TradeOrderConvert.INSTANCE.convert(user, item, spu, sku)); + brokerageRecordService.addBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, addList); + } + + protected void cancelBrokerage(Long userId, Long orderItemId) { + brokerageRecordService.cancelBrokerage(userId, BrokerageRecordBizTypeEnum.ORDER, String.valueOf(orderItemId)); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java similarity index 69% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java index 17b01ca0e..43e24ce2b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java @@ -11,13 +11,16 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS; + /** - * 拼团订单 handler 接口实现类 + * 拼团订单的 {@link TradeOrderHandler} 实现类 * * @author HUIHUI */ @Component -public class TradeCombinationHandler implements TradeOrderHandler { +public class TradeCombinationOrderHandler implements TradeOrderHandler { @Resource private CombinationRecordApi combinationRecordApi; @@ -25,7 +28,7 @@ public class TradeCombinationHandler implements TradeOrderHandler { @Override public void beforeOrderCreate(TradeOrderDO order, List orderItems) { // 如果不是拼团订单则结束 - if (TradeOrderTypeEnum.isCombination(order.getType())) { + if (!TradeOrderTypeEnum.isCombination(order.getType())) { return; } Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); @@ -40,22 +43,26 @@ public class TradeCombinationHandler implements TradeOrderHandler { @Override public void afterPayOrder(TradeOrderDO order, List orderItems) { // 如果不是拼团订单则结束 - if (TradeOrderTypeEnum.isCombination(order.getType())) { + if (!TradeOrderTypeEnum.isCombination(order.getType())) { return; } Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); - // 获取商品信息 - TradeOrderItemDO item = orderItems.get(0); // 创建拼团记录 + TradeOrderItemDO item = orderItems.get(0); combinationRecordApi.createCombinationRecord(TradeOrderConvert.INSTANCE.convert(order, item)); } @Override - public void cancelOrder(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isCombination(order.getType())) { + public void beforeDeliveryOrder(TradeOrderDO order) { + if (!TradeOrderTypeEnum.isCombination(order.getType())) { return; } + // 校验订单拼团是否成功 + if (!combinationRecordApi.isCombinationRecordSuccess(order.getUserId(), order.getId())) { + throw exception(ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS); + } } } + diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCouponOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCouponOrderHandler.java new file mode 100644 index 000000000..0f953fec7 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCouponOrderHandler.java @@ -0,0 +1,42 @@ +package cn.iocoder.yudao.module.trade.service.order.handler; + +import cn.iocoder.yudao.module.promotion.api.coupon.CouponApi; +import cn.iocoder.yudao.module.promotion.api.coupon.dto.CouponUseReqDTO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 优惠劵的 {@link TradeOrderHandler} 实现类 + * + * @author 芋道源码 + */ +@Component +public class TradeCouponOrderHandler implements TradeOrderHandler { + + @Resource + private CouponApi couponApi; + + @Override + public void afterOrderCreate(TradeOrderDO order, List orderItems) { + if (order.getCouponId() == null || order.getCouponId() <= 0) { + return; + } + // 不在前置扣减的原因,是因为优惠劵要记录使用的订单号 + couponApi.useCoupon(new CouponUseReqDTO().setId(order.getCouponId()).setUserId(order.getUserId()) + .setOrderId(order.getId())); + } + + @Override + public void afterCancelOrder(TradeOrderDO order, List orderItems) { + if (order.getCouponId() == null || order.getCouponId() <= 0) { + return; + } + // 退回优惠劵 + couponApi.returnUsedCoupon(order.getCouponId()); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java new file mode 100644 index 000000000..b4ea71712 --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java @@ -0,0 +1,98 @@ +package cn.iocoder.yudao.module.trade.service.order.handler; + +import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; +import cn.iocoder.yudao.module.member.api.point.MemberPointApi; +import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; +import cn.iocoder.yudao.module.member.enums.point.MemberPointBizTypeEnum; +import cn.iocoder.yudao.module.trade.dal.dataobject.aftersale.AfterSaleDO; +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.service.aftersale.AfterSaleService; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +/** + * 会员积分、等级的 {@link TradeOrderHandler} 实现类 + * + * @author owen + */ +@Component +public class TradeMemberPointOrderHandler implements TradeOrderHandler { + + @Resource + private MemberPointApi memberPointApi; + @Resource + private MemberLevelApi memberLevelApi; + + @Resource + private AfterSaleService afterSaleService; + + @Override + public void afterOrderCreate(TradeOrderDO order, List orderItems) { + // 扣减用户积分(订单抵扣)。不在前置扣减的原因,是因为积分扣减时,需要记录关联业务 + reducePoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_USE, order.getId()); + } + + @Override + public void afterPayOrder(TradeOrderDO order, List orderItems) { + // 增加用户积分(订单赠送) + addPoint(order.getUserId(), order.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE, + order.getId()); + + // 增加用户经验 + memberLevelApi.addExperience(order.getUserId(), order.getPayPrice(), MemberExperienceBizTypeEnum.ORDER.getType(), + String.valueOf(order.getId())); + } + + @Override + public void afterCancelOrder(TradeOrderDO order, List orderItems) { + // 扣减(回滚)用户积分(订单抵扣) + addPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_CANCEL, + order.getId()); + // TODO 芋艿:需要校验;如果部分子订单已经售后退款,则不进行整单退;因为已经退了一部分积分了 + } + + @Override + public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) { + // 扣减(回滚)积分(订单赠送) + reducePoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, + orderItem.getAfterSaleId()); + // 扣减(回滚)积分:增加用户积分(返还抵扣) + addPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED, + orderItem.getAfterSaleId()); + + // 扣减(回滚)用户经验 + AfterSaleDO afterSale = afterSaleService.getAfterSale(orderItem.getAfterSaleId()); + memberLevelApi.addExperience(order.getUserId(), -afterSale.getRefundPrice(), MemberExperienceBizTypeEnum.REFUND.getType(), + String.valueOf(orderItem.getAfterSaleId())); + } + + /** + * 添加用户积分 + *

+ * 目前是支付成功后,就会创建积分记录。 + *

+ * 业内还有两种做法,可以根据自己的业务调整: + * 1. 确认收货后,才创建积分记录 + * 2. 支付 or 下单成功时,创建积分记录(冻结),确认收货解冻或者 n 天后解冻 + * + * @param userId 用户编号 + * @param point 增加积分数量 + * @param bizType 业务编号 + * @param bizId 业务编号 + */ + protected void addPoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) { + if (point != null && point > 0) { + memberPointApi.addPoint(userId, point, bizType.getType(), String.valueOf(bizId)); + } + } + + protected void reducePoint(Long userId, Integer point, MemberPointBizTypeEnum bizType, Long bizId) { + if (point != null && point > 0) { + memberPointApi.reducePoint(userId, point, bizType.getType(), String.valueOf(bizId)); + } + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index 646ebd1b7..c3cf7cdfc 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -35,16 +35,29 @@ public interface TradeOrderHandler { * @param order 订单 * @param orderItems 订单项 */ - default void afterPayOrder(TradeOrderDO order, List orderItems) { - } + default void afterPayOrder(TradeOrderDO order, List orderItems) {} /** - * 订单取消 + * 订单取消后 * * @param order 订单 * @param orderItems 订单项 */ - default void cancelOrder(TradeOrderDO order, List orderItems) { - } + default void afterCancelOrder(TradeOrderDO order, List orderItems) {} + + /** + * 订单项取消后 + * + * @param order 订单 + * @param orderItem 订单项 + */ + default void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) {} + + /** + * 订单发货前 + * + * @param order 订单 + */ + default void beforeDeliveryOrder(TradeOrderDO order) {} } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java new file mode 100644 index 000000000..6e9d91cfc --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java @@ -0,0 +1,41 @@ +package cn.iocoder.yudao.module.trade.service.order.handler; + +import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; +import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; +import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderItemDO; +import org.springframework.stereotype.Component; + +import javax.annotation.Resource; +import java.util.List; + +import static java.util.Collections.singletonList; + +/** + * 商品 SKU 库存的 {@link TradeOrderHandler} 实现类 + * + * @author 芋道源码 + */ +@Component +public class TradeProductSkuOrderHandler implements TradeOrderHandler { + + @Resource + private ProductSkuApi productSkuApi; + + @Override + public void beforeOrderCreate(TradeOrderDO order, List orderItems) { + productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convertNegative(orderItems)); + } + + @Override + public void afterCancelOrder(TradeOrderDO order, List orderItems) { + // TODO 芋艿:如果部分售后,最后导致取消;这里需要过滤下; + productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); + } + + @Override + public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) { + productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(singletonList(orderItem))); + } + +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillOrderHandler.java similarity index 71% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillOrderHandler.java index b9bd3e4bd..19a0fbc3e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillOrderHandler.java @@ -10,19 +10,19 @@ import javax.annotation.Resource; import java.util.List; /** - * 秒杀订单 handler 实现类 + * 秒杀订单的 {@link TradeOrderHandler} 实现类 * * @author HUIHUI */ @Component -public class TradeSeckillHandler implements TradeOrderHandler { +public class TradeSeckillOrderHandler implements TradeOrderHandler { @Resource private SeckillActivityApi seckillActivityApi; @Override public void beforeOrderCreate(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isSeckill(order.getType())) { + if (!TradeOrderTypeEnum.isSeckill(order.getType())) { return; } @@ -31,12 +31,4 @@ public class TradeSeckillHandler implements TradeOrderHandler { orderItems.get(0).getSkuId(), orderItems.get(0).getCount()); } - @Override - public void cancelOrder(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isSeckill(order.getType())) { - return; - } - - } - } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java index 1ddd899cb..8c055632d 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java @@ -18,6 +18,7 @@ public interface MemberLevelApi { */ MemberLevelRespDTO getMemberLevel(Long id); + // TODO 芋艿:后续增加一个减少接口; /** * 增加会员经验 * From 150a1c9771e987101d2f8eccb0a8daeda7430260 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 10 Oct 2023 20:38:20 +0800 Subject: [PATCH 17/21] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E5=B0=86?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=9A=84=E5=88=86=E6=94=AF=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E6=8A=BD=E5=88=B0=20TradeOrderHandler=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=B1=BB=E4=B8=AD=EF=BC=88=E5=8F=96=E6=B6=88=E7=9A=84?= =?UTF-8?q?=E6=8E=92=E9=87=8D=E9=80=BB=E8=BE=91=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../handler/TradeBrokerageOrderHandler.java | 26 ++++++++++++---- .../handler/TradeMemberPointOrderHandler.java | 30 ++++++++++++++++--- .../order/handler/TradeOrderHandler.java | 15 ++++++++++ .../handler/TradeProductSkuOrderHandler.java | 7 ++++- 4 files changed, 68 insertions(+), 10 deletions(-) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java index 994dd1d20..6dd37111a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBrokerageOrderHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; @@ -53,21 +54,36 @@ public class TradeBrokerageOrderHandler implements TradeOrderHandler { @Override public void afterPayOrder(TradeOrderDO order, List orderItems) { - if (order.getBrokerageUserId() != null) { - addBrokerage(order.getUserId(), orderItems); + if (order.getBrokerageUserId() == null) { + return; } + addBrokerage(order.getUserId(), orderItems); } @Override public void afterCancelOrder(TradeOrderDO order, List orderItems) { - // TODO 芋艿:取消支付时,需要处理下; + // 如果是未支付的订单,不会产生分销结果,所以直接 return + if (!order.getPayStatus()) { + return; + } + if (order.getBrokerageUserId() == null) { + return; + } + + // 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚 + orderItems = filterOrderItemListByNoneAfterSale(orderItems); + if (CollUtil.isEmpty(orderItems)) { + return; + } + orderItems.forEach(orderItem -> afterCancelOrderItem(order, orderItem)); } @Override public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) { - if (order.getBrokerageUserId() != null) { - cancelBrokerage(order.getId(), orderItem.getOrderId()); + if (order.getBrokerageUserId() == null) { + return; } + cancelBrokerage(order.getId(), orderItem.getOrderId()); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java index b4ea71712..c81bee809 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.enums.MemberExperienceBizTypeEnum; @@ -13,6 +14,8 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; +import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.getSumValue; + /** * 会员积分、等级的 {@link TradeOrderHandler} 实现类 * @@ -48,10 +51,29 @@ public class TradeMemberPointOrderHandler implements TradeOrderHandler { @Override public void afterCancelOrder(TradeOrderDO order, List orderItems) { - // 扣减(回滚)用户积分(订单抵扣) - addPoint(order.getUserId(), order.getUsePoint(), MemberPointBizTypeEnum.ORDER_CANCEL, + // 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚 + orderItems = filterOrderItemListByNoneAfterSale(orderItems); + if (CollUtil.isEmpty(orderItems)) { + return; + } + + // 增加(回滚)用户积分(订单抵扣) + Integer usePoint = getSumValue(orderItems, TradeOrderItemDO::getUsePoint, Integer::sum); + addPoint(order.getUserId(), usePoint, MemberPointBizTypeEnum.ORDER_CANCEL, order.getId()); - // TODO 芋艿:需要校验;如果部分子订单已经售后退款,则不进行整单退;因为已经退了一部分积分了 + // 如下的返还,需要经过支持,也就是经历 afterPayOrder 流程 + if (!order.getPayStatus()) { + return; + } + // 扣减(回滚)积分(订单赠送) + Integer givePoint = getSumValue(orderItems, TradeOrderItemDO::getGivePoint, Integer::sum); + reducePoint(order.getUserId(), givePoint, MemberPointBizTypeEnum.ORDER_CANCEL, + order.getId()); + // 扣减(回滚)用户经验 + int payPrice = order.getPayPrice() - order.getRefundPrice(); + // TODO @疯狂:这里的 bizId 和 afterCancelOrderItem 不一致了,有什么建议的处理方案? + memberLevelApi.addExperience(order.getUserId(), -payPrice, MemberExperienceBizTypeEnum.REFUND.getType(), + String.valueOf(order.getId())); } @Override @@ -59,7 +81,7 @@ public class TradeMemberPointOrderHandler implements TradeOrderHandler { // 扣减(回滚)积分(订单赠送) reducePoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, orderItem.getAfterSaleId()); - // 扣减(回滚)积分:增加用户积分(返还抵扣) + // 增加(回滚)积分(订单抵扣) addPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED, orderItem.getAfterSaleId()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index c3cf7cdfc..605d6ae5c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -1,7 +1,9 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.collection.CollUtil; 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.enums.order.TradeOrderItemAfterSaleStatusEnum; import java.util.List; @@ -60,4 +62,17 @@ public interface TradeOrderHandler { */ default void beforeDeliveryOrder(TradeOrderDO order) {} + // ========== 公用方法 ========== + + /** + * 过滤“未售后”的订单项列表 + * + * @param orderItems 订单项列表 + * @return 过滤后的订单项列表 + */ + default List filterOrderItemListByNoneAfterSale(List orderItems) { + CollUtil.filterNew(orderItems, item -> !TradeOrderItemAfterSaleStatusEnum.isNone(item.getAfterSaleStatus())); + return orderItems; + } + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java index 6e9d91cfc..d28a643c6 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeProductSkuOrderHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.collection.CollUtil; import cn.iocoder.yudao.module.product.api.sku.ProductSkuApi; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -29,7 +30,11 @@ public class TradeProductSkuOrderHandler implements TradeOrderHandler { @Override public void afterCancelOrder(TradeOrderDO order, List orderItems) { - // TODO 芋艿:如果部分售后,最后导致取消;这里需要过滤下; + // 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚 + orderItems = filterOrderItemListByNoneAfterSale(orderItems); + if (CollUtil.isEmpty(orderItems)) { + return; + } productSkuApi.updateSkuStock(TradeOrderConvert.INSTANCE.convert(orderItems)); } From b0179457ce0ccf4cf5336e99206fcab5e34853f9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 11 Oct 2023 07:49:23 +0800 Subject: [PATCH 18/21] =?UTF-8?q?=E9=87=8D=E6=9E=84=EF=BC=9A=E5=B0=86?= =?UTF-8?q?=E8=AE=A2=E5=8D=95=E7=9A=84=E5=88=86=E6=94=AF=E6=B5=81=E7=A8=8B?= =?UTF-8?q?=EF=BC=8C=E6=8A=BD=E5=88=B0=20TradeOrderHandler=20=E5=AE=9E?= =?UTF-8?q?=E7=8E=B0=E7=B1=BB=E4=B8=AD=EF=BC=88=E8=A1=A5=E5=85=A8=E5=90=84?= =?UTF-8?q?=E7=A7=8D=E6=8E=92=E9=87=8D=E9=80=BB=E8=BE=91=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../seckillactivity/SeckillProductMapper.java | 2 +- .../handler/TradeBargainOrderHandler.java | 23 ++++++++++++---- .../handler/TradeCombinationOrderHandler.java | 18 ++++++------- .../handler/TradeMemberPointOrderHandler.java | 26 +++++++++---------- .../order/handler/TradeOrderHandler.java | 6 ++--- .../handler/TradeSeckillOrderHandler.java | 20 +++++++++++--- .../member/api/level/MemberLevelApi.java | 11 +++++++- .../enums/MemberExperienceBizTypeEnum.java | 5 ++-- .../enums/point/MemberPointBizTypeEnum.java | 13 ++++++---- .../member/api/level/MemberLevelApiImpl.java | 5 ++++ 10 files changed, 86 insertions(+), 43 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java index 8e1692415..8fb140179 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/seckill/seckillactivity/SeckillProductMapper.java @@ -41,7 +41,7 @@ public interface SeckillProductMapper extends BaseMapperX { Assert.isTrue(count > 0); return update(null, new LambdaUpdateWrapper() .eq(SeckillProductDO::getId, id) - .gt(SeckillProductDO::getStock, count) + .ge(SeckillProductDO::getStock, count) .setSql("stock = stock - " + count)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainOrderHandler.java index d34b72bf0..9af7be670 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeBargainOrderHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.promotion.api.bargain.BargainActivityApi; import cn.iocoder.yudao.module.promotion.api.bargain.BargainRecordApi; @@ -50,16 +51,28 @@ public class TradeBargainOrderHandler implements TradeOrderHandler { } @Override - public void cancelOrder(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isBargain(order.getType())) { + public void afterCancelOrder(TradeOrderDO order, List orderItems) { + if (!TradeOrderTypeEnum.isBargain(order.getType())) { return; } // 明确校验一下 Assert.isTrue(orderItems.size() == 1, "砍价时,只允许选择一个商品"); - // 恢复砍价活动的库存 - bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), - orderItems.get(0).getCount()); + // 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚 + orderItems = filterOrderItemListByNoneAfterSale(orderItems); + if (CollUtil.isEmpty(orderItems)) { + return; + } + afterCancelOrderItem(order, orderItems.get(0)); + } + + @Override + public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) { + if (!TradeOrderTypeEnum.isBargain(order.getType())) { + return; + } + // 恢复(增加)砍价活动的库存 + bargainActivityApi.updateBargainActivityStock(order.getBargainActivityId(), orderItem.getCount()); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java index 0a5c20ddb..5c00e5a12 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.common.core.KeyValue; -import cn.iocoder.yudao.framework.common.core.KeyValue; import cn.iocoder.yudao.module.promotion.api.combination.CombinationRecordApi; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -17,11 +16,9 @@ import org.springframework.stereotype.Component; import javax.annotation.Resource; import java.util.List; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS; - import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_CREATE_FAIL_EXIST_UNPAID; +import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_DELIVERY_FAIL_COMBINATION_RECORD_STATUS_NOT_SUCCESS; /** * 拼团订单的 {@link TradeOrderHandler} 实现类 @@ -50,11 +47,11 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler { } Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); - // 校验是否满足拼团活动相关限制 + // 1. 校验是否满足拼团活动相关限制 TradeOrderItemDO item = orderItems.get(0); combinationRecordApi.validateCombinationRecord(order.getUserId(), order.getCombinationActivityId(), order.getCombinationHeadId(), item.getSkuId(), item.getCount()); - // 校验该用户是否存在未支付的拼团活动订单;就是还没支付的时候,重复下单了;需要校验下;不然的话,一个拼团可以下多个单子了; + // 2. 校验该用户是否存在未支付的拼团活动订单;就是还没支付的时候,重复下单了;需要校验下;不然的话,一个拼团可以下多个单子了; TradeOrderDO activityOrder = orderQueryService.getActivityOrderByUserIdAndActivityIdAndStatus( order.getUserId(), order.getCombinationActivityId(), TradeOrderStatusEnum.UNPAID.getStatus()); if (activityOrder != null) { @@ -65,17 +62,18 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler { @Override public void afterPayOrder(TradeOrderDO order, List orderItems) { // 1.如果不是拼团订单则结束 - if (TradeOrderTypeEnum.isCombination(order.getType())) { + if (!TradeOrderTypeEnum.isCombination(order.getType())) { return; } Assert.isTrue(orderItems.size() == 1, "拼团时,只允许选择一个商品"); - // 2.获取商品信息 + // 2. 创建拼团记录 TradeOrderItemDO item = orderItems.get(0); - // 2.1.创建拼团记录 KeyValue recordIdAndHeadId = combinationRecordApi.createCombinationRecord( TradeOrderConvert.INSTANCE.convert(order, item)); - // 3.更新拼团相关信息到订单 + + // 3. 更新拼团相关信息到订单 + // TODO 芋艿,只需要更新 record orderUpdateService.updateOrderCombinationInfo(order.getId(), order.getCombinationActivityId(), recordIdAndHeadId.getKey(), recordIdAndHeadId.getValue()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java index c81bee809..0c1f9d497 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeMemberPointOrderHandler.java @@ -45,8 +45,8 @@ public class TradeMemberPointOrderHandler implements TradeOrderHandler { order.getId()); // 增加用户经验 - memberLevelApi.addExperience(order.getUserId(), order.getPayPrice(), MemberExperienceBizTypeEnum.ORDER.getType(), - String.valueOf(order.getId())); + memberLevelApi.addExperience(order.getUserId(), order.getPayPrice(), + MemberExperienceBizTypeEnum.ORDER_GIVE.getType(), String.valueOf(order.getId())); } @Override @@ -59,36 +59,36 @@ public class TradeMemberPointOrderHandler implements TradeOrderHandler { // 增加(回滚)用户积分(订单抵扣) Integer usePoint = getSumValue(orderItems, TradeOrderItemDO::getUsePoint, Integer::sum); - addPoint(order.getUserId(), usePoint, MemberPointBizTypeEnum.ORDER_CANCEL, + addPoint(order.getUserId(), usePoint, MemberPointBizTypeEnum.ORDER_USE_CANCEL, order.getId()); + // 如下的返还,需要经过支持,也就是经历 afterPayOrder 流程 if (!order.getPayStatus()) { return; } // 扣减(回滚)积分(订单赠送) Integer givePoint = getSumValue(orderItems, TradeOrderItemDO::getGivePoint, Integer::sum); - reducePoint(order.getUserId(), givePoint, MemberPointBizTypeEnum.ORDER_CANCEL, + reducePoint(order.getUserId(), givePoint, MemberPointBizTypeEnum.ORDER_GIVE_CANCEL, order.getId()); // 扣减(回滚)用户经验 int payPrice = order.getPayPrice() - order.getRefundPrice(); - // TODO @疯狂:这里的 bizId 和 afterCancelOrderItem 不一致了,有什么建议的处理方案? - memberLevelApi.addExperience(order.getUserId(), -payPrice, MemberExperienceBizTypeEnum.REFUND.getType(), - String.valueOf(order.getId())); + memberLevelApi.addExperience(order.getUserId(), payPrice, + MemberExperienceBizTypeEnum.ORDER_GIVE_CANCEL.getType(), String.valueOf(order.getId())); } @Override public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) { // 扣减(回滚)积分(订单赠送) - reducePoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.AFTER_SALE_DEDUCT_GIVE, - orderItem.getAfterSaleId()); + reducePoint(order.getUserId(), orderItem.getGivePoint(), MemberPointBizTypeEnum.ORDER_GIVE_CANCEL_ITEM, + orderItem.getId()); // 增加(回滚)积分(订单抵扣) - addPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.AFTER_SALE_REFUND_USED, - orderItem.getAfterSaleId()); + addPoint(order.getUserId(), orderItem.getUsePoint(), MemberPointBizTypeEnum.ORDER_USE_CANCEL_ITEM, + orderItem.getId()); // 扣减(回滚)用户经验 AfterSaleDO afterSale = afterSaleService.getAfterSale(orderItem.getAfterSaleId()); - memberLevelApi.addExperience(order.getUserId(), -afterSale.getRefundPrice(), MemberExperienceBizTypeEnum.REFUND.getType(), - String.valueOf(orderItem.getAfterSaleId())); + memberLevelApi.reduceExperience(order.getUserId(), afterSale.getRefundPrice(), + MemberExperienceBizTypeEnum.ORDER_GIVE_CANCEL_ITEM.getType(), String.valueOf(orderItem.getId())); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java index 605d6ae5c..4cc5c69a3 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeOrderHandler.java @@ -1,6 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; -import cn.hutool.core.collection.CollUtil; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; 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.enums.order.TradeOrderItemAfterSaleStatusEnum; @@ -71,8 +71,8 @@ public interface TradeOrderHandler { * @return 过滤后的订单项列表 */ default List filterOrderItemListByNoneAfterSale(List orderItems) { - CollUtil.filterNew(orderItems, item -> !TradeOrderItemAfterSaleStatusEnum.isNone(item.getAfterSaleStatus())); - return orderItems; + return CollectionUtils.filterList(orderItems, + item -> TradeOrderItemAfterSaleStatusEnum.isNone(item.getAfterSaleStatus())); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillOrderHandler.java index f77442b12..68227df7d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeSeckillOrderHandler.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.order.handler; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.module.promotion.api.seckill.SeckillActivityApi; import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; @@ -35,16 +36,29 @@ public class TradeSeckillOrderHandler implements TradeOrderHandler { } @Override - public void cancelOrder(TradeOrderDO order, List orderItems) { - if (TradeOrderTypeEnum.isSeckill(order.getType())) { + public void afterCancelOrder(TradeOrderDO order, List orderItems) { + if (!TradeOrderTypeEnum.isSeckill(order.getType())) { return; } // 明确校验一下 Assert.isTrue(orderItems.size() == 1, "秒杀时,只允许选择一个商品"); + // 售后的订单项,已经在 afterCancelOrderItem 回滚库存,所以这里不需要重复回滚 + orderItems = filterOrderItemListByNoneAfterSale(orderItems); + if (CollUtil.isEmpty(orderItems)) { + return; + } + afterCancelOrderItem(order, orderItems.get(0)); + } + + @Override + public void afterCancelOrderItem(TradeOrderDO order, TradeOrderItemDO orderItem) { + if (!TradeOrderTypeEnum.isSeckill(order.getType())) { + return; + } // 恢复秒杀活动的库存 seckillActivityApi.updateSeckillStockIncr(order.getSeckillActivityId(), - orderItems.get(0).getSkuId(), orderItems.get(0).getCount()); + orderItem.getSkuId(), orderItem.getCount()); } } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java index 8c055632d..587683797 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApi.java @@ -18,7 +18,6 @@ public interface MemberLevelApi { */ MemberLevelRespDTO getMemberLevel(Long id); - // TODO 芋艿:后续增加一个减少接口; /** * 增加会员经验 * @@ -29,4 +28,14 @@ public interface MemberLevelApi { */ void addExperience(Long userId, Integer experience, Integer bizType, String bizId); + /** + * 扣减会员经验 + * + * @param userId 会员ID + * @param experience 经验 + * @param bizType 业务类型 {@link MemberExperienceBizTypeEnum} + * @param bizId 业务编号 + */ + void reduceExperience(Long userId, Integer experience, Integer bizType, String bizId); + } diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java index c719ab79f..3038dba31 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/MemberExperienceBizTypeEnum.java @@ -20,10 +20,11 @@ public enum MemberExperienceBizTypeEnum { */ ADMIN(0, "管理员调整", "管理员调整获得 {} 经验", true), INVITE_REGISTER(1, "邀新奖励", "邀请好友获得 {} 经验", true), - ORDER(2, "下单奖励", "下单获得 {} 经验", true), - REFUND(3, "退单扣除", "退单获得 {} 经验", false), SIGN_IN(4, "签到奖励", "签到获得 {} 经验", true), LOTTERY(5, "抽奖奖励", "抽奖获得 {} 经验", true), + ORDER_GIVE(11, "下单奖励", "下单获得 {} 经验", true), + ORDER_GIVE_CANCEL(12, "下单奖励(整单取消)", "取消订单获得 {} 经验", false), // ORDER_GIVE 的取消 + ORDER_GIVE_CANCEL_ITEM(13, "下单奖励(单个退款)", "退款订单获得 {} 经验", false), // ORDER_GIVE 的取消 ; /** diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java index 3450a52aa..ef491f42a 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/point/MemberPointBizTypeEnum.java @@ -18,11 +18,14 @@ public enum MemberPointBizTypeEnum implements IntArrayValuable { SIGN(1, "签到", "签到获得 {} 积分", true), ADMIN(2, "管理员修改", "管理员修改 {} 积分", true), - ORDER_GIVE(10, "订单奖励", "下单获得 {} 积分", true), // 支付订单时,赠送积分 - ORDER_CANCEL(11, "订单取消", "订单取消,退还 {} 积分", true), // 取消订单时,退回积分 - ORDER_USE(12, "订单使用", "下单使用 {} 积分", false), // 下单时,扣减积分 - AFTER_SALE_REFUND_USED(13, "订单退款", "订单退款,退还 {} 积分", true), // 售后订单成功时,退回积分(对应 ORDER_USE 操作) - AFTER_SALE_DEDUCT_GIVE(14, "订单退款", "订单退款,扣除赠送的 {} 积分", false), // 售后订单成功时,扣减积分(对应 ORDER_GIVE 操作) + + ORDER_USE(11, "订单积分抵扣", "下单使用 {} 积分", false), // 下单时,扣减积分 + ORDER_USE_CANCEL(12, "订单积分抵扣(整单取消)", "订单取消,退还 {} 积分", true), // ORDER_USE 的取消 + ORDER_USE_CANCEL_ITEM(13, "订单积分抵扣(单个退款)", "订单退款,退还 {} 积分", true), // ORDER_USE 的取消 + + ORDER_GIVE(21, "订单积分奖励", "下单获得 {} 积分", true), // 支付订单时,赠送积分 + ORDER_GIVE_CANCEL(22, "订单积分奖励(整单取消)", "订单取消,退还 {} 积分", false), // ORDER_GIVE 的取消 + ORDER_GIVE_CANCEL_ITEM(23, "订单积分奖励(单个退款)", "订单退款,扣除赠送的 {} 积分", false) // ORDER_GIVE 的取消 ; /** diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java index 519a8e8a1..79fed98eb 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/api/level/MemberLevelApiImpl.java @@ -38,4 +38,9 @@ public class MemberLevelApiImpl implements MemberLevelApi { memberLevelService.addExperience(userId, experience, bizTypeEnum, bizId); } + @Override + public void reduceExperience(Long userId, Integer experience, Integer bizType, String bizId) { + addExperience(userId, -experience, bizType, bizId); + } + } From 670a098aa89490824fb6a094520dbfa7d567c985 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 11 Oct 2023 11:04:22 +0800 Subject: [PATCH 19/21] =?UTF-8?q?code=20review=EF=BC=9A=E6=8B=BC=E5=9B=A2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/combination/CombinationRecordApi.java | 4 +- .../combination/CombinationRecordApiImpl.java | 1 + .../CombinationRecordController.java | 4 ++ .../bargain/AppBargainRecordController.java | 6 --- .../mysql/bargain/BargainActivityMapper.java | 4 +- .../combination/CombinationRecordMapper.java | 1 + .../CombinationRecordExpireJob.java | 2 +- .../bargain/BargainActivityServiceImpl.java | 6 +-- .../combination/CombinationRecordService.java | 2 - .../CombinationRecordServiceImpl.java | 38 +++++++++---------- .../module/trade/api/order/TradeOrderApi.java | 11 +----- .../trade/api/order/TradeOrderApiImpl.java | 7 ---- .../dal/mysql/order/TradeOrderMapper.java | 1 + .../order/TradeOrderUpdateServiceImpl.java | 4 +- .../handler/TradeCombinationOrderHandler.java | 8 ++-- 15 files changed, 37 insertions(+), 62 deletions(-) diff --git a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java index f45b0be1f..4b42aca07 100644 --- a/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java +++ b/yudao-module-mall/yudao-module-promotion-api/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApi.java @@ -6,8 +6,6 @@ import cn.iocoder.yudao.module.promotion.api.combination.dto.CombinationValidate import javax.validation.Valid; -// TODO @芋艿:后面也再撸撸这几个接口 - /** * 拼团记录 API 接口 * @@ -30,7 +28,7 @@ public interface CombinationRecordApi { * 创建开团记录 * * @param reqDTO 请求 DTO - * @return key 开团记录编号 value 团长编号 + * @return key 开团记录编号、value 团长编号 */ KeyValue createCombinationRecord(@Valid CombinationRecordCreateReqDTO reqDTO); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java index 4a3f1dbd5..5588f3735 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/api/combination/CombinationRecordApiImpl.java @@ -29,6 +29,7 @@ public class CombinationRecordApiImpl implements CombinationRecordApi { recordService.validateCombinationRecord(userId, activityId, headId, skuId, count); } + // TODO @puhui999:搞个创建的 RespDTO 哈; @Override public KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { return recordService.createCombinationRecord(reqDTO); diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java index 98a4f3cdd..8f2b3fe99 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/admin/combination/CombinationRecordController.java @@ -40,6 +40,9 @@ public class CombinationRecordController { @Lazy private CombinationRecordService combinationRecordService; + // TODO @puhui999:getBargainRecordPage 和 getBargainRecordPage 是不是可以合并;然后 CombinationRecordReqPageVO 加一个 headId; + // 然后如果 headId 非空,并且第一页,单独多查询一条 head ;放到第 0 个位置;相当于说,第一页特殊一点; + @GetMapping("/page") @Operation(summary = "获得拼团记录分页") @PreAuthorize("@ss.hasPermission('promotion:combination-record:query')") @@ -47,6 +50,7 @@ public class CombinationRecordController { PageResult recordPage = combinationRecordService.getCombinationRecordPage(pageVO); List activities = combinationActivityService.getCombinationActivityListByIds( convertSet(recordPage.getList(), CombinationRecordDO::getActivityId)); + // TODO @puhui999:商品没读取 return success(CombinationActivityConvert.INSTANCE.convert(recordPage, activities)); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java index e09e9fdb8..b4805e6f9 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/controller/app/bargain/AppBargainRecordController.java @@ -27,7 +27,6 @@ import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; import io.swagger.v3.oas.annotations.tags.Tag; -import org.springframework.context.annotation.Lazy; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -49,20 +48,15 @@ public class AppBargainRecordController { @Resource private BargainHelpService bargainHelpService; @Resource - @Lazy private BargainRecordService bargainRecordService; @Resource - @Lazy private BargainActivityService bargainActivityService; - @Resource private TradeOrderApi tradeOrderApi; @Resource - @Lazy private MemberUserApi memberUserApi; @Resource - @Lazy private ProductSpuApi productSpuApi; @GetMapping("/get-summary") diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java index ea62b2005..0d4b85cd3 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/bargain/BargainActivityMapper.java @@ -9,7 +9,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.bargain.BargainActivityD import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import org.apache.ibatis.annotations.Mapper; -import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; import java.util.Collection; @@ -87,6 +86,7 @@ public interface BargainActivityMapper extends BaseMapperX { .last("LIMIT " + count)); } + // TODO @puhui999:是不是返回 BargainActivityDO 更干净哈? /** * 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 * @@ -94,7 +94,7 @@ public interface BargainActivityMapper extends BaseMapperX { * @param status 状态 * @return 包含 spuId 和 activityId 的 map 对象列表 */ - default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(@Param("spuIds") Collection spuIds, @Param("status") Integer status) { + default List> selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(Collection spuIds, Integer status) { return selectMaps(new QueryWrapper() .select("spu_id AS spuId, MAX(DISTINCT(id)) AS activityId") // 时间越大 id 也越大 直接用 id .in("spu_id", spuIds) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java index c232fb9d9..5d85c8938 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/dal/mysql/combination/CombinationRecordMapper.java @@ -120,6 +120,7 @@ public interface CombinationRecordMapper extends BaseMapperX() + // TODO @puhui999:这种偏逻辑性的,不要给 mapper 哈;可以考虑拆成 2 个 mapper,上层也是 2 个 service; .select(status == null && virtualGroup == null && headId == null, "DISTINCT (user_id)") .eq(status != null, "status", status) .eq(virtualGroup != null, "virtual_group", virtualGroup) diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java index 2ee6e8b63..fc0e4c6bc 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/job/combination/CombinationRecordExpireJob.java @@ -22,7 +22,7 @@ public class CombinationRecordExpireJob implements JobHandler { @Override @TenantJob - public String execute(String param) throws Exception { + public String execute(String param) { KeyValue keyValue = combinationRecordService.expireCombinationRecord(); return StrUtil.format("过期拼团 {} 个, 虚拟成团 {} 个", keyValue.getKey(), keyValue.getValue()); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java index 364cdf9ee..d43c98ba4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/bargain/BargainActivityServiceImpl.java @@ -94,7 +94,6 @@ public class BargainActivityServiceImpl implements BargainActivityService { } else if (count > 0) { bargainActivityMapper.updateStock(id, count); } - } private void validateBargainConflict(Long spuId, Long activityId) { @@ -184,12 +183,13 @@ public class BargainActivityServiceImpl implements BargainActivityService { @Override public List getBargainActivityBySpuIdsAndStatus(Collection spuIds, Integer status) { - // 1.查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 + // 1. 查询出指定 spuId 的 spu 参加的活动最接近现在的一条记录。多个的话,一个 spuId 对应一个最近的活动编号 + // TODO @puhui999:我想了下,这种是不是只展示当前正在进行中的。已经结束、或者未开始的,可能没啥意义? List> spuIdAndActivityIdMaps = bargainActivityMapper.selectSpuIdAndActivityIdMapsBySpuIdsAndStatus(spuIds, status); if (CollUtil.isEmpty(spuIdAndActivityIdMaps)) { return Collections.emptyList(); } - // 2.查询活动详情 + // 2. 查询活动详情 return bargainActivityMapper.selectListByIds(convertSet(spuIdAndActivityIdMaps, map -> MapUtil.getLong(map, "activityId"))); } diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java index 68cdde760..e6200c4d0 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordService.java @@ -146,7 +146,6 @@ public interface CombinationRecordService { */ PageResult getCombinationRecordPage2(CombinationRecordReqPage2VO pageVO); - /** * 【拼团活动】获得拼团记录数量 Map * @@ -159,7 +158,6 @@ public interface CombinationRecordService { @Nullable Integer status, @Nullable Long headId); - /** * 获取拼团记录 * diff --git a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java index 76122fa39..17b8a6ef4 100644 --- a/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-promotion-biz/src/main/java/cn/iocoder/yudao/module/promotion/service/combination/CombinationRecordServiceImpl.java @@ -23,7 +23,6 @@ import cn.iocoder.yudao.module.promotion.dal.dataobject.combination.CombinationR import cn.iocoder.yudao.module.promotion.dal.mysql.combination.CombinationRecordMapper; import cn.iocoder.yudao.module.promotion.enums.combination.CombinationRecordStatusEnum; import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; -import org.springframework.context.annotation.Lazy; import org.springframework.scheduling.annotation.Async; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -52,7 +51,6 @@ import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*; public class CombinationRecordServiceImpl implements CombinationRecordService { @Resource - @Lazy private CombinationActivityService combinationActivityService; @Resource private CombinationRecordMapper combinationRecordMapper; @@ -60,16 +58,13 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Resource private MemberUserApi memberUserApi; @Resource - @Lazy private ProductSpuApi productSpuApi; @Resource - @Lazy private ProductSkuApi productSkuApi; @Resource private TradeOrderApi tradeOrderApi; - // TODO @芋艿:在详细预览下; @Override @Transactional(rollbackFor = Exception.class) public void updateCombinationRecordStatusByUserIdAndOrderId(Integer status, Long userId, Long orderId) { @@ -77,6 +72,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { CombinationRecordDO record = validateCombinationRecord(userId, orderId); // 更新状态 + // TODO @puhui999:不要整个更新,new 一个出来;why?例如说,两个线程都去更新,这样存在相互覆盖的问题 record.setStatus(status); combinationRecordMapper.updateById(record); } @@ -169,16 +165,16 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override @Transactional(rollbackFor = Exception.class) public KeyValue createCombinationRecord(CombinationRecordCreateReqDTO reqDTO) { - // 1.校验拼团活动 + // 1. 校验拼团活动 KeyValue keyValue = validateCombinationRecord(reqDTO.getUserId(), reqDTO.getActivityId(), reqDTO.getHeadId(), reqDTO.getSkuId(), reqDTO.getCount()); - // 2.组合数据创建拼团记录 + // 2. 组合数据创建拼团记录 MemberUserRespDTO user = memberUserApi.getUser(reqDTO.getUserId()); ProductSpuRespDTO spu = productSpuApi.getSpu(reqDTO.getSpuId()); ProductSkuRespDTO sku = productSkuApi.getSku(reqDTO.getSkuId()); CombinationRecordDO record = CombinationActivityConvert.INSTANCE.convert(reqDTO, keyValue.getKey(), user, spu, sku); - // 2.1.如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP + // 2.1. 如果是团长需要设置 headId 为 CombinationRecordDO#HEAD_ID_GROUP if (record.getHeadId() == null) { record.setStartTime(LocalDateTime.now()) .setExpireTime(keyValue.getKey().getStartTime().plusHours(keyValue.getKey().getLimitDuration())) @@ -191,12 +187,10 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { } combinationRecordMapper.insert(record); - if (ObjUtil.equal(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { - return new KeyValue<>(record.getId(), record.getHeadId()); + // 3. 更新拼团记录 + if (ObjUtil.notEqual(CombinationRecordDO.HEAD_ID_GROUP, record.getHeadId())) { + updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey()); } - - // 3、更新拼团记录 - updateCombinationRecordWhenCreate(reqDTO.getHeadId(), keyValue.getKey()); return new KeyValue<>(record.getId(), record.getHeadId()); } @@ -349,6 +343,7 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { @Override public KeyValue expireCombinationRecord() { + // TODO @puhui999:数字一般是 1. 2. 这种格式哈 // 1。获取所有正在进行中的过期的父拼团 List headExpireRecords = combinationRecordMapper.selectListByHeadIdAndStatusAndExpireTimeLt( CombinationRecordDO.HEAD_ID_GROUP, CombinationRecordStatusEnum.IN_PROGRESS.getStatus(), LocalDateTime.now()); @@ -356,18 +351,21 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return new KeyValue<>(0, 0); } - // 2.获取拼团活动 + // 2. 获取拼团活动 + // TODO @puhui999:在自己模块里,变量可以简略点;例如说 activityList List combinationActivities = combinationActivityService.getCombinationActivityListByIds( convertSet(headExpireRecords, CombinationRecordDO::getActivityId)); Map activityMap = convertMap(combinationActivities, CombinationActivityDO::getId); - // 3.校验是否虚拟成团 + // TODO @puhui999:job 一般不建议异步跑;因为可能下次跑,结果上次还没跑完; + // TODO 这里,我们可以每个 record 处理下;然后按照是否需要虚拟拼团,各搞一个方法逻辑 + 事务;这样,保证 job 里面尽量不要大事务,而是 n 个独立小事务的处理。 + // 3. 校验是否虚拟成团 List virtualGroupHeadRecords = new ArrayList<>(); // 虚拟成团 for (Iterator iterator = headExpireRecords.iterator(); iterator.hasNext(); ) { CombinationRecordDO record = iterator.next(); // 3.1 不匹配,则直接跳过 - CombinationActivityDO activityDO = activityMap.get(record.getActivityId()); - if (activityDO == null || !activityDO.getVirtualGroup()) { // 取不到活动的或者不是虚拟拼团的 + CombinationActivityDO activity = activityMap.get(record.getActivityId()); + if (activity == null || !activity.getVirtualGroup()) { // 取不到活动的或者不是虚拟拼团的 continue; } // 3.2 匹配,则移除,添加到虚拟成团中,并结束寻找 @@ -380,7 +378,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { getSelf().handleExpireRecord(headExpireRecords); // 5.虚拟成团 getSelf().handleVirtualGroupRecord(virtualGroupHeadRecords); - return new KeyValue<>(headExpireRecords.size(), virtualGroupHeadRecords.size()); } @@ -401,7 +398,6 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { headsAndRecords.forEach(item -> { tradeOrderApi.cancelPaidOrder(item.getUserId(), item.getOrderId()); }); - } @Async @@ -410,9 +406,9 @@ public class CombinationRecordServiceImpl implements CombinationRecordService { return; } - // 1.团员补齐 + // 1. 团员补齐 combinationRecordMapper.insertBatch(CombinationActivityConvert.INSTANCE.convertVirtualGroupList(virtualGroupHeadRecords)); - // 2.更新拼团记录 + // 2. 更新拼团记录 updateBatchCombinationRecords(virtualGroupHeadRecords, CombinationRecordStatusEnum.SUCCESS); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java index 91298874c..ed11bc992 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java @@ -39,16 +39,7 @@ public interface TradeOrderApi { */ TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); - /** - * 更新拼团相关信息到订单 - * - * @param orderId 订单编号 - * @param activityId 拼团活动编号 - * @param combinationRecordId 拼团记录编号 - * @param headId 团长编号 - */ - void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); - + // TODO 芋艿:需要优化下; /** * 取消支付订单 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index e872b5507..6bd265331 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -5,7 +5,6 @@ import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderSummaryRespDTO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import org.springframework.validation.annotation.Validated; @@ -26,7 +25,6 @@ public class TradeOrderApiImpl implements TradeOrderApi { @Resource private TradeOrderUpdateService tradeOrderUpdateService; @Resource - @Lazy private TradeOrderQueryService tradeOrderQueryService; @Override @@ -44,11 +42,6 @@ public class TradeOrderApiImpl implements TradeOrderApi { return tradeOrderQueryService.getOrderSummary(beginTime, endTime); } - @Override - public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { - tradeOrderUpdateService.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); - } - @Override public void cancelPaidOrder(Long userId, Long orderId) { tradeOrderUpdateService.cancelPaidOrder(userId, orderId); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java index 72d05336e..a7e901543 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/order/TradeOrderMapper.java @@ -110,6 +110,7 @@ public interface TradeOrderMapper extends BaseMapperX { return selectOne(TradeOrderDO::getPickUpVerifyCode, pickUpVerifyCode); } + // TODO @hui999:是不是只针对 combinationActivityId 的查询呀? default TradeOrderDO selectByUserIdAndActivityIdAndStatus(Long userId, Long activityId, Integer status) { return selectOne(new LambdaQueryWrapperX() .and(q -> q.eq(TradeOrderDO::getUserId, userId) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 352d0083c..765b84e8b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -657,7 +657,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { public void updateOrderAddress(TradeOrderUpdateAddressReqVO reqVO) { // 校验交易订单 TradeOrderDO order = validateOrderExists(reqVO.getId()); - // 只有待发货状态才可以修改订单收货地址; + // 只有待发货状态,才可以修改订单收货地址; if (!TradeOrderStatusEnum.isUndelivered(order.getStatus())) { throw exception(ORDER_UPDATE_ADDRESS_FAIL_STATUS_NOT_DELIVERED); } @@ -823,11 +823,11 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Override @Transactional(rollbackFor = Exception.class) public void cancelPaidOrder(Long userId, Long orderId) { + // TODO 芋艿:这里实现要优化下; TradeOrderDO order = tradeOrderMapper.selectOrderByIdAndUserId(orderId, userId); if (order == null) { throw exception(ORDER_NOT_FOUND); } - cancelOrder0(order, TradeOrderCancelTypeEnum.MEMBER_CANCEL); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java index 5c00e5a12..9d32190fb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/handler/TradeCombinationOrderHandler.java @@ -10,7 +10,6 @@ import cn.iocoder.yudao.module.trade.enums.order.TradeOrderStatusEnum; import cn.iocoder.yudao.module.trade.enums.order.TradeOrderTypeEnum; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -29,14 +28,11 @@ import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_DELIV public class TradeCombinationOrderHandler implements TradeOrderHandler { @Resource - @Lazy private TradeOrderUpdateService orderUpdateService; @Resource - @Lazy private TradeOrderQueryService orderQueryService; @Resource - @Lazy private CombinationRecordApi combinationRecordApi; @Override @@ -51,7 +47,9 @@ public class TradeCombinationOrderHandler implements TradeOrderHandler { TradeOrderItemDO item = orderItems.get(0); combinationRecordApi.validateCombinationRecord(order.getUserId(), order.getCombinationActivityId(), order.getCombinationHeadId(), item.getSkuId(), item.getCount()); - // 2. 校验该用户是否存在未支付的拼团活动订单;就是还没支付的时候,重复下单了;需要校验下;不然的话,一个拼团可以下多个单子了; + + // 2. 校验该用户是否存在未支付的拼团活动订单,避免一个拼团可以下多个单子了 + // TODO @puhui999:只校验未支付的拼团订单噢 TradeOrderDO activityOrder = orderQueryService.getActivityOrderByUserIdAndActivityIdAndStatus( order.getUserId(), order.getCombinationActivityId(), TradeOrderStatusEnum.UNPAID.getStatus()); if (activityOrder != null) { From fef808d88ccaf1088d15c12e3c77cc6a6e8e8d21 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Wed, 11 Oct 2023 12:32:28 +0800 Subject: [PATCH 20/21] =?UTF-8?q?code=20review=EF=BC=9A=E7=BB=9F=E8=AE=A1?= =?UTF-8?q?=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/ip/core/utils/AreaUtils.java | 2 ++ .../infra/ApiAccessLogStatisticsMapper.java | 8 +++--- .../mysql/member/MemberStatisticsMapper.java | 5 ++-- .../mysql/pay/PayWalletStatisticsMapper.java | 3 ++- .../trade/AfterSaleStatisticsMapper.java | 2 +- .../trade/BrokerageStatisticsMapper.java | 2 +- .../trade/TradeOrderStatisticsMapper.java | 2 +- .../mysql/trade/TradeStatisticsMapper.java | 2 ++ .../infra/ApiAccessLogStatisticsService.java | 2 +- .../ApiAccessLogStatisticsServiceImpl.java | 2 +- .../member/MemberStatisticsService.java | 2 +- .../member/MemberStatisticsServiceImpl.java | 2 +- .../pay/PayWalletStatisticsService.java | 2 +- .../pay/PayWalletStatisticsServiceImpl.java | 11 ++++---- .../trade/TradeOrderStatisticsService.java | 2 +- .../trade/TradeStatisticsServiceImpl.java | 27 +++++++++---------- .../service/trade/bo/WalletSummaryRespBO.java | 1 + .../infra/ApiAccessLogStatisticsMapper.xml | 10 ++++--- .../mapper/member/MemberStatisticsMapper.xml | 5 +++- .../mapper/pay/PayWalletStatisticsMapper.xml | 9 ++++--- .../trade/AfterSaleStatisticsMapper.xml | 6 +++-- .../trade/BrokerageStatisticsMapper.xml | 4 ++- .../trade/TradeOrderStatisticsMapper.xml | 12 +++++---- .../mapper/trade/TradeStatisticsMapper.xml | 2 ++ .../api/aftersale/TradeAfterSaleApi.java | 10 ------- .../api/brokerage/TradeBrokerageApi.java | 10 ------- .../module/trade/api/order/TradeOrderApi.java | 19 ------------- .../api/aftersale/TradeAfterSaleApiImpl.java | 21 --------------- .../api/brokerage/TradeBrokerageApiImpl.java | 21 --------------- .../trade/api/order/TradeOrderApiImpl.java | 14 ---------- .../module/pay/api/wallet/PayWalletApi.java | 10 ------- .../pay/api/wallet/PayWalletApiImpl.java | 24 ----------------- 32 files changed, 73 insertions(+), 181 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java delete mode 100644 yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java delete mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java delete mode 100644 yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java delete mode 100644 yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java diff --git a/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java b/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java index 8455dff9a..552bfc9be 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-ip/src/main/java/cn/iocoder/yudao/framework/ip/core/utils/AreaUtils.java @@ -132,7 +132,9 @@ public class AreaUtils { return convertList(areas.values(), func, area -> type.getType().equals(area.getType())); } + // TODO @疯狂:注释写下; public static Integer getParentIdByType(Integer id, @NonNull AreaTypeEnum type) { + // TODO @疯狂:这种不要用 while true;因为万一脏数据,可能会死循环;可以转换成 for (int i = 0; i < Byte.MAX; i++) 一般是优先层级; do { Area area = AreaUtils.getArea(id); if (area == null) { diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java index 0e8d719ad..757b8f544 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/infra/ApiAccessLogStatisticsMapper.java @@ -7,15 +7,17 @@ import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; /** - * API 访问日志统计 Mapper + * API 访问日志的统计 Mapper * * @author owen */ @Mapper public interface ApiAccessLogStatisticsMapper extends BaseMapperX { - Integer selectCountByIp(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + Integer selectCountByIp(@Param("beginTime") LocalDateTime beginTime, + @Param("endTime") LocalDateTime endTime); - Integer selectCountByUserId(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + Integer selectCountByUserId(@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/dal/mysql/member/MemberStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java index 22a89ea9d..ca6c6d362 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/member/MemberStatisticsMapper.java @@ -10,7 +10,7 @@ import java.time.LocalDateTime; import java.util.List; /** - * 会员统计 Mapper + * 会员信息的统计 Mapper * * @author owen */ @@ -21,6 +21,7 @@ public interface MemberStatisticsMapper extends BaseMapperX { List selectSummaryListBySex(); - Integer selectUserCount(@Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + Integer selectUserCount(@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/dal/mysql/pay/PayWalletStatisticsMapper.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java index 75e6a4ae1..4aff0ab8d 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/dal/mysql/pay/PayWalletStatisticsMapper.java @@ -10,7 +10,7 @@ import org.apache.ibatis.annotations.Param; import java.time.LocalDateTime; /** - * 交易统计 Mapper + * 支付钱包的统计 Mapper * * @author owen */ @@ -29,6 +29,7 @@ public interface PayWalletStatisticsMapper extends BaseMapperX { + // TODO @疯狂:这个要不要也挪到 xml 里,保持统一? @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") @@ -33,4 +34,5 @@ public interface TradeStatisticsMapper extends BaseMapperX { Integer selectExpensePriceByTimeBetween(@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/infra/ApiAccessLogStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java index c83f4da82..e29f5fd9c 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsService.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.statistics.service.infra; import java.time.LocalDateTime; /** - * API 访问日志统计 Service 接口 + * API 访问日志的统计 Service 接口 * * @author owen */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java index 4c9fb08e2..be920169f 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/infra/ApiAccessLogStatisticsServiceImpl.java @@ -8,7 +8,7 @@ import javax.annotation.Resource; import java.time.LocalDateTime; /** - * API 访问日志统计 Service 实现类 + * API 访问日志的统计 Service 实现类 * * @author owen */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java index 2c84c3616..7c60affeb 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java @@ -9,7 +9,7 @@ import java.time.LocalDateTime; import java.util.List; /** - * 会员统计 Service 接口 + * 会员信息的统计 Service 接口 * * @author owen */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java index 153e7c581..02623e7de 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java @@ -24,7 +24,7 @@ import java.util.Optional; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertMap; /** - * 会员统计 Service 实现类 + * 会员信息的统计 Service 实现类 * * @author owen */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java index 77e3e4fd2..09285f88f 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsService.java @@ -6,7 +6,7 @@ import cn.iocoder.yudao.module.statistics.service.trade.bo.WalletSummaryRespBO; import java.time.LocalDateTime; /** - * 钱包统计 Service 接口 + * 钱包的统计 Service 接口 * * @author owen */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java index 28b1f434e..f2cfd5bf7 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/pay/PayWalletStatisticsServiceImpl.java @@ -12,7 +12,7 @@ import javax.annotation.Resource; import java.time.LocalDateTime; /** - * 钱包统计 Service 实现类 + * 钱包的统计 Service 实现类 * * @author owen */ @@ -31,11 +31,10 @@ public class PayWalletStatisticsServiceImpl implements PayWalletStatisticsServic beginTime, endTime, PayRefundStatusEnum.SUCCESS.getStatus()); Integer walletPayPrice = payWalletStatisticsMapper.selectPriceSummaryByBizTypeAndCreateTimeBetween( beginTime, endTime, PayWalletBizTypeEnum.PAYMENT.getType()); - - paySummary.setOrderWalletPayPrice(walletPayPrice); - paySummary.setRechargeRefundCount(refundSummary.getRechargeRefundCount()); - paySummary.setRechargeRefundPrice(refundSummary.getRechargeRefundPrice()); - + // 拼接 + paySummary.setOrderWalletPayPrice(walletPayPrice) + .setRechargeRefundCount(refundSummary.getRechargeRefundCount()) + .setRechargeRefundPrice(refundSummary.getRechargeRefundPrice()); return paySummary; } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java index b02745e6f..9388fe76c 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/TradeOrderStatisticsService.java @@ -7,7 +7,7 @@ import java.time.LocalDateTime; import java.util.List; /** - * 交易订单统计 Service 接口 + * 交易订单的统计 Service 接口 * * @author owen */ 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 index 7a25dfe89..6a751a0cd 100644 --- 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 @@ -45,16 +45,15 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { @Override public TradeStatisticsComparisonRespVO getTradeSummaryComparison() { - // 昨天的数据 + // 1.1 昨天的数据 TradeSummaryRespBO yesterdayData = getTradeSummaryByDays(-1); - // 前天的数据(用于对照昨天的数据) + // 1.2 前天的数据(用于对照昨天的数据) TradeSummaryRespBO beforeYesterdayData = getTradeSummaryByDays(-2); - - // 本月数据; + // 2.1 本月数据 TradeSummaryRespBO monthData = getTradeSummaryByMonths(0); - // 上月数据(用于对照本月的数据) + // 2.2 上月数据(用于对照本月的数据) TradeSummaryRespBO lastMonthData = getTradeSummaryByMonths(-1); - + // 转换返回 return TradeStatisticsConvert.INSTANCE.convert(yesterdayData, beforeYesterdayData, monthData, lastMonthData); } @@ -81,31 +80,31 @@ public class TradeStatisticsServiceImpl implements TradeStatisticsService { @Override public String statisticsYesterdayTrade() { - // 处理统计参数 LocalDateTime yesterday = LocalDateTime.now().minusDays(1); LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); - // 统计 + // 1.1 统计订单 StopWatch stopWatch = new StopWatch("交易统计"); stopWatch.start("统计订单"); TradeOrderSummaryRespBO orderSummary = tradeOrderStatisticsService.getOrderSummary(beginTime, endTime); stopWatch.stop(); - + // 1.2 统计售后 stopWatch.start("统计售后"); AfterSaleSummaryRespBO afterSaleSummary = afterSaleStatisticsService.getAfterSaleSummary(beginTime, endTime); stopWatch.stop(); - + // 1.3 统计佣金 stopWatch.start("统计佣金"); Integer brokerageSettlementPrice = brokerageStatisticsService.getBrokerageSettlementPriceSummary(beginTime, endTime); stopWatch.stop(); - + // 1.4 统计充值 stopWatch.start("统计充值"); WalletSummaryRespBO walletSummary = payWalletStatisticsService.getWalletSummary(beginTime, endTime); stopWatch.stop(); - // 插入数据 - TradeStatisticsDO entity = TradeStatisticsConvert.INSTANCE.convert(yesterday, orderSummary, afterSaleSummary, brokerageSettlementPrice, walletSummary); + + // 2. 插入数据 + TradeStatisticsDO entity = TradeStatisticsConvert.INSTANCE.convert(yesterday, orderSummary, afterSaleSummary, + brokerageSettlementPrice, walletSummary); tradeStatisticsMapper.insert(entity); - // 返回计时结果 return stopWatch.prettyPrint(); } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java index 97e319722..ada494e30 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/trade/bo/WalletSummaryRespBO.java @@ -9,6 +9,7 @@ import lombok.Data; */ @Data public class WalletSummaryRespBO { + /** * 总支付金额(余额),单位:分 */ diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml index 2ef803ac1..6ff6c1307 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/infra/ApiAccessLogStatisticsMapper.xml @@ -1,20 +1,22 @@ + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml index decdd78a6..f739656d7 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/member/MemberStatisticsMapper.xml @@ -8,6 +8,7 @@ FROM member_user WHERE deleted = FALSE GROUP BY area_id + ORDER BY userCount DESC @@ -17,6 +18,7 @@ FROM member_user WHERE deleted = FALSE GROUP BY sex + ORDER BY userCount DESC @@ -31,4 +33,5 @@ AND create_time <= #{endTime} - \ No newline at end of file + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml index e03f490a3..a8acb056f 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/pay/PayWalletStatisticsMapper.xml @@ -7,8 +7,8 @@ SUM(pay_price) AS rechargePayPrice FROM pay_wallet_recharge WHERE pay_status = #{payStatus} - AND deleted = FALSE AND pay_time BETWEEN #{beginTime} AND #{endTime} + AND deleted = FALSE SELECT SUM(price) FROM pay_wallet_transaction WHERE biz_type = #{bizType} - AND deleted = FALSE AND create_time BETWEEN #{beginTime} AND #{endTime} + AND deleted = FALSE + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml index c89fe9ed4..000cb26fd 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/AfterSaleStatisticsMapper.xml @@ -1,12 +1,14 @@ + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml index ae19fcef4..f8f9b2c11 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/BrokerageStatisticsMapper.xml @@ -1,12 +1,14 @@ + + diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml index 0d585f2a2..dbc3a11c7 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml @@ -1,6 +1,7 @@ + SELECT COUNT(1) FROM trade_order - WHERE deleted = FALSE + WHERE pay_time BETWEEN #{beginTime} AND #{endTime} AND pay_status = TRUE - AND pay_time BETWEEN #{beginTime} AND #{endTime} + AND deleted = FALSE GROUP BY user_id + 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 index 06f8cf993..5ca3c38ed 100644 --- 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 @@ -1,6 +1,7 @@ + + diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java deleted file mode 100644 index 5f58b5393..000000000 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApi.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.module.trade.api.aftersale; - -/** - * 售后 API 接口 - * - * @author owen - */ -public interface TradeAfterSaleApi { - -} diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java deleted file mode 100644 index 8628098a3..000000000 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApi.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.module.trade.api.brokerage; - -/** - * 分销 API 接口 - * - * @author owen - */ -public interface TradeBrokerageApi { - -} diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java index 1f6bed553..744a7b8fd 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApi.java @@ -28,25 +28,6 @@ public interface TradeOrderApi { */ TradeOrderRespDTO getOrder(Long id); - /** - * 获取订单统计 - * - * @param beginTime 起始时间 - * @param endTime 截止时间 - * @return 订单统计结果 - */ - TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime); - - /** - * 更新拼团相关信息到订单 - * - * @param orderId 订单编号 - * @param activityId 拼团活动编号 - * @param combinationRecordId 拼团记录编号 - * @param headId 团长编号 - */ - void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId); - // TODO 芋艿:需要优化下; /** * 取消支付订单 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java deleted file mode 100644 index 474943e38..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/aftersale/TradeAfterSaleApiImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -package cn.iocoder.yudao.module.trade.api.aftersale; - -import cn.iocoder.yudao.module.trade.service.aftersale.AfterSaleService; -import org.springframework.stereotype.Service; -import org.springframework.validation.annotation.Validated; - -import javax.annotation.Resource; - -/** - * 售后 API 接口实现类 - * - * @author owen - */ -@Service -@Validated -public class TradeAfterSaleApiImpl implements TradeAfterSaleApi { - - @Resource - private AfterSaleService afterSaleService; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java deleted file mode 100644 index c860d4b7f..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/brokerage/TradeBrokerageApiImpl.java +++ /dev/null @@ -1,21 +0,0 @@ -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; - -/** - * 订单 API 接口实现类 - * - * @author HUIHUI - */ -@Service -@Validated -public class TradeBrokerageApiImpl implements TradeBrokerageApi { - - @Resource - private BrokerageRecordService brokerageRecordService; - -} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java index 6153c0657..3cb7bbae7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/api/order/TradeOrderApiImpl.java @@ -2,7 +2,6 @@ package cn.iocoder.yudao.module.trade.api.order; import cn.iocoder.yudao.module.trade.api.order.dto.TradeOrderRespDTO; import cn.iocoder.yudao.module.trade.convert.order.TradeOrderConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.order.TradeOrderDO; import cn.iocoder.yudao.module.trade.service.order.TradeOrderQueryService; import cn.iocoder.yudao.module.trade.service.order.TradeOrderUpdateService; import org.springframework.stereotype.Service; @@ -12,9 +11,6 @@ import javax.annotation.Resource; import java.util.Collection; import java.util.List; -import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; -import static cn.iocoder.yudao.module.trade.enums.ErrorCodeConstants.ORDER_NOT_FOUND; - /** * 订单 API 接口实现类 * @@ -39,16 +35,6 @@ public class TradeOrderApiImpl implements TradeOrderApi { return TradeOrderConvert.INSTANCE.convert(tradeOrderQueryService.getOrder(id)); } - @Override - public TradeOrderSummaryRespDTO getOrderSummary(LocalDateTime beginTime, LocalDateTime endTime) { - return tradeOrderQueryService.getOrderSummary(beginTime, endTime); - } - - @Override - public void updateOrderCombinationInfo(Long orderId, Long activityId, Long combinationRecordId, Long headId) { - tradeOrderUpdateService.updateOrderCombinationInfo(orderId, activityId, combinationRecordId, headId); - } - @Override public void cancelPaidOrder(Long userId, Long orderId) { tradeOrderUpdateService.cancelPaidOrder(userId, orderId); diff --git a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java b/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java deleted file mode 100644 index 5bb50bf6d..000000000 --- a/yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApi.java +++ /dev/null @@ -1,10 +0,0 @@ -package cn.iocoder.yudao.module.pay.api.wallet; - -/** - * 钱包 API 接口 - * - * @author owen - */ -public interface PayWalletApi { - -} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java deleted file mode 100644 index 89be2a25e..000000000 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/api/wallet/PayWalletApiImpl.java +++ /dev/null @@ -1,24 +0,0 @@ -package cn.iocoder.yudao.module.pay.api.wallet; - -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; - -/** - * 钱包 API 接口实现类 - * - * @author owen - */ -@Service -@Validated -public class PayWalletApiImpl implements PayWalletApi { - - @Resource - private PayWalletRechargeService payWalletRechargeService; - @Resource - private PayWalletTransactionService payWalletTransactionService; - -} From a72869b97edb263793cfc514736a42f6e85ad8d9 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 12 Oct 2023 21:54:06 +0800 Subject: [PATCH 21/21] =?UTF-8?q?code=20review=EF=BC=9A=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E9=83=A8=E5=88=86=E7=BB=9F=E8=AE=A1=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/admin/member/package-info.java | 9 ------- .../member/MemberStatisticsService.java | 14 +++++------ .../member/MemberStatisticsServiceImpl.java | 25 +++++++++---------- .../trade/TradeOrderStatisticsMapper.xml | 6 ++--- 4 files changed, 21 insertions(+), 33 deletions(-) delete mode 100644 yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/package-info.java diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/package-info.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/package-info.java deleted file mode 100644 index f3a5e3fff..000000000 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/controller/admin/member/package-info.java +++ /dev/null @@ -1,9 +0,0 @@ -/** - * TODO - * 1. 会员总数据 - * 2. 性别统计 - * 3. 渠道统计 - * 4. 地域统计 - * 5. 会员概览 - */ -package cn.iocoder.yudao.module.statistics.controller.admin.member; diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java index 7c60affeb..1f30eeb8d 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsService.java @@ -15,6 +15,13 @@ import java.util.List; */ public interface MemberStatisticsService { + /** + * 获取会员统计 + * + * @return 会员统计 + */ + MemberSummaryRespVO getMemberSummary(); + /** * 按照省份,获得会员统计列表 * @@ -38,11 +45,4 @@ public interface MemberStatisticsService { */ MemberAnalyseRespVO getMemberAnalyse(LocalDateTime beginTime, LocalDateTime endTime); - /** - * 获取会员统计 - * - * @return 会员统计 - */ - MemberSummaryRespVO getMemberSummary(); - } diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java index 02623e7de..a93938b06 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/java/cn/iocoder/yudao/module/statistics/service/member/MemberStatisticsServiceImpl.java @@ -44,6 +44,18 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { @Resource private ApiAccessLogStatisticsService apiAccessLogStatisticsService; + @Override + public MemberSummaryRespVO getMemberSummary() { + MemberSummaryRespVO vo = payWalletStatisticsService.getUserRechargeSummary(null, null); + Integer expensePrice = tradeStatisticsService.getExpensePrice(null, null); + Integer userCount = memberStatisticsMapper.selectUserCount(null, null); + // 拼接数据 + if (vo == null) { + vo = new MemberSummaryRespVO().setRechargeUserCount(0).setRechargePrice(0); + } + return vo.setUserCount(userCount).setExpensePrice(expensePrice); + } + @Override public List getMemberAreaStatisticsList() { // 统计用户 @@ -89,19 +101,6 @@ public class MemberStatisticsServiceImpl implements MemberStatisticsService { .setComparison(new TradeStatisticsComparisonRespVO<>(vo, reference)); } - @Override - public MemberSummaryRespVO getMemberSummary() { - MemberSummaryRespVO vo = payWalletStatisticsService.getUserRechargeSummary(null, null); - Integer expensePrice = tradeStatisticsService.getExpensePrice(null, null); - Integer userCount = memberStatisticsMapper.selectUserCount(null, null); - - if (vo == null) { - vo = new MemberSummaryRespVO().setRechargeUserCount(0).setRechargePrice(0); - } - - return vo.setUserCount(userCount).setExpensePrice(expensePrice); - } - private MemberAnalyseComparisonRespVO getMemberAnalyseComparisonData(LocalDateTime beginTime, LocalDateTime endTime) { Integer rechargeUserCount = Optional.ofNullable(payWalletStatisticsService.getUserRechargeSummary(beginTime, endTime)) .map(MemberSummaryRespVO::getRechargeUserCount).orElse(0); diff --git a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml index dbc3a11c7..2cecd468e 100644 --- a/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml +++ b/yudao-module-mall/yudao-module-statistics-biz/src/main/resources/mapper/trade/TradeOrderStatisticsMapper.xml @@ -24,20 +24,18 @@