feat(user-character): 新增用户人设管理功能模块
This commit is contained in:
@@ -0,0 +1,104 @@
|
||||
package com.yolo.keyboard.controller.admin.usercharacter;
|
||||
|
||||
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.usercharacter.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.usercharacter.KeyboardUserCharacterDO;
|
||||
import com.yolo.keyboard.service.usercharacter.KeyboardUserCharacterService;
|
||||
|
||||
@Tag(name = "管理后台 - 用户人设管理")
|
||||
@RestController
|
||||
@RequestMapping("/keyboard/user-character")
|
||||
@Validated
|
||||
public class KeyboardUserCharacterController {
|
||||
|
||||
@Resource
|
||||
private KeyboardUserCharacterService userCharacterService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建用户人设管理")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-character:create')")
|
||||
public CommonResult<Long> createUserCharacter(@Valid @RequestBody KeyboardUserCharacterSaveReqVO createReqVO) {
|
||||
return success(userCharacterService.createUserCharacter(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新用户人设管理")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-character:update')")
|
||||
public CommonResult<Boolean> updateUserCharacter(@Valid @RequestBody KeyboardUserCharacterSaveReqVO updateReqVO) {
|
||||
userCharacterService.updateUserCharacter(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除用户人设管理")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-character:delete')")
|
||||
public CommonResult<Boolean> deleteUserCharacter(@RequestParam("id") Long id) {
|
||||
userCharacterService.deleteUserCharacter(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除用户人设管理")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-character:delete')")
|
||||
public CommonResult<Boolean> deleteUserCharacterList(@RequestParam("ids") List<Long> ids) {
|
||||
userCharacterService.deleteUserCharacterListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得用户人设管理")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-character:query')")
|
||||
public CommonResult<KeyboardUserCharacterRespVO> getUserCharacter(@RequestParam("id") Long id) {
|
||||
KeyboardUserCharacterDO userCharacter = userCharacterService.getUserCharacter(id);
|
||||
return success(BeanUtils.toBean(userCharacter, KeyboardUserCharacterRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得用户人设管理分页")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-character:query')")
|
||||
public CommonResult<PageResult<KeyboardUserCharacterRespVO>> getUserCharacterPage(@Valid KeyboardUserCharacterPageReqVO pageReqVO) {
|
||||
PageResult<KeyboardUserCharacterDO> pageResult = userCharacterService.getUserCharacterPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, KeyboardUserCharacterRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出用户人设管理 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('keyboard:user-character:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportUserCharacterExcel(@Valid KeyboardUserCharacterPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<KeyboardUserCharacterDO> list = userCharacterService.getUserCharacterPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "用户人设管理.xls", "数据", KeyboardUserCharacterRespVO.class,
|
||||
BeanUtils.toBean(list, KeyboardUserCharacterRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
package com.yolo.keyboard.controller.admin.usercharacter.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 KeyboardUserCharacterPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "键盘人设 id", example = "7333")
|
||||
private Long characterId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "用户 Id", example = "31348")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "emoji 标签")
|
||||
private String emoji;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
package com.yolo.keyboard.controller.admin.usercharacter.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 KeyboardUserCharacterRespVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "32344")
|
||||
@ExcelProperty("主键 Id")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "键盘人设 id", example = "7333")
|
||||
@ExcelProperty("键盘人设 id")
|
||||
private Long characterId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
@ExcelProperty("创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
@ExcelProperty("更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "用户 Id", example = "31348")
|
||||
@ExcelProperty("用户 Id")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "emoji 标签")
|
||||
@ExcelProperty("emoji 标签")
|
||||
private String emoji;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.yolo.keyboard.controller.admin.usercharacter.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 KeyboardUserCharacterSaveReqVO {
|
||||
|
||||
@Schema(description = "主键 Id", requiredMode = Schema.RequiredMode.REQUIRED, example = "32344")
|
||||
private Long id;
|
||||
|
||||
@Schema(description = "键盘人设 id", example = "7333")
|
||||
private Long characterId;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createdAt;
|
||||
|
||||
@Schema(description = "更新时间")
|
||||
private LocalDateTime updatedAt;
|
||||
|
||||
@Schema(description = "用户 Id", example = "31348")
|
||||
private Long userId;
|
||||
|
||||
@Schema(description = "emoji 标签")
|
||||
private String emoji;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package com.yolo.keyboard.dal.dataobject.usercharacter;
|
||||
|
||||
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_user_character")
|
||||
@KeySequence("keyboard_user_character_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@TenantIgnore
|
||||
public class KeyboardUserCharacterDO{
|
||||
|
||||
/**
|
||||
* 主键 Id
|
||||
*/
|
||||
@TableId
|
||||
private Long id;
|
||||
/**
|
||||
* 键盘人设 id
|
||||
*/
|
||||
private Long characterId;
|
||||
/**
|
||||
* 创建时间
|
||||
*/
|
||||
private LocalDateTime createdAt;
|
||||
/**
|
||||
* 更新时间
|
||||
*/
|
||||
private LocalDateTime updatedAt;
|
||||
/**
|
||||
* 用户 Id
|
||||
*/
|
||||
private Long userId;
|
||||
/**
|
||||
* emoji 标签
|
||||
*/
|
||||
private String emoji;
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
package com.yolo.keyboard.dal.mysql.usercharacter;
|
||||
|
||||
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.usercharacter.KeyboardUserCharacterDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
import com.yolo.keyboard.controller.admin.usercharacter.vo.*;
|
||||
|
||||
/**
|
||||
* 用户人设管理 Mapper
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Mapper
|
||||
public interface KeyboardUserCharacterMapper extends BaseMapperX<KeyboardUserCharacterDO> {
|
||||
|
||||
default PageResult<KeyboardUserCharacterDO> selectPage(KeyboardUserCharacterPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<KeyboardUserCharacterDO>()
|
||||
.eqIfPresent(KeyboardUserCharacterDO::getCharacterId, reqVO.getCharacterId())
|
||||
.eqIfPresent(KeyboardUserCharacterDO::getCreatedAt, reqVO.getCreatedAt())
|
||||
.eqIfPresent(KeyboardUserCharacterDO::getUpdatedAt, reqVO.getUpdatedAt())
|
||||
.eqIfPresent(KeyboardUserCharacterDO::getUserId, reqVO.getUserId())
|
||||
.eqIfPresent(KeyboardUserCharacterDO::getEmoji, reqVO.getEmoji())
|
||||
.orderByDesc(KeyboardUserCharacterDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,62 @@
|
||||
package com.yolo.keyboard.service.usercharacter;
|
||||
|
||||
import java.util.*;
|
||||
import jakarta.validation.*;
|
||||
import com.yolo.keyboard.controller.admin.usercharacter.vo.*;
|
||||
import com.yolo.keyboard.dal.dataobject.usercharacter.KeyboardUserCharacterDO;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageParam;
|
||||
|
||||
/**
|
||||
* 用户人设管理 Service 接口
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
public interface KeyboardUserCharacterService {
|
||||
|
||||
/**
|
||||
* 创建用户人设管理
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Long createUserCharacter(@Valid KeyboardUserCharacterSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新用户人设管理
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateUserCharacter(@Valid KeyboardUserCharacterSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除用户人设管理
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteUserCharacter(Long id);
|
||||
|
||||
/**
|
||||
* 批量删除用户人设管理
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteUserCharacterListByIds(List<Long> ids);
|
||||
|
||||
/**
|
||||
* 获得用户人设管理
|
||||
*
|
||||
* @param id 编号
|
||||
* @return 用户人设管理
|
||||
*/
|
||||
KeyboardUserCharacterDO getUserCharacter(Long id);
|
||||
|
||||
/**
|
||||
* 获得用户人设管理分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return 用户人设管理分页
|
||||
*/
|
||||
PageResult<KeyboardUserCharacterDO> getUserCharacterPage(KeyboardUserCharacterPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
package com.yolo.keyboard.service.usercharacter;
|
||||
|
||||
import com.yolo.keyboard.controller.admin.usercharacter.vo.KeyboardUserCharacterPageReqVO;
|
||||
import com.yolo.keyboard.controller.admin.usercharacter.vo.KeyboardUserCharacterSaveReqVO;
|
||||
import com.yolo.keyboard.dal.dataobject.usercharacter.KeyboardUserCharacterDO;
|
||||
import com.yolo.keyboard.dal.mysql.usercharacter.KeyboardUserCharacterMapper;
|
||||
import com.yolo.keyboard.framework.common.pojo.PageResult;
|
||||
import com.yolo.keyboard.framework.common.util.object.BeanUtils;
|
||||
import jakarta.annotation.Resource;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static com.yolo.keyboard.framework.common.exception.util.ServiceExceptionUtil.exception;
|
||||
import static com.yolo.keyboard.module.infra.enums.ErrorCodeConstants.USER_CHARACTER_NOT_EXISTS;
|
||||
|
||||
/**
|
||||
* 用户人设管理 Service 实现类
|
||||
*
|
||||
* @author ziin
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class KeyboardUserCharacterServiceImpl implements KeyboardUserCharacterService {
|
||||
|
||||
@Resource
|
||||
private KeyboardUserCharacterMapper userCharacterMapper;
|
||||
|
||||
@Override
|
||||
public Long createUserCharacter(KeyboardUserCharacterSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
KeyboardUserCharacterDO userCharacter = BeanUtils.toBean(createReqVO, KeyboardUserCharacterDO.class);
|
||||
userCharacterMapper.insert(userCharacter);
|
||||
|
||||
// 返回
|
||||
return userCharacter.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateUserCharacter(KeyboardUserCharacterSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateUserCharacterExists(updateReqVO.getId());
|
||||
// 更新
|
||||
KeyboardUserCharacterDO updateObj = BeanUtils.toBean(updateReqVO, KeyboardUserCharacterDO.class);
|
||||
userCharacterMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserCharacter(Long id) {
|
||||
// 校验存在
|
||||
validateUserCharacterExists(id);
|
||||
// 删除
|
||||
userCharacterMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteUserCharacterListByIds(List<Long> ids) {
|
||||
// 删除
|
||||
userCharacterMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
|
||||
private void validateUserCharacterExists(Long id) {
|
||||
if (userCharacterMapper.selectById(id) == null) {
|
||||
throw exception(USER_CHARACTER_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public KeyboardUserCharacterDO getUserCharacter(Long id) {
|
||||
return userCharacterMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<KeyboardUserCharacterDO> getUserCharacterPage(KeyboardUserCharacterPageReqVO pageReqVO) {
|
||||
return userCharacterMapper.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.usercharacter.KeyboardUserCharacterMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user