初始化项目
This commit is contained in:
252
Services/Manager/AppServer.cs
Normal file
252
Services/Manager/AppServer.cs
Normal file
@@ -0,0 +1,252 @@
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using Services.Cache;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
public class AppServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 查询 app 不查询禁用的权限
|
||||
/// </summary>
|
||||
/// <param name="id"></param>
|
||||
/// <param name="IsValid"></param>
|
||||
/// <returns></returns>
|
||||
#region 单个App权限信息
|
||||
private static dynamic GetAppInfo(int id,int IsValid = 10,bool reauthorities = true)
|
||||
{
|
||||
ApplicationDomain app = Cache.CacheHelp.cacheSysApp.FirstOrDefault(x=>x.Id == id);
|
||||
if(app == null)
|
||||
return null;
|
||||
List<AppAutho> autho = Cache.CacheHelp.cacheSysAppAutho.Where(x => x.AppId == id).ToList();
|
||||
List<Authority> authorities = new List<Authority>();
|
||||
if(reauthorities)
|
||||
authorities = Cache.CacheHelp.cacheSysAutho.Where(x=> autho.FirstOrDefault(y=>y.AuthorityId == x.Id)!=null && x.IsValid != IsValid).ToList();
|
||||
return new
|
||||
{
|
||||
data = authorities,
|
||||
AppName = app.AppName,
|
||||
AppId = app.Id,
|
||||
Desc = app.Desc,
|
||||
app.WebSite,
|
||||
app.AppType,
|
||||
app.Version,
|
||||
app.ReleaseDate,
|
||||
app.Icon,
|
||||
app.DowSum
|
||||
};
|
||||
}
|
||||
#endregion
|
||||
#region 所有App权限信息
|
||||
/// <summary>
|
||||
/// 所有正常App权限信息 查询所有就默认值即可 查询正常的权限 输入1 查询关闭的权限 输入 0
|
||||
/// </summary>
|
||||
/// <param name="IsValid"></param>
|
||||
/// <param name="reauthorities">是否返回权限信息</param>
|
||||
/// <returns></returns>
|
||||
public static List<dynamic> GetAppInfo( int appid = 0, int appIsValid = 0 ,int IsValid = 0,bool reauthorities = true)
|
||||
{
|
||||
List<dynamic> res = new List<dynamic>();
|
||||
foreach (var app in CacheHelp.cacheSysApp.Where(x =>( x.IsValid == appIsValid || appIsValid == -1) && (appid == x.Id || appid == 0)).ToList())
|
||||
{
|
||||
res.Add(GetAppInfo(app.Id, IsValid,reauthorities));
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endregion
|
||||
#region 查询App名是否存
|
||||
public static bool CheckName(string name)
|
||||
{
|
||||
return Cache.CacheHelp.cacheSysApp.FirstOrDefault(x=>x.AppName == name && x.IsValid == 0) == null;
|
||||
}
|
||||
#endregion
|
||||
#region 添加App
|
||||
public static int? AddApp(string name, string Desc = "", string uid = "", string Version = "1.0", string appicon = null, DateTime ReleaseDate = default, string WebSite = "",int AppType =0)
|
||||
{
|
||||
if (CacheHelp.cacheSysApp.FirstOrDefault(u => u.AppName == name && u.IsValid == 0) != null)
|
||||
return null;
|
||||
ApplicationDomain app = new ApplicationDomain {
|
||||
AppName = name,
|
||||
Desc = Desc,
|
||||
CreatedBy = uid,
|
||||
ReleaseDate = ReleaseDate,
|
||||
WebSite = WebSite,
|
||||
Version = Version,
|
||||
AppType = AppType,
|
||||
CreateTime = DateTime.Now,
|
||||
Icon = appicon
|
||||
};
|
||||
int id= SqlSugarBase.Db.Insertable(app).ExecuteReturnIdentity();
|
||||
DbLogServer.WriteDbLog($"添加了应用{app.AppName}({id})");
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAppsListKey);
|
||||
return id;
|
||||
}
|
||||
#endregion
|
||||
#region 删除应用
|
||||
public static bool DelApp(int appid,int IsValid, string uid = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
|
||||
|
||||
ApplicationDomain app = SqlSugarBase.Db.Queryable<ApplicationDomain>().First(x => x.Id == appid);
|
||||
if (app == null)
|
||||
return false;
|
||||
app.IsValid = IsValid;
|
||||
app.CreatedBy = uid;
|
||||
SqlSugarBase.Db.Updateable(app).ExecuteCommand();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
if (IsValid!=0)
|
||||
DbLogServer.WriteDbLog($"删除了应用{app.AppName}({app.Id})",2);
|
||||
else
|
||||
DbLogServer.WriteDbLog($"恢复了应用{app.AppName}({app.Id})", 1);
|
||||
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAppsListKey);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CacheHelp.Removesys(CacheHelp.syskey.Appversions);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 检测权限名
|
||||
public static bool Checkautho(int AppId, string AuthoNmae)
|
||||
{
|
||||
var au = CacheHelp.cacheView_AppAutho.FirstOrDefault(x => x.AppId == AppId && x.AuthorityName == AuthoNmae);
|
||||
if (au == null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
#region 添加权限
|
||||
public static int? Addautho(int AppId, string AuthoNmae, string Desc = "", string uid = null, string authoStatusTypeId = null)
|
||||
{
|
||||
try {
|
||||
dynamic au = CacheHelp.cacheView_AppAutho.FirstOrDefault(x => x.AppId == AppId && x.AuthorityName == AuthoNmae);
|
||||
if (au != null)
|
||||
return null;
|
||||
au = CacheHelp.cacheSysApp.FirstOrDefault(x => x.Id == AppId);
|
||||
if (au == null)
|
||||
return null;
|
||||
|
||||
Authority authority = new Authority { AuthorityName = AuthoNmae, Desc = Desc,CreatedBy = uid, AuthoStatusTypeId = authoStatusTypeId };
|
||||
int id= SqlSugarBase.Db.Insertable(new Authority { AuthorityName = AuthoNmae, Desc = Desc, CreatedBy = uid, AuthoStatusTypeId = authoStatusTypeId }).ExecuteReturnIdentity();
|
||||
SqlSugarBase.Db.Insertable(new AppAutho() { AppId = AppId, AuthorityId = id, CreatedBy = uid }).ExecuteCommand();
|
||||
DbLogServer.WriteDbLog($"给应用{au.AppName}({au.Id})添加了权限'{AuthoNmae}({id})'",0);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_AppAuthoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAuthorityListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAppAuthoListKey);
|
||||
return id;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CacheHelp.Removesys(CacheHelp.syskey.Appversions);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 删除权限
|
||||
public static bool Delautho(int authoId, int status = 0, string uid = null)
|
||||
{
|
||||
var au = CacheHelp.cacheSysAutho.FirstOrDefault(x=>x.Id == authoId);
|
||||
var app = CacheHelp.cacheView_AppAutho.FirstOrDefault(x=>x.AuthorityId == authoId);
|
||||
if (au == null || app == null)
|
||||
return false;
|
||||
|
||||
var autho = SqlSugarBase.Db.Queryable<Authority>().First(x => x.Id == authoId);
|
||||
|
||||
autho.IsValid = status;
|
||||
SqlSugarBase.Db.Updateable(autho).ExecuteCommand();
|
||||
|
||||
|
||||
if(status==1)
|
||||
DbLogServer.WriteDbLog($"禁用了应用{app.AppName}({app.AppId})权限{au.AuthorityName}({au.Id}).",2);
|
||||
else
|
||||
DbLogServer.WriteDbLog( $"恢复了应用{app.AppName}({app.AppId})权限{au.AuthorityName}({au.Id}).", 2);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_AppAuthoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAuthorityListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAppAuthoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAppAuthoListKey);
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
#region 编辑权限
|
||||
public static bool Editautho(Authority authority, string uid)
|
||||
{
|
||||
try {
|
||||
if (authority.Id <= 0)
|
||||
return false;
|
||||
var auc = CacheHelp.cacheSysAutho.FirstOrDefault(x => x.Id == authority.Id);
|
||||
var app = CacheHelp.cacheView_AppAutho.FirstOrDefault(x => x.AuthorityId == authority.Id);
|
||||
if (auc == null || app == null)
|
||||
return false;
|
||||
|
||||
var au = SqlSugarBase.Db.Queryable<Authority>().First(x => x.Id == authority.Id);
|
||||
au.Desc = authority.Desc ?? au.Desc;
|
||||
au.AuthoStatusTypeId = authority.AuthoStatusTypeId ?? au.AuthoStatusTypeId;
|
||||
au.AuthorityName = authority.AuthorityName ?? au.AuthorityName;
|
||||
SqlSugarBase.Db.Updateable(au).ExecuteCommand();
|
||||
DbLogServer.WriteDbLog( $"修改了{app.AuthorityName} ({app.AppId})权限{au.AuthorityName}({au.Id}).修改后为:" + JsonConvert.SerializeObject(au), 1);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_AppAuthoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAuthorityListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAppAuthoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysAppAuthoListKey);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
CacheHelp.Removesys(CacheHelp.syskey.Appversions);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
#region 下载量添加
|
||||
public static bool AddDown( int AppId,int sum = 1)
|
||||
{
|
||||
try
|
||||
{
|
||||
var app = SqlSugarBase.Db.Queryable<ApplicationDomain>().First(x => x.Id == AppId);
|
||||
app.DowSum+=sum;
|
||||
|
||||
return SqlSugarBase.Db.Updateable(app).ExecuteCommand()>0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return false;
|
||||
}finally
|
||||
{
|
||||
CacheHelp.Removesys( CacheHelp.syskey.Appversions);
|
||||
CacheHelp.Removesys( CacheHelp.syskey.sysAppsListKey);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
25
Services/Manager/AuthoStatusServer.cs
Normal file
25
Services/Manager/AuthoStatusServer.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
public class AuthoStatusServer
|
||||
{
|
||||
public static AuthoStatusType AddAuthoStatus(string Name,string desc)
|
||||
{
|
||||
|
||||
AuthoStatusType authoStatus = Cache.CacheHelp.cacheSysAuthoStatusType.FirstOrDefault(x => x.Name == Name);
|
||||
if (authoStatus != null)
|
||||
return null;
|
||||
authoStatus = new AuthoStatusType() {Name = Name ,Desc = desc };
|
||||
SqlSugarBase.Db.Insertable(authoStatus).ExecuteCommand();
|
||||
Cache.CacheHelp.Removesys(Cache.CacheHelp.syskey.sysAuthoStatusTypeListKey);
|
||||
return authoStatus;
|
||||
}
|
||||
}
|
||||
}
|
||||
64
Services/Manager/DbLogServer.cs
Normal file
64
Services/Manager/DbLogServer.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
public class DbLogServer
|
||||
{
|
||||
/// <summary>
|
||||
/// 写日志
|
||||
/// </summary>
|
||||
/// <param name="uid">操作者</param>
|
||||
/// <param name="content">内容</param>
|
||||
/// <param name="type">0 新增 1 更新 2 删除</param>
|
||||
public static void WriteDbLog(string content, int type = 0, DbLog logs = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
//从Session拷贝一个模板过来
|
||||
DbLog log = new DbLog();
|
||||
log = logs != null ? logs : HttpContext.Current.Session["log"] as DbLog;
|
||||
if(logs != null)
|
||||
{
|
||||
log = logs;
|
||||
}
|
||||
else
|
||||
{
|
||||
DbLog tmpSessionLog = HttpContext.Current.Session["log"] as DbLog;
|
||||
if(tmpSessionLog != null)
|
||||
{
|
||||
log = tmpSessionLog;
|
||||
}
|
||||
else
|
||||
{
|
||||
log.location = "";
|
||||
log.Ip = "";
|
||||
log.Client = "";
|
||||
log.Uid = "";
|
||||
}
|
||||
}
|
||||
//除了content, type, 其他的全部用模板的值
|
||||
DbLog dlog = new DbLog
|
||||
{
|
||||
location = log.location,
|
||||
Ip = log.Ip,
|
||||
Client = log.Client,
|
||||
CreateTime = DateTime.Now,
|
||||
Uid = log.Uid,
|
||||
Type = type,
|
||||
Content = content
|
||||
};
|
||||
SqlSugarBase.Db.Insertable(dlog).ExecuteCommand();
|
||||
}
|
||||
catch (Exception EX)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(EX);
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
259
Services/Manager/FaceServer.cs
Normal file
259
Services/Manager/FaceServer.cs
Normal file
@@ -0,0 +1,259 @@
|
||||
using Models;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using Models.ModelItems;
|
||||
using Services.Tool;
|
||||
using static Services.Tool.HttpRequestHelp;
|
||||
using SqlSugar;
|
||||
using UI.Lib;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
public class FaceServer
|
||||
{
|
||||
public static List<Hosts> CheckfaceSNHosts(string faceSN)
|
||||
{
|
||||
var RES = CheckfaceSN(faceSN);
|
||||
List<Hosts> RESDATA = new List<Hosts>();
|
||||
List<Hosts> HOS = new List<Hosts>();
|
||||
if (RES == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var item in RES)
|
||||
{
|
||||
int HOTELID = 0;
|
||||
int RoomId = 0;
|
||||
if (!int.TryParse(item.HotelCode, out HOTELID))
|
||||
{
|
||||
HOTELID = 0;
|
||||
};
|
||||
|
||||
RoomId = int.Parse(item.RoomId == null ? 0.ToString() : item.RoomId.ToString());
|
||||
// 已经分配酒店
|
||||
if (HOTELID > 0 )
|
||||
{
|
||||
//未分配房间
|
||||
if (RoomId == 0)
|
||||
{
|
||||
RESDATA.Add(new Hosts { Id = RoomId,HotelID = HOTELID,HotelName = Cache.CacheHelp.cacheHotels.Single(x=> x.Id == HOTELID ).Name,RoomNumber = "暂无绑定房间" });
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
var TEMP = HOS.FirstOrDefault(X => X.Id == RoomId);
|
||||
if (TEMP == null)
|
||||
{
|
||||
HOS.AddRange(HttpRequestHelp.GetHosts(int.Parse(item.HotelCode)));
|
||||
var str = JsonConvert.SerializeObject(HOS.Select(x=>x.Id));
|
||||
TEMP = HOS.FirstOrDefault(X => X.Id == RoomId);
|
||||
}
|
||||
if (TEMP != null)
|
||||
RESDATA.Add(TEMP);
|
||||
else
|
||||
{
|
||||
RESDATA.Add(new Hosts { Id = RoomId, HotelID = HOTELID, HotelName = Cache.CacheHelp.cacheHotels.Single(x => x.Id == HOTELID).Name, RoomNumber = "绑定房间已经被删除" });
|
||||
// 绑定的房间被删除了
|
||||
//throw new Exception("人脸机绑定的房间ID没有在房间列表找到 ~");
|
||||
|
||||
}
|
||||
//return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return RESDATA;
|
||||
}
|
||||
/// <summary>
|
||||
/// 检查人脸机是否已经被绑定的
|
||||
/// </summary>
|
||||
/// <param name="faceSN"></param>
|
||||
/// <returns></returns>
|
||||
public static List<DeviceManage> CheckfaceSN(string faceSN)
|
||||
{
|
||||
return Test_Feac.Db.Queryable<DeviceManage>().Where(X=>X.SerialNo == faceSN).ToList();
|
||||
//($"select * from DeviceManage WHERE SerialNo = '{faceSN}'").ToList();
|
||||
}
|
||||
|
||||
public static DeviceManage SelfaceSN_RoomId(int RoomId)
|
||||
{
|
||||
return Test_Feac.Db.Queryable<DeviceManage>().Where(X => X.RoomId == RoomId).First();
|
||||
}
|
||||
public static List<DeviceManage> SelfaceSN_HotelID(int HotelID)
|
||||
{
|
||||
return Test_Feac.Db.Queryable<DeviceManage>().Where(X => X.HotelCode == HotelID+"").ToList();
|
||||
|
||||
//using (AuthorityDB DB = new AuthorityDB())
|
||||
//{
|
||||
// SqlSugarBase.Db.Queryable<DeviceManage>()
|
||||
// return DB.Database.SqlQuery<DeviceManage>($"select * from Face.DBO.DeviceManage WHERE HotelCode = @HotelID", new SqlParameter("@HotelID", HotelID)).ToList();
|
||||
//}
|
||||
}
|
||||
/// <summary>
|
||||
/// 根据房间号绑定人脸机 往人脸机表添加字段
|
||||
/// RETURN
|
||||
/// 0 成功
|
||||
/// 1 已经注册已经绑定酒店
|
||||
/// 2 已经注册更新失败
|
||||
/// 3 未注册为分配酒店 添加注册 添加酒店是啊比
|
||||
/// 4 未能预计的结果--
|
||||
/// 5 数据不符合
|
||||
/// 6 解绑失败
|
||||
/// </summary>
|
||||
/// <param name="faceSN"></param>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <param name="hotelID"></param>
|
||||
/// <returns></returns>
|
||||
public static int GetfaceSN(UserInfo userinfo = null, string faceSN = "", string roomNumber = "", int hotelID = 0, string faceAddress = "",string roomID = "", bool isjb = false)
|
||||
{
|
||||
|
||||
int RES = 5;
|
||||
|
||||
// 如果传入 酒店房间号 就是绑定 判断是否已经绑定
|
||||
if (!isjb)
|
||||
{
|
||||
|
||||
var olddata = CheckfaceSN(faceSN);
|
||||
//已经注册已经绑定酒店
|
||||
if (olddata != null && olddata.Count > 0 && olddata[0].HotelCode != "0" && olddata[0].RoomId > 0)
|
||||
{
|
||||
//已经绑定 房间
|
||||
RES = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
Test_Feac.Db.Ado.ExecuteCommand($"UPDATE DeviceManage SET bindingStatus = 0, RoomId = '0',faceAddress = @faceAddress, HotelCode = 0 WHERE RoomId = @roomID and HotelCode = @hotelID; ", new SugarParameter("@SerialNo", faceSN), new SugarParameter("@roomID", roomID), new SugarParameter("@hotelID", hotelID), new SugarParameter("@faceAddress", faceAddress));
|
||||
|
||||
|
||||
//AuthorityDB DB = new AuthorityDB();
|
||||
////如果之前有 SN 绑定房间 直接解绑
|
||||
//DB.Database.ExecuteSqlCommand($"UPDATE Face.DBO.DeviceManage SET bindingStatus = 'false', RoomId = '0',faceAddress = @faceAddress, HotelCode = 0 WHERE RoomId = @roomID and HotelCode = @hotelID; ", new SqlParameter("@SerialNo", faceSN), new SqlParameter("@roomID", roomID), new SqlParameter("@hotelID", hotelID), new SqlParameter("@faceAddress", faceAddress));
|
||||
//已经注册
|
||||
if (olddata != null && olddata.Count > 0)
|
||||
{
|
||||
if (Test_Feac.Db.Ado.ExecuteCommand($"UPDATE DeviceManage SET bindingStatus = 1,RoomId = @roomID ,faceAddress = @faceAddress, HotelCode = @hotelID WHERE SerialNo = @SerialNo", new SugarParameter("@SerialNo", faceSN), new SugarParameter("@roomID", roomID), new SugarParameter("@hotelID", hotelID), new SugarParameter("@faceAddress", faceAddress)) > 0)
|
||||
{
|
||||
RES = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
RES = 2;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//未注册为分配酒店 添加注册 添加酒店 [Status], faceAddress, bindingStatus) values('6926895501368', 2, '968', 'false',
|
||||
if (olddata == null || olddata.Count <= 0)
|
||||
{
|
||||
|
||||
if (Test_Feac.Db.Ado.ExecuteCommand($"insert DeviceManage(SerialNo, HotelCode, RoomId,`Status`, faceAddress, bindingStatus) values(@SerialNo, @hotelID, @roomID,0, @faceAddress, 1); ", new SugarParameter("@SerialNo", faceSN), new SugarParameter("@roomID", roomID), new SugarParameter("@hotelID", hotelID), new SugarParameter("@faceAddress", faceAddress)) > 0)
|
||||
{
|
||||
RES = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
RES = 3;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
LogHelp.WriteExceptionLog(new Exception("未能预计的结果--" + JsonConvert.SerializeObject(olddata)));
|
||||
RES = 4;
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
else
|
||||
{
|
||||
//执行解绑
|
||||
if (!string.IsNullOrEmpty(faceSN) && roomID != "0" && hotelID != 0)
|
||||
{
|
||||
//using (AuthorityDB DB = new AuthorityDB())
|
||||
//{
|
||||
if (Test_Feac.Db.Ado.ExecuteCommand($"UPDATE DeviceManage SET RoomId = '0' ,faceAddress = @faceAddress, HotelCode ='0' WHERE SerialNo = @SerialNo and HotelCode = @hotelID and RoomId = @roomID", new SugarParameter("@SerialNo", faceSN), new SugarParameter("@roomID", roomID), new SugarParameter("@hotelID", hotelID), new SugarParameter("@faceAddress", faceAddress)) >= 0)
|
||||
{
|
||||
RES = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
RES = 6;
|
||||
}
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
if (RES == 0)
|
||||
{
|
||||
List<MACLogs> logs = new List<MACLogs>();
|
||||
var Ip = IPHelper.GetIP();
|
||||
logs.Add(new MACLogs()
|
||||
{
|
||||
HotelID = hotelID,
|
||||
MAC = faceSN,
|
||||
roomNumber = roomNumber,
|
||||
userid = userinfo.Id,
|
||||
roomID = roomID,
|
||||
AppType = 1,
|
||||
type = isjb? 1 : 0
|
||||
});
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (faceAddress == null)
|
||||
{
|
||||
Data locs = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (locs != null && locs.status == 0)
|
||||
{
|
||||
if (locs.data.Count > 0)
|
||||
{
|
||||
|
||||
faceAddress = locs.data[0].location;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex, "日志错误");
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
lock (HostsServer.LOCK)
|
||||
{
|
||||
var maclogs = SqlSugarBase.Db.Queryable<MACLogs>().Select(x => x.ActionId).ToList();
|
||||
int ActionId = (maclogs.Count > 0 ? maclogs.Max() : 0) + 1;
|
||||
foreach (var item in logs)
|
||||
{
|
||||
item.Ip = Ip;
|
||||
item.location = faceAddress;
|
||||
item.ActionId = ActionId;
|
||||
item.createtime = DateTime.Now;
|
||||
item.Status = 0;
|
||||
SqlSugarBase.Db.Insertable(item).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return RES;
|
||||
}
|
||||
}
|
||||
}
|
||||
166
Services/Manager/HostsServer.cs
Normal file
166
Services/Manager/HostsServer.cs
Normal file
@@ -0,0 +1,166 @@
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using Services.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using static Services.Tool.HttpRequestHelp;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
public class HostsServer
|
||||
{
|
||||
public static object LOCK = new object();
|
||||
static string macsql = "select TOP 1 MAC,Id,RoomStatusID,HotelID,[RoomNumber],[Status] = convert(int, convert(nvarchar(50),[Status])) ,[Desc] = [remark],[CreateTime] =[registerdate] from BLW.CRICS.[dbo].tb_Hosts where MAC = @MAC";
|
||||
static string macup = @"
|
||||
--参数 @MAC 新的MAC @ID 为需要更新mac的id
|
||||
begin tran
|
||||
DECLARE @HostsId int;
|
||||
DECLARE @oldmac nvarchar(50);
|
||||
DECLARE @HostsIdoldmac nvarchar(50);
|
||||
SET @HostsId = -1;
|
||||
SET @oldmac = '-1';
|
||||
SET @HostsIdoldmac = '-1';
|
||||
SELECT TOP 1 @HostsId = id, @oldmac= MAC FROM tb_Hosts where MAC = @MAC
|
||||
SELECT TOP 1 @HostsIdoldmac = MAC FROM tb_Hosts where Id = @ID and mac is not null and mac!=''
|
||||
PRINT convert(varchar,@HostsId) +'&'+ @oldmac+'&'+@HostsIdoldmac
|
||||
update tb_Hosts set MAC='' where id = @HostsId
|
||||
update tb_Hosts set MAC=@MAC where Id = @ID
|
||||
if @@ERROR>0
|
||||
begin
|
||||
rollback tran
|
||||
end
|
||||
ELSE
|
||||
BEGIN
|
||||
COMMIT TRAN
|
||||
END
|
||||
";
|
||||
static string sql = " select MAC,Id,RoomStatusID,HotelID,[RoomNumber],[Status] = convert(int, convert(nvarchar(50),[Status])) ,[Desc] = [remark],[CreateTime] =[registerdate] from BLW.CRICS.[dbo].tb_Hosts where HotelID = @HotelID";
|
||||
/// <summary>
|
||||
/// 获取房间信息
|
||||
/// </summary>
|
||||
/// <param name="HotelID">酒点id</param>
|
||||
/// <returns></returns>
|
||||
public static List<HostsAdd> GetHostsInfo(int HotelID)
|
||||
{
|
||||
return HttpRequestHelp.GetHosts(HotelID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 检查MAC是否已经绑定
|
||||
/// </summary>
|
||||
/// <param name="MAC">MAC</param>
|
||||
/// <returns></returns>
|
||||
public static List<Hosts> CheckMAC(string MAC = "")
|
||||
{
|
||||
|
||||
string newmac = string.Empty;
|
||||
for (int i = 0; i < MAC.Length; i += 2)
|
||||
{
|
||||
newmac += MAC.Substring(i, 2) + "-";
|
||||
}
|
||||
newmac = newmac.Substring(0, newmac.Length - 1);
|
||||
var res = new List<Hosts>();
|
||||
res = HttpRequestHelp.GetHostByMAC(newmac);
|
||||
if (res.Count == 0)
|
||||
return null;
|
||||
else
|
||||
return res;
|
||||
}
|
||||
public static bool GetMAC(string MAC = "", int HotelID = 0, string roomID = "", string roomNumber = "", UserInfo userinfo = null, string loc = null)
|
||||
{
|
||||
var Ip = IPHelper.GetIP();
|
||||
string newmac = string.Empty;
|
||||
if (!string.IsNullOrEmpty(MAC)) {
|
||||
for (int i = 0; i < MAC.Length; i += 2)
|
||||
{
|
||||
newmac += MAC.Substring(i, 2) + "-";
|
||||
}
|
||||
newmac = newmac.Substring(0, newmac.Length - 1);
|
||||
}
|
||||
List<MACLogs> logs = new List<MACLogs>();
|
||||
logs.Add(new MACLogs()
|
||||
{
|
||||
AppType = 1,
|
||||
HotelID = HotelID,
|
||||
MAC = newmac,
|
||||
roomNumber = roomNumber,
|
||||
roomID = roomID,
|
||||
userid = userinfo.Id,
|
||||
type = MAC==""?1:0
|
||||
});
|
||||
int Status = 0;
|
||||
if (HttpRequestHelp.SetHostMAC(HotelID, newmac, roomNumber)) { Status = 1; };
|
||||
Task.Run(() =>
|
||||
{
|
||||
try
|
||||
{
|
||||
if (loc == null)
|
||||
{
|
||||
Data locs = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (locs != null && locs.status == 0)
|
||||
{
|
||||
if (locs.data.Count > 0)
|
||||
{
|
||||
|
||||
loc = locs.data[0].location;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex, "日志错误");
|
||||
}
|
||||
finally
|
||||
{
|
||||
lock (LOCK)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
var maclogs = SqlSugarBase.Db.Queryable<MACLogs>().Select(x => x.ActionId).ToList();
|
||||
int ActionId = (maclogs.Count > 0 ? maclogs.Max():0) + 1;
|
||||
foreach (var item in logs)
|
||||
{
|
||||
item.Ip = Ip;
|
||||
item.location = loc;
|
||||
item.ActionId = ActionId;
|
||||
item.createtime = DateTime.Now;
|
||||
item.Status = Status;
|
||||
SqlSugarBase.Db.Insertable(item).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
return Status == 1;
|
||||
}
|
||||
/// <summary>
|
||||
/// 写入用户反馈的错误
|
||||
/// </summary>
|
||||
public static bool AddErrorInfo(int userid, string MAC, int HotelID, int type,string roomNumber)
|
||||
{
|
||||
try
|
||||
{
|
||||
SqlSugarBase.Db.Insertable(new ErrorInfo() { createtime = DateTime.Now, type = type, status = 0, userid = userid, roomNumber = roomNumber, HotelID = HotelID, MAC = MAC }).ExecuteCommand();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex, "反馈信息错误");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
173
Services/Manager/HotelServer.cs
Normal file
173
Services/Manager/HotelServer.cs
Normal file
@@ -0,0 +1,173 @@
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using Models.View;
|
||||
using Services.Cache;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SqlClient;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json;
|
||||
using static Services.Cache.CacheHelp;
|
||||
using SqlSugar;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
public class HotelServer
|
||||
{
|
||||
//键值对存储酒店的最高就酒店组 如果存在就不需要查找
|
||||
public static Dictionary<int, int> keyValues = new Dictionary<int, int>();
|
||||
#region 检测组名
|
||||
public static bool CheckGroupName(string Name, int ParentId)
|
||||
{
|
||||
|
||||
var au = CacheHelp.cacheHoteldGroups.FirstOrDefault(x => x.ParentId == ParentId && x.Name == Name);
|
||||
if (au == null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
#region 添加组名
|
||||
public static int? AddGroupName(string Name, int ParentId, string Desc)
|
||||
{
|
||||
var au = CacheHelp.cacheHoteldGroups.FirstOrDefault(x => x.ParentId == ParentId && x.Name == Name);
|
||||
if (au != null)
|
||||
return null;
|
||||
|
||||
HotelGroups groups = new HotelGroups() { Name = Name, ParentId = ParentId, Desc = Desc };
|
||||
SqlSugarBase.Db.Insertable(groups).ExecuteCommand();
|
||||
CacheHelp.Removesys(syskey.sysHoteldGroupsListKey);
|
||||
return groups.Id;
|
||||
|
||||
}
|
||||
#endregion
|
||||
#region 检测酒店名
|
||||
public static bool CheckHotelName(string Name, int ParentId)
|
||||
{
|
||||
|
||||
var au = CacheHelp.cacheHotels.FirstOrDefault(x => x.GroupId == ParentId && x.Name == Name);
|
||||
if (au == null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
#region 添加酒店名
|
||||
public static int? AddHotel(string Name, int ParentId, string Desc)
|
||||
{
|
||||
var au = CacheHelp.cacheHotels.FirstOrDefault(x => x.GroupId == ParentId && x.Name == Name);
|
||||
if (au != null)
|
||||
return null;
|
||||
Hotels hotels = new Hotels() { Name = Name, GroupId = ParentId, Desc = Desc };
|
||||
SqlSugarBase.Db.Insertable(hotels).ExecuteCommand();
|
||||
CacheHelp.Removesys(syskey.sysHotelsListKey);
|
||||
return hotels.Id;
|
||||
}
|
||||
#endregion
|
||||
//返回酒店下面的人员信息 权限数量
|
||||
#region 找查酒店用户信息
|
||||
public static dynamic FindUserinfo()
|
||||
{
|
||||
dynamic resdata;
|
||||
var res = new List<dynamic>();
|
||||
var data = UserInfoServer.GetUserInfo(null);
|
||||
foreach (var item in data)
|
||||
{
|
||||
foreach (var tump in item.HotelInfo)
|
||||
{
|
||||
res.Add(new
|
||||
{
|
||||
hotelId = tump.id,
|
||||
Id = item.Id,
|
||||
Uid = item.Uid,
|
||||
sum = tump.sum
|
||||
});
|
||||
}
|
||||
}
|
||||
resdata = res.GroupBy(x => x.hotelId).ToList();
|
||||
return resdata;
|
||||
}
|
||||
#endregion
|
||||
#region 找查 用户最高所属酒店组 或者 公司信息
|
||||
public static dynamic FindUserinfoGs(View_UserInfo u)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (u.Company != null)
|
||||
{
|
||||
return new
|
||||
{
|
||||
//0 宝来威 1 住好 2 卓豪
|
||||
Id = u.Company,
|
||||
name = u.Company == 0?"宝来威":(u.Company == 1? "住好" : "卓豪")
|
||||
};
|
||||
}
|
||||
//if(u.Company)
|
||||
var S = 2;
|
||||
if (u.IsImport > 0)
|
||||
{
|
||||
if (u.HotelGroupID > 0)
|
||||
S = FindRoot(u.HotelGroupID);
|
||||
else
|
||||
{
|
||||
if (u.HotelID > 1)
|
||||
S = FindRoot_(u.HotelID);
|
||||
}
|
||||
}
|
||||
S -= 2;
|
||||
if (S < 0)
|
||||
{
|
||||
throw new Exception("用户没有找到对应的公司"+u.Id.ToString());
|
||||
}
|
||||
// S 2 "宝来威" 3 住好
|
||||
|
||||
UserInfo info = new UserInfo();
|
||||
info.Id = u.Id;
|
||||
info.Company = S;
|
||||
var result = SqlSugarBase.Db.Updateable(info).UpdateColumns(it => new { it.Company }).ExecuteCommand();
|
||||
Task.Run(() =>{
|
||||
Cache.CacheHelp.Removesys(syskey.sysUserInfoListKey);
|
||||
});
|
||||
return new
|
||||
{
|
||||
Id = S,
|
||||
name = S == 0 ? "宝来威" : (u.Company == 1 ? "住好" : "卓豪")
|
||||
};
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.WriteTimingUDPLog("参入参数:"+JsonConvert.SerializeObject( u));
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return new
|
||||
{
|
||||
Id = 0,
|
||||
name = "宝来威"
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
static dynamic FindRoot(int? group)
|
||||
{
|
||||
if (group == null)
|
||||
return 0;
|
||||
var groupinfo = cacheHoteldGroups.FirstOrDefault(x => x.Id == group);
|
||||
if (groupinfo == null)
|
||||
throw new Exception("group未找到!");
|
||||
if (groupinfo.ParentId <= 1)
|
||||
return groupinfo.Id;
|
||||
return FindRoot(groupinfo.ParentId);
|
||||
}
|
||||
static dynamic FindRoot_(int? id)
|
||||
{
|
||||
if (id == null)
|
||||
return 0;
|
||||
var groupinfo = cacheHotels.First(x => x.Id == id);
|
||||
return FindRoot(groupinfo.GroupId);
|
||||
}
|
||||
}
|
||||
}
|
||||
360
Services/Manager/Logs.cs
Normal file
360
Services/Manager/Logs.cs
Normal file
@@ -0,0 +1,360 @@
|
||||
using LogServer;
|
||||
using Newtonsoft.Json;
|
||||
using Services.Tool;
|
||||
using System;
|
||||
using System.Data.Entity.Validation;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
/// <summary>
|
||||
/// 日志类
|
||||
/// </summary>
|
||||
public partial class Logs
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 锁1 路径/App_Data/Log/
|
||||
/// </summary>
|
||||
private static readonly object _lock = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 锁2 路径/App_Data/TimingPlan/
|
||||
/// </summary>
|
||||
private static readonly object _lock1 = new object();
|
||||
|
||||
/// <summary>
|
||||
/// 锁3 路径/App_Data/UDPlog/
|
||||
/// </summary>
|
||||
private static readonly object _lockUdp = new object();
|
||||
|
||||
public static void WriteErrorLog(Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (ex != null)
|
||||
{
|
||||
string content = "类型:错误代码\r\n";
|
||||
content += "时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "来源:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "内容:" + ex.Message + "\r\n";
|
||||
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
|
||||
|
||||
|
||||
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志\r\n";
|
||||
content += "时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
//}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
string errtxt = "";
|
||||
string exname = ex.GetType().ToString();
|
||||
if (exname == "System.Data.Entity.Validation.DbEntityValidationException")
|
||||
{
|
||||
foreach (var item in ((DbEntityValidationException)ex).EntityValidationErrors)
|
||||
{
|
||||
foreach (var err in item.ValidationErrors)
|
||||
{
|
||||
errtxt += "EntityValidationErrors >>>>>> “" + err.PropertyName + "”字段" + err.ErrorMessage + "\r\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自页面:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n" + errtxt;
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
//if (BaseConfigs.GetLogInDB == 1)
|
||||
//{
|
||||
//TSysLog log = new TSysLog();
|
||||
//log.Content = content;
|
||||
//log.Type = "系统日志";
|
||||
//log.CreateTime = DateTime.Now;
|
||||
//DataAccess.CreateSysLog().Add(log);
|
||||
//}
|
||||
//if (BaseConfigs.GetLogInFile == 1)
|
||||
//{
|
||||
Page page = new Page();
|
||||
HttpServerUtility server = page.Server;
|
||||
string dir = server.MapPath("/App_Data/Log/");
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, System.Text.Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
//}
|
||||
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void WriteTimingPlanLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/TimingPlan/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
public static void WriteUserinfo(dynamic msgs)
|
||||
{
|
||||
try
|
||||
{
|
||||
string msg = JsonConvert.SerializeObject(msgs);
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/Userinfo/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorTimingPlanLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自作业线程:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n";
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/TimingPlan/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
lock (_lock1)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exl)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
LogHelp.WriteExceptionLog(exl);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteTimingUDPLog(string msg)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(msg))
|
||||
{
|
||||
|
||||
string content = "类型:调试日志 ";
|
||||
content += "时间:" + DateTime.Now.ToString() + " ";
|
||||
content += "内容:" + msg + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/UDPLog/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
|
||||
lock (_lockUdp)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
//FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
}
|
||||
|
||||
public static void WriteErrorTimingUDPLog(string errsrc, Exception ex)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (ex != null)
|
||||
{
|
||||
string content = (!string.IsNullOrEmpty(errsrc) ? "来自作业线程:" + errsrc : "") + "\r\n";
|
||||
content += "发生时间:" + DateTime.Now.ToString() + "\r\n";
|
||||
content += "异常对像:" + ex.TargetSite.ReflectedType.ToString() + "." + ex.TargetSite.Name + "\r\n";
|
||||
content += "错误追踪:" + ex.StackTrace + "\r\n";
|
||||
content += "错误提示:" + ex.Message + "\r\n";
|
||||
if (ex.InnerException != null && ex.InnerException.InnerException != null)
|
||||
content += ex.InnerException.InnerException.Message + "\r\n";
|
||||
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory + "/App_Data/UDPLog/";
|
||||
if (!Directory.Exists(dir))
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
}
|
||||
|
||||
string path = dir + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
|
||||
lock (_lockUdp)
|
||||
{
|
||||
StreamWriter FileWriter = new StreamWriter(path, true, Encoding.UTF8); //创建日志文件
|
||||
FileWriter.Write("---------------------------------------------------\r\n");
|
||||
FileWriter.Write(content);
|
||||
FileWriter.Close(); //关闭StreamWriter对象
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception exl)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(exl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static class LogHelp
|
||||
{
|
||||
/// <summary>
|
||||
/// 写入日志
|
||||
/// </summary>
|
||||
/// <param name="ex">异常对象</param>
|
||||
/// <param name="operationer">操作人</param>
|
||||
/// <param name="actionName">功能站点名称</param>
|
||||
public static void WriteExceptionLog(Exception ex, string actionName = "", string operationer = "")
|
||||
{
|
||||
if (HttpContext.Current == null)
|
||||
{
|
||||
ExceptionLogHelper.Log(new ExceptionLogMessage() { ActionName = actionName, exception = ex, Header = "", Url = "线程", Operationer = "线程", IP = "" });
|
||||
}
|
||||
else
|
||||
{
|
||||
ExceptionLogHelper.Log(new ExceptionLogMessage() { ActionName = actionName, exception = ex, Header = HttpContext.Current.Request.Headers.ToString(), Url = HttpContext.Current.Request.Url.ToString(), Operationer = operationer, IP = IPHelper.GetIP() });
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
101
Services/Manager/OrgAuthoServer.cs
Normal file
101
Services/Manager/OrgAuthoServer.cs
Normal 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
|
||||
}
|
||||
}
|
||||
17
Services/Manager/SyncData.cs
Normal file
17
Services/Manager/SyncData.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace Services.Manager
|
||||
{
|
||||
//同步酒店信息
|
||||
public class SyncData
|
||||
{
|
||||
public static bool UpDate()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
1752
Services/Manager/SyncHotelServer.cs
Normal file
1752
Services/Manager/SyncHotelServer.cs
Normal file
File diff suppressed because it is too large
Load Diff
379
Services/Manager/UserInfoServer.cs
Normal file
379
Services/Manager/UserInfoServer.cs
Normal file
@@ -0,0 +1,379 @@
|
||||
// Services.Manager.UserInfoServer
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using Models.View;
|
||||
using Services.Cache;
|
||||
using Services.Extensions;
|
||||
using Services.Manager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using Newtonsoft.Json;
|
||||
using System.Threading;
|
||||
using UH_CENTER;
|
||||
|
||||
public class UserInfoServer
|
||||
{
|
||||
//普通用户信息
|
||||
|
||||
#region 返回用户信息
|
||||
public static dynamic GetUserInfo( Func<dynamic,bool> func = null)
|
||||
{
|
||||
//取得普通用户信息
|
||||
var res = CacheHelp.cacheSysUserInfo.OrderByDescending(u => u.CreateTime).Select((View_UserInfo u) =>
|
||||
{
|
||||
var hoteles = SyncHotelServer.FindUHotelInfo(u);
|
||||
return new
|
||||
{
|
||||
Id = u.Id,
|
||||
IsValid = u.IsValid,
|
||||
Age = u.Age,
|
||||
Uid = u.Uid,
|
||||
sex = ((u.Sex == 0) ? "男" : ((u.Sex == 1) ? "女" : "未知")),
|
||||
Sex = u.Sex,
|
||||
OrganizationName = u.OrganizationName,
|
||||
Authoncount = u.Authoncount,
|
||||
isValid = (u.IsValid == 1) ? "冻结" : (u.IsValid >= 2 ? "管理" : "正常"),
|
||||
u.HeadImg,
|
||||
u.EndTime,
|
||||
u.Desc,
|
||||
u.CreateTime,
|
||||
u.IsImport,
|
||||
Gs = HotelServer.FindUserinfoGs(u),
|
||||
HotelInfo = hoteles,
|
||||
Hoteles = hoteles.Select(x=>x.id).ToArray()
|
||||
};
|
||||
}).Where(X=> func == null || func(X)).ToList();
|
||||
return res;
|
||||
}
|
||||
#endregion
|
||||
#region 冻结激活用户账号
|
||||
public static bool EditIsValid(string uid, int isvalid, string CreatedBy)
|
||||
{
|
||||
try
|
||||
{
|
||||
//UserInfo userInfo = authorityDB.UserInfos.FirstOrDefault((UserInfo x) => x.Uid == uid);
|
||||
UserInfo userInfo =SqlSugarBase.Db.Queryable<UserInfo>().First((UserInfo x) => x.Uid == uid);
|
||||
if (CacheHelp.cacheSysUserInfo.FirstOrDefault(X => X.Uid == CreatedBy).IsValid <= userInfo.IsValid && CreatedBy.ToLower() != "adminblv")
|
||||
return false;
|
||||
if (userInfo == null)
|
||||
{
|
||||
throw new CustomException("未查找到" + uid + "!");
|
||||
}
|
||||
userInfo.IsValid = isvalid;
|
||||
SqlSugarBase.Db.Updateable(userInfo).ExecuteCommand();
|
||||
//authorityDB.SaveChanges();
|
||||
DbLogServer.WriteDbLog((isvalid == 0 ? $"激活了用户{userInfo.Uid}({userInfo.Id })" : $"冻结了用户{userInfo.Id }({userInfo.Uid})"), 1);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysUserInfoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_UAListKey);
|
||||
return true;
|
||||
}
|
||||
catch (CustomException ex)
|
||||
{
|
||||
throw ex;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 用户权限用户组信息等
|
||||
public static List<View_UOA> GetUOA(string uid)
|
||||
{
|
||||
// 目前这些功能并未使用 可以直接 返回 [];
|
||||
return new List<View_UOA>();
|
||||
return CacheHelp.cacheView_UOA.Where(X => X.Uid == uid).ToList();
|
||||
}
|
||||
#endregion
|
||||
#region 用户权限信息等
|
||||
public static dynamic GetUA(string uid)
|
||||
{
|
||||
var RES = SqlSugarBase.Db.Queryable<View_UA>().Where(X => X.Uid == uid && X.AuthotypeId != 1).Select(X=>new{HotelId=X.HotelId,AuthorityId = X.AuthorityId, AuthotypeId = X.AuthotypeId, AuthorityName = X.AuthorityName }).ToArray();
|
||||
return RES;
|
||||
}
|
||||
#endregion
|
||||
#region 更改用户权限
|
||||
public static bool EditAuthoType(string uid, int type, int authorityid, int hotels, string CreatedBy)
|
||||
{
|
||||
try
|
||||
{
|
||||
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);
|
||||
var uinfo = CacheHelp.cacheSysUserInfo.FirstOrDefault(x => x.Uid.ToLower() == uid.ToLower());
|
||||
if (uinfo == null)
|
||||
{
|
||||
Logs.WriteTimingUDPLog("模型验证失败~");
|
||||
return false;
|
||||
}
|
||||
if (CreatedBy.ToLower() != uid.ToLower() && CacheHelp.cacheSysUserInfo.FirstOrDefault(X => X.Uid == CreatedBy).IsValid <= uinfo.IsValid && CreatedBy.ToLower() != "adminblv")
|
||||
{
|
||||
Logs.WriteTimingUDPLog("权限不足~");
|
||||
return false;
|
||||
}
|
||||
//UserAutho autho = db.UserAuthos.FirstOrDefault(x => x.UserId == uinfo.Id && x.AuthorityId == authorityid && x.HotelId == hotels);
|
||||
UserAuthoes autho = SqlSugarBase.Db.Queryable<UserAuthoes>().First(x => x.UserId == uinfo.Id && x.AuthorityId == authorityid && x.HotelId == hotels);
|
||||
if (autho == null)
|
||||
{
|
||||
DbLogServer.WriteDbLog($"新增了用户{uinfo.Uid }({uinfo.Id})对{hotels1.Name}({hotels})酒店的{authority.AuthorityName}({authority.Id})权限:无 => {statusType.Name}");
|
||||
//db.UserAuthos.Add(new UserAutho() { AuthotypeId = type, UserId = uinfo.Id, AuthorityId = authorityid, HotelId = hotels, CreatedBy = CreatedBy });
|
||||
SqlSugarBase.Db.Insertable(new UserAuthoes() { AuthotypeId = type, UserId = uinfo.Id, AuthorityId = authorityid, HotelId = hotels, CreatedBy = CreatedBy }).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
AuthoStatusType statusTypeold = CacheHelp.cacheSysAuthoStatusType.FirstOrDefault(x => x.Id == autho.AuthotypeId);
|
||||
DbLogServer.WriteDbLog($"更改了用户{uinfo.Uid }({uinfo.Id})对{hotels1.Name}({hotels})酒店的{authority.AuthorityName}({authority.Id})权限:{statusTypeold.Name} => {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);
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region 检查用户uid是否可用
|
||||
public static bool CheckUid(string uid)
|
||||
{
|
||||
if (CacheHelp.cacheSysUserInfo.FirstOrDefault(u => u.Uid.ToLower() == uid.ToLower()) == null)
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
#endregion
|
||||
#region 添加、修改用户
|
||||
public static bool AddUserinfo(View_UserInfo userInfo, string uid, int type = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
int ID=-1;
|
||||
OrgUsers orgUser = new OrgUsers();
|
||||
UserInfo user = new UserInfo();
|
||||
if (type != 0)
|
||||
{
|
||||
user = SqlSugarBase.Db.Queryable<UserInfo>().First(x => x.Id == userInfo.Id) ?? null;
|
||||
orgUser = SqlSugarBase.Db.Queryable<OrgUsers>().First(x => x.UserId == user.Id) ?? null;
|
||||
if (user == null)
|
||||
return false;
|
||||
if (orgUser == null)
|
||||
return false;
|
||||
int? orgid = userInfo.OrgId;
|
||||
orgUser.OrgId = int.Parse(orgid.ToString());
|
||||
SqlSugarBase.Db.Updateable(orgUser).ExecuteCommand();
|
||||
|
||||
if (user.Uid.ToLower() != uid.ToLower() && CacheHelp.cacheSysUserInfo.FirstOrDefault(X => X.Uid == uid).IsValid <= user.IsValid && uid.ToLower() != "adminblv")
|
||||
return false;
|
||||
}
|
||||
user.Age = userInfo.Age;
|
||||
user.Uid = userInfo.Uid.ToLower();
|
||||
user.HeadImg = userInfo.HeadImg;
|
||||
user.Sex = userInfo.Sex;
|
||||
user.Desc = userInfo.Desc;
|
||||
user.IsValid = userInfo.IsValid;
|
||||
user.CreatedBy = uid;
|
||||
user.Company = userInfo.Company;
|
||||
user.EndTime =DateTime.Now.AddYears(200);/* userInfo.EndTime*/
|
||||
if (!string.IsNullOrEmpty(userInfo.Pwd))
|
||||
{
|
||||
user.Pwd = userInfo.Pwd;
|
||||
Services.Tool.RSA rSA = HttpContext.Current.Session["ras"] as Services.Tool.RSA ?? throw new Exception();
|
||||
string pwd = rSA.DecodeOrNull(user.Pwd) ?? throw new CustomException("出错!");
|
||||
user.Pwd = user.PwdSee = pwd;
|
||||
user = user.ComputePasswordHash();
|
||||
}
|
||||
if (user.Uid.ToLower() != uid.ToLower() && CacheHelp.cacheSysUserInfo.FirstOrDefault(X => X.Uid == uid).IsValid < user.IsValid && uid.ToLower() != "adminblv")
|
||||
return false;
|
||||
Logs.WriteUserinfo(user);
|
||||
if (type == 0)
|
||||
{
|
||||
ID= SqlSugarBase.Db.Insertable(user).ExecuteReturnIdentity();
|
||||
}
|
||||
if (type == 0)
|
||||
{
|
||||
orgUser = new OrgUsers();
|
||||
orgUser.OrgId = userInfo.OrgId ?? 1;
|
||||
orgUser.UserId = ID;
|
||||
|
||||
SqlSugarBase.Db.Insertable(orgUser).ExecuteCommand();
|
||||
|
||||
DbLogServer.WriteDbLog($"添加了用户信息{user.Uid}({ID})");
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
SqlSugarBase.Db.Updateable(user).ExecuteCommand();
|
||||
DbLogServer.WriteDbLog($"修改了用户信息{user.Uid}({ID})");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new CustomException(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysUserAuthoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_UAListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysUserInfoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_UOAListKey);
|
||||
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
#region 删除用户
|
||||
public static bool DelUserinfo(int id, string uid)
|
||||
{
|
||||
UserInfo user = new UserInfo();
|
||||
try
|
||||
{
|
||||
using (AuthorityDB db = new AuthorityDB())
|
||||
{
|
||||
user = db.UserInfos.FirstOrDefault(x => x.Id == id);
|
||||
if (user.Uid.ToLower() != uid.ToLower() && CacheHelp.cacheSysUserInfo.FirstOrDefault(X => X.Uid == uid).IsValid <= user.IsValid && uid.ToLower() != "adminblv")
|
||||
return false;
|
||||
if (user == null)
|
||||
{
|
||||
DbLogServer.WriteDbLog($"删除用户{id}失败!");
|
||||
return false;
|
||||
}
|
||||
db.OrgUsers.Remove(db.OrgUsers.FirstOrDefault(x => x.UserId == id));
|
||||
db.UserAuthos.RemoveRange(db.UserAuthos.Where(x => x.UserId == id));
|
||||
db.UserInfos.Remove(user);
|
||||
db.SaveChanges();
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DbLogServer.WriteDbLog($"删除用户{id}失败!");
|
||||
throw new CustomException(ex.ToString());
|
||||
}
|
||||
finally
|
||||
{
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysUserAuthoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_UAListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysUserInfoListKey);
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysView_UOAListKey);
|
||||
}
|
||||
DbLogServer.WriteDbLog($"删除用户{user.Uid}({user.Id})成功!");
|
||||
return true;
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 获取用户信息
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="draw"></param>
|
||||
/// <param name="gs"></param>
|
||||
/// <param name="IsImport"></param>
|
||||
/// <param name="search"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
public static dynamic GetUserinfoView(int start, int length, int draw, int gs = -1, int IsImport = -1, Dictionary<string, string> search = null)
|
||||
{
|
||||
var data = CacheHelp.cacheView_UserInfo.OrderByDescending(X=>X.CreateTime).ToList();
|
||||
string searchstr = string.Empty;
|
||||
if(search != null && search["value"].Length>0)
|
||||
{
|
||||
int s = search["value"].Length;
|
||||
searchstr = $"uid like '%{search["value"].ToUpper()}%'";
|
||||
data = data.Where(x=>x.Uid.Trim().ToUpper().Contains(search["value"].ToUpper())).ToList();
|
||||
}
|
||||
if (gs!=-1)
|
||||
{
|
||||
data= data.Where(x => x.Company == gs).ToList();
|
||||
if (searchstr == string.Empty)
|
||||
{
|
||||
searchstr = $"Company = '{gs}'";
|
||||
}
|
||||
else
|
||||
{
|
||||
searchstr += $" and Company = '{gs}' ";
|
||||
}
|
||||
}
|
||||
if (IsImport != -1)
|
||||
{
|
||||
data = data.Where(x => x.IsImport == IsImport).ToList();
|
||||
|
||||
if (searchstr == string.Empty)
|
||||
{
|
||||
searchstr = $"IsImport = '{IsImport}'";
|
||||
}
|
||||
else
|
||||
{
|
||||
searchstr += $" and IsImport = '{IsImport}' ";
|
||||
}
|
||||
}
|
||||
if (searchstr == string.Empty)
|
||||
{
|
||||
searchstr = $" 1 = 1 ";
|
||||
}
|
||||
int recordsFiltered = 0;
|
||||
string sqlsum = $"select count(*) from View_UserInfo where {searchstr}";
|
||||
//recordsFiltered = db.Database.SqlQuery<int>(sqlsum).ToList()[0];
|
||||
// recordsFiltered = SqlSugarBase.Db.Ado.SqlQuery<int>(sqlsum).ToList()[0]; 推荐使用
|
||||
recordsFiltered = data.Count();
|
||||
//if (start == -10)
|
||||
//{
|
||||
// searchstr += $@" and id not in (select
|
||||
// id from View_UserInfo where { searchstr}
|
||||
// order by CreateTime desc LIMIT 1,{ start}) ";
|
||||
//}
|
||||
|
||||
List <dynamic> res = null;
|
||||
bool SX = false;
|
||||
res = new List<dynamic>();
|
||||
string sql = $"select * from View_UserInfo where {searchstr} order by CreateTime desc LIMIT {start},{ length}";
|
||||
res.AddRange(
|
||||
data.Skip(start).Take(length).Select((View_UserInfo u) =>
|
||||
{
|
||||
var hoteles = UH_CENTER_Help.Sel_Hotel(u);
|
||||
// 上面的操作会刷新数据 这里刷新缓存 架构 问题
|
||||
if (string.IsNullOrEmpty(u.Hotel_Data))
|
||||
SX = true;
|
||||
return new
|
||||
{
|
||||
Id = u.Id,
|
||||
IsValid = u.IsValid,
|
||||
Age = u.Age,
|
||||
Uid = u.Uid,
|
||||
sex = ((u.Sex == 0) ? "男" : ((u.Sex == 1) ? "女" : "未知")),
|
||||
Sex = u.Sex,
|
||||
OrganizationName = u.OrganizationName,
|
||||
Authoncount = u.Authoncount,
|
||||
isValid = (u.IsValid == 1 ? "冻结" :
|
||||
(u.IsValid == 0 ? "正常" :
|
||||
(u.IsValid == 2 ? "管理" :
|
||||
(u.IsValid == 3 ? "超管" : "其他")))),
|
||||
u.HeadImg,
|
||||
u.EndTime,
|
||||
u.Desc,
|
||||
u.CreateTime,
|
||||
u.IsImport,
|
||||
Gs = HotelServer.FindUserinfoGs(u),
|
||||
Hoteles = hoteles.Select(X=>X.id).ToArray(),
|
||||
HotelInfo = hoteles
|
||||
};
|
||||
}
|
||||
));
|
||||
if(SX)
|
||||
CacheHelp.Removesys(CacheHelp.syskey.sysUserInfoListKey);
|
||||
return new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = CacheHelp.cacheSysUserInfo.Count(),
|
||||
recordsFiltered = recordsFiltered,
|
||||
data = res
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user