问题知识库-插入es数据完善。
This commit is contained in:
+66
-7
@@ -10,6 +10,10 @@ import com.jero.common.system.query.QueryGenerator;
|
||||
import com.jero.common.system.vo.DictModel;
|
||||
import com.jero.common.system.vo.LoginUser;
|
||||
import com.jero.modules.document.enums.SearchEnum;
|
||||
import com.jero.modules.document.utils.ReadPdfUtil;
|
||||
import com.jero.modules.document.utils.ReadWordUtil;
|
||||
import com.jero.modules.oss.entity.OSSFile;
|
||||
import com.jero.modules.oss.service.IOSSFileService;
|
||||
import com.jero.modules.problemKnowledgeBase.entity.*;
|
||||
import com.jero.modules.problemKnowledgeBase.enums.CollectStatusEnum;
|
||||
import com.jero.modules.problemKnowledgeBase.enums.PraiseStatusEnum;
|
||||
@@ -23,6 +27,7 @@ import com.jero.modules.system.util.StringUtils;
|
||||
import org.apache.commons.collections4.CollectionUtils;
|
||||
import org.apache.shiro.SecurityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.*;
|
||||
@@ -60,8 +65,12 @@ public class ProblemKnowledgeBaseEOServiceImpl extends ServiceImpl<ProblemKnowle
|
||||
private IProblemKnowledgeBaseCommentEOService problemKnowledgeBaseCommentEOService;
|
||||
@Autowired
|
||||
private JeroElasticsearchTemplate jeroElasticsearchTemplate;
|
||||
@Autowired
|
||||
private IOSSFileService iOSSFileService;
|
||||
|
||||
public static final String SEARCH_FLAG = "魑";
|
||||
@Value(value = "${jero.path.upload}")
|
||||
private String uploadpath;
|
||||
|
||||
/**
|
||||
* 保存
|
||||
@@ -95,11 +104,49 @@ public class ProblemKnowledgeBaseEOServiceImpl extends ServiceImpl<ProblemKnowle
|
||||
List<Map<String, Object>> mapListTempCn = new ArrayList<>();
|
||||
List<Map<String, Object>> mapListTempEn = new ArrayList<>();
|
||||
|
||||
//查询该数据的文件。
|
||||
StringBuffer fileTextSb = new StringBuffer();
|
||||
List<OSSFile> accessoryFileList = iOSSFileService.getFileInfos(problemKnowledgeBaseEO.getAccessoryFile());
|
||||
if(CollectionUtils.isNotEmpty(accessoryFileList)){
|
||||
for (OSSFile ossFile : accessoryFileList) {
|
||||
String fileText = "";
|
||||
// 读取文件内容
|
||||
if (ossFile.getFileName().endsWith(".doc")
|
||||
|| ossFile.getFileName().endsWith(".docx")
|
||||
|| ossFile.getFileName().endsWith(".DOC")
|
||||
|| ossFile.getFileName().endsWith(".DOCX")) {
|
||||
|
||||
String wordContent = null;
|
||||
try {
|
||||
wordContent = ReadWordUtil.readWord(ossFile.getUrl(),uploadpath);
|
||||
} catch (Exception e) {
|
||||
log.error("文档库: 读取word内容失败");
|
||||
}
|
||||
if (StringUtils.isNotBlank(wordContent)) {
|
||||
fileText = ossFile.getFileName() + " : " +wordContent;
|
||||
}
|
||||
} else if (ossFile.getFileName().endsWith(".pdf") || ossFile.getFileName().endsWith(".PDF")) {
|
||||
String pdfContent = null;
|
||||
try {
|
||||
pdfContent = ReadPdfUtil.readPdf(ossFile.getUrl());
|
||||
} catch (Exception e) {
|
||||
log.error("文档库: 读取PDF文件内容失败");
|
||||
}
|
||||
if (StringUtils.isNotBlank(pdfContent)) {
|
||||
fileText = ossFile.getFileName() + " : " + pdfContent;
|
||||
}
|
||||
}
|
||||
|
||||
fileTextSb.append(fileText);
|
||||
fileTextSb.append("\n");
|
||||
}
|
||||
}
|
||||
|
||||
//sbCn sbEn 这两个字段作为es中英文切换
|
||||
StringBuilder sbCn = new StringBuilder();
|
||||
esFullText(problemKnowledgeBaseEO,sbCn,null,CutEnum.CN.getValue());
|
||||
esFullText(problemKnowledgeBaseEO,sbCn,null,CutEnum.CN.getValue(),fileTextSb.toString());
|
||||
StringBuilder sbEn = new StringBuilder();
|
||||
esFullText(problemKnowledgeBaseEO,null,sbEn,CutEnum.EN.getValue());
|
||||
esFullText(problemKnowledgeBaseEO,null,sbEn,CutEnum.EN.getValue(),fileTextSb.toString());
|
||||
|
||||
Map<String, Object> stringMapCn = new HashMap<>();
|
||||
this.problemKnowledgeBaseEOConvertMapByCut(problemKnowledgeBaseEO,CutEnum.EN.getValue(),stringMapCn);
|
||||
@@ -169,7 +216,7 @@ public class ProblemKnowledgeBaseEOServiceImpl extends ServiceImpl<ProblemKnowle
|
||||
}
|
||||
}
|
||||
|
||||
public void esFullText(ProblemKnowledgeBaseEO problemKnowledgeBaseEO,StringBuilder sbCn,StringBuilder sbEn,String cut){
|
||||
public void esFullText(ProblemKnowledgeBaseEO problemKnowledgeBaseEO,StringBuilder sbCn,StringBuilder sbEn,String cut,String fileText){
|
||||
if(StringUtils.equals(cut,CutEnum.CN.getValue())){
|
||||
if(StringUtils.isNotEmpty(problemKnowledgeBaseEO.getShowPermissions_dicText())){
|
||||
sbCn.append("展示权限" + ":" + problemKnowledgeBaseEO.getShowPermissions_dicText() + " ");
|
||||
@@ -212,10 +259,16 @@ public class ProblemKnowledgeBaseEOServiceImpl extends ServiceImpl<ProblemKnowle
|
||||
}else {
|
||||
sbCn.append("内容" + ":" + "-- ");
|
||||
}
|
||||
|
||||
if(StringUtils.isNotEmpty(fileText)){
|
||||
sbCn.append("附件内容" + ":" + fileText + " ");
|
||||
}else {
|
||||
sbCn.append("附件内容" + ":" + "-- ");
|
||||
}
|
||||
}else if(StringUtils.equals(cut,CutEnum.EN.getValue())){
|
||||
|
||||
if(StringUtils.isNotEmpty(problemKnowledgeBaseEO.getShowPermissions_dicText())){
|
||||
sbEn.append("Display permission" + ":" + problemKnowledgeBaseEO.getShowPermissions_dicText() + " ");
|
||||
if(StringUtils.isNotEmpty(problemKnowledgeBaseEO.getShowPermissions())){
|
||||
sbEn.append("Display permission" + ":" + problemKnowledgeBaseEO.getShowPermissions() + " ");
|
||||
}else {
|
||||
sbEn.append("Display permission" + ":" + "-- ");
|
||||
}
|
||||
@@ -232,8 +285,8 @@ public class ProblemKnowledgeBaseEOServiceImpl extends ServiceImpl<ProblemKnowle
|
||||
sbEn.append("Problem classification" + ":" + "-- ");
|
||||
}
|
||||
|
||||
if(StringUtils.isNotEmpty(problemKnowledgeBaseEO.getTargetMarket_dicText())){
|
||||
sbEn.append("Market" + ":" + problemKnowledgeBaseEO.getTargetMarket_dicText() + " ");
|
||||
if(StringUtils.isNotEmpty(problemKnowledgeBaseEO.getTargetMarket())){
|
||||
sbEn.append("Market" + ":" + problemKnowledgeBaseEO.getTargetMarket() + " ");
|
||||
}else {
|
||||
sbEn.append("Market" + ":" + "-- ");
|
||||
}
|
||||
@@ -255,6 +308,12 @@ public class ProblemKnowledgeBaseEOServiceImpl extends ServiceImpl<ProblemKnowle
|
||||
}else {
|
||||
sbEn.append("Content" + ":" + "-- ");
|
||||
}
|
||||
|
||||
if(StringUtils.isNotEmpty(fileText)){
|
||||
sbEn.append("Accessory File content" + ":" + fileText + " ");
|
||||
}else {
|
||||
sbEn.append("Accessory File content" + ":" + "-- ");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+43
-5
@@ -1091,12 +1091,14 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
|
||||
String selectValue = (String) map.get("selectValue");
|
||||
String selectValueTwo = (String) map.get("selectValueTwo");
|
||||
String problem_type = (String) map.get("problem_type");
|
||||
String target_market = (String) map.get("target_market");
|
||||
//1. 需要查询的字段
|
||||
List<String> fieldList = new ArrayList<>();
|
||||
fieldList.add("title");//权重5
|
||||
fieldList.add("file_text");//权重4
|
||||
fieldList.add("content");//权重3
|
||||
fieldList.add("file_name"); //权重2
|
||||
fieldList.add("content");//权重4
|
||||
// fieldList.add("problem_type");//权重3
|
||||
// fieldList.add("target_market"); //权重2
|
||||
fieldList.add("module_type");
|
||||
fieldList.add("id");
|
||||
fieldList.add("flag");
|
||||
@@ -1104,6 +1106,8 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
JSONArray queryMapJson = new JSONArray();
|
||||
JSONArray queryMapJsonTwo = new JSONArray();
|
||||
JSONArray queryMapJsonThree = new JSONArray();
|
||||
JSONArray queryMapJsonProblemType = new JSONArray();
|
||||
JSONArray queryMapJsonTargetMarket = new JSONArray();
|
||||
JSONArray queryMapJsonAll = new JSONArray();
|
||||
|
||||
Map<String,Object> mapHighlight = new HashMap<>();
|
||||
@@ -1136,6 +1140,40 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
}
|
||||
mapHighlight1.put("fields",mapHighlight);
|
||||
}
|
||||
|
||||
//封装问题类型选择框查询条件。
|
||||
if (StringUtils.isNotBlank(problem_type)) {
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
Map<String, Object> map4 = new HashMap<>();
|
||||
|
||||
map3.put("query",problem_type);
|
||||
map2.put("problem_type", map3);
|
||||
map4.put("match",map2);
|
||||
queryMapJson.add(map4);
|
||||
//高亮
|
||||
highlight(mapHighlight, problem_type);
|
||||
|
||||
mapHighlight1.put("fields",mapHighlight);
|
||||
}
|
||||
|
||||
//封装市场选择框查询条件。
|
||||
if (StringUtils.isNotBlank(target_market)) {
|
||||
Map<String, Object> map2 = new HashMap<>();
|
||||
Map<String, Object> map3 = new HashMap<>();
|
||||
Map<String, Object> map4 = new HashMap<>();
|
||||
|
||||
map3.put("query",target_market);
|
||||
map2.put("target_market", map3);
|
||||
map4.put("match",map2);
|
||||
queryMapJson.add(map4);
|
||||
//高亮
|
||||
highlight(mapHighlight, target_market);
|
||||
|
||||
mapHighlight1.put("fields",mapHighlight);
|
||||
}
|
||||
|
||||
|
||||
if(CollectionUtils.isNotEmpty(queryMapJson)){
|
||||
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson);
|
||||
queryMapJsonAll.add(jsonObject);
|
||||
@@ -1253,9 +1291,9 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
|
||||
mapSource.put(key,fieldConyent);
|
||||
}
|
||||
//如果这一条数据中有高亮字段值,但是file_text中没有高亮值, 则赋控制,否则列表中会展示所有的文件内容, 赋空后,则展示基础数据
|
||||
String fileText = (String) mapSource.get("file_text");
|
||||
String fileText = (String) mapSource.get("content");
|
||||
if(StringUtils.isNotBlank(fileText) && !fileText.contains("<text class='highlight-class'>")){
|
||||
mapSource.put("file_text","");
|
||||
mapSource.put("content","");
|
||||
}
|
||||
}
|
||||
mapList.add(mapSource);
|
||||
|
||||
Reference in New Issue
Block a user