feat(tag): 新增人设标签管理功能(含增删改查接口)
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package com.yolo.keyboard.controller.admin.tag;
|
||||
|
||||
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.tag.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.tag.KeyboardTagDO;
|
||||
import com.yolo.keyboard.service.tag.KeyboardTagService;
|
||||
|
||||
@Tag(name = "管理后台 - 人设标签")
|
||||
@RestController
|
||||
@RequestMapping("/keyboard/tag")
|
||||
@Validated
|
||||
public class KeyboardTagController {
|
||||
|
||||
@Resource
|
||||
private KeyboardTagService tagService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建人设标签")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tag:create')")
|
||||
public CommonResult<Integer> createTag(@Valid @RequestBody KeyboardTagSaveReqVO createReqVO) {
|
||||
return success(tagService.createTag(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新人设标签")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tag:update')")
|
||||
public CommonResult<Boolean> updateTag(@Valid @RequestBody KeyboardTagSaveReqVO updateReqVO) {
|
||||
tagService.updateTag(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除人设标签")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tag:delete')")
|
||||
public CommonResult<Boolean> deleteTag(@RequestParam("id") Integer id) {
|
||||
tagService.deleteTag(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除人设标签")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tag:delete')")
|
||||
public CommonResult<Boolean> deleteTagList(@RequestParam("ids") List<Integer> ids) {
|
||||
tagService.deleteTagListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得人设标签")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tag:query')")
|
||||
public CommonResult<KeyboardTagRespVO> getTag(@RequestParam("id") Integer id) {
|
||||
KeyboardTagDO tag = tagService.getTag(id);
|
||||
return success(BeanUtils.toBean(tag, KeyboardTagRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得人设标签分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tag:query')")
|
||||
public CommonResult<PageResult<KeyboardTagRespVO>> getTagPage(@Valid KeyboardTagPageReqVO pageReqVO) {
|
||||
PageResult<KeyboardTagDO> pageResult = tagService.getTagPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardTagRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出人设标签 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:tag:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportTagExcel(@Valid KeyboardTagPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardTagDO> list = tagService.getTagPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "人设标签.xls", "数据", KeyboardTagRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardTagRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package com.yolo.keyboard.controller.admin.tag.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 KeyboardTagPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "标签名", example = "王五")
|
||||
private String tagName;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yolo.keyboard.controller.admin.tag.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 KeyboardTagRespVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20413")
|
||||
@ExcelProperty("主键 Id")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "标签名", example = "王五")
|
||||
@ExcelProperty("标签名")
|
||||
private String tagName;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package com.yolo.keyboard.controller.admin.tag.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 KeyboardTagSaveReqVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "20413")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "标签名", example = "王五")
|
||||
private String tagName;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.yolo.keyboard.dal.dataobject.tag;
|
||||
|
||||
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_tag")
|
||||
@KeySequence("keyboard_tag_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
public class KeyboardTagDO{
|
||||
|
||||
/**
|
||||
* 主键 Id
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 标签名
|
||||
*/
|
||||
private String tagName;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package com.yolo.keyboard.dal.mysql.tag;
|
||||
|
||||
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.tag.KeyboardTagDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.yolo.keyboard.controller.admin.tag.vo.*;
|
||||
|
||||
/**
|
||||
* 人设标签 Mapper
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeyboardTagMapper extends BaseMapperX<KeyboardTagDO> {
|
||||
|
||||
default PageResult<KeyboardTagDO> selectPage(KeyboardTagPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardTagDO>()
|
||||
.likeIfPresent(KeyboardTagDO::getTagName, reqVO.getTagName())
|
||||
.eqIfPresent(KeyboardTagDO::getCreatedAt, reqVO.getCreatedAt())
|
||||
.eqIfPresent(KeyboardTagDO::getUpdatedAt, reqVO.getUpdatedAt())
|
||||
.orderByDesc(KeyboardTagDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.yolo.keyboard.service.tag;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.yolo.keyboard.controller.admin.tag.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.tag.KeyboardTagDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 人设标签 Service 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface KeyboardTagService {
|
||||
|
||||
/**
|
||||
* 创建人设标签
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createTag(@Valid KeyboardTagSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新人设标签
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateTag(@Valid KeyboardTagSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除人设标签
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteTag(Integer id);
|
||||
|
||||
/**
|
||||
* 批量删除人设标签
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteTagListByIds(List<Integer> ids);
|
||||
|
||||
/**
|
||||
* 获得人设标签
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 人设标签
|
||||
*/
|
||||
KeyboardTagDO getTag(Integer id);
|
||||
|
||||
/**
|
||||
* 获得人设标签分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 人设标签分页
|
||||
*/
|
||||
PageResult<KeyboardTagDO> getTagPage(KeyboardTagPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package com.yolo.keyboard.service.tag;
|
||||
|
||||
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.tag.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.tag.KeyboardTagDO;
|
||||
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.tag.KeyboardTagMapper;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.convertList;
|
||||
import static com.yolo.keyboard.framework.common.util.collection.CollectionUtils.diffList;
|
||||
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.TAG_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 人设标签 Service 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class KeyboardTagServiceImpl implements KeyboardTagService {
|
||||
|
||||
@Resource
|
||||
private KeyboardTagMapper tagMapper;
|
||||
|
||||
@Override
|
||||
public Integer createTag(KeyboardTagSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
KeyboardTagDO tag = BeanUtils.toBean(createReqVO, KeyboardTagDO.class);
|
||||
tagMapper.insert(tag);
|
||||
|
||||
// 返回
|
||||
return tag.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTag(KeyboardTagSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateTagExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardTagDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardTagDO.class);
|
||||
tagMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTag(Integer id) {
|
||||
// 校验存在
|
||||
validateTagExists(id);
|
||||
// 删除
|
||||
tagMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteTagListByIds(List<Integer> ids) {
|
||||
// 删除
|
||||
tagMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateTagExists(Integer id) {
|
||||
if (tagMapper.selectById(id) == null) {
|
||||
throw exception(TAG_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardTagDO getTag(Integer id) {
|
||||
return tagMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardTagDO> getTagPage(KeyboardTagPageReqVO pageReqVO) {
|
||||
return tagMapper.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.tag.KeyboardTagMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
@@ -81,4 +81,6 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode PRODUCT_ITEMS_NOT_EXISTS = new ErrorCode(1_001_202_007, "内购商品不存在");
|
||||
ErrorCode USER_CALL_LOG_NOT_EXISTS = new ErrorCode(1_001_202_008, "用户每次调用日志(用于记录token、模型、耗时、成功率等)不存在");
|
||||
ErrorCode I18N_MESSAGE_NOT_EXISTS = new ErrorCode(1_001_202_009, "国际化错误提醒配置不存在");
|
||||
ErrorCode TAG_NOT_EXISTS = new ErrorCode(1_001_202_010, "人设标签不存在");
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user