feat(userthemes): 新增用户主题管理功能

新增用户主题完整CRUD模块,含控制器、DO、Mapper、Service及VO定义,并补充错误码。
This commit is contained in:
2025-12-25 13:46:02 +08:00
parent 6328a5531d
commit 6c7cc367b5
10 changed files with 446 additions and 0 deletions

View File

@@ -0,0 +1,104 @@
package com.yolo.keyboard.controller.admin.userthemes;
import org.springframework.web.bind.annotation.*;
import jakarta.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 jakarta.validation.constraints.*;
import jakarta.validation.*;
import jakarta.servlet.http.*;
import java.util.*;
import java.io.IOException;
import com.yolo.keyboard.framework.common.pojo.PageParam;
import com.yolo.keyboard.framework.common.pojo.PageResult;
import com.yolo.keyboard.framework.common.pojo.CommonResult;
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
import static com.yolo.keyboard.framework.common.pojo.CommonResult.success;
import com.yolo.keyboard.framework.excel.core.util.ExcelUtils;
import com.yolo.keyboard.framework.apilog.core.annotation.ApiAccessLog;
import static com.yolo.keyboard.framework.apilog.core.enums.OperateTypeEnum.*;
import com.yolo.keyboard.controller.admin.userthemes.vo.*;
import com.yolo.keyboard.dal.dataobject.userthemes.KeyboardUserThemesDO;
import com.yolo.keyboard.service.userthemes.KeyboardUserThemesService;
@Tag(name = "管理后台 - 用户主题")
@RestController
@RequestMapping("/keyboard/user-themes")
@Validated
public class KeyboardUserThemesController {
@Resource
private KeyboardUserThemesService userThemesService;
@PostMapping("/create")
@Operation(summary = "创建用户主题")
@PreAuthorize("@ss.hasPermission('keyboard:user-themes:create')")
public CommonResult<Long> createUserThemes(@Valid @RequestBody KeyboardUserThemesSaveReqVO createReqVO) {
return success(userThemesService.createUserThemes(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新用户主题")
@PreAuthorize("@ss.hasPermission('keyboard:user-themes:update')")
public CommonResult<Boolean> updateUserThemes(@Valid @RequestBody KeyboardUserThemesSaveReqVO updateReqVO) {
userThemesService.updateUserThemes(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除用户主题")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('keyboard:user-themes:delete')")
public CommonResult<Boolean> deleteUserThemes(@RequestParam("id") Long id) {
userThemesService.deleteUserThemes(id);
return success(true);
}
@DeleteMapping("/delete-list")
@Parameter(name = "ids", description = "编号", required = true)
@Operation(summary = "批量删除用户主题")
@PreAuthorize("@ss.hasPermission('keyboard:user-themes:delete')")
public CommonResult<Boolean> deleteUserThemesList(@RequestParam("ids") List<Long> ids) {
userThemesService.deleteUserThemesListByIds(ids);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得用户主题")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('keyboard:user-themes:query')")
public CommonResult<KeyboardUserThemesRespVO> getUserThemes(@RequestParam("id") Long id) {
KeyboardUserThemesDO userThemes = userThemesService.getUserThemes(id);
return success(BeanUtils.toBean(userThemes, KeyboardUserThemesRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得用户主题分页")
@PreAuthorize("@ss.hasPermission('keyboard:user-themes:query')")
public CommonResult<PageResult<KeyboardUserThemesRespVO>> getUserThemesPage(@Valid KeyboardUserThemesPageReqVO pageReqVO) {
PageResult<KeyboardUserThemesDO> pageResult = userThemesService.getUserThemesPage(pageReqVO);
return success(BeanUtils.toBean(pageResult, KeyboardUserThemesRespVO.class));
}
@GetMapping("/export-excel")
@Operation(summary = "导出用户主题 Excel")
@PreAuthorize("@ss.hasPermission('keyboard:user-themes:export')")
@ApiAccessLog(operateType = EXPORT)
public void exportUserThemesExcel(@Valid KeyboardUserThemesPageReqVO pageReqVO,
HttpServletResponse response) throws IOException {
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
List<KeyboardUserThemesDO> list = userThemesService.getUserThemesPage(pageReqVO).getList();
// 导出 Excel
ExcelUtils.write(response, "用户主题.xls", "数据", KeyboardUserThemesRespVO.class,
BeanUtils.toBean(list, KeyboardUserThemesRespVO.class));
}
}

View File

@@ -0,0 +1,31 @@
package com.yolo.keyboard.controller.admin.userthemes.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import com.yolo.keyboard.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static com.yolo.keyboard.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 用户主题分页 Request VO")
@Data
public class KeyboardUserThemesPageReqVO extends PageParam {
@Schema(description = "主题主键", example = "21647")
private Long themeId;
@Schema(description = "用户 Id", example = "9884")
private Long userId;
@Schema(description = "创建时间")
private LocalDateTime createdAt;
@Schema(description = "是否从显示移除")
private Boolean viewDeleted;
@Schema(description = "更新时间")
private Boolean updatedAt;
}

View File

@@ -0,0 +1,39 @@
package com.yolo.keyboard.controller.admin.userthemes.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 cn.idev.excel.annotation.*;
@Schema(description = "管理后台 - 用户主题 Response VO")
@Data
@ExcelIgnoreUnannotated
public class KeyboardUserThemesRespVO {
@Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "746")
@ExcelProperty("主键 id")
private Long id;
@Schema(description = "主题主键", example = "21647")
@ExcelProperty("主题主键")
private Long themeId;
@Schema(description = "用户 Id", example = "9884")
@ExcelProperty("用户 Id")
private Long userId;
@Schema(description = "创建时间")
@ExcelProperty("创建时间")
private LocalDateTime createdAt;
@Schema(description = "是否从显示移除")
@ExcelProperty("是否从显示移除")
private Boolean viewDeleted;
@Schema(description = "更新时间")
@ExcelProperty("更新时间")
private Boolean updatedAt;
}

View File

@@ -0,0 +1,32 @@
package com.yolo.keyboard.controller.admin.userthemes.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
import jakarta.validation.constraints.*;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
@Schema(description = "管理后台 - 用户主题新增/修改 Request VO")
@Data
public class KeyboardUserThemesSaveReqVO {
@Schema(description = "主键 id", requiredMode = Schema.RequiredMode.REQUIRED, example = "746")
private Long id;
@Schema(description = "主题主键", example = "21647")
private Long themeId;
@Schema(description = "用户 Id", example = "9884")
private Long userId;
@Schema(description = "创建时间")
private LocalDateTime createdAt;
@Schema(description = "是否从显示移除")
private Boolean viewDeleted;
@Schema(description = "更新时间")
private Boolean updatedAt;
}

View File

@@ -0,0 +1,52 @@
package com.yolo.keyboard.dal.dataobject.userthemes;
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
import lombok.*;
import java.util.*;
import java.time.LocalDateTime;
import com.baomidou.mybatisplus.annotation.*;
import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
/**
* 用户主题 DO
*
* @author 芋道源码
*/
@TableName("keyboard_user_themes")
@KeySequence("keyboard_user_themes_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
@Data
@ToString(callSuper = true)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@TenantIgnore
public class KeyboardUserThemesDO{
/**
* 主键 id
*/
@TableId
private Long id;
/**
* 主题主键
*/
private Long themeId;
/**
* 用户 Id
*/
private Long userId;
/**
* 创建时间
*/
private LocalDateTime createdAt;
/**
* 是否从显示移除
*/
private Boolean viewDeleted;
/**
* 更新时间
*/
private Boolean updatedAt;
}

View File

@@ -0,0 +1,30 @@
package com.yolo.keyboard.dal.mysql.userthemes;
import java.util.*;
import com.yolo.keyboard.framework.common.pojo.PageResult;
import com.yolo.keyboard.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.yolo.keyboard.framework.mybatis.core.mapper.BaseMapperX;
import com.yolo.keyboard.dal.dataobject.userthemes.KeyboardUserThemesDO;
import org.apache.ibatis.annotations.Mapper;
import com.yolo.keyboard.controller.admin.userthemes.vo.*;
/**
* 用户主题 Mapper
*
* @author 芋道源码
*/
@Mapper
public interface KeyboardUserThemesMapper extends BaseMapperX<KeyboardUserThemesDO> {
default PageResult<KeyboardUserThemesDO> selectPage(KeyboardUserThemesPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardUserThemesDO>()
.eqIfPresent(KeyboardUserThemesDO::getThemeId, reqVO.getThemeId())
.eqIfPresent(KeyboardUserThemesDO::getUserId, reqVO.getUserId())
.eqIfPresent(KeyboardUserThemesDO::getCreatedAt, reqVO.getCreatedAt())
.eqIfPresent(KeyboardUserThemesDO::getViewDeleted, reqVO.getViewDeleted())
.eqIfPresent(KeyboardUserThemesDO::getUpdatedAt, reqVO.getUpdatedAt())
.orderByDesc(KeyboardUserThemesDO::getId));
}
}

View File

@@ -0,0 +1,62 @@
package com.yolo.keyboard.service.userthemes;
import java.util.*;
import jakarta.validation.*;
import com.yolo.keyboard.controller.admin.userthemes.vo.*;
import com.yolo.keyboard.dal.dataobject.userthemes.KeyboardUserThemesDO;
import com.yolo.keyboard.framework.common.pojo.PageResult;
import com.yolo.keyboard.framework.common.pojo.PageParam;
/**
* 用户主题 Service 接口
*
* @author 芋道源码
*/
public interface KeyboardUserThemesService {
/**
* 创建用户主题
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createUserThemes(@Valid KeyboardUserThemesSaveReqVO createReqVO);
/**
* 更新用户主题
*
* @param updateReqVO 更新信息
*/
void updateUserThemes(@Valid KeyboardUserThemesSaveReqVO updateReqVO);
/**
* 删除用户主题
*
* @param id 编号
*/
void deleteUserThemes(Long id);
/**
* 批量删除用户主题
*
* @param ids 编号
*/
void deleteUserThemesListByIds(List<Long> ids);
/**
* 获得用户主题
*
* @param id 编号
* @return 用户主题
*/
KeyboardUserThemesDO getUserThemes(Long id);
/**
* 获得用户主题分页
*
* @param pageReqVO 分页查询
* @return 用户主题分页
*/
PageResult<KeyboardUserThemesDO> getUserThemesPage(KeyboardUserThemesPageReqVO pageReqVO);
}

View File

@@ -0,0 +1,83 @@
package com.yolo.keyboard.service.userthemes;
import cn.hutool.core.collection.CollUtil;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import java.util.*;
import com.yolo.keyboard.controller.admin.userthemes.vo.*;
import com.yolo.keyboard.dal.dataobject.userthemes.KeyboardUserThemesDO;
import com.yolo.keyboard.framework.common.pojo.PageResult;
import com.yolo.keyboard.framework.common.pojo.PageParam;
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
import com.yolo.keyboard.dal.mysql.userthemes.KeyboardUserThemesMapper;
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.USER_THEMES_NOT_EXISTS;
/**
* 用户主题 Service 实现类
*
* @author 芋道源码
*/
@Service
@Validated
public class KeyboardUserThemesServiceImpl implements KeyboardUserThemesService {
@Resource
private KeyboardUserThemesMapper userThemesMapper;
@Override
public Long createUserThemes(KeyboardUserThemesSaveReqVO createReqVO) {
// 插入
KeyboardUserThemesDO userThemes = BeanUtils.toBean(createReqVO, KeyboardUserThemesDO.class);
userThemesMapper.insert(userThemes);
// 返回
return userThemes.getId();
}
@Override
public void updateUserThemes(KeyboardUserThemesSaveReqVO updateReqVO) {
// 校验存在
validateUserThemesExists(updateReqVO.getId());
// 更新
KeyboardUserThemesDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardUserThemesDO.class);
userThemesMapper.updateById(updateObj);
}
@Override
public void deleteUserThemes(Long id) {
// 校验存在
validateUserThemesExists(id);
// 删除
userThemesMapper.deleteById(id);
}
@Override
public void deleteUserThemesListByIds(List<Long> ids) {
// 删除
userThemesMapper.deleteByIds(ids);
}
private void validateUserThemesExists(Long id) {
if (userThemesMapper.selectById(id) == null) {
throw exception(USER_THEMES_NOT_EXISTS);
}
}
@Override
public KeyboardUserThemesDO getUserThemes(Long id) {
return userThemesMapper.selectById(id);
}
@Override
public PageResult<KeyboardUserThemesDO> getUserThemesPage(KeyboardUserThemesPageReqVO pageReqVO) {
return userThemesMapper.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="com.yolo.keyboard.dal.mysql.userthemes.KeyboardUserThemesMapper">
<!--
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
文档可见https://www.iocoder.cn/MyBatis/x-plugins/
-->
</mapper>

View File

@@ -84,6 +84,7 @@ public interface ErrorCodeConstants {
ErrorCode TAG_NOT_EXISTS = new ErrorCode(1_001_202_010, "人设标签不存在");
ErrorCode USER_QUOTA_TOTAL_NOT_EXISTS = new ErrorCode(1_001_202_011, "用户免费功能永久总次数额度表(所有功能共用)不存在");
ErrorCode USER_CHARACTER_NOT_EXISTS = new ErrorCode(1_001_202_012, "用户人设管理不存在");
ErrorCode USER_THEMES_NOT_EXISTS = new ErrorCode(1_001_202_013, "用户主题不存在");
}