Procházet zdrojové kódy

某些接口增加查询条件

459242451@qq.com před 3 roky
rodič
revize
e06ee23e7a

+ 2 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gas/BlackGasController.java

@@ -137,8 +137,8 @@ public class BlackGasController extends BaseController {
             endTime = DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parseDate(beginTime))) + " 23:59:59";
         }
         Map<String, Object> rangeCondition = new HashMap<>();
-        rangeCondition.put("snapTimeFmt", StrUtil.concat(true, "[", beginTime, ",", endTime, "]"));
-        Map<Object, Object> aggs = client.aggs(ElasticConstants.HEIYAN_SHIP_RECOGNITION, AggsType.count, "snapPos", "id", null, rangeCondition);
+        rangeCondition.put("createTime", StrUtil.concat(true, "[", beginTime, ",", endTime, "]"));
+        Map<Object, Object> aggs = client.aggs(AggsType.count, "monitorPointName", "id", null, rangeCondition, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
         // 构造黑烟的数据
         List<SysDictData> heiyan_snap_pos = dictTypeService.selectDictDataByType("heiyan_snap_pos");
         Map<String, Object> result = new HashMap<>();

+ 5 - 2
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gas/GasCommonController.java

@@ -82,8 +82,11 @@ public class GasCommonController {
 //        Map<String, Object> so2RangeCondition = new HashMap<>();
 //        so2RangeCondition.put("createTime", StrUtil.concat(true, "[", Convert.toStr(params.get("beginTime")), ",", Convert.toStr(params.get("endTime")), "]"));
 //        so2RangeCondition.put("peakTime", StrUtil.concat(true, "[", Convert.toStr(params.get("beginTime")), ",", Convert.toStr(params.get("endTime")), "]"));
-        long so2Count = client.count(null, null, ElasticConstants.SO2_ALERT, ElasticConstants.AIS_ILLEGAL_SHIP);
-        long blackCount = client.count(null, null, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
+        Map<String, Object> equalsCondition = new HashMap<>();
+        equalsCondition.put("illegalStatus", 2);
+        long so2Count = client.count(equalsCondition, null, ElasticConstants.SO2_ALERT, ElasticConstants.AIS_ILLEGAL_SHIP);
+        equalsCondition.put("illegalStatus", 3);
+        long blackCount = client.count(equalsCondition, null, ElasticConstants.HEIYAN_SHIP_RECOGNITION);
         Map<String, Object> result = new HashMap<>();
         result.put("so2Count", so2Count);
         result.put("blackCount", blackCount);

+ 12 - 13
ruoyi-admin/src/main/java/com/ruoyi/web/controller/gas/So2Controller.java

@@ -259,19 +259,17 @@ public class So2Controller extends BaseController {
             beginTime = month + "-01 00:00:00";
             endTime = DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parseDate(beginTime))) + " 23:59:59";
         }
-        Map<String, Object> aisRangeCondition = new HashMap<>();
-        aisRangeCondition.put("peakTime", StrUtil.concat(true, "[", beginTime, ",", endTime, "]"));
-        Map<Object, Object> aisAggs = client.aggs(ElasticConstants.AIS_ILLEGAL_SHIP, AggsType.count, "monitorPointName", "id", null, aisRangeCondition);
+        Map<String, Object> equalsCondition = new HashMap<>();
+        equalsCondition.put("illegalStatus", 2);
         Map<String, Object> so2RangeCondition = new HashMap<>();
         so2RangeCondition.put("createTime", StrUtil.concat(true, "[", beginTime, ",", endTime, "]"));
-        Map<Object, Object> so2Aggs = client.aggs(ElasticConstants.SO2_ALERT, AggsType.count, "monitorPointName", "id", null, so2RangeCondition);
+        Map<Object, Object> so2Aggs = client.aggs(AggsType.count, "monitorPointName", "id", equalsCondition, so2RangeCondition, ElasticConstants.AIS_ILLEGAL_SHIP, ElasticConstants.SO2_ALERT);
         // 构造硫的数据
         List<SysDictData> so2_snap_pos = dictTypeService.selectDictDataByType("so2_snap_pos");
         Map<String, Object> result = new HashMap<>();
         for (SysDictData so2_snap_po : so2_snap_pos) {
             result.put(so2_snap_po.getDictLabel(),
-                    (ObjectUtil.isEmpty(aisAggs.get(so2_snap_po.getDictLabel())) ? 0 : Convert.toInt(aisAggs.get(so2_snap_po.getDictLabel())))
-                            + (ObjectUtil.isEmpty(so2Aggs.get(so2_snap_po.getDictLabel())) ? 0 : Convert.toInt(so2Aggs.get(so2_snap_po.getDictLabel()))));
+                    (ObjectUtil.isEmpty(so2Aggs.get(so2_snap_po.getDictLabel())) ? 0 : Convert.toInt(so2Aggs.get(so2_snap_po.getDictLabel()))));
         }
         return AjaxResult.success(result);
     }
@@ -283,8 +281,7 @@ public class So2Controller extends BaseController {
             // 默认值为1个月
             interval = "1M";
         }
-        Map<String, Object> so2RangeCondition = new HashMap<>();
-        Map<String, Object> heiyanRangeCondition = new HashMap<>();
+        Map<String, Object> rangeCondition = new HashMap<>();
         if (!StrUtil.isAllBlank(startMonth, endMonth)) {
             if (StrUtil.isNotBlank(startMonth)) {
                 startMonth = startMonth + "-01 00:00:00";
@@ -292,12 +289,14 @@ public class So2Controller extends BaseController {
             if (StrUtil.isNotBlank(endMonth)) {
                 endMonth = DateUtil.formatDate(DateUtil.endOfMonth(DateUtil.parseDate(endMonth + "-01 00:00:00"))) + " 23:59:59";
             }
-            so2RangeCondition.put("createTime", StrUtil.concat(true, "[", startMonth, ",", endMonth, "]"));
-            heiyanRangeCondition.put("snapTimeFmt", StrUtil.concat(true, "[", startMonth, ",", endMonth, "]"));
+            rangeCondition.put("createTime", StrUtil.concat(true, "[", startMonth, ",", endMonth, "]"));
         }
-        Map<Object, Object> aisAggs = client.dateHistogramAggs(ElasticConstants.AIS_ILLEGAL_SHIP, AggsType.count, "peakTime", "id", null, so2RangeCondition, new DateHistogramInterval(interval));
-        Map<Object, Object> so2Aggs = client.dateHistogramAggs(ElasticConstants.SO2_ALERT, AggsType.count, "createTime", "id", null, so2RangeCondition, new DateHistogramInterval(interval));
-        Map<Object, Object> heiyanAggs = client.dateHistogramAggs(ElasticConstants.HEIYAN_SHIP_RECOGNITION, AggsType.count, "snapTimeFmt", "id", null, heiyanRangeCondition, new DateHistogramInterval(interval));
+        Map<String, Object> equalsCondition = new HashMap<>();
+        equalsCondition.put("illegalStatus", 2);
+        Map<Object, Object> aisAggs = client.dateHistogramAggs(ElasticConstants.AIS_ILLEGAL_SHIP, AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval));
+        Map<Object, Object> so2Aggs = client.dateHistogramAggs(ElasticConstants.SO2_ALERT, AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval));
+        equalsCondition.put("illegalStatus", 3);
+        Map<Object, Object> heiyanAggs = client.dateHistogramAggs(ElasticConstants.HEIYAN_SHIP_RECOGNITION, AggsType.count, "createTime", "id", equalsCondition, rangeCondition, new DateHistogramInterval(interval));
         Map<String, Map<Object, Object>> result = new HashMap<>();
         result.put("ais", aisAggs);
         result.put("so2", so2Aggs);

+ 3 - 3
ruoyi-framework/src/main/java/com/ruoyi/framework/config/ElasticSearchClient.java

@@ -450,12 +450,12 @@ public class ElasticSearchClient {
      * @param rangeCondition
      * @return
      */
-    public Map<Object, Object> aggs(String indexName,
-                                    AggsType aggsType,
+    public Map<Object, Object> aggs(AggsType aggsType,
                                     String bucketName,
                                     String metricName,
                                     Map<String, Object> equalsCondition,
-                                    Map<String, Object> rangeCondition) {
+                                    Map<String, Object> rangeCondition,
+                                    String... indexName) {
         SearchSourceBuilder sourceBuilder = new SearchSourceBuilder();
 
         String by = "by_" + bucketName.replaceAll(keyword, "");