Commit 9495df61 authored by alex yao's avatar alex yao

feat: 知识库文档模糊查询

parent d5bebd15
...@@ -50,7 +50,7 @@ public interface KnowledgeService { ...@@ -50,7 +50,7 @@ public interface KnowledgeService {
/** /**
* 获取用户知识库 * 获取用户知识库
*/ */
List<BizKnowledgeDocumentEntity> getList(String search, String trainStatus, PagingInfo pagingInfo) throws Exception; List<BizKnowledgeDocumentEntity> searchDocuments(String search, String trainStatus,List<Integer> kdIds, PagingInfo pagingInfo) throws Exception;
/** /**
* 获取用户知识库文档 * 获取用户知识库文档
......
...@@ -202,13 +202,13 @@ public class KnowledgeServiceImpl implements KnowledgeService { ...@@ -202,13 +202,13 @@ public class KnowledgeServiceImpl implements KnowledgeService {
} }
@Override @Override
public List<BizKnowledgeDocumentEntity> getList(String search, String trainStatus, PagingInfo pagingInfo) throws Exception { public List<BizKnowledgeDocumentEntity> searchDocuments(String search, String trainStatus, List<Integer> kdIds, PagingInfo pagingInfo) throws Exception {
List<BizKnowledgeDocumentEntity> result = new ArrayList<>(); List<BizKnowledgeDocumentEntity> result = new ArrayList<>();
String memberId = BlContext.getCurrentUser().getUserId().toString(); String memberId = BlContext.getCurrentUser().getUserId().toString();
if (StringUtils.isBlank(memberId)) { if (StringUtils.isBlank(memberId)) {
memberId = BlContext.getCurrentUserNotException().getUserId().toString(); memberId = BlContext.getCurrentUserNotException().getUserId().toString();
} }
List<KnowledgeQueryItem> knowledgeQueryItems = bizKnowledgeDocumentService.searchKnowledge(search, trainStatus, memberId, null, pagingInfo); List<KnowledgeQueryItem> knowledgeQueryItems = bizKnowledgeDocumentService.searchKnowledge(search, trainStatus, memberId, null, kdIds, pagingInfo);
if (CollectionUtils.isNotEmpty(knowledgeQueryItems)) { if (CollectionUtils.isNotEmpty(knowledgeQueryItems)) {
result = knowledgeQueryItems.stream().map(item -> { result = knowledgeQueryItems.stream().map(item -> {
BizKnowledgeDocumentEntity entity = new BizKnowledgeDocumentEntity(); BizKnowledgeDocumentEntity entity = new BizKnowledgeDocumentEntity();
......
...@@ -17,4 +17,5 @@ where bkd.is_deleted = 'N' ...@@ -17,4 +17,5 @@ where bkd.is_deleted = 'N'
<<and bkd.document_name = :documentName>> <<and bkd.document_name = :documentName>>
<<and bkd.train_status =:trainStatus>> <<and bkd.train_status =:trainStatus>>
<<and locate(:searchDocumentName,bkd.document_name) >> <<and locate(:searchDocumentName,bkd.document_name) >>
<<and bkd.kd_id in (:kdIds)>>
order by bkd.upload_time desc order by bkd.upload_time desc
\ No newline at end of file
package cn.com.poc.knowledge.query; package cn.com.poc.knowledge.query;
import java.io.Serializable; import java.io.Serializable;
import java.util.List;
/** /**
* Query Condition class for KnowledgeQuery * Query Condition class for KnowledgeQuery
...@@ -50,4 +51,14 @@ public class KnowledgeQueryCondition implements Serializable{ ...@@ -50,4 +51,14 @@ public class KnowledgeQueryCondition implements Serializable{
public void setSearchDocumentName(String searchDocumentName) { public void setSearchDocumentName(String searchDocumentName) {
this.searchDocumentName = searchDocumentName; this.searchDocumentName = searchDocumentName;
} }
private List<Integer> kdIds;
public List<Integer> getKdIds() {
return kdIds;
}
public void setKdIds(List<Integer> kdIds) {
this.kdIds = kdIds;
}
} }
\ No newline at end of file
...@@ -61,9 +61,12 @@ public interface KnowledgeRest extends BaseRest { ...@@ -61,9 +61,12 @@ public interface KnowledgeRest extends BaseRest {
Boolean trainKnowledge(@RequestBody TrainKnowledgeDto dto) throws Exception; Boolean trainKnowledge(@RequestBody TrainKnowledgeDto dto) throws Exception;
/** /**
* 获取用户知识库 * 模糊查询知识库文档
*/ */
List<BizKnowledgeDocumentDto> getList(@RequestParam(required = false) String search, @RequestParam(required = false) String trainStatus, PagingInfo pagingInfo) throws Exception; List<BizKnowledgeDocumentDto> searchDocuments(@RequestParam(required = false) String search,
@RequestParam(required = false) String trainStatus,
@RequestParam Integer knowledgeInfoId,
PagingInfo pagingInfo) throws Exception;
/** /**
* 获取知识库的文档列表 * 获取知识库的文档列表
......
...@@ -89,9 +89,24 @@ public class KnowledgeRestImpl implements KnowledgeRest { ...@@ -89,9 +89,24 @@ public class KnowledgeRestImpl implements KnowledgeRest {
} }
@Override @Override
public List<BizKnowledgeDocumentDto> getList(String search, String trainStatus, PagingInfo pagingInfo) throws Exception { public List<BizKnowledgeDocumentDto> searchDocuments(String search, String trainStatus, Integer knowledgeInfoId, PagingInfo pagingInfo) throws Exception {
List<BizKnowledgeDocumentDto> result = new ArrayList<>(); List<BizKnowledgeDocumentDto> result = new ArrayList<>();
List<BizKnowledgeDocumentEntity> entities = knowledgeService.getList(search, trainStatus, pagingInfo); BizKnowledgeInfoEntity bizKnowledgeInfoEntity = bizKnowledgeInfoService.get(knowledgeInfoId);
if (bizKnowledgeInfoEntity == null) {
throw new BusinessException("知识库不存在");
}
String kdIds = bizKnowledgeInfoEntity.getKdIds();
if (StringUtils.isBlank(kdIds)) {
return result;
}
List<Integer> kdIdList = JsonUtils.deSerialize(kdIds, new TypeReference<List<Integer>>() {
}.getType());
if (CollectionUtils.isEmpty(kdIdList)) {
return result;
}
List<BizKnowledgeDocumentEntity> entities = knowledgeService.searchDocuments(search, trainStatus, kdIdList, pagingInfo);
if (CollectionUtils.isNotEmpty(entities)) { if (CollectionUtils.isNotEmpty(entities)) {
result = entities.stream().map(entity -> { result = entities.stream().map(entity -> {
BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto(); BizKnowledgeDocumentDto dto = new BizKnowledgeDocumentDto();
......
...@@ -19,5 +19,5 @@ public interface BizKnowledgeDocumentService extends BaseService { ...@@ -19,5 +19,5 @@ public interface BizKnowledgeDocumentService extends BaseService {
Boolean deleted(Integer kdId); Boolean deleted(Integer kdId);
List<KnowledgeQueryItem> searchKnowledge(String document,String trainStatus, String memberId, String documentName, PagingInfo pagingInfo); List<KnowledgeQueryItem> searchKnowledge(String document, String trainStatus, String memberId, String documentName, List<Integer> kdIds, PagingInfo pagingInfo);
} }
\ No newline at end of file
...@@ -81,12 +81,13 @@ public class BizKnowledgeDocumentServiceImpl extends BaseServiceImpl ...@@ -81,12 +81,13 @@ public class BizKnowledgeDocumentServiceImpl extends BaseServiceImpl
} }
@Override @Override
public List<KnowledgeQueryItem> searchKnowledge(String searchDocumentName, String trainStatus, String memberId, String documentName, PagingInfo pagingInfo) { public List<KnowledgeQueryItem> searchKnowledge(String searchDocumentName, String trainStatus, String memberId, String documentName, List<Integer> kdIds, PagingInfo pagingInfo) {
KnowledgeQueryCondition condition = new KnowledgeQueryCondition(); KnowledgeQueryCondition condition = new KnowledgeQueryCondition();
condition.setMemberId(memberId); condition.setMemberId(memberId);
condition.setDocumentName(documentName); condition.setDocumentName(documentName);
condition.setTrainStatus(trainStatus); condition.setTrainStatus(trainStatus);
condition.setSearchDocumentName(searchDocumentName); condition.setSearchDocumentName(searchDocumentName);
condition.setKdIds(kdIds);
return this.sqlDao.query(condition, KnowledgeQueryItem.class, pagingInfo); return this.sqlDao.query(condition, KnowledgeQueryItem.class, pagingInfo);
} }
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment