添加知识分类

This commit is contained in:
Pancaihua 2024-07-29 11:13:02 +08:00
parent 457efeb494
commit 901b6b8b1f
12 changed files with 331 additions and 12 deletions

View File

@ -83,4 +83,6 @@ public interface ErrorCodeConstants {
ErrorCode KNOWTYPE_PARENT_IS_CHILD = new ErrorCode(1_009_015_005, "不能设置自己的子Knowtype为父Knowtype");
// ========== 知识发布 1_009_016_000 ==========
ErrorCode KNOWLEDGE_NOT_EXISTS = new ErrorCode(1_009_016_000, "知识发布不存在");
// ========== 评论 1_009_017_000 ==========
ErrorCode COMMENT_NOT_EXISTS = new ErrorCode(1_009_017_000, "评论不存在");
}

View File

@ -0,0 +1,96 @@
package cn.iocoder.yudao.module.bpm.controller.admin.knows;
import org.springframework.web.bind.annotation.*;
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 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.*;
import cn.iocoder.yudao.module.bpm.controller.admin.knows.vo.*;
import cn.iocoder.yudao.module.bpm.dal.dataobject.knows.CommentDO;
import cn.iocoder.yudao.module.bpm.service.knows.CommentService;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
@Tag(name = "管理后台 - 评论")
@RestController
@RequestMapping("/bpm/comment")
@Validated
public class CommentController {
@Resource
private CommentService commentService;
@PostMapping("/create")
@Operation(summary = "创建评论")
@PreAuthorize("@ss.hasPermission('bpm:comment:create')")
public CommonResult<Long> createComment(@Valid @RequestBody CommentSaveReqVO createReqVO) {
return success(commentService.createComment(createReqVO));
}
@PutMapping("/update")
@Operation(summary = "更新评论")
@PreAuthorize("@ss.hasPermission('bpm:comment:update')")
public CommonResult<Boolean> updateComment(@Valid @RequestBody CommentSaveReqVO updateReqVO) {
commentService.updateComment(updateReqVO);
return success(true);
}
@DeleteMapping("/delete")
@Operation(summary = "删除评论")
@Parameter(name = "id", description = "编号", required = true)
@PreAuthorize("@ss.hasPermission('bpm:comment:delete')")
public CommonResult<Boolean> deleteComment(@RequestParam("id") Long id) {
commentService.deleteComment(id);
return success(true);
}
@GetMapping("/get")
@Operation(summary = "获得评论")
@Parameter(name = "id", description = "编号", required = true, example = "1024")
@PreAuthorize("@ss.hasPermission('bpm:comment:query')")
public CommonResult<CommentRespVO> getComment(@RequestParam("id") Long id) {
CommentDO comment = commentService.getComment(id);
return success(BeanUtils.toBean(comment, CommentRespVO.class));
}
@GetMapping("/page")
@Operation(summary = "获得评论分页")
@PreAuthorize("@ss.hasPermission('bpm: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 = "导出评论 Excel")
@PreAuthorize("@ss.hasPermission('bpm: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, "评论.xls", "数据", CommentRespVO.class,
BeanUtils.toBean(list, CommentRespVO.class));
}
}

View File

@ -1,19 +1,13 @@
package cn.iocoder.yudao.module.bpm.controller.admin.knows;
import cn.hutool.core.collection.CollUtil;
import cn.iocoder.yudao.framework.common.util.number.NumberUtils;
import cn.iocoder.yudao.framework.common.util.spring.SpringUtils;
import cn.iocoder.yudao.module.bpm.convert.knows.KnowledgeConvert;
import cn.iocoder.yudao.module.bpm.dal.dataobject.knows.KnowtypeDO;
import cn.iocoder.yudao.module.bpm.service.knows.KnowtypeService;
import cn.iocoder.yudao.module.system.api.user.AdminUserApi;
import cn.iocoder.yudao.module.system.api.user.dto.AdminUserRespDTO;
import cn.iocoder.yudao.module.system.dal.dataobject.dept.DeptDO;
import cn.iocoder.yudao.module.system.dal.dataobject.user.AdminUserDO;
import cn.iocoder.yudao.module.system.service.dept.DeptService;
import cn.iocoder.yudao.module.system.service.user.AdminUserService;
import cn.iocoder.yudao.module.system.service.user.AdminUserServiceImpl;
import io.reactivex.rxjava3.core.Single;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
@ -22,7 +16,7 @@ import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;
import java.io.IOException;
import java.util.*;
import java.util.stream.Stream;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
@ -36,8 +30,6 @@ 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.*;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertList;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertListByFlatMap;
import static cn.iocoder.yudao.framework.common.util.collection.CollectionUtils.convertSet;
import cn.iocoder.yudao.module.bpm.controller.admin.knows.vo.*;
import cn.iocoder.yudao.module.bpm.dal.dataobject.knows.KnowledgeDO;
import cn.iocoder.yudao.module.bpm.dal.dataobject.knows.CommentDO;

