diff --git a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/problemKnowledgeBase/service/impl/ProblemKnowledgeBaseEOServiceImpl.java b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/problemKnowledgeBase/service/impl/ProblemKnowledgeBaseEOServiceImpl.java index 036574e31..acb14a326 100644 --- a/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/problemKnowledgeBase/service/impl/ProblemKnowledgeBaseEOServiceImpl.java +++ b/jero-boot/jero-boot-modules/src/main/java/com/jero/modules/problemKnowledgeBase/service/impl/ProblemKnowledgeBaseEOServiceImpl.java @@ -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> mapListTempCn = new ArrayList<>(); List> mapListTempEn = new ArrayList<>(); + //查询该数据的文件。 + StringBuffer fileTextSb = new StringBuffer(); + List 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 stringMapCn = new HashMap<>(); this.problemKnowledgeBaseEOConvertMapByCut(problemKnowledgeBaseEO,CutEnum.EN.getValue(),stringMapCn); @@ -169,7 +216,7 @@ public class ProblemKnowledgeBaseEOServiceImpl extends ServiceImpl 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 mapHighlight = new HashMap<>(); @@ -1136,6 +1140,40 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService { } mapHighlight1.put("fields",mapHighlight); } + + //封装问题类型选择框查询条件。 + if (StringUtils.isNotBlank(problem_type)) { + Map map2 = new HashMap<>(); + Map map3 = new HashMap<>(); + Map 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 map2 = new HashMap<>(); + Map map3 = new HashMap<>(); + Map 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("")){ - mapSource.put("file_text",""); + mapSource.put("content",""); } } mapList.add(mapSource);