文档库--修改数据格式

This commit is contained in:
zhn
2022-03-15 17:48:06 +08:00
parent 0c93a4278d
commit 18fe584df1
4 changed files with 84 additions and 60 deletions
@@ -1808,7 +1808,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
* @param entry * @param entry
* @param collect * @param collect
*/ */
private void dictItem(List<SysDictItem> sysDictItems, Map.Entry<String, Object> entry, List<OnlCgformField> collect, String cut) { public void dictItem(List<SysDictItem> sysDictItems, Map.Entry<String, Object> entry, List<OnlCgformField> collect, String cut) {
Map<String, Object> map = new HashMap<>(); Map<String, Object> map = new HashMap<>();
//通过dictField判断字段是否为下拉选(不为空则为下拉选) //通过dictField判断字段是否为下拉选(不为空则为下拉选)
if (collect.size() != 0 && StringUtils.isNotBlank(collect.get(0).getDictField())) { if (collect.size() != 0 && StringUtils.isNotBlank(collect.get(0).getDictField())) {
@@ -2590,7 +2590,7 @@ public class BussDocumentLibraryEOServiceImpl extends ServiceImpl<BussDocumentLi
* @param treeFieldList * @param treeFieldList
* @param cut * @param cut
*/ */
private void treeDictItem(List<SysCategory> categoryList, Map.Entry<String, Object> entry, List<OnlCgformField> treeFieldList, String cut) { public void treeDictItem(List<SysCategory> categoryList, Map.Entry<String, Object> entry, List<OnlCgformField> treeFieldList, String cut) {
List<String> treeFields = treeFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList()); List<String> treeFields = treeFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
String key = entry.getKey(); String key = entry.getKey();
if (treeFields.contains(entry.getKey())) { if (treeFields.contains(entry.getKey())) {
@@ -1,9 +1,8 @@
package com.jero.modules.searchcenter.controller; package com.jero.modules.searchcenter.controller;
import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jero.common.api.vo.Result; import com.jero.common.api.vo.Result;
import com.jero.common.aspect.annotation.AutoLog; import com.jero.common.aspect.annotation.AutoLog;
import com.jero.modules.searchcenter.service.impl.DocumentSearchServiceImpl;
import com.jero.modules.searchcenter.service.impl.IDocumentSearchService; import com.jero.modules.searchcenter.service.impl.IDocumentSearchService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
@@ -14,7 +13,6 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -66,7 +64,7 @@ public class DocumentSearchController {
@ApiOperation(value="列表查询", notes="列表查询") @ApiOperation(value="列表查询", notes="列表查询")
@GetMapping(value = "/getInfoList") @GetMapping(value = "/getInfoList")
public Result<?> getInfoList(@RequestParam Map<String,Object> map) { public Result<?> getInfoList(@RequestParam Map<String,Object> map) {
JSONObject infoList = iDocumentSearchService.getInfoList(map); IPage infoList = iDocumentSearchService.getInfoList(map);
return Result.OK(infoList); return Result.OK(infoList);
} }
} }
@@ -1,27 +1,29 @@
package com.jero.modules.searchcenter.service.impl; package com.jero.modules.searchcenter.service.impl;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jero.common.constant.enums.ModuleEnum; import com.jero.common.constant.enums.ModuleEnum;
import com.jero.common.constant.enums.YesOrNoEnum; import com.jero.common.constant.enums.YesOrNoEnum;
import com.jero.common.es.JeroElasticsearchTemplate; import com.jero.common.es.JeroElasticsearchTemplate;
import com.jero.common.es.QueryStringBuilder;
import com.jero.generater.modules.online.cgform.entity.OnlCgformField; import com.jero.generater.modules.online.cgform.entity.OnlCgformField;
import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl; import com.jero.generater.modules.online.cgform.service.impl.OnlCgformFieldServiceImpl;
import com.jero.modules.document.enums.FieldTypeEnum; import com.jero.modules.document.enums.FieldTypeEnum;
import com.jero.modules.document.service.IBussDocumentLibraryEOService; import com.jero.modules.document.service.IBussDocumentLibraryEOService;
import io.swagger.annotations.ApiOperation; import com.jero.modules.document.service.impl.BussDocumentLibraryEOServiceImpl;
import com.jero.modules.system.entity.SysCategory;
import com.jero.modules.system.entity.SysDictItem;
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.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.regex.Pattern;
import java.util.stream.Collectors; import java.util.stream.Collectors;
/** /**
@@ -37,24 +39,29 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
private JeroElasticsearchTemplate jeroElasticsearchTemplate; private JeroElasticsearchTemplate jeroElasticsearchTemplate;
@Autowired @Autowired
private OnlCgformFieldServiceImpl onlCgformFieldService; private OnlCgformFieldServiceImpl onlCgformFieldService;
@Autowired
private SysCategoryServiceImpl sysCategoryService;
@Autowired
private SysDictItemServiceImpl sysDictItemServiceImpl;
@Autowired
private BussDocumentLibraryEOServiceImpl bussDocumentLibraryEOService;
@Override @Override
public List<Map<String, Object>> queryCondition(String flag, String cut,String searchFlag) { public List<Map<String, Object>> queryCondition(String flag, String cut, String searchFlag) {
List<Map<String, Object>> mapList = iBussDocumentLibraryEOService.queryCondition(flag, cut, searchFlag); List<Map<String, Object>> mapList = iBussDocumentLibraryEOService.queryCondition(flag, cut, searchFlag);
//type = 0时,查询下拉,树形,日期等字段 type = 1时,查询输入框字段 //type = 0时,查询下拉,树形,日期等字段 type = 1时,查询输入框字段
return mapList; return mapList;
} }
@Override @Override
public List<Map<String, Object>> getHeader(String flag, String cut,String searchFlag) { public List<Map<String, Object>> getHeader(String flag, String cut, String searchFlag) {
List<Map<String, Object>> header = iBussDocumentLibraryEOService.getHeader(flag, cut, searchFlag); List<Map<String, Object>> header = iBussDocumentLibraryEOService.getHeader(flag, cut, searchFlag);
return header; return header;
} }
@Override @Override
public JSONObject getInfoList(Map<String,Object> map) { public IPage getInfoList(Map<String, Object> map) {
//文档库所有的字段 //文档库所有的字段
List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList(ModuleEnum.DOCUMENT_LIBRARY.getValue()); List<OnlCgformField> fieldList = onlCgformFieldService.getFieldList(ModuleEnum.DOCUMENT_LIBRARY.getValue());
//需要查询的列表字段 //需要查询的列表字段
@@ -77,77 +84,96 @@ public class DocumentSearchServiceImpl implements IDocumentSearchService {
.collect(Collectors.toList()); .collect(Collectors.toList());
List<String> otherFieldList = otherOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldEnName).collect(Collectors.toList()); List<String> otherFieldList = otherOnlCgformFieldList.stream().map(OnlCgformField::getDbFieldEnName).collect(Collectors.toList());
Map<String,Object> inputMap = new HashMap<>();//条件内容为输入框的 //过滤出下拉选
Map<String,Object> otherMap = new HashMap<>();//条件内容为下拉,日期,树形 List<OnlCgformField> onlCgformFieldList = fieldList.stream()
.filter(e -> FieldTypeEnum.PULL_SINGLE.getValue().equals(e.getFieldShowType())
|| FieldTypeEnum.PULL_MORE.getValue().equals(e.getFieldShowType()))
.collect(Collectors.toList());
//下拉选字段
List<String> fieldPullList = onlCgformFieldList.stream().map(OnlCgformField::getDbFieldName).collect(Collectors.toList());
//过滤出树形字段
List<OnlCgformField> treeFieldList = fieldList.stream()
.filter(e -> FieldTypeEnum.TREE.getValue().equals(e.getFieldShowType()))
.collect(Collectors.toList());
Map<String, Object> inputMap = new HashMap<>();//条件内容为输入框的
Map<String, Object> otherMap = new HashMap<>();//条件内容为下拉,日期,树形
//区分输入框和下拉,树形,日期等字段 //区分输入框和下拉,树形,日期等字段
if(ObjectUtils.isNotEmpty(map)){ if (ObjectUtils.isNotEmpty(map)) {
for (Map.Entry<String, Object> entry : map.entrySet()) { for (Map.Entry<String, Object> entry : map.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
if(inputFieldList.contains(key)){ if (inputFieldList.contains(key)) {
inputMap.put(key,value); inputMap.put(key, value);
} }
if(otherFieldList.contains(key)){ if (otherFieldList.contains(key)) {
otherMap.put(key,value); otherMap.put(key, value);
} }
} }
} }
JSONArray should = new JSONArray(); JSONArray should = new JSONArray();
//封装输入框查询条件 //封装输入框查询条件
if(ObjectUtils.isNotEmpty(inputMap)){ if (ObjectUtils.isNotEmpty(inputMap)) {
Map<String,Object> queryMap = new HashMap<>(); Map<String, Object> queryMap = new HashMap<>();
for (Map.Entry<String, Object> entry : inputMap.entrySet()) { for (Map.Entry<String, Object> entry : inputMap.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
Map<String,Object> queryMapTemp = new HashMap<>(); Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put(key,value); queryMapTemp.put(key, value);
queryMap.put("match",queryMapTemp); queryMap.put("match", queryMapTemp);
} }
} }
//封装下拉,树形,日期查询条件 //封装下拉,树形,日期查询条件
JSONArray must = new JSONArray(); JSONArray must = new JSONArray();
if(ObjectUtils.isNotEmpty(otherMap)){ if (ObjectUtils.isNotEmpty(otherMap)) {
for (Map.Entry<String, Object> entry : otherMap.entrySet()) { for (Map.Entry<String, Object> entry : otherMap.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
Object value = entry.getValue(); Object value = entry.getValue();
Map<String,Object> queryMap = new HashMap<>(); Map<String, Object> queryMap = new HashMap<>();
Map<String,Object> queryMapTemp = new HashMap<>(); Map<String, Object> queryMapTemp = new HashMap<>();
queryMapTemp.put(key,value); queryMapTemp.put(key, value);
queryMap.put("match",queryMapTemp); queryMap.put("match", queryMapTemp);
must.add(queryMap); must.add(queryMap);
} }
} }
// String indexName = "documentLibrary"; // String indexName = "documentLibrary";
// String typeName = "document"; // String typeName = "document";
JSONObject search = null;
try {
//封装查询条件 //封装查询条件
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(must, null, null);
// Map<String,Object> queryMap = new HashMap<>(); //封装分页和字段值
// Map<String,Object> queryMap2 = new HashMap<>(); JSONObject queryObject = jeroElasticsearchTemplate.buildQuery(sourceList, jsonObject, null, Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
// queryMap2.put("serial_number","1332");
// queryMap.put("term",queryMap2);
// must.add(queryMap);
//
JSONObject jsonObject = jeroElasticsearchTemplate.buildBoolQuery(must, null, null);
//封装分页和字段值
// JSONObject queryObject = jeroElasticsearchTemplate.buildQuery(sourceList, jsonObject,null, 0,10);
JSONObject queryObject = jeroElasticsearchTemplate.buildQuery(sourceList, jsonObject,null, Integer.parseInt(map.get("pageNo").toString()),Integer.parseInt(map.get("pageSize").toString()));
// //
//数据查询 //数据查询
search = jeroElasticsearchTemplate.search("documentLibrary", "document", queryObject); JSONObject search = jeroElasticsearchTemplate.search("documentLibrary", "document", queryObject);
// Map map1 = JSONObject.parseObject(search.toJSONString(), Map.class); //处理数据字典
// String s = search.toJSONString(); List<SysDictItem> sysDictItems = sysDictItemServiceImpl.selectItemsAll();//下拉数据字典
// Map<String,Object> map2 = JSON.parseObject(search.toJSONString(), Map.class); List<SysCategory> categoryList = sysCategoryService.list();//树形数据字典
// List<Map<String,Object>> list = ((Map) search.get("hits")).get("hits"); List<Map<String, Object>> list = (List<Map<String, Object>>) (((Map) search.get("hits")).get("hits"));
} catch (Exception e) { List<Map<String, Object>> mapList = new ArrayList<>();
e.printStackTrace(); for (Map<String, Object> stringObjectMap : list) {
Map<String, Object> mapTemp = (Map<String, Object>) stringObjectMap.get("_source");
mapList.add(mapTemp);
mapTemp.entrySet().forEach(entry -> {
//下拉选处理数据字典
bussDocumentLibraryEOService.treeDictItem(categoryList, entry, treeFieldList, (String) map.get("cut"));
});
//下拉单选和下拉多选数据字典处理
mapTemp.entrySet().forEach(entry -> {
if (fieldPullList.contains(entry.getKey())) {
//下拉选处理数据字典
bussDocumentLibraryEOService.dictItem(sysDictItems, entry, onlCgformFieldList, (String) map.get("cut"));
}
});
} }
return search; IPage page = new Page(Integer.parseInt(map.get("pageNo").toString()), Integer.parseInt(map.get("pageSize").toString()));
page.setTotal(Long.parseLong(String.valueOf(((Map) search.get("hits")).get("total"))));
page.setRecords(mapList);
return page;
} }
@@ -1,6 +1,6 @@
package com.jero.modules.searchcenter.service.impl; package com.jero.modules.searchcenter.service.impl;
import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.metadata.IPage;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@@ -12,10 +12,10 @@ import java.util.Map;
*/ */
public interface IDocumentSearchService { public interface IDocumentSearchService {
List<Map<String, Object>> queryCondition(String flag, String cut,String searchFlag); List<Map<String, Object>> queryCondition(String flag, String cut, String searchFlag);
List<Map<String, Object>> getHeader(String flag, String cut,String searchFla); List<Map<String, Object>> getHeader(String flag, String cut, String searchFla);
JSONObject getInfoList(Map<String,Object> map); IPage getInfoList(Map<String, Object> map);
} }