View File

@ -0,0 +1,28 @@
package cn.iocoder.yudao.module.bpm.controller.admin.knows.vo;
import lombok.*;
import java.util.*;
import io.swagger.v3.oas.annotations.media.Schema;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import org.springframework.format.annotation.DateTimeFormat;
import java.time.LocalDateTime;
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND;
@Schema(description = "管理后台 - 评论分页 Request VO")
@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
public class CommentPageReqVO extends PageParam {
@Schema(description = "创建时间")
@DateTimeFormat(pattern = FORMAT_YEAR_MONTH_DAY_HOUR_MINUTE_SECOND)
private LocalDateTime[] createTime;
@Schema(description = "类型id", example = "6659")
private Long knowId;
@Schema(description = "内容")
private String content;
}

View File

@ -0,0 +1,31 @@
package cn.iocoder.yudao.module.bpm.controller.admin.knows.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 com.alibaba.excel.annotation.*;
@Schema(description = "管理后台 - 评论 Response VO")
@Data
@ExcelIgnoreUnannotated
public class CommentRespVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "5346")
@ExcelProperty("id")
private Long id;
@Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED)
@ExcelProperty("创建时间")
private LocalDateTime createTime;
@Schema(description = "类型id", example = "6659")
@ExcelProperty("类型id")
private Long knowId;
@Schema(description = "内容")
@ExcelProperty("内容")
private String content;
}

View File

@ -0,0 +1,20 @@
package cn.iocoder.yudao.module.bpm.controller.admin.knows.vo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import java.util.*;
@Schema(description = "管理后台 - 评论新增/修改 Request VO")
@Data
public class CommentSaveReqVO {
@Schema(description = "id", requiredMode = Schema.RequiredMode.REQUIRED, example = "5346")
private Long id;
@Schema(description = "类型id", example = "6659")
private Long knowId;
@Schema(description = "内容")
private String content;
}

View File

@ -3,11 +3,11 @@ package cn.iocoder.yudao.module.bpm.dal.mysql.knows;
import java.util.*;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.module.bpm.dal.dataobject.knows.CommentDO;
import org.apache.ibatis.annotations.Mapper;
import cn.iocoder.yudao.module.bpm.controller.admin.knows.vo.*;
/**
* 评论 Mapper
@ -24,5 +24,11 @@ public interface CommentMapper extends BaseMapperX<CommentDO> {
default int deleteByKnowId(Long knowId) {
return delete(CommentDO::getKnowId, knowId);
}
}
default PageResult<CommentDO> selectPage(CommentPageReqVO reqVO) {
return selectPage(reqVO, new LambdaQueryWrapperX<CommentDO>()
.betweenIfPresent(CommentDO::getCreateTime, reqVO.getCreateTime())
.eqIfPresent(CommentDO::getKnowId, reqVO.getKnowId())
.eqIfPresent(CommentDO::getContent, reqVO.getContent())
.orderByDesc(CommentDO::getId));
}
}

View File

@ -0,0 +1,56 @@
package cn.iocoder.yudao.module.bpm.service.knows;
import java.util.*;
import cn.iocoder.yudao.module.bpm.controller.admin.knows.vo.*;
import cn.iocoder.yudao.module.bpm.dal.dataobject.knows.CommentDO;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.common.pojo.PageParam;
import javax.validation.Valid;
/**
* 评论 Service 接口
*
* @author pch
*/
public interface CommentService {
/**
* 创建评论
*
* @param createReqVO 创建信息
* @return 编号
*/
Long createComment(@Valid CommentSaveReqVO createReqVO);
/**
* 更新评论
*
* @param updateReqVO 更新信息
*/
void updateComment(@Valid CommentSaveReqVO updateReqVO);
/**
* 删除评论
*
* @param id 编号
*/
void deleteComment(Long id);
/**
* 获得评论
*
* @param id 编号
* @return 评论
*/
CommentDO getComment(Long id);
/**
* 获得评论分页
*
* @param pageReqVO 分页查询
* @return 评论分页
*/
PageResult<CommentDO> getCommentPage(CommentPageReqVO pageReqVO);
}

