知识库展示列表拆分成两列

This commit is contained in:
moyangzhan 2024-03-18 00:36:03 +08:00
parent 273dc9df8b
commit 41822d9898
5 changed files with 47 additions and 6 deletions

View File

@ -37,9 +37,14 @@ public class KnowledgeBaseController {
return knowledgeBaseService.uploadDoc(uuid, embedding, doc);
}
@GetMapping("/search")
public Page<KnowledgeBase> 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<KnowledgeBase> 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<KnowledgeBase> 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);
}
}

View File

@ -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;

View File

@ -191,7 +191,7 @@ public class KnowledgeBaseService extends ServiceImpl<KnowledgeBaseMapper, Knowl
return true;
}
public Page<KnowledgeBase> search(String keyword, Boolean includeOthersPublic, Integer currentPage, Integer pageSize) {
public Page<KnowledgeBase> 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<KnowledgeBaseMapper, Knowl
}
}
public Page<KnowledgeBase> searchPublic(String keyword, Integer currentPage, Integer pageSize) {
LambdaQueryWrapper<KnowledgeBase> 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<KnowledgeBaseMapper, Knowl
return sseEmitter;
}
public boolean star(String kbUuid) {
KnowledgeBase knowledgeBase = getOrThrow(kbUuid);
return ChainWrappers.lambdaUpdateChain(baseMapper)
.eq(KnowledgeBase::getId, knowledgeBase.getId())
.set(KnowledgeBase::getStarCount, knowledgeBase.getStarCount() + 1)
.update();
}
/**
* 知识库问答限额判断
*/

View File

@ -26,7 +26,7 @@
<if test="keyword != null and keyword != ''">
and title like "%"#{keyword}"%"
</if>
order by update_time desc
order by star_count,update_time desc
</select>
</mapper>

View File

@ -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 '所属人名称';