Commit 87e4155e authored by tianyiming's avatar tianyiming

refactor: 提取人员过滤条件构建逻辑到新方法

parent f7b6a819
...@@ -320,7 +320,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -320,7 +320,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} }
// 组装人员过滤条件 // 组装人员过滤条件
String orgCode = filter.getString("orgCode"); String orgCode = filter.getString("orgCode");
this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType, orgCode); personOrgCodeBoolMust(orgCode, boolMust);
this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType);
if ("custom".equals(filterType)) { if ("custom".equals(filterType)) {
JSONArray leftGroup = filterParams.getJSONArray("group1"); JSONArray leftGroup = filterParams.getJSONArray("group1");
JSONArray rightGroup = filterParams.getJSONArray("group2"); JSONArray rightGroup = filterParams.getJSONArray("group2");
...@@ -400,31 +401,27 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -400,31 +401,27 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
return result; return result;
} }
private void personOrgCodeBoolMust(String orgCode, BoolQueryBuilder boolMust) {
String officeRegion = commonMapper.getCompanyCodeByOrgCode(orgCode);
BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery();
BoolQueryBuilder queryBuilder2 = QueryBuilders.boolQuery();
EnhancedDynamicQueryBuilder enhancedDynamicQueryBuilder = new EnhancedDynamicQueryBuilder();
queryBuilder1.must(QueryBuilders.termQuery("superviseOrgCode", "50"))
.must(QueryBuilders.wildcardQuery("officeRegion", "*" + officeRegion + "*"));
queryBuilder2.mustNot(QueryBuilders.termQuery("superviseOrgCode", "50"))
.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
enhancedDynamicQueryBuilder.add(queryBuilder1, or);
enhancedDynamicQueryBuilder.add(queryBuilder2, or);
boolMust.must(enhancedDynamicQueryBuilder.build());
}
/** /**
* 组装人员过滤条件 * 组装人员过滤条件
*/ */
private void getPersonBoolQueryBuilder(JSONObject filterParams, BoolQueryBuilder boolMust, String filterType, String orgCode) { private void getPersonBoolQueryBuilder(JSONObject filterParams, BoolQueryBuilder boolMust, String filterType) {
deleteUnitCategory(filterParams); deleteUnitCategory(filterParams);
// 快捷筛选和自定义筛选解析筛选规则不一致 // 快捷筛选和自定义筛选解析筛选规则不一致
if (filterType.equals("advanced")) { if (filterType.equals("advanced")) {
JSONArray unitType = filterParams.getJSONArray("unitType");
if (!ObjectUtils.isEmpty(unitType)) {
if (unitType.contains("检验机构") || unitType.contains("检测机构")) {
String officeRegion = commonMapper.getCompanyCodeByOrgCode(orgCode);
BoolQueryBuilder queryBuilder1 = QueryBuilders.boolQuery();
BoolQueryBuilder queryBuilder2 = QueryBuilders.boolQuery();
EnhancedDynamicQueryBuilder enhancedDynamicQueryBuilder = new EnhancedDynamicQueryBuilder();
queryBuilder1.must(QueryBuilders.termQuery("superviseOrgCode", "50"))
.must(QueryBuilders.wildcardQuery("officeRegion", "*" + officeRegion + "*"));
queryBuilder2.mustNot(QueryBuilders.termQuery("superviseOrgCode", "50"))
.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
enhancedDynamicQueryBuilder.add(queryBuilder1, or);
enhancedDynamicQueryBuilder.add(queryBuilder2, or);
boolMust.must(enhancedDynamicQueryBuilder.build());
} else {
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode));
}
}
filterParams.forEach((k, v) -> { filterParams.forEach((k, v) -> {
if (v instanceof JSONArray) { if (v instanceof JSONArray) {
if (!((JSONArray) v).contains("all") && ((JSONArray) v).size() > 0) { if (!((JSONArray) v).contains("all") && ((JSONArray) v).size() > 0) {
...@@ -3084,13 +3081,13 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -3084,13 +3081,13 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode)); boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
data = queryDpCompanyStatistics(filter, request, builder, boolMust, tabTotalMap); data = queryDpCompanyStatistics(filter, request, builder, boolMust, tabTotalMap);
} else if (StatisticalAnalysisEnum.person.getCode().equals(businessType)) { } else if (StatisticalAnalysisEnum.person.getCode().equals(businessType)) {
// boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode)); personOrgCodeBoolMust(orgCode, boolMust);
data = queryDpPersonStatistics(filter, request, builder, boolMust, tabTotalMap); data = queryDpPersonStatistics(filter, request, builder, boolMust, tabTotalMap);
} else if (StatisticalAnalysisEnum.inspectionCompany.getCode().equals(businessType)) { } else if (StatisticalAnalysisEnum.inspectionCompany.getCode().equals(businessType)) {
boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode)); boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode.keyword", orgCode));
data = queryDpInspectionCompanyStatistics(filter, request, builder, boolMust, tabTotalMap); data = queryDpInspectionCompanyStatistics(filter, request, builder, boolMust, tabTotalMap);
} else { } else {
// boolMust.must(QueryBuilders.prefixQuery("superviseOrgCode", orgCode)); personOrgCodeBoolMust(orgCode, boolMust);
data = queryDpInspectionPersonStatistics(filter, request, builder, boolMust, tabTotalMap); data = queryDpInspectionPersonStatistics(filter, request, builder, boolMust, tabTotalMap);
} }
...@@ -3107,7 +3104,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -3107,7 +3104,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
JSONObject filterParams = JSONObject.parseObject(JSONObject.toJSONString(filter.get("filterParams"))); JSONObject filterParams = JSONObject.parseObject(JSONObject.toJSONString(filter.get("filterParams")));
String filterType = "advanced"; String filterType = "advanced";
// 组装人员过滤条件 // 组装人员过滤条件
this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType, filter.getString("orgCode")); this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType);
// 通过是否传参 unitType 单位类型 区分一二级查询 // 通过是否传参 unitType 单位类型 区分一二级查询
boolean is2LeveFlag = Optional.of(filter) boolean is2LeveFlag = Optional.of(filter)
.map(obj -> obj.getJSONObject("filterParams")) .map(obj -> obj.getJSONObject("filterParams"))
...@@ -3291,7 +3288,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -3291,7 +3288,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
String filterType = "advanced"; String filterType = "advanced";
String unitCategory = filterParams.getString("unitCategory"); String unitCategory = filterParams.getString("unitCategory");
// 组装人员过滤条件 // 组装人员过滤条件
this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType, filter.getString("orgCode")); this.getPersonBoolQueryBuilder(filterParams, boolMust, filterType);
// 通过是否传参 unitType 单位类型 区分一二级查询 // 通过是否传参 unitType 单位类型 区分一二级查询
boolean is2LeveFlag = Optional.of(filter) boolean is2LeveFlag = Optional.of(filter)
...@@ -3973,8 +3970,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl { ...@@ -3973,8 +3970,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
JSONObject filterParams = JSONObject.parseObject(JSONObject.toJSONString(filter.get("filterParams"))); JSONObject filterParams = JSONObject.parseObject(JSONObject.toJSONString(filter.get("filterParams")));
String filterType = "advanced"; String filterType = "advanced";
// 组装人员过滤条件 // 组装人员过滤条件
this.getPersonBoolQueryBuilder(filterParams, boolQuery, filterType, orgCode); personOrgCodeBoolMust(orgCode, boolQuery);
this.getPersonBoolQueryBuilder(filterParams, boolQuery, filterType);
// 查询 // 查询
JSONObject expiryDateStatus = this.getExpiryDateStatusGroupStatistics(boolQuery); JSONObject expiryDateStatus = this.getExpiryDateStatusGroupStatistics(boolQuery);
JSONObject personType = this.getPersonTypeGroupStatistics(boolQuery); JSONObject personType = this.getPersonTypeGroupStatistics(boolQuery);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment