wanghc vor 3 Jahren
Ursprung
Commit
e3fcd37799

+ 97 - 92
ipfcst-console/src/main/java/com/jiayue/ipfcst/console/service/ReceiveDataService.java

@@ -125,6 +125,7 @@ public class ReceiveDataService {
     paramMap.put("deviceIds", equipmentNo);
     paramMap.put("startTime", startTime);
     paramMap.put("endTime", endTime);
+    log.info("param"+JSON.toJSONString(paramMap));
     String body = httpClient(paramMap);
     AnalysisData(body, id, equipmentType, electricField);
   }
@@ -142,104 +143,107 @@ public class ReceiveDataService {
       List<DataPoint> dataPointList = dataPointService.getByEquipmentType(equipmentType);
       JSONObject jsonObject= JSON.parseObject(body);
       JSONArray jsonResults = (JSONArray) jsonObject.get("results");
-      JSONObject jsonObj = jsonResults.getJSONObject(0);
-      JSONArray jsonRows = (JSONArray) jsonObj.get("rows");
-      //所有设备点位
-      JSONArray sensorIds = (JSONArray) jsonObj.get("sensorIds");
-      JSONObject values;
-      Map<String, String> map = new HashMap<>();
-      SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
-      if (jsonRows.size()>0){
-        values = jsonRows.getJSONObject(0);
-        //时间戳
-        String time = values.getString("timestamp");
-        //所有数据
-        JSONArray jsonValues = (JSONArray) values.get("values");
-        long timestamp = Long.parseLong(time);
-        map.put("stationCode",electricField.getStationCode());
-        map.put("equipmentId", equipmentId.toString());
-        map.put("time", simpleDateFormat.format(timestamp));
-
-        for (DataPoint dataPoint : dataPointList) {
-          for (int i = 0; i < sensorIds.size(); i++) {
-            if (dataPoint.getMeasuringPoint().equals(sensorIds.get(i))) {
-              if(jsonValues.get(i) == null ){
-                map.put(dataPoint.getEquipmentAttribute().getFieldName(), "-99");
-              }else{
-                map.put(dataPoint.getEquipmentAttribute().getFieldName(), jsonValues.get(i).toString());
+      if (jsonResults.size()>0){
+        JSONObject jsonObj = jsonResults.getJSONObject(0);
+        JSONArray jsonRows = (JSONArray) jsonObj.get("rows");
+        //所有设备点位
+        JSONArray sensorIds = (JSONArray) jsonObj.get("sensorIds");
+        JSONObject values;
+        Map<String, String> map = new HashMap<>();
+        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
+        if (jsonRows.size()>0){
+          values = jsonRows.getJSONObject(0);
+          //时间戳
+          String time = values.getString("timestamp");
+          //所有数据
+          JSONArray jsonValues = (JSONArray) values.get("values");
+          long timestamp = Long.parseLong(time);
+          map.put("stationCode",electricField.getStationCode());
+          map.put("equipmentId", equipmentId.toString());
+          map.put("time", simpleDateFormat.format(timestamp));
+          for (DataPoint dataPoint : dataPointList) {
+            for (int i = 0; i < sensorIds.size(); i++) {
+              if (dataPoint.getMeasuringPoint().equals(sensorIds.get(i))) {
+                if(jsonValues.get(i) == null ){
+                  map.put(dataPoint.getEquipmentAttribute().getFieldName(), "-99");
+                }else{
+                  map.put(dataPoint.getEquipmentAttribute().getFieldName(), jsonValues.get(i).toString());
+                }
               }
             }
           }
-        }
-        String STATUS = "status";
-        switch (map.get(STATUS)) {
-          case "1.00":
-          case "true":
-            //运行
-            map.put(STATUS, "1");
-            break;
-          case "2.00":
-            //待机
-            map.put(STATUS, "2");
-            break;
-          case "3.00":
-            //停用
-            map.put(STATUS, "3");
-            break;
-          case "4.00":
-          case "false":
-            //故障
-            map.put(STATUS, "4");
-            break;
-          case "-99":
-            map.put(STATUS, "5");
-            break;
-          default:
-            break;
-        }
+          String STATUS = "status";
+          switch (map.get(STATUS)) {
+            case "1.00":
+            case "true":
+              //运行
+              map.put(STATUS, "1");
+              break;
+            case "2.00":
+              //待机
+              map.put(STATUS, "2");
+              break;
+            case "3.00":
+              //停用
+              map.put(STATUS, "3");
+              break;
+            case "4.00":
+            case "false":
+              //故障
+              map.put(STATUS, "4");
+              break;
+            case "-99":
+              map.put(STATUS, "5");
+              break;
+            default:
+              break;
+          }
 
-        String ap = map.get(Active);
-        switch(equipmentType.getCode()){
-          case 1:
-            //气象站
-            redisUtils.hmset("qxz-" + electricField.getStationCode() + "-" + equipmentId, map);
-            WeatherStationStatusData weatherStationStatusData = JSON.parseObject(JSON.toJSONString(map), WeatherStationStatusData.class);
-            weatherStationStatusDataRepository.save(weatherStationStatusData);
-            log.info("qxz-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
-            break;
-          case 2:
-            //逆变器
-            if (ap != null && map.get("electricalCurrent") != null) {
-              //有功
-              BigDecimal activePower = new BigDecimal(ap);
-              //电流
-              BigDecimal electricalCurrent = new BigDecimal(map.get("electricalCurrent"));
-              //有功/电流=电压
-              BigDecimal voltage = activePower.divide(electricalCurrent, 2, BigDecimal.ROUND_HALF_UP);
-              map.put("voltage", voltage.toString());
-            }
-            redisUtils.hmset("nbq-" + electricField.getStationCode() + "-" + equipmentId, map);
-            InverterStatusData inverterStatusData = JSON.parseObject(JSON.toJSONString(map), InverterStatusData.class);
-            inverterStatusDataRepository.save(inverterStatusData);
-            log.info("nbq-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
-            break;
-          case 3:
-            redisUtils.hmset("fj-" + electricField.getStationCode() + "-" + equipmentId, map);
-            WindTurbineStatusData windTurbineStatusData = JSON.parseObject(JSON.toJSONString(map), WindTurbineStatusData.class);
-            windTurbineStatusDataRepository.save(windTurbineStatusData);
-            log.info("fj-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
-            break;
-          case 4:
-            redisUtils.hmset("cft-" + electricField.getStationCode() + "-" + equipmentId, map);
-            WindTowerStatusData windTowerStatusData = JSON.parseObject(JSON.toJSONString(map), WindTowerStatusData.class);
-            windTowerStatusDataRepository.save(windTowerStatusData);
-            log.info("cft-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
-            break;
-          default:
-            break;
+          String ap = map.get(Active);
+          switch(equipmentType.getCode()){
+            case 1:
+              //气象站
+              redisUtils.hmset("qxz-" + electricField.getStationCode() + "-" + equipmentId, map);
+              WeatherStationStatusData weatherStationStatusData = JSON.parseObject(JSON.toJSONString(map), WeatherStationStatusData.class);
+              weatherStationStatusDataRepository.save(weatherStationStatusData);
+              log.info("qxz-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
+              break;
+            case 2:
+              //逆变器
+              if (ap != null && map.get("electricalCurrent") != null) {
+                //有功
+                BigDecimal activePower = new BigDecimal(ap);
+                //电流
+                BigDecimal electricalCurrent = new BigDecimal(map.get("electricalCurrent"));
+                //有功/电流=电压
+                BigDecimal voltage = activePower.divide(electricalCurrent, 2, BigDecimal.ROUND_HALF_UP);
+                map.put("voltage", voltage.toString());
+              }
+              redisUtils.hmset("nbq-" + electricField.getStationCode() + "-" + equipmentId, map);
+              InverterStatusData inverterStatusData = JSON.parseObject(JSON.toJSONString(map), InverterStatusData.class);
+              inverterStatusDataRepository.save(inverterStatusData);
+              log.info("nbq-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
+              break;
+            case 3:
+              redisUtils.hmset("fj-" + electricField.getStationCode() + "-" + equipmentId, map);
+              WindTurbineStatusData windTurbineStatusData = JSON.parseObject(JSON.toJSONString(map), WindTurbineStatusData.class);
+              windTurbineStatusDataRepository.save(windTurbineStatusData);
+              log.info("fj-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
+              break;
+            case 4:
+              redisUtils.hmset("cft-" + electricField.getStationCode() + "-" + equipmentId, map);
+              WindTowerStatusData windTowerStatusData = JSON.parseObject(JSON.toJSONString(map), WindTowerStatusData.class);
+              windTowerStatusDataRepository.save(windTowerStatusData);
+              log.info("cft-" + electricField.getStationCode() + "-" + equipmentId+"已存入");
+              break;
+            default:
+              break;
+          }
+        }else {
+          log.info(electricField.getStationCode()+ "-" +equipmentType.getMessage() + "-" + equipmentId+"无数据,不进行任何操作");
         }
       }else {
-        log.info(electricField.getStationCode()+ "-" +equipmentType.getMessage() + "-" + equipmentId+"无数据,不进行任何操作");
+        log.info(electricField.getStationCode()+ "-" +equipmentType.getMessage() + "-" + equipmentId+"对方没有该设备,请核对设备编号");
       }
     } catch (Exception e) {
       log.info(electricField.getName()+equipmentType.getMessage()+"接数程序异常");
@@ -257,6 +261,7 @@ public class ReceiveDataService {
     try{
       CloseableHttpClient  httpClient = HttpClientBuilder.create().build();
       HttpPost httpPost = new HttpPost("http://"+ip+":"+port+path);
+
       StringEntity entity = new StringEntity(JSON.toJSONString(paramMap),"UTF-8");
       httpPost.setEntity(entity);
       //设置请求超时时间,链接超时时间