Former-commit-id: 5cbb27542f47121bc49751a2e11f8de693110767
Former-commit-id: 803ae639bcd0c905ad00214a40e72863f6c88bfc
1.0
wanggang 5 years ago
parent 127bf127c0
commit b5b5599b3f

@ -10,7 +10,7 @@ namespace Infrastructure.Extensions
{
if (list != null)
{
foreach (var item in list)
foreach (var item in list.OrderBy(o=>o.DisplayOrder))
{
if (item.ParentId.HasValue)
{

@ -123,4 +123,8 @@ img.pointer {
line-height: 24px;
margin: 0 auto;
overflow: hidden;
}
.ant-tree-switcher-line-icon {
line-height:14px;
vertical-align: text-top;
}

@ -52,10 +52,10 @@ namespace Platform.Controllers
public IActionResult GetOrgan()
{
var userOrganId = User.GetOrganId().Value;//当前用户机构Id
var organId = User.GetOrganId().Value;//当前用户机构Id
var organ = this._organRepo.ReadOnlyTable()
.Include(o => o.Buildings)
.FirstOrDefault(o => o.Id == userOrganId);
.FirstOrDefault(o => o.Id == organId);
organ.Buildings.ToTree();
var rootBuildingId = this._buildingRepo.ReadOnlyTable().Where(o => o.ParentId == null).Select(o => o.Id).FirstOrDefault();
organ.Buildings = organ.Buildings
@ -63,28 +63,37 @@ namespace Platform.Controllers
.ToList();
var model = new {
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,
MaxLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MaxLight").FirstOrDefault()?.Value,
MinLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MinLight").FirstOrDefault()?.Value,
MaxTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MaxTemperature").FirstOrDefault()?.Value,
MinTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MinTemperature").FirstOrDefault()?.Value,
MaxHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MaxHumidity").FirstOrDefault()?.Value,
MinHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]MinHumidity").FirstOrDefault()?.Value,
DeviceOpenCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]DeviceOpenCount").FirstOrDefault()?.Value,
DeviceCloseCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}]DeviceCloseCount").FirstOrDefault()?.Value,
};
return Json(model);
}
public IActionResult GetBuilding(Guid id)
{
var model = new
{
Building = this._buildingRepo.ReadOnlyTable()
.Include(o=>o.Scenes)
var organId = User.GetOrganId().Value;//当前用户机构Id
var building = this._buildingRepo.ReadOnlyTable()
.Include(o => o.Scenes)
.Include(o => o.IoTGateways)
.ThenInclude(o => o.Devices).ThenInclude(o => o.Data)
.ToList()
.FirstOrDefault();
var model = new
{
Building = building,
MaxLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MaxLight").FirstOrDefault()?.Value,
MinLight = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MinLight").FirstOrDefault()?.Value,
MaxTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MaxTemperature").FirstOrDefault()?.Value,
MinTemperature = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MinTemperature").FirstOrDefault()?.Value,
MaxHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MaxHumidity").FirstOrDefault()?.Value,
MinHumidity = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]MinHumidity").FirstOrDefault()?.Value,
DeviceOpenCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]DeviceOpenCount").FirstOrDefault()?.Value,
DeviceCloseCount = this._statisticRepo.ReadOnlyTable().Where(o => o.Key == $"[{organId}][{id}]DeviceCloseCount").FirstOrDefault()?.Value,
};
return Json(model);
}

