diff --git a/sql/mysql/brokerage.sql b/sql/mysql/brokerage.sql index 161dfa256..127fcb728 100644 --- a/sql/mysql/brokerage.sql +++ b/sql/mysql/brokerage.sql @@ -42,7 +42,7 @@ create index idx_invite_user_id on trade_brokerage_user (brokerage_user_id) comm create index idx_agent on trade_brokerage_user (brokerage_enabled) comment '是否成为推广员'; -create table member_brokerage_record +create table trade_brokerage_record ( id int auto_increment comment '编号' primary key, @@ -65,12 +65,12 @@ create table member_brokerage_record ) comment '佣金记录'; -create index idx_user_id on member_brokerage_record (user_id) comment '用户编号'; -create index idx_biz on member_brokerage_record (biz_type, biz_id) comment '业务'; -create index idx_status on member_brokerage_record (status) comment '状态'; +create index idx_user_id on trade_brokerage_record (user_id) comment '用户编号'; +create index idx_biz on trade_brokerage_record (biz_type, biz_id) comment '业务'; +create index idx_status on trade_brokerage_record (status) comment '状态'; -create table member_brokerage_withdraw +create table trade_brokerage_withdraw ( id int auto_increment comment '编号' primary key, @@ -97,8 +97,8 @@ create table member_brokerage_withdraw ) comment '佣金提现'; -create index idx_user_id on member_brokerage_withdraw (user_id) comment '用户编号'; -create index idx_audit_status on member_brokerage_withdraw (status) comment '状态'; +create index idx_user_id on trade_brokerage_withdraw (user_id) comment '用户编号'; +create index idx_audit_status on trade_brokerage_withdraw (status) comment '状态'; -- 增加字典 insert into system_dict_type(type, name) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java similarity index 51% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java index c4bc9bb37..38b2f4d71 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/MemberBrokerageRecordController.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/TradeBrokerageRecordController.java @@ -2,11 +2,11 @@ package cn.iocoder.yudao.module.trade.controller.admin.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.CommonResult; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; +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.TradeBrokerageRecordService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.tags.Tag; @@ -24,28 +24,28 @@ import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; @Tag(name = "管理后台 - 佣金记录") @RestController -@RequestMapping("/trade/member-brokerage-record") +@RequestMapping("/trade/brokerage-record") @Validated -public class MemberBrokerageRecordController { +public class TradeBrokerageRecordController { @Resource - private MemberBrokerageRecordService memberBrokerageRecordService; + private TradeBrokerageRecordService tradeBrokerageRecordService; @GetMapping("/get") @Operation(summary = "获得佣金记录") @Parameter(name = "id", description = "编号", required = true, example = "1024") - @PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')") - public CommonResult getMemberBrokerageRecord(@RequestParam("id") Integer id) { - MemberBrokerageRecordDO memberBrokerageRecord = memberBrokerageRecordService.getMemberBrokerageRecord(id); - return success(MemberBrokerageRecordConvert.INSTANCE.convert(memberBrokerageRecord)); + @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") + public CommonResult getBrokerageRecord(@RequestParam("id") Integer id) { + TradeBrokerageRecordDO tradeBrokerageRecord = tradeBrokerageRecordService.getBrokerageRecord(id); + return success(TradeBrokerageRecordConvert.INSTANCE.convert(tradeBrokerageRecord)); } @GetMapping("/page") @Operation(summary = "获得佣金记录分页") - @PreAuthorize("@ss.hasPermission('member:member-brokerage-record:query')") - public CommonResult> getMemberBrokerageRecordPage(@Valid MemberBrokerageRecordPageReqVO pageVO) { - PageResult pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(pageVO); - return success(MemberBrokerageRecordConvert.INSTANCE.convertPage(pageResult)); + @PreAuthorize("@ss.hasPermission('trade:brokerage-record:query')") + public CommonResult> getBrokerageRecordPage(@Valid TradeBrokerageRecordPageReqVO pageVO) { + PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(pageVO); + return success(TradeBrokerageRecordConvert.INSTANCE.convertPage(pageResult)); } } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java similarity index 98% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java index 51cd4a631..1fb87f294 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordBaseVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordBaseVO.java @@ -14,7 +14,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ * 如果子 VO 存在差异的字段,请不要添加到这里,影响 Swagger 文档生成 */ @Data -public class MemberBrokerageRecordBaseVO { +public class TradeBrokerageRecordBaseVO { @Schema(description = "用户编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "25973") @NotNull(message = "用户编号不能为空") diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java similarity index 94% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java index 3a5e05527..abd948f09 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordPageReqVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordPageReqVO.java @@ -15,7 +15,7 @@ import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_ @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberBrokerageRecordPageReqVO extends PageParam { +public class TradeBrokerageRecordPageReqVO extends PageParam { @Schema(description = "用户编号", example = "25973") private Long userId; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java similarity index 88% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java index 3550a64ba..724d7d3e5 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/MemberBrokerageRecordRespVO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/controller/admin/brokerage/record/vo/TradeBrokerageRecordRespVO.java @@ -11,7 +11,7 @@ import java.time.LocalDateTime; @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) -public class MemberBrokerageRecordRespVO extends MemberBrokerageRecordBaseVO { +public class TradeBrokerageRecordRespVO extends TradeBrokerageRecordBaseVO { @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "28896") private Integer id; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java similarity index 69% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java index 48af52cf5..b84e51354 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/MemberBrokerageRecordConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/brokerage/record/TradeBrokerageRecordConvert.java @@ -2,8 +2,8 @@ package cn.iocoder.yudao.module.trade.convert.brokerage.record; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordRespVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordRespVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.user.TradeBrokerageUserDO; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordBizTypeEnum; import cn.iocoder.yudao.module.trade.enums.brokerage.BrokerageRecordStatusEnum; @@ -19,22 +19,22 @@ import java.util.List; * @author owen */ @Mapper -public interface MemberBrokerageRecordConvert { +public interface TradeBrokerageRecordConvert { - MemberBrokerageRecordConvert INSTANCE = Mappers.getMapper(MemberBrokerageRecordConvert.class); + TradeBrokerageRecordConvert INSTANCE = Mappers.getMapper(TradeBrokerageRecordConvert.class); - MemberBrokerageRecordRespVO convert(MemberBrokerageRecordDO bean); + TradeBrokerageRecordRespVO convert(TradeBrokerageRecordDO bean); - List convertList(List list); + List convertList(List list); - PageResult convertPage(PageResult page); + PageResult convertPage(PageResult page); - default MemberBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { + default TradeBrokerageRecordDO convert(TradeBrokerageUserDO user, String bizId, int brokerageFrozenDays, int brokerage, LocalDateTime unfreezeTime) { // 不冻结时,佣金直接就是结算状态 Integer status = brokerageFrozenDays > 0 ? BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus() : BrokerageRecordStatusEnum.SETTLEMENT.getStatus(); - return new MemberBrokerageRecordDO() + return new TradeBrokerageRecordDO() .setUserId(user.getId()) .setBizType(BrokerageRecordBizTypeEnum.ORDER.getType()) .setBizId(bizId) diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java index d17b81124..f42af2d73 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/convert/order/TradeOrderConvert.java @@ -7,7 +7,7 @@ import cn.iocoder.yudao.framework.common.util.string.StrUtils; import cn.iocoder.yudao.framework.dict.core.util.DictFrameworkUtils; import cn.iocoder.yudao.framework.ip.core.utils.AreaUtils; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.user.dto.MemberUserRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.enums.DictTypeConstants; @@ -275,8 +275,8 @@ public interface TradeOrderConvert { TradeOrderDO convert(TradeOrderRemarkReqVO reqVO); - default BrokerageAddReqDTO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { - return new BrokerageAddReqDTO().setBizId(String.valueOf(item.getId())) + default BrokerageAddReqBO convert(TradeOrderItemDO item, ProductSkuRespDTO sku) { + return new BrokerageAddReqBO().setBizId(String.valueOf(item.getId())) .setPayPrice(item.getPayPrice()).setCount(item.getCount()) .setSkuFirstBrokeragePrice(sku.getSubCommissionFirstPrice()) .setSkuSecondBrokeragePrice(sku.getSubCommissionSecondPrice()); diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java similarity index 85% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java index 94d37ff89..0bf7c0cf2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/MemberBrokerageRecordDO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/dataobject/brokerage/record/TradeBrokerageRecordDO.java @@ -15,15 +15,15 @@ import java.time.LocalDateTime; * * @author owen */ -@TableName("member_brokerage_record") -@KeySequence("member_brokerage_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 +@TableName("trade_brokerage_record") +@KeySequence("trade_brokerage_record_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 @Data @EqualsAndHashCode(callSuper = true) @ToString(callSuper = true) @Builder @NoArgsConstructor @AllArgsConstructor -public class MemberBrokerageRecordDO extends BaseDO { +public class TradeBrokerageRecordDO extends BaseDO { /** * 编号 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java deleted file mode 100644 index da89b8bba..000000000 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/MemberBrokerageRecordMapper.java +++ /dev/null @@ -1,47 +0,0 @@ -package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; - -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; -import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; -import org.apache.ibatis.annotations.Mapper; - -import java.time.LocalDateTime; -import java.util.List; - -/** - * 佣金记录 Mapper - * - * @author owen - */ -@Mapper -public interface MemberBrokerageRecordMapper extends BaseMapperX { - - default PageResult selectPage(MemberBrokerageRecordPageReqVO reqVO) { - return selectPage(reqVO, new LambdaQueryWrapperX() - .eqIfPresent(MemberBrokerageRecordDO::getUserId, reqVO.getUserId()) - .eqIfPresent(MemberBrokerageRecordDO::getBizType, reqVO.getBizType()) - .eqIfPresent(MemberBrokerageRecordDO::getStatus, reqVO.getStatus()) - .betweenIfPresent(MemberBrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) - .orderByDesc(MemberBrokerageRecordDO::getId)); - } - - default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { - return selectList(new LambdaQueryWrapper() - .eq(MemberBrokerageRecordDO::getStatus, status) - .lt(MemberBrokerageRecordDO::getUnfreezeTime, unfreezeTime)); - } - - default int updateByIdAndStatus(Integer id, Integer status, MemberBrokerageRecordDO updateObj) { - return update(updateObj, new LambdaQueryWrapper() - .eq(MemberBrokerageRecordDO::getId, id) - .eq(MemberBrokerageRecordDO::getStatus, status)); - } - - default MemberBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) { - return selectOne(MemberBrokerageRecordDO::getBizType, bizType, - MemberBrokerageRecordDO::getBizId, bizId); - } -} 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 new file mode 100644 index 000000000..78efbc53a --- /dev/null +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/dal/mysql/brokerage/record/TradeBrokerageRecordMapper.java @@ -0,0 +1,47 @@ +package cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record; + +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; +import org.apache.ibatis.annotations.Mapper; + +import java.time.LocalDateTime; +import java.util.List; + +/** + * 佣金记录 Mapper + * + * @author owen + */ +@Mapper +public interface TradeBrokerageRecordMapper extends BaseMapperX { + + default PageResult selectPage(TradeBrokerageRecordPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(TradeBrokerageRecordDO::getUserId, reqVO.getUserId()) + .eqIfPresent(TradeBrokerageRecordDO::getBizType, reqVO.getBizType()) + .eqIfPresent(TradeBrokerageRecordDO::getStatus, reqVO.getStatus()) + .betweenIfPresent(TradeBrokerageRecordDO::getCreateTime, reqVO.getCreateTime()) + .orderByDesc(TradeBrokerageRecordDO::getId)); + } + + default List selectListByStatusAndUnfreezeTimeLt(Integer status, LocalDateTime unfreezeTime) { + return selectList(new LambdaQueryWrapper() + .eq(TradeBrokerageRecordDO::getStatus, status) + .lt(TradeBrokerageRecordDO::getUnfreezeTime, unfreezeTime)); + } + + default int updateByIdAndStatus(Integer id, Integer status, TradeBrokerageRecordDO updateObj) { + return update(updateObj, new LambdaQueryWrapper() + .eq(TradeBrokerageRecordDO::getId, id) + .eq(TradeBrokerageRecordDO::getStatus, status)); + } + + default TradeBrokerageRecordDO selectByUserIdAndBizTypeAndBizId(Integer bizType, String bizId) { + return selectOne(TradeBrokerageRecordDO::getBizType, bizType, + TradeBrokerageRecordDO::getBizId, bizId); + } +} diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java similarity index 63% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java index d41bc840c..94218d47e 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/MemberBrokerageRecordUnfreezeJob.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/job/brokerage/TradeBrokerageRecordUnfreezeJob.java @@ -3,7 +3,7 @@ package cn.iocoder.yudao.module.trade.job.brokerage; import cn.hutool.core.util.StrUtil; import cn.iocoder.yudao.framework.quartz.core.handler.JobHandler; import cn.iocoder.yudao.framework.tenant.core.job.TenantJob; -import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; import org.springframework.stereotype.Component; import javax.annotation.Resource; @@ -15,14 +15,14 @@ import javax.annotation.Resource; */ @Component @TenantJob -public class MemberBrokerageRecordUnfreezeJob implements JobHandler { +public class TradeBrokerageRecordUnfreezeJob implements JobHandler { @Resource - private MemberBrokerageRecordService memberBrokerageRecordService; + private TradeBrokerageRecordService tradeBrokerageRecordService; @Override public String execute(String param) { - int count = memberBrokerageRecordService.unfreezeRecord(); + int count = tradeBrokerageRecordService.unfreezeRecord(); return StrUtil.format("解冻佣金 {} 个", count); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java similarity index 74% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java index 5cdd9e1b5..6b83bdbc0 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordService.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordService.java @@ -1,9 +1,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +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 java.util.List; @@ -12,7 +12,7 @@ import java.util.List; * * @author owen */ -public interface MemberBrokerageRecordService { +public interface TradeBrokerageRecordService { /** * 获得佣金记录 @@ -20,7 +20,7 @@ public interface MemberBrokerageRecordService { * @param id 编号 * @return 佣金记录 */ - MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id); + TradeBrokerageRecordDO getBrokerageRecord(Integer id); /** * 获得佣金记录分页 @@ -28,7 +28,7 @@ public interface MemberBrokerageRecordService { * @param pageReqVO 分页查询 * @return 佣金记录分页 */ - PageResult getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO); + PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO); /** * 增加佣金 @@ -36,7 +36,7 @@ public interface MemberBrokerageRecordService { * @param userId 会员编号 * @param list 请求参数列表 */ - void addBrokerage(Long userId, List list); + void addBrokerage(Long userId, List list); /** * 取消佣金:将佣金记录,状态修改为已失效 diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java similarity index 78% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java index e56ae5dab..5502bcbf7 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImpl.java @@ -6,13 +6,13 @@ 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.service.brokerage.record.bo.BrokerageAddReqDTO; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.convert.brokerage.record.MemberBrokerageRecordConvert; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; +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.MemberBrokerageRecordMapper; +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.user.TradeBrokerageUserService; @@ -37,28 +37,28 @@ import java.util.function.Function; @Slf4j @Service @Validated -public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordService { +public class TradeBrokerageRecordServiceImpl implements TradeBrokerageRecordService { @Resource - private MemberBrokerageRecordMapper memberBrokerageRecordMapper; + private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; @Resource private TradeConfigService tradeConfigService; @Resource private TradeBrokerageUserService tradeBrokerageUserService; @Override - public MemberBrokerageRecordDO getMemberBrokerageRecord(Integer id) { - return memberBrokerageRecordMapper.selectById(id); + public TradeBrokerageRecordDO getBrokerageRecord(Integer id) { + return tradeBrokerageRecordMapper.selectById(id); } @Override - public PageResult getMemberBrokerageRecordPage(MemberBrokerageRecordPageReqVO pageReqVO) { - return memberBrokerageRecordMapper.selectPage(pageReqVO); + public PageResult getBrokerageRecordPage(TradeBrokerageRecordPageReqVO pageReqVO) { + return tradeBrokerageRecordMapper.selectPage(pageReqVO); } @Override @Transactional(rollbackFor = Exception.class) - public void addBrokerage(Long buyerId, List list) { + public void addBrokerage(Long buyerId, List list) { TradeConfigDO memberConfig = tradeConfigService.getTradeConfig(); // 0 未启用分销功能 if (memberConfig == null || !BooleanUtil.isTrue(memberConfig.getBrokerageEnabled())) { @@ -73,7 +73,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 1.2 计算一级分佣 - addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqDTO::getSkuFirstBrokeragePrice); + addBrokerage(firstUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageFirstPercent(), BrokerageAddReqBO::getSkuFirstBrokeragePrice); // 2.1 获得二级推广员 @@ -83,20 +83,20 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 2.2 计算二级分佣 - addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqDTO::getSkuSecondBrokeragePrice); + addBrokerage(secondUser, list, memberConfig.getBrokerageFrozenDays(), memberConfig.getBrokerageSecondPercent(), BrokerageAddReqBO::getSkuSecondBrokeragePrice); } @Override @Transactional(rollbackFor = Exception.class) public void cancelBrokerage(Long userId, String bizId) { - MemberBrokerageRecordDO record = memberBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); + TradeBrokerageRecordDO record = tradeBrokerageRecordMapper.selectByUserIdAndBizTypeAndBizId(BrokerageRecordBizTypeEnum.ORDER.getType(), bizId); if (record == null || ObjectUtil.notEqual(record.getUserId(), userId)) { log.error("[cancelBrokerage][userId({})][bizId({}) 更新为已失效失败:记录不存在]", userId, bizId); return; } - MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); - int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO().setStatus(BrokerageRecordStatusEnum.CANCEL.getStatus()); + int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[cancelBrokerage][record({}) 更新为已失效失败]", record.getId()); return; @@ -140,8 +140,8 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe * @param brokeragePercent 佣金比例 * @param skuBrokeragePriceFun 商品 SKU 设置的佣金 */ - private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, - Integer brokeragePercent, Function skuBrokeragePriceFun) { + private void addBrokerage(TradeBrokerageUserDO user, List list, Integer brokerageFrozenDays, + Integer brokeragePercent, Function skuBrokeragePriceFun) { // 处理冻结时间 brokerageFrozenDays = ObjectUtil.defaultIfNull(brokerageFrozenDays, 0); LocalDateTime unfreezeTime = null; @@ -151,12 +151,12 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe // 计算分佣 int totalBrokerage = 0; - List records = new ArrayList<>(); - for (BrokerageAddReqDTO dto : list) { + List records = new ArrayList<>(); + for (BrokerageAddReqBO dto : list) { int brokeragePerItem = calculateBrokerage(dto.getPayPrice(), brokeragePercent, skuBrokeragePriceFun.apply(dto)); if (brokeragePerItem > 0) { int brokerage = brokeragePerItem * dto.getCount(); - records.add(MemberBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); + records.add(TradeBrokerageRecordConvert.INSTANCE.convert(user, dto.getBizId(), brokerageFrozenDays, brokerage, unfreezeTime)); totalBrokerage += brokerage; } } @@ -166,7 +166,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } // 保存佣金记录 - memberBrokerageRecordMapper.insertBatch(records); + tradeBrokerageRecordMapper.insertBatch(records); if (brokerageFrozenDays > 0) { // 更新用户冻结佣金 @@ -180,7 +180,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe @Override public int unfreezeRecord() { // 1. 查询待结算的佣金记录 - List records = memberBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( + List records = tradeBrokerageRecordMapper.selectListByStatusAndUnfreezeTimeLt( BrokerageRecordStatusEnum.WAIT_SETTLEMENT.getStatus(), LocalDateTime.now()); if (CollUtil.isEmpty(records)) { return 0; @@ -188,7 +188,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe // 2. 遍历执行 int count = 0; - for (MemberBrokerageRecordDO record : records) { + for (TradeBrokerageRecordDO record : records) { try { boolean successful = getSelf().unfreezeRecord(record); if (successful) { @@ -202,12 +202,12 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe } @Transactional(rollbackFor = Exception.class) - public boolean unfreezeRecord(MemberBrokerageRecordDO record) { + public boolean unfreezeRecord(TradeBrokerageRecordDO record) { // 更新记录状态 - MemberBrokerageRecordDO updateObj = new MemberBrokerageRecordDO() + TradeBrokerageRecordDO updateObj = new TradeBrokerageRecordDO() .setStatus(BrokerageRecordStatusEnum.SETTLEMENT.getStatus()) .setUnfreezeTime(LocalDateTime.now()); - int updateRows = memberBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); + int updateRows = tradeBrokerageRecordMapper.updateByIdAndStatus(record.getId(), record.getStatus(), updateObj); if (updateRows == 0) { log.error("[unfreezeRecord][record({}) 更新为已结算失败]", record.getId()); return false; @@ -225,7 +225,7 @@ public class MemberBrokerageRecordServiceImpl implements MemberBrokerageRecordSe * * @return 自己 */ - private MemberBrokerageRecordServiceImpl getSelf() { + private TradeBrokerageRecordServiceImpl getSelf() { return SpringUtil.getBean(getClass()); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java similarity index 90% rename from yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java rename to yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java index a15ef76c0..a968d14ea 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqDTO.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/brokerage/record/bo/BrokerageAddReqBO.java @@ -5,13 +5,13 @@ import lombok.Data; import lombok.NoArgsConstructor; /** - * 佣金 增加 Request DTO + * 佣金 增加 Request BO * @author owen */ @Data @NoArgsConstructor @AllArgsConstructor -public class BrokerageAddReqDTO { +public class BrokerageAddReqBO { /** * 业务ID */ diff --git a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java index 9ab4842b8..b75b7ac7c 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/main/java/cn/iocoder/yudao/module/trade/service/order/TradeOrderUpdateServiceImpl.java @@ -12,8 +12,8 @@ import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.module.member.api.address.AddressApi; import cn.iocoder.yudao.module.member.api.address.dto.AddressRespDTO; -import cn.iocoder.yudao.module.trade.service.brokerage.record.MemberBrokerageRecordService; -import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqDTO; +import cn.iocoder.yudao.module.trade.service.brokerage.record.TradeBrokerageRecordService; +import cn.iocoder.yudao.module.trade.service.brokerage.record.bo.BrokerageAddReqBO; import cn.iocoder.yudao.module.member.api.level.MemberLevelApi; import cn.iocoder.yudao.module.member.api.point.MemberPointApi; import cn.iocoder.yudao.module.member.api.user.MemberUserApi; @@ -120,7 +120,7 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Resource private MemberPointApi memberPointApi; @Resource - private MemberBrokerageRecordService memberBrokerageRecordService; + private TradeBrokerageRecordService tradeBrokerageRecordService; @Resource private ProductCommentApi productCommentApi; @@ -752,14 +752,14 @@ public class TradeOrderUpdateServiceImpl implements TradeOrderUpdateService { @Async protected void addBrokerageAsync(Long userId, Long orderId) { List orderItems = tradeOrderItemMapper.selectListByOrderId(orderId); - List list = convertList(orderItems, + List list = convertList(orderItems, item -> TradeOrderConvert.INSTANCE.convert(item, productSkuApi.getSku(item.getSkuId()))); - memberBrokerageRecordService.addBrokerage(userId, list); + tradeBrokerageRecordService.addBrokerage(userId, list); } @Async protected void cancelBrokerageAsync(Long userId, Long orderItemId) { - memberBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); + tradeBrokerageRecordService.cancelBrokerage(userId, String.valueOf(orderItemId)); } /** diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java similarity index 66% rename from yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java rename to yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java index ae367ae63..a6d8dffb1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/MemberBrokerageRecordServiceImplTest.java +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/java/cn/iocoder/yudao/module/trade/service/brokerage/record/TradeBrokerageRecordServiceImplTest.java @@ -3,9 +3,9 @@ package cn.iocoder.yudao.module.trade.service.brokerage.record; import cn.hutool.core.util.NumberUtil; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest; -import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.MemberBrokerageRecordPageReqVO; -import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.MemberBrokerageRecordDO; -import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.MemberBrokerageRecordMapper; +import cn.iocoder.yudao.module.trade.controller.admin.brokerage.record.vo.TradeBrokerageRecordPageReqVO; +import cn.iocoder.yudao.module.trade.dal.dataobject.brokerage.record.TradeBrokerageRecordDO; +import cn.iocoder.yudao.module.trade.dal.mysql.brokerage.record.TradeBrokerageRecordMapper; import cn.iocoder.yudao.module.trade.service.brokerage.user.TradeBrokerageUserService; import cn.iocoder.yudao.module.trade.service.config.TradeConfigService; import org.junit.jupiter.api.Disabled; @@ -26,17 +26,17 @@ import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo; import static org.junit.jupiter.api.Assertions.assertEquals; /** - * {@link MemberBrokerageRecordServiceImpl} 的单元测试类 + * {@link TradeBrokerageRecordServiceImpl} 的单元测试类 * * @author owen */ -@Import(MemberBrokerageRecordServiceImpl.class) -public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { +@Import(TradeBrokerageRecordServiceImpl.class) +public class TradeBrokerageRecordServiceImplTest extends BaseDbUnitTest { @Resource - private MemberBrokerageRecordServiceImpl memberBrokerageRecordService; + private TradeBrokerageRecordServiceImpl tradeBrokerageRecordService; @Resource - private MemberBrokerageRecordMapper memberBrokerageRecordMapper; + private TradeBrokerageRecordMapper tradeBrokerageRecordMapper; @MockBean private TradeConfigService tradeConfigService; @@ -45,36 +45,36 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { @Test @Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解 - public void testGetMemberBrokerageRecordPage() { + public void testGetBrokerageRecordPage() { // mock 数据 - MemberBrokerageRecordDO dbMemberBrokerageRecord = randomPojo(MemberBrokerageRecordDO.class, o -> { // 等会查询到 + TradeBrokerageRecordDO dbBrokerageRecord = randomPojo(TradeBrokerageRecordDO.class, o -> { // 等会查询到 o.setUserId(null); o.setBizType(null); o.setStatus(null); o.setCreateTime(null); }); - memberBrokerageRecordMapper.insert(dbMemberBrokerageRecord); + tradeBrokerageRecordMapper.insert(dbBrokerageRecord); // 测试 userId 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setUserId(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setUserId(null))); // 测试 bizType 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setBizType(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setBizType(null))); // 测试 status 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setStatus(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setStatus(null))); // 测试 createTime 不匹配 - memberBrokerageRecordMapper.insert(cloneIgnoreId(dbMemberBrokerageRecord, o -> o.setCreateTime(null))); + tradeBrokerageRecordMapper.insert(cloneIgnoreId(dbBrokerageRecord, o -> o.setCreateTime(null))); // 准备参数 - MemberBrokerageRecordPageReqVO reqVO = new MemberBrokerageRecordPageReqVO(); + TradeBrokerageRecordPageReqVO reqVO = new TradeBrokerageRecordPageReqVO(); reqVO.setUserId(null); reqVO.setBizType(null); reqVO.setStatus(null); reqVO.setCreateTime(buildBetweenTime(2023, 2, 1, 2023, 2, 28)); // 调用 - PageResult pageResult = memberBrokerageRecordService.getMemberBrokerageRecordPage(reqVO); + PageResult pageResult = tradeBrokerageRecordService.getBrokerageRecordPage(reqVO); // 断言 assertEquals(1, pageResult.getTotal()); assertEquals(1, pageResult.getList().size()); - assertPojoEquals(dbMemberBrokerageRecord, pageResult.getList().get(0)); + assertPojoEquals(dbBrokerageRecord, pageResult.getList().get(0)); } @Test @@ -84,7 +84,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = randomInt(1, 101); Integer skuBrokeragePrice = randomInt(); // 调用 - int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, skuBrokeragePrice); } @@ -97,7 +97,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer skuBrokeragePrice = randomEle(new Integer[]{0, null}); System.out.println("skuBrokeragePrice=" + skuBrokeragePrice); // 调用 - int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, NumberUtil.div(NumberUtil.mul(payPrice, percent), 100, 0, RoundingMode.DOWN).intValue()); } @@ -109,7 +109,7 @@ public class MemberBrokerageRecordServiceImplTest extends BaseDbUnitTest { Integer percent = null; Integer skuBrokeragePrice = null; // 调用 - int brokerage = memberBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); + int brokerage = tradeBrokerageRecordService.calculateBrokerage(payPrice, percent, skuBrokeragePrice); // 断言 assertEquals(brokerage, 0); } diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql index b0715ca16..f02fdcaf1 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/clean.sql @@ -2,4 +2,5 @@ DELETE FROM trade_order; DELETE FROM trade_order_item; DELETE FROM trade_after_sale; DELETE FROM trade_after_sale_log; -DELETE FROM "trade_brokerage_user"; +DELETE FROM trade_brokerage_user; +DELETE FROM trade_brokerage_record; diff --git a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql index df68fd53b..02045d2c2 100644 --- a/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-mall/yudao-module-trade-biz/src/test/resources/sql/create_tables.sql @@ -142,4 +142,25 @@ CREATE TABLE IF NOT EXISTS "trade_brokerage_user" "deleted" bit NOT NULL DEFAULT FALSE, "tenant_id" bigint NOT NULL DEFAULT '0', PRIMARY KEY ("id") -) COMMENT '分销用户'; \ No newline at end of file +) COMMENT '分销用户'; +CREATE TABLE IF NOT EXISTS "trade_brokerage_record" +( + "id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY, + "user_id" bigint NOT NULL, + "biz_id" varchar NOT NULL, + "biz_type" varchar NOT NULL, + "title" varchar NOT NULL, + "price" int NOT NULL, + "total_price" int NOT NULL, + "description" varchar NOT NULL, + "status" varchar NOT NULL, + "frozen_days" int NOT NULL, + "unfreeze_time" varchar, + "creator" varchar DEFAULT '', + "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updater" varchar DEFAULT '', + "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + "deleted" bit NOT NULL DEFAULT FALSE, + "tenant_id" bigint not null default '0', + PRIMARY KEY ("id") +) COMMENT '佣金记录'; \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql index 6981982c4..f972e048d 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/clean.sql @@ -2,5 +2,4 @@ DELETE FROM "member_user"; DELETE FROM "member_address"; DELETE FROM "member_tag"; DELETE FROM "member_level"; -DELETE FROM "member_group"; -DELETE FROM "member_brokerage_record"; \ No newline at end of file +DELETE FROM "member_group"; \ No newline at end of file diff --git a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql index ccefc4bf1..5fdc526b0 100644 --- a/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql +++ b/yudao-module-member/yudao-module-member-biz/src/test/resources/sql/create_tables.sql @@ -89,25 +89,4 @@ CREATE TABLE IF NOT EXISTS "member_group" "deleted" bit NOT NULL DEFAULT FALSE, "tenant_id" bigint not null default '0', PRIMARY KEY ("id") -) COMMENT '用户分组'; -CREATE TABLE IF NOT EXISTS "member_brokerage_record" -( - "id" int NOT NULL GENERATED BY DEFAULT AS IDENTITY, - "user_id" bigint NOT NULL, - "biz_id" varchar NOT NULL, - "biz_type" varchar NOT NULL, - "title" varchar NOT NULL, - "price" int NOT NULL, - "total_price" int NOT NULL, - "description" varchar NOT NULL, - "status" varchar NOT NULL, - "frozen_days" int NOT NULL, - "unfreeze_time" varchar, - "creator" varchar DEFAULT '', - "create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP, - "updater" varchar DEFAULT '', - "update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, - "deleted" bit NOT NULL DEFAULT FALSE, - "tenant_id" bigint not null default '0', - PRIMARY KEY ("id") -) COMMENT '佣金记录'; \ No newline at end of file +) COMMENT '用户分组'; \ No newline at end of file