feat(wallet): 新增用户钱包余额查询功能
This commit is contained in:
@@ -86,7 +86,8 @@ public class SaTokenConfigure implements WebMvcConfigurer {
|
||||
"/user/resetPassWord",
|
||||
"/chat/talk",
|
||||
"/chat/save_embed",
|
||||
"/themes/listByStyle"
|
||||
"/themes/listByStyle",
|
||||
"/wallet/balance"
|
||||
};
|
||||
}
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
package com.yolo.keyborad.controller;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import com.yolo.keyborad.common.BaseResponse;
|
||||
import com.yolo.keyborad.common.ResultUtils;
|
||||
import com.yolo.keyborad.model.vo.wallet.KeyboardUserWalletRespVO;
|
||||
import com.yolo.keyborad.service.KeyboardUserWalletService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import jakarta.annotation.Resource;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/10
|
||||
*/
|
||||
@RestController
|
||||
@Slf4j
|
||||
@RequestMapping("/wallet")
|
||||
@Tag(name = "钱包", description = "用户钱包接口")
|
||||
public class WalletController {
|
||||
|
||||
@Resource
|
||||
private KeyboardUserWalletService walletService;
|
||||
|
||||
@GetMapping("/balance")
|
||||
@Operation(summary = "查询钱包余额", description = "查询当前登录用户的钱包余额")
|
||||
public BaseResponse<KeyboardUserWalletRespVO> getBalance() {
|
||||
Long userId = StpUtil.getLoginIdAsLong();
|
||||
KeyboardUserWalletRespVO balance = walletService.getWalletBalance(userId);
|
||||
return ResultUtils.success(balance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package com.yolo.keyborad.mapper;
|
||||
|
||||
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||
import com.yolo.keyborad.model.entity.KeyboardUserWallet;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/10 18:18
|
||||
*/
|
||||
|
||||
public interface KeyboardUserWalletMapper extends BaseMapper<KeyboardUserWallet> {
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package com.yolo.keyborad.model.entity;
|
||||
|
||||
import com.baomidou.mybatisplus.annotation.IdType;
|
||||
import com.baomidou.mybatisplus.annotation.TableField;
|
||||
import com.baomidou.mybatisplus.annotation.TableId;
|
||||
import com.baomidou.mybatisplus.annotation.TableName;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import lombok.Data;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/10 18:18
|
||||
*/
|
||||
|
||||
@Schema
|
||||
@Data
|
||||
@TableName(value = "keyboard_user_wallet")
|
||||
public class KeyboardUserWallet {
|
||||
/**
|
||||
* 主键 Id
|
||||
*/
|
||||
@TableId(value = "id", type = IdType.AUTO)
|
||||
@Schema(description = "主键 Id")
|
||||
private Long id;
|
||||
|
||||
/**
|
||||
* 用户 id
|
||||
*/
|
||||
@TableField(value = "user_id")
|
||||
@Schema(description = "用户 id")
|
||||
private Long userId;
|
||||
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
@TableField(value = "balance")
|
||||
@Schema(description = "余额")
|
||||
private BigDecimal balance;
|
||||
|
||||
/**
|
||||
* 乐观锁版本
|
||||
*/
|
||||
@TableField(value = "version")
|
||||
@Schema(description = "乐观锁版本")
|
||||
private Integer version;
|
||||
|
||||
/**
|
||||
* 状态
|
||||
*/
|
||||
@TableField(value = "\"status\"")
|
||||
@Schema(description = "状态")
|
||||
private Short status;
|
||||
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
@TableField(value = "created_at")
|
||||
@Schema(description = "创建时间")
|
||||
private Date createdAt;
|
||||
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
@TableField(value = "updated_at")
|
||||
@Schema(description = "更新时间")
|
||||
private Date updatedAt;
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package com.yolo.keyborad.model.vo.wallet;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/10
|
||||
*/
|
||||
@Schema(description = "用户钱包返回对象")
|
||||
@Data
|
||||
public class KeyboardUserWalletRespVO {
|
||||
/**
|
||||
* 余额
|
||||
*/
|
||||
@Schema(description = "余额")
|
||||
private BigDecimal balance;
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.yolo.keyborad.service;
|
||||
|
||||
import com.yolo.keyborad.model.entity.KeyboardUserWallet;
|
||||
import com.yolo.keyborad.model.vo.wallet.KeyboardUserWalletRespVO;
|
||||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/10 18:15
|
||||
*/
|
||||
|
||||
public interface KeyboardUserWalletService extends IService<KeyboardUserWallet>{
|
||||
|
||||
/**
|
||||
* 获取用户钱包余额
|
||||
* @param userId 用户ID
|
||||
* @return 钱包余额信息
|
||||
*/
|
||||
KeyboardUserWalletRespVO getWalletBalance(Long userId);
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yolo.keyborad.service.impl;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.yolo.keyborad.common.ErrorCode;
|
||||
import com.yolo.keyborad.exception.BusinessException;
|
||||
import com.yolo.keyborad.model.vo.wallet.KeyboardUserWalletRespVO;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.stereotype.Service;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.yolo.keyborad.mapper.KeyboardUserWalletMapper;
|
||||
import com.yolo.keyborad.model.entity.KeyboardUserWallet;
|
||||
import com.yolo.keyborad.service.KeyboardUserWalletService;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/*
|
||||
* @author: ziin
|
||||
* @date: 2025/12/10 18:15
|
||||
*/
|
||||
|
||||
@Service
|
||||
@Slf4j
|
||||
public class KeyboardUserWalletServiceImpl extends ServiceImpl<KeyboardUserWalletMapper, KeyboardUserWallet> implements KeyboardUserWalletService{
|
||||
|
||||
@Override
|
||||
public KeyboardUserWalletRespVO getWalletBalance(Long userId) {
|
||||
KeyboardUserWallet wallet = this.lambdaQuery()
|
||||
.eq(KeyboardUserWallet::getUserId, userId)
|
||||
.one();
|
||||
KeyboardUserWalletRespVO respVO = new KeyboardUserWalletRespVO();
|
||||
if (wallet == null) {
|
||||
// 如果用户没有钱包记录,返回余额为0
|
||||
respVO.setBalance(BigDecimal.ZERO);
|
||||
} else {
|
||||
respVO.setBalance(wallet.getBalance());
|
||||
}
|
||||
return respVO;
|
||||
}
|
||||
}
|
||||
19
src/main/resources/mapper/KeyboardUserWalletMapper.xml
Normal file
19
src/main/resources/mapper/KeyboardUserWalletMapper.xml
Normal file
@@ -0,0 +1,19 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||
<mapper namespace="com.yolo.keyborad.mapper.KeyboardUserWalletMapper">
|
||||
<resultMap id="BaseResultMap" type="com.yolo.keyborad.model.entity.KeyboardUserWallet">
|
||||
<!--@mbg.generated-->
|
||||
<!--@Table keyboard_user_wallet-->
|
||||
<id column="id" jdbcType="BIGINT" property="id" />
|
||||
<result column="user_id" jdbcType="BIGINT" property="userId" />
|
||||
<result column="balance" jdbcType="NUMERIC" property="balance" />
|
||||
<result column="version" jdbcType="INTEGER" property="version" />
|
||||
<result column="status" jdbcType="SMALLINT" property="status" />
|
||||
<result column="created_at" jdbcType="TIMESTAMP" property="createdAt" />
|
||||
<result column="updated_at" jdbcType="TIMESTAMP" property="updatedAt" />
|
||||
</resultMap>
|
||||
<sql id="Base_Column_List">
|
||||
<!--@mbg.generated-->
|
||||
id, user_id, balance, version, "status", created_at, updated_at
|
||||
</sql>
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user