Former-commit-id: 609371d00a19f9f2f471e4b6e115e34552e2cf38
Former-commit-id: fb7736243b26001d1f64e913d8b31f2c061c716c
1.0
wanggang 5 years ago
parent 606c3090f2
commit 10a294303a

@ -21,22 +21,26 @@ namespace Application.Domain.Entities
public void SetValue(object value)
{
this.UpdateAt = DateTime.UtcNow;
if (value is Int32)
if (this.Type == StatisticType.Int)
{
this.IntValue = Convert.ToInt32(value);
this.Value = this.IntValue.ToString();
}
else if (value is Double)
else if (this.Type == StatisticType.Double)
{
this.DoubleValue = Convert.ToDouble(value);
this.Value = this.DoubleValue.Value.ToString("f2");
}
else if (value is DateTime)
else if (this.Type == StatisticType.DateTime)
{
var timestamp = Convert.ToInt64(value, CultureInfo.InvariantCulture);
this.DateTimeValue = DateTimeOffset.FromUnixTimeMilliseconds(timestamp).DateTime;
this.Value = Convert.ToString(value);
}
else
{
this.Value = value.ToString();
}
}
}
}

@ -604,7 +604,8 @@ namespace IoTNode.DeviceServices.FBee
}
else
{
this.UpdateIoTData(device.Id, DataKeys.CurtainState, switchState);
var key = device.Name.Contains("电机") ? DataKeys.CurtainState : DataKeys.PowerState;
this.UpdateIoTData(device.Id, key, switchState);
}
}
else

@ -25,14 +25,21 @@ namespace Platform.Controllers
private readonly IRepository<Organ> _organRepo;
private readonly IRepository<Building> _buildingRepo;
private readonly IRepository<Statistic> _statisticRepo;
public HomeController(IUserService userService, IRepository<User> userRepo, IRepository<Area> areaRepo, IRepository<Organ> organRepo, IRepository<Building> buildingRepo)
public HomeController(IUserService userService,
IRepository<User> userRepo,
IRepository<Area> areaRepo,
IRepository<Organ> organRepo,
IRepository<Building> buildingRepo,
IRepository<Statistic> statisticRepo)
{
this._useService = userService;
this._userRepo = userRepo;
this._areaRepo = areaRepo;
this._organRepo = organRepo;
this._buildingRepo = buildingRepo;
this._statisticRepo = statisticRepo;
}
public IActionResult Index()
@ -54,12 +61,32 @@ namespace Platform.Controllers
.Where(o => o.Parent == null)
.ToList();
var model = new {
Organ= organ
Organ= organ,
MaxLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MaxLight").FirstOrDefault()?.Value,
MinLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MinLight").FirstOrDefault()?.Value,
MaxTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MaxTemperature").FirstOrDefault()?.Value,
MinTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MinTemperature").FirstOrDefault()?.Value,
MaxHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MaxHumidity").FirstOrDefault()?.Value,
MinHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]MinHumidity").FirstOrDefault()?.Value,
DeviceOpenCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]DeviceOpenCount").FirstOrDefault()?.Value,
DeviceCloseCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{userOrganId}]DeviceCloseCount").FirstOrDefault()?.Value,
};
return Json(model);
}
public IActionResult GetBuilding(Guid id)
{
var model = new
{
Building = this._buildingRepo.ReadOnlyTable()
.Include(o=>o.Scenes)
.Include(o => o.IoTGateways)
.ThenInclude(o => o.Devices).ThenInclude(o => o.Data)
.ToList()
};
return Json(model);
}
public IActionResult Building(HomeModel model)
{

@ -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);
}
}
}
}

@ -1,7 +1,7 @@
<template>
<div class="row" v-if="model" style="padding-top:1rem;">
<div class="row" style="padding-top:1rem;">
<div class="col-sm-2">
<div class="card">
<div class="card" v-if="model.organ">
<div class="card-header">建筑列表</div>
<div class="card-body">
<a-tree :tree-data="tree"
@ -14,6 +14,129 @@
</div>
</div>
<div class="col-sm-10">
<div class="card">
<div class="card-header">
<h5 class="card-title">
当前:{{model.building?model.building.building.name:model.organ.organ.name}}
</h5>
</div>
<div class="card-body">
<div class="row">
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
光照
</div>
</div>
<p>
最大值:
<template v-if="model.building">
{{model.building.maxLight}}
</template>
<template v-else>
{{model.organ.maxLight}}
</template>
</p>
<p>
最小值:
<template v-if="model.building">
{{model.building.minLight}}
</template>
<template v-else>
{{model.organ.minLight}}
</template>
</p>
</div>
</div>
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
温度
</div>
</div>
<p>
最大值:
<template v-if="model.building">
{{model.building.maxTemperature}}
</template>
<template v-else>
{{model.organ.maxTemperature}}
</template>
</p>
<p>
最小值:
<template v-if="model.building">
{{model.building.minTemperature}}
</template>
<template v-else>
{{model.organ.minTemperature}}
</template>
</p>
</div>
</div>
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
湿度
</div>
</div>
<p>
最大值:
<template v-if="model.building">
{{model.building.maxHumidity}}
</template>
<template v-else>
{{model.organ.maxHumidity}}
</template>
RH%"
</p>
<p>
最小值:
<template v-if="model.building">
{{model.building.minHumidity}}
</template>
<template v-else>
{{model.organ.minHumidity}}
</template>
RH%"
</p>
</div>
</div>
<div class="col-sm-3">
<div class="position-relative p-3 bg-gray">
<div class="ribbon-wrapper">
<div class="ribbon bg-primary">
用电
</div>
</div>
<p>
开:
<template v-if="model.building">
{{model.building.deviceOpenCount}}
</template>
<template v-else>
{{model.organ.deviceOpenCount}}
</template>
</p>
<p>
关:
<template v-if="model.building">
{{model.building.deviceCloseCount}}
</template>
<template v-else>
{{model.organ.deviceCloseCount}}
</template>
</p>
</div>
</div>
</div>
</div>
</div>
<div class="card">
<div class="card-header">下级建筑</div>
<div class="card-body">
@ -38,7 +161,10 @@
data() {
return {
url: config.baseUrl + '/Home/GetOrgan',
model: null,
model: {
organ: null,
building:null
},
events: ['OrganEntityInserted',
'OrganEntityUpdated',
'OrganEntityDeleted',
@ -64,7 +190,7 @@
load: function () {
var parent = this;
axios.post(this.url).then(function (response) {
parent.model = response.data;
parent.model.organ = response.data;
});
},
onSelect(selectedKeys, info) {
@ -87,15 +213,15 @@
},
computed: {
tree: function () {
return this.model.organ.buildings;
return this.model.organ.organ.buildings;
},
buildings: function () {
console.log(this.model.buildingId);
if (!this.model.buildingId) {
return this.model.organ.buildings;
return this.model.organ.organ.buildings;
}
else {
return this.findBuilding(this.model.organ.buildings, this.model.buildingId);
return this.findBuilding(this.model.organ.organ.buildings, this.model.buildingId);
}
}
}

Loading…
Cancel
Save