parent
9700e86f6b
commit
d24ac9c9e8
Binary file not shown.
@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Domain;
|
||||
|
||||
namespace Application.Domain.Entities
|
||||
{
|
||||
[Display(Name = "权限")]
|
||||
public class Permission : BaseEntity, IDisableUpdate, IDisableDelete
|
||||
{
|
||||
public string Name { get; set; }
|
||||
|
||||
public string Number { get; set; }
|
||||
public Guid? CategoryId { get; set; }
|
||||
public PermissionCategory Category { get; set; } = new PermissionCategory();
|
||||
|
||||
public List<RolePermission> RolePermissions { get; set; } = new List<RolePermission>();
|
||||
}
|
||||
}
|
@ -1,12 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Domain;
|
||||
|
||||
namespace Application.Domain.Entities
|
||||
{
|
||||
[Display(Name = "权限分类")]
|
||||
public class PermissionCategory : BaseTreeEntity<PermissionCategory>
|
||||
{
|
||||
public List<Permission> Permissions { get; set; } = new List<Permission>();
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Domain;
|
||||
|
||||
namespace Application.Domain.Entities
|
||||
{
|
||||
[Display(Name = "角色")]
|
||||
public class Role : BaseEntity
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public List<UserRole> UserRoles { get; set; } = new List<UserRole>();
|
||||
public List<RolePermission> RolePermissions { get; set; } = new List<RolePermission>();
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Domain;
|
||||
|
||||
namespace Application.Domain.Entities
|
||||
{
|
||||
[Display(Name = "角色权限")]
|
||||
public class RolePermission : BaseEntity
|
||||
{
|
||||
public Guid RoleId { get; set; }
|
||||
public Guid PermissionId { get; set; }
|
||||
public Role Role { get; set; }
|
||||
public Permission Permission { get; set; }
|
||||
}
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Domain;
|
||||
|
||||
namespace Application.Domain.Entities
|
||||
{
|
||||
[Display(Name = "用户")]
|
||||
public class User : BaseEntity, IDisableDelete
|
||||
{
|
||||
public string UserName { get; set; }
|
||||
|
||||
public List<UserRole> UserRoles { get; set; } = new List<UserRole>();
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
using System;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Domain;
|
||||
|
||||
namespace Application.Domain.Entities
|
||||
{
|
||||
[Display(Name = "用户角色")]
|
||||
public class UserRole : BaseEntity
|
||||
{
|
||||
public Guid UserId { get; set; }
|
||||
public Guid RoleId { get; set; }
|
||||
public User User { get; set; }
|
||||
public Role Role { get; set; }
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Application;
|
||||
|
||||
namespace Application.Models
|
||||
{
|
||||
[Display(Name = "权限")]
|
||||
public class EditPermissionModel : EditModel
|
||||
{
|
||||
[Display(Name = "分类")]
|
||||
public string CategoryName { get; set; }
|
||||
|
||||
[Display(Name = "名称"), Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Display(Name = "编号"), Required]
|
||||
public string Number { get; set; }
|
||||
}
|
||||
}
|
@ -1,18 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Application;
|
||||
|
||||
namespace Application.Models
|
||||
{
|
||||
[Display(Name = "角色")]
|
||||
public class EditRoleModel : EditModel
|
||||
{
|
||||
[Display(Name = "名称"), Required]
|
||||
public string Name { get; set; }
|
||||
|
||||
[DataType("MultiSelectList")]
|
||||
[Display(Name = "权限")]
|
||||
public List<Guid> Permissions { get; set; } = new List<Guid>();
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Application;
|
||||
|
||||
namespace Application.Models
|
||||
{
|
||||
[Display(Name = "配置")]
|
||||
public class EditSettingModel : EditModel
|
||||
{
|
||||
[Display(Name = "名称", Order = 10)]
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
public string Name { get; set; }
|
||||
|
||||
[Display(Name = "Logo", Order = 20)]
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
[DataType(DataType.ImageUrl)]
|
||||
public string Logo { get; set; }
|
||||
|
||||
[Display(Name = "版权", Order = 30)]
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
[DataType(DataType.Html)]
|
||||
public string Copyright { get; set; }
|
||||
|
||||
[Display(Name = "版本", Order = 40)]
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
public string Version { get; set; }
|
||||
|
||||
[Display(Name = "密码错误次数", Order = 50)]
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
public int MaxFailedAccessAttemptsBeforeLockout { get; set; }
|
||||
|
||||
[Display(Name = "账户锁定时间", Order = 60)]
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
public int DefaultAccountLockoutMinutes { get; set; }
|
||||
|
||||
[Display(Name = "验证间隔时间", Order = 70)]
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
public int CaptchaSeconds { get; set; }
|
||||
|
||||
[Display(Name = "邮件服务器", Order = 100)]
|
||||
public string EmailHost { get; set; }
|
||||
|
||||
[Display(Name = "端口号", Order = 110)]
|
||||
[RegularExpression(@"\d+")]
|
||||
public int EmailPort { get; set; }
|
||||
|
||||
[Display(Name = "用户名", Order = 120)]
|
||||
public string EmailUser { get; set; }
|
||||
|
||||
[Display(Name = "密码", Order = 130)]
|
||||
[DataType(DataType.Password)]
|
||||
public string EmailPassword { get; set; }
|
||||
|
||||
[Display(Name = "关闭注册", Order = 130)]
|
||||
public bool RegisterDisabled { get; set; }
|
||||
}
|
||||
}
|
@ -1,21 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Infrastructure.Application;
|
||||
|
||||
namespace Application.Models
|
||||
{
|
||||
[Display(Name = "用户")]
|
||||
public class EditUserModel : EditModel
|
||||
{
|
||||
[Required(ErrorMessage = nameof(RequiredAttribute))]
|
||||
[RegularExpression("^[a-zA-Z0-9]+$", ErrorMessage = "用户名只能由数字和字母组成")]
|
||||
[StringLength(30, MinimumLength = 5, ErrorMessage = "用户名长度为5-30")]
|
||||
[Display(Name = "用户名")]
|
||||
public string UserName { get; set; }
|
||||
|
||||
[DataType("MultiSelectList")]
|
||||
[Display(Name = "角色")]
|
||||
public List<Guid> Roles { get; set; } = new List<Guid>();
|
||||
}
|
||||
}
|
@ -1,33 +1,33 @@
|
||||
using System.Linq;
|
||||
using Application.Domain.Entities;
|
||||
using Application.Models;
|
||||
using Infrastructure.Data;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Web.Mvc;
|
||||
using IoTShared.Controllers;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
//using System.Linq;
|
||||
//using Application.Domain.Entities;
|
||||
//using Application.Models;
|
||||
//using Infrastructure.Data;
|
||||
//using Infrastructure.Extensions;
|
||||
//using Infrastructure.Web.Mvc;
|
||||
//using IoTShared.Controllers;
|
||||
//using Microsoft.AspNetCore.Authorization;
|
||||
//using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace IoTCenter.Areas.Admin.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Area(nameof(Admin))]
|
||||
public class ApiController : CrudController<Api, ApiSearchModel, EditApiModel, EditApiModel>
|
||||
{
|
||||
private readonly AjaxController _ajax;
|
||||
//namespace IoTCenter.Areas.Admin.Controllers
|
||||
//{
|
||||
// [Authorize]
|
||||
// [Area(nameof(Admin))]
|
||||
// public class ApiController : CrudController<Api, ApiSearchModel, EditApiModel, EditApiModel>
|
||||
// {
|
||||
// private readonly AjaxController _ajax;
|
||||
|
||||
public ApiController(IRepository<Api> repo, AjaxController ajax) : base(repo)
|
||||
{
|
||||
this._ajax = ajax;
|
||||
}
|
||||
// public ApiController(IRepository<Api> repo, AjaxController ajax) : base(repo)
|
||||
// {
|
||||
// this._ajax = ajax;
|
||||
// }
|
||||
|
||||
public override IQueryable<Api> Query(ApiSearchModel model, IQueryable<Api> query)
|
||||
{
|
||||
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId));
|
||||
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue);
|
||||
return query.WhereIf(model.NodeId.HasValue, o => o.Device.NodeId == model.NodeId.Value)
|
||||
.WhereIf(model.DeviceId.HasValue, o => o.DeviceId == model.DeviceId.Value)
|
||||
.WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword));
|
||||
}
|
||||
}
|
||||
}
|
||||
// public override IQueryable<Api> Query(ApiSearchModel model, IQueryable<Api> query)
|
||||
// {
|
||||
// ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId));
|
||||
// ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue);
|
||||
// return query.WhereIf(model.NodeId.HasValue, o => o.Device.NodeId == model.NodeId.Value)
|
||||
// .WhereIf(model.DeviceId.HasValue, o => o.DeviceId == model.DeviceId.Value)
|
||||
// .WhereIf(!string.IsNullOrEmpty(model.Keyword), o => o.Name.Contains(model.Keyword));
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,165 +1,165 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Application.Domain.Entities;
|
||||
using Application.Models;
|
||||
using Application.Services;
|
||||
using Infrastructure.Application;
|
||||
using Infrastructure.Data;
|
||||
using Infrastructure.Extensions;
|
||||
using Infrastructure.Web.Mvc;
|
||||
using IoTShared;
|
||||
using IoTShared.Controllers;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.AspNetCore.SignalR;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using Application.Domain.Entities;
|
||||
//using Application.Models;
|
||||
//using Application.Services;
|
||||
//using Infrastructure.Application;
|
||||
//using Infrastructure.Data;
|
||||
//using Infrastructure.Extensions;
|
||||
//using Infrastructure.Web.Mvc;
|
||||
//using IoTShared;
|
||||
//using IoTShared.Controllers;
|
||||
//using Microsoft.AspNetCore.Authorization;
|
||||
//using Microsoft.AspNetCore.Mvc;
|
||||
//using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
//using Microsoft.AspNetCore.SignalR;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace IoTCenter.Areas.Admin.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
[Area(nameof(Admin))]
|
||||
public class CommandController : CrudController<Command, PagedListModel<DisplayCommandModel>, DisplayCommandModel, EditCommandModel>
|
||||
{
|
||||
private readonly IRepository<Node> _nodeRepo;
|
||||
private readonly IRepository<Sence> _senceRepo;
|
||||
private readonly IRepository<Api> _apiRepo;
|
||||
private readonly IRepository<Command> _repo;
|
||||
private readonly AjaxController _ajax;
|
||||
private readonly IHubContext<PageHub> _pageHubContext;
|
||||
//namespace IoTCenter.Areas.Admin.Controllers
|
||||
//{
|
||||
// [Authorize]
|
||||
// [Area(nameof(Admin))]
|
||||
// public class CommandController : CrudController<Command, PagedListModel<DisplayCommandModel>, DisplayCommandModel, EditCommandModel>
|
||||
// {
|
||||
// private readonly IRepository<Node> _nodeRepo;
|
||||
// private readonly IRepository<Sence> _senceRepo;
|
||||
// private readonly IRepository<Api> _apiRepo;
|
||||
// private readonly IRepository<Command> _repo;
|
||||
// private readonly AjaxController _ajax;
|
||||
// private readonly IHubContext<PageHub> _pageHubContext;
|
||||
|
||||
public CommandController(IRepository<Node> nodeRepo, IRepository<Sence> senceRepo, IRepository<Api> apiRepo, IRepository<Command> repo, AjaxController ajax, IHubContext<PageHub> pageHubContext) : base(repo)
|
||||
{
|
||||
this._repo = repo;
|
||||
this._nodeRepo = nodeRepo;
|
||||
this._senceRepo = senceRepo;
|
||||
this._apiRepo = apiRepo;
|
||||
this._ajax = ajax;
|
||||
this._pageHubContext = pageHubContext;
|
||||
}
|
||||
// public CommandController(IRepository<Node> nodeRepo, IRepository<Sence> senceRepo, IRepository<Api> apiRepo, IRepository<Command> repo, AjaxController ajax, IHubContext<PageHub> pageHubContext) : base(repo)
|
||||
// {
|
||||
// this._repo = repo;
|
||||
// this._nodeRepo = nodeRepo;
|
||||
// this._senceRepo = senceRepo;
|
||||
// this._apiRepo = apiRepo;
|
||||
// this._ajax = ajax;
|
||||
// this._pageHubContext = pageHubContext;
|
||||
// }
|
||||
|
||||
public override IActionResult Add(EditCommandModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.NodeId).Number;
|
||||
this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.CreateCommand), model);
|
||||
return RedirectTo();
|
||||
}
|
||||
ModelState.AddModelError("", "服务器出现异常,请稍后重试");
|
||||
return View(model);
|
||||
}
|
||||
// public override IActionResult Add(EditCommandModel model)
|
||||
// {
|
||||
// if (ModelState.IsValid)
|
||||
// {
|
||||
// var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.NodeId).Number;
|
||||
// this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.CreateCommand), model);
|
||||
// return RedirectTo();
|
||||
// }
|
||||
// ModelState.AddModelError("", "服务器出现异常,请稍后重试");
|
||||
// return View(model);
|
||||
// }
|
||||
|
||||
public override IActionResult Edit(EditCommandModel model)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var entity = this._repo.Table().FirstOrDefault(o => o.Id == model.Id);
|
||||
var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.NodeId).Number;
|
||||
this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.EditCommand), model);
|
||||
return RedirectTo();
|
||||
}
|
||||
// public override IActionResult Edit(EditCommandModel model)
|
||||
// {
|
||||
// if (ModelState.IsValid)
|
||||
// {
|
||||
// var entity = this._repo.Table().FirstOrDefault(o => o.Id == model.Id);
|
||||
// var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == model.NodeId).Number;
|
||||
// this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.EditCommand), model);
|
||||
// return RedirectTo();
|
||||
// }
|
||||
|
||||
ModelState.AddModelError("", "服务器出现异常,请稍后重试");
|
||||
return View(model);
|
||||
}
|
||||
// ModelState.AddModelError("", "服务器出现异常,请稍后重试");
|
||||
// return View(model);
|
||||
// }
|
||||
|
||||
public override IActionResult Delete(List<Guid> list)
|
||||
{
|
||||
foreach (var id in list)
|
||||
{
|
||||
try
|
||||
{
|
||||
var entity = this._repo.Table().FirstOrDefault(o => o.Id == id);
|
||||
var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Sences.Any(s => s.Id == entity.SenceId)).Number;
|
||||
this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.DeleteCommand), id);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.PrintStack();
|
||||
return RedirectTo(message: ex.Message);
|
||||
}
|
||||
}
|
||||
return RedirectTo();
|
||||
}
|
||||
// public override IActionResult Delete(List<Guid> list)
|
||||
// {
|
||||
// foreach (var id in list)
|
||||
// {
|
||||
// try
|
||||
// {
|
||||
// var entity = this._repo.Table().FirstOrDefault(o => o.Id == id);
|
||||
// var number = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Sences.Any(s => s.Id == entity.SenceId)).Number;
|
||||
// this._pageHubContext.Clients.Group(number).SendAsync(nameof(INodeService.DeleteCommand), id);
|
||||
// }
|
||||
// catch (Exception ex)
|
||||
// {
|
||||
// ex.PrintStack();
|
||||
// return RedirectTo(message: ex.Message);
|
||||
// }
|
||||
// }
|
||||
// return RedirectTo();
|
||||
// }
|
||||
|
||||
public IActionResult Api(Guid id)
|
||||
{
|
||||
var model = this.GetParameters(id, null);
|
||||
return PartialView("_Api", model);
|
||||
}
|
||||
// public IActionResult Api(Guid id)
|
||||
// {
|
||||
// var model = this.GetParameters(id, null);
|
||||
// return PartialView("_Api", model);
|
||||
// }
|
||||
|
||||
public override IQueryable<Command> Include(IQueryable<Command> query)
|
||||
{
|
||||
return query.Include(o => o.Sence).Include(o => o.Api).ThenInclude(o => o.Device).ThenInclude(o => o.Node);
|
||||
}
|
||||
// public override IQueryable<Command> Include(IQueryable<Command> query)
|
||||
// {
|
||||
// return query.Include(o => o.Sence).Include(o => o.Api).ThenInclude(o => o.Device).ThenInclude(o => o.Node);
|
||||
// }
|
||||
|
||||
public override void ToDisplayModel(Command entity, DisplayCommandModel model)
|
||||
{
|
||||
model.NodeId = entity.Api.Device.Node.Name;
|
||||
model.DeviceId = entity.Api.Device.DisplayName;
|
||||
model.ApiId = entity.Api.Name;
|
||||
model.SenceId = entity.Sence.Name;
|
||||
}
|
||||
// public override void ToDisplayModel(Command entity, DisplayCommandModel model)
|
||||
// {
|
||||
// model.NodeId = entity.Api.Device.Node.Name;
|
||||
// model.DeviceId = entity.Api.Device.DisplayName;
|
||||
// model.ApiId = entity.Api.Name;
|
||||
// model.SenceId = entity.Sence.Name;
|
||||
// }
|
||||
|
||||
public override void ToModel(Command entity, EditCommandModel model)
|
||||
{
|
||||
if (entity != null)
|
||||
{
|
||||
model.NodeId = entity.Api.Device.NodeId;
|
||||
model.DeviceId = entity.Api.DeviceId;
|
||||
}
|
||||
ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId));
|
||||
ViewData.SelectList(o => model.SenceId, () => this._ajax.GetSenceSelectList(model.NodeId.Value, model.SenceId), model.NodeId.HasValue);
|
||||
ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue);
|
||||
ViewData.SelectList(o => model.ApiId, () => this._ajax.GetApiSelectList(model.DeviceId.Value, model.ApiId), model.DeviceId.HasValue);
|
||||
if (model.ApiId.HasValue)
|
||||
{
|
||||
model.Parameters = this.GetParameters(model.ApiId.Value, entity.QueryString);
|
||||
}
|
||||
}
|
||||
// public override void ToModel(Command entity, EditCommandModel model)
|
||||
// {
|
||||
// if (entity != null)
|
||||
// {
|
||||
// model.NodeId = entity.Api.Device.NodeId;
|
||||
// model.DeviceId = entity.Api.DeviceId;
|
||||
// }
|
||||
// ViewData.SelectList(o => model.NodeId, () => this._ajax.GetNodeSelectList(model.NodeId));
|
||||
// ViewData.SelectList(o => model.SenceId, () => this._ajax.GetSenceSelectList(model.NodeId.Value, model.SenceId), model.NodeId.HasValue);
|
||||
// ViewData.SelectList(o => model.DeviceId, () => this._ajax.GetDeviceSelectList(model.NodeId.Value, model.DeviceId), model.NodeId.HasValue);
|
||||
// ViewData.SelectList(o => model.ApiId, () => this._ajax.GetApiSelectList(model.DeviceId.Value, model.ApiId), model.DeviceId.HasValue);
|
||||
// if (model.ApiId.HasValue)
|
||||
// {
|
||||
// model.Parameters = this.GetParameters(model.ApiId.Value, entity.QueryString);
|
||||
// }
|
||||
// }
|
||||
|
||||
public override void ToEntity(EditCommandModel model, Command entity)
|
||||
{
|
||||
entity.QueryString = model.GetQueryString();
|
||||
}
|
||||
// public override void ToEntity(EditCommandModel model, Command entity)
|
||||
// {
|
||||
// entity.QueryString = model.GetQueryString();
|
||||
// }
|
||||
|
||||
private List<EditApiParameterModel> GetParameters(Guid apiId, string queryString)
|
||||
{
|
||||
var api = this._apiRepo.ReadOnlyTable().Include(o => o.Parameters).Include(o => o.Device).ThenInclude(o => o.Data).FirstOrDefault(o => o.Id == apiId);
|
||||
ViewData["Number"] = api.Device.Number;
|
||||
var parameters = api.Parameters.Select(o => o.To<EditApiParameterModel>()).ToList();
|
||||
if (!string.IsNullOrEmpty(queryString))
|
||||
{
|
||||
foreach (var item in queryString.Split('&'))
|
||||
{
|
||||
var array = item.Split('=');
|
||||
var name = array[0];
|
||||
var vlaue = array[1];
|
||||
var param = parameters.FirstOrDefault(o => o.Name == name);
|
||||
if (param != null)
|
||||
{
|
||||
param.Value = vlaue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (api.Device.Name == "红外转发器")
|
||||
{
|
||||
if (!api.Path.Contains("add") && !api.Path.Contains("get"))
|
||||
{
|
||||
foreach (var item in parameters)
|
||||
{
|
||||
if (item.Name == "code")
|
||||
{
|
||||
var list = api.Device.Data.Where(o => o.Name != "状态").ToList()
|
||||
.Select(o => new SelectListItem { Text = o.Name, Value = o.Value });
|
||||
item.SelectList = new SelectList(list, "Value", "Text", item.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
}
|
||||
}
|
||||
}
|
||||
// private List<EditApiParameterModel> GetParameters(Guid apiId, string queryString)
|
||||
// {
|
||||
// var api = this._apiRepo.ReadOnlyTable().Include(o => o.Parameters).Include(o => o.Device).ThenInclude(o => o.Data).FirstOrDefault(o => o.Id == apiId);
|
||||
// ViewData["Number"] = api.Device.Number;
|
||||
// var parameters = api.Parameters.Select(o => o.To<EditApiParameterModel>()).ToList();
|
||||
// if (!string.IsNullOrEmpty(queryString))
|
||||
// {
|
||||
// foreach (var item in queryString.Split('&'))
|
||||
// {
|
||||
// var array = item.Split('=');
|
||||
// var name = array[0];
|
||||
// var vlaue = array[1];
|
||||
// var param = parameters.FirstOrDefault(o => o.Name == name);
|
||||
// if (param != null)
|
||||
// {
|
||||
// param.Value = vlaue;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// if (api.Device.Name == "红外转发器")
|
||||
// {
|
||||
// if (!api.Path.Contains("add") && !api.Path.Contains("get"))
|
||||
// {
|
||||
// foreach (var item in parameters)
|
||||
// {
|
||||
// if (item.Name == "code")
|
||||
// {
|
||||
// var list = api.Device.Data.Where(o => o.Name != "状态").ToList()
|
||||
// .Select(o => new SelectListItem { Text = o.Name, Value = o.Value });
|
||||
// item.SelectList = new SelectList(list, "Value", "Text", item.Value);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return parameters;
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,78 +1,78 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Application.Domain.Entities;
|
||||
using Infrastructure.Data;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Vibrant.InfluxDB.Client;
|
||||
using Vibrant.InfluxDB.Client.Rows;
|
||||
//using System;
|
||||
//using System.Collections.Generic;
|
||||
//using System.Linq;
|
||||
//using Application.Domain.Entities;
|
||||
//using Infrastructure.Data;
|
||||
//using Microsoft.AspNetCore.Authorization;
|
||||
//using Microsoft.AspNetCore.Mvc;
|
||||
//using Microsoft.EntityFrameworkCore;
|
||||
//using Microsoft.Extensions.Configuration;
|
||||
//using Vibrant.InfluxDB.Client;
|
||||
//using Vibrant.InfluxDB.Client.Rows;
|
||||
|
||||
namespace IoTCenter.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class DeviceController : Controller
|
||||
{
|
||||
private readonly IConfiguration _configuration;
|
||||
private readonly IRepository<Node> _nodeRepo;
|
||||
private readonly IRepository<Device> _deviceRepo;
|
||||
//namespace IoTCenter.Controllers
|
||||
//{
|
||||
// [Authorize]
|
||||
// public class DeviceController : Controller
|
||||
// {
|
||||
// private readonly IConfiguration _configuration;
|
||||
// private readonly IRepository<Node> _nodeRepo;
|
||||
// private readonly IRepository<Device> _deviceRepo;
|
||||
|
||||
public DeviceController(IConfiguration configuration, IRepository<Node> nodeRepo, IRepository<Device> deviceRepo)
|
||||
{
|
||||
this._configuration = configuration;
|
||||
this._nodeRepo = nodeRepo;
|
||||
this._deviceRepo = deviceRepo;
|
||||
}
|
||||
// public DeviceController(IConfiguration configuration, IRepository<Node> nodeRepo, IRepository<Device> deviceRepo)
|
||||
// {
|
||||
// this._configuration = configuration;
|
||||
// this._nodeRepo = nodeRepo;
|
||||
// this._deviceRepo = deviceRepo;
|
||||
// }
|
||||
|
||||
public IActionResult Index(Guid id)
|
||||
{
|
||||
var model = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id);
|
||||
return View(model);
|
||||
}
|
||||
// public IActionResult Index(Guid id)
|
||||
// {
|
||||
// var model = this._nodeRepo.ReadOnlyTable().FirstOrDefault(o => o.Id == id);
|
||||
// return View(model);
|
||||
// }
|
||||
|
||||
public IActionResult Details(Guid id, string time = "10m")
|
||||
{
|
||||
var model = this._deviceRepo.ReadOnlyTable()
|
||||
.Include(o => o.Node)
|
||||
.Include(o => o.Data)
|
||||
.Include(o => o.Apis).ThenInclude(o => o.Parameters)
|
||||
.FirstOrDefault(o => o.Id == id);
|
||||
ViewBag.time = time;
|
||||
return View(model);
|
||||
}
|
||||
// public IActionResult Details(Guid id, string time = "10m")
|
||||
// {
|
||||
// var model = this._deviceRepo.ReadOnlyTable()
|
||||
// .Include(o => o.Node)
|
||||
// .Include(o => o.Data)
|
||||
// .Include(o => o.Apis).ThenInclude(o => o.Parameters)
|
||||
// .FirstOrDefault(o => o.Id == id);
|
||||
// ViewBag.time = time;
|
||||
// return View(model);
|
||||
// }
|
||||
|
||||
public IActionResult Data(Guid id, string time)
|
||||
{
|
||||
var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).Include(o => o.Data).FirstOrDefault(o => o.Id == id);
|
||||
var url = this._configuration["influxdb:url"];
|
||||
var usr = this._configuration["influxdb:usr"];
|
||||
var pwd = this._configuration["influxdb:pwd"];
|
||||
var dbName = "iot";
|
||||
var measurementName = "data";
|
||||
var list = new List<object>();
|
||||
using (var client = new InfluxClient(new Uri(url), usr, pwd))
|
||||
{
|
||||
var fileds = String.Join(',', device.Data.Where(o => o.Type == "Int" || o.Type == "Float").Select(o => o.Key));
|
||||
var query = $"select {fileds} from {measurementName} where time>now()-{time} and DeviceNumber = '{device.Number}' limit 10000";
|
||||
var result = client.ReadAsync<DynamicInfluxRow>(dbName, query).Result;
|
||||
var rows = result.Results.FirstOrDefault()?
|
||||
.Series.FirstOrDefault()?
|
||||
.Rows;
|
||||
var labels = rows?.Select(o => o.Timestamp.Value).Select(o => o.ToString("MM-dd HH:mm:ss")).ToList() ?? new List<string>();
|
||||
foreach (var data in device.Data.Where(o => o.Type == "Int" || o.Type == "Float"))
|
||||
{
|
||||
list.Add(new
|
||||
{
|
||||
id = data.Key,
|
||||
label = data.Name,
|
||||
labels,
|
||||
data = rows?.Select(o => o.GetField(data.Key)).ToList() ?? new List<object>()
|
||||
});
|
||||
}
|
||||
}
|
||||
return Json(list);
|
||||
}
|
||||
}
|
||||
}
|
||||
// public IActionResult Data(Guid id, string time)
|
||||
// {
|
||||
// var device = this._deviceRepo.ReadOnlyTable().Include(o => o.Node).Include(o => o.Data).FirstOrDefault(o => o.Id == id);
|
||||
// var url = this._configuration["influxdb:url"];
|
||||
// var usr = this._configuration["influxdb:usr"];
|
||||
// var pwd = this._configuration["influxdb:pwd"];
|
||||
// var dbName = "iot";
|
||||
// var measurementName = "data";
|
||||
// var list = new List<object>();
|
||||
// using (var client = new InfluxClient(new Uri(url), usr, pwd))
|
||||
// {
|
||||
// var fileds = String.Join(',', device.Data.Where(o => o.Type == "Int" || o.Type == "Float").Select(o => o.Key));
|
||||
// var query = $"select {fileds} from {measurementName} where time>now()-{time} and DeviceNumber = '{device.Number}' limit 10000";
|
||||
// var result = client.ReadAsync<DynamicInfluxRow>(dbName, query).Result;
|
||||
// var rows = result.Results.FirstOrDefault()?
|
||||
// .Series.FirstOrDefault()?
|
||||
// .Rows;
|
||||
// var labels = rows?.Select(o => o.Timestamp.Value).Select(o => o.ToString("MM-dd HH:mm:ss")).ToList() ?? new List<string>();
|
||||
// foreach (var data in device.Data.Where(o => o.Type == "Int" || o.Type == "Float"))
|
||||
// {
|
||||
// list.Add(new
|
||||
// {
|
||||
// id = data.Key,
|
||||
// label = data.Name,
|
||||
// labels,
|
||||
// data = rows?.Select(o => o.GetField(data.Key)).ToList() ?? new List<object>()
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
// return Json(list);
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -1,6 +0,0 @@
|
||||
{
|
||||
"version": "1.0",
|
||||
"defaultProvider": "cdnjs",
|
||||
"libraries": [
|
||||
]
|
||||
}
|
Loading…
Reference in new issue