1.添加 ai 评论配置
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
package cn.iocoder.yudao.module.tkdata.controller.admin.configController;
|
||||
|
||||
import cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo.CommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo.CommentRespVO;
|
||||
import cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo.CommentSaveReqVO;
|
||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.comment.CommentDO;
|
||||
import cn.iocoder.yudao.module.tkdata.service.comment.CommentService;
|
||||
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.*;
|
||||
|
||||
|
||||
|
||||
@Tag(name = "管理后台 - AI 评论内容")
|
||||
@RestController
|
||||
@RequestMapping("/server/comment")
|
||||
@Validated
|
||||
public class CommentController {
|
||||
|
||||
@Resource
|
||||
private CommentService commentService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@Operation(summary = "创建AI 评论内容")
|
||||
@PreAuthorize("@ss.hasPermission('server:comment:create')")
|
||||
public CommonResult<Integer> createComment(@Valid @RequestBody CommentSaveReqVO createReqVO) {
|
||||
return success(commentService.createComment(createReqVO));
|
||||
}
|
||||
|
||||
@PutMapping("/update")
|
||||
@Operation(summary = "更新AI 评论内容")
|
||||
@PreAuthorize("@ss.hasPermission('server:comment:update')")
|
||||
public CommonResult<Boolean> updateComment(@Valid @RequestBody CommentSaveReqVO updateReqVO) {
|
||||
commentService.updateComment(updateReqVO);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete")
|
||||
@Operation(summary = "删除AI 评论内容")
|
||||
@Parameter(name = "id", description = "编号", required = true)
|
||||
@PreAuthorize("@ss.hasPermission('server:comment:delete')")
|
||||
public CommonResult<Boolean> deleteComment(@RequestParam("id") Integer id) {
|
||||
commentService.deleteComment(id);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@DeleteMapping("/delete-list")
|
||||
@Parameter(name = "ids", description = "编号", required = true)
|
||||
@Operation(summary = "批量删除AI 评论内容")
|
||||
@PreAuthorize("@ss.hasPermission('server:comment:delete')")
|
||||
public CommonResult<Boolean> deleteCommentList(@RequestParam("ids") List<Integer> ids) {
|
||||
commentService.deleteCommentListByIds(ids);
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@GetMapping("/get")
|
||||
@Operation(summary = "获得AI 评论内容")
|
||||
@Parameter(name = "id", description = "编号", required = true, example = "1024")
|
||||
@PreAuthorize("@ss.hasPermission('server:comment:query')")
|
||||
public CommonResult<CommentRespVO> getComment(@RequestParam("id") Integer id) {
|
||||
CommentDO comment = commentService.getComment(id);
|
||||
return success(BeanUtils.toBean(comment, CommentRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/page")
|
||||
@Operation(summary = "获得AI 评论内容 分页")
|
||||
@PreAuthorize("@ss.hasPermission('server:comment:query')")
|
||||
public CommonResult<PageResult<CommentRespVO>> getCommentPage(@Valid CommentPageReqVO pageReqVO) {
|
||||
PageResult<CommentDO> pageResult = commentService.getCommentPage(pageReqVO);
|
||||
return success(BeanUtils.toBean(pageResult, CommentRespVO.class));
|
||||
}
|
||||
|
||||
@GetMapping("/export-excel")
|
||||
@Operation(summary = "导出AI 评论内容 Excel")
|
||||
@PreAuthorize("@ss.hasPermission('server:comment:export')")
|
||||
@ApiAccessLog(operateType = EXPORT)
|
||||
public void exportCommentExcel(@Valid CommentPageReqVO pageReqVO,
|
||||
HttpServletResponse response) throws IOException {
|
||||
pageReqVO.setPageSize(PageParam.PAGE_SIZE_NONE);
|
||||
List<CommentDO> list = commentService.getCommentPage(pageReqVO).getList();
|
||||
// 导出 Excel
|
||||
ExcelUtils.write(response, "AI 评论内容 .xls", "数据", CommentRespVO.class,
|
||||
BeanUtils.toBean(list, CommentRespVO.class));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
|
||||
@Schema(description = "管理后台 - AI 评论内容分页 Request VO")
|
||||
@Data
|
||||
public class CommentPageReqVO extends PageParam {
|
||||
|
||||
@Schema(description = "具体评论")
|
||||
private String content;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import com.alibaba.excel.annotation.*;
|
||||
|
||||
@Schema(description = "管理后台 - AI 评论内容Response VO")
|
||||
@Data
|
||||
@ExcelIgnoreUnannotated
|
||||
public class CommentRespVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "18114")
|
||||
@ExcelProperty("主键")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "具体评论")
|
||||
@ExcelProperty("具体评论")
|
||||
private String content;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo;
|
||||
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
@Schema(description = "管理后台 - AI 评论内容 新增/修改 Request VO")
|
||||
@Data
|
||||
public class CommentSaveReqVO {
|
||||
|
||||
@Schema(description = "主键", requiredMode = Schema.RequiredMode.REQUIRED, example = "18114")
|
||||
private Integer id;
|
||||
|
||||
@Schema(description = "具体评论")
|
||||
private String content;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package cn.iocoder.yudao.module.tkdata.dal.dataobject.comment;
|
||||
|
||||
import lombok.*;
|
||||
import java.util.*;
|
||||
import com.baomidou.mybatisplus.annotation.*;
|
||||
import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO;
|
||||
|
||||
/**
|
||||
* AI 评论内容
|
||||
DO
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
@TableName("ai_comment")
|
||||
@KeySequence("ai_comment_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。
|
||||
@Data
|
||||
@ToString(callSuper = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public class CommentDO {
|
||||
|
||||
/**
|
||||
* 主键
|
||||
*/
|
||||
@TableId
|
||||
private Integer id;
|
||||
/**
|
||||
* 具体评论
|
||||
*/
|
||||
private String content;
|
||||
|
||||
private Byte deleted;
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package cn.iocoder.yudao.module.tkdata.dal.mysql.comment;
|
||||
|
||||
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.tkdata.controller.admin.configController.vo.CommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.comment.CommentDO;
|
||||
import org.apache.ibatis.annotations.Mapper;
|
||||
|
||||
/**
|
||||
* AI 评论内容
|
||||
Mapper
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
@Mapper
|
||||
public interface CommentMapper extends BaseMapperX<CommentDO> {
|
||||
|
||||
default PageResult<CommentDO> selectPage(CommentPageReqVO reqVO) {
|
||||
return selectPage(reqVO, new LambdaQueryWrapperX<CommentDO>()
|
||||
.eqIfPresent(CommentDO::getContent, reqVO.getContent())
|
||||
.orderByDesc(CommentDO::getId));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,4 +14,5 @@ public interface ErrorCodeConstants {
|
||||
ErrorCode EMPLOYEE_HOSTS_NOT_EXISTS = new ErrorCode(1_001_301_001, "分配员工数据不存在");
|
||||
ErrorCode BIG_BROTHER_NOT_EXISTS = new ErrorCode(1_001_401_001, "大哥数据不存在");
|
||||
ErrorCode EMPLOYEE_BIG_BROTHER_NOT_EXISTS = new ErrorCode(1_001_401_001, "大哥数据员工业务不存在");
|
||||
ErrorCode COMMENT_NOT_EXISTS = new ErrorCode(1_001_501_001, "AI 评论内容不存在");
|
||||
}
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
package cn.iocoder.yudao.module.tkdata.service.comment;
|
||||
|
||||
import java.util.*;
|
||||
import javax.validation.*;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo.CommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo.CommentSaveReqVO;
|
||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.comment.CommentDO;
|
||||
|
||||
/**
|
||||
* AI 评论内容
|
||||
Service 接口
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
public interface CommentService {
|
||||
|
||||
/**
|
||||
* 创建AI 评论内容
|
||||
|
||||
*
|
||||
* @param createReqVO 创建信息
|
||||
* @return 编号
|
||||
*/
|
||||
Integer createComment(@Valid CommentSaveReqVO createReqVO);
|
||||
|
||||
/**
|
||||
* 更新AI 评论内容
|
||||
|
||||
*
|
||||
* @param updateReqVO 更新信息
|
||||
*/
|
||||
void updateComment(@Valid CommentSaveReqVO updateReqVO);
|
||||
|
||||
/**
|
||||
* 删除AI 评论内容
|
||||
|
||||
*
|
||||
* @param id 编号
|
||||
*/
|
||||
void deleteComment(Integer id);
|
||||
|
||||
/**
|
||||
* 批量删除AI 评论内容
|
||||
|
||||
*
|
||||
* @param ids 编号
|
||||
*/
|
||||
void deleteCommentListByIds(List<Integer> ids);
|
||||
|
||||
/**
|
||||
* 获得AI 评论内容
|
||||
|
||||
*
|
||||
* @param id 编号
|
||||
* @return AI 评论内容
|
||||
|
||||
*/
|
||||
CommentDO getComment(Integer id);
|
||||
|
||||
/**
|
||||
* 获得AI 评论内容
|
||||
分页
|
||||
*
|
||||
* @param pageReqVO 分页查询
|
||||
* @return AI 评论内容
|
||||
分页
|
||||
*/
|
||||
PageResult<CommentDO> getCommentPage(CommentPageReqVO pageReqVO);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package cn.iocoder.yudao.module.tkdata.service.comment;
|
||||
|
||||
import cn.hutool.core.collection.CollUtil;
|
||||
import cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo.CommentPageReqVO;
|
||||
import cn.iocoder.yudao.module.tkdata.controller.admin.configController.vo.CommentSaveReqVO;
|
||||
import cn.iocoder.yudao.module.tkdata.dal.dataobject.comment.CommentDO;
|
||||
import cn.iocoder.yudao.module.tkdata.dal.mysql.comment.CommentMapper;
|
||||
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.framework.common.pojo.PageResult;
|
||||
import cn.iocoder.yudao.framework.common.pojo.PageParam;
|
||||
import cn.iocoder.yudao.framework.common.util.object.BeanUtils;
|
||||
|
||||
|
||||
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.tkdata.enums.ErrorCodeConstants.COMMENT_NOT_EXISTS;
|
||||
|
||||
|
||||
/**
|
||||
* AI 评论内容
|
||||
Service 实现类
|
||||
*
|
||||
* @author 总后台
|
||||
*/
|
||||
@Service
|
||||
@Validated
|
||||
public class CommentServiceImpl implements CommentService {
|
||||
|
||||
@Resource
|
||||
private CommentMapper commentMapper;
|
||||
|
||||
@Override
|
||||
public Integer createComment(CommentSaveReqVO createReqVO) {
|
||||
// 插入
|
||||
CommentDO comment = BeanUtils.toBean(createReqVO, CommentDO.class);
|
||||
commentMapper.insert(comment);
|
||||
// 返回
|
||||
return comment.getId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateComment(CommentSaveReqVO updateReqVO) {
|
||||
// 校验存在
|
||||
validateCommentExists(updateReqVO.getId());
|
||||
// 更新
|
||||
CommentDO updateObj = BeanUtils.toBean(updateReqVO, CommentDO.class);
|
||||
commentMapper.updateById(updateObj);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteComment(Integer id) {
|
||||
// 校验存在
|
||||
validateCommentExists(id);
|
||||
// 删除
|
||||
commentMapper.deleteById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteCommentListByIds(List<Integer> ids) {
|
||||
// 校验存在
|
||||
validateCommentExists(ids);
|
||||
// 删除
|
||||
commentMapper.deleteByIds(ids);
|
||||
}
|
||||
|
||||
private void validateCommentExists(List<Integer> ids) {
|
||||
List<CommentDO> list = commentMapper.selectByIds(ids);
|
||||
if (CollUtil.isEmpty(list) || list.size() != ids.size()) {
|
||||
throw exception(COMMENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
private void validateCommentExists(Integer id) {
|
||||
if (commentMapper.selectById(id) == null) {
|
||||
throw exception(COMMENT_NOT_EXISTS);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommentDO getComment(Integer id) {
|
||||
return commentMapper.selectById(id);
|
||||
}
|
||||
|
||||
@Override
|
||||
public PageResult<CommentDO> getCommentPage(CommentPageReqVO pageReqVO) {
|
||||
return commentMapper.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="cn.iocoder.yudao.module.tkdata.dal.mysql.comment.CommentMapper">
|
||||
|
||||
<!--
|
||||
一般情况下,尽可能使用 Mapper 进行 CRUD 增删改查即可。
|
||||
无法满足的场景,例如说多表关联查询,才使用 XML 编写 SQL。
|
||||
代码生成器暂时只生成 Mapper XML 文件本身,更多推荐 MybatisX 快速开发插件来生成查询。
|
||||
文档可见:https://www.iocoder.cn/MyBatis/x-plugins/
|
||||
-->
|
||||
|
||||
</mapper>
|
||||
Reference in New Issue
Block a user