From 41822d989860012d4dbb81e78545e20d9c230b56 Mon Sep 17 00:00:00 2001 From: moyangzhan Date: Mon, 18 Mar 2024 00:36:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=9F=A5=E8=AF=86=E5=BA=93=E5=B1=95=E7=A4=BA?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E6=8B=86=E5=88=86=E6=88=90=E4=B8=A4=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/KnowledgeBaseController.java | 23 +++++++++++++++---- .../moyz/adi/common/entity/KnowledgeBase.java | 4 ++++ .../common/service/KnowledgeBaseService.java | 21 ++++++++++++++++- .../resources/mapper/KnowledgeBaseMapper.xml | 2 +- docs/create.sql | 3 +++ 5 files changed, 47 insertions(+), 6 deletions(-) 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 '所属人名称';