feat(system): 新增租户积分管理功能

新增租户积分实体、Mapper、Service及Controller全套代码,并补充对应错误码TENANT_POINTS_NOT_EXISTS。
This commit is contained in:
2025-11-19 20:39:29 +08:00
parent 6e0f41e661
commit c75df4743d
10 changed files with 518 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
package cn.iocoder.yudao.module.system.controller.admin.tenantpoints;
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.tenantpoints.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.tenantpoints.TenantPointsDO;
import cn.iocoder.yudao.module.system.service.tenantpoints.TenantPointsService;
@Tag(name = "管理后台 - 租户积分记录")
@RestController
@RequestMapping("/system/tenant-points")
@Validated
public class TenantPointsController {
@Resource
private TenantPointsService tenantPointsService;
@PostMapping("/create")
@Operation(summary = "创建租户积分记录")
@PreAuthorize("@ss.hasPermission('system:tenant-points:create')")
public CommonResult<Long> createTenantPoints(@Valid @RequestBody TenantPointsSaveReqVO createReqVO) {
return success(tenantPointsService.createTenantPoints(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新租户积分记录")
@PreAuthorize("@ss.hasPermission('system:tenant-points:update')")
public CommonResult<Boolean> updateTenantPoints(@Valid @RequestBody TenantPointsSaveReqVO updateReqVO) {
tenantPointsService.updateTenantPoints(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除租户积分记录")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('system:tenant-points:delete')")
public CommonResult<Boolean> deleteTenantPoints(@RequestParam("id") Long id) {
tenantPointsService.deleteTenantPoints(id);
return success(true);
}
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除租户积分记录")
@PreAuthorize("@ss.hasPermission('system:tenant-points:delete')")
public CommonResult<Boolean> deleteTenantPointsList(@RequestParam("ids") List<Long> ids) {
tenantPointsService.deleteTenantPointsListByIds(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得租户积分记录")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('system:tenant-points:query')")
public CommonResult<TenantPointsRespVO> getTenantPoints(@RequestParam("id") Long id) {
TenantPointsDO tenantPoints = tenantPointsService.getTenantPoints(id);
return success(BeanUtils.toBean(tenantPoints, TenantPointsRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得租户积分记录分页")
@PreAuthorize("@ss.hasPermission('system:tenant-points:query')")
public CommonResult<PageResult<TenantPointsRespVO>> getTenantPointsPage(@Valid TenantPointsPageReqVO pageReqVO) {
PageResult<TenantPointsDO> pageResult = tenantPointsService.getTenantPointsPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, TenantPointsRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出租户积分记录 Excel")
@PreAuthorize("@ss.hasPermission('system:tenant-points:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportTenantPointsExcel(@Valid TenantPointsPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<TenantPointsDO> list = tenantPointsService.getTenantPointsPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "租户积分记录.xls", "数据", TenantPointsRespVO.class,
BeanUtils.toBean(list, TenantPointsRespVO.class));
}
}

View File

@@ -0,0 +1,43 @@
package cn.iocoder.yudao.module.system.controller.admin.tenantpoints.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 TenantPointsPageReqVO extends PageParam {
@Schema(description = "本次变动点数,正加负减")
private Integer points;
@Schema(description = "变动后余额快照(冗余)")
private Integer balance;
@Schema(description = "变动类型,如 RECHARGE, CONSUME, TRANSFER_OUT, TRANSFER_IN", example = "1")
private String type;
@Schema(description = "变动描述", example = "随便")
private String description;
@Schema(description = "订单 Id/业务单号", example = "84")
private Long orderId;
@Schema(description = "业务流水号(转账、订单等唯一标识)")
private String bizNo;
@Schema(description = "操作人 Id", example = "8171")
private Long operatorId;
@Schema(description = "目标租户 Id转账使用", example = "18731")
private Long targetTenantId;
@Schema(description = "创建时间")
private LocalDateTime createdAt;
}

View File

@@ -0,0 +1,55 @@
package cn.iocoder.yudao.module.system.controller.admin.tenantpoints.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 TenantPointsRespVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "16587")
@ExcelProperty("主键")
private Long id;
@Schema(description = "本次变动点数,正加负减", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("本次变动点数,正加负减")
private Integer points;
@Schema(description = "变动后余额快照(冗余)")
@ExcelProperty("变动后余额快照(冗余)")
private Integer balance;
@Schema(description = "变动类型,如 RECHARGE, CONSUME, TRANSFER_OUT, TRANSFER_IN", example = "1")
@ExcelProperty("变动类型,如 RECHARGE, CONSUME, TRANSFER_OUT, TRANSFER_IN")
private String type;
@Schema(description = "变动描述", example = "随便")
@ExcelProperty("变动描述")
private String description;
@Schema(description = "订单 Id/业务单号", example = "84")
@ExcelProperty("订单 Id/业务单号")
private Long orderId;
@Schema(description = "业务流水号(转账、订单等唯一标识)")
@ExcelProperty("业务流水号(转账、订单等唯一标识)")
private String bizNo;
@Schema(description = "操作人 Id", example = "8171")
@ExcelProperty("操作人 Id")
private Long operatorId;
@Schema(description = "目标租户 Id转账使用", example = "18731")
@ExcelProperty("目标租户 Id转账使用")
private Long targetTenantId;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createdAt;
}

View File

@@ -0,0 +1,46 @@
package cn.iocoder.yudao.module.system.controller.admin.tenantpoints.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 TenantPointsSaveReqVO {
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "16587")
private Long id;
@Schema(description = "本次变动点数,正加负减", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "本次变动点数,正加负减不能为空")
private Integer points;
@Schema(description = "变动后余额快照(冗余)")
private Integer balance;
@Schema(description = "变动类型,如 RECHARGE, CONSUME, TRANSFER_OUT, TRANSFER_IN", example = "1")
private String type;
@Schema(description = "变动描述", example = "随便")
private String description;
@Schema(description = "订单 Id/业务单号", example = "84")
private Long orderId;
@Schema(description = "业务流水号(转账、订单等唯一标识)")
private String bizNo;
@Schema(description = "操作人 Id", example = "8171")
private Long operatorId;
@Schema(description = "目标租户 Id转账使用", example = "18731")
private Long targetTenantId;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@NotNull(message = "创建时间不能为空")
private LocalDateTime createdAt;
}

View File

@@ -0,0 +1,67 @@
package cn.iocoder.yudao.module.system.dal.dataobject.tenantpoints;
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_points")
@KeySequence("system_tenant_points_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TenantPointsDO extends BaseDO {
/**
* 主键
*/
@TableId
private Long id;
/**
* 本次变动点数,正加负减
*/
private Integer points;
/**
* 变动后余额快照(冗余)
*/
private Integer balance;
/**
* 变动类型,如 RECHARGE, CONSUME, TRANSFER_OUT, TRANSFER_IN
*/
private String type;
/**
* 变动描述
*/
private String description;
/**
* 订单 Id/业务单号
*/
private Long orderId;
/**
* 业务流水号(转账、订单等唯一标识)
*/
private String bizNo;
/**
* 操作人 Id
*/
private Long operatorId;
/**
* 目标租户 Id转账使用
*/
private Long targetTenantId;
/**
* 创建时间
*/
private LocalDateTime createdAt;
}

View File

@@ -0,0 +1,34 @@
package cn.iocoder.yudao.module.system.dal.mysql.tenantpoints;
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.tenantpoints.TenantPointsDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.system.controller.admin.tenantpoints.vo.*;
/**
* 租户积分记录 Mapper
*
* @author 总后台
*/
@Mapper
public interface TenantPointsMapper extends BaseMapperX<TenantPointsDO> {
default PageResult<TenantPointsDO> selectPage(TenantPointsPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<TenantPointsDO>()
.eqIfPresent(TenantPointsDO::getPoints, reqVO.getPoints())
.eqIfPresent(TenantPointsDO::getBalance, reqVO.getBalance())
.eqIfPresent(TenantPointsDO::getType, reqVO.getType())
.eqIfPresent(TenantPointsDO::getDescription, reqVO.getDescription())
.eqIfPresent(TenantPointsDO::getOrderId, reqVO.getOrderId())
.eqIfPresent(TenantPointsDO::getBizNo, reqVO.getBizNo())
.eqIfPresent(TenantPointsDO::getOperatorId, reqVO.getOperatorId())
.eqIfPresent(TenantPointsDO::getTargetTenantId, reqVO.getTargetTenantId())
.eqIfPresent(TenantPointsDO::getCreatedAt, reqVO.getCreatedAt())
.orderByDesc(TenantPointsDO::getId));
}
}

View File

@@ -116,6 +116,9 @@ public interface ErrorCodeConstants {
ErrorCode TENANT_PACKAGE_DISABLE = new ErrorCode(1_002_016_002, "名字为【{}】的租户套餐已被禁用");
ErrorCode TENANT_PACKAGE_NAME_DUPLICATE = new ErrorCode(1_002_016_003, "已经存在该名字的租户套餐");
// ========== 租户套餐 1-002-017-000 ==========
ErrorCode TENANT_POINTS_NOT_EXISTS = new ErrorCode(1_002_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, "社交授权失败,找不到对应的用户");

View File

@@ -0,0 +1,62 @@
package cn.iocoder.yudao.module.system.service.tenantpoints;
import java.util.*;
import javax.validation.*;
import cn.iocoder.yudao.module.system.controller.admin.tenantpoints.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.tenantpoints.TenantPointsDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
/**
* 租户积分记录 Service 接口
*
* @author 总后台
*/
public interface TenantPointsService {
/**
* 创建租户积分记录
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createTenantPoints(@Valid TenantPointsSaveReqVO createReqVO);
/**
* 更新租户积分记录
*
* @param updateReqVO 更新信息
*/
void updateTenantPoints(@Valid TenantPointsSaveReqVO updateReqVO);
/**
* 删除租户积分记录
*
* @param id 编号
*/
void deleteTenantPoints(Long id);
/**
* 批量删除租户积分记录
*
* @param ids 编号
*/
void deleteTenantPointsListByIds(List<Long> ids);
/**
* 获得租户积分记录
*
* @param id 编号
* @return 租户积分记录
*/
TenantPointsDO getTenantPoints(Long id);
/**
* 获得租户积分记录分页
*
* @param pageReqVO 分页查询
* @return 租户积分记录分页
*/
PageResult<TenantPointsDO> getTenantPointsPage(TenantPointsPageReqVO pageReqVO);
}

View File

@@ -0,0 +1,92 @@
package cn.iocoder.yudao.module.system.service.tenantpoints;
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.tenantpoints.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.tenantpoints.TenantPointsDO;
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.tenantpoints.TenantPointsMapper;
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 TenantPointsServiceImpl implements TenantPointsService {
@Resource
private TenantPointsMapper tenantPointsMapper;
@Override
public Long createTenantPoints(TenantPointsSaveReqVO createReqVO) {
// 插入
TenantPointsDO tenantPoints = BeanUtils.toBean(createReqVO, TenantPointsDO.class);
tenantPointsMapper.insert(tenantPoints);
// 返回
return tenantPoints.getId();
}
@Override
public void updateTenantPoints(TenantPointsSaveReqVO updateReqVO) {
// 校验存在
validateTenantPointsExists(updateReqVO.getId());
// 更新
TenantPointsDO updateObj = BeanUtils.toBean(updateReqVO, TenantPointsDO.class);
tenantPointsMapper.updateById(updateObj);
}
@Override
public void deleteTenantPoints(Long id) {
// 校验存在
validateTenantPointsExists(id);
// 删除
tenantPointsMapper.deleteById(id);
}
@Override
public void deleteTenantPointsListByIds(List<Long> ids) {
// 校验存在
validateTenantPointsExists(ids);
// 删除
tenantPointsMapper.deleteByIds(ids);
}
private void validateTenantPointsExists(List<Long> ids) {
List<TenantPointsDO> list = tenantPointsMapper.selectByIds(ids);
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
throw exception(TENANT_POINTS_NOT_EXISTS);
}
}
private void validateTenantPointsExists(Long id) {
if (tenantPointsMapper.selectById(id) == null) {
throw exception(TENANT_POINTS_NOT_EXISTS);
}
}
@Override
public TenantPointsDO getTenantPoints(Long id) {
return tenantPointsMapper.selectById(id);
}
@Override
public PageResult<TenantPointsDO> getTenantPointsPage(TenantPointsPageReqVO pageReqVO) {
return tenantPointsMapper.selectPage(pageReqVO);
}
}

View File

@@ -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.tenantpoints.TenantPointsMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>