feat(character): 新增键盘人设管理功能
新增 Controller/Service/Mapper/VO/DO 全套模块,支持人设分页查询、保存及详情接口,并补充 CHARACTER_NOT_EXISTS 错误码。
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package com.yolo.keyboard.controller.admin.character;
|
||||
|
||||
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.character.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.character.KeyboardCharacterDO;
|
||||
import com.yolo.keyboard.service.character.KeyboardCharacterService;
|
||||
|
||||
@Tag(name = "管理后台 - 键盘人设")
|
||||
@RestController
|
||||
@RequestMapping("/keyboard/character")
|
||||
@Validated
|
||||
public class KeyboardCharacterController {
|
||||
|
||||
@Resource
|
||||
private KeyboardCharacterService characterService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建键盘人设")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:character:create')")
|
||||
public CommonResult<Long> createCharacter(@Valid @RequestBody KeyboardCharacterSaveReqVO createReqVO) {
|
||||
return success(characterService.createCharacter(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新键盘人设")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:character:update')")
|
||||
public CommonResult<Boolean> updateCharacter(@Valid @RequestBody KeyboardCharacterSaveReqVO updateReqVO) {
|
||||
characterService.updateCharacter(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除键盘人设")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:character:delete')")
|
||||
public CommonResult<Boolean> deleteCharacter(@RequestParam("id") Long id) {
|
||||
characterService.deleteCharacter(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除键盘人设")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:character:delete')")
|
||||
public CommonResult<Boolean> deleteCharacterList(@RequestParam("ids") List<Long> ids) {
|
||||
characterService.deleteCharacterListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得键盘人设")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:character:query')")
|
||||
public CommonResult<KeyboardCharacterRespVO> getCharacter(@RequestParam("id") Long id) {
|
||||
KeyboardCharacterDO character = characterService.getCharacter(id);
|
||||
return success(BeanUtils.toBean(character, KeyboardCharacterRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得键盘人设分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:character:query')")
|
||||
public CommonResult<PageResult<KeyboardCharacterRespVO>> getCharacterPage(@Valid KeyboardCharacterPageReqVO pageReqVO) {
|
||||
PageResult<KeyboardCharacterDO> pageResult = characterService.getCharacterPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardCharacterRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出键盘人设 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:character:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportCharacterExcel(@Valid KeyboardCharacterPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardCharacterDO> list = characterService.getCharacterPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "键盘人设.xls", "数据", KeyboardCharacterRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardCharacterRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package com.yolo.keyboard.controller.admin.character.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 KeyboardCharacterPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "标题", example = "王五")
|
||||
private String characterName;
|
||||
|
||||
@Schema(description = "背景描述")
|
||||
private String characterBackground;
|
||||
|
||||
@Schema(description = "角色头像", example = "https://www.iocoder.cn")
|
||||
private String avatarUrl;
|
||||
|
||||
@Schema(description = "下载次数")
|
||||
private String download;
|
||||
|
||||
@Schema(description = "标签id")
|
||||
private Long tag;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "人设提示词")
|
||||
private String prompt;
|
||||
|
||||
@Schema(description = "排名顺序")
|
||||
private Integer rank;
|
||||
|
||||
@Schema(description = "emoji 标签")
|
||||
private String emoji;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.yolo.keyboard.controller.admin.character.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 KeyboardCharacterRespVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "7592")
|
||||
@ExcelProperty("主键 Id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标题", example = "王五")
|
||||
@ExcelProperty("标题")
|
||||
private String characterName;
|
||||
|
||||
@Schema(description = "背景描述")
|
||||
@ExcelProperty("背景描述")
|
||||
private String characterBackground;
|
||||
|
||||
@Schema(description = "角色头像", example = "https://www.iocoder.cn")
|
||||
@ExcelProperty("角色头像")
|
||||
private String avatarUrl;
|
||||
|
||||
@Schema(description = "下载次数")
|
||||
@ExcelProperty("下载次数")
|
||||
private String download;
|
||||
|
||||
@Schema(description = "标签id")
|
||||
@ExcelProperty("标签id")
|
||||
private Long tag;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "人设提示词")
|
||||
@ExcelProperty("人设提示词")
|
||||
private String prompt;
|
||||
|
||||
@Schema(description = "排名顺序")
|
||||
@ExcelProperty("排名顺序")
|
||||
private Integer rank;
|
||||
|
||||
@Schema(description = "emoji 标签")
|
||||
@ExcelProperty("emoji 标签")
|
||||
private String emoji;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package com.yolo.keyboard.controller.admin.character.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 KeyboardCharacterSaveReqVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "7592")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "标题", example = "王五")
|
||||
private String characterName;
|
||||
|
||||
@Schema(description = "背景描述")
|
||||
private String characterBackground;
|
||||
|
||||
@Schema(description = "角色头像", example = "https://www.iocoder.cn")
|
||||
private String avatarUrl;
|
||||
|
||||
@Schema(description = "下载次数")
|
||||
private String download;
|
||||
|
||||
@Schema(description = "标签id")
|
||||
private Long tag;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "人设提示词")
|
||||
private String prompt;
|
||||
|
||||
@Schema(description = "排名顺序")
|
||||
private Integer rank;
|
||||
|
||||
@Schema(description = "emoji 标签")
|
||||
private String emoji;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
package com.yolo.keyboard.dal.dataobject.character;
|
||||
|
||||
import com.yolo.keyboard.framework.tenant.core.aop.TenantIgnore;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.LocalDateTime;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import com.yolo.keyboard.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* 键盘人设 DO
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@TableName("keyboard_character")
|
||||
@KeySequence("keyboard_character_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
public class KeyboardCharacterDO {
|
||||
|
||||
/**
|
||||
* 主键 Id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 标题
|
||||
*/
|
||||
private String characterName;
|
||||
/**
|
||||
* 背景描述
|
||||
*/
|
||||
private String characterBackground;
|
||||
/**
|
||||
* 角色头像
|
||||
*/
|
||||
private String avatarUrl;
|
||||
/**
|
||||
* 下载次数
|
||||
*/
|
||||
private String download;
|
||||
/**
|
||||
* 标签id
|
||||
*/
|
||||
private Long tag;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
/**
|
||||
* 人设提示词
|
||||
*/
|
||||
private String prompt;
|
||||
/**
|
||||
* 排名顺序
|
||||
*/
|
||||
private Integer rank;
|
||||
/**
|
||||
* emoji 标签
|
||||
*/
|
||||
private String emoji;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.yolo.keyboard.dal.mysql.character;
|
||||
|
||||
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.character.KeyboardCharacterDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.yolo.keyboard.controller.admin.character.vo.*;
|
||||
|
||||
/**
|
||||
* 键盘人设 Mapper
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeyboardCharacterMapper extends BaseMapperX<KeyboardCharacterDO> {
|
||||
|
||||
default PageResult<KeyboardCharacterDO> selectPage(KeyboardCharacterPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardCharacterDO>()
|
||||
.likeIfPresent(KeyboardCharacterDO::getCharacterName, reqVO.getCharacterName())
|
||||
.eqIfPresent(KeyboardCharacterDO::getCharacterBackground, reqVO.getCharacterBackground())
|
||||
.eqIfPresent(KeyboardCharacterDO::getAvatarUrl, reqVO.getAvatarUrl())
|
||||
.eqIfPresent(KeyboardCharacterDO::getDownload, reqVO.getDownload())
|
||||
.eqIfPresent(KeyboardCharacterDO::getTag, reqVO.getTag())
|
||||
.eqIfPresent(KeyboardCharacterDO::getCreatedAt, reqVO.getCreatedAt())
|
||||
.eqIfPresent(KeyboardCharacterDO::getUpdatedAt, reqVO.getUpdatedAt())
|
||||
.eqIfPresent(KeyboardCharacterDO::getPrompt, reqVO.getPrompt())
|
||||
.eqIfPresent(KeyboardCharacterDO::getRank, reqVO.getRank())
|
||||
.eqIfPresent(KeyboardCharacterDO::getEmoji, reqVO.getEmoji())
|
||||
.orderByDesc(KeyboardCharacterDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,61 @@
|
||||
package com.yolo.keyboard.service.character;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.yolo.keyboard.controller.admin.character.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.character.KeyboardCharacterDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
|
||||
/**
|
||||
* 键盘人设 Service 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface KeyboardCharacterService {
|
||||
|
||||
/**
|
||||
* 创建键盘人设
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createCharacter(@Valid KeyboardCharacterSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新键盘人设
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateCharacter(@Valid KeyboardCharacterSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除键盘人设
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteCharacter(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除键盘人设
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteCharacterListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得键盘人设
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 键盘人设
|
||||
*/
|
||||
KeyboardCharacterDO getCharacter(Long id);
|
||||
|
||||
/**
|
||||
* 获得键盘人设分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 键盘人设分页
|
||||
*/
|
||||
PageResult<KeyboardCharacterDO> getCharacterPage(KeyboardCharacterPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,81 @@
|
||||
package com.yolo.keyboard.service.character;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.*;
|
||||
import com.yolo.keyboard.controller.admin.character.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.character.KeyboardCharacterDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
|
||||
import com.yolo.keyboard.dal.mysql.character.KeyboardCharacterMapper;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.CHARACTER_NOT_EXISTS;
|
||||
|
||||
|
||||
/**
|
||||
* 键盘人设 Service 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class KeyboardCharacterServiceImpl implements KeyboardCharacterService {
|
||||
|
||||
@Resource
|
||||
private KeyboardCharacterMapper characterMapper;
|
||||
|
||||
@Override
|
||||
public Long createCharacter(KeyboardCharacterSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
KeyboardCharacterDO character = BeanUtils.toBean(createReqVO, KeyboardCharacterDO.class);
|
||||
characterMapper.insert(character);
|
||||
|
||||
// 返回
|
||||
return character.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateCharacter(KeyboardCharacterSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCharacterExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardCharacterDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardCharacterDO.class);
|
||||
characterMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCharacter(Long id) {
|
||||
// 校验存在
|
||||
validateCharacterExists(id);
|
||||
// 删除
|
||||
characterMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCharacterListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
characterMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateCharacterExists(Long id) {
|
||||
if (characterMapper.selectById(id) == null) {
|
||||
throw exception(CHARACTER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardCharacterDO getCharacter(Long id) {
|
||||
return characterMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardCharacterDO> getCharacterPage(KeyboardCharacterPageReqVO pageReqVO) {
|
||||
return characterMapper.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="com.yolo.keyboard.dal.mysql.character.KeyboardCharacterMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user