@ -113,16 +113,17 @@ namespace Platform.Data
public void Seed(DbContext db)
{
var order = 0;
var root = db.Set<IoTProductCategory>().Add(new IoTProductCategory
{
Name = "产品分类",
Number = "root"
}).Entity;
db.Set<IoTProductCategory>().Add(new IoTProductCategory { ParentId = root.Id, Number = "00", Name = "网关", Image = "/images/gateway.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory { ParentId = root.Id, Number = "10", Name = "安防", Image = "/images/safe.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory { ParentId = root.Id, Number = "20", Name = "电器", Image = "/images/socket.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory { ParentId = root.Id, Number = "30", Name = "照明", Image = "/images/light.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory { ParentId = root.Id, Number = "40", Name = "监测", Image = "/images/monitor.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "00", Name = "网关", Image = "/images/gateway.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "10", Name = "安防", Image = "/images/safe.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "20", Name = "电器", Image = "/images/socket.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "30", Name = "照明", Image = "/images/light.svg" });
db.Set<IoTProductCategory>().Add(new IoTProductCategory {DisplayOrder=order++, ParentId = root.Id, Number = "40", Name = "监测", Image = "/images/monitor.svg" });
db.SaveChanges();
db.Set<IoTProductCategory>().FirstOrDefault(o => o.Number == "root").Update();
db.SaveChanges();
@ -157,7 +158,8 @@ namespace Platform.Data
{
Parent = categoryGroup,
Name = name,
Number = number
Number = number,
DisplayOrder=order++
};
var scopeAttribute = type.GetCustomAttribute<ScopeAttribute>();
if (scopeAttribute != null)
@ -297,7 +299,7 @@ namespace Platform.Data
var organId = db.Set<Organ>().FirstOrDefault(o => o.Number == "xuexiao").Id;
var buildingRoot = new Building
{
Image= image,
Image = image,
Name = "建筑",
Number = "root",
OrganId = organRoot.Id,
@ -306,6 +308,7 @@ namespace Platform.Data
new Building
{
Image= image,
DisplayOrder=order++,
OrganId=organId,
Type= BuildingType.Building,
Name="默认建筑",
@ -313,6 +316,7 @@ namespace Platform.Data
Children = new List<Building> {
new Building {
Image= image,
DisplayOrder=order++,
OrganId=organId,
Type= BuildingType.Layer,
Name="1楼",
@ -321,6 +325,7 @@ namespace Platform.Data
{
new Building{
Image= image,
DisplayOrder=order++,
OrganId=organId,
Type= BuildingType.Room,
Name="101室",
@ -328,6 +333,7 @@ namespace Platform.Data
},
new Building{
Image= image,
DisplayOrder=order++,
OrganId=organId,
Type= BuildingType.Room,
Name="102室",
@ -337,6 +343,7 @@ namespace Platform.Data
},
new Building {
Image= image,
DisplayOrder=order++,
OrganId=organId,
Type= BuildingType.Layer,
Name="2楼",
@ -345,6 +352,7 @@ namespace Platform.Data
{
new Building{
Image= image,
DisplayOrder=order++,
OrganId=organId,
Type= BuildingType.Room,
Name="201室",
@ -352,6 +360,7 @@ namespace Platform.Data
},
new Building{
Image= image,
DisplayOrder=order++,
OrganId=organId,
Type= BuildingType.Room,
Name="202室",

@ -1,10 +1,11 @@
<template>
<div class="row" style="padding-top:1rem;">
<div class="row" style="padding-top:1rem;" v-if="model.organ">
<div class="col-sm-2">
<div class="card" v-if="model.organ">
<div class="card">
<div class="card-header">建筑列表</div>
<div class="card-body">
<a-tree :tree-data="tree"
:default-expanded-keys="expanded"
:replace-fields="{title:'name',key:'id'}"
block-node
show-line
@ -153,6 +154,9 @@
</div>
</div>
</div>
<div class="card">
</div>
</div>
</div>
</template>
@ -163,7 +167,8 @@
url: config.baseUrl + '/Home/GetOrgan',
model: {
organ: null,
building:null
building: null,
expanded:[],
},
events: ['OrganEntityInserted',
'OrganEntityUpdated',
@ -194,34 +199,56 @@
});
},
onSelect(selectedKeys, info) {
var url = config.baseUrl + '/Home/GetBuilding/' + selectedKeys[0];
axios.get(url).then(function (response) {
parent.model.building = response.data;
});
var parent = this;
var key = selectedKeys[0];
if (key === this.model.organ.organ.id) {
this.model.building = null;
}
else {
var url = config.baseUrl + '/Home/GetBuilding/' + key;
axios.get(url).then(function (response) {
parent.model.building = response.data;
});
}
},
findBuilding: function (buildings, id) {
findBuildings: function (buildings,id) {
for (var i in buildings) {
var item = buildings[i];
if (item.id == id) {
return item.children;
}
if (item.children.length > 0) {
this.findBuilding(item.children, id);
return this.findBuildings(item.children, id);
}
}
}
},
computed: {
tree: function () {
return this.model.organ.organ.buildings;
var result = [];
if (this.model.organ != null) {
result.push({
id:this.model.organ.organ.id,
name:this.model.organ.organ.name,
children: this.model.organ.organ.buildings
});
}
return result;
},
expanded : function () {
var result = [];
if (this.model.organ != null) {
result.push(this.model.organ.organ.id);
}
return result;
},
buildings: function () {
console.log(this.model.buildingId);
if (!this.model.buildingId) {
//console.log(this.model.buildingId);
if (!this.model.building) {
return this.model.organ.organ.buildings;
}
else {
return this.findBuilding(this.model.organ.organ.buildings, this.model.buildingId);
return this.findBuildings(this.model.organ.organ.buildings,this.model.building.building.id);
}
}
}

Loading…
Cancel
Save