From 5808f77ade3c0843c4119ea7e1744c2b638a6f81 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Fri, 8 Sep 2023 00:29:25 +0800 Subject: [PATCH] =?UTF-8?q?code=20review=EF=BC=9A=E8=AE=A2=E5=8D=95?= =?UTF-8?q?=E5=88=86=E4=BD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- yudao-dependencies/pom.xml | 4 +- .../mybatis/core/mapper/BaseMapperX.java | 8 ++- .../api/sku/dto/ProductSkuRespDTO.java | 1 + .../trade/enums/ErrorCodeConstants.java | 14 +++--- .../brokerage/BrokerageBindModeEnum.java | 2 + .../BrokerageEnabledConditionEnum.java | 1 + .../brokerage/BrokerageRecordBizTypeEnum.java | 1 + .../record/vo/TradeBrokerageRecordBaseVO.java | 5 +- ...kerageUserUpdateBrokerageEnabledReqVO.java | 2 + .../admin/config/vo/TradeConfigBaseVO.java | 1 + .../record/TradeBrokerageRecordConvert.java | 2 +- .../record/TradeBrokerageRecordDO.java | 16 +++--- .../brokerage/user/TradeBrokerageUserDO.java | 7 +++ .../record/TradeBrokerageRecordMapper.java | 2 + .../yudao/module/trade/job/package-info.java | 4 ++ .../record/TradeBrokerageRecordService.java | 4 ++ .../TradeBrokerageRecordServiceImpl.java | 49 ++++++++++--------- .../record/bo/BrokerageAddReqBO.java | 8 +++ .../user/TradeBrokerageUserService.java | 3 ++ .../user/TradeBrokerageUserServiceImpl.java | 20 +++++--- .../service/config/TradeConfigService.java | 1 - .../TradeBrokerageRecordServiceImplTest.java | 1 + .../TradeBrokerageUserServiceImplTest.java | 1 + .../member/enums/ErrorCodeConstants.java | 2 +- .../dal/dataobject/user/MemberUserDO.java | 1 + .../dal/mysql/user/MemberUserMapper.java | 1 + 26 files changed, 108 insertions(+), 53 deletions(-) create mode 100644 yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/package-info.java diff --git a/yudao-dependencies/pom.xml b/yudao-dependencies/pom.xml index f3273f02a..849be7b87 100644 --- a/yudao-dependencies/pom.xml +++ b/yudao-dependencies/pom.xml @@ -27,7 +27,7 @@ 3.5.3.2 3.5.3.2 3.6.1 - 1.4.5 + 1.4.6 3.18.0 8.1.2.141 @@ -220,7 +220,7 @@ com.github.yulichang mybatis-plus-join-boot-starter - ${mybatis-plus-join-boot-starter.version} + ${mybatis-plus-join.version} diff --git a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java index eebe42d11..3383ec879 100644 --- a/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java +++ b/yudao-framework/yudao-spring-boot-starter-mybatis/src/main/java/cn/iocoder/yudao/framework/mybatis/core/mapper/BaseMapperX.java @@ -11,6 +11,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.toolkit.support.SFunction; import com.baomidou.mybatisplus.extension.toolkit.Db; +import com.github.yulichang.base.MPJBaseMapper; import org.apache.ibatis.annotations.Param; import java.util.Collection; @@ -18,8 +19,11 @@ import java.util.List; /** * 在 MyBatis Plus 的 BaseMapper 的基础上拓展,提供更多的能力 + * + * 1. {@link BaseMapper} 为 MyBatis Plus 的基础接口,提供基础的 CRUD 能力 + * 2. {@link MPJBaseMapper} 为 MyBatis Plus Join 的基础接口,提供连表 Join 能力 */ -public interface BaseMapperX extends BaseMapper { +public interface BaseMapperX extends MPJBaseMapper { default PageResult selectPage(PageParam pageParam, @Param("ew") Wrapper queryWrapper) { // MyBatis Plus 查询 @@ -128,4 +132,4 @@ public interface BaseMapperX extends BaseMapper { Db.saveOrUpdateBatch(collection); } -} \ No newline at end of file +} diff --git a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java index 2899fc075..c412faf4e 100644 --- a/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java +++ b/yudao-module-mall/yudao-module-product-api/src/main/java/cn/iocoder/yudao/module/product/api/sku/dto/ProductSkuRespDTO.java @@ -60,6 +60,7 @@ public class ProductSkuRespDTO { */ private Double volume; + // TODO @puhui:这 2 字段,需要改下;firstBrokerageRecord、secondBrokerageRecord;和分佣保持一致; /** * 一级分销的佣金,单位:分 */ 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 3107dbedf..f6c0ca782 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 @@ -11,7 +11,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; */ public interface ErrorCodeConstants { - // ========== Order 模块 1011000000 ========== + // ========== Order 模块 1011000000 ========== ErrorCode ORDER_CREATE_SKU_NOT_FOUND = new ErrorCode(1011000001, "商品 SKU 不存在"); ErrorCode ORDER_CREATE_SPU_NOT_SALE = new ErrorCode(1011000002, "商品 SPU 不可售卖"); ErrorCode ORDER_CREATE_SKU_STOCK_NOT_ENOUGH = new ErrorCode(1011000004, "商品 SKU 库存不足"); @@ -35,7 +35,7 @@ public interface ErrorCodeConstants { ErrorCode ORDER_DELIVERY_FAIL_DELIVERY_TYPE_NOT_EXPRESS = new ErrorCode(1011000024, "交易订单发货失败,发货类型不是快递"); ErrorCode ORDER_CANCEL_FAIL_STATUS_NOT_UNPAID = new ErrorCode(1011000025, "交易订单取消失败,订单不是【待支付】状态"); - // ========== After Sale 模块 1011000100 ========== + // ========== After Sale 模块 1011000100 ========== ErrorCode AFTER_SALE_NOT_FOUND = new ErrorCode(1011000100, "售后单不存在"); ErrorCode AFTER_SALE_CREATE_FAIL_REFUND_PRICE_ERROR = new ErrorCode(1011000101, "申请退款金额错误"); ErrorCode AFTER_SALE_CREATE_FAIL_ORDER_STATUS_CANCELED = new ErrorCode(1011000102, "订单已关闭,无法申请售后"); @@ -50,7 +50,7 @@ public interface ErrorCodeConstants { ErrorCode AFTER_SALE_CANCEL_FAIL_STATUS_NOT_APPLY_OR_AGREE_OR_BUYER_DELIVERY = new ErrorCode(1011000111, "取消售后单失败,售后单状态不是【待审核】或【卖家同意】或【商家待收货】"); - // ========== Cart 模块 1011002000 ========== + // ========== Cart 模块 1011002000 ========== ErrorCode CARD_ITEM_NOT_FOUND = new ErrorCode(1011002000, "购物车项不存在"); // ========== Price 相关 1011003000 ============ @@ -58,7 +58,7 @@ public interface ErrorCodeConstants { ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_USER_ADDR_IS_EMPTY = new ErrorCode(1011003001, "计算快递运费异常,收件人地址编号为空"); ErrorCode PRICE_CALCULATE_DELIVERY_PRICE_TEMPLATE_NOT_FOUND = new ErrorCode(1011003002, "计算快递运费异常,找不到对应的运费模板"); - // ========== 物流 Express 模块 1011004000 ========== + // ========== 物流 Express 模块 1011004000 ========== ErrorCode EXPRESS_NOT_EXISTS = new ErrorCode(1011004000, "快递公司不存在"); ErrorCode EXPRESS_CODE_DUPLICATE = new ErrorCode(1011004001, "已经存在该编码的快递公司"); ErrorCode EXPRESS_CLIENT_NOT_PROVIDE = new ErrorCode(1011004002, "需要接入快递服务商,比如【快递100】"); @@ -67,15 +67,15 @@ public interface ErrorCodeConstants { ErrorCode EXPRESS_API_QUERY_ERROR = new ErrorCode(1011004101, "快递查询接口异常"); ErrorCode EXPRESS_API_QUERY_FAILED = new ErrorCode(1011004102, "快递查询返回失败,原因:{}"); - // ========== 物流 Template 模块 1011005000 ========== + // ========== 物流 Template 模块 1011005000 ========== ErrorCode EXPRESS_TEMPLATE_NAME_DUPLICATE = new ErrorCode(1011005000, "已经存在该运费模板名"); ErrorCode EXPRESS_TEMPLATE_NOT_EXISTS = new ErrorCode(1011005001, "运费模板不存在"); - // ========== 物流 PICK_UP 模块 1011006000 ========== + // ========== 物流 PICK_UP 模块 1011006000 ========== ErrorCode PICK_UP_STORE_NOT_EXISTS = new ErrorCode(1011006000, "自提门店不存在"); - // ========== 分销 分销用户 模块 1011007000 ========== + // ========== 分销用户 模块 1011007000 ========== ErrorCode BROKERAGE_USER_NOT_EXISTS = new ErrorCode(1011007000, "分销用户不存在"); } diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java index 6946167bc..19bb53daa 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageBindModeEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum BrokerageBindModeEnum implements IntArrayValuable { + // TODO @疯狂:要不从 1 开始? /** * 只要用户没有推广人,随时都可以绑定分销关系 */ @@ -23,6 +24,7 @@ public enum BrokerageBindModeEnum implements IntArrayValuable { * 仅新用户注册时才能绑定推广关系 */ REGISTER(1, "新用户"), + // TODO @疯狂:要加个 2,每次扫码都覆盖 ; public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(BrokerageBindModeEnum::getMode).toArray(); diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java index 6d984a284..1d1ef0c81 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageEnabledConditionEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum BrokerageEnabledConditionEnum implements IntArrayValuable { + // TODO @疯狂:这个也从 1 开始哇 /** * 所有用户都可以分销 */ diff --git a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java index ce449f0b8..50c83c05a 100644 --- a/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java +++ b/yudao-module-mall/yudao-module-trade-api/src/main/java/cn/iocoder/yudao/module/trade/enums/brokerage/BrokerageRecordBizTypeEnum.java @@ -15,6 +15,7 @@ import java.util.Arrays; @Getter public enum BrokerageRecordBizTypeEnum implements IntArrayValuable { + // TODO @疯狂:这个也从 1 开始哇 ORDER(0, "获得推广佣金", "获得推广佣金 {}", true), WITHDRAW(1, "提现申请", "提现申请扣除佣金 {}", false), ; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java index 1fb87f294..f15d07706 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java @@ -4,6 +4,7 @@ import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import org.springframework.format.annotation.DateTimeFormat; +import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; import java.time.LocalDateTime; @@ -21,7 +22,7 @@ public class TradeBrokerageRecordBaseVO { private Long userId; @Schema(description = "业务编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "23353") - @NotNull(message = "业务编号不能为空") + @NotEmpty(message = "业务编号不能为空") private String bizId; @Schema(description = "业务类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") @@ -29,7 +30,7 @@ public class TradeBrokerageRecordBaseVO { private Integer bizType; @Schema(description = "标题", requiredMode = Schema.RequiredMode.REQUIRED) - @NotNull(message = "标题不能为空") + @NotEmpty(message = "标题不能为空") private String title; @Schema(description = "金额", requiredMode = Schema.RequiredMode.REQUIRED, example = "28731") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java index 002eed371..1fd38b028 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/user/vo/TradeBrokerageUserUpdateBrokerageEnabledReqVO.java @@ -15,6 +15,8 @@ public class TradeBrokerageUserUpdateBrokerageEnabledReqVO { @NotNull(message = "用户编号不能为空") private Long id; + // TODO @疯狂:是不是这个字段,可以改成 enabled + @Schema(description = "推广资格", requiredMode = Schema.RequiredMode.REQUIRED) @NotNull(message = "推广资格不能为空") private Boolean brokerageEnabled; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java index ee20156f1..55b168582 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/config/vo/TradeConfigBaseVO.java @@ -54,6 +54,7 @@ public class TradeConfigBaseVO { @PositiveOrZero(message = "用户提现最低金额不能是负数") private Integer brokerageWithdrawMinPrice; + // TODO @疯狂:要不要做成字典?按道理都可以体现对哇?感觉是全局的配置哈; @Schema(description = "提现银行", requiredMode = Schema.RequiredMode.REQUIRED, example = "[0, 1]") @NotEmpty(message = "提现银行不能为空") private List brokerageBankNames; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java index b84e51354..1e8290460 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java @@ -40,7 +40,7 @@ public interface TradeBrokerageRecordConvert { .setBizId(bizId) .setPrice(brokerage) .setTotalPrice(user.getBrokeragePrice()) - .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) + .setTitle(BrokerageRecordBizTypeEnum.ORDER.getTitle()) // TODO @疯狂:可能 title 不是很固化,会存在类似:沐晴成功购买《XXX JVM 实战》 .setDescription(StrUtil.format(BrokerageRecordBizTypeEnum.ORDER.getDescription(), String.valueOf(brokerage / 100.0))) .setStatus(status) .setFrozenDays(brokerageFrozenDays) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java index 0bf7c0cf2..bb3f09c52 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java @@ -41,13 +41,19 @@ public class TradeBrokerageRecordDO extends BaseDO { /** * 业务类型 *

- * 枚举 {@link BrokerageRecordBizTypeEnum 对应的类} + * 枚举 {@link BrokerageRecordBizTypeEnum} */ private Integer bizType; + /** * 标题 */ private String title; + /** + * 说明 + */ + private String description; + /** * 金额 */ @@ -56,16 +62,14 @@ public class TradeBrokerageRecordDO extends BaseDO { * 当前总佣金 */ private Integer totalPrice; - /** - * 说明 - */ - private String description; + /** * 状态 *

- * 枚举 {@link BrokerageRecordStatusEnum 对应的类} + * 枚举 {@link BrokerageRecordStatusEnum} */ private Integer status; + /** * 冻结时间(天) */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java index 0bc552dca..3f1cc73aa 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/user/TradeBrokerageUserDO.java @@ -8,6 +8,7 @@ import lombok.*; import java.time.LocalDateTime; +// TODO @疯狂:因为独立了表,是不是可以把字段的 brokerage 去掉了哈? /** * 分销用户 DO * @@ -28,14 +29,19 @@ public class TradeBrokerageUserDO extends BaseDO { */ @TableId private Long id; + + // TODO @疯狂:貌似改成 bindUserId,更明确? /** * 推广员编号 + * + * 关联 MemberUserDO 的 id 字段 */ private Long brokerageUserId; /** * 推广员绑定时间 */ private LocalDateTime brokerageBindTime; + /** * 推广资格 */ @@ -44,6 +50,7 @@ public class TradeBrokerageUserDO extends BaseDO { * 成为分销员时间 */ private LocalDateTime brokerageTime; + /** * 可用佣金 */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java index 78efbc53a..41ed8bad9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java @@ -40,8 +40,10 @@ public interface TradeBrokerageRecordMapper extends BaseMapperX getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); + // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 增加佣金 * @@ -38,8 +39,10 @@ public interface TradeBrokerageRecordService { */ void addBrokerage(Long userId, List list); + // TODO @疯狂:是不是 bizType 得加下?方便未来拓展哈; /** * 取消佣金:将佣金记录,状态修改为已失效 + * * @param userId 会员编号 * @param bizId 业务编号 */ @@ -51,4 +54,5 @@ public interface TradeBrokerageRecordService { * @return 解冻佣金的数量 */ int unfreezeRecord(); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java index 5502bcbf7..8ced49abb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java @@ -6,15 +6,15 @@ import cn.hutool.core.util.NumberUtil; import cn.hutool.core.util.ObjectUtil; import cn.hutool.extra.spring.SpringUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.convert.brokerage.record.TradeBrokerageRecordConvert; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.dal.dataobject.config.TradeConfigDO; import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; 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.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import lombok.extern.slf4j.Slf4j; @@ -56,11 +56,13 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return tradeBrokerageRecordMapper.selectPage(pageReqVO); } + // TODO @疯狂:buyerId 要不要统一改成 userId 哈; @Override @Transactional(rollbackFor = Exception.class) public void addBrokerage(Long buyerId, List list) { TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); // 0 未启用分销功能 + // TODO @疯狂:BooleanUtil.isFalse();逻辑里,尽量不做 !取反,这样要多思考一层; if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { log.warn("[addBrokerage][增加佣金失败:brokerageEnabled 未配置,buyerId({})", buyerId); return; @@ -72,11 +74,11 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } - // 1.2 计算一级分佣 + // 1.2 计算一级分佣 // TODO 疯狂:类似 1.1 和 1.2 的空行,可以去掉;一般在代码里的空行,是为了逻辑分块;但是分块如果太多,就会导致代码里都是空行哈; addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice); - // 2.1 获得二级推广员 + // TODO @疯狂:这里可以加个 firstUser.getBrokerageUserId() 为空的判断 return TradeBrokerageUserDO secondUser = tradeBrokerageUserService.getBrokerageUser(firstUser.getBrokerageUserId()); if (secondUser == null || !BooleanUtil.isTrue(secondUser.getBrokerageEnabled())) { return; @@ -95,6 +97,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } + // 1. 更新佣金记录为已失效 TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { @@ -102,6 +105,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ return; } + // 2. 更新用户的佣金 if (BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus().equals(record.getStatus())) { tradeBrokerageUserService.updateUserFrozenBrokeragePrice(userId, -record.getPrice()); } else if (BrokerageRecordStatusEnum.SETTLEMENT.getStatus().equals(record.getStatus())) { @@ -109,6 +113,7 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ } } + // TODO @疯狂:是不是 calculateBrokeragePrice /** * 计算佣金 * @@ -122,12 +127,11 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ if (skuBrokeragePrice != null && skuBrokeragePrice > 0) { return ObjectUtil.defaultIfNull(skuBrokeragePrice, 0); } - // 2. 根据订单支付金额计算佣金 + // TODO @疯狂:要不要把 MoneyUtils 抽到 common 里,然后这里也使用这个类的方法; if (payPrice != null && payPrice > 0 && percent != null && percent > 0) { return NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue(); } - return 0; } @@ -142,37 +146,35 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ */ private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, Integer brokeragePercent, Function skuBrokeragePriceFun) { - // 处理冻结时间 + // 1.1 处理冻结时间 + // TODO @疯狂:是不是 brokerageFrozenDays != null && brokerageFrozenDays > 0 ?然后计算;更简洁一点; brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); LocalDateTime unfreezeTime = null; if (brokerageFrozenDays > 0) { unfreezeTime = LocalDateTime.now().plusDays(brokerageFrozenDays); } - - // 计算分佣 + // 1.2 计算分佣 int totalBrokerage = 0; List records = new ArrayList<>(); - for (BrokerageAddReqBO dto : list) { - int brokeragePerItem = calculateBrokerage(dto.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(dto)); + for (BrokerageAddReqBO item : list) { + int brokeragePerItem = calculateBrokerage(item.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(item)); + // TODO @疯狂:其实可以 brokeragePerItem <= 0 ,continue;这样 { 层级更少;代码更简洁;} if (brokeragePerItem > 0) { - int brokerage = brokeragePerItem * dto.getCount(); - records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); + int brokerage = brokeragePerItem * item.getCount(); + records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, item.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); totalBrokerage += brokerage; } } - - if (records.isEmpty()) { + if (CollUtil.isEmpty(records)) { return; } - - // 保存佣金记录 + // 1.3 保存佣金记录 tradeBrokerageRecordMapper.insertBatch(records); - if (brokerageFrozenDays > 0) { - // 更新用户冻结佣金 + // 2. 更新用户佣金 + if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 tradeBrokerageUserService.updateUserFrozenBrokeragePrice(user.getId(), totalBrokerage); - } else { - // 更新用户可用佣金 + } else { // 更新用户可用佣金 tradeBrokerageUserService.updateUserBrokeragePrice(user.getId(), totalBrokerage); } } @@ -190,8 +192,8 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ int count = 0; for (TradeBrokerageRecordDO record : records) { try { - boolean successful = getSelf().unfreezeRecord(record); - if (successful) { + boolean success = getSelf().unfreezeRecord(record); + if (success) { count++; } } catch (Exception e) { @@ -215,7 +217,6 @@ public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordServ // 更新用户冻结佣金 tradeBrokerageUserService.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(record.getUserId(), -record.getPrice()); - log.info("[unfreezeRecord][record({}) 更新为已结算成功]", record.getId()); return true; } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java index a968d14ea..d325118a9 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java @@ -4,22 +4,29 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; +// TODO @疯狂:要不要 service 还是拍平;就是都放在 brokerage 包下,然后 bo 里面,稍微分分; /** * 佣金 增加 Request BO + * * @author owen */ @Data @NoArgsConstructor @AllArgsConstructor public class BrokerageAddReqBO { + + // TODO @疯狂:bo 的话,也可以考虑加下 @Validated 注解,校验下参数;防御性下哈,虽然不一定用的到 + /** * 业务ID */ private String bizId; + // TODO @疯狂:不需要 payPrice 和 count,计算成 price 就好啦; /** * 商品支付价格 */ private Integer payPrice; + // TODO @疯狂:可以去掉 sku 哈,更抽象一点; /** * SKU 一级佣金 */ @@ -32,4 +39,5 @@ public class BrokerageAddReqBO { * 购买数量 */ private Integer count; + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java index 773342e55..54913b98a 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserService.java @@ -7,6 +7,7 @@ import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerag import java.util.Collection; import java.util.List; +// TODO @疯狂:要不去掉 Trade 前缀哈;交易这块,我准备除了 tradeorder 保持下,类似 aftersale,都要取消前缀了;tradeorder 保持的原因,是避免 payorder 和它重复 /** * 分销用户 Service 接口 * @@ -70,6 +71,7 @@ public interface TradeBrokerageUserService { */ void updateUserBrokeragePrice(Long id, int brokeragePrice); + // TODO @疯狂:int 类型一般不用哈;尽量都用封装类型;不差这点内存哈; /** * 更新用户冻结佣金 * @@ -85,4 +87,5 @@ public interface TradeBrokerageUserService { * @param frozenBrokeragePrice 减少冻结佣金(负数) */ void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice); + } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java index 9691a8154..c4300c1ae 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImpl.java @@ -30,12 +30,6 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService @Resource private TradeBrokerageUserMapper brokerageUserMapper; - private void validateBrokerageUserExists(Long id) { - if (brokerageUserMapper.selectById(id) == null) { - throw exception(BROKERAGE_USER_NOT_EXISTS); - } - } - @Override public TradeBrokerageUserDO getBrokerageUser(Long id) { return brokerageUserMapper.selectById(id); @@ -55,15 +49,23 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService public void updateBrokerageUserId(Long id, Long brokerageUserId) { // 校验存在 validateBrokerageUserExists(id); - + // TODO @疯狂:貌似没实现完 } @Override public void updateBrokerageEnabled(Long id, Boolean brokerageEnabled) { // 校验存在 validateBrokerageUserExists(id); + // TODO @疯狂:貌似没实现完 } + private void validateBrokerageUserExists(Long id) { + if (brokerageUserMapper.selectById(id) == null) { + throw exception(BROKERAGE_USER_NOT_EXISTS); + } + } + + // TODO @疯狂:getBindBrokerageUser 会不会好点,因为统一使用 Bind 替代了 Invite @Override public TradeBrokerageUserDO getInviteBrokerageUser(Long id) { return Optional.ofNullable(id) @@ -73,6 +75,7 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService .orElse(null); } + // TODO @疯狂:单个更新,不用事务哈; @Override @Transactional(rollbackFor = Exception.class) public void updateUserBrokeragePrice(Long id, int brokeragePrice) { @@ -83,6 +86,7 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } + // TODO @疯狂:单个更新,不用事务哈; @Override @Transactional(rollbackFor = Exception.class) public void updateUserFrozenBrokeragePrice(Long id, int frozenBrokeragePrice) { @@ -93,12 +97,14 @@ public class TradeBrokerageUserServiceImpl implements TradeBrokerageUserService } } + // TODO @疯狂:单个更新,不用事务哈; @Override @Transactional(rollbackFor = Exception.class) public void updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(Long id, int frozenBrokeragePrice) { Assert.isTrue(frozenBrokeragePrice < 0); int updateRows = brokerageUserMapper.updateFrozenBrokeragePriceDecrAndBrokeragePriceIncr(id, frozenBrokeragePrice); if (updateRows == 0) { + // TODO @疯狂:挪到 trade 这变的错误码哈; throw exception(MEMBER_FROZEN_BROKERAGE_PRICE_NOT_ENOUGH); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java index c00825f2e..1edb4f30b 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/config/TradeConfigService.java @@ -12,7 +12,6 @@ import javax.validation.Valid; */ public interface TradeConfigService { - /** * 更新交易中心配置 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java index a6d8dffb1..9daf3cafb 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java @@ -25,6 +25,7 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomIntege import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static org.junit.jupiter.api.Assertions.assertEquals; +// TODO @芋艿:单测后续看看 /** * {@link TradeBrokerageRecordServiceImpl} 的单元测试类 * diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java index 49e8aa351..153bbb426 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/user/TradeBrokerageUserServiceImplTest.java @@ -17,6 +17,7 @@ import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEq import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static org.junit.jupiter.api.Assertions.assertEquals; +// TODO @芋艿:单测后续看看 /** * {@link TradeBrokerageUserServiceImpl} 的单元测试类 * diff --git a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java index dc6439e74..dc7a58770 100644 --- a/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java +++ b/yudao-module-member/yudao-module-member-api/src/main/java/cn/iocoder/yudao/module/member/enums/ErrorCodeConstants.java @@ -9,7 +9,7 @@ import cn.iocoder.yudao.framework.common.exception.ErrorCode; */ public interface ErrorCodeConstants { - // ========== 用户相关 1004001000============ + // ========== 用户相关 1004001000============ ErrorCode USER_NOT_EXISTS = new ErrorCode(1004001000, "用户不存在"); ErrorCode USER_MOBILE_NOT_EXISTS = new ErrorCode(1004001001, "手机号未注册用户"); ErrorCode USER_MOBILE_USED = new ErrorCode(1004001002, "修改手机失败,该手机号({})已经被使用"); diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java index cfa93c983..242cb7110 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/dataobject/user/MemberUserDO.java @@ -136,6 +136,7 @@ public class MemberUserDO extends TenantBaseDO { */ private Long groupId; + // TODO @疯狂:看看要不要删除掉哈 // ========== 分销相关 ========== /** diff --git a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java index 7e35cdf2a..902057272 100644 --- a/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java +++ b/yudao-module-member/yudao-module-member-biz/src/main/java/cn/iocoder/yudao/module/member/dal/mysql/user/MemberUserMapper.java @@ -61,4 +61,5 @@ public interface MemberUserMapper extends BaseMapperX { return selectCount(new LambdaQueryWrapperX() .apply("FIND_IN_SET({0}, tag_ids)", tagId)); } + }