feat(tenant-balance): 新增租户余额管理功能
新增租户余额实体、Mapper、Service、Controller 及对应 VO,支持余额分页查询、保存与错误码定义。
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.tenantbalance;
|
||||
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.security.access.prepost.PreAuthorize;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
|
||||
import javax.validation.constraints.*;
|
||||
import javax.validation.*;
|
||||
import javax.servlet.http.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
|
||||
import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils;
|
||||
|
||||
import cn.iocoder.yudao.framework.apilog.core.annotation.ApiAccessLog;
|
||||
import static cn.iocoder.yudao.framework.apilog.core.enums.OperateTypeEnum.*;
|
||||
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import cn.iocoder.yudao.module.system.service.tenantbalance.TenantBalanceService;
|
||||
|
||||
@Tag(name = "管理后台 - 租户余额")
|
||||
@RestController
|
||||
@RequestMapping("/system/tenant-balance")
|
||||
@Validated
|
||||
public class TenantBalanceController {
|
||||
|
||||
@Resource
|
||||
private TenantBalanceService tenantBalanceService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建租户余额")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-balance:create')")
|
||||
public CommonResult<Long> createTenantBalance(@Valid @RequestBody TenantBalanceSaveReqVO createReqVO) {
|
||||
return success(tenantBalanceService.createTenantBalance(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新租户余额")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-balance:update')")
|
||||
public CommonResult<Boolean> updateTenantBalance(@Valid @RequestBody TenantBalanceSaveReqVO updateReqVO) {
|
||||
tenantBalanceService.updateTenantBalance(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除租户余额")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-balance:delete')")
|
||||
public CommonResult<Boolean> deleteTenantBalance(@RequestParam("id") Long id) {
|
||||
tenantBalanceService.deleteTenantBalance(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除租户余额")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-balance:delete')")
|
||||
public CommonResult<Boolean> deleteTenantBalanceList(@RequestParam("ids") List<Long> ids) {
|
||||
tenantBalanceService.deleteTenantBalanceListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得租户余额")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-balance:query')")
|
||||
public CommonResult<TenantBalanceRespVO> getTenantBalance(@RequestParam("id") Long id) {
|
||||
TenantBalanceDO tenantBalance = tenantBalanceService.getTenantBalance(id);
|
||||
return success(BeanUtils.toBean(tenantBalance, TenantBalanceRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得租户余额分页")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-balance:query')")
|
||||
public CommonResult<PageResult<TenantBalanceRespVO>> getTenantBalancePage(@Valid TenantBalancePageReqVO pageReqVO) {
|
||||
PageResult<TenantBalanceDO> pageResult = tenantBalanceService.getTenantBalancePage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, TenantBalanceRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出租户余额 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('system:tenant-balance:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportTenantBalanceExcel(@Valid TenantBalancePageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<TenantBalanceDO> list = tenantBalanceService.getTenantBalancePage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "租户余额.xls", "数据", TenantBalanceRespVO.class,
|
||||
BeanUtils.toBean(list, TenantBalanceRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
|
||||
|
||||
@Schema(description = "管理后台 - 租户余额分页 Request VO")
|
||||
@Data
|
||||
public class TenantBalancePageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "当前积分余额")
|
||||
private Integer balance;
|
||||
|
||||
@Schema(description = "乐观锁版本号")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - 租户余额 Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class TenantBalanceRespVO {
|
||||
|
||||
@Schema(description = "当前积分余额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("当前积分余额")
|
||||
private Integer balance;
|
||||
|
||||
@Schema(description = "乐观锁版本号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("乐观锁版本号")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
@Schema(description = "管理后台 - 租户余额新增/修改 Request VO")
|
||||
@Data
|
||||
public class TenantBalanceSaveReqVO {
|
||||
|
||||
@Schema(description = "租户 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "19954")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "当前积分余额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "当前积分余额不能为空")
|
||||
private Integer balance;
|
||||
|
||||
@Schema(description = "乐观锁版本号", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "乐观锁版本号不能为空")
|
||||
private Integer version;
|
||||
|
||||
@Schema(description = "更新时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "更新时间不能为空")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package cn.iocoder.yudao.module.system.dal.dataobject.tenantbalance;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 租户余额 DO
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
@TableName("system_tenant_balance")
|
||||
@KeySequence("system_tenant_balance_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class TenantBalanceDO extends BaseDO {
|
||||
|
||||
private Long id;
|
||||
/**
|
||||
* 当前积分余额
|
||||
*/
|
||||
private Integer balance;
|
||||
/**
|
||||
* 乐观锁版本号
|
||||
*/
|
||||
private Integer version;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package cn.iocoder.yudao.module.system.dal.mysql.tenantbalance;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo.*;
|
||||
|
||||
/**
|
||||
* 租户余额 Mapper
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
@Mapper
|
||||
public interface TenantBalanceMapper extends BaseMapperX<TenantBalanceDO> {
|
||||
|
||||
default PageResult<TenantBalanceDO> selectPage(TenantBalancePageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<TenantBalanceDO>()
|
||||
.eqIfPresent(TenantBalanceDO::getBalance, reqVO.getBalance())
|
||||
.eqIfPresent(TenantBalanceDO::getVersion, reqVO.getVersion())
|
||||
.eqIfPresent(TenantBalanceDO::getUpdatedAt, reqVO.getUpdatedAt())
|
||||
.orderByDesc(TenantBalanceDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -119,6 +119,10 @@ public interface ErrorCodeConstants {
|
||||
// ========== 租户套餐 1-002-017-000 ==========
|
||||
ErrorCode TENANT_POINTS_NOT_EXISTS = new ErrorCode(1_002_017_000, "租户积分不存在");
|
||||
|
||||
// ========== 租户余额 1-003-017-000 ==========
|
||||
ErrorCode TENANT_BALANCE_NOT_EXISTS = new ErrorCode(1_003_017_000, "租户余额不存在");
|
||||
|
||||
|
||||
// ========== 社交用户 1-002-018-000 ==========
|
||||
ErrorCode SOCIAL_USER_AUTH_FAILURE = new ErrorCode(1_002_018_000, "社交授权失败,原因是:{}");
|
||||
ErrorCode SOCIAL_USER_NOT_FOUND = new ErrorCode(1_002_018_001, "社交授权失败,找不到对应的用户");
|
||||
|
||||
@@ -0,0 +1,62 @@
|
||||
package cn.iocoder.yudao.module.system.service.tenantbalance;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 租户余额 Service 接口
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
public interface TenantBalanceService {
|
||||
|
||||
/**
|
||||
* 创建租户余额
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createTenantBalance(@Valid TenantBalanceSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新租户余额
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateTenantBalance(@Valid TenantBalanceSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除租户余额
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteTenantBalance(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除租户余额
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteTenantBalanceListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得租户余额
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 租户余额
|
||||
*/
|
||||
TenantBalanceDO getTenantBalance(Long id);
|
||||
|
||||
/**
|
||||
* 获得租户余额分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 租户余额分页
|
||||
*/
|
||||
PageResult<TenantBalanceDO> getTenantBalancePage(TenantBalancePageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package cn.iocoder.yudao.module.system.service.tenantbalance;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import org.springframework.stereotype.Service;
|
||||
import javax.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.*;
|
||||
import cn.iocoder.yudao.module.system.controller.admin.tenantbalance.vo.*;
|
||||
import cn.iocoder.yudao.module.system.dal.dataobject.tenantbalance.TenantBalanceDO;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
import cn.iocoder.yudao.module.system.dal.mysql.tenantbalance.TenantBalanceMapper;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static cn.iocoder.yudao.module.system.enums.ErrorCodeConstants.*;
|
||||
|
||||
/**
|
||||
* 租户余额 Service 实现类
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class TenantBalanceServiceImpl implements TenantBalanceService {
|
||||
|
||||
@Resource
|
||||
private TenantBalanceMapper tenantBalanceMapper;
|
||||
|
||||
@Override
|
||||
public Long createTenantBalance(TenantBalanceSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
TenantBalanceDO tenantBalance = BeanUtils.toBean(createReqVO, TenantBalanceDO.class);
|
||||
tenantBalanceMapper.insert(tenantBalance);
|
||||
// 返回
|
||||
return tenantBalance.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTenantBalance(TenantBalanceSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTenantBalanceExists(updateReqVO.getId());
|
||||
// 更新
|
||||
TenantBalanceDO updateObj = BeanUtils.toBean(updateReqVO, TenantBalanceDO.class);
|
||||
tenantBalanceMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTenantBalance(Long id) {
|
||||
// 校验存在
|
||||
validateTenantBalanceExists(id);
|
||||
// 删除
|
||||
tenantBalanceMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTenantBalanceListByIds(List<Long> ids) {
|
||||
// 校验存在
|
||||
validateTenantBalanceExists(ids);
|
||||
// 删除
|
||||
tenantBalanceMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateTenantBalanceExists(List<Long> ids) {
|
||||
List<TenantBalanceDO> list = tenantBalanceMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(TENANT_BALANCE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateTenantBalanceExists(Long id) {
|
||||
if (tenantBalanceMapper.selectById(id) == null) {
|
||||
throw exception(TENANT_BALANCE_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public TenantBalanceDO getTenantBalance(Long id) {
|
||||
return tenantBalanceMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<TenantBalanceDO> getTenantBalancePage(TenantBalancePageReqVO pageReqVO) {
|
||||
return tenantBalanceMapper.selectPage(pageReqVO);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
<?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="cn.iocoder.yudao.module.system.dal.mysql.tenantbalance.TenantBalanceMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user