```refactor(system): 用户余额查询改为返回字符串表示的BigDecimal更改内容:
- 【控件层】SysUserController:用户余额现在作为BigDecimal返回,提高了精度和避免了潜在的数值误差。 - 【数据访问层】SysUserMapper:余额查询结果类型更改为BigDecimal,与数据库存储的货币值更一致。- 【Mapper XML】SysUserMapper.xml:selectBalance方法的结果类型更新为BigDecimal,增强了类型匹配和数据准确性。 - 【服务层】SysUserService:余额查询签名更新,返回类型改为BigDecimal,优化了服务接口。 - 【服务实现】SysUserServiceImpl:实现了新的BigDecimal余额查询方法,直接从Mapper返回BigDecimal值,简化了数据处理。 此改动确保了用户余额在所有层面上一致且精确的表示,避免了由于整形或字符串转换导致的潜在数据丢失或格式错误问题。 ```master
parent
e895310e0a
commit
b98ec80a4f
|
@ -26,6 +26,7 @@ import org.springframework.web.multipart.MultipartFile;
|
|||
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -275,9 +276,10 @@ public class SysUserController extends BaseController {
|
|||
@GetMapping("/balance/{userId}")
|
||||
public Result userBalance(@PathVariable("userId") Long userId){
|
||||
userService.checkUserDataScope(userId);
|
||||
int rows = userService.selectBalance(userId);
|
||||
System.out.println(rows);
|
||||
return Result.success(rows);
|
||||
BigDecimal balance = userService.selectBalance(userId);
|
||||
String balanceString = balance.toPlainString();
|
||||
System.out.println(balanceString);
|
||||
return Result.success(balanceString);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
|||
import com.muyu.common.system.domain.SysUser;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -144,5 +145,6 @@ public interface SysUserMapper extends BaseMapper<SysUser> {
|
|||
public SysUser checkEmailUnique (String email);
|
||||
|
||||
|
||||
public int selectBalance(Long userId);
|
||||
|
||||
BigDecimal selectBalance(Long userId);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ package com.muyu.system.service;
|
|||
import com.baomidou.mybatisplus.extension.service.IService;
|
||||
import com.muyu.common.system.domain.SysUser;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
|
@ -229,5 +230,5 @@ public interface SysUserService extends IService<SysUser> {
|
|||
int insertBalance(SysUser user);
|
||||
|
||||
|
||||
int selectBalance(Long userId);
|
||||
BigDecimal selectBalance(Long userId);
|
||||
}
|
||||
|
|
|
@ -128,10 +128,8 @@ public class SysUserServiceImpl extends ServiceImpl<SysUserMapper, SysUser> impl
|
|||
|
||||
|
||||
@Override
|
||||
public int selectBalance(Long userId) {
|
||||
int i = userMapper.selectBalance(userId);
|
||||
System.out.println(i);
|
||||
return i;
|
||||
public BigDecimal selectBalance(Long userId) {
|
||||
return userMapper.selectBalance(userId);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -184,7 +184,7 @@
|
|||
and del_flag = '0'
|
||||
limit 1
|
||||
</select>
|
||||
<select id="selectBalance" resultType="java.lang.Integer">
|
||||
<select id="selectBalance" resultType="java.math.BigDecimal">
|
||||
select user_balance from sys_user where user_id = #{userId}
|
||||
</select>
|
||||
|
||||
|
|
Loading…
Reference in New Issue