Former-commit-id: a20569f16763df53c27c65767a75c02123100269
Former-commit-id: 30928faa249fd8ab7e7456da673ad6281a3e5d23
1.0
wanggang 5 years ago
parent 9c426f9903
commit b9b0583761

@ -1,7 +1,7 @@
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using System;
using System.Linq.Expressions;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
namespace Infrastructure.Extensions
{
@ -85,4 +85,4 @@ namespace Infrastructure.Extensions
}
}
}
}
}

@ -336,5 +336,10 @@ namespace Infrastructure.Web.Mvc
}
return RedirectTo();
}
protected ControllerScopeType? GetScopeType()
{
return (this.GetType().GetCustomAttributes(false).FirstOrDefault(o => o.GetType() == typeof(ControllerScopeAttribute)) as ControllerScopeAttribute)?.Scope;
}
}
}

@ -14,5 +14,6 @@ namespace IoT.Shared.Application.Domain.Entities
public Guid OrganId { get; set; }
public Organ Organ { get; set; }
public List<DepartmentUser> DepartmentUsers { get; set; } = new List<DepartmentUser>();
public List<Job> Jobs { get; set; } = new List<Job>();
}
}

@ -8,11 +8,14 @@ namespace IoT.Shared.Application.Domain.Entities
[Scope(ScopeAttribute.PlatformAll | ScopeAttribute.OrganAll | ScopeType.UserRead | ScopeType.UserEdit)]
public class DepartmentUser : BaseEntity
{
public string Position { get; set; }
public DepartmentUserType Type { get; set; }
public string CustomType { get; set; }
public Guid UserId { get; set; }
public Guid DeparementId { get; set; }
public Guid? JobId { get; set; }
public User User { get; set; }
public Department Department { get; set; }
public Job Job { get; set; }
}
}

@ -0,0 +1,17 @@
using Infrastructure.Domain;
using System;
using System.Collections.Generic;
namespace IoT.Shared.Application.Domain.Entities
{
public class Job : BaseEntity
{
public string Name { get; set; }
public int Level { get; set; }
public Guid TitleId { get; set; }
public Guid DepartmentId { get; set; }
public Title Title { get; set; }
public Department Department { get; set; }
public List<DepartmentUser> DepartmentUsers { get; set; } = new List<DepartmentUser>();
}
}

@ -22,5 +22,6 @@ namespace IoT.Shared.Application.Domain.Entities
public List<OrganIoTScene> OrganScenes { get; set; } = new List<OrganIoTScene>();
public List<Role> Roles { get; set; } = new List<Role>();
public List<PermissionCategory> Categories { get; set; } = new List<PermissionCategory>();
public List<Title> Titles { get; set; } = new List<Title>();
}
}

@ -0,0 +1,16 @@
using Infrastructure.Domain;
using System;
using System.Collections.Generic;
namespace IoT.Shared.Application.Domain.Entities
{
public class Title : BaseEntity
{
public string Name { get; set; }
public int MinLevel { get; set; }
public int MaxLevel { get; set; }
public Guid OrganId { get; set; }
public Organ Organ { get; set; }
public List<Job> Jobs { get; set; } = new List<Job>();
}
}

@ -4,6 +4,7 @@ using Infrastructure.Extensions;
using IoT.Shared.Application.Domain.Entities;
using Jint;
using Jint.Native;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
@ -18,6 +19,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
public class AjaxController
{
protected readonly ILogger<AjaxController> _logger;
protected readonly IHttpContextAccessor _httpContext;
protected readonly IRepository<IoTProductCategory> _categoryRepo;
protected readonly IRepository<Organ> _organRepo;
protected readonly IRepository<BuildingIoTGateway> _buildingIoTGatewayRepo;
@ -32,6 +34,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
protected readonly IRepository<IoTSceneTigger> _sceneTiggerRepo;
public AjaxController(ILogger<AjaxController> logger,
IHttpContextAccessor httpContxt,
IRepository<IoTProductCategory> categoryRepo,
IRepository<IoTProduct> productRepo,
IRepository<Organ> organRepo,
@ -46,6 +49,7 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
IRepository<IoTSceneTigger> sceneTiggerRepo)
{
this._logger = logger;
this._httpContext = httpContxt;
this._categoryRepo = categoryRepo;
this._productRepo = productRepo;
this._organRepo = organRepo;
@ -351,5 +355,10 @@ namespace IoT.Shared.Areas.IoTCenter.Controlls
return new JsonResult(ex.Message);
}
}
protected bool IsAjax()
{
return this._httpContext.HttpContext.Request.IsAjax();
}
}
}

