From b1ce971a2f647fa21cc1431d081792e93c2c5ea6 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Thu, 28 Sep 2023 16:39:07 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=EF=BC=9A=E8=A7=A3=E5=86=B3?= =?UTF-8?q?=E5=88=86=E4=BD=A3=E7=9A=84=20npe=20=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ProductCommentServiceImplTest.java | 3 --- .../brokerage/BrokerageUserController.java | 24 +++++++++---------- .../vo/user/BrokerageUserRespVO.java | 14 +++++------ .../brokerage/AppBrokerageUserController.java | 4 ++-- .../brokerage/BrokerageUserConvert.java | 24 +++++++++---------- .../brokerage/BrokerageRecordMapper.java | 12 +++++----- .../brokerage/BrokerageWithdrawMapper.java | 8 +++---- .../brokerage/BrokerageRecordService.java | 15 ++++++++---- .../brokerage/BrokerageRecordServiceImpl.java | 14 +++++++---- .../brokerage/BrokerageUserServiceImpl.java | 8 +++---- .../brokerage/BrokerageWithdrawService.java | 9 +++---- .../BrokerageWithdrawServiceImpl.java | 10 ++++++-- ...va => BrokerageWithdrawSummaryRespBO.java} | 4 ++-- ...O.java => UserBrokerageSummaryRespBO.java} | 2 +- 14 files changed, 82 insertions(+), 69 deletions(-) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/{UserWithdrawSummaryBO.java => BrokerageWithdrawSummaryRespBO.java} (85%) rename yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/{UserBrokerageSummaryBO.java => UserBrokerageSummaryRespBO.java} (91%) diff --git a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java index 2f55af837..fb6bc3649 100644 --- a/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java +++ b/yudao-module-mall/yudao-module-product-biz/src/test/java/cn/iocoder/yudao/module/product/service/comment/ProductCommentServiceImplTest.java @@ -16,7 +16,6 @@ import cn.iocoder.yudao.module.product.dal.mysql.comment.ProductCommentMapper; import cn.iocoder.yudao.module.product.enums.comment.ProductCommentScoresEnum; import cn.iocoder.yudao.module.product.service.sku.ProductSkuService; import cn.iocoder.yudao.module.product.service.spu.ProductSpuService; -import cn.iocoder.yudao.module.trade.api.order.TradeOrderApi; import org.junit.jupiter.api.Test; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.context.annotation.Import; @@ -48,8 +47,6 @@ public class ProductCommentServiceImplTest extends BaseDbUnitTest { @Lazy private ProductCommentServiceImpl productCommentService; - @MockBean - private TradeOrderApi tradeOrderApi; @MockBean private ProductSpuService productSpuService; @MockBean diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java index 71832fd8b..7ec3d8f0f 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/BrokerageUserController.java @@ -13,8 +13,8 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum 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.BrokerageWithdrawService; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryRespBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -88,24 +88,24 @@ public class BrokerageUserController { // 分页查询 PageResult pageResult = brokerageUserService.getBrokerageUserPage(pageVO); - // 涉及到的用户 - Set userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); // 查询用户信息 + Set userIds = convertSet(pageResult.getList(), BrokerageUserDO::getId); Map userMap = memberUserApi.getUserMap(userIds); - // 合计分佣订单 - Map userOrderSummaryMap = brokerageRecordService.getUserBrokerageSummaryMapByUserId( + // 合计分佣的推广订单 + Map brokerageOrderSummaryMap = brokerageRecordService.getUserBrokerageSummaryMapByUserId( userIds, BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus()); - // TODO @芋艿:看看下面 getBrokerageUserCountByBindUserId 有没可能一次性出结果,不然 n 次有点太花性能了; - // 合计推广用户数量 + // 合计分佣的推广用户 + // TODO @疯狂:转成 map 批量读取 Map brokerageUserCountMap = convertMap(userIds, userId -> userId, userId -> brokerageUserService.getBrokerageUserCountByBindUserId(userId, null)); - // 合计提现 - Map withdrawMap = brokerageWithdrawService.getWithdrawSummaryMapByUserId(userIds, - BrokerageWithdrawStatusEnum.AUDIT_SUCCESS); + // 合计分佣的提现 + // TODO @疯狂:如果未来支持了打款这个动作,可能 status 会不对; + Map withdrawMap = brokerageWithdrawService.getWithdrawSummaryMapByUserId( + userIds, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS); // 拼接返回 return success(BrokerageUserConvert.INSTANCE.convertPage(pageResult, userMap, brokerageUserCountMap, - userOrderSummaryMap, withdrawMap)); + brokerageOrderSummaryMap, withdrawMap)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java index 4713d8e13..29b54ff2e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/vo/user/BrokerageUserRespVO.java @@ -21,25 +21,25 @@ public class BrokerageUserRespVO extends BrokerageUserBaseVO { // ========== 用户信息 ========== - @Schema(description = "用户头像", example = "https://www.iocoder.cn/xxx.png") + @Schema(description = "用户头像", requiredMode = Schema.RequiredMode.REQUIRED, example = "https://www.iocoder.cn/xxx.png") private String avatar; - @Schema(description = "用户昵称", example = "李四") + @Schema(description = "用户昵称", requiredMode = Schema.RequiredMode.REQUIRED, example = "李四") private String nickname; // ========== 推广信息 ========== - @Schema(description = "推广用户数量", example = "20019") + @Schema(description = "推广用户数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") private Integer brokerageUserCount; - @Schema(description = "推广订单数量", example = "20019") + @Schema(description = "推广订单数量", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") private Integer brokerageOrderCount; - @Schema(description = "推广订单金额", example = "20019") + @Schema(description = "推广订单金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") private Integer brokerageOrderPrice; // ========== 提现信息 ========== - @Schema(description = "已提现金额", example = "20019") + @Schema(description = "已提现金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") private Integer withdrawPrice; - @Schema(description = "已提现次数", example = "20019") + @Schema(description = "已提现次数", requiredMode = Schema.RequiredMode.REQUIRED, example = "20019") private Integer withdrawCount; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java index 905b910da..d9d64e6fa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageUserController.java @@ -15,7 +15,7 @@ import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum 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.BrokerageWithdrawService; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -88,7 +88,7 @@ public class AppBrokerageUserController { // 统计用户提现的佣金 Integer withdrawPrice = brokerageWithdrawService.getWithdrawSummaryListByUserId(Collections.singleton(brokerageUser.getId()), BrokerageWithdrawStatusEnum.AUDIT_SUCCESS).stream() - .findFirst().map(UserWithdrawSummaryBO::getPrice).orElse(0); + .findFirst().map(BrokerageWithdrawSummaryRespBO::getPrice).orElse(0); // 统计分销用户数量(一级) Long firstBrokerageUserCount = brokerageUserService.getBrokerageUserCountByBindUserId(brokerageUser.getId(), 1); // 统计分销用户数量(二级) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java index 086ef0aa1..c3f7fbf58 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/BrokerageUserConvert.java @@ -8,8 +8,8 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.user.Brokerag import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserMySummaryRespVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByUserCountRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageUserDO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryRespBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO; import org.mapstruct.Mapper; import org.mapstruct.MappingTarget; import org.mapstruct.factory.Mappers; @@ -32,29 +32,27 @@ public interface BrokerageUserConvert { List convertList(List list); - PageResult convertPage(PageResult page, Map userMap, Map brokerageUserCountMap, Map userOrderSummaryMap); + PageResult convertPage(PageResult page, Map userMap, Map brokerageUserCountMap, Map userOrderSummaryMap); default PageResult convertPage(PageResult pageResult, Map userMap, Map brokerageUserCountMap, - Map userOrderSummaryMap, - Map withdrawMap) { + Map userOrderSummaryMap, + Map withdrawMap) { PageResult result = convertPage(pageResult, userMap, brokerageUserCountMap, userOrderSummaryMap); for (BrokerageUserRespVO userVO : result.getList()) { // 用户信息 copyTo(userMap.get(userVO.getId()), userVO); - // 推广用户数量 userVO.setBrokerageUserCount(MapUtil.getInt(brokerageUserCountMap, userVO.getId(), 0)); // 推广订单数量、推广订单金额 - Optional orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(userVO.getId())); - userVO.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryBO::getCount).orElse(0)) - .setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryBO::getPrice).orElse(0)); + Optional orderSummaryOptional = Optional.ofNullable(userOrderSummaryMap.get(userVO.getId())); + userVO.setBrokerageOrderCount(orderSummaryOptional.map(UserBrokerageSummaryRespBO::getCount).orElse(0)) + .setBrokerageOrderPrice(orderSummaryOptional.map(UserBrokerageSummaryRespBO::getPrice).orElse(0)); // 已提现次数、已提现金额 - Optional withdrawSummaryOptional = Optional.ofNullable(withdrawMap.get(userVO.getId())); - userVO.setWithdrawCount(withdrawSummaryOptional.map(UserWithdrawSummaryBO::getCount).orElse(0)) - .setWithdrawPrice(withdrawSummaryOptional.map(UserWithdrawSummaryBO::getPrice).orElse(0)); - userVO.setWithdrawCount(0).setWithdrawPrice(0); + Optional withdrawSummaryOptional = Optional.ofNullable(withdrawMap.get(userVO.getId())); + userVO.setWithdrawCount(withdrawSummaryOptional.map(BrokerageWithdrawSummaryRespBO::getCount).orElse(0)) + .setWithdrawPrice(withdrawSummaryOptional.map(BrokerageWithdrawSummaryRespBO::getPrice).orElse(0)); } return result; } 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 aa71111fb..e0414807c 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 @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.record.BrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokerageUserRankByPriceRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryRespBO; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.github.yulichang.toolkit.MPJWrappers; @@ -56,18 +56,18 @@ public interface BrokerageRecordMapper extends BaseMapperX { BrokerageRecordDO::getUserId, userId); } - default List selectCountAndSumPriceByUserIdInAndBizTypeAndStatus(Collection userIds, - Integer bizType, - Integer status) { + default List selectCountAndSumPriceByUserIdInAndBizTypeAndStatus(Collection userIds, + Integer bizType, + Integer status) { List> list = selectMaps(MPJWrappers.lambdaJoin(BrokerageRecordDO.class) .select(BrokerageRecordDO::getUserId) - .selectCount(BrokerageRecordDO::getId, UserBrokerageSummaryBO::getCount) + .selectCount(BrokerageRecordDO::getId, UserBrokerageSummaryRespBO::getCount) .selectSum(BrokerageRecordDO::getPrice) .in(BrokerageRecordDO::getUserId, userIds) .eq(BrokerageRecordDO::getBizId, bizType) .eq(BrokerageRecordDO::getStatus, status) .groupBy(BrokerageRecordDO::getUserId)); - return BeanUtil.copyToList(list, UserBrokerageSummaryBO.class); + return BeanUtil.copyToList(list, UserBrokerageSummaryRespBO.class); // selectJoinList有BUG,会与租户插件冲突:解析SQL时,发生异常 https://gitee.com/best_handsome/mybatis-plus-join/issues/I84GYW // return selectJoinList(UserBrokerageSummaryBO.class, MPJWrappers.lambdaJoin(BrokerageRecordDO.class) // .select(BrokerageRecordDO::getUserId) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java index 4bbf427e9..9e2cf68ad 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageWithdrawMapper.java @@ -6,7 +6,7 @@ import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.BrokerageWithdrawPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.github.yulichang.wrapper.MPJLambdaWrapper; import org.apache.ibatis.annotations.Mapper; @@ -41,15 +41,15 @@ public interface BrokerageWithdrawMapper extends BaseMapperX selectCountAndSumPriceByUserIdAndStatus(Collection userIds, Integer status) { + default List selectCountAndSumPriceByUserIdAndStatus(Collection userIds, Integer status) { List> list = selectMaps(new MPJLambdaWrapper() .select(BrokerageWithdrawDO::getUserId) - .selectCount(BrokerageWithdrawDO::getId, UserWithdrawSummaryBO::getCount) + .selectCount(BrokerageWithdrawDO::getId, BrokerageWithdrawSummaryRespBO::getCount) .selectSum(BrokerageWithdrawDO::getPrice) .in(BrokerageWithdrawDO::getUserId, userIds) .eq(BrokerageWithdrawDO::getStatus, status) .groupBy(BrokerageWithdrawDO::getUserId)); - return BeanUtil.copyToList(list, UserWithdrawSummaryBO.class); + return BeanUtil.copyToList(list, BrokerageWithdrawSummaryRespBO.class); // selectJoinList有BUG,会与租户插件冲突:解析SQL时,发生异常 https://gitee.com/best_handsome/mybatis-plus-join/issues/I84GYW // return selectJoinList(UserWithdrawSummaryBO.class, new MPJLambdaWrapper() // .select(BrokerageWithdrawDO::getUserId) 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 edca9f370..410c7631b 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 @@ -8,7 +8,7 @@ import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.user.AppBrokera import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageRecordDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryRespBO; import javax.validation.Valid; import java.time.LocalDateTime; @@ -85,7 +85,8 @@ public interface BrokerageRecordService { * @param status 佣金状态 * @return 用户佣金汇总 List */ - List getUserBrokerageSummaryListByUserId(Collection userIds, Integer bizType, Integer status); + List getUserBrokerageSummaryListByUserId(Collection userIds, + Integer bizType, Integer status); /** * 按照 userId,汇总每个用户的佣金 @@ -95,8 +96,10 @@ public interface BrokerageRecordService { * @param status 佣金状态 * @return 用户佣金汇总 Map */ - default Map getUserBrokerageSummaryMapByUserId(Collection userIds, Integer bizType, Integer status) { - return convertMap(getUserBrokerageSummaryListByUserId(userIds, bizType, status), UserBrokerageSummaryBO::getUserId); + default Map getUserBrokerageSummaryMapByUserId(Collection userIds, + Integer bizType, Integer status) { + return convertMap(getUserBrokerageSummaryListByUserId(userIds, bizType, status), + UserBrokerageSummaryRespBO::getUserId); } /** @@ -116,7 +119,8 @@ public interface BrokerageRecordService { * @param pageReqVO 分页查询 * @return 排行榜分页 */ - PageResult getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO); + PageResult getBrokerageUserChildSummaryPageByPrice( + AppBrokerageUserRankPageReqVO pageReqVO); /** * 获取用户的排名(基于佣金总数) @@ -135,4 +139,5 @@ public interface BrokerageRecordService { * @return 用户佣金 */ AppBrokerageProductPriceRespVO calculateProductBrokeragePrice(Long spuId, Long userId); + } 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 63b98e9c5..02fc897ba 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 @@ -26,7 +26,7 @@ import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.BrokerageRecordMapper; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserBrokerageSummaryRespBO; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import com.baomidou.mybatisplus.core.metadata.IPage; import lombok.extern.slf4j.Slf4j; @@ -232,18 +232,24 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { } @Override - public List getUserBrokerageSummaryListByUserId(Collection userIds, Integer bizType, Integer status) { + public List getUserBrokerageSummaryListByUserId(Collection userIds, + Integer bizType, Integer status) { + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } return brokerageRecordMapper.selectCountAndSumPriceByUserIdInAndBizTypeAndStatus(userIds, bizType, status); } @Override public Integer getSummaryPriceByUserId(Long userId, Integer bizType, LocalDateTime beginTime, LocalDateTime endTime) { - return brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, bizType, beginTime, endTime); + return brokerageRecordMapper.selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(userId, bizType, + beginTime, endTime); } @Override public PageResult getBrokerageUserChildSummaryPageByPrice(AppBrokerageUserRankPageReqVO pageReqVO) { - IPage pageResult = brokerageRecordMapper.selectSummaryPricePageGroupByUserId(MyBatisUtils.buildPage(pageReqVO), + IPage pageResult = brokerageRecordMapper.selectSummaryPricePageGroupByUserId( + MyBatisUtils.buildPage(pageReqVO), BrokerageRecordBizTypeEnum.ORDER.getType(), BrokerageRecordStatusEnum.SETTLEMENT.getStatus(), ArrayUtil.get(pageReqVO.getTimes(), 0), ArrayUtil.get(pageReqVO.getTimes(), 1)); return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java index d8d4bdc62..2d192092c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageUserServiceImpl.java @@ -26,10 +26,7 @@ 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.Objects; -import java.util.Optional; +import java.util.*; import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList; @@ -304,6 +301,9 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { * @return 绑定用户编号列表 */ private List buildBindUserIdsByLevel(Long bindUserId, Integer level) { + if (bindUserId == null) { + return Collections.emptyList(); + } Assert.isTrue(level == null || level <= 2, "目前只支持 level 小于等于 2"); List bindUserIds = CollUtil.newArrayList(); if (level == null || level == 1) { diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java index e77fb3596..b934afa35 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawService.java @@ -5,7 +5,7 @@ import cn.iocoder.yudao.module.trade.controller.admin.brokerage.vo.withdraw.Brok import cn.iocoder.yudao.module.trade.controller.app.brokerage.vo.withdraw.AppBrokerageWithdrawCreateReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.BrokerageWithdrawDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO; import java.util.Collection; import java.util.List; @@ -62,7 +62,7 @@ public interface BrokerageWithdrawService { * @param status 提现状态 * @return 用户提现汇总 List */ - List getWithdrawSummaryListByUserId(Collection userIds, BrokerageWithdrawStatusEnum status); + List getWithdrawSummaryListByUserId(Collection userIds, BrokerageWithdrawStatusEnum status); /** * 按照 userId,汇总每个用户的提现 @@ -71,8 +71,9 @@ public interface BrokerageWithdrawService { * @param status 提现状态 * @return 用户提现汇总 Map */ - default Map getWithdrawSummaryMapByUserId(Set userIds, BrokerageWithdrawStatusEnum status) { - return convertMap(getWithdrawSummaryListByUserId(userIds, status), UserWithdrawSummaryBO::getUserId); + default Map getWithdrawSummaryMapByUserId(Set userIds, + BrokerageWithdrawStatusEnum status) { + return convertMap(getWithdrawSummaryListByUserId(userIds, status), BrokerageWithdrawSummaryRespBO::getUserId); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java index 4fde9af3b..5c045a03b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/BrokerageWithdrawServiceImpl.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.trade.service.brokerage; +import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.LocalDateTimeUtil; import cn.hutool.core.map.MapUtil; import cn.hutool.core.util.ObjectUtil; @@ -17,7 +18,7 @@ import cn.iocoder.yudao.module.trade.enums.MessageTemplateConstants; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawStatusEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageWithdrawTypeEnum; -import cn.iocoder.yudao.module.trade.service.brokerage.bo.UserWithdrawSummaryBO; +import cn.iocoder.yudao.module.trade.service.brokerage.bo.BrokerageWithdrawSummaryRespBO; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -27,6 +28,7 @@ import javax.annotation.Resource; import javax.validation.Validator; import java.time.LocalDateTime; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -144,7 +146,11 @@ public class BrokerageWithdrawServiceImpl implements BrokerageWithdrawService { } @Override - public List getWithdrawSummaryListByUserId(Collection userIds, BrokerageWithdrawStatusEnum status) { + public List getWithdrawSummaryListByUserId(Collection userIds, + BrokerageWithdrawStatusEnum status) { + if (CollUtil.isEmpty(userIds)) { + return Collections.emptyList(); + } return brokerageWithdrawMapper.selectCountAndSumPriceByUserIdAndStatus(userIds, status.getStatus()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserWithdrawSummaryBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageWithdrawSummaryRespBO.java similarity index 85% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserWithdrawSummaryBO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageWithdrawSummaryRespBO.java index 0061185fa..1c3a3c991 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserWithdrawSummaryBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/BrokerageWithdrawSummaryRespBO.java @@ -5,14 +5,14 @@ import lombok.Data; import lombok.NoArgsConstructor; /** - * 用户佣金提现合计 BO + * 佣金提现合计 BO * * @author owen */ @Data @NoArgsConstructor @AllArgsConstructor -public class UserWithdrawSummaryBO { +public class BrokerageWithdrawSummaryRespBO { /** * 用户编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryRespBO.java similarity index 91% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryRespBO.java index 87ea0127d..3e677b96a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/bo/UserBrokerageSummaryRespBO.java @@ -12,7 +12,7 @@ import lombok.NoArgsConstructor; @Data @NoArgsConstructor @AllArgsConstructor -public class UserBrokerageSummaryBO { +public class UserBrokerageSummaryRespBO { /** * 用户编号