|
@@ -0,0 +1,527 @@
|
|
|
+package com.jiayue.ipfcst.console.service;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
|
+import com.jiayue.ipfcst.common.core.util.DateTimeUtil;
|
|
|
+import com.jiayue.ipfcst.common.core.util.JsonBeanUtil;
|
|
|
+import com.jiayue.ipfcst.common.data.constant.enums.AlarmTypeEnum;
|
|
|
+import com.jiayue.ipfcst.common.data.constant.enums.EquipmentTypeEnum;
|
|
|
+import com.jiayue.ipfcst.common.data.entity.*;
|
|
|
+import com.jiayue.ipfcst.common.data.repository.*;
|
|
|
+import com.jiayue.ipfcst.common.data.service.BaseService;
|
|
|
+import com.jiayue.ipfcst.console.util.RedisUtils;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import org.apache.http.HttpEntity;
|
|
|
+import org.apache.http.client.config.RequestConfig;
|
|
|
+import org.apache.http.client.methods.CloseableHttpResponse;
|
|
|
+import org.apache.http.client.methods.HttpPost;
|
|
|
+import org.apache.http.entity.StringEntity;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClientBuilder;
|
|
|
+import org.apache.http.util.EntityUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.io.IOException;
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.nio.charset.StandardCharsets;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.*;
|
|
|
+
|
|
|
+/**
|
|
|
+ * 接收数据service类 切片查询 按设备类型查询
|
|
|
+ *
|
|
|
+ * @author whc
|
|
|
+ */
|
|
|
+@Service
|
|
|
+@Slf4j
|
|
|
+public class ReceiveAllTypeService extends BaseService {
|
|
|
+ @Autowired
|
|
|
+ ElectricFieldService electricFieldService;
|
|
|
+ @Autowired
|
|
|
+ WindTowerInfoService windTowerInfoService;
|
|
|
+ @Autowired
|
|
|
+ WindTurbineInfoService windTurbineInfoService;
|
|
|
+ @Autowired
|
|
|
+ WeatherStationInfoService weatherStationInfoService;
|
|
|
+ @Autowired
|
|
|
+ InverterInfoService inverterInfoService;
|
|
|
+ @Autowired
|
|
|
+ DataPointService dataPointService;
|
|
|
+ @Autowired
|
|
|
+ WeatherStationStatusDataRepository weatherStationStatusDataRepository;
|
|
|
+ @Autowired
|
|
|
+ InverterStatusDataRepository inverterStatusDataRepository;
|
|
|
+ @Autowired
|
|
|
+ WindTurbineStatusDataRepository windTurbineStatusDataRepository;
|
|
|
+ @Autowired
|
|
|
+ WindTowerStatusDataRepository windTowerStatusDataRepository;
|
|
|
+ @Autowired
|
|
|
+ RedisUtils redisUtils;
|
|
|
+ @Autowired
|
|
|
+ EquipmentAttributeService equipmentAttributeService;
|
|
|
+ @Autowired
|
|
|
+ PowerStationStatusDataRepository powerStationStatusDataRepository;
|
|
|
+ @Autowired
|
|
|
+ PowerStationDataPackerContainer powerStationDataPackerContainer;
|
|
|
+ @Autowired
|
|
|
+ SysAlarmService sysAlarmService;
|
|
|
+ @Value("${receive.ip}")
|
|
|
+ private String ip;
|
|
|
+ @Value("${receive.port}")
|
|
|
+ private String port;
|
|
|
+ @Value("${receive.path}")
|
|
|
+ private String path;
|
|
|
+ @Value("${receive.mode}")
|
|
|
+ private String mode;
|
|
|
+ private final String Active = "activePower";
|
|
|
+
|
|
|
+ //请求超时时间,这个时间定义了socket读数据的超时时间,也就是连接到服务器之后到从服务器获取响应数据需要等待的时间,发生超时,会抛出SocketTimeoutException异常。
|
|
|
+ private static final int SOCKET_TIME_OUT = 5000;
|
|
|
+ //连接超时时间,这个时间定义了通过网络与服务器建立连接的超时时间,也就是取得了连接池中的某个连接之后到接通目标url的连接等待时间。发生超时,会抛出ConnectionTimeoutException异常
|
|
|
+ private static final int CONNECT_TIME_OUT = 3000;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public void receive() {
|
|
|
+ long endTime = DateTimeUtil.getCurrentTimeForMinute().getTime();
|
|
|
+ try {
|
|
|
+ //按设备类型请求 气象站因为检修状态测点原因使用通用接口单独请求数据
|
|
|
+ List<InverterInfo> inverterInfoList = inverterInfoService.getAll();
|
|
|
+ List<WindTowerInfo> windTowerInfoList = windTowerInfoService.getAll();
|
|
|
+ List<WindTurbineInfo> windTurbineInfoList = windTurbineInfoService.getAll();
|
|
|
+ //逆变器
|
|
|
+ if (!inverterInfoList.isEmpty()) {
|
|
|
+ //设备编号
|
|
|
+ List<String> equipmentNo =new ArrayList<>();
|
|
|
+ //测点id
|
|
|
+ List<String> sensorIds =new ArrayList<>();
|
|
|
+ List<DataPoint> dataPointList;
|
|
|
+ for (InverterInfo inverterInfo : inverterInfoList) {
|
|
|
+ equipmentNo.add(inverterInfo.getEquipmentNo());
|
|
|
+ }
|
|
|
+ dataPointList = dataPointService.getByEquipmentType(inverterInfoList.get(0).getEquipmentType());
|
|
|
+ for (DataPoint dataPoint : dataPointList) {
|
|
|
+ sensorIds.add(dataPoint.getMeasuringPoint());
|
|
|
+ }
|
|
|
+ map(endTime, equipmentNo, inverterInfoList.get(0).getEquipmentType(), sensorIds);
|
|
|
+ }
|
|
|
+ //测风塔
|
|
|
+ if (!windTowerInfoList.isEmpty()) {
|
|
|
+ //设备编号
|
|
|
+ List<String> equipmentNo =new ArrayList<>();
|
|
|
+ //测点id
|
|
|
+ List<String> sensorIds =new ArrayList<>();
|
|
|
+ List<DataPoint> dataPointList;
|
|
|
+ for (WindTowerInfo windTowerInfo : windTowerInfoList) {
|
|
|
+ equipmentNo.add(windTowerInfo.getEquipmentNo());
|
|
|
+ }
|
|
|
+ dataPointList = dataPointService.getByEquipmentType(windTowerInfoList.get(0).getEquipmentType());
|
|
|
+ for (DataPoint dataPoint : dataPointList) {
|
|
|
+ sensorIds.add(dataPoint.getMeasuringPoint());
|
|
|
+ }
|
|
|
+ map(endTime, equipmentNo, windTowerInfoList.get(0).getEquipmentType(), sensorIds);
|
|
|
+ }
|
|
|
+ //风机
|
|
|
+ if (!windTurbineInfoList.isEmpty()) {
|
|
|
+ //设备编号
|
|
|
+ List<String> equipmentNo =new ArrayList<>();
|
|
|
+ //测点id
|
|
|
+ List<String> sensorIds =new ArrayList<>();
|
|
|
+ List<DataPoint> dataPointList;
|
|
|
+ for (WindTurbineInfo windTurbineInfo : windTurbineInfoList) {
|
|
|
+ equipmentNo.add(windTurbineInfo.getEquipmentNo());
|
|
|
+ }
|
|
|
+ dataPointList = dataPointService.getByEquipmentType(windTurbineInfoList.get(0).getEquipmentType());
|
|
|
+ for (DataPoint dataPoint : dataPointList) {
|
|
|
+ sensorIds.add(dataPoint.getMeasuringPoint());
|
|
|
+ }
|
|
|
+ map( endTime, equipmentNo, windTurbineInfoList.get(0).getEquipmentType(), sensorIds);
|
|
|
+ }
|
|
|
+ //该接口拿不到气象站检修状态数据,只能通过通用端口拿取数据
|
|
|
+ receiveQXZZT(endTime);
|
|
|
+ //计算实际功率
|
|
|
+ savePowerStationStatusData();
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private void map(Long endTime, List<String> equipmentNo,EquipmentTypeEnum equipmentType,List<String> sensorIds) {
|
|
|
+ HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("deviceIds", equipmentNo);
|
|
|
+ paramMap.put("timestamp", endTime);
|
|
|
+ paramMap.put("sensorIds",sensorIds);
|
|
|
+ log.debug(JSON.toJSONString(paramMap));
|
|
|
+ String body = httpClient(paramMap);
|
|
|
+ log.debug(body);
|
|
|
+ AnalysisData(body, equipmentType);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 解析数据
|
|
|
+ *
|
|
|
+ * @param body 所有数据
|
|
|
+ * @param equipmentType 设备类型
|
|
|
+ */
|
|
|
+ public void AnalysisData(String body, EquipmentTypeEnum equipmentType) {
|
|
|
+ try {
|
|
|
+ List<ElectricField> electricFieldList = electricFieldService.getAll();
|
|
|
+ List<DataPoint> dataPointList = dataPointService.getByEquipmentType(equipmentType);
|
|
|
+ JSONObject jsonObject= JSON.parseObject(body);
|
|
|
+ JSONArray jsonResults = (JSONArray) jsonObject.get("results");
|
|
|
+ if (!jsonResults.isEmpty()){
|
|
|
+ for(int i = 0 ; i < jsonResults.size() ; i ++){
|
|
|
+ //results
|
|
|
+ JSONObject jsonObj = jsonResults.getJSONObject(i);
|
|
|
+ //设备id
|
|
|
+ String equipmentId = (String) jsonObj.get("deviceId");
|
|
|
+ //rows
|
|
|
+ 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.isEmpty()){
|
|
|
+ values = jsonRows.getJSONObject(0);
|
|
|
+ //时间戳
|
|
|
+ String time = values.getString("timestamp");
|
|
|
+ //所有数据
|
|
|
+ JSONArray jsonValues = (JSONArray) values.get("values");
|
|
|
+ //青海场站id
|
|
|
+ String stationId = jsonObj.getString("stationId");
|
|
|
+ //嘉越场站编号
|
|
|
+ String electricFieldId = "";
|
|
|
+ for(ElectricField electricField : electricFieldList){
|
|
|
+ if(electricField.getElectricFieldId().equals(stationId)){
|
|
|
+ electricFieldId = electricField.getStationCode();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ long timestamp = Long.parseLong(time);
|
|
|
+ //通过接收到的id找出编号
|
|
|
+ map.put("stationCode",electricFieldId);
|
|
|
+ map.put("equipmentId", equipmentId);
|
|
|
+ map.put("time", simpleDateFormat.format(timestamp));
|
|
|
+ for (DataPoint dataPoint : dataPointList) {
|
|
|
+ for (int j = 0; j < sensorIds.size(); j++) {
|
|
|
+ if (dataPoint.getMeasuringPoint().equals(sensorIds.get(j))) {
|
|
|
+ if(jsonValues.get(j) == null ){
|
|
|
+ map.put(dataPoint.getEquipmentAttribute().getFieldName(), "-99");
|
|
|
+ }else{
|
|
|
+ map.put(dataPoint.getEquipmentAttribute().getFieldName(), jsonValues.get(j).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String STATUS = "status";switch (map.get(STATUS)) {
|
|
|
+ case "1.00": case "1.0": case "true":
|
|
|
+ //运行
|
|
|
+ map.put(STATUS, "1");
|
|
|
+ break; case "2.00": case "2.0"://待机
|
|
|
+ map.put(STATUS, "2");
|
|
|
+ break; case "3.00": case "3.0"://停用
|
|
|
+ map.put(STATUS, "3");
|
|
|
+ break; case "4.00": case "4.0": case "false"://通讯中断
|
|
|
+ map.put(STATUS, "4");
|
|
|
+ break; case "5.00": case "5.0": case "-99": map.put(STATUS, "5");
|
|
|
+ break;
|
|
|
+ default: break;
|
|
|
+ }
|
|
|
+ String ap = map.get(Active);
|
|
|
+ switch(equipmentType.getCode()){
|
|
|
+ case 2:
|
|
|
+ //逆变器
|
|
|
+ if (ap != null && map.get("electricalCurrent") != null) {
|
|
|
+ //有功
|
|
|
+ BigDecimal activePower = new BigDecimal(ap);
|
|
|
+ //电流
|
|
|
+ BigDecimal electricalCurrent = new BigDecimal(map.get("electricalCurrent"));
|
|
|
+ BigDecimal voltage;
|
|
|
+ if(!electricalCurrent.equals(new BigDecimal(0))){
|
|
|
+ map.put("voltage","0");
|
|
|
+ }else{
|
|
|
+ //有功/电流=电压
|
|
|
+ voltage = activePower.divide(electricalCurrent, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ map.put("voltage", voltage.toString());
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ redisUtils.hmset("nbq-" + electricFieldId + "-" + equipmentId, map);
|
|
|
+ InverterStatusData inverterStatusData = JSON.parseObject(JSON.toJSONString(map), InverterStatusData.class);
|
|
|
+ inverterStatusDataRepository.save(inverterStatusData);
|
|
|
+ log.info(map.get("time")+"nbq-" + electricFieldId + "-" + equipmentId+"已存入");
|
|
|
+ break;
|
|
|
+ case 3:
|
|
|
+ redisUtils.hmset("fj-" + electricFieldId + "-" + equipmentId, map);
|
|
|
+ WindTurbineStatusData windTurbineStatusData = JSON.parseObject(JSON.toJSONString(map), WindTurbineStatusData.class);
|
|
|
+ windTurbineStatusDataRepository.save(windTurbineStatusData);
|
|
|
+ log.info("fj-" + electricFieldId + "-" + equipmentId+"已存入");
|
|
|
+ break;
|
|
|
+ case 4:
|
|
|
+ redisUtils.hmset("cft-" + electricFieldId + "-" + equipmentId, map);
|
|
|
+ WindTowerStatusData windTowerStatusData = JSON.parseObject(JSON.toJSONString(map), WindTowerStatusData.class);
|
|
|
+ windTowerStatusDataRepository.save(windTowerStatusData);
|
|
|
+ log.info("cft-" + electricFieldId + "-" + equipmentId+"已存入");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.info(equipmentType.getMessage() + "-" + equipmentId+"无数据,不进行任何操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.info(equipmentType.getMessage() + "-" +"对方没有该类型设备,请核对设备信息");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info(equipmentType.getMessage()+"类型数据程序解析数据异常");
|
|
|
+ // 进行告警
|
|
|
+ String errorInfo = equipmentType.getMessage()+"类型数据程序解析数据异常";
|
|
|
+ String name = "程序解析数据异常";
|
|
|
+ String describe = "";
|
|
|
+ String solution = "";
|
|
|
+ sysAlarmService.saveSysAlarm(AlarmTypeEnum.E5, name, describe, errorInfo, solution);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 发http请求
|
|
|
+ * @param paramMap 参数
|
|
|
+ * @return 返回的数据
|
|
|
+ */
|
|
|
+ public String httpClient( HashMap<String, Object> paramMap){
|
|
|
+ String body = "";
|
|
|
+ try{
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+ HttpPost httpPost = new HttpPost("http://"+ip+":"+port+path+mode);
|
|
|
+
|
|
|
+ StringEntity entity = new StringEntity(JSON.toJSONString(paramMap),"UTF-8");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ //设置请求超时时间,链接超时时间
|
|
|
+ RequestConfig reqConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIME_OUT).setConnectTimeout(CONNECT_TIME_OUT).build();
|
|
|
+ httpPost.setConfig(reqConfig);
|
|
|
+ httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
|
+ CloseableHttpResponse response;
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
+ HttpEntity responseEntity = response.getEntity();
|
|
|
+ body = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
|
|
+ }catch (RuntimeException | IOException e){
|
|
|
+ String errorInfo = "发送http请求数据异常";
|
|
|
+ log.info(errorInfo);
|
|
|
+ log.info("所用线程"+Thread.currentThread().getName());
|
|
|
+ log.info("停止请求数据");
|
|
|
+ // 进行告警
|
|
|
+ String describe = "";
|
|
|
+ String solution = "停止请求数据";
|
|
|
+ sysAlarmService.saveSysAlarm(AlarmTypeEnum.E5, errorInfo, describe, errorInfo, solution);
|
|
|
+ Thread.currentThread().stop();
|
|
|
+ }
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void savePowerStationStatusData() {
|
|
|
+ List<ElectricField> electricFieldList = electricFieldService.getAll();
|
|
|
+ for(ElectricField electricField:electricFieldList){
|
|
|
+ try {
|
|
|
+ log.info("开始计算实际功率");
|
|
|
+ BigDecimal pssd = new BigDecimal("0");
|
|
|
+ if (electricField.getElectricFieldTypeEnum().getCode() == 1) {
|
|
|
+ List<InverterInfo> inverterInfoList = inverterInfoService.getByStationCode(electricField.getStationCode());
|
|
|
+ for (InverterInfo inverterInfo : inverterInfoList) {
|
|
|
+ Map<String, String> getMap = redisUtils.hgetall("nbq-" + electricField.getStationCode() + "-" + inverterInfo.getId());
|
|
|
+ String activePower = getMap.get(Active);
|
|
|
+ if (activePower != null) {
|
|
|
+ pssd = pssd.add(new BigDecimal(activePower));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ List<WindTurbineInfo> windTurbineInfoList = windTurbineInfoService.getByStationCode(electricField.getStationCode());
|
|
|
+ for (WindTurbineInfo windTurbineInfo : windTurbineInfoList) {
|
|
|
+ Map<String, String> getMap = redisUtils.hgetall("fj-" + electricField.getStationCode() + "-" + windTurbineInfo.getId());
|
|
|
+ String activePower = getMap.get(Active);
|
|
|
+ if (activePower != null) {
|
|
|
+ pssd = pssd.add(new BigDecimal(activePower));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (pssd.compareTo(new BigDecimal("0")) > 0) {
|
|
|
+ pssd = pssd.divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ }
|
|
|
+ PowerStationStatusData p = powerStationDataPackerContainer.getDataPacker(electricField.getStationCode()).packageData(pssd);
|
|
|
+ powerStationStatusDataRepository.save(p);
|
|
|
+ //对象转map
|
|
|
+ Map<String, String> map = JSON.parseObject(JSON.toJSONString(p), new TypeReference<Map<String, String>>() {
|
|
|
+ });
|
|
|
+ redisUtils.hmset("power-" + electricField.getStationCode(), map);
|
|
|
+ log.info("实际功率结束");
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ public void receiveQXZZT(Long endTime){
|
|
|
+ List<ElectricField> electricFieldList = electricFieldService.getAll();
|
|
|
+ log.info("开始调用通用接口请求气象站数据");
|
|
|
+ for (ElectricField electricField: electricFieldList){
|
|
|
+ List<WeatherStationInfo> weatherStationInfoList = weatherStationInfoService.get(electricField.getStationCode());
|
|
|
+ if (!weatherStationInfoList.isEmpty()) {
|
|
|
+ for (WeatherStationInfo weatherStationInfo : weatherStationInfoList) {
|
|
|
+ getTaosDataMap(endTime, weatherStationInfo.getEquipmentNo(), weatherStationInfoList.get(0).getEquipmentType(), electricField.getStationCode());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ log.info("调用通用接口请求气象站数据");
|
|
|
+ }
|
|
|
+ private void getTaosDataMap(Long endTime, String equipmentNo,EquipmentTypeEnum equipmentType,String stationCode) {
|
|
|
+ HashMap<String, Object> paramMap = new HashMap<>();
|
|
|
+ paramMap.put("deviceIds", equipmentNo);
|
|
|
+ paramMap.put("endTime", endTime);
|
|
|
+ paramMap.put("startTime",endTime-3000);
|
|
|
+ log.debug(JSON.toJSONString(paramMap));
|
|
|
+ String body = httpClientGetTaosData(paramMap);
|
|
|
+ log.debug(body);
|
|
|
+ AnalysisDataWeatherStationStatusData(body, equipmentType,stationCode);
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 发http请求 通用接口 气象站
|
|
|
+ * @param paramMap 参数
|
|
|
+ * @return 返回的数据
|
|
|
+ */
|
|
|
+ public String httpClientGetTaosData( HashMap<String, Object> paramMap){
|
|
|
+ String body = "";
|
|
|
+ try{
|
|
|
+ CloseableHttpClient httpClient = HttpClientBuilder.create().build();
|
|
|
+ HttpPost httpPost = new HttpPost("http://"+ip+":"+port+path+"getTaosData");
|
|
|
+
|
|
|
+ StringEntity entity = new StringEntity(JSON.toJSONString(paramMap),"UTF-8");
|
|
|
+ httpPost.setEntity(entity);
|
|
|
+ //设置请求超时时间,链接超时时间
|
|
|
+ RequestConfig reqConfig = RequestConfig.custom().setSocketTimeout(SOCKET_TIME_OUT).setConnectTimeout(CONNECT_TIME_OUT).build();
|
|
|
+ httpPost.setConfig(reqConfig);
|
|
|
+ httpPost.setHeader("Content-Type", "application/json; charset=utf-8");
|
|
|
+ CloseableHttpResponse response;
|
|
|
+ response = httpClient.execute(httpPost);
|
|
|
+ HttpEntity responseEntity = response.getEntity();
|
|
|
+ body = EntityUtils.toString(responseEntity, StandardCharsets.UTF_8);
|
|
|
+ }catch (RuntimeException | IOException e){
|
|
|
+ String errorInfo = "发送http请求气象站检修状态数据异常";
|
|
|
+ log.info(errorInfo);
|
|
|
+ log.info("所用线程"+Thread.currentThread().getName());
|
|
|
+ log.info("停止请求象站检修状态数据");
|
|
|
+ // 进行告警
|
|
|
+ String describe = "";
|
|
|
+ String solution = "停止请求象站检修状态数据";
|
|
|
+ sysAlarmService.saveSysAlarm(AlarmTypeEnum.E5, errorInfo, describe, errorInfo, solution);
|
|
|
+ Thread.currentThread().stop();
|
|
|
+ }
|
|
|
+ return body;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 气象站数据解析
|
|
|
+ * @param body http返回的数据
|
|
|
+ * @param equipmentType 设备类型
|
|
|
+ * @param stationCode 场站
|
|
|
+ */
|
|
|
+ public void AnalysisDataWeatherStationStatusData(String body, EquipmentTypeEnum equipmentType,String stationCode) {
|
|
|
+ try {
|
|
|
+ List<DataPoint> dataPointList = dataPointService.getByEquipmentType(equipmentType);
|
|
|
+ JSONObject jsonObject= JSON.parseObject(body);
|
|
|
+ JSONArray jsonResults = (JSONArray) jsonObject.get("results");
|
|
|
+ if (!jsonResults.isEmpty()){
|
|
|
+ for(int i = 0 ; i < jsonResults.size() ; i ++){
|
|
|
+ //results
|
|
|
+ JSONObject jsonObj = jsonResults.getJSONObject(i);
|
|
|
+ //设备id
|
|
|
+ String equipmentId = (String) jsonObj.get("deviceId");
|
|
|
+ //rows
|
|
|
+ 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.isEmpty()){
|
|
|
+ values = jsonRows.getJSONObject(0);
|
|
|
+ //时间戳
|
|
|
+ String time = values.getString("timestamp");
|
|
|
+ //所有数据
|
|
|
+ JSONArray jsonValues = (JSONArray) values.get("values");
|
|
|
+ long timestamp = Long.parseLong(time);
|
|
|
+ //通过接收到的id找出编号
|
|
|
+ map.put("stationCode",stationCode);
|
|
|
+ map.put("equipmentId", equipmentId);
|
|
|
+ map.put("time", simpleDateFormat.format(timestamp));
|
|
|
+ for (DataPoint dataPoint : dataPointList) {
|
|
|
+ for (int j = 0; j < sensorIds.size(); j++) {
|
|
|
+ if (dataPoint.getMeasuringPoint().equals(sensorIds.get(j))) {
|
|
|
+ if(jsonValues.get(j) == null ){
|
|
|
+ map.put(dataPoint.getEquipmentAttribute().getFieldName(), "-99");
|
|
|
+ }else{
|
|
|
+ map.put(dataPoint.getEquipmentAttribute().getFieldName(), jsonValues.get(j).toString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ String STATUS = "status";
|
|
|
+ switch (map.get(STATUS)) {
|
|
|
+ case "1.00":
|
|
|
+ case "1.0":
|
|
|
+ case "true":
|
|
|
+ //运行
|
|
|
+ map.put(STATUS, "1");
|
|
|
+ break;
|
|
|
+ case "2.00":
|
|
|
+ case "2.0":
|
|
|
+ //待机
|
|
|
+ map.put(STATUS, "2");
|
|
|
+ break;
|
|
|
+ case "3.00":
|
|
|
+ case "3.0":
|
|
|
+ //停用
|
|
|
+ map.put(STATUS, "3");
|
|
|
+ break;
|
|
|
+ case "4.00":
|
|
|
+ case "4.0":
|
|
|
+ case "false":
|
|
|
+ //通讯中断
|
|
|
+ map.put(STATUS, "4");
|
|
|
+ break;
|
|
|
+ case "5.00":
|
|
|
+ case "5.0":
|
|
|
+ case "-99":
|
|
|
+ map.put(STATUS, "5");
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ //气象站
|
|
|
+ redisUtils.hmset("qxz-" + stationCode + "-" + equipmentId, map);
|
|
|
+ WeatherStationStatusData weatherStationStatusData = JSON.parseObject(JSON.toJSONString(map), WeatherStationStatusData.class);
|
|
|
+ weatherStationStatusDataRepository.save(weatherStationStatusData);
|
|
|
+ log.info(map.get("time")+"qxz-" + stationCode + "-" + equipmentId+"已存入");
|
|
|
+ }else {
|
|
|
+ log.info("气象站" + "-" + equipmentId+"无数据,不进行任何操作");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }else {
|
|
|
+ log.info("对方没有气象站类型设备,请核对设备信息");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("气象站类型数据程序解析数据异常");
|
|
|
+ // 进行告警
|
|
|
+ String errorInfo = "气象站类型数据程序解析数据异常";
|
|
|
+ String name = "程序解析数据异常";
|
|
|
+ String describe = "";
|
|
|
+ String solution = "";
|
|
|
+ sysAlarmService.saveSysAlarm(AlarmTypeEnum.E5, name, describe, errorInfo, solution);
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|