diff --git a/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java b/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java index 2c131ae..c251479 100644 --- a/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java +++ b/adi-chat/src/main/java/com/moyz/adi/chat/controller/KnowledgeBaseController.java @@ -27,7 +27,7 @@ public class KnowledgeBaseController { } @PostMapping(path = "/uploadDocs/{uuid}", headers = "content-type=multipart/form-data", produces = MediaType.APPLICATION_JSON_VALUE) - public boolean uploadDocs(@PathVariable String uuid,@RequestParam(value = "embedding", defaultValue = "true") Boolean embedding, @RequestParam("files") MultipartFile[] docs) { + public boolean uploadDocs(@PathVariable String uuid, @RequestParam(value = "embedding", defaultValue = "true") Boolean embedding, @RequestParam("files") MultipartFile[] docs) { knowledgeBaseService.uploadDocs(uuid, embedding, docs); return true; } @@ -37,9 +37,14 @@ public class KnowledgeBaseController { return knowledgeBaseService.uploadDoc(uuid, embedding, doc); } - @GetMapping("/search") - public Page list(String keyword, Boolean includeOthersPublic, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { - return knowledgeBaseService.search(keyword, includeOthersPublic, currentPage, pageSize); + @GetMapping("/searchMine") + public Page searchMine(@RequestParam(defaultValue = "") String keyword, @RequestParam(defaultValue = "false") Boolean includeOthersPublic, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { + return knowledgeBaseService.searchMine(keyword, includeOthersPublic, currentPage, pageSize); + } + + @GetMapping("/searchPublic") + public Page searchPublic(@RequestParam(defaultValue = "") String keyword, @NotNull @Min(1) Integer currentPage, @NotNull @Min(10) Integer pageSize) { + return knowledgeBaseService.searchPublic(keyword, currentPage, pageSize); } @GetMapping("/info/{uuid}") @@ -59,4 +64,14 @@ public class KnowledgeBaseController { public boolean embedding(@PathVariable String uuid, @RequestParam(defaultValue = "false") Boolean forceAll) { return knowledgeBaseService.embedding(uuid, forceAll); } + + /** + * 点赞 + * + * @return + */ + @PostMapping("/star/{uuid}") + public boolean star(@PathVariable String kbUuid) { + return knowledgeBaseService.star(kbUuid); + } } diff --git a/adi-common/src/main/java/com/moyz/adi/common/entity/KnowledgeBase.java b/adi-common/src/main/java/com/moyz/adi/common/entity/KnowledgeBase.java index da40fe7..1e70424 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/entity/KnowledgeBase.java +++ b/adi-common/src/main/java/com/moyz/adi/common/entity/KnowledgeBase.java @@ -26,6 +26,10 @@ public class KnowledgeBase extends BaseEntity { @TableField("is_public") private Boolean isPublic; + @Schema(title = "点赞数") + @TableField("star_count") + private Long starCount; + @Schema(title = "所属人id") @TableField("owner_id") private Long ownerId; diff --git a/adi-common/src/main/java/com/moyz/adi/common/service/KnowledgeBaseService.java b/adi-common/src/main/java/com/moyz/adi/common/service/KnowledgeBaseService.java index b6ba019..1c053eb 100644 --- a/adi-common/src/main/java/com/moyz/adi/common/service/KnowledgeBaseService.java +++ b/adi-common/src/main/java/com/moyz/adi/common/service/KnowledgeBaseService.java @@ -191,7 +191,7 @@ public class KnowledgeBaseService extends ServiceImpl search(String keyword, Boolean includeOthersPublic, Integer currentPage, Integer pageSize) { + public Page searchMine(String keyword, Boolean includeOthersPublic, Integer currentPage, Integer pageSize) { User user = ThreadContext.getCurrentUser(); if (user.getIsAdmin()) { return baseMapper.searchByAdmin(new Page<>(currentPage, pageSize), keyword); @@ -200,6 +200,17 @@ public class KnowledgeBaseService extends ServiceImpl searchPublic(String keyword, Integer currentPage, Integer pageSize) { + LambdaQueryWrapper wrapper = new LambdaQueryWrapper(); + wrapper.eq(KnowledgeBase::getIsPublic, true); + wrapper.eq(KnowledgeBase::getIsDeleted, false); + if(StringUtils.isNotBlank(keyword)){ + wrapper.like(KnowledgeBase::getTitle, keyword); + } + wrapper.orderByDesc(KnowledgeBase::getStarCount, KnowledgeBase::getUpdateTime); + return baseMapper.selectPage(new Page<>(currentPage, pageSize), wrapper); + } + public boolean softDelete(String uuid) { checkPrivilege(null, uuid); return ChainWrappers.lambdaUpdateChain(baseMapper) @@ -227,6 +238,14 @@ public class KnowledgeBaseService extends ServiceImpl and title like "%"#{keyword}"%" - order by update_time desc + order by star_count,update_time desc diff --git a/docs/create.sql b/docs/create.sql index c082c6a..6d867a8 100644 --- a/docs/create.sql +++ b/docs/create.sql @@ -419,6 +419,7 @@ create table adi_knowledge_base title varchar(250) default ''::character varying not null, remark text default ''::character varying not null, is_public boolean default false not null, + star_count int default 0 not null, owner_id bigint default 0 not null, owner_name varchar(45) default ''::character varying not null, create_time timestamp default CURRENT_TIMESTAMP not null, @@ -434,6 +435,8 @@ comment on column adi_knowledge_base.remark is '知识库描述'; comment on column adi_knowledge_base.is_public is '是否公开'; +comment on column adi_knowledge_base.star_count is '点赞数'; + comment on column adi_knowledge_base.owner_id is '所属人id'; comment on column adi_knowledge_base.owner_name is '所属人名称';