Commit 8f565915 authored by tianyiming's avatar tianyiming

refactor: 调整综合查询

parent 77fa2049
......@@ -123,6 +123,7 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
private final String DOWNLOAD_TOPIC = "/topic/download/excel/%s";
private final String BUCKET_NAME = "upload";
private final String UPLOAD_PATH = "/tzs/excelTempFile";
private final List<String> equList = Arrays.asList("1000","2000","3000","4000","5000","6000","8000","9000");
// 大屏统计图片路径前缀
private final String dpEquipPhotoPrefix = "/upload/tzs/dpscreen/statistic/equip/";
// 大屏统计图片路径后缀
......@@ -955,27 +956,25 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
throw new RuntimeException(e);
}
Map<String, Object> sum = new HashMap<>();
sum.put("name", "设备总数(台套)");
sum.put("value", totle);
statics.add(sum);
BoolQueryBuilder pipeQuery = QueryBuilderUtils.copyBoolQuery(boolMust);
List<Map<String, Object>> equipStatusMap = new ArrayList<>();
getEquipStatusStatic(boolMust, builder, equipStatusMap);
result.put("keyIndicator", equipStatusMap);
if (ObjectUtils.isEmpty(filterParams) || !filterParams.containsKey("EQU_LIST")) {
filterParams = new JSONObject();
JSONArray jsonArray = new JSONArray();
jsonArray.add("all");
filterParams.put("EQU_LIST", jsonArray);
String equList = ObjectUtils.isEmpty(filterParams) || "".equals(filterParams.get("equList").toString()) ? "all" : filterParams.get("equList").toString();
String equCategory = ObjectUtils.isEmpty(filterParams) || "".equals(filterParams.get("equCategory").toString()) ? "all" : filterParams.get("equCategory").toString();
if (!equList.equals("8000") && !equCategory.equals("2300")) {
BoolQueryBuilder queryBuilder = QueryBuilderUtils.copyBoolQuery(boolMust);
queryBuilder.mustNot(QueryBuilders.termQuery("EQU_LIST_CODE","8000"))
.mustNot(QueryBuilders.termQuery("EQU_CATEGORY_CODE","2300"));
Long count = getStatisticCount(queryBuilder, StatisticalAnalysisEnum.equip.getKey());
Map<String, Object> sum = new HashMap<>();
sum.put("name", "设备总数(台套)");
sum.put("value", count);
statics.add(sum);
}
JSONArray equList = (JSONArray) filterParams.get("EQU_LIST");
if (ObjectUtils.isEmpty(equList) || equList.contains("8000") || equList.contains("all")) {
if (equList.contains("8000") || equList.contains("all")) {
// 获取压力管道长度
BigDecimal pipeLength = getPipeLength(boolMust, builder, "pipeLength");
Map<String, Object> pipeMap = new HashMap<>();
......@@ -984,7 +983,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
statics.add(pipeMap);
}
if (ObjectUtils.isEmpty(equList) || equList.contains("2000") || equList.contains("all")) {
if (equList.contains("all") || (equList.contains("2000") && "all".equals(equCategory)) || equCategory.contains("2300")) {
// 气瓶数量
CountRequest countRequest = new CountRequest();
countRequest.indices(StatisticalAnalysisEnum.equip.getKey());
......@@ -996,7 +996,6 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} catch (IOException e) {
throw new RuntimeException(e);
}
Map<String, Object> gasMap = new HashMap<>();
gasMap.put("name", "气瓶(个)");
gasMap.put("value", ObjectUtils.isEmpty(response) ? 0 : response.getCount());
......@@ -1030,6 +1029,8 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
}
private void getEquipmentBoolQueryBuilder(BoolQueryBuilder boolMust, JSONObject filterParams, String filterType) {
List<String> equListCodes = new ArrayList<>();
List<String> equCategoryCodes = new ArrayList<>();
//快捷筛选和自定义筛选解析筛选规则不一致
if (filterType.equals("advanced")) {
JSONObject finalFilterParams = filterParams;
......@@ -1098,10 +1099,13 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
boolMust.filter(QueryBuilders.rangeQuery(field).gte(startDate).lte(endDate));
}
} else if (k.equals("EQU_LIST") || k.equals("EQU_CATEGORY") || k.equals("EQU_DEFINE") || k.equals("DATA_QUALITY_SCORE")) {
JSONArray jsonArray = (JSONArray) v;
if (k.equals("EQU_LIST")) {
field = "EQU_LIST_CODE";
equListCodes.addAll((jsonArray).toJavaList(String.class));
} else if (k.equals("EQU_CATEGORY")) {
field = "EQU_CATEGORY_CODE";
equCategoryCodes.addAll((jsonArray).toJavaList(String.class));
} else if (k.equals("EQU_DEFINE")) {
field = "EQU_DEFINE_CODE";
}
......@@ -1180,27 +1184,51 @@ public class ComprehensiveStatisticalAnalysisServiceImpl {
} else {
JSONArray leftGroup = filterParams.getJSONArray("group1");
JSONArray rightGroup = filterParams.getJSONArray("group2");
JSONArray equListCodes = new JSONArray();
leftGroup.forEach(item -> {
JSONObject left = JSONObject.parseObject(JSONObject.toJSONString(item));
String leftField = left.getString("field");
String leftValue = left.getString("value");
String leftItemCondition = left.getString("itemCondition");
if (!ObjectUtils.isEmpty(leftField) && leftField.equals("EQU_LIST_CODE") && !ObjectUtils.isEmpty(leftValue)) {
if ("in".equals(leftItemCondition) || "eq".equals(leftItemCondition)) {
equListCodes.add(leftValue);
} else {
//todo
}
}
if (!ObjectUtils.isEmpty(leftField) && leftField.equals("EQU_CATEGORY_CODE") && !ObjectUtils.isEmpty(leftValue)) {
if ("in".equals(leftItemCondition) || "eq".equals(leftItemCondition)) {
equCategoryCodes.add(leftValue);
} else {
// todo
}
}
});
rightGroup.forEach(item -> {
JSONObject left = JSONObject.parseObject(JSONObject.toJSONString(item));
String rightField = left.getString("field");
String rightValue = left.getString("value");
JSONObject right = JSONObject.parseObject(JSONObject.toJSONString(item));
String rightField = right.getString("field");
String rightValue = right.getString("value");
String rightItemCondition = right.getString("itemCondition");
if (!ObjectUtils.isEmpty(rightField) && rightField.equals("EQU_LIST_CODE") && !ObjectUtils.isEmpty(rightValue)) {
if ("in".equals(rightItemCondition) || "eq".equals(rightItemCondition)) {
equListCodes.add(rightValue);
} else {
// todo
}
}
if (!ObjectUtils.isEmpty(rightField) && rightField.equals("EQU_CATEGORY_CODE") && !ObjectUtils.isEmpty(rightValue)) {
if ("in".equals(rightItemCondition) || "eq".equals(rightItemCondition)) {
equCategoryCodes.add(rightValue);
} else {
// todo
}
}
});
filterParams.put("EQU_LIST", equListCodes);
Boolean isOrGroup = or.equals(filterParams.getString("groupAndOr")) ? Boolean.TRUE : Boolean.FALSE;
handleAdvancedFilter(boolMust, leftGroup, rightGroup, isOrGroup, StatisticalAnalysisEnum.equip.getCode());
}
filterParams.put("equList", String.join(",", equListCodes));
filterParams.put("equCategory", String.join(",", equCategoryCodes));
}
private void getEquipStatusStatic(BoolQueryBuilder boolMust, SearchSourceBuilder builder, List<Map<String, Object>> statics) {
......
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