diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/CommentController.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/CommentController.java new file mode 100644 index 0000000..a4ea2f4 --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/CommentController.java @@ -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 createComment(@Valid @RequestBody CommentSaveReqVO createReqVO) { + return success(commentService.createComment(createReqVO)); + } + + @PutMapping("/update") + @Operation(summary = "更新AI 评论内容") + @PreAuthorize("@ss.hasPermission('server:comment:update')") + public CommonResult 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 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 deleteCommentList(@RequestParam("ids") List 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 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> getCommentPage(@Valid CommentPageReqVO pageReqVO) { + PageResult 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 list = commentService.getCommentPage(pageReqVO).getList(); + // 导出 Excel + ExcelUtils.write(response, "AI 评论内容 .xls", "数据", CommentRespVO.class, + BeanUtils.toBean(list, CommentRespVO.class)); + } + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentPageReqVO.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentPageReqVO.java new file mode 100644 index 0000000..c3f9058 --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentPageReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentRespVO.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentRespVO.java new file mode 100644 index 0000000..034d9e7 --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentRespVO.java @@ -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; + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentSaveReqVO.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentSaveReqVO.java new file mode 100644 index 0000000..c987779 --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/controller/admin/configController/vo/CommentSaveReqVO.java @@ -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; + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/dal/dataobject/comment/CommentDO.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/dal/dataobject/comment/CommentDO.java new file mode 100644 index 0000000..a7c144c --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/dal/dataobject/comment/CommentDO.java @@ -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; + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/dal/mysql/comment/CommentMapper.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/dal/mysql/comment/CommentMapper.java new file mode 100644 index 0000000..653c215 --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/dal/mysql/comment/CommentMapper.java @@ -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 { + + default PageResult selectPage(CommentPageReqVO reqVO) { + return selectPage(reqVO, new LambdaQueryWrapperX() + .eqIfPresent(CommentDO::getContent, reqVO.getContent()) + .orderByDesc(CommentDO::getId)); + } + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/enums/ErrorCodeConstants.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/enums/ErrorCodeConstants.java index a6d5b6f..210dce4 100644 --- a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/enums/ErrorCodeConstants.java +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/enums/ErrorCodeConstants.java @@ -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 评论内容不存在"); } diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/service/comment/CommentService.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/service/comment/CommentService.java new file mode 100644 index 0000000..5f6c0a8 --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/service/comment/CommentService.java @@ -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 ids); + + /** + * 获得AI 评论内容 + + * + * @param id 编号 + * @return AI 评论内容 + + */ + CommentDO getComment(Integer id); + + /** + * 获得AI 评论内容 +分页 + * + * @param pageReqVO 分页查询 + * @return AI 评论内容 +分页 + */ + PageResult getCommentPage(CommentPageReqVO pageReqVO); + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/service/comment/CommentServiceImpl.java b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/service/comment/CommentServiceImpl.java new file mode 100644 index 0000000..699e93d --- /dev/null +++ b/tkdata-model-server/src/main/java/cn/iocoder/yudao/module/tkdata/service/comment/CommentServiceImpl.java @@ -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 ids) { + // 校验存在 + validateCommentExists(ids); + // 删除 + commentMapper.deleteByIds(ids); + } + + private void validateCommentExists(List ids) { + List 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 getCommentPage(CommentPageReqVO pageReqVO) { + return commentMapper.selectPage(pageReqVO); + } + +} \ No newline at end of file diff --git a/tkdata-model-server/src/main/resources/mapper/comment/CommentMapper.xml b/tkdata-model-server/src/main/resources/mapper/comment/CommentMapper.xml new file mode 100644 index 0000000..b4f6313 --- /dev/null +++ b/tkdata-model-server/src/main/resources/mapper/comment/CommentMapper.xml @@ -0,0 +1,12 @@ + + + + + + + \ No newline at end of file diff --git a/yudao-server/src/main/resources/application.yaml b/yudao-server/src/main/resources/application.yaml index b54b37a..f4fc874 100644 --- a/yudao-server/src/main/resources/application.yaml +++ b/yudao-server/src/main/resources/application.yaml @@ -191,6 +191,7 @@ yudao: - /admin-api/system/auth/** ignore-tables: - server_country_info + - ai_comment ignore-caches: - user_role_ids - permission_menu_ids