Commit f33b66558c3b2047827cab1b155a16d518c9b0ed
1 parent
1ffbd939
新增查询钱包余额明细接口
Showing
14 changed files
with
203 additions
and
19 deletions
sql/mysql/pay_wallet.sql
| ... | ... | @@ -27,7 +27,6 @@ CREATE TABLE `pay_wallet_transaction` |
| 27 | 27 | ( |
| 28 | 28 | `id` bigint NOT NULL AUTO_INCREMENT COMMENT '编号', |
| 29 | 29 | `wallet_id` bigint NOT NULL COMMENT '会员钱包 id', |
| 30 | - `user_id` bigint NOT NULL COMMENT '用户 id', | |
| 31 | 30 | `biz_type` tinyint NOT NULL COMMENT '关联类型', |
| 32 | 31 | `biz_id` bigint NOT NULL COMMENT '关联业务编号', |
| 33 | 32 | `no` varchar(64) NOT NULL COMMENT '流水号', |
| ... | ... | @@ -35,6 +34,7 @@ CREATE TABLE `pay_wallet_transaction` |
| 35 | 34 | `amount` int NOT NULL COMMENT '交易金额, 单位分', |
| 36 | 35 | `balance` int NOT NULL COMMENT '余额, 单位分', |
| 37 | 36 | `transaction_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '交易时间', |
| 37 | + `creator` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '创建者', | |
| 38 | 38 | `create_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间', |
| 39 | 39 | `updater` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NULL DEFAULT '' COMMENT '更新者', |
| 40 | 40 | `update_time` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间', | ... | ... |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/ErrorCodeConstants.java
| ... | ... | @@ -41,6 +41,9 @@ public interface ErrorCodeConstants { |
| 41 | 41 | ErrorCode REFUND_NOT_FOUND = new ErrorCode(1007006004, "支付退款单不存在"); |
| 42 | 42 | ErrorCode REFUND_STATUS_IS_NOT_WAITING = new ErrorCode(1007006005, "支付退款单不处于待退款"); |
| 43 | 43 | |
| 44 | + // ========== 钱包模块(退款) 1007007000 ========== | |
| 45 | + ErrorCode WALLET_NOT_FOUND = new ErrorCode(1007007000, "用户钱包不存在"); | |
| 46 | + | |
| 44 | 47 | // ========== 示例订单 1007900000 ========== |
| 45 | 48 | ErrorCode DEMO_ORDER_NOT_FOUND = new ErrorCode(1007900000, "示例订单不存在"); |
| 46 | 49 | ErrorCode DEMO_ORDER_UPDATE_PAID_STATUS_NOT_UNPAID = new ErrorCode(1007900001, "示例订单更新支付状态失败,订单不是【未支付】状态"); | ... | ... |
yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTypeEnum.java renamed to yudao-module-pay/yudao-module-pay-api/src/main/java/cn/iocoder/yudao/module/pay/enums/member/WalletTransactionQueryTypeEnum.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.enums.member; |
| 2 | 2 | |
| 3 | +import cn.hutool.core.util.ArrayUtil; | |
| 4 | +import cn.iocoder.yudao.framework.common.core.IntArrayValuable; | |
| 3 | 5 | import lombok.AllArgsConstructor; |
| 4 | 6 | import lombok.Getter; |
| 5 | 7 | |
| 8 | +import java.util.Arrays; | |
| 9 | + | |
| 6 | 10 | /** |
| 7 | - * 钱包交易大分类 | |
| 11 | + * 钱包明细查询类型 | |
| 8 | 12 | * |
| 9 | 13 | * @author jason |
| 10 | 14 | */ |
| 11 | 15 | @AllArgsConstructor |
| 12 | 16 | @Getter |
| 13 | -public enum WalletTypeEnum { | |
| 17 | +public enum WalletTransactionQueryTypeEnum implements IntArrayValuable { | |
| 14 | 18 | RECHARGE(1, "充值"), |
| 15 | 19 | EXPENSE(2, "消费"); |
| 16 | 20 | |
| 17 | 21 | private final Integer type; |
| 18 | 22 | |
| 19 | 23 | private final String desc; |
| 24 | + | |
| 25 | + public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(WalletTransactionQueryTypeEnum::getType).toArray(); | |
| 26 | + | |
| 27 | + @Override | |
| 28 | + public int[] array() { | |
| 29 | + return ARRAYS; | |
| 30 | + } | |
| 31 | + | |
| 32 | + public static WalletTransactionQueryTypeEnum valueOf(Integer type) { | |
| 33 | + return ArrayUtil.firstMatch(o -> o.getType().equals(type), values()); | |
| 34 | + } | |
| 20 | 35 | } | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletController.java
| ... | ... | @@ -22,7 +22,7 @@ import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUti |
| 22 | 22 | /** |
| 23 | 23 | * @author jason |
| 24 | 24 | */ |
| 25 | -@Tag(name = "用户 APP - 支付钱包") | |
| 25 | +@Tag(name = "用户 APP - 钱包") | |
| 26 | 26 | @RestController |
| 27 | 27 | @RequestMapping("/pay/wallet") |
| 28 | 28 | @Validated |
| ... | ... | @@ -33,7 +33,7 @@ public class AppPayWalletController { |
| 33 | 33 | private PayWalletService payWalletService; |
| 34 | 34 | |
| 35 | 35 | @GetMapping("/get") |
| 36 | - @Operation(summary = "获取支付钱包") | |
| 36 | + @Operation(summary = "获取钱包") | |
| 37 | 37 | public CommonResult<AppPayWalletRespVO> getPayWallet() { |
| 38 | 38 | PayWalletDO payWallet = payWalletService.getPayWallet(getLoginUserId(), UserTypeEnum.MEMBER.getValue()); |
| 39 | 39 | return success(PayWalletConvert.INSTANCE.convert(payWallet)); | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/AppPayWalletTransactionController.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.controller.app.wallet; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.CommonResult; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 6 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO; | |
| 7 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionRespVO; | |
| 8 | +import cn.iocoder.yudao.module.pay.convert.wallet.PayWalletTransactionConvert; | |
| 9 | +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; | |
| 10 | +import cn.iocoder.yudao.module.pay.service.wallet.PayWalletTransactionService; | |
| 11 | +import io.swagger.v3.oas.annotations.Operation; | |
| 12 | +import io.swagger.v3.oas.annotations.tags.Tag; | |
| 13 | +import lombok.extern.slf4j.Slf4j; | |
| 14 | +import org.springframework.validation.annotation.Validated; | |
| 15 | +import org.springframework.web.bind.annotation.GetMapping; | |
| 16 | +import org.springframework.web.bind.annotation.RequestMapping; | |
| 17 | +import org.springframework.web.bind.annotation.RestController; | |
| 18 | + | |
| 19 | +import javax.annotation.Resource; | |
| 20 | +import javax.validation.Valid; | |
| 21 | + | |
| 22 | +import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | |
| 23 | +import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | |
| 24 | + | |
| 25 | +@Tag(name = "用户 APP - 钱包余额明细") | |
| 26 | +@RestController | |
| 27 | +@RequestMapping("/pay/wallet-transaction") | |
| 28 | +@Validated | |
| 29 | +@Slf4j | |
| 30 | +public class AppPayWalletTransactionController { | |
| 31 | + | |
| 32 | + @Resource | |
| 33 | + private PayWalletTransactionService payWalletTransactionService; | |
| 34 | + | |
| 35 | + @GetMapping("/page") | |
| 36 | + @Operation(summary = "获得钱包余额明细分页") | |
| 37 | + public CommonResult<PageResult<AppPayWalletTransactionRespVO>> pageWalletTransaction( | |
| 38 | + @Valid AppPayWalletTransactionPageReqVO pageVO) { | |
| 39 | + PageResult<PayWalletTransactionDO> result = payWalletTransactionService.getWalletTransactionPage(getLoginUserId(), | |
| 40 | + UserTypeEnum.MEMBER.getValue(), pageVO); | |
| 41 | + return success(PayWalletTransactionConvert.INSTANCE.convertPage(result)); | |
| 42 | + } | |
| 43 | +} | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionPageReqVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 4 | +import cn.iocoder.yudao.framework.common.validation.InEnum; | |
| 5 | +import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum; | |
| 6 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 7 | +import lombok.Data; | |
| 8 | + | |
| 9 | +@Schema(description = "用户 APP - 钱包余额明细分页 Request VO") | |
| 10 | +@Data | |
| 11 | +public class AppPayWalletTransactionPageReqVO extends PageParam { | |
| 12 | + | |
| 13 | + @Schema(description = "余额明细查询分类", example = "1") | |
| 14 | + @InEnum(value = WalletTransactionQueryTypeEnum.class, message = "查询类型必须是 {value}") | |
| 15 | + private Integer type; | |
| 16 | +} | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/wallet/vo/AppPayWalletTransactionRespVO.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.controller.app.wallet.vo; | |
| 2 | + | |
| 3 | +import io.swagger.v3.oas.annotations.media.Schema; | |
| 4 | +import lombok.Data; | |
| 5 | + | |
| 6 | +import java.time.LocalDateTime; | |
| 7 | + | |
| 8 | +@Schema(description = "用户 APP - 钱包余额明细分页 Response VO") | |
| 9 | +@Data | |
| 10 | +public class AppPayWalletTransactionRespVO { | |
| 11 | + @Schema(description = "交易金额, 单位分", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | |
| 12 | + private Integer amount; | |
| 13 | + | |
| 14 | + @Schema(description = "业务分类", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | |
| 15 | + private Integer bizType; | |
| 16 | + | |
| 17 | + @Schema(description = "交易时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "100") | |
| 18 | + private LocalDateTime transactionTime; | |
| 19 | +} | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/wallet/PayWalletTransactionConvert.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.convert.wallet; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionRespVO; | |
| 5 | +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; | |
| 6 | +import org.mapstruct.Mapper; | |
| 7 | +import org.mapstruct.factory.Mappers; | |
| 8 | + | |
| 9 | +@Mapper | |
| 10 | +public interface PayWalletTransactionConvert { | |
| 11 | + | |
| 12 | + PayWalletTransactionConvert INSTANCE = Mappers.getMapper(PayWalletTransactionConvert.class); | |
| 13 | + | |
| 14 | + PageResult<AppPayWalletTransactionRespVO> convertPage(PageResult<PayWalletTransactionDO> page); | |
| 15 | +} | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/dataobject/wallet/PayWalletTransactionDO.java
| ... | ... | @@ -27,22 +27,13 @@ public class PayWalletTransactionDO extends BaseDO { |
| 27 | 27 | |
| 28 | 28 | /** |
| 29 | 29 | * 会员钱包 id |
| 30 | - * | |
| 31 | 30 | * 关联 {@link PayWalletDO#getId()} |
| 32 | 31 | */ |
| 33 | 32 | private Long walletId; |
| 34 | 33 | |
| 35 | 34 | /** |
| 36 | - * 用户 id | |
| 37 | - * | |
| 38 | - * 关联 MemberUserDO 的 id 编号 | |
| 39 | - */ | |
| 40 | - private Long userId; | |
| 41 | - | |
| 42 | - /** | |
| 43 | - * 关联业务 | |
| 44 | - * | |
| 45 | - * 枚举 {@link WalletBizTypeEnum#getBizType()} | |
| 35 | + * 钱包交易业务分类 | |
| 36 | + * 关联枚举 {@link WalletBizTypeEnum#getBizType()} | |
| 46 | 37 | */ |
| 47 | 38 | private Integer bizType; |
| 48 | 39 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/dal/mysql/wallet/PayWalletTransactionMapper.java
| 1 | 1 | package cn.iocoder.yudao.module.pay.dal.mysql.wallet; |
| 2 | 2 | |
| 3 | 3 | |
| 4 | +import cn.iocoder.yudao.framework.common.pojo.PageParam; | |
| 5 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | 6 | import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; |
| 7 | +import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX; | |
| 5 | 8 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; |
| 9 | +import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum; | |
| 6 | 10 | import org.apache.ibatis.annotations.Mapper; |
| 7 | 11 | |
| 8 | 12 | @Mapper |
| 9 | 13 | public interface PayWalletTransactionMapper extends BaseMapperX<PayWalletTransactionDO> { |
| 10 | 14 | |
| 15 | + default PageResult<PayWalletTransactionDO> selectPageByWalletIdAndQueryType(Long walletId, | |
| 16 | + WalletTransactionQueryTypeEnum queryType, | |
| 17 | + PageParam pageParam) { | |
| 18 | + LambdaQueryWrapperX<PayWalletTransactionDO> query = new LambdaQueryWrapperX<PayWalletTransactionDO>() | |
| 19 | + .eq(PayWalletTransactionDO::getWalletId, walletId); | |
| 20 | + if (WalletTransactionQueryTypeEnum.RECHARGE == queryType ) { | |
| 21 | + query.ge(PayWalletTransactionDO::getAmount, 0); | |
| 22 | + } | |
| 23 | + if (WalletTransactionQueryTypeEnum.EXPENSE == queryType ) { | |
| 24 | + query.lt(PayWalletTransactionDO::getAmount, 0); | |
| 25 | + } | |
| 26 | + query.orderByDesc(PayWalletTransactionDO::getTransactionTime); | |
| 27 | + return selectPage(pageParam, query); | |
| 28 | + } | |
| 11 | 29 | } |
| 12 | 30 | |
| 13 | 31 | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletService.java
| ... | ... | @@ -3,14 +3,14 @@ package cn.iocoder.yudao.module.pay.service.wallet; |
| 3 | 3 | import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; |
| 4 | 4 | |
| 5 | 5 | /** |
| 6 | - * 支付钱包 Service 接口 | |
| 6 | + * 钱包 Service 接口 | |
| 7 | 7 | * |
| 8 | 8 | * @author jason |
| 9 | 9 | */ |
| 10 | 10 | public interface PayWalletService { |
| 11 | 11 | |
| 12 | 12 | /** |
| 13 | - * 得到用户的支付钱包 | |
| 13 | + * 获取钱包信息 | |
| 14 | 14 | * @param userId 用户 id |
| 15 | 15 | * @param userType 用户类型 |
| 16 | 16 | */ | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletServiceImpl.java
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionService.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.service.wallet; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; | |
| 6 | + | |
| 7 | +/** | |
| 8 | + * 钱包余额明细 Service 接口 | |
| 9 | + * | |
| 10 | + * @author jason | |
| 11 | + */ | |
| 12 | +public interface PayWalletTransactionService { | |
| 13 | + | |
| 14 | + /** | |
| 15 | + * 查询钱包余额明细, 分页 | |
| 16 | + * | |
| 17 | + * @param userId 用户 id | |
| 18 | + * @param userType 用户类型 | |
| 19 | + * @param pageVO 分页查询参数 | |
| 20 | + */ | |
| 21 | + PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType, | |
| 22 | + AppPayWalletTransactionPageReqVO pageVO); | |
| 23 | +} | ... | ... |
yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/wallet/PayWalletTransactionServiceImpl.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.pay.service.wallet; | |
| 2 | + | |
| 3 | +import cn.iocoder.yudao.framework.common.pojo.PageResult; | |
| 4 | +import cn.iocoder.yudao.module.pay.controller.app.wallet.vo.AppPayWalletTransactionPageReqVO; | |
| 5 | +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletDO; | |
| 6 | +import cn.iocoder.yudao.module.pay.dal.dataobject.wallet.PayWalletTransactionDO; | |
| 7 | +import cn.iocoder.yudao.module.pay.dal.mysql.wallet.PayWalletTransactionMapper; | |
| 8 | +import cn.iocoder.yudao.module.pay.enums.member.WalletTransactionQueryTypeEnum; | |
| 9 | +import lombok.extern.slf4j.Slf4j; | |
| 10 | +import org.springframework.stereotype.Service; | |
| 11 | + | |
| 12 | +import javax.annotation.Resource; | |
| 13 | + | |
| 14 | +import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception; | |
| 15 | +import static cn.iocoder.yudao.module.pay.enums.ErrorCodeConstants.WALLET_NOT_FOUND; | |
| 16 | + | |
| 17 | +/** | |
| 18 | + * 钱包余额明细 Service 实现类 | |
| 19 | + * | |
| 20 | + * @author jason | |
| 21 | + */ | |
| 22 | +@Service | |
| 23 | +@Slf4j | |
| 24 | +public class PayWalletTransactionServiceImpl implements PayWalletTransactionService{ | |
| 25 | + @Resource | |
| 26 | + private PayWalletService payWalletService; | |
| 27 | + @Resource | |
| 28 | + private PayWalletTransactionMapper payWalletTransactionMapper; | |
| 29 | + | |
| 30 | + @Override | |
| 31 | + public PageResult<PayWalletTransactionDO> getWalletTransactionPage(Long userId, Integer userType, | |
| 32 | + AppPayWalletTransactionPageReqVO pageVO) { | |
| 33 | + PayWalletDO payWallet = payWalletService.getPayWallet(userId, userType); | |
| 34 | + if (payWallet == null) { | |
| 35 | + log.error("[pageWalletTransaction] 用户 {} 钱包不存在", userId); | |
| 36 | + throw exception(WALLET_NOT_FOUND); | |
| 37 | + } | |
| 38 | + return payWalletTransactionMapper.selectPageByWalletIdAndQueryType(payWallet.getId(), | |
| 39 | + WalletTransactionQueryTypeEnum.valueOf(pageVO.getType()), pageVO); | |
| 40 | + } | |
| 41 | +} | ... | ... |