初始化项目

This commit is contained in:
2025-11-20 09:50:21 +08:00
commit 94b24e1a5d
4209 changed files with 1570805 additions and 0 deletions

196
Models/View/ViewInit.cs Normal file
View File

@@ -0,0 +1,196 @@
using Models.ModelItems;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models.View
{
public class ViewInit
{
#region userinfo
static readonly string userinfo = @"
create view View_UserInfo
as
select a.*,d.OrganizationName,c.OrgId,Authoncount = (select count(*) from UserAuthoes where UserAuthoes.UserId = a.Id) from UserInfo a
left join
OrgUsers c
on c.UserId = a.Id
left join
Organization d
on
c.OrgId = d.Id --WHERE a.Id IS NOT NULL and d.Id is not null";
#endregion
#region - view_uoa
static readonly string view_uoa = @"
create view View_UOA
as
select distinct u.Id,u.Uid ,HotelId,
OrgId = o.id,
o.OrganizationName,
Orgdesc = o.[Desc] ,
AppId = app.id,
app.AppName,
AppDesc = app.[Desc],
AuthorityId =a.Id,
a.AuthorityName,
AuthDesc = a.[Desc] ,
oa.AuthotypeId,
AstName = ast.Name,
AstDesc = ast.[Desc],
Sfjc = (select count(*) from UserAuthoes where UserId = u.Id and AuthorityId = a.Id and AuthotypeId = oa.AuthotypeId and HotelId = oa.HotelId)
from UserInfo u
left join OrgUsers ou
on u.id = ou.UserId
left join Organization o
on ou.OrgId = o.Id
left join OrgAuthority oa
on o.Id = oa.OrgId
left join Authority a
on a.Id = oa.AuthorityId
left join AppAutho aa
on a.Id = aa.AuthorityId
left join ApplicationDomain app
on aa.AppId = app.Id
left join AuthoStatusType ast
on oa.AuthotypeId = ast.Id
where ou.OrgId is not null
and oa.AuthorityId is not null
";
#endregion
# region view_ua
static readonly string view_ua = @"
create view View_UA
as
select Id = ui.id ,HotelId,
Uid ,
AppId = app.id,
app.AppName,
a.AuthorityName,
AppDesc = app.[Desc],
AuthorityId = a.Id,
AuthDesc = a.[Desc] ,
ua.AuthotypeId,
AstName = ast.Name,
AstDesc = ast.[Desc]
from UserInfo ui
left join
UserAuthoes ua
on ui.id = ua.UserId
left join AppAutho aa
on ua.AuthorityId = aa.AuthorityId
left join ApplicationDomain app
on aa.AppId = app.Id
left join Authority a
on a.Id = ua.AuthorityId
left join AuthoStatusType ast
on ua.AuthotypeId = ast.Id
where ua.UserId is not null";
#endregion
#region view_AppAutho
static readonly string view_AppAutho = @"
create view View_AppAutho
as
select AppId = APP.Id,
AppName = app.AppName,
AppDesc = app.[Desc],
AuthorityId,
AuthorityName,
IsValid,
AuthorityDesc = auth.[Desc]
from ApplicationDomain app left join AppAutho aa on app.Id = aa.AppId left join Authority auth on aa.AuthorityId = auth.id where aa.AuthorityId is not null
";
#endregion
#region
static readonly string org = @"if exists(select * from sys.triggers where name='trigger_OrgAuthority_update')
--删除DML触发器
begin
drop trigger trigger_OrgAuthority_update;
end
go
--用户组更改权限
create trigger trigger_OrgAuthority_update
on OrgAuthority
for update
as
declare @AuthotypeIdnew int; --从临时表Inserted记录新的ID
declare @AuthotypeIdold int; --从临时表Delete记录更新以前旧的ID
declare @AuthoId int; --从临时表Inserted记录权限ID
declare @OrgId int; --从临时表Inserted记录用户组ID
select @AuthotypeIdold = AuthotypeId
from deleted;
select @AuthotypeIdnew = AuthotypeId,@AuthoId = AuthorityId,@OrgId = OrgId
from inserted;
if update(AuthotypeId)
begin
update UserAuthoes set AuthotypeId = @AuthotypeIdnew where AuthorityId = @AuthoId and AuthotypeId = @AuthotypeIdold and UserId in (select UserId from OrgUsers where OrgId = @OrgId)
print @@ROWCOUNT
end;
go
if exists(select * from sys.triggers where name='trigger_OrgAuthority_del')
begin
drop trigger trigger_OrgAuthority_del;
end
go
--用户组权限删除触发器
create trigger trigger_OrgAuthority_del
on OrgAuthority
for delete
as
declare @AuthotypeIdold int; --从临时表Delete记录更新以前旧的ID
declare @AuthoId int; --从临时表Inserted记录权限ID
declare @OrgId int; --从临时表Inserted记录用户组ID
select @AuthotypeIdold = AuthotypeId, @AuthoId = AuthorityId,@OrgId = OrgId
from deleted;
delete UserAuthoes where AuthorityId = @AuthoId and AuthotypeId = @AuthotypeIdold and UserId in (select UserId from OrgUsers where OrgId = @OrgId)
print @@ROWCOUNT
go
--用户组新增权限
if exists(select * from sys.triggers where name='trigger_OrgAuthority_Insert')
begin
drop trigger trigger_OrgAuthority_Insert;
end
go
create trigger trigger_OrgAuthority_Insert
on OrgAuthority
for insert
as
declare @AuthotypeIdnew int; --从临时表Inserted记录新的ID
declare @AuthoId int; --从临时表Inserted记录权限ID
declare @OrgId int; --从临时表Inserted记录用户组ID
select @AuthotypeIdnew = AuthotypeId,@AuthoId = AuthorityId,@OrgId = OrgId
from inserted;
insert into UserAuthoes(AuthorityId,AuthotypeId,UserId) select @AuthoId,@AuthotypeIdnew,UserId from OrgUsers where OrgId = @OrgId
print @@ROWCOUNT
go
";
#endregion
public static void Init(AuthorityDB dB)
{
try
{
if (dB.OrgUsers.Count() > 0)
return;
var context = dB;
string drop = @"Drop Table View_UserInfo;
Drop Table View_UOA;
Drop Table View_AppAutho;
Drop Table View_UA;";
dB.Database.ExecuteSqlCommand(drop);
dB.Database.ExecuteSqlCommand(userinfo);
dB.Database.ExecuteSqlCommand(view_ua);
dB.Database.ExecuteSqlCommand(view_uoa);
dB.Database.ExecuteSqlCommand(view_AppAutho);
//dB.Database.ExecuteSqlCommand(org);
}
catch (Exception ex)
{
File.AppendAllText(AppContext.BaseDirectory+"\\view.txt", ex.ToString());
}
}
}
}

