初始化项目

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

View File

@@ -0,0 +1,101 @@
using Models;
using Models.ModelItems;
using Services.Cache;
using Services.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Services.Manager
{
public class OrgAuthoServer
{
#region
public static bool EditAuthoType(int OrgId, int type, int authorityid,int hotels,string CreatedBy)
{
try
{
Organization org = CacheHelp.cacheSysOrganization.FirstOrDefault(x => x.Id == OrgId && x.IsValid ==0);
//OrgAuthority autho = db.OrgAuthorities.FirstOrDefault(x => x.OrgId == OrgId && x.AuthorityId == authorityid && x.HotelId == hotels);
OrgAuthority autho= SqlSugarBase.Db.Queryable<OrgAuthority>().First(x => x.OrgId == OrgId && x.AuthorityId == authorityid && x.HotelId == hotels);
Hotels hotels1 = CacheHelp.cacheHotels.FirstOrDefault(x=>x.Id == hotels);
Authority authority = CacheHelp.cacheSysAutho.FirstOrDefault(x => x.Id == authorityid);
AuthoStatusType statusType = CacheHelp.cacheSysAuthoStatusType.FirstOrDefault(x=>x.Id == type);
if (autho == null)
{
OrgAuthority authos = new OrgAuthority() { AuthorityId = authorityid,OrgId = OrgId,AuthotypeId = type,HotelId = hotels};
DbLogServer.WriteDbLog($"新增了用户组{org.OrganizationName }对{hotels1.Name}({hotels})酒店的{authority.AuthorityName}({authority.Id})权限'{authority.AuthorityName }({authority.Id})':无 => {statusType.Name}");
SqlSugarBase.Db.Insertable(authos).ExecuteCommand();
}
else
{
AuthoStatusType statusTypeold = CacheHelp.cacheSysAuthoStatusType.FirstOrDefault(x => x.Id == autho.AuthotypeId);
DbLogServer.WriteDbLog($"更改了用户组{org.OrganizationName }({org.Id})对{hotels1.Name}({hotels})酒店的{authority.AuthorityName}({authority.Id})权限'{authority.AuthorityName }({authority.Id})':{statusTypeold} => {statusType.Name}", 1);
autho.AuthotypeId = type;
autho.CreatedBy = CreatedBy;
SqlSugarBase.Db.Updateable(autho).ExecuteCommand();
}
return true;
}
catch (Exception ex)
{
throw ex;
}
finally
{
CacheHelp.Removesys(CacheHelp.syskey.sysUserAuthoListKey);
CacheHelp.Removesys(CacheHelp.syskey.sysView_UAListKey);
CacheHelp.Removesys(CacheHelp.syskey.sysUserInfoListKey);
CacheHelp.Removesys(CacheHelp.syskey.sysOrgAuthorityListKey);
}
}
#endregion
#region
public static bool DelOrg(int OrgId,string CreatedBy = null)
{
Organization org = SqlSugarBase.Db.Queryable<Organization>().First(x => x.Id == OrgId);
//Organization org = db.Organizations.FirstOrDefault(x =>x.Id == OrgId);
//List<OrgUser> OrgUser = CacheHelp.cacheSysOrgUser.Where(x => ).ToList();
if (org == null)
return false;
org.IsValid = 1;
SqlSugarBase.Db.Deleteable<OrgUsers>().Where(x => x.OrgId == org.Id);
//db.OrgUsers.RemoveRange(db.OrgUsers.Where(x => x.OrgId == org.Id));
//将没有用户组的用户添加到默认用户组
//db.Database.ExecuteSqlCommand($"insert into OrgUsers select 1,Id,'{DateTime.Now.ToString("G")}','{CreatedBy}' from UserInfo where id not in (select UserId from OrgUsers)");
SqlSugarBase.Db.Ado.ExecuteCommand($"insert into OrgUsers select 1,Id,'{DateTime.Now.ToString("G")}','{CreatedBy}' from UserInfo where id not in (select UserId from OrgUsers)");
//db.SaveChanges();
DbLogServer.WriteDbLog( $"删除了用户组{org.OrganizationName }({org.Id})",2);
CacheHelp.Removesys(null);
return true;
}
#endregion
#region
public static bool CheckName(string name)
{
if (CacheHelp.cacheSysOrganization.FirstOrDefault(u => u.OrganizationName == name) == null)
return true;
else
return false;
}
#endregion
#region
public static int? AddOrg(string name,string Desc = "", string CreatedBy = null)
{
if (CacheHelp.cacheSysOrganization.FirstOrDefault(u => u.OrganizationName == name) != null)
return null;
//AuthorityDB db = new AuthorityDB();
Organization organization = new Organization() { OrganizationName = name , Desc = Desc,CreatedBy = CreatedBy };
int id= SqlSugarBase.Db.Insertable(organization).ExecuteReturnIdentity();
//db.Organizations.Add(organization);
//db.SaveChanges();
CacheHelp.Removesys(CacheHelp.syskey.sysOrganizationListKey);
DbLogServer.WriteDbLog($"添加了用户组{organization.OrganizationName }({id})");
return id;
}
#endregion
}
}