|
|
|
@ -124,6 +124,11 @@ namespace Platform.EventHandlers
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Temperature.GetName(), StatisticType.Double);
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Humidity.GetName(), StatisticType.Double);
|
|
|
|
|
//用电器
|
|
|
|
|
UpdateOrganPowerState(organId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateOrganPowerState(Guid organId)
|
|
|
|
|
{
|
|
|
|
|
var key = DataKeys.PowerState.GetName();
|
|
|
|
|
var query = this._dataRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.IoTDevice.IoTGateway.BuildingId.HasValue)
|
|
|
|
@ -133,7 +138,7 @@ namespace Platform.EventHandlers
|
|
|
|
|
var close = query.Count(o => o.IntValue == 0);
|
|
|
|
|
var open = total - close;
|
|
|
|
|
UpdateValue($"[{organId}]", "DeviceOpenCount", open, StatisticType.Int);
|
|
|
|
|
UpdateValue($"[{organId}]", "DeviceCloseCount", open, StatisticType.Int);
|
|
|
|
|
UpdateValue($"[{organId}]", "DeviceCloseCount", close, StatisticType.Int);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void UpdateBuildingData(Guid organId, Guid buildingId)
|
|
|
|
@ -147,6 +152,11 @@ namespace Platform.EventHandlers
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId, DataKeys.Temperature.GetName(), StatisticType.Double);
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId, DataKeys.Humidity.GetName(), StatisticType.Double);
|
|
|
|
|
//用电器
|
|
|
|
|
UpdateBuildingPowerState(organId, buildingId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateBuildingPowerState(Guid organId, Guid buildingId)
|
|
|
|
|
{
|
|
|
|
|
var key = DataKeys.PowerState.GetName();
|
|
|
|
|
var query = this._dataRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.IoTDevice.IoTGateway.BuildingId == buildingId)
|
|
|
|
@ -155,7 +165,7 @@ namespace Platform.EventHandlers
|
|
|
|
|
var close = query.Count(o => o.IntValue == 0);
|
|
|
|
|
var open = total - close;
|
|
|
|
|
UpdateValue($"[{organId}][{buildingId}]", "DeviceOpenCount", open, StatisticType.Int);
|
|
|
|
|
UpdateValue($"[{organId}][{buildingId}]", "DeviceCloseCount", open, StatisticType.Int);
|
|
|
|
|
UpdateValue($"[{organId}][{buildingId}]", "DeviceCloseCount", close, StatisticType.Int);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void UpdateOrganDataValue(Guid organId, string key, StatisticType type)
|
|
|
|
@ -217,21 +227,42 @@ namespace Platform.EventHandlers
|
|
|
|
|
|
|
|
|
|
private void IoTDataEventHandle(BaseEvent<IoTData> message)
|
|
|
|
|
{
|
|
|
|
|
var deviceId = message.Data.IoTDeviceId;
|
|
|
|
|
var buildingId = this._deviceRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.Id == deviceId)
|
|
|
|
|
.Where(o => o.IoTGateway.BuildingId.HasValue)
|
|
|
|
|
.Select(o => o.IoTGateway.BuildingId)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
if (buildingId != null)
|
|
|
|
|
|
|
|
|
|
if (message.Data.Key == DataKeys.Light.GetName() ||
|
|
|
|
|
message.Data.Key == DataKeys.Temperature.GetName() ||
|
|
|
|
|
message.Data.Key == DataKeys.Humidity.GetName() ||
|
|
|
|
|
message.Data.Key == DataKeys.PowerState.GetName())
|
|
|
|
|
{
|
|
|
|
|
var organId = this.GetOrganId(buildingId.Value);
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Light.GetName(), StatisticType.Int);
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Temperature.GetName(), StatisticType.Double);
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Humidity.GetName(), StatisticType.Double);
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId.Value, DataKeys.Light.GetName(), StatisticType.Int);
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId.Value, DataKeys.Temperature.GetName(), StatisticType.Double);
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId.Value, DataKeys.Humidity.GetName(), StatisticType.Double);
|
|
|
|
|
var deviceId = message.Data.IoTDeviceId;
|
|
|
|
|
var buildingId = this._deviceRepo.ReadOnlyTable()
|
|
|
|
|
.Where(o => o.Id == deviceId)
|
|
|
|
|
.Where(o => o.IoTGateway.BuildingId.HasValue)
|
|
|
|
|
.Select(o => o.IoTGateway.BuildingId)
|
|
|
|
|
.FirstOrDefault();
|
|
|
|
|
if (buildingId != null)
|
|
|
|
|
{
|
|
|
|
|
var organId = this.GetOrganId(buildingId.Value);
|
|
|
|
|
if (message.Data.Key == DataKeys.Light.GetName())
|
|
|
|
|
{
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Light.GetName(), StatisticType.Int);
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId.Value, DataKeys.Light.GetName(), StatisticType.Int);
|
|
|
|
|
}
|
|
|
|
|
else if(message.Data.Key == DataKeys.Temperature.GetName())
|
|
|
|
|
{
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Temperature.GetName(), StatisticType.Double);
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId.Value, DataKeys.Temperature.GetName(), StatisticType.Double);
|
|
|
|
|
}
|
|
|
|
|
else if(message.Data.Key == DataKeys.Humidity.GetName())
|
|
|
|
|
{
|
|
|
|
|
UpdateOrganDataValue(organId, DataKeys.Humidity.GetName(), StatisticType.Double);
|
|
|
|
|
UpdateBuildingDataValue(organId, buildingId.Value, DataKeys.Humidity.GetName(), StatisticType.Double);
|
|
|
|
|
}
|
|
|
|
|
else if(message.Data.Key == DataKeys.PowerState.GetName())
|
|
|
|
|
{
|
|
|
|
|
UpdateOrganPowerState(organId);
|
|
|
|
|
UpdateBuildingPowerState(organId, buildingId.Value);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|