diff --git a/docs/资料/物联网中心/设备接入/飞比/计量插座计量部分API接口 V1.02.doc b/docs/资料/物联网中心/设备接入/飞比/计量插座计量部分API接口 V1.02.doc new file mode 100644 index 00000000..ccec6611 Binary files /dev/null and b/docs/资料/物联网中心/设备接入/飞比/计量插座计量部分API接口 V1.02.doc differ diff --git a/projects/Infrastructure/Web/BaseStartup.cs b/projects/Infrastructure/Web/BaseStartup.cs index 50fe6366..3fd2ad74 100644 --- a/projects/Infrastructure/Web/BaseStartup.cs +++ b/projects/Infrastructure/Web/BaseStartup.cs @@ -122,7 +122,7 @@ namespace Infrastructure.Web { options.PayloadSerializerSettings.ContractResolver = new DefaultContractResolver(); - }); ; + }); services.AddMemoryCache(); services.AddHttpContextAccessor(); services.AddSingleton(); diff --git a/projects/IoT/IoT.Shared/Controllers/AccountController.cs b/projects/IoT/IoT.Shared/Controllers/AccountController.cs index bbe95656..7119163f 100644 --- a/projects/IoT/IoT.Shared/Controllers/AccountController.cs +++ b/projects/IoT/IoT.Shared/Controllers/AccountController.cs @@ -19,7 +19,7 @@ namespace IoT.UI.Shard.Controllers { [Authorize] [ApiExplorerSettings(IgnoreApi = true)] - public class AccountController : BaseController + public class BaseAccountController : BaseController { private readonly IConfiguration _configuration; private readonly IRepository _userRepo; @@ -27,7 +27,7 @@ namespace IoT.UI.Shard.Controllers private readonly IEncryptionService _encryptionService; private readonly IEmailSender _emailSender; - public AccountController(IConfiguration configuration, + public BaseAccountController(IConfiguration configuration, IRepository userRepo, IEncryptionService encryptionService, IStringLocalizer localizer, diff --git a/projects/IoT/IoTServices/FBeeService/Controllers/AccountController.cs b/projects/IoT/IoTServices/FBeeService/Controllers/AccountController.cs new file mode 100644 index 00000000..5fc0a5e2 --- /dev/null +++ b/projects/IoT/IoTServices/FBeeService/Controllers/AccountController.cs @@ -0,0 +1,22 @@ +using Application.Domain.Entities; +using Infrastructure.Data; +using Infrastructure.Email; +using Infrastructure.Resources; +using Infrastructure.Security; +using IoT.UI.Shard.Controllers; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Localization; + +namespace FBeeService.Controllers +{ + public class AccountController : BaseAccountController + { + public AccountController(IConfiguration configuration, + IRepository userRepo, + IEncryptionService encryptionService, + IStringLocalizer localizer, + IEmailSender emaliSender) : base(configuration, userRepo, encryptionService, localizer, emaliSender) + { + } + } +} \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Startup.cs b/projects/IoT/IoTServices/FBeeService/Startup.cs index 78f8c3ce..56d139aa 100644 --- a/projects/IoT/IoTServices/FBeeService/Startup.cs +++ b/projects/IoT/IoTServices/FBeeService/Startup.cs @@ -1,8 +1,6 @@ -using Application.Domain.Entities; using IoT.UI.Shard; using Microsoft.AspNetCore.Builder; using Microsoft.AspNetCore.Hosting; -using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; @@ -26,10 +24,5 @@ namespace FBeeService base.Configure(app, env, loggerFactory); app.ApplicationServices.GetService().Start(); } - - public override void OnModelCreating(ModelBuilder modelBuilder) - { - base.OnModelCreating(modelBuilder); - } } } \ No newline at end of file diff --git a/projects/IoT/IoTServices/FBeeService/Views/Home/Index.cshtml b/projects/IoT/IoTServices/FBeeService/Views/Home/Index.cshtml index bd958b72..9931abcc 100644 --- a/projects/IoT/IoTServices/FBeeService/Views/Home/Index.cshtml +++ b/projects/IoT/IoTServices/FBeeService/Views/Home/Index.cshtml @@ -24,8 +24,8 @@ @Html.DisplayFor(o => item.Enable) @item.UserName @item.Password - 查询网关信息 - 查询网关设备 + 查询网关信息 + 查询网关设备 查看设备 } diff --git a/projects/IoTCenter/Application/Domain/Entities/Users/Permission.cs b/projects/IoTCenter/Application/Domain/Entities/Users/Permission.cs deleted file mode 100644 index 4b376e5f..00000000 --- a/projects/IoTCenter/Application/Domain/Entities/Users/Permission.cs +++ /dev/null @@ -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 RolePermissions { get; set; } = new List(); - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Domain/Entities/Users/PermissionCategory.cs b/projects/IoTCenter/Application/Domain/Entities/Users/PermissionCategory.cs deleted file mode 100644 index 252cc500..00000000 --- a/projects/IoTCenter/Application/Domain/Entities/Users/PermissionCategory.cs +++ /dev/null @@ -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 - { - public List Permissions { get; set; } = new List(); - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Domain/Entities/Users/Role.cs b/projects/IoTCenter/Application/Domain/Entities/Users/Role.cs deleted file mode 100644 index 97559793..00000000 --- a/projects/IoTCenter/Application/Domain/Entities/Users/Role.cs +++ /dev/null @@ -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 UserRoles { get; set; } = new List(); - public List RolePermissions { get; set; } = new List(); - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Domain/Entities/Users/RolePermission.cs b/projects/IoTCenter/Application/Domain/Entities/Users/RolePermission.cs deleted file mode 100644 index a0ebf3a2..00000000 --- a/projects/IoTCenter/Application/Domain/Entities/Users/RolePermission.cs +++ /dev/null @@ -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; } - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Domain/Entities/Users/User.cs b/projects/IoTCenter/Application/Domain/Entities/Users/User.cs deleted file mode 100644 index 3b380d0a..00000000 --- a/projects/IoTCenter/Application/Domain/Entities/Users/User.cs +++ /dev/null @@ -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 UserRoles { get; set; } = new List(); - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Domain/Entities/Users/UserRole.cs b/projects/IoTCenter/Application/Domain/Entities/Users/UserRole.cs deleted file mode 100644 index 0afa0826..00000000 --- a/projects/IoTCenter/Application/Domain/Entities/Users/UserRole.cs +++ /dev/null @@ -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; } - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Models/Users/EditPermissionModel.cs b/projects/IoTCenter/Application/Models/Users/EditPermissionModel.cs deleted file mode 100644 index 1f076097..00000000 --- a/projects/IoTCenter/Application/Models/Users/EditPermissionModel.cs +++ /dev/null @@ -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; } - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Models/Users/EditRoleModel.cs b/projects/IoTCenter/Application/Models/Users/EditRoleModel.cs deleted file mode 100644 index ce799a85..00000000 --- a/projects/IoTCenter/Application/Models/Users/EditRoleModel.cs +++ /dev/null @@ -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 Permissions { get; set; } = new List(); - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Models/Users/EditSettingModel.cs b/projects/IoTCenter/Application/Models/Users/EditSettingModel.cs deleted file mode 100644 index ca79fc54..00000000 --- a/projects/IoTCenter/Application/Models/Users/EditSettingModel.cs +++ /dev/null @@ -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; } - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Application/Models/Users/EditUserModel.cs b/projects/IoTCenter/Application/Models/Users/EditUserModel.cs deleted file mode 100644 index 0bf852cc..00000000 --- a/projects/IoTCenter/Application/Models/Users/EditUserModel.cs +++ /dev/null @@ -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 Roles { get; set; } = new List(); - } -} \ No newline at end of file diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/ApiController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/ApiController.cs index ac2d140f..c9e15ef5 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/IoT/ApiController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/ApiController.cs @@ -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 - { - private readonly AjaxController _ajax; +//namespace IoTCenter.Areas.Admin.Controllers +//{ +// [Authorize] +// [Area(nameof(Admin))] +// public class ApiController : CrudController +// { +// private readonly AjaxController _ajax; - public ApiController(IRepository repo, AjaxController ajax) : base(repo) - { - this._ajax = ajax; - } +// public ApiController(IRepository repo, AjaxController ajax) : base(repo) +// { +// this._ajax = ajax; +// } - public override IQueryable Query(ApiSearchModel model, IQueryable 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)); - } - } -} \ No newline at end of file +// public override IQueryable Query(ApiSearchModel model, IQueryable 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)); +// } +// } +//} \ No newline at end of file diff --git a/projects/IoTCenter/Areas/Admin/Controllers/IoT/CommandController.cs b/projects/IoTCenter/Areas/Admin/Controllers/IoT/CommandController.cs index a0fdffe5..82a12a1c 100644 --- a/projects/IoTCenter/Areas/Admin/Controllers/IoT/CommandController.cs +++ b/projects/IoTCenter/Areas/Admin/Controllers/IoT/CommandController.cs @@ -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, DisplayCommandModel, EditCommandModel> - { - private readonly IRepository _nodeRepo; - private readonly IRepository _senceRepo; - private readonly IRepository _apiRepo; - private readonly IRepository _repo; - private readonly AjaxController _ajax; - private readonly IHubContext _pageHubContext; +//namespace IoTCenter.Areas.Admin.Controllers +//{ +// [Authorize] +// [Area(nameof(Admin))] +// public class CommandController : CrudController, DisplayCommandModel, EditCommandModel> +// { +// private readonly IRepository _nodeRepo; +// private readonly IRepository _senceRepo; +// private readonly IRepository _apiRepo; +// private readonly IRepository _repo; +// private readonly AjaxController _ajax; +// private readonly IHubContext _pageHubContext; - public CommandController(IRepository nodeRepo, IRepository senceRepo, IRepository apiRepo, IRepository repo, AjaxController ajax, IHubContext pageHubContext) : base(repo) - { - this._repo = repo; - this._nodeRepo = nodeRepo; - this._senceRepo = senceRepo; - this._apiRepo = apiRepo; - this._ajax = ajax; - this._pageHubContext = pageHubContext; - } +// public CommandController(IRepository nodeRepo, IRepository senceRepo, IRepository apiRepo, IRepository repo, AjaxController ajax, IHubContext 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 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 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 Include(IQueryable query) - { - return query.Include(o => o.Sence).Include(o => o.Api).ThenInclude(o => o.Device).ThenInclude(o => o.Node); - } +// public override IQueryable Include(IQueryable 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 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()).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; - } - } -} \ No newline at end of file +// private List 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()).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; +// } +// } +//} \ No newline at end of file diff --git a/projects/IoTCenter/Controllers/AppController.cs b/projects/IoTCenter/Controllers/AppController.cs index b873a828..c6b56b40 100644 --- a/projects/IoTCenter/Controllers/AppController.cs +++ b/projects/IoTCenter/Controllers/AppController.cs @@ -1,162 +1,162 @@ -using Application.Domain.Entities; -using Application.Models; -using Application.Services; -using Infrastructure.Data; -using Infrastructure.Extensions; -using Infrastructure.Jwt; -using IoTShared; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.SignalR; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.Configuration; -using Newtonsoft.Json; -using System; -using System.Collections.Generic; -using System.Linq; -using Vibrant.InfluxDB.Client; -using Vibrant.InfluxDB.Client.Rows; +//using Application.Domain.Entities; +//using Application.Models; +//using Application.Services; +//using Infrastructure.Data; +//using Infrastructure.Extensions; +//using Infrastructure.Jwt; +//using IoTShared; +//using Microsoft.AspNetCore.Authorization; +//using Microsoft.AspNetCore.Mvc; +//using Microsoft.AspNetCore.SignalR; +//using Microsoft.EntityFrameworkCore; +//using Microsoft.Extensions.Configuration; +//using Newtonsoft.Json; +//using System; +//using System.Collections.Generic; +//using System.Linq; +//using Vibrant.InfluxDB.Client; +//using Vibrant.InfluxDB.Client.Rows; -namespace IoTCenter.Controllers -{ - public class AppController : Controller - { - private readonly IConfiguration _configuration; - private readonly IJwtHelper _jwtHelper; - private readonly IRepository _nodeRepo; - private readonly IRepository _deviceRepo; - private readonly IHubContext _pageHubContext; +//namespace IoTCenter.Controllers +//{ +// public class AppController : Controller +// { +// private readonly IConfiguration _configuration; +// private readonly IJwtHelper _jwtHelper; +// private readonly IRepository _nodeRepo; +// private readonly IRepository _deviceRepo; +// private readonly IHubContext _pageHubContext; - public AppController(IConfiguration configuration, - IJwtHelper jwtHelper, - IRepository nodeRepo, - IRepository deviceRepo, - IHubContext pageHubContext) - { - this._configuration = configuration; - this._jwtHelper = jwtHelper; - this._nodeRepo = nodeRepo; - this._deviceRepo = deviceRepo; - this._pageHubContext = pageHubContext; - } +// public AppController(IConfiguration configuration, +// IJwtHelper jwtHelper, +// IRepository nodeRepo, +// IRepository deviceRepo, +// IHubContext pageHubContext) +// { +// this._configuration = configuration; +// this._jwtHelper = jwtHelper; +// this._nodeRepo = nodeRepo; +// this._deviceRepo = deviceRepo; +// this._pageHubContext = pageHubContext; +// } - [Authorize] - public IActionResult Index() - { - return View(); - } +// [Authorize] +// public IActionResult Index() +// { +// return View(); +// } - public IActionResult GetNodes(string token) - { - var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); - var model = this._nodeRepo.ReadOnlyTable() - .Select(o => new { o.Id, o.Number, o.Name, o.DisplayOrder, Count = o.Devices.Count }) - .ToList(); - return Json(model); - } +// public IActionResult GetNodes(string token) +// { +// var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); +// var model = this._nodeRepo.ReadOnlyTable() +// .Select(o => new { o.Id, o.Number, o.Name, o.DisplayOrder, Count = o.Devices.Count }) +// .ToList(); +// return Json(model); +// } - public IActionResult GetNode(string token, string number) - { - var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); - var model = this._nodeRepo.ReadOnlyTable() - .Include(o => o.Sences) - .Include(o => o.Devices).ThenInclude(o => o.Data) - .FirstOrDefault(o => o.Number == number); - return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); - } +// public IActionResult GetNode(string token, string number) +// { +// var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); +// var model = this._nodeRepo.ReadOnlyTable() +// .Include(o => o.Sences) +// .Include(o => o.Devices).ThenInclude(o => o.Data) +// .FirstOrDefault(o => o.Number == number); +// return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); +// } - public IActionResult GetDevice(string token, string number) - { - var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); - var model = this._deviceRepo.ReadOnlyTable() - .Include(o => o.Data) - .Include(o => o.Apis).ThenInclude(o => o.Parameters) - .FirstOrDefault(o => o.Number == number); - return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); - } +// public IActionResult GetDevice(string token, string number) +// { +// var userName = this._jwtHelper.GetPayload(token)["UserName"].ToString(); +// var model = this._deviceRepo.ReadOnlyTable() +// .Include(o => o.Data) +// .Include(o => o.Apis).ThenInclude(o => o.Parameters) +// .FirstOrDefault(o => o.Number == number); +// return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); +// } - public IActionResult Exec(string connectionId, string node, string cmd, Guid id) - { - try - { - var query = string.Empty; - foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id"))) - { - query = query.SetParam(item.Key, item.Value); - } - this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Exec), connectionId, id, cmd, query); - return Json(ApiResponse.AsyncSuccess()); - } - catch (Exception ex) - { - ex.PrintStack(); - return Json(ApiResponse.Error(ex)); - } - } +// public IActionResult Exec(string connectionId, string node, string cmd, Guid id) +// { +// try +// { +// var query = string.Empty; +// foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id"))) +// { +// query = query.SetParam(item.Key, item.Value); +// } +// this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Exec), connectionId, id, cmd, query); +// return Json(ApiResponse.AsyncSuccess()); +// } +// catch (Exception ex) +// { +// ex.PrintStack(); +// return Json(ApiResponse.Error(ex)); +// } +// } - public IActionResult ExecAll(string connectionId, string node, string cmd, List id) - { - try - { - var query = string.Empty; - foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id["))) - { - query = query.SetParam(item.Key, item.Value); - } - this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.ExecAll), connectionId, id, cmd, query); - return Json(ApiResponse.AsyncSuccess()); - } - catch (Exception ex) - { - ex.PrintStack(); - return Json(ApiResponse.Error(ex)); - } - } +// public IActionResult ExecAll(string connectionId, string node, string cmd, List id) +// { +// try +// { +// var query = string.Empty; +// foreach (var item in Request.Query.Where(o => o.Key != "node" && o.Key != "cmd" && !o.Key.StartsWith("id["))) +// { +// query = query.SetParam(item.Key, item.Value); +// } +// this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.ExecAll), connectionId, id, cmd, query); +// return Json(ApiResponse.AsyncSuccess()); +// } +// catch (Exception ex) +// { +// ex.PrintStack(); +// return Json(ApiResponse.Error(ex)); +// } +// } - public IActionResult Sence(string connectionId, string node, Guid id) - { - try - { - this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Sence), connectionId, id); - return Json(ApiResponse.AsyncSuccess()); - } - catch (Exception ex) - { - ex.PrintStack(); - return Json(ApiResponse.Error(ex)); - } - } +// public IActionResult Sence(string connectionId, string node, Guid id) +// { +// try +// { +// this._pageHubContext.Clients.Group(node).SendAsync(nameof(INodeService.Sence), connectionId, id); +// return Json(ApiResponse.AsyncSuccess()); +// } +// catch (Exception ex) +// { +// ex.PrintStack(); +// return Json(ApiResponse.Error(ex)); +// } +// } - public IActionResult Data(Guid id, string time = "10m") - { - 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(); - 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(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(); - 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() - }); - } - } - return Json(list); - } - } -} \ No newline at end of file +// public IActionResult Data(Guid id, string time = "10m") +// { +// 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(); +// 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(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(); +// 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() +// }); +// } +// } +// return Json(list); +// } +// } +//} \ No newline at end of file diff --git a/projects/IoTCenter/Controllers/DeviceController.cs b/projects/IoTCenter/Controllers/DeviceController.cs index 8a617e5f..4d59196e 100644 --- a/projects/IoTCenter/Controllers/DeviceController.cs +++ b/projects/IoTCenter/Controllers/DeviceController.cs @@ -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 _nodeRepo; - private readonly IRepository _deviceRepo; +//namespace IoTCenter.Controllers +//{ +// [Authorize] +// public class DeviceController : Controller +// { +// private readonly IConfiguration _configuration; +// private readonly IRepository _nodeRepo; +// private readonly IRepository _deviceRepo; - public DeviceController(IConfiguration configuration, IRepository nodeRepo, IRepository deviceRepo) - { - this._configuration = configuration; - this._nodeRepo = nodeRepo; - this._deviceRepo = deviceRepo; - } +// public DeviceController(IConfiguration configuration, IRepository nodeRepo, IRepository 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(); - 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(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(); - 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() - }); - } - } - return Json(list); - } - } -} \ No newline at end of file +// 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(); +// 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(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(); +// 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() +// }); +// } +// } +// return Json(list); +// } +// } +//} \ No newline at end of file diff --git a/projects/IoTCenter/Controllers/HomeController.cs b/projects/IoTCenter/Controllers/HomeController.cs index d74f7936..5482deaf 100644 --- a/projects/IoTCenter/Controllers/HomeController.cs +++ b/projects/IoTCenter/Controllers/HomeController.cs @@ -45,7 +45,7 @@ namespace IoTCenter.Controllers var model = this._nodeRepo.ReadOnlyTable() .Include(o => o.Sences) .Include(o => o.Devices).ThenInclude(o => o.Data) - .Include(o => o.Devices).ThenInclude(o => o.Apis).ThenInclude(o => o.Parameters) + //.Include(o => o.Devices).ThenInclude(o => o.Apis).ThenInclude(o => o.Parameters) .FirstOrDefault(o => o.Id == id); return Json(model, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore }); } diff --git a/projects/IoTCenter/Controllers/NotifyController.cs b/projects/IoTCenter/Controllers/NotifyController.cs index fa52c9a9..6dbc0f24 100644 --- a/projects/IoTCenter/Controllers/NotifyController.cs +++ b/projects/IoTCenter/Controllers/NotifyController.cs @@ -73,7 +73,7 @@ namespace IoTCenter.Controllers var device = this._deviceRepo.Table() .Include(o => o.Data) - .Include(o => o.Apis).ThenInclude(o => o.Parameters) + //.Include(o => o.Apis).ThenInclude(o => o.Parameters) .FirstOrDefault(o => o.Number == newDevice.Number); if (device != null && device.Id != newDevice.Id) @@ -107,42 +107,42 @@ namespace IoTCenter.Controllers data.FromPlain(newData); } - foreach (var command in device.Apis.Select(o => o.Command).ToList()) - { - if (!newDevice.Apis.Any(o => o.Command == command)) - { - var api = device.Apis.FirstOrDefault(o => o.Command == command); - device.Apis.Remove(api); - } - } - foreach (var newApi in newDevice.Apis) - { - var api = device.Apis.FirstOrDefault(o => o.Command == newApi.Command); - if (api == null) - { - api = new Api(); - device.Apis.Add(api); - } - api.FromPlain(newApi); - foreach (var name in api.Parameters.Select(o => o.Name).ToList()) - { - if (!newApi.Parameters.Any(o => o.Name == name)) - { - var parameter = api.Parameters.FirstOrDefault(o => o.Name == name); - api.Parameters.Remove(parameter); - } - } - foreach (var newParameter in newApi.Parameters) - { - var parameter = api.Parameters.FirstOrDefault(o => o.Name == newParameter.Name); - if (parameter == null) - { - parameter = new Parameter(); - api.Parameters.Add(parameter); - } - parameter.FromPlain(newParameter); - } - } + //foreach (var command in device.Apis.Select(o => o.Command).ToList()) + //{ + // if (!newDevice.Apis.Any(o => o.Command == command)) + // { + // var api = device.Apis.FirstOrDefault(o => o.Command == command); + // device.Apis.Remove(api); + // } + //} + //foreach (var newApi in newDevice.Apis) + //{ + // var api = device.Apis.FirstOrDefault(o => o.Command == newApi.Command); + // if (api == null) + // { + // api = new Api(); + // device.Apis.Add(api); + // } + // api.FromPlain(newApi); + // foreach (var name in api.Parameters.Select(o => o.Name).ToList()) + // { + // if (!newApi.Parameters.Any(o => o.Name == name)) + // { + // var parameter = api.Parameters.FirstOrDefault(o => o.Name == name); + // api.Parameters.Remove(parameter); + // } + // } + // foreach (var newParameter in newApi.Parameters) + // { + // var parameter = api.Parameters.FirstOrDefault(o => o.Name == newParameter.Name); + // if (parameter == null) + // { + // parameter = new Parameter(); + // api.Parameters.Add(parameter); + // } + // parameter.FromPlain(newParameter); + // } + //} this._deviceRepo.SaveChanges(); device.Node = node; UpdatePage(device); @@ -206,15 +206,15 @@ namespace IoTCenter.Controllers private IComparable GetDataValue(Data deviceData) { - if (deviceData.Type == "Int") + if (deviceData.Type == DeviceDataType.Int) { return int.Parse(deviceData.Value); } - else if (deviceData.Type == "Float") + else if (deviceData.Type == DeviceDataType.Float) { return double.Parse(deviceData.Value); } - if (deviceData.Type == "DateTime") + if (deviceData.Type == DeviceDataType.DateTime) { return DateTime.Parse(deviceData.Value); } diff --git a/projects/IoTCenter/IoTCenter.csproj b/projects/IoTCenter/IoTCenter.csproj index e91f67ea..3f8f107f 100644 --- a/projects/IoTCenter/IoTCenter.csproj +++ b/projects/IoTCenter/IoTCenter.csproj @@ -1,7 +1,6 @@  netcoreapp2.2 - InProcess true @@ -15,4 +14,9 @@ + + + + + \ No newline at end of file diff --git a/projects/IoTCenter/Program.cs b/projects/IoTCenter/Program.cs index 688e9ad6..2f9c0a4b 100644 --- a/projects/IoTCenter/Program.cs +++ b/projects/IoTCenter/Program.cs @@ -13,6 +13,7 @@ namespace IoTCenter var host = "localhost"; WebHost.CreateDefaultBuilder(args) .Run(new List { + new EFConfigurationValue { Id = "openapi.name", Value= "v1" }, new EFConfigurationValue { Id = "openapi.title", Value= "web api" }, new EFConfigurationValue { Id = "openapi.version", Value= "1.0" }, new EFConfigurationValue { Id = "server.urls", Value= "http://*:8001" }, diff --git a/projects/IoTCenter/Startup.cs b/projects/IoTCenter/Startup.cs index 72473e28..064297aa 100644 --- a/projects/IoTCenter/Startup.cs +++ b/projects/IoTCenter/Startup.cs @@ -1,29 +1,15 @@ -using Application.Domain.Entities; using Application.Services; -using Infrastructure.Data; -using Infrastructure.Domain; using Infrastructure.Email; -using Infrastructure.Extensions; using Infrastructure.Sms; -using Infrastructure.UI; -using Infrastructure.Web; -using IoTShared; -using Microsoft.AspNetCore.Authentication; -using Microsoft.AspNetCore.Authentication.Cookies; -using Microsoft.AspNetCore.Builder; +using IoT.UI.Shard; using Microsoft.AspNetCore.Hosting; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; namespace IoTCenter { - public class Startup : BaseStartup + public class Startup : IoTServiceStartup { public Startup(IConfiguration configuration, IHostingEnvironment env) : base(configuration, env) { @@ -34,139 +20,12 @@ namespace IoTCenter services.AddTransient(); services.AddTransient(); services.AddSingleton(); - services.AddSignalR(o => o.EnableDetailedErrors = true); base.ConfigureServices(services); } - public override void ConfigureOptions(IServiceCollection services) - { - services.ConfigureOptions(new FileConfigureOptions(_env, new List { "IoT.Shared" })); - } - - public override void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) - { - base.Configure(app, env, loggerFactory); - } - - public override Task ValidatePrincipal(CookieValidatePrincipalContext arg) - { - return Task.Run(() => - { - var userRepo = arg.HttpContext.RequestServices.GetService>(); - - var userName = arg.Principal.Identity.Name; - var userPermissions = userRepo.ReadOnlyTable().Where(o => o.UserName == userName) - .SelectMany(o => o.UserRoles) - .Select(o => o.Role) - .SelectMany(o => o.RolePermissions) - .Select(o => o.Permission.Number) - .ToList(); - var currentPermissions = arg.Principal.Claims.Where(o => o.Type == "Role").Select(o => o.Value).ToList(); - if (!currentPermissions.SequenceEqual(userPermissions)) - { - arg.HttpContext.SignOutAsync(); - arg.HttpContext.SignIn(userName, userPermissions, arg.Properties.IsPersistent); - } - }); - } - public override void OnModelCreating(ModelBuilder modelBuilder) { - modelBuilder.Entity().HasOne(o => o.Parent).WithMany(o => o.Children).HasForeignKey(o => o.ParentId).OnDelete(DeleteBehavior.SetNull); - modelBuilder.Entity().HasOne(o => o.Category).WithMany(o => o.Permissions).HasForeignKey(o => o.CategoryId).OnDelete(DeleteBehavior.SetNull); - modelBuilder.Entity().HasOne(o => o.User).WithMany(o => o.UserRoles).HasForeignKey(o => o.UserId); - modelBuilder.Entity().HasOne(o => o.Role).WithMany(o => o.UserRoles).HasForeignKey(o => o.RoleId); - modelBuilder.Entity().HasOne(o => o.Role).WithMany(o => o.RolePermissions).HasForeignKey(o => o.RoleId); - modelBuilder.Entity().HasOne(o => o.Permission).WithMany(o => o.RolePermissions).HasForeignKey(o => o.PermissionId); - modelBuilder.Entity().HasIndex(o => o.UserName).IsUnique(); - modelBuilder.Entity().HasIndex(o => o.Name).IsUnique(); - modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); - modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); - modelBuilder.Entity().HasIndex(o => new { o.UserId, o.RoleId }).IsUnique(); - modelBuilder.Entity().HasIndex(o => new { o.RoleId, o.PermissionId }).IsUnique(); - // - modelBuilder.Entity().HasOne(o => o.Node).WithMany(o => o.Devices).HasForeignKey(o => o.NodeId); - modelBuilder.Entity().HasOne(o => o.Device).WithMany(o => o.Data).HasForeignKey(o => o.DeviceId); - modelBuilder.Entity().HasOne(o => o.Device).WithMany(o => o.Apis).HasForeignKey(o => o.DeviceId); - modelBuilder.Entity().HasOne(o => o.Api).WithMany(o => o.Parameters).HasForeignKey(o => o.ApiId); - modelBuilder.Entity().HasOne(o => o.Node).WithMany(o => o.Sences).HasForeignKey(o => o.NodeId); - modelBuilder.Entity().HasOne(o => o.Sence).WithMany(o => o.Commands).HasForeignKey(o => o.SenceId); - modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); - modelBuilder.Entity().HasIndex(o => o.Number).IsUnique(); - modelBuilder.Entity().HasIndex(o => new { o.DeviceId, o.Key }).IsUnique(); - modelBuilder.Entity().HasIndex(o => new { o.DeviceId, o.Path, o.Command }).IsUnique(); - modelBuilder.Entity().HasIndex(o => new { o.ApiId, o.Name }).IsUnique(); - } - - public override void UseSignalR(IApplicationBuilder app) - { - app.UseSignalR(routes => - { - routes.MapHub("/hub", o => - { - o.ApplicationMaxBufferSize = long.MaxValue; - o.TransportMaxBufferSize = long.MaxValue; - }); - }); - } - - public override void Seed(DbContext dbContext, IServiceProvider serviceProvider, IConfiguration configuration) - { - dbContext.Set().Add(new PermissionCategory - { - Name = "配置", - Number = "Configuration", - Permissions = new List { - new Permission { Name = "查询配置", Number = "ListConfiguration",DisplayOrder =1 }, - new Permission { Name = "修改配置", Number = "EditConfiguration",DisplayOrder =2 } - } - }); - int i = 1; - var skipReadCollection = new string[] { "Permission" }; - var skipAddCollection = new string[] { "Permission", "Setting", "Node", "Device", "Data", "Api", "Parameter" }; - foreach (var item in dbContext.Model.GetEntityTypes()) - { - var type = item.ClrType; - var name = type.GetDisplayName(); - var number = type.Name; - var category = new PermissionCategory - { - Name = name, - Number = type.Name, - DisplayOrder = i - }; - category.Permissions.Add(new Permission { Name = $"查询{name}", Number = $"List{number}", DisplayOrder = 10 * i + 1 }); - if (!skipReadCollection.Contains(type.Name)) - { - category.Permissions.Add(new Permission { Name = $"查看{name}", Number = $"Read{number}", DisplayOrder = 10 * i + 2 }); - } - if (!skipAddCollection.Contains(type.Name)) - { - category.Permissions.Add(new Permission { Name = $"添加{name}", Number = $"Add{number}", DisplayOrder = 10 * i + 3 }); - } - if (!typeof(IDisableUpdate).IsAssignableFrom(type)) - { - category.Permissions.Add(new Permission { Name = $"修改{name}", Number = $"Edit{number}", DisplayOrder = 10 * i + 4 }); - } - if (!typeof(IDisableDelete).IsAssignableFrom(type)) - { - category.Permissions.Add(new Permission { Name = $"删除{name}", Number = $"Delete{number}", DisplayOrder = 10 * i + 5 }); - } - dbContext.Set().Add(category); - i += 1; - } - dbContext.SaveChanges(); - var adminRole = new Role { Name = "管理员", IsReadOnly = true }; - foreach (var item in dbContext.Set()) - { - adminRole.RolePermissions.Add(new RolePermission { Permission = item, IsReadOnly = true }); - } - dbContext.Set().Add(new User - { - UserName = "admin", - UserRoles = new List { new UserRole { Role = adminRole } } - }); - dbContext.SaveChanges(); + base.OnModelCreating(modelBuilder); } } } \ No newline at end of file diff --git a/projects/IoTCenter/appsettings.json b/projects/IoTCenter/appsettings.json index 03983ee5..3a3d7e8c 100644 --- a/projects/IoTCenter/appsettings.json +++ b/projects/IoTCenter/appsettings.json @@ -8,7 +8,7 @@ "UseMiniProfiler": false, "ConnectionStrings": { "database.mysql.connection": "Server=127.0.0.1;Port=3306;Database=iotcenter;Uid=root;Pwd=root;", - "database.sqlite.connection": "Data Source=iotcenter.db" + "database.sqlite.connection": "Data Source=data.db" }, "AppSettings": { "database": "sqlite", diff --git a/projects/IoTCenter/libman.json b/projects/IoTCenter/libman.json deleted file mode 100644 index 9c72767d..00000000 --- a/projects/IoTCenter/libman.json +++ /dev/null @@ -1,6 +0,0 @@ -{ - "version": "1.0", - "defaultProvider": "cdnjs", - "libraries": [ - ] -} \ No newline at end of file diff --git a/projects/UserCenter/appsettings.json b/projects/UserCenter/appsettings.json index da102c7d..e20a5425 100644 --- a/projects/UserCenter/appsettings.json +++ b/projects/UserCenter/appsettings.json @@ -8,7 +8,7 @@ "UseMiniProfiler": false, "ConnectionStrings": { "database.mysql.connection": "Server=127.0.0.1;Port=3306;Database=usercenter;Uid=root;Pwd=root;", - "database.sqlite.connection": "Data Source=usercenter.db" + "database.sqlite.connection": "Data Source=data.db" }, "AppSettings": { "database": "sqlite", @@ -16,7 +16,7 @@ }, //Ocelot config "GlobalConfiguration": { - "BaseUrl": "http://192.168.3.83:8000/" + "BaseUrl": "http://localhost:8000/" }, "ReRoutes": [ { @@ -24,7 +24,7 @@ "DownstreamScheme": "http", "DownstreamHostAndPorts": [ { - "Host": "192.168.3.83", + "Host": "localhost", "Port": 8001 } ],