Commit 044fa535 by 李小惠

Merge branch 'develop' of http://gitlab.sothing.top/843502640/jyzb_platformV2 into develop-lxh

parents 03f32cbb ddf521a6
...@@ -13,6 +13,7 @@ public class QueryOrgReq { ...@@ -13,6 +13,7 @@ public class QueryOrgReq {
private String orgCode; private String orgCode;
@NotNull(message = "组织机构不能为空",groups = {ValidationApi.detail.class}) @NotNull(message = "组织机构不能为空",groups = {ValidationApi.detail.class})
private Long orgId; private Long orgId;
private Long currentOrg;
private String orgName; private String orgName;
private Long parentId; private Long parentId;
private Integer isDepartment; private Integer isDepartment;
......
...@@ -158,7 +158,11 @@ public class PubOrg implements Serializable { ...@@ -158,7 +158,11 @@ public class PubOrg implements Serializable {
*/ */
@TableField(value = "d_name") @TableField(value = "d_name")
private String dName; private String dName;
// /**
// * dName2
// */
// @TableField(value = "dName")
// private String dName;
/** /**
* 联系人 * 联系人
*/ */
......
...@@ -10,10 +10,14 @@ import com.junmp.jyzb.api.bean.req.UpdateOrgReq; ...@@ -10,10 +10,14 @@ import com.junmp.jyzb.api.bean.req.UpdateOrgReq;
import com.junmp.jyzb.api.exception.JYZBAppException; import com.junmp.jyzb.api.exception.JYZBAppException;
import com.junmp.jyzb.api.exception.enums.OrgExceptionEnum; import com.junmp.jyzb.api.exception.enums.OrgExceptionEnum;
import com.junmp.jyzb.api.exception.enums.PubOrgExceptionEnum; import com.junmp.jyzb.api.exception.enums.PubOrgExceptionEnum;
import com.junmp.jyzb.entity.EquipmentType;
import com.junmp.jyzb.entity.PubOrg; import com.junmp.jyzb.entity.PubOrg;
import com.junmp.jyzb.utils.*; import com.junmp.jyzb.utils.*;
import com.junmp.v2.auth.api.context.LoginContext;
import com.junmp.v2.common.exception.base.ServiceException; import com.junmp.v2.common.exception.base.ServiceException;
import com.junmp.v2.common.util.BeanPlusUtil; import com.junmp.v2.common.util.BeanPlusUtil;
import com.junmp.v2.sys.user.entity.SysUser;
import com.junmp.v2.sys.user.service.SysUserService;
import org.elasticsearch.action.search.ClearScrollRequest; import org.elasticsearch.action.search.ClearScrollRequest;
import org.elasticsearch.action.search.SearchRequest; import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.action.search.SearchResponse;
...@@ -44,7 +48,8 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -44,7 +48,8 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
private PubOrgMapper pubOrgMapper; private PubOrgMapper pubOrgMapper;
@Resource @Resource
private RestHighLevelClient client; private RestHighLevelClient client;
@Resource
private SysUserService sysUserService;
@Autowired @Autowired
private RedisUtils redisUtils; private RedisUtils redisUtils;
@Autowired @Autowired
...@@ -372,8 +377,7 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -372,8 +377,7 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
* @return * @return
* @throws IOException * @throws IOException
*/ */
public List<PubOrg> searchOrg(Integer pageNum, Integer pageSize, String keyword) throws IOException { public List<PubOrg> searchOrg(Integer pageNum, Integer pageSize, String keyword, Long currentOrg) throws IOException {
if (pageNum < 0) pageNum = 0; if (pageNum < 0) pageNum = 0;
SearchRequest request = new SearchRequest("org_pinyin"); SearchRequest request = new SearchRequest("org_pinyin");
...@@ -383,16 +387,20 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -383,16 +387,20 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
builder.size(pageSize); builder.size(pageSize);
// 添加 MatchQueryBuilder 作为 must 条件 // 添加 MatchQueryBuilder 作为 must 条件
MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("dName", keyword).operator(Operator.AND); MatchQueryBuilder matchQueryBuilder = QueryBuilders.matchQuery("dName", keyword).operator(Operator.AND);
// MatchQueryBuilder matchQueryBuilder2 = QueryBuilders.matchQuery("dName.pinyin", keyword).operator(Operator.AND);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.should(matchQueryBuilder); boolQueryBuilder.must(matchQueryBuilder);
// boolQueryBuilder.should(matchQueryBuilder2);
// 添加过滤条件,只获取 delFlag 为 1 的数据 // 添加过滤条件,只获取 delFlag 为 1 的数据
builder.postFilter(QueryBuilders.termQuery("delFlag", 1)); boolQueryBuilder.filter(QueryBuilders.termQuery("delFlag", 1));
// 添加过滤条件,orgParentIds 包含当前字段,或者 orgId 等于当前字段
BoolQueryBuilder orgFilter = QueryBuilders.boolQuery();
orgFilter.should(QueryBuilders.wildcardQuery("orgParentIds", "*" + currentOrg + "*"));
orgFilter.should(QueryBuilders.termQuery("orgId", currentOrg.toString()));
boolQueryBuilder.filter(orgFilter);
builder.query(boolQueryBuilder); builder.query(boolQueryBuilder);
builder.timeout(new TimeValue(60, TimeUnit.SECONDS)); builder.timeout(new TimeValue(60, TimeUnit.SECONDS));
...@@ -412,6 +420,42 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -412,6 +420,42 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
} }
/**
* 搜索条件
* @param pageNum
* @param pageSize
* @return
* @throws IOException
*/
public List<PubOrg> searchAll(Integer pageNum, Integer pageSize ) throws IOException {
if (pageNum < 0) pageNum = 0;
SearchRequest request = new SearchRequest("org_pinyin");
SearchSourceBuilder builder = new SearchSourceBuilder();
builder.from(pageNum);
builder.size(pageSize);
// 添加过滤条件,只获取 delFlag 为 1 的数据
builder.postFilter(QueryBuilders.termQuery("delFlag", 1));
builder.timeout(new TimeValue(60, TimeUnit.SECONDS));
request.source(builder);
SearchResponse searchResponse = client.search(request, RequestOptions.DEFAULT);
List<PubOrg> pubOrgList = new ArrayList<>();
for (SearchHit documentFields : searchResponse.getHits().getHits()) {
Map<String, Object> sourceAsMap = documentFields.getSourceAsMap();
PubOrg pubOrg = this.fromMap(sourceAsMap);
// 添加到结果列表
pubOrgList.add(pubOrg);
}
return pubOrgList;
}
public List<OrgDto> buildTree(List<PubOrg> searchResults, List<PubOrg> allOrgs) { public List<OrgDto> buildTree(List<PubOrg> searchResults, List<PubOrg> allOrgs) {
Map<Long, OrgDto> orgDtoMap = new HashMap<>(); Map<Long, OrgDto> orgDtoMap = new HashMap<>();
...@@ -506,13 +550,13 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem ...@@ -506,13 +550,13 @@ public class PubOrgServiceImpl extends ServiceImpl<PubOrgMapper, PubOrg> implem
@Override @Override
public ESOrgDto getOrgTreeByEs(QueryOrgReq req) throws IOException { public ESOrgDto getOrgTreeByEs(QueryOrgReq req) throws IOException {
// 先进行搜索,获取前20条数据 // 先进行搜索,获取前20条数据
List<PubOrg> searchResults = searchOrg(0, 10, req.getOrgName()); List<PubOrg> searchResults = searchOrg(0, 20, req.getOrgName(),req.getCurrentOrg());
req.setDelFlag(1); req.setDelFlag(1);
LambdaQueryWrapper<PubOrg> wp = this.createWrapper(req);
// 获取所有组织机构数据 // 获取所有组织机构数据
List<PubOrg> allOrgs = this.list(wp); List<PubOrg> orgsAll=searchAll(0, 3000);
List<OrgDto> treeResult= buildTree(searchResults,allOrgs); List<OrgDto> treeResult= buildTree(searchResults,orgsAll);
ESOrgDto resultDto =new ESOrgDto(); ESOrgDto resultDto =new ESOrgDto();
resultDto.setOrgDto(treeResult); resultDto.setOrgDto(treeResult);
SetIds(treeResult); SetIds(treeResult);
......
...@@ -37,6 +37,7 @@ public class ElasticsearchUtil<T> { ...@@ -37,6 +37,7 @@ public class ElasticsearchUtil<T> {
builder.size(pageSize); builder.size(pageSize);
BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery(); BoolQueryBuilder boolQueryBuilder = QueryBuilders.boolQuery();
boolQueryBuilder.mustNot(QueryBuilders.matchQuery("name", "超级根")); boolQueryBuilder.mustNot(QueryBuilders.matchQuery("name", "超级根"));
builder.query(boolQueryBuilder); builder.query(boolQueryBuilder);
builder.timeout(new TimeValue(60, TimeUnit.SECONDS)); builder.timeout(new TimeValue(60, TimeUnit.SECONDS));
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论