View File

@@ -0,0 +1,18 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Models.View
{
[Table("View_AppAutho")]
public class View_AppAutho
{
[Key]
public int AppId { get; set; }
public string AppName { get; set; }
public string AppDesc { get; set; }
public int AuthorityId { get; set; }
public string AuthorityName { get; set; }
public string AuthorityDesc { get; set; }
public int IsValid { get; set; } = 0;
}
}

View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models.View
{
public class View_MAClog
{
public int Id { get; set; }
/// <summary>
/// 酒店ID
/// </summary>
public int HotelID { get; set; }
/// <summary>
/// 房间号
/// </summary>
public string roomNumber { get; set; }
public string roomID { get; set; }
/// <summary>
/// 状态
/// </summary>
public int Status { get; set; } = 0;
/// <summary>
/// 操作ID 同一次操作可能多次结果
/// </summary>
public int ActionId { get; set; }
/// <summary>
/// 新的MAC
/// </summary>
public string MAC { get; set; }
//操作者用户ID
public int userid { get; set; }
/// <summary>
/// 用户昵称
/// </summary>
public string uid { get; set; }
/// <summary>
/// 酒店名
/// </summary>
public string Name { get; set; }
/// <summary>
/// 酒店id
/// </summary>
public int Hotelsid { get; set; }
/// <summary>
/// 操作日志 0 新增 1 解绑
/// </summary>
public int type { get; set; }
/// <summary>
/// 地址
/// </summary>
public string location { get; set; }
public string Ip { get; set; }
public DateTime createtime { get; set; } = default;
public int AppType { get; set; } = 0; // 0 表示 rcu主机 1表示人脸机
}
}

22
Models/View/View_UA.cs Normal file
View File

@@ -0,0 +1,22 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Models.View
{
[Table("View_UA")]
public class View_UA
{
public int Id { get; set; }
public string Uid { get; set; }
public int AppId { get; set; }
public string AppName { get; set; }
public string AppDesc { get; set; }
public int AuthorityId { get; set; }
public string AuthorityName { get; set; } = "";
public string AuthDesc { get; set; }
public int AuthotypeId { get; set; }
public string AstName { get; set; }
public string AstDesc { get; set; }
public int HotelId { get; set; }
public int IsValid { get; set; }
}
}

26
Models/View/View_UOA.cs Normal file
View File

@@ -0,0 +1,26 @@
using System.ComponentModel.DataAnnotations.Schema;
namespace Models.View
{
[Table("View_UOA")]
public class View_UOA
{
public int Id { get; set; }
public string Uid { get; set; }
public int OrgId { get; set; }
public string OrganizationName { get; set; } = "";
public string Orgdesc { get; set; }
public int AppId { get; set; }
public string AppName { get; set; }
public string AppDesc { get; set; }
public int AuthorityId { get; set; }
public string AuthorityName { get; set; }
public string AuthDesc { get; set; }
public int AuthotypeId { get; set; }
public string AstName { get; set; }
public string AstDesc { get; set; }
public int Sfjc { get; set; }
public int HotelId { get; set; }
}
}

View File

@@ -0,0 +1,71 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Models.View
{
[Table("View_UserInfo")]
public class View_UserInfo
{
public int Id { get; set; }
/// <summary>
/// 用户标识(账号)
/// </summary>
public string Uid { get; set; }
public string Hotel_Data { get; set; }
/// <summary>
/// 密码
/// </summary>
public string Pwd { get; set; }
/// <summary>
/// 性别 0-3 0 男 1 女 2 未知 3 预留待定 默认0
/// </summary>
public int Sex { get; set; } = 0;
/// <summary>
/// 年龄 默认18
/// </summary>
public int? Age { get; set; } = 18;
/// <summary>
/// 创建人
/// </summary>
public string CreatedBy { get; set; } = "";
/// <summary>
/// 是否可用 0 可用 其他不可
/// </summary>
public int IsValid { get; set; } = 0;
/// <summary>
/// 用户用户组
/// </summary>
public string OrganizationName { get; set; }
/// <summary>
/// 权限数量
/// </summary>
public int Authoncount { get; set; }
public DateTime? EndTime { get; set; } = DateTime.Now.AddMonths(2);
/// <summary>
/// 说明
/// </summary>
public string Desc { get; set; }
public string HeadImg { get; set; } = "default.png";
public DateTime CreateTime { get; set; }
public int? OrgId { get; set; }
public int? HotelID { get; set; } = 0;
public int? HotelGroupID { get; set; } = 0;
public int IsImport { get; set; } = 0;
/// <summary>
/// 公司 0 宝来威 1 住好 2 卓豪
/// </summary>
public int? Company { get; set; }
public int Autho { get; set; } = 0;
}
}