feat(tenant-balance): 新增查询自身及下级余额接口

- Controller 增加 /get-self-amount 与 /get-self-subordinate-amount-page 端点
- Service 与 Mapper 实现当前租户余额查询及下级分页查询
- RespVO 移除乐观锁字段,改用 updatedAt 并补充 tenantName 展示
This commit is contained in:
2025-11-21 15:51:17 +08:00
parent 1c40343c6d
commit dfdedbb92d
6 changed files with 53 additions and 4 deletions

View File

@@ -117,4 +117,20 @@ public class TenantBalanceController {
tenantBalanceService.transferToTenant(transferReqVO);
return success(true);
}
@GetMapping("/get-self-amount")
@Operation(summary = "获得自己的余额")
@PreAuthorize("@ss.hasPermission('system:tenant-balance:self-amount')")
public CommonResult<TenantBalanceRespVO> getTenantBalance() {
TenantBalanceDO tenantBalance = tenantBalanceService.getSelfBalance();
return success(BeanUtils.toBean(tenantBalance, TenantBalanceRespVO.class));
}
@GetMapping("/get-self-subordinate-amount-page")
@Operation(summary = "获得自己下级余额的分页")
@PreAuthorize("@ss.hasPermission('system:tenant-balance:self-subordinate')")
public CommonResult<PageResult<TenantBalanceRespVO>> getSelfSubordinate(@Valid TenantBalancePageReqVO pageReqVO) {
PageResult<TenantBalanceRespVO> tenantBalancePage = tenantBalanceService.getSelfSubordinateTenantBalancePage(pageReqVO);
return success(BeanUtils.toBean(tenantBalancePage, TenantBalanceRespVO.class));
}
}

View File

@@ -20,10 +20,6 @@ public class TenantBalanceRespVO {
@ExcelProperty("当前积分余额")
private Integer balance;
@Schema(description = "乐观锁版本号", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("乐观锁版本号")
private Integer version;
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("更新时间")
private LocalDateTime updatedAt;

View File

@@ -45,4 +45,6 @@ public interface TenantBalanceMapper extends BaseMapperX<TenantBalanceDO> {
IPage<TenantBalanceRespVO> selectPageWithTenantName(IPage<TenantBalanceRespVO> iPage,@Param("req") TenantBalancePageReqVO pageReqVO);
IPage<TenantBalanceRespVO> selectPageWithSelfSubordinateTenant(@Param("iPage") IPage<TenantBalanceRespVO> iPage, @Param("pageReqVO") TenantBalancePageReqVO pageReqVO, @Param("tenantId") Long tenantId);
}

View File

@@ -62,4 +62,8 @@ public interface TenantBalanceService {
void addTenantBalance(@Valid TenantBalanceAddReqVO updateReqVO);
void transferToTenant(@Valid TenantBalanceTransferReqVO transferReqVO);
TenantBalanceDO getSelfBalance();
PageResult<TenantBalanceRespVO> getSelfSubordinateTenantBalancePage(@Valid TenantBalancePageReqVO pageReqVO);
}

View File

@@ -259,4 +259,22 @@ public class TenantBalanceServiceImpl implements TenantBalanceService {
}
@Override
public TenantBalanceDO getSelfBalance() {
Long tenantId = TenantContextHolder.getTenantId();
TenantBalanceDO tenantBalance = tenantBalanceMapper.selectById(tenantId);
if (tenantBalance == null) {
throw exception(TENANT_WALLET_NOT_EXISTS);
}
return tenantBalance;
}
@Override
public PageResult<TenantBalanceRespVO> getSelfSubordinateTenantBalancePage(TenantBalancePageReqVO pageReqVO) {
Long tenantId = TenantContextHolder.getTenantId();
IPage<TenantBalanceRespVO> iPage = new Page<>(pageReqVO.getPageNo(),pageReqVO.getPageSize());
IPage<TenantBalanceRespVO> tenantBalanceRespVOIPage = tenantBalanceMapper.selectPageWithSelfSubordinateTenant(iPage, pageReqVO,tenantId);
return new PageResult<>(tenantBalanceRespVOIPage.getRecords(),tenantBalanceRespVOIPage.getTotal());
}
}

View File

@@ -21,4 +21,17 @@
</where>
order by stb.id desc
</select>
<select id="selectPageWithSelfSubordinateTenant"
resultType="cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo.TenantBalanceRespVO">
select stb.*, st.name as tenantName from system_tenant_balance as stb
left join system_tenant as st on stb.id = st.id
<where>
and st.parent_Id = #{tenantId,jdbcType=BIGINT}
<if test="pageReqVO.id != null">
and stb.id = #{pageReqVO.id,jdbcType=BIGINT}
</if>
</where>
order by stb.id desc
</select>
</mapper>