From 421bb7d1548667fdc8844e59345d9ce504c40cab Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sun, 24 Sep 2023 11:56:00 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=EF=BC=9A=E5=88=86=E9=94=80?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../pom.xml | 2 +- .../trade/enums/ErrorCodeConstants.java | 4 ++-- .../BrokerageWithdrawStatusEnum.java | 2 ++ .../AppBrokerageRecordController.java | 1 + .../brokerage/AppBrokerageUserController.java | 9 ++++---- .../AppBrokerageWithdrawController.java | 2 ++ .../app/config/AppTradeConfigController.java | 5 +++- .../app/config/vo/AppTradeConfigRespVO.java | 1 + .../delivery/AppDeliverConfigController.java | 1 + .../brokerage/BrokerageUserConvert.java | 8 +++---- .../brokerage/BrokerageRecordMapper.java | 5 ++-- .../mysql/brokerage/BrokerageUserMapper.java | 1 + .../brokerage/BrokerageWithdrawMapper.java | 4 +++- .../brokerage/BrokerageRecordService.java | 6 +++-- .../brokerage/BrokerageRecordServiceImpl.java | 11 +++++---- .../brokerage/BrokerageUserServiceImpl.java | 23 +++++++++++++++---- .../brokerage/BrokerageWithdrawService.java | 1 - .../mapper/brokerage/BrokerageUserMapper.xml | 13 +++++------ .../system/api/dict/DictDataApiImpl.java | 1 + .../app/dict/AppDictDataController.java | 4 +++- .../app/dict/vo/AppDictDataRespVO.java | 2 ++ 21 files changed, 71 insertions(+), 35 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml b/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml index ff3c32d97a..06e41c1eb3 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml +++ b/yudao-framework/yudao-spring-boot-starter-biz-error-code/pom.xml @@ -14,7 +14,7 @@ ${project.artifactId} 错误码 ErrorCode 的自动配置功能,提供如下功能: - 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提水可配置; + 1. 远程读取:项目启动时,从 system-server 服务,读取数据库中的 ErrorCode 错误码,实现错误码的提示可配置; 2. 自动更新:管理员在管理后台修数据库中的 ErrorCode 错误码时,项目自动从 system-server 服务加载最新的 ErrorCode 错误码; 3. 自动写入:项目启动时,将项目本地的错误码写到 system-server 服务中,方便管理员在管理后台编辑; 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 52018bf4fd..da0d8fa2bd 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 @@ -87,7 +87,7 @@ public interface ErrorCodeConstants { // ========== 分销提现 模块 1011008000 ========== ErrorCode BROKERAGE_WITHDRAW_NOT_EXISTS = new ErrorCode(1011008000, "佣金提现记录不存在"); ErrorCode BROKERAGE_WITHDRAW_STATUS_NOT_AUDITING = new ErrorCode(1011008001, "佣金提现记录状态不是审核中"); - ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于{}元"); - ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现{}元"); + ErrorCode BROKERAGE_WITHDRAW_MIN_PRICE = new ErrorCode(1011008002, "提现金额不能低于 {} 元"); + ErrorCode BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH = new ErrorCode(1011008003, "您当前最多可提现 {} 元"); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java index daf0da3aaf..59dfbfbc89 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageWithdrawStatusEnum.java @@ -22,7 +22,9 @@ public enum BrokerageWithdrawStatusEnum implements IntArrayValuable { WITHDRAW_FAIL(21, "提现失败"), ; + // TODO @疯狂:字典现在枚举在每个模块的 DictTypeConstants 里哈;可以创建一个出来;主要是想,治理每个模块到底有多少个枚举; public static final String DICT_TYPE = "BROKERAGE_WITHDRAW_STATUS"; + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageWithdrawStatusEnum::getStatus).toArray(); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java index 0b7d01ed85..f5c3385db8 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageRecordController.java @@ -45,6 +45,7 @@ public class AppBrokerageRecordController { return success(BrokerageRecordConvert.INSTANCE.convertPage02(pageResult)); } + // TODO @疯狂:这里还有一个漏网之鱼~ @GetMapping("/get-product-brokerage-price") @Operation(summary = "获得商品的分销金额") public CommonResult getProductBrokeragePrice(@RequestParam("spuId") Long spuId) { 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 13d1493e9d..c7db41647d 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 @@ -55,6 +55,7 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUser() { Optional user = Optional.ofNullable(brokerageUserService.getBrokerageUser(getLoginUserId())); + // 返回数据 AppBrokerageUserRespVO respVO = new AppBrokerageUserRespVO() .setBrokerageEnabled(user.map(BrokerageUserDO::getBrokerageEnabled).orElse(false)) .setBrokeragePrice(user.map(BrokerageUserDO::getBrokeragePrice).orElse(0)) @@ -66,6 +67,7 @@ public class AppBrokerageUserController { @Operation(summary = "绑定推广员") @PreAuthenticated public CommonResult bindBrokerageUser(@Valid @RequestBody AppBrokerageUserBindReqVO reqVO) { + // TODO @疯狂:是不是 isNewUser 不用传递哈,交给 service 自己计算出来? return success(brokerageUserService.bindBrokerageUser(getLoginUserId(), reqVO.getBindUserId(), false)); } @@ -74,17 +76,17 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult getBrokerageUserSummary() { Long userId = getLoginUserId(); + // 统计 yesterdayPrice、withdrawPrice、firstBrokerageUserCount、secondBrokerageUserCount 字段 LocalDateTime yesterday = LocalDateTime.now().minusDays(1); LocalDateTime beginTime = LocalDateTimeUtil.beginOfDay(yesterday); LocalDateTime endTime = LocalDateTimeUtil.endOfDay(yesterday); - AppBrokerageUserMySummaryRespVO respVO = new AppBrokerageUserMySummaryRespVO() .setYesterdayPrice(brokerageRecordService.getSummaryPriceByUserId(userId, BrokerageRecordBizTypeEnum.ORDER.getType(), beginTime, endTime)) .setWithdrawPrice(brokerageWithdrawService.getSummaryPriceByUserIdAndStatus(userId, BrokerageWithdrawStatusEnum.AUDIT_SUCCESS.getStatus())) - .setBrokeragePrice(0) - .setFrozenPrice(0) + .setBrokeragePrice(0).setFrozenPrice(0) .setFirstBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 1)) .setSecondBrokerageUserCount(brokerageUserService.getBrokerageUserCountByBindUserId(userId, 2)); + // 设置 brokeragePrice、frozenPrice 字段 Optional.ofNullable(brokerageUserService.getBrokerageUser(userId)) .ifPresent(user -> respVO.setBrokeragePrice(user.getBrokeragePrice()).setFrozenPrice(user.getFrozenPrice())); return success(respVO); @@ -117,7 +119,6 @@ public class AppBrokerageUserController { @PreAuthenticated public CommonResult> getBrokerageUserChildSummaryPage( AppBrokerageUserChildSummaryPageReqVO pageReqVO) { - // 分页查询 PageResult pageResult = brokerageUserService.getBrokerageUserChildSummaryPage(pageReqVO, getLoginUserId()); return success(pageResult); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java index 434022f6a2..77bae4be93 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/brokerage/AppBrokerageWithdrawController.java @@ -30,6 +30,7 @@ import static cn.iocoder.yudao.framework.web.core.util.WebFrameworkUtils.getLogi @Validated @Slf4j public class AppBrokerageWithdrawController { + @Resource private BrokerageWithdrawService brokerageWithdrawService; @@ -44,6 +45,7 @@ public class AppBrokerageWithdrawController { PageResult pageResult = brokerageWithdrawService.getBrokerageWithdrawPage( BrokerageWithdrawConvert.INSTANCE.convert(pageReqVO, getLoginUserId())); // 拼接信息 + // TODO @疯狂:后端可以直接用 DictFrameworkUtils.getDictDataLabel() 去渲染哈;这样就不用 getDictDataLabelMap 方法了; Map statusNameMap = dictDataApi.getDictDataLabelMap(BrokerageWithdrawStatusEnum.DICT_TYPE); return success(BrokerageWithdrawConvert.INSTANCE.convertPage02(pageResult, statusNameMap)); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java index cb6e3813a4..47c21ed57a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/AppTradeConfigController.java @@ -5,6 +5,7 @@ import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.module.trade.controller.app.config.vo.AppTradeConfigRespVO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; +import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; @@ -24,13 +25,15 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated @Slf4j public class AppTradeConfigController { + @Resource private TradeConfigService tradeConfigService; @GetMapping("/get") + @Operation(summary = "获得交易配置") public CommonResult getTradeConfig() { TradeConfigDO tradeConfig = ObjUtil.defaultIfNull(tradeConfigService.getTradeConfig(), new TradeConfigDO()); - + // TODO @疯狂:是不是直接 convert 就好啦; AppTradeConfigRespVO respVO = new AppTradeConfigRespVO() .setBrokeragePosterUrls(tradeConfig.getBrokeragePostUrls()) .setBrokerageFrozenDays(tradeConfig.getBrokerageFrozenDays()) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java index cd7de5287f..099e37c565 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/config/vo/AppTradeConfigRespVO.java @@ -18,6 +18,7 @@ public class AppTradeConfigRespVO { @Schema(description = "佣金提现最小金额,单位:分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") private Integer brokerageWithdrawMinPrice; + // TODO @疯狂:如果是 list,要不加个 s,复数; @Schema(description = "提现方式", requiredMode = Schema.RequiredMode.REQUIRED, example = "[1, 2]") private List brokerageWithdrawType; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java index d5b86fcb0a..1d4e36f90b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/app/delivery/AppDeliverConfigController.java @@ -17,6 +17,7 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Validated public class AppDeliverConfigController { + // TODO @芋艿:这里后面干掉,合并到 AppTradeConfigController 中 @GetMapping("/get") @Operation(summary = "获得配送配置") public CommonResult getDeliveryConfig() { 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 e1d218416c..41e51401e6 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 @@ -58,12 +58,12 @@ public interface BrokerageUserConvert { return target; } - default PageResult convertPage03(PageResult pageResult, Map userMap) { - for (AppBrokerageUserRankByUserCountRespVO vo : pageResult.getList()) { - copyTo(userMap.get(vo.getId()), vo); - } + default PageResult convertPage03(PageResult pageResult, + Map userMap) { + pageResult.getList().forEach(vo -> copyTo(userMap.get(vo.getId()), vo)); return pageResult; } void copyTo(MemberUserRespDTO from, @MappingTarget AppBrokerageUserRankByUserCountRespVO to); + } 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 4faa86c8dd..f42fa3d0c9 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 @@ -25,7 +25,6 @@ import java.util.List; public interface BrokerageRecordMapper extends BaseMapperX { default PageResult selectPage(BrokerageRecordPageReqVO reqVO) { - // 分页查询 return selectPage(reqVO, new LambdaQueryWrapperX() .eqIfPresent(BrokerageRecordDO::getUserId, reqVO.getUserId()) .eqIfPresent(BrokerageRecordDO::getBizType, reqVO.getBizType()) @@ -59,7 +58,8 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("bizType") Integer bizType, @Param("status") Integer status); - @Select("SELECT SUM(price) FROM trade_brokerage_record WHERE user_id = #{userId} AND biz_type = #{bizType} " + + @Select("SELECT SUM(price) FROM trade_brokerage_record " + + "WHERE user_id = #{userId} AND biz_type = #{bizType} " + "AND create_time BETWEEN #{beginTime} AND #{endTime}") Integer selectSummaryPriceByUserIdAndBizTypeAndCreateTimeBetween(@Param("userId") Long userId, @Param("bizType") Integer bizType, @@ -76,4 +76,5 @@ public interface BrokerageRecordMapper extends BaseMapperX { @Param("status") Integer status, @Param("beginTime") LocalDateTime beginTime, @Param("endTime") LocalDateTime endTime); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java index 9bd2fe078a..fc53ce9427 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/BrokerageUserMapper.java @@ -145,4 +145,5 @@ public interface BrokerageUserMapper extends BaseMapperX { default List selectListByBindUserId(Long bindUserId) { return selectList(BrokerageUserDO::getBindUserId, bindUserId); } + } 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 293fdf51c2..92f54046ea 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 @@ -36,6 +36,8 @@ public interface BrokerageWithdrawMapper extends BaseMapperX getBrokerageRecordPage(BrokerageRecordPageReqVO pageReqVO); /** - * 增加佣金 + * 增加佣金【多级分佣】 * * @param userId 会员编号 * @param bizType 业务类型 @@ -46,7 +46,7 @@ public interface BrokerageRecordService { void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, @Valid List list); /** - * 增加佣金 + * 增加佣金【只针对自己】 * * @param userId 会员编号 * @param bizType 业务类型 @@ -95,6 +95,7 @@ public interface BrokerageRecordService { /** * 获得用户佣金排行分页列表(基于佣金总数) + * * @param pageReqVO 分页查询 * @return 排行榜分页 */ @@ -108,4 +109,5 @@ public interface BrokerageRecordService { * @return 用户的排名 */ Integer getUserRankByPrice(Long userId, LocalDateTime[] times); + } 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 b630976617..88114731de 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 @@ -240,10 +240,11 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { return new PageResult<>(pageResult.getRecords(), pageResult.getTotal()); } + // TODO @疯狂:这个求出来,应该是不准的?例如说超过 100+ 名后? @Override public Integer getUserRankByPrice(Long userId, LocalDateTime[] times) { AppBrokerageUserRankPageReqVO pageParam = new AppBrokerageUserRankPageReqVO().setTimes(times); - // 取前100名 + // 取前 100 名 pageParam.setPageSize(100); PageResult pageResult = getBrokerageUserChildSummaryPageByPrice(pageParam); // 获得索引 @@ -255,21 +256,23 @@ public class BrokerageRecordServiceImpl implements BrokerageRecordService { @Override @Transactional(rollbackFor = Exception.class) public void addBrokerage(Long userId, BrokerageRecordBizTypeEnum bizType, String bizId, Integer brokeragePrice, String title) { - // 校验佣金余额 + // 1. 校验佣金余额 BrokerageUserDO user = brokerageUserService.getBrokerageUser(userId); int balance = Optional.of(user) .map(BrokerageUserDO::getBrokeragePrice).orElse(0); if (balance + brokeragePrice < 0) { + // TODO @疯狂:要不 MoneyUtils 那,统一搞个 format 金额的方法?然后把分到元的字符串,统一收口掉; throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); } - // 扣减佣金余额 + // 2. 更新佣金余额 boolean success = brokerageUserService.updateUserPrice(userId, brokeragePrice); if (!success) { + // 失败时,则抛出异常。只会出现扣减佣金时,余额不足的情况 throw exception(BROKERAGE_WITHDRAW_USER_BALANCE_NOT_ENOUGH, new Money(0, balance)); } - // 新增记录 + // 3. 新增记录 BrokerageRecordDO record = BrokerageRecordConvert.INSTANCE.convert(user, bizType, bizId, 0, brokeragePrice, null, title, null, null); brokerageRecordMapper.insert(record); 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 650edda13c..658e99326f 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 @@ -67,7 +67,6 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { public void updateBrokerageUserId(Long id, Long bindUserId) { // 校验存在 BrokerageUserDO brokerageUser = validateBrokerageUserExists(id); - // 绑定关系未发生变化 if (Objects.equals(brokerageUser.getBindUserId(), bindUserId)) { return; @@ -185,6 +184,13 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { return true; } + /** + * 补全绑定用户的字段 + * + * @param bindUserId 绑定的用户编号 + * @param brokerageUser update 对象 + * @return 补全后的 update 对象 + */ private BrokerageUserDO fillBindUserData(Long bindUserId, BrokerageUserDO brokerageUser) { return brokerageUser.setBindUserId(bindUserId).setBindUserTime(LocalDateTime.now()); } @@ -255,6 +261,7 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } // 下级不能绑定自己的上级 + // TODO @疯狂:这里是不是查询不到的时候,应该有个 break 结束循环哈 for (int i = 0; i <= Short.MAX_VALUE; i++) { if (Objects.equals(bindUser.getBindUserId(), user.getId())) { throw exception(BROKERAGE_BIND_LOOP); @@ -263,18 +270,24 @@ public class BrokerageUserServiceImpl implements BrokerageUserService { } } + /** + * 根据绑定用户编号,获得绑定用户编号列表 + * + * @param bindUserId 绑定用户编号 + * @param level 绑定用户的层级。 + * 如果 level 为空,则查询 1+2 两个层级 + * @return 绑定用户编号列表 + */ private List buildBindUserIdsByLevel(Long bindUserId, Integer level) { + Assert.isTrue(level == null || level <= 2, "目前只支持 level 小于等于 2"); List bindUserIds = CollUtil.newArrayList(); if (level == null || level == 1) { bindUserIds.add(bindUserId); } if (level == null || level == 2) { - List firstUserIds = convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId); - bindUserIds.addAll(firstUserIds); + bindUserIds.addAll(convertList(brokerageUserMapper.selectListByBindUserId(bindUserId), BrokerageUserDO::getId)); } - return bindUserIds; - } } 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 66279c998e..a80234da5c 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 @@ -20,7 +20,6 @@ public interface BrokerageWithdrawService { * @param status 审核状态 * @param auditReason 驳回原因 */ - void auditBrokerageWithdraw(Integer id, BrokerageWithdrawStatusEnum status, String auditReason); /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml index 4605f6744e..b1a1ef8d6d 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/resources/mapper/brokerage/BrokerageUserMapper.xml @@ -4,14 +4,13 @@ + diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java index cf16c07b7b..d50ac02998 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/api/dict/DictDataApiImpl.java @@ -38,6 +38,7 @@ public class DictDataApiImpl implements DictDataApi { @Override public List getDictDataList(String type) { + // TODO @疯狂:不用 DictDataExportReqVO 哈;可以考虑直接加个允许传递 type 传递的 List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(type)); return DictDataConvert.INSTANCE.convertList04(list); } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java index 0b5909f35c..95ae7e1874 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/AppDictDataController.java @@ -28,10 +28,12 @@ public class AppDictDataController { @Resource private DictDataService dictDataService; + // TODO @疯狂:暂时不用 path 参数哈;主要考虑一些中间件支持的一般,例如说链路追踪之类的;还是作为一个参数噶; @GetMapping("/type/{dictType}") @Operation(summary = "根据字典类型查询字典数据信息") - public CommonResult> getDicts(@PathVariable String dictType) { + public CommonResult> getDictDataList(@PathVariable String dictType) { List list = dictDataService.getDictDataList(new DictDataExportReqVO().setDictType(dictType)); return success(DictDataConvert.INSTANCE.convertList03(list)); } + } diff --git a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java index 4ee511507d..307fa98213 100644 --- a/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java +++ b/yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/controller/app/dict/vo/AppDictDataRespVO.java @@ -14,6 +14,8 @@ import lombok.NoArgsConstructor; @EqualsAndHashCode(callSuper = true) public class AppDictDataRespVO extends DictDataBaseVO { + // TODO @疯狂:app 的接口,不集成 admin 接口的 vo 哈;看看是不是只返回必要的字段,类似 remark、sort 不好返回的哈; + @Schema(description = "字典数据编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "1024") private Long id;