文档库--段落

This commit is contained in:
zhn
2022-03-25 17:49:35 +08:00
parent 1ebea886cb
commit 1e32857c0f
5 changed files with 104 additions and 36 deletions
@@ -340,7 +340,7 @@ public class JeroElasticsearchTemplate {
action.put("create", actionInfo);
bodySB.append(action.toJSONString()).append("\n");
// 该行的数据
data.remove("id");
// data.remove("id");
bodySB.append(data.toJSONString()).append("\n");
}
System.out.println("+-+-+-: bodySB.toString(): " + bodySB.toString());
@@ -1064,13 +1064,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
} catch (Exception e) {
e.printStackTrace();
}
// Map<String,Object> mapFullText = new HashMap<>();
// mapFullText.put("id", idTemp);
// mapFullText.put("module_type", "文档库");
// mapFullText.put("serial_number", map.get("serial_number"));
// mapFullText.put("title", map.get("title"));
// mapFullText.put("file_text", fileTextList);
// mapFullText.put("content", sb.toString());
//多文件es iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
List<String> fileIdList = oSSFileAll.stream().map(OSSFile::getId).collect(Collectors.toList());
List<OSSFile> fileInfos = iOSSFileService.getFileInfos(StringUtils.join(fileIdList, ","));
@@ -1130,6 +1123,9 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
mapListTemp.add(stringMap);
}
} catch (Exception e) {
log.error("文档库新增es错误");
}
@@ -1457,11 +1453,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
}
if(oSSFileList.size() != 0){
oSSFileAll.addAll(oSSFileList);
//读取word或PDF文件内容
// List<String> list = readFileContent(oSSFileList);
// if(list.size() != 0){
// fileTextList.add(list) ;
// }
}
iOSSFileService.updateFileInfo(oSSFileList);
valuesBuilder.append("'" + valueTemp + "'" + ",");
@@ -1470,11 +1461,6 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
OSSFile ossFile = new OSSFile();
ossFile.setId((String) value);
oSSFileList.add(ossFile);
//读取word或PDF文件内容
// List<String> list = readFileContent(oSSFileList);
// if (list.size() != 0) {
// fileTextList.add(list);
// }
valuesBuilder.append("'" + value + "'" + ",");
}
} else {
@@ -1552,6 +1538,14 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
stringMap.put("content", sb.toString());
stringMap.put("file_text","");
stringMap.put("file_name","");
//下拉框,日期,属性字段也存入到es中
// Map<String,Object> hashMap = new HashMap<>();
// for (Map.Entry<String, Object> entry : map.entrySet()) {
// if(fieldListTemp.contains(entry.getKey())){
// hashMap.put(entry.getKey(),entry.getValue());
// }
// }
// mapCopy(hashMap, stringMap);
mapListTemp.add(stringMap);
}
@@ -1582,12 +1576,14 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
bussDocumentLibraryEOMapper.insertInfo(insertField, insertValue);
map.put("module_type", "文档库");
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(map));
JSONObject jsonObjectAll = JSON.parseObject(JSON.toJSONString(mapFullText));
JSONArray array= JSONArray.parseArray(JSON.toJSONString(mapListTemp));
// JSONObject jsonObjectAll = JSON.parseObject(JSON.toJSONString(mapFullText));
//修改es
try {
jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.INDEX_NAME_DOCUMENT.getValue(), SearchEnum.TYPE_NAME_DOCUMENT.getValue(), (String) map.get("id"), jsonObject);
//添加全文
jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), (String) map.get("id"), jsonObjectAll);
jeroElasticsearchTemplate.saveBatch(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), array);
// jeroElasticsearchTemplate.saveOrUpdate(SearchEnum.FULL_TEXT_SEARCH.getValue(), SearchEnum.FULL_TEXT_SEARCH.getValue(), (String) map.get("id"), jsonObjectAll);
} catch (Exception e) {
log.error("文档库编辑es失败");
}
@@ -78,6 +78,13 @@ public class DocumentSearchController {
return Result.OK(pageInfo);
}
@ApiOperation(value="文档库查询段落", notes="文档库查询段落")
@PostMapping(value = "/getParagraphInfoList")
public Result<?> getParagraphInfoList(@RequestBody Map<String,Object> map) {
IPage pageInfo = iDocumentSearchService.getParagraphInfoList(map);
return Result.OK(pageInfo);
}
@ApiOperation(value="根据id删除", notes="根据id删除")
@@ -23,6 +23,7 @@ import com.jero.modules.system.service.impl.SysCategoryServiceImpl;
import com.jero.modules.system.service.impl.SysDictItemServiceImpl;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -181,6 +182,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
return page;
}
private void queryCondition(Map<String, Object> mapOne, List<String> inputFieldList, List<String> otherFieldList, JSONArray must) {
Map<String, Object> inputMap = new HashMap<>();//条件内容为输入框的
Map<String, Object> otherMap = new HashMap<>();//条件内容为下拉,日期,树形
@@ -413,6 +415,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
fieldList.add("file_text");
fieldList.add("content");
fieldList.add("file_name");
fieldList.add("id");
JSONArray queryMapJson = new JSONArray();
if(StringUtils.isNotBlank(selectValue)){
@@ -424,8 +427,27 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
queryMapJson.add(queryMap);
}
}
//处理二次查询中选择了课表数据进行查询的情况
if(StringUtils.isNotBlank(searchVO.getIds())){
for (String s : searchVO.getIds().split(",")) {
Map<String, Object> queryMap = new HashMap<>();
Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put("id", s);
queryMap.put("match", queryMapTemp);
queryMapJson.add(queryMap);
}
}
Integer pageNo = searchVO.getPage();
Integer pageSize = searchVO.getPageSize();
IPage page = getiPage(selectValue, selectValueTwo, queryMapJson, pageNo, pageSize);
return page;
}
@NotNull
private IPage getiPage(String selectValue, String selectValueTwo, JSONArray queryMapJson, Integer pageNo, Integer pageSize) {
//基础添加封装
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(null, null, queryMapJson);
//全部
@@ -434,8 +456,8 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
jsonObject,
null,
null,
searchVO.getPage(),
searchVO.getPageSize());
pageNo,
pageSize);
// JSONObject queryObject11 = jeroElasticsearchTemplate.buildQuery(null, jsonObject11,highlightMap,null, Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
//2. 数据查询
JSONObject search = jeroElasticsearchTemplate.search(SearchEnum.FULL_TEXT_SEARCH.getValue(),
@@ -455,10 +477,10 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
//二次搜索结果
List<Map<String, Object>> mapListTwo = new ArrayList<>();
//如果勾选了列表数据,则先通过ids过滤一遍数据
if (list.size() != 0 && StringUtils.isNotBlank(searchVO.getIds())) {
list = list.stream().filter(e -> searchVO.getIds().contains((String) e.get("id"))).collect(Collectors.toList());
}
// //如果勾选了列表数据,则先通过ids过滤一遍数据
// if (list.size() != 0 && StringUtils.isNotBlank(searchVO.getIds())) {
// list = list.stream().filter(e -> searchVO.getIds().contains((String) e.get("id"))).collect(Collectors.toList());
// }
List<Map<String, Object>> listNew = new ArrayList<>();
for (Map<String, Object> stringObjectMap : list) {
@@ -519,18 +541,10 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
//截取第一处高亮的前后100个字符
value = getFileText(value, selectValue);
}
// else{
// mapSource.put("file_text_flag","flag");
// }
}
if("content".equals(key)){
//判断value中是否包含搜索中的字符
boolean flag = judgeContains(value, selectValue);
// if(flag){
// mapSource.put("content_flag","true");
// }else{
// mapSource.put("content_flag","false");
// }
}
for (int i = 0; i < value.length(); i++) {
String chStr = String.valueOf(value.charAt(i));
@@ -551,7 +565,7 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
//处理分页
IPage page = new Page(searchVO.getPage(), searchVO.getPageSize());
IPage page = new Page(pageNo, pageSize);
if (StringUtils.isNotBlank(selectValueTwo)) {
//二次搜索的结果
page.setTotal(Long.parseLong(String.valueOf(((Map) search.get("hits")).get("total"))));
@@ -562,7 +576,6 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
page.setRecords(mapList);
}
return page;
}
private String getFileText(String fileTextInfo,String selectValue){
@@ -635,4 +648,54 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
}
/**
* 查询段落
* @param map
* @return
*/
@Override
public IPage getParagraphInfoList(Map<String, Object> map) {
//module_type 代表文档库的段落
//判断索引是否存在
boolean flagTemp = jeroElasticsearchTemplate.indexExists(SearchEnum.FULL_TEXT_SEARCH.getValue());
if(!flagTemp){
return new Page(Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
}
//文档库所有的字段
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList(ModuleEnum.DOCUMENT_LIBRARY.getValue());
//输入框字段
List<OnlCgformField> inputOnlCgformFieldList = fieldList.stream()
.filter(e -> FieldTypeEnum.TEXT_STRING.getValue().equals(e.getFieldShowType())
|| FieldTypeEnum.TEXT_NUMBER.getValue().equals(e.getFieldShowType()))
.collect(Collectors.toList());
List<String> inputFieldList = inputOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
//下拉,树形,日期等字段
List<OnlCgformField> otherOnlCgformFieldList = fieldList.stream()
.filter(e -> FieldTypeEnum.PULL_SINGLE.getValue().equals(e.getFieldShowType())//下拉单选
|| FieldTypeEnum.PULL_MORE.getValue().equals(e.getFieldShowType())//下拉多选
|| FieldTypeEnum.DATE_SINGLE.getValue().equals(e.getFieldShowType())//日期单选
|| FieldTypeEnum.DATE_MORE.getValue().equals(e.getFieldShowType())//日期多选
|| FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType()))//树形
.collect(Collectors.toList());
List<String> otherFieldList = otherOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
Map<String, Object> mapOne = (Map<String, Object>) map.get("mapOne");
Map<String, Object> mapTwo = (Map<String, Object>) map.get("mapTwo");
JSONArray must = new JSONArray();
//处理首次查询条件
if(ObjectUtils.isNotEmpty(mapOne)){
queryCondition(mapOne, inputFieldList, otherFieldList, must);
}
//处理二次查询条件
if(ObjectUtils.isNotEmpty(mapTwo)){
queryCondition(mapTwo, inputFieldList, otherFieldList, must);
}
int pageNo = Integer.parseInt(map.get("pageNo").toString());
int pageSize = Integer.parseInt(map.get("pageSize").toString());
getiPage(null,null,must,pageNo,pageSize);
return null;
}
}
@@ -19,6 +19,8 @@ public interface IDocumentSearchService {
IPage getInfoList(Map<String, Object> map);
IPage getParagraphInfoList(Map<String, Object> map);
IPage getFullTextInfoList(SearchVO searchVO);
void deleteById(String ids);