|
@@ -4,13 +4,10 @@ import cn.hutool.http.HttpUtil;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONObject;
|
|
import cn.hutool.json.JSONUtil;
|
|
import cn.hutool.json.JSONUtil;
|
|
import com.alibaba.fastjson.JSON;
|
|
import com.alibaba.fastjson.JSON;
|
|
-import com.jiayue.ipfcst.common.core.exception.BusinessException;
|
|
|
|
|
|
+import com.alibaba.fastjson.TypeReference;
|
|
import com.jiayue.ipfcst.common.core.util.DateTimeUtil;
|
|
import com.jiayue.ipfcst.common.core.util.DateTimeUtil;
|
|
import com.jiayue.ipfcst.common.data.entity.*;
|
|
import com.jiayue.ipfcst.common.data.entity.*;
|
|
-import com.jiayue.ipfcst.common.data.repository.InverterStatusDataRepository;
|
|
|
|
-import com.jiayue.ipfcst.common.data.repository.WeatherStationStatusDataRepository;
|
|
|
|
-import com.jiayue.ipfcst.common.data.repository.WindTowerStatusDataRepository;
|
|
|
|
-import com.jiayue.ipfcst.common.data.repository.WindTurbineStatusDataRepository;
|
|
|
|
|
|
+import com.jiayue.ipfcst.common.data.repository.*;
|
|
import com.jiayue.ipfcst.console.dto.ResponseResults;
|
|
import com.jiayue.ipfcst.console.dto.ResponseResults;
|
|
import com.jiayue.ipfcst.console.dto.ResponseRows;
|
|
import com.jiayue.ipfcst.console.dto.ResponseRows;
|
|
import com.jiayue.ipfcst.console.util.RedisUtils;
|
|
import com.jiayue.ipfcst.console.util.RedisUtils;
|
|
@@ -18,6 +15,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
+import java.math.BigDecimal;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
@@ -55,7 +53,10 @@ public class ReceiveDataService {
|
|
RedisUtils redisUtils;
|
|
RedisUtils redisUtils;
|
|
@Autowired
|
|
@Autowired
|
|
EquipmentAttributeService equipmentAttributeService;
|
|
EquipmentAttributeService equipmentAttributeService;
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ PowerStationStatusDataRepository powerStationStatusDataRepository;
|
|
|
|
+ @Autowired
|
|
|
|
+ PowerStationDataPackerContainer powerStationDataPackerContainer;
|
|
|
|
|
|
public void receive() {
|
|
public void receive() {
|
|
List<ElectricField> electricFieldList = electricFieldService.getAll();
|
|
List<ElectricField> electricFieldList = electricFieldService.getAll();
|
|
@@ -124,55 +125,101 @@ public class ReceiveDataService {
|
|
* @param equipmentType 设备类型
|
|
* @param equipmentType 设备类型
|
|
* @param electricField 场站对象
|
|
* @param electricField 场站对象
|
|
*/
|
|
*/
|
|
- public void AnalysisData(String boby, Integer equipmentId, Integer equipmentType, ElectricField electricField) throws BusinessException {
|
|
|
|
- List<DataPoint> dataPointList = dataPointService.getByEquipmentType(equipmentType);
|
|
|
|
- JSONObject jsonObject = JSONUtil.parseObj(boby);
|
|
|
|
- ResponseResults results = (ResponseResults) jsonObject.get("results");
|
|
|
|
- ResponseRows rows = results.getRows();
|
|
|
|
- String[] value = rows.getValues();
|
|
|
|
- String[] sensorIds = results.getSensorIds();
|
|
|
|
- Map<String, String> map = new HashMap<>();
|
|
|
|
- map.put("equipmentNo", equipmentId.toString());
|
|
|
|
- map.put("time", new Date(rows.getTimestamp()).toString());
|
|
|
|
- for (DataPoint dataPoint : dataPointList) {
|
|
|
|
- for (int i = 0; i < sensorIds.length; i++) {
|
|
|
|
- if (dataPoint.getMeasuringPoint().equals(sensorIds[i])) {
|
|
|
|
- map.put(dataPoint.getEquipmentAttribute().getFieldName(), value[i]);
|
|
|
|
|
|
+ public void AnalysisData(String boby, Integer equipmentId, Integer equipmentType, ElectricField electricField) {
|
|
|
|
+ try {
|
|
|
|
+ List<DataPoint> dataPointList = dataPointService.getByEquipmentType(equipmentType);
|
|
|
|
+ JSONObject jsonObject = JSONUtil.parseObj(boby);
|
|
|
|
+ ResponseResults results = (ResponseResults) jsonObject.get("results");
|
|
|
|
+ ResponseRows rows = results.getRows();
|
|
|
|
+ String[] value = rows.getValues();
|
|
|
|
+ String[] sensorIds = results.getSensorIds();
|
|
|
|
+ Map<String, String> map = new HashMap<>();
|
|
|
|
+ map.put("equipmentNo", equipmentId.toString());
|
|
|
|
+ map.put("time", new Date(rows.getTimestamp()).toString());
|
|
|
|
+ for (DataPoint dataPoint : dataPointList) {
|
|
|
|
+ for (int i = 0; i < sensorIds.length; i++) {
|
|
|
|
+ if (dataPoint.getMeasuringPoint().equals(sensorIds[i])) {
|
|
|
|
+ map.put(dataPoint.getEquipmentAttribute().getFieldName(), value[i]);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- }
|
|
|
|
- //光
|
|
|
|
- if (electricField.getElectricFieldTypeEnum().getCode() == 1) {
|
|
|
|
- WeatherStationInfo weatherStationInfo = weatherStationInfoService.get(equipmentId);
|
|
|
|
- if (weatherStationInfo != null) {
|
|
|
|
- redisUtils.hmset("qxz-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
- WeatherStationStatusData weatherStationStatusData = JSON.parseObject(JSON.toJSONString(map), WeatherStationStatusData.class);
|
|
|
|
- weatherStationStatusDataRepository.save(weatherStationStatusData);
|
|
|
|
|
|
+ //光
|
|
|
|
+ if (electricField.getElectricFieldTypeEnum().getCode() == 1) {
|
|
|
|
+ WeatherStationInfo weatherStationInfo = weatherStationInfoService.get(equipmentId);
|
|
|
|
+ if (weatherStationInfo != null) {
|
|
|
|
+ redisUtils.hmset("qxz-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
+ WeatherStationStatusData weatherStationStatusData = JSON.parseObject(JSON.toJSONString(map), WeatherStationStatusData.class);
|
|
|
|
+ weatherStationStatusDataRepository.save(weatherStationStatusData);
|
|
|
|
+ } else {
|
|
|
|
+ InverterInfo inverterInfo = inverterInfoService.get(equipmentId);
|
|
|
|
+ if (map.get("activePower") != null && map.get("electricalCurrent") != null) {
|
|
|
|
+ //有功
|
|
|
|
+ BigDecimal activePower = new BigDecimal(map.get("activePower"));
|
|
|
|
+ //电流
|
|
|
|
+ BigDecimal electricalCurrent = new BigDecimal(map.get("electricalCurrent"));
|
|
|
|
+ //有功/电流=电压
|
|
|
|
+ BigDecimal voltage = activePower.divide(electricalCurrent, 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ map.put("voltage", voltage.toString());
|
|
|
|
+ }
|
|
|
|
+ if (inverterInfo != null) {
|
|
|
|
+ redisUtils.hmset("nbq-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
+ InverterStatusData inverterStatusData = JSON.parseObject(JSON.toJSONString(map), InverterStatusData.class);
|
|
|
|
+ inverterStatusDataRepository.save(inverterStatusData);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- InverterInfo inverterInfo = inverterInfoService.get(equipmentId);
|
|
|
|
- if (inverterInfo != null) {
|
|
|
|
- redisUtils.hmset("nbq-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
- InverterStatusData inverterStatusData = JSON.parseObject(JSON.toJSONString(map), InverterStatusData.class);
|
|
|
|
- inverterStatusDataRepository.save(inverterStatusData);
|
|
|
|
|
|
+ //风
|
|
|
|
+ WindTurbineInfo windTurbineInfo = windTurbineInfoService.get(equipmentId);
|
|
|
|
+ if (windTurbineInfo != null) {
|
|
|
|
+ redisUtils.hmset("fj-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
+ WindTurbineStatusData windTurbineStatusData = JSON.parseObject(JSON.toJSONString(map), WindTurbineStatusData.class);
|
|
|
|
+ windTurbineStatusDataRepository.save(windTurbineStatusData);
|
|
|
|
+ } else {
|
|
|
|
+ WindTowerInfo windTowerInfo = windTowerInfoService.get(equipmentId);
|
|
|
|
+ if (windTowerInfo != null) {
|
|
|
|
+ redisUtils.hmset("cft-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
+ WindTowerStatusData windTowerStatusData = JSON.parseObject(JSON.toJSONString(map), WindTowerStatusData.class);
|
|
|
|
+ windTowerStatusDataRepository.save(windTowerStatusData);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
- } else {
|
|
|
|
- //风
|
|
|
|
- WindTurbineInfo windTurbineInfo = windTurbineInfoService.get(equipmentId);
|
|
|
|
- if (windTurbineInfo != null) {
|
|
|
|
- redisUtils.hmset("fj-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
- WindTurbineStatusData windTurbineStatusData = JSON.parseObject(JSON.toJSONString(map), WindTurbineStatusData.class);
|
|
|
|
- windTurbineStatusDataRepository.save(windTurbineStatusData);
|
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ public void savePowerStationStatusData(ElectricField electricField) {
|
|
|
|
+ try {
|
|
|
|
+ BigDecimal powerStationStatusData = 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());
|
|
|
|
+ if (getMap.get("activePower") != null) {
|
|
|
|
+ powerStationStatusData = powerStationStatusData.add(new BigDecimal(getMap.get("activePower")));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
} else {
|
|
} else {
|
|
- WindTowerInfo windTowerInfo = windTowerInfoService.get(equipmentId);
|
|
|
|
- if (windTowerInfo != null) {
|
|
|
|
- redisUtils.hmset("cft-" + electricField.getStationCode() + "-" + equipmentId, map);
|
|
|
|
- WindTowerStatusData windTowerStatusData = JSON.parseObject(JSON.toJSONString(map), WindTowerStatusData.class);
|
|
|
|
- windTowerStatusDataRepository.save(windTowerStatusData);
|
|
|
|
|
|
+ List<WindTurbineInfo> windTurbineInfoList = windTurbineInfoService.getByStationCode(electricField.getStationCode());
|
|
|
|
+ for (WindTurbineInfo windTurbineInfo : windTurbineInfoList) {
|
|
|
|
+ Map<String, String> getMap = redisUtils.hgetall("fj-" + electricField.getStationCode() + "-" + windTurbineInfo.getId());
|
|
|
|
+ if (getMap.get("activePower") != null) {
|
|
|
|
+ powerStationStatusData = powerStationStatusData.add(new BigDecimal(getMap.get("activePower")));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+ if (powerStationStatusData.compareTo(new BigDecimal("0")) > 0) {
|
|
|
|
+ powerStationStatusData.divide(new BigDecimal("1000"), 2, BigDecimal.ROUND_HALF_UP);
|
|
|
|
+ }
|
|
|
|
+ PowerStationStatusData p = powerStationDataPackerContainer.getDataPacker(electricField.getStationCode()).packageData(powerStationStatusData);
|
|
|
|
+ powerStationStatusDataRepository.save(p);
|
|
|
|
+ //对象转map
|
|
|
|
+ Map<String, String> map = JSON.parseObject(JSON.toJSONString(p), new TypeReference<Map<String, String>>() {
|
|
|
|
+ });
|
|
|
|
+ redisUtils.hmset("power-" + electricField.getStationCode(), map);
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
}
|
|
}
|
|
- }
|
|
|
|
|
|
|
|
|
|
+ }
|
|
}
|
|
}
|