@ -7,6 +7,10 @@
object-fit: contain;
}
.nav-header {
padding: .5rem !important;
}
.navbar-nav .nav-link.active {
color: #fff !important;
background-color: #007bff;

@ -1,6 +1,7 @@
using Infrastructure.Data;
using Infrastructure.Extensions;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.Extensions.Logging;
@ -14,9 +15,11 @@ namespace Platform.Areas.IoTCenter.Controllers
public class AjaxController : IoT.Shared.Areas.IoTCenter.Controlls.AjaxController
{
private readonly IRepository<Area> _areaRepo;
private readonly IRepository<Building> _buildingRepo;
private readonly IRepository<Role> _roleRepo;
public AjaxController(ILogger<AjaxController> logger,
IHttpContextAccessor httpContxt,
IRepository<IoTProductCategory> categoryRepo,
IRepository<IoTProduct> productRepo,
IRepository<Organ> organRepo,
@ -30,8 +33,10 @@ namespace Platform.Areas.IoTCenter.Controllers
IRepository<IoTApi> apiRepo,
IRepository<IoTSceneTigger> sceneTiggerRepo,
IRepository<Area> areaRepo,
IRepository<Building> buildingRepo,
IRepository<Role> roleRepo)
: base(logger,
httpContxt,
categoryRepo,
productRepo,
organRepo,
@ -46,6 +51,7 @@ namespace Platform.Areas.IoTCenter.Controllers
sceneTiggerRepo)
{
this._areaRepo = areaRepo;
this._buildingRepo = buildingRepo;
this._roleRepo = roleRepo;
}
@ -61,6 +67,19 @@ namespace Platform.Areas.IoTCenter.Controllers
return new SelectList(list, "Id", "Name", selected);
}
public JsonResult GetOrganBuilding(Guid parentId, Guid? selected = null, Guid? currentId = null)
{
var list = this._buildingRepo.ReadOnlyTable()
.Where(o => o.ParentId != null)
.Where(o => o.OrganId == parentId)
.WhereIf(currentId.HasValue, o => o.Id != currentId.Value)
.OrderBy(o => o.Parent)
.ThenBy(o => o.DisplayOrder)
.Select(o => new { o.Id, Name = $"{o.Name}({o.Number})" })
.ToList();
return new JsonResult(new SelectList(list, "Id", "Name", selected));
}
public MultiSelectList GetOrganMultiSelectList(List<Guid> selected)
{
if (selected == null)

@ -5,6 +5,7 @@ using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Rendering;
using Microsoft.EntityFrameworkCore;
using Platform.Application.Models;
using Platform.Areas.IoTCenter.Controllers;
@ -37,7 +38,12 @@ namespace Platform.Areas.UserCenter.Controllers
public override IQueryable<Building> Query(PagedListModel<EditBuildingModel> model, IQueryable<Building> query)
{
return query.Where(o => o.ParentId != null);
return query
.WhereIf(model.Query.ParentId.HasValue, o => o.ParentId == model.Query.ParentId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(!string.IsNullOrEmpty(model.Query.Number), o => o.Number.Contains(model.Query.Number))
.WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.CustomType), o => o.CustomType.Contains(model.Query.CustomType));
}
public override void ToDisplayModel(Building entity, EditBuildingModel model)
@ -61,8 +67,11 @@ namespace Platform.Areas.UserCenter.Controllers
model.IoTGateways = entity.BuildingIoTGateways.Select(o => o.IoTGatewayId).ToList();
}
this.ViewData.MultiSelectList(o => model.IoTGateways, () => this._ajax.GetNodeMultiSelectList(model.IoTGateways));
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetAreaSelectList(model.ParentId, model.Id));
ViewData.SelectList(o => model.OrganId, () => this._ajax.GetOrganSelectList(model.OrganId));
if (model.OrganId.HasValue)
{
ViewData.SelectList(o => model.ParentId, () => this._ajax.GetOrganBuilding(model.OrganId.Value, model.ParentId, model.Id).Value as SelectList);
}
}
public override void ToEntity(EditBuildingModel model, Building entity)

