From f00e250be93e3f9180327bce7cdf97fb56416852 Mon Sep 17 00:00:00 2001 From: ziin Date: Wed, 19 Nov 2025 21:04:06 +0800 Subject: [PATCH] =?UTF-8?q?feat(tenant-balance):=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E7=A7=9F=E6=88=B7=E4=BD=99=E9=A2=9D=E7=AE=A1=E7=90=86=E5=8A=9F?= =?UTF-8?q?=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 新增租户余额实体、Mapper、Service、Controller 及对应 VO,支持余额分页查询、保存与错误码定义。 --- .../TenantBalanceController.java | 104 ++++++++++++++++++ .../vo/TenantBalancePageReqVO.java | 25 +++++ .../tenantbalance/vo/TenantBalanceRespVO.java | 27 +++++ .../vo/TenantBalanceSaveReqVO.java | 29 +++++ .../tenantbalance/TenantBalanceDO.java | 39 +++++++ .../tenantbalance/TenantBalanceMapper.java | 28 +++++ .../system/enums/ErrorCodeConstants.java | 4 + .../tenantbalance/TenantBalanceService.java | 62 +++++++++++ .../TenantBalanceServiceImpl.java | 92 ++++++++++++++++ .../resources/mapper/TenantBalanceMapper.xml | 12 ++ 10 files changed, 422 insertions(+) create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/TenantBalanceController.java create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalancePageReqVO.java create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceRespVO.java create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceSaveReqVO.java create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenantbalance/TenantBalanceDO.java create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenantbalance/TenantBalanceMapper.java create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceService.java create mode 100644 yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceServiceImpl.java create mode 100644 yudao-module-system/src/main/resources/mapper/TenantBalanceMapper.xml diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/TenantBalanceController.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/TenantBalanceController.java new file mode 100644 index 0000000..a4d8c8a --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/TenantBalanceController.java @@ -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 createTenantBalance(@Valid @RequestBody TenantBalanceSaveReqVO createReqVO) { + return success(tenantBalanceService.createTenantBalance(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新租户余额") + @PreAuthorize("@ss.hasPermission('system:tenant-balance:update')") + public CommonResult 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 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 deleteTenantBalanceList(@RequestParam("ids") List 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 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> getTenantBalancePage(@Valid TenantBalancePageReqVO pageReqVO) { + PageResult 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 list = tenantBalanceService.getTenantBalancePage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "租户余额.xls", "数据", TenantBalanceRespVO.class, + BeanUtils.toBean(list, TenantBalanceRespVO.class)); + } + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalancePageReqVO.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalancePageReqVO.java new file mode 100644 index 0000000..4dff99d --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalancePageReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceRespVO.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceRespVO.java new file mode 100644 index 0000000..6458986 --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceRespVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceSaveReqVO.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceSaveReqVO.java new file mode 100644 index 0000000..29ba2f5 --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/controller/admin/tenantbalance/vo/TenantBalanceSaveReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenantbalance/TenantBalanceDO.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenantbalance/TenantBalanceDO.java new file mode 100644 index 0000000..5f85cff --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/dataobject/tenantbalance/TenantBalanceDO.java @@ -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; + + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenantbalance/TenantBalanceMapper.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenantbalance/TenantBalanceMapper.java new file mode 100644 index 0000000..8cfcfa2 --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/dal/mysql/tenantbalance/TenantBalanceMapper.java @@ -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 { + + default PageResult selectPage(TenantBalancePageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(TenantBalanceDO::getBalance, reqVO.getBalance()) + .eqIfPresent(TenantBalanceDO::getVersion, reqVO.getVersion()) + .eqIfPresent(TenantBalanceDO::getUpdatedAt, reqVO.getUpdatedAt()) + .orderByDesc(TenantBalanceDO::getId)); + } + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java index cc9bb84..e430946 100644 --- a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/enums/ErrorCodeConstants.java @@ -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, "社交授权失败,找不到对应的用户"); diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceService.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceService.java new file mode 100644 index 0000000..581682a --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceService.java @@ -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 ids); + + /** + * 获得租户余额 + * + * @param id 编号 + * @return 租户余额 + */ + TenantBalanceDO getTenantBalance(Long id); + + /** + * 获得租户余额分页 + * + * @param pageReqVO 分页查询 + * @return 租户余额分页 + */ + PageResult getTenantBalancePage(TenantBalancePageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceServiceImpl.java b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceServiceImpl.java new file mode 100644 index 0000000..7f4958b --- /dev/null +++ b/yudao-module-system/src/main/java/cn/iocoder/yudao/module/system/service/tenantbalance/TenantBalanceServiceImpl.java @@ -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 ids) { + // 校验存在 + validateTenantBalanceExists(ids); + // 删除 + tenantBalanceMapper.deleteByIds(ids); + } + + private void validateTenantBalanceExists(List ids) { + List 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 getTenantBalancePage(TenantBalancePageReqVO pageReqVO) { + return tenantBalanceMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/yudao-module-system/src/main/resources/mapper/TenantBalanceMapper.xml b/yudao-module-system/src/main/resources/mapper/TenantBalanceMapper.xml new file mode 100644 index 0000000..fca190a --- /dev/null +++ b/yudao-module-system/src/main/resources/mapper/TenantBalanceMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file