|
|
@ -8,6 +8,7 @@ using Microsoft.EntityFrameworkCore;
|
|
|
|
using Platform.ViewModels;
|
|
|
|
using Platform.ViewModels;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Platform.Controllers
|
|
|
|
namespace Platform.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -45,27 +46,12 @@ namespace Platform.Controllers
|
|
|
|
public IActionResult Building(HomeModel model)
|
|
|
|
public IActionResult Building(HomeModel model)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var userOrganId = User.GetOrganId().Value;//当前用户机构Id
|
|
|
|
var userOrganId = User.GetOrganId().Value;//当前用户机构Id
|
|
|
|
var userOrgans = this._userRepo.ReadOnlyTable()
|
|
|
|
|
|
|
|
.Where(o=>o.UserName==User.Identity.Name)
|
|
|
|
|
|
|
|
.SelectMany(o => o.OrganUsers)
|
|
|
|
|
|
|
|
.Select(o => o.Organ)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
var organList = new List<Organ>();
|
|
|
|
|
|
|
|
foreach (var item in userOrgans)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var userOrganList = this._organRepo.ReadOnlyTable()//当前用户机构及下级机构
|
|
|
|
|
|
|
|
.Where(o => o.ParentId != null)
|
|
|
|
|
|
|
|
.Where(o => o.Left >= item.Left && o.Right <= item.Right)
|
|
|
|
|
|
|
|
.Include(o => o.Buildings)
|
|
|
|
|
|
|
|
.ToList();
|
|
|
|
|
|
|
|
organList.AddRange(userOrganList);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var currentUserOrgan = this._organRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == userOrganId);//当前用户机构
|
|
|
|
var currentUserOrgan = this._organRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == userOrganId);//当前用户机构
|
|
|
|
//var organList = this._organRepo.ReadOnlyTable()//当前用户机构及下级机构
|
|
|
|
var organList = this._organRepo.ReadOnlyTable()//当前用户机构及下级机构
|
|
|
|
// .Where(o => o.ParentId != null)
|
|
|
|
.Where(o => o.ParentId != null)
|
|
|
|
// .Where(o => o.Left >= currentUserOrgan.Left && o.Right <= currentUserOrgan.Right)
|
|
|
|
.Where(o => o.Left >= currentUserOrgan.Left && o.Right <= currentUserOrgan.Right)
|
|
|
|
// .Include(o => o.Buildings)
|
|
|
|
.Include(o => o.Buildings)
|
|
|
|
// .ToList();
|
|
|
|
.ToList();
|
|
|
|
organList.ToTree();
|
|
|
|
organList.ToTree();
|
|
|
|
var rootOrganId = this._organRepo.ReadOnlyTable().Where(o => o.Number == "root").Select(o => o.Id).FirstOrDefault();
|
|
|
|
var rootOrganId = this._organRepo.ReadOnlyTable().Where(o => o.Number == "root").Select(o => o.Id).FirstOrDefault();
|
|
|
|
model.Organs = organList.Where(o => o.Parent == null).ToList();
|
|
|
|
model.Organs = organList.Where(o => o.Parent == null).ToList();
|
|
|
@ -122,6 +108,7 @@ namespace Platform.Controllers
|
|
|
|
model.TotalCount = query.Count();
|
|
|
|
model.TotalCount = query.Count();
|
|
|
|
model.Deviceses = query
|
|
|
|
model.Deviceses = query
|
|
|
|
.Include(o => o.Data)
|
|
|
|
.Include(o => o.Data)
|
|
|
|
|
|
|
|
.Include(o=>o.Product)
|
|
|
|
.Skip(model.PageSize * (model.PageIndex - 1))
|
|
|
|
.Skip(model.PageSize * (model.PageIndex - 1))
|
|
|
|
.Take(model.PageSize).ToList();
|
|
|
|
.Take(model.PageSize).ToList();
|
|
|
|
|
|
|
|
|
|
|
@ -129,9 +116,41 @@ namespace Platform.Controllers
|
|
|
|
{
|
|
|
|
{
|
|
|
|
item.Buildings = item.Buildings.ToTree().Where(o => o.ParentId == rootBuildingId).ToList();
|
|
|
|
item.Buildings = item.Buildings.ToTree().Where(o => o.ParentId == rootBuildingId).ToList();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
var light = this.GetDataValue<int>(query, "Light");
|
|
|
|
|
|
|
|
model.MinLight = light.Item1;
|
|
|
|
|
|
|
|
model.MaxLight = light.Item2;
|
|
|
|
|
|
|
|
var temperature = this.GetDataValue<float>(query, "Temperature");
|
|
|
|
|
|
|
|
model.MinTemperaturest = temperature.Item1;
|
|
|
|
|
|
|
|
model.MaxTemperatures = temperature.Item2;
|
|
|
|
|
|
|
|
var humidity = this.GetDataValue<float>(query, "Humidity");
|
|
|
|
|
|
|
|
model.MinHumidity = humidity.Item1;
|
|
|
|
|
|
|
|
model.MaxHumidity = humidity.Item2;
|
|
|
|
|
|
|
|
var query2 = query.Where(o => o.Name.Contains("开关") || o.Name.Contains("插座")).SelectMany(o => o.Data).Where(o => o.Key == "State");
|
|
|
|
|
|
|
|
var hasDevices = query2.Any();
|
|
|
|
|
|
|
|
model.Open = hasDevices? new int?( query2.Where(o => o.Value == "开").Count()):null;
|
|
|
|
|
|
|
|
model.Close= hasDevices ? new int?(query2.Where(o => o.Value == "关").Count()) : null;
|
|
|
|
return View(model);
|
|
|
|
return View(model);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private Tuple<T?, T?> GetDataValue<T>(IQueryable<IoTDevice> query, string key)where T : struct
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var list = query.SelectMany(o => o.Data)
|
|
|
|
|
|
|
|
.Where(o => o.Key == key).Select(o => o.Value)
|
|
|
|
|
|
|
|
.ToList()
|
|
|
|
|
|
|
|
.Select(o => ConvertTo<T>(o));
|
|
|
|
|
|
|
|
return new Tuple<T?, T?>(
|
|
|
|
|
|
|
|
list.Any()? new T?( list.Min()):null,
|
|
|
|
|
|
|
|
list.Any() ? new T?(list.Max()) :null
|
|
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private T ConvertTo<T>(string value) where T:struct
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
T result = (T)Convert.ChangeType(value, typeof(T));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IActionResult Alarm()
|
|
|
|
public IActionResult Alarm()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return View();
|
|
|
|
return View();
|
|
|
@ -172,16 +191,6 @@ namespace Platform.Controllers
|
|
|
|
return View();
|
|
|
|
return View();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private object Convert(Organ root)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return new
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
title = root.Name,
|
|
|
|
|
|
|
|
key = root.Number,
|
|
|
|
|
|
|
|
children = root.Children.Select(o => Convert(o))
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public string Mac(string id)
|
|
|
|
public string Mac(string id)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return Helper.Instance.MacEncrypt(id);
|
|
|
|
return Helper.Instance.MacEncrypt(id);
|
|
|
|