@ -0,0 +1,32 @@
using Infrastructure.Application;
using Infrastructure.Data;
using Infrastructure.Extensions;
using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Platform.Application.Models;
using Platform.Areas.IoTCenter.Controllers;
using System.Linq;
namespace Platform.Areas.UserCenter.Controllers
{
[Authorize]
[ApiController]
[Route("UserCenter/[controller]/[action]")]
[Area("UserCenter")]
[ControllerScope(ControllerScopeType.Organ)]
public class OrganBuildingController : BuildingController
{
public OrganBuildingController(IRepository<Building> repo, AjaxController ajax) : base(repo, ajax)
{
}
public override IQueryable<Building> Query(PagedListModel<EditBuildingModel> model, IQueryable<Building> query)
{
var currentOrganNumber = User.GetUserData();
return base.Query(model, query)
.Where(o => o.Organ.Number == currentOrganNumber);
}
}
}

@ -38,8 +38,12 @@ namespace Platform.Areas.UserCenter.Controllers
{
return base.Query(model, query)
.Where(o => o.ParentId != null)
.WhereIf(model.Query.AreaId.HasValue, o => o.AreaId == model.Query.AreaId.Value)
.WhereIf(model.Query.ParentId.HasValue, o => o.ParentId == model.Query.ParentId.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(!string.IsNullOrEmpty(model.Query.Number), o => o.Number.Contains(model.Query.Number));
.WhereIf(!string.IsNullOrEmpty(model.Query.Number), o => o.Number.Contains(model.Query.Number))
.WhereIf(model.Query.Type.HasValue, o => o.Type == model.Query.Type.Value)
.WhereIf(!string.IsNullOrEmpty(model.Query.CustomType), o => o.CustomType.Contains(model.Query.CustomType));
}
public override void ToDisplayModel(Organ entity, EditOrganModel model)

@ -5,10 +5,8 @@ using Infrastructure.Web.Mvc;
using IoT.Shared.Application.Domain.Entities;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Platform.Application.Models;
using Platform.Areas.IoTCenter.Controllers;
using System;
using System.Linq;
namespace Platform.Areas.UserCenter.Controllers
@ -18,136 +16,18 @@ namespace Platform.Areas.UserCenter.Controllers
[Route("UserCenter/[controller]/[action]")]
[Area("UserCenter")]
[ControllerScope(ControllerScopeType.Organ)]
public class OrganOrganController : CrudController<Organ, EditOrganModel>
public class OrganOrganController : OrganController
{
private readonly AjaxController _ajax;
public OrganOrganController(IRepository<Organ> repo, AjaxController ajax) : base(repo)
{
this._ajax = ajax;
}
public override IQueryable<Organ> Include(IQueryable<Organ> query)
public OrganOrganController(IRepository<Organ> repo, AjaxController ajax) : base(repo, ajax)
{
return query
.Include(o => o.Area)
.Include(o => o.Parent);
}
public override IQueryable<Organ> Query(PagedListModel<EditOrganModel> model, IQueryable<Organ> query)
{
var currentOrganNumber = User.GetUserData();
return base.Query(model, query)
.Where(o => o.ParentId != null)
.Where(o => o.Number == currentOrganNumber)
.WhereIf(!string.IsNullOrEmpty(model.Query.Name), o => o.Name.Contains(model.Query.Name))
.WhereIf(!string.IsNullOrEmpty(model.Query.Number), o => o.Number.Contains(model.Query.Number));
.Where(o => o.Number == currentOrganNumber);
}
public override void ToDisplayModel(Organ entity, EditOrganModel model)
{
if (entity.AreaId.HasValue)
{
ViewData.Add(entity.AreaId.Value, entity.Area.Name);
}
if (entity.ParentId.HasValue)
{
ViewData.Add(entity.ParentId.Value, entity.Parent.Name);
}
}
public override void ToEditModel(Organ entity, EditOrganModel model)
{
this.ViewData.SelectList(o => model.AreaId, () => this._ajax.GetAreaSelectList(model.AreaId));
this.ViewData.SelectList(o => model.ParentId, () => this._ajax.GetOrganSelectList(model.ParentId, model.Id));
}
public override void ToEntity(EditOrganModel model, Organ entity)
{
if (!model.ParentId.HasValue)
{
var root = this.Repo.ReadOnlyTable().FirstOrDefault(o => o.ParentId == null);
if (root == null)
{
throw new Exception("根节点没有初始化");
}
entity.ParentId = root.Id;
}
}
public override IActionResult Add(EditOrganModel model)
{
if (ModelState.IsValid)
{
try
{
var entity = new Organ();
entity.From(model);
this.ToEntity(model, entity);
this.Repo.Add(entity);
this.Repo.SaveChanges();
Update();
return this.Success();
}
catch (DbUpdateException ex)
{
ex.PrintStack();
ModelState.AddModelError("", $"{ex.Message}{ex.InnerException?.Message}");
}
}
this.ToEditModel(null, model);
return Result(model);
}
public override IActionResult Edit(EditOrganModel model)
{
var id = model.Id;
var query = this.Repo.Table();
query = this.Include(query);
var entity = query.FirstOrDefault(o => o.Id == id);
if (ModelState.IsValid)
{
try
{
if (model.ParentId != null)
{
if (model.ParentId == model.Id)
{
throw new Exception("上级节点不能是当前节点");
}
var parent = this.Repo.Table().ToList().FirstOrDefault(o => o.Id == model.ParentId);
while (parent.ParentId.HasValue)
{
if (parent.ParentId == model.Id)
{
throw new Exception("上级节点不能是当前节点的下级节点");
}
else
{
parent = parent.Parent;
}
}
}
entity.From(model, skipReadonly: true);
this.ToEntity(model, entity);
this.Repo.SaveChanges();
return this.Success();
}
catch (Exception ex)
{
ex.PrintStack();
ModelState.AddModelError("", ex.Message);
}
}
this.ToEditModel(entity, model);
return Result(model);
}
private void Update()
{
var root = this.Repo.Table().ToList().FirstOrDefault(o => o.ParentId == null);
root.Update();
this.Repo.SaveChanges();
}
}
}