View File

@ -0,0 +1,73 @@
package cn.iocoder.yudao.module.bpm.service.knows;
import org.springframework.stereotype.Service;
import org.springframework.validation.annotation.Validated;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.*;
import cn.iocoder.yudao.module.bpm.controller.admin.knows.vo.*;
import cn.iocoder.yudao.module.bpm.dal.dataobject.knows.CommentDO;
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 cn.iocoder.yudao.module.bpm.dal.mysql.knows.CommentMapper;
import static cn.iocoder.yudao.framework.common.exception.util.ServiceExceptionUtil.exception;
import static cn.iocoder.yudao.module.bpm.enums.ErrorCodeConstants.*;
/**
* 评论 Service 实现类
*
* @author pch
*/
@Service
@Validated
public class CommentServiceImpl implements CommentService {
@Resource
private CommentMapper commentMapper;
@Override
public Long 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(Long id) {
// 校验存在
validateCommentExists(id);
// 删除
commentMapper.deleteById(id);
}
private void validateCommentExists(Long id) {
if (commentMapper.selectById(id) == null) {
throw exception(COMMENT_NOT_EXISTS);
}
}
@Override
public CommentDO getComment(Long id) {
return commentMapper.selectById(id);
}
@Override
public PageResult<CommentDO> getCommentPage(CommentPageReqVO pageReqVO) {
return commentMapper.selectPage(pageReqVO);
}
}

View File

@ -3,3 +3,4 @@ DELETE FROM "bpm_user_group";
DELETE FROM "bpm_category";
DELETE FROM "des_knowtype";
DELETE FROM "des_knowledge";
DELETE FROM "des_comment";

View File

@ -72,3 +72,16 @@ CREATE TABLE IF NOT EXISTS "des_knowledge" (
"tenant_id" bigint NOT NULL,
PRIMARY KEY ("id")
) COMMENT '知识表';
-- 将该建表 SQL 语句,添加到 yudao-module-bpm-biz 模块的 test/resources/sql/create_tables.sql 文件里
CREATE TABLE IF NOT EXISTS "des_comment" (
"id" bigint NOT NULL GENERATED BY DEFAULT AS IDENTITY,
"creator" varchar DEFAULT '',
"create_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updater" varchar DEFAULT '',
"update_time" datetime NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
"deleted" bit NOT NULL DEFAULT FALSE,
"tenant_id" bigint NOT NULL,
"know_id" bigint,
"content" varchar,
PRIMARY KEY ("id")
) COMMENT '评论表';

View File

@ -47,6 +47,7 @@ spring:
datasource:
master:
url: jdbc:mysql://192.168.1.102:3306/yudao-vue?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=false&serverTimezone=Asia/Shanghai&allowPublicKeyRetrieval=true&nullCatalogMeansCurrent=true # MySQL Connector/J 8.X 连接的示例
# url: jdbc:mysql://127.0.0.1:3306/ruoyi-vue-pro?useSSL=true&allowPublicKeyRetrieval=true&useUnicode=true&characterEncoding=UTF-8&serverTimezone=Asia/Shanghai # MySQL Connector/J 5.X 连接的示例
# url: jdbc:postgresql://127.0.0.1:5432/ruoyi-vue-pro # PostgreSQL 连接的示例
# url: jdbc:oracle:thin:@127.0.0.1:1521:xe # Oracle 连接的示例