@ -35,6 +35,10 @@
{
<li class="nav-item"><a class="@GetLinkClass("OrganOrgan")" href="@Url.Action("Index","OrganOrgan")"><i class="far fa-circle nav-icon"></i><p>机构管理</p></a></li>
}
@if (HasPermission("Read-Organ-Building"))
{
<li class="nav-item"><a class="@GetLinkClass("OrganBuilding")" href="@Url.Action("Index","OrganBuilding")"><i class="far fa-circle nav-icon"></i><span>建筑管理</span></a></li>
}
@if (User.Claims.Any(o => o.Value.Contains("-User-")))
{
<li class="nav-header">用户</li>

@ -0,0 +1,8 @@
<script>
$(function () {
$('#OrganId').change(function () {
var id = $(this).find(':selected').val();
update('@Url.Action("GetOrganBuilding", "Ajax",new{area="IoTCenter"})', id, "#ParentId");
});;
});
</script>

@ -63,27 +63,40 @@
<aside class="main-sidebar sidebar-dark-primary elevation-4">
<div class="brand-link" href="@Url.Action("Index","Home",new { area=""})">
<span class="brand-text font-weight-light">
@if (User.Identity.IsAuthenticated)
{
var userName = User.Identity.Name;
@{
var hasOrgan = false;
var organs = new List<Organ>();
var organNumber = User.Claims.FirstOrDefault(o => o.Type == System.Security.Claims.ClaimTypes.UserData)?.Value;
var organs = organUserRepo.ReadOnlyTable().Where(o => o.User.UserName == userName).Select(o => new { o.Organ.Number, o.Organ.Name, o.Organ.Image });
var organImage = organs.FirstOrDefault(o => o.Number == organNumber)?.Image ?? logo;
var list = new SelectList(organs, "Number", "Name", organNumber);
<img class="logo" src="@Url.Content2(organImage)" />
<span class="brand-text font-weight-light">
<form method="get" action="@Url.Action("ChangeOrgan","Account",new{area=""})">
<input type="hidden" name="ReturnUrl" value="@ViewContext.HttpContext.Request.GetDisplayUrl()" />
@Html.DropDownList("UserCurrentOrganNumber", list,new { @class = "organ submit",style="background-color:#343a40;border-color: #343a40;" })
</form>
</span>
}
else
{
<img class="logo" src="@Url.Content2(logo)" />
<span class="brand-text font-weight-light">@name</span>
if (!string.IsNullOrEmpty(organNumber) && User.Identity.IsAuthenticated)
{
var userName = User.Identity.Name;
organs = organUserRepo.ReadOnlyTable()
.Where(o => o.User.UserName == userName)
.Select(o => o.Organ)
.ToList();
if (organs != null && organs.Any(o => o.Number == organNumber))
{
hasOrgan = true;
}
}
if (hasOrgan)
{
var organImage = organs.FirstOrDefault(o => o.Number == organNumber)?.Image ?? logo;
var list = new SelectList(organs, "Number", "Name", organNumber);
<img class="logo" src="@Url.Content2(organImage)" />
<span class="brand-text font-weight-light">
<form method="get" action="@Url.Action("ChangeOrgan","Account",new{area=""})">
<input type="hidden" name="ReturnUrl" value="@ViewContext.HttpContext.Request.GetDisplayUrl()" />
@Html.DropDownList("UserCurrentOrganNumber", list,new { @class = "organ submit",style="background-color:#343a40;border-color: #343a40;" })
</form>
</span>
}
else
{
<img class="logo" src="@Url.Content2(logo)" />
<span class="brand-text font-weight-light">@name</span>
}
}
</div>
<div class="sidebar">
<nav class="mt-2">

@ -5,13 +5,19 @@
<li class="nav-item d-none d-sm-inline-block">
<a href="@Url.Action("Index","Home",new { area=""})" class="@GetLinkClass(area:"")">首页</a>
</li>
@if (HasPermission("Read-Platform-Setting"))
{
<li class="nav-item d-none d-sm-inline-block">
<a href="@Url.Action("Index","Setting",new { area="Settings"})" class="@GetLinkClass(area:"Settings")">配置</a>
</li>
<li class="nav-item d-none d-sm-inline-block">
<a href="@Url.Action("Index","Area",new { area="UserCenter"})" class="@GetLinkClass(area:"UserCenter")">组织机构</a>
<a href="@Url.Action("Index","Setting",new { area="Settings"})" class="@GetLinkClass(area:"Settings")">平台配置</a>
</li>
}
@if (HasPermission("Read-Platform-Area"))
{
<li class="nav-item d-none d-sm-inline-block">
<a href="@Url.Action("Index","Area",new { area="UserCenter"})" class="@GetLinkClass(area:"UserCenter")">用户中心</a>
</li>
}
<li class="nav-item d-none d-sm-inline-block">
<a href="@Url.Action("Index","Home",new { area="IoTCenter"})" class="@GetLinkClass(area:"IoTCenter")">设备管控</a>
<a href="@Url.Action("Index","Home",new { area="IoTCenter"})" class="@GetLinkClass(area:"IoTCenter")">物联管控</a>
</li>
</ul>

@ -257,6 +257,17 @@ CREATE TABLE `iot_Role` (
CONSTRAINT `FK_iot_Role_iot_Organ_OrganId` FOREIGN KEY (`OrganId`) REFERENCES `iot_Organ` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_Title` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
`Name` longtext CHARACTER SET utf8mb4 NULL,
`MinLevel` int NOT NULL,
`MaxLevel` int NOT NULL,
`OrganId` char(36) NOT NULL,
CONSTRAINT `PK_iot_Title` PRIMARY KEY (`Id`),
CONSTRAINT `FK_iot_Title_iot_Organ_OrganId` FOREIGN KEY (`OrganId`) REFERENCES `iot_Organ` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_IoTSceneTimer` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
@ -313,19 +324,6 @@ CREATE TABLE `iot_BuildingIoTGateway` (
CONSTRAINT `FK_iot_BuildingIoTGateway_iot_IoTGateway_IoTGatewayId` FOREIGN KEY (`IoTGatewayId`) REFERENCES `iot_IoTGateway` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_DepartmentUser` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
`Type` int NOT NULL,
`CustomType` longtext CHARACTER SET utf8mb4 NULL,
`UserId` char(36) NOT NULL,
`DeparementId` char(36) NOT NULL,
`DepartmentId` char(36) NULL,
CONSTRAINT `PK_iot_DepartmentUser` PRIMARY KEY (`Id`),
CONSTRAINT `FK_iot_DepartmentUser_iot_Department_DepartmentId` FOREIGN KEY (`DepartmentId`) REFERENCES `iot_Department` (`Id`) ON DELETE RESTRICT,
CONSTRAINT `FK_iot_DepartmentUser_iot_User_UserId` FOREIGN KEY (`UserId`) REFERENCES `iot_User` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_OrganIoTSceneTimer` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
@ -360,6 +358,18 @@ CREATE TABLE `iot_UserRole` (
CONSTRAINT `FK_iot_UserRole_iot_User_UserId` FOREIGN KEY (`UserId`) REFERENCES `iot_User` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_Job` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
`Name` longtext CHARACTER SET utf8mb4 NULL,
`Level` int NOT NULL,
`TitleId` char(36) NOT NULL,
`DepartmentId` char(36) NOT NULL,
CONSTRAINT `PK_iot_Job` PRIMARY KEY (`Id`),
CONSTRAINT `FK_iot_Job_iot_Department_DepartmentId` FOREIGN KEY (`DepartmentId`) REFERENCES `iot_Department` (`Id`) ON DELETE CASCADE,
CONSTRAINT `FK_iot_Job_iot_Title_TitleId` FOREIGN KEY (`TitleId`) REFERENCES `iot_Title` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_IoTParameter` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
@ -416,6 +426,22 @@ CREATE TABLE `iot_RolePermission` (
CONSTRAINT `FK_iot_RolePermission_iot_Role_RoleId` FOREIGN KEY (`RoleId`) REFERENCES `iot_Role` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_DepartmentUser` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
`Position` longtext CHARACTER SET utf8mb4 NULL,
`Type` int NOT NULL,
`CustomType` longtext CHARACTER SET utf8mb4 NULL,
`UserId` char(36) NOT NULL,
`DeparementId` char(36) NOT NULL,
`JobId` char(36) NULL,
`DepartmentId` char(36) NULL,
CONSTRAINT `PK_iot_DepartmentUser` PRIMARY KEY (`Id`),
CONSTRAINT `FK_iot_DepartmentUser_iot_Department_DepartmentId` FOREIGN KEY (`DepartmentId`) REFERENCES `iot_Department` (`Id`) ON DELETE RESTRICT,
CONSTRAINT `FK_iot_DepartmentUser_iot_Job_JobId` FOREIGN KEY (`JobId`) REFERENCES `iot_Job` (`Id`) ON DELETE RESTRICT,
CONSTRAINT `FK_iot_DepartmentUser_iot_User_UserId` FOREIGN KEY (`UserId`) REFERENCES `iot_User` (`Id`) ON DELETE CASCADE
);
CREATE TABLE `iot_IoTSceneIoTCommand` (
`Id` char(36) NOT NULL,
`IsDeleted` longtext CHARACTER SET utf8mb4 NULL,
@ -484,6 +510,8 @@ CREATE UNIQUE INDEX `IX_iot_Department_OrganId_Number` ON `iot_Department` (`Org
CREATE INDEX `IX_iot_DepartmentUser_DepartmentId` ON `iot_DepartmentUser` (`DepartmentId`);
CREATE INDEX `IX_iot_DepartmentUser_JobId` ON `iot_DepartmentUser` (`JobId`);
CREATE INDEX `IX_iot_DepartmentUser_UserId` ON `iot_DepartmentUser` (`UserId`);
CREATE UNIQUE INDEX `IX_iot_IoTApi_ProductId_Name` ON `iot_IoTApi` (`ProductId`, `Name`);
@ -530,6 +558,10 @@ CREATE INDEX `IX_iot_IoTSceneTigger_SceneId` ON `iot_IoTSceneTigger` (`SceneId`)
CREATE INDEX `IX_iot_IoTSceneTimer_SceneId` ON `iot_IoTSceneTimer` (`SceneId`);
CREATE INDEX `IX_iot_Job_DepartmentId` ON `iot_Job` (`DepartmentId`);
CREATE INDEX `IX_iot_Job_TitleId` ON `iot_Job` (`TitleId`);
CREATE INDEX `IX_iot_Organ_AreaId` ON `iot_Organ` (`AreaId`);
CREATE UNIQUE INDEX `IX_iot_Organ_Name` ON `iot_Organ` (`Name`);
@ -576,6 +608,8 @@ CREATE UNIQUE INDEX `IX_iot_RolePermission_RoleId_PermissionId` ON `iot_RolePerm
CREATE UNIQUE INDEX `IX_iot_Site_Name` ON `iot_Site` (`Name`);
CREATE INDEX `IX_iot_Title_OrganId` ON `iot_Title` (`OrganId`);
CREATE UNIQUE INDEX `IX_iot_User_Email` ON `iot_User` (`Email`);
CREATE UNIQUE INDEX `IX_iot_User_PhoneNumber` ON `iot_User` (`PhoneNumber`);

Loading…
Cancel
Save