659 lines
20 KiB
C#
659 lines
20 KiB
C#
using System;
|
||
using System.Web.Mvc;
|
||
using Models;
|
||
using Models.View;
|
||
using Services;
|
||
using Services.Cache;
|
||
using Services.Extensions;
|
||
using Services.Manager;
|
||
using UI.Controllers;
|
||
using Newtonsoft.Json;
|
||
using System.Linq;
|
||
using Models.ModelItems;
|
||
using System.IO;
|
||
using System.Collections.Generic;
|
||
|
||
public class UIMySyncInfo
|
||
{
|
||
public bool isBusying { set; get; }
|
||
public DateTime lastTm { set; get; }
|
||
public string strLastTm { set; get; }
|
||
}
|
||
|
||
public class ApiController : BaseController
|
||
{
|
||
[HttpGet]
|
||
|
||
#region 退出登录
|
||
public ActionResult LoginOut()
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
UserLoginHelper.UserLogout();
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 获取用户信息
|
||
[HttpPost]
|
||
public ActionResult GetUserinfo(int start, int length, int draw, int gs = -1, int IsImport = -1, Dictionary<string, string> search = null)
|
||
{
|
||
try
|
||
{
|
||
var z = UserInfoServer.GetUserinfoView(start, length, draw, gs, IsImport, search);
|
||
return Content(
|
||
JsonConvert.SerializeObject(z)
|
||
);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
return Json(new
|
||
{
|
||
draw,
|
||
recordsTotal = 0,
|
||
recordsFiltered = 0,
|
||
data = "",
|
||
error = "服务器异常~" + ex.Message
|
||
});
|
||
}
|
||
}
|
||
#endregion
|
||
#region 修改账号信息
|
||
[HttpPost]
|
||
public ActionResult EditIsValid(string Uid, int IsValid)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
Logs.WriteTimingUDPLog($"EditIsValid接口UID:{Uid},IsValid:{IsValid}");
|
||
if (UserInfoServer.EditIsValid(Uid, IsValid, Umodel.Uid))
|
||
returnResult.Status = 200;
|
||
else
|
||
{
|
||
returnResult.Status = 100;
|
||
returnResult.Message = "修改失败!";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 用户用户组权限信息
|
||
[HttpPost]
|
||
public ActionResult GetUOA(string uid)
|
||
{
|
||
ReturnResult<dynamic> returnResult = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
|
||
returnResult.Data = new { UOA = UserInfoServer.GetUOA(uid), UA = UserInfoServer.GetUA(uid), AppInfo = new int[] { } };
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
public ActionResult GetOrgAutho(int OrgId)
|
||
{
|
||
ReturnResult<dynamic> returnResult = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
Logs.WriteTimingUDPLog($"GetOrgAutho接口UID:{OrgId}");
|
||
returnResult.Data = CacheHelp.cacheSysOrgAuthority.Where(x => x.OrgId == OrgId && x.AuthotypeId != 1).ToList();
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 应用权限信息 权限状态信息
|
||
public ActionResult GetApps(int appid = 0)
|
||
{
|
||
ReturnResult<dynamic> returnResult = new ReturnResult<dynamic>();
|
||
try
|
||
{
|
||
//appid == 0 查询所有正常 app 的 正常的权限 appid >0 指定app 所有权限
|
||
returnResult.Data = new
|
||
{
|
||
Appinfos = appid == 0 ?
|
||
// appid app状态 权限状态 是否返回下面的权限信息
|
||
AppServer.GetAppInfo(0, 0, 1) : AppServer.GetAppInfo(appid, -1, 10),
|
||
Types = CacheHelp.cacheSysAuthoStatusType
|
||
};
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 修改个人/用户组 权限信息
|
||
/// <summary>
|
||
///
|
||
/// </summary>
|
||
/// <param name="id">权限ID</param>
|
||
/// <param name="status">状态 0 删除权限 其他参考AuthoStatusType表</param>
|
||
/// <param name="type">个人0/用户组1</param>
|
||
/// <returns></returns>
|
||
[HttpPost]
|
||
public ActionResult EditAuthoType(string uid, int id, int hotels, int status = 0, int type = 0)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
Logs.WriteTimingUDPLog($"EditIsValid接口hotels{hotels}uid(type不为1时表示用户组id):{uid},权限ID:{id},status:{status},type:{type}");
|
||
if (type == 0)
|
||
{
|
||
if (!UserInfoServer.EditAuthoType(uid, status, id, hotels, Umodel.Uid))
|
||
throw new CustomException("失败!");
|
||
}
|
||
else
|
||
{
|
||
if (!OrgAuthoServer.EditAuthoType(int.Parse(uid), status, id, hotels, Umodel.Uid))
|
||
throw new CustomException("失败!");
|
||
}
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 用户添加-查询用户账号是否可用
|
||
[HttpPost]
|
||
public ActionResult CheckUid(string Uid)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
returnResult.Status = 0;
|
||
if (UserInfoServer.CheckUid(Uid))
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 添加用户信息
|
||
[HttpPost]
|
||
public ActionResult AddUserinfo(View_UserInfo userInfo, int type = 0)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
Logs.WriteTimingUDPLog($" AddUserinfo接口=:{JsonConvert.SerializeObject(userInfo)}");
|
||
if (UserInfoServer.AddUserinfo(userInfo, Umodel.Uid, type))
|
||
returnResult.Status = 200;
|
||
else
|
||
{
|
||
returnResult.Status = 100;
|
||
returnResult.Message = "修改失败!";
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
|
||
[HttpPost]
|
||
#region 清除缓存redis 和 同步酒店信息
|
||
public ActionResult Clear()
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
DbLogServer.WriteDbLog($"刷新了缓存信息");
|
||
var sx = SyncHotelServer.SyncHotelGroups(Umodel.Uid);
|
||
if (!sx)
|
||
{
|
||
returnResult.Status = 100;
|
||
returnResult.Message = "不能频繁刷新~";
|
||
}
|
||
if (returnResult.Status == 0)
|
||
{
|
||
returnResult.Status = 200;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = "服务器异常~";
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
[HttpPost]
|
||
public ActionResult ClearCache()
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
DbLogServer.WriteDbLog($"刷新了缓存信息");
|
||
CacheHelp.Removesys(null);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = "服务器异常~";
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
public ActionResult GetRunSyncState()
|
||
{
|
||
UIMySyncInfo uiinfo = new UIMySyncInfo();
|
||
|
||
uiinfo.isBusying = Services.Manager.GlobalTest.isInProcessing;
|
||
uiinfo.lastTm = Services.Manager.GlobalTest.lastStartTime;
|
||
uiinfo.strLastTm = uiinfo.lastTm.ToString("yyyy-mm-dd HH:mm:ss");
|
||
|
||
return Json(uiinfo, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
|
||
|
||
|
||
public ActionResult Clear2()
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
var sx = SyncHotelServer.SyncHotelGroups("接口调用");
|
||
if (!sx)
|
||
{
|
||
returnResult.Status = 100;
|
||
returnResult.Message = "不能频繁刷新~";
|
||
}
|
||
if (returnResult.Status == 0)
|
||
{
|
||
returnResult.Status = 200;
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = "服务器异常~";
|
||
}
|
||
return Json(returnResult, JsonRequestBehavior.AllowGet);
|
||
}
|
||
|
||
|
||
|
||
#endregion
|
||
#region 删除用户组
|
||
[HttpPost]
|
||
public ActionResult DelOrg(int OrgId)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
if (OrgAuthoServer.DelOrg(OrgId, Umodel.Uid))
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 检查用户组应用名是否可用
|
||
[HttpPost]
|
||
public ActionResult CheckOrgApp(string Name, int Type = 0)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
if (Type == 0)
|
||
{
|
||
if (OrgAuthoServer.CheckName(Name))
|
||
returnResult.Status = 200;
|
||
}
|
||
else if
|
||
(AppServer.CheckName(Name))
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 添加用户组App
|
||
[HttpPost]
|
||
public ActionResult AddOrgApp(string appicon, string Name, string Desc = "", int Type = 0, string WebSite = "", int AppType = 0, string Version = "1.0", string ReleaseDate = "")
|
||
{
|
||
ReturnResult<int?> returnResult = new ReturnResult<int?>();
|
||
try
|
||
{
|
||
DateTime ReleaseDates = DateTime.Now;
|
||
DateTime.TryParse(ReleaseDate, out ReleaseDates);
|
||
if (ReleaseDates == default)
|
||
ReleaseDates = DateTime.Now;
|
||
if (Type == 0)
|
||
returnResult.Data = OrgAuthoServer.AddOrg(Name, Desc, Umodel.Uid);
|
||
else
|
||
returnResult.Data = AppServer.AddApp(Name, Desc, Umodel.Uid, Version, appicon, ReleaseDates, WebSite, AppType);
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 删除应用
|
||
[HttpPost]
|
||
public ActionResult DelApp(int AppId, int IsValid)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
if (AppServer.DelApp(AppId, IsValid, Umodel.Uid))
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 检查权限名
|
||
[HttpPost]
|
||
public ActionResult Checkautho(int AppId, string AuthoNmae)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
if (AppServer.Checkautho(AppId, AuthoNmae))
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 添加权限
|
||
[HttpPost]
|
||
public ActionResult Addautho(int AppId, string AuthoNmae, string AuthoStatusTypeId, string Desc = "")
|
||
{
|
||
ReturnResult<int?> returnResult = new ReturnResult<int?>();
|
||
try
|
||
{
|
||
returnResult.Data = AppServer.Addautho(AppId, AuthoNmae, Desc, Umodel.Uid, AuthoStatusTypeId);
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 检查酒店 酒店分组
|
||
[HttpPost]
|
||
public ActionResult CheckGroupName(string Name, int ParentId, int Type = 0)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
if (Type == 0)
|
||
{
|
||
if (HotelServer.CheckGroupName(Name, ParentId))
|
||
returnResult.Status = 200;
|
||
else
|
||
returnResult.Status = 100;
|
||
}
|
||
else
|
||
{
|
||
if (HotelServer.CheckHotelName(Name, ParentId))
|
||
returnResult.Status = 200;
|
||
else
|
||
returnResult.Status = 100;
|
||
}
|
||
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 添加酒店、酒店分组
|
||
[HttpPost]
|
||
public ActionResult AddHotel(string Name, int ParentId, string Desc, int Type = 0)
|
||
{
|
||
ReturnResult<int?> returnResult = new ReturnResult<int?>();
|
||
try
|
||
{
|
||
if (Type == 0)
|
||
returnResult.Data = HotelServer.AddGroupName(Name, ParentId, Desc);
|
||
else
|
||
returnResult.Data = HotelServer.AddHotel(Name, ParentId, Desc);
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 删除权限
|
||
[HttpPost]
|
||
public ActionResult DelAppAutho(int AuthoId, int status)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
returnResult.Message = AppServer.Delautho(AuthoId, status, Umodel.Uid);
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 修改权限
|
||
[HttpPost]
|
||
public ActionResult EditAppAutho(Authority authority)
|
||
{
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
returnResult.Message = AppServer.Editautho(authority, Umodel.Uid);
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 删除用户
|
||
[HttpPost]
|
||
public ActionResult Deluser(int id)
|
||
{
|
||
|
||
ReturnResult returnResult = new ReturnResult();
|
||
try
|
||
{
|
||
if (UserInfoServer.DelUserinfo(id, Umodel.Uid))
|
||
returnResult.Status = 200;
|
||
else
|
||
returnResult.Status = 100;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Status = 500;
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 添加类型
|
||
public ActionResult AddType(string name, string desc)
|
||
{
|
||
ReturnResult<AuthoStatusType> returnResult = new ReturnResult<AuthoStatusType>();
|
||
try
|
||
{
|
||
returnResult.Data = AuthoStatusServer.AddAuthoStatus(name, desc);
|
||
if (returnResult.Data == null)
|
||
returnResult.Status = 100;
|
||
else
|
||
returnResult.Status = 200;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
returnResult.Message = ex.Message;
|
||
LogHelp.WriteExceptionLog(ex);
|
||
}
|
||
return Json(returnResult);
|
||
}
|
||
#endregion
|
||
#region 日志分页
|
||
public ActionResult GetLog(int start, int length, int draw, Dictionary<string, string> search = null)
|
||
{
|
||
try
|
||
{
|
||
|
||
var content = (search == null || string.IsNullOrEmpty(search["value"]) ? 0.ToString() : search["value"]);
|
||
string sql = string.Empty;
|
||
// id
|
||
sql += $"( {content} = 0 or id ={content} )";
|
||
// Uid
|
||
if (sql == string.Empty)
|
||
{
|
||
sql += $"(0 = {content} or Uid = '{content}' )";
|
||
}
|
||
else
|
||
{
|
||
sql += $" OR (0 = {content} or Uid = '{content}' )";
|
||
|
||
}
|
||
// Content
|
||
if (sql == string.Empty)
|
||
{
|
||
sql += $"(0 = {content} or Content LIKE '%{content}%' )";
|
||
}
|
||
else
|
||
{
|
||
sql += $" OR (0 = {content} or Content LIKE '%{content}%' )";
|
||
|
||
}
|
||
// location
|
||
if (sql == string.Empty)
|
||
{
|
||
sql += $"(0 = {content} or location LIKE '%{content}%' )";
|
||
}
|
||
else
|
||
{
|
||
sql += $" OR (0 = {content} or location LIKE '%{content}%' )";
|
||
|
||
}
|
||
|
||
if (sql!= string.Empty)
|
||
{
|
||
sql = " WHERE (" + sql;
|
||
}
|
||
//var resdatastr = $"SELECT top {length} * FROM DbLog " + sql + $" ) and id not in ( SELECT top {start} id FROM DbLog " + sql+ " ) order by id desc ) order by id desc ";
|
||
//var resdatastr = string.Format("SELECT * FROM DbLog " + sql + $" ) and id not in ( SELECT id FROM DbLog " + sql + " ) order by id desc LIMIT 1,{0} ) order by id desc LIMIT 1,{1}",start, length);
|
||
var resdatastr = $"SELECT * FROM DbLog " + sql + $" ) order by id desc LIMIT {start},{length}";
|
||
|
||
sql = "SELECT count(*) FROM DbLog " + sql+")";
|
||
var data = SqlSugarBase.Db.Ado.SqlQuery<int>(sql).ToList().DefaultIfEmpty();
|
||
var resdata = SqlSugarBase.Db.Ado.SqlQuery<DbLog>(resdatastr).ToList();
|
||
return Json(new
|
||
{
|
||
draw,
|
||
recordsTotal = SqlSugarBase.Db.Queryable<DbLog>().Count(),
|
||
recordsFiltered = data,
|
||
data = resdata
|
||
});
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelp.WriteExceptionLog(ex);
|
||
return Json(new
|
||
{
|
||
draw,
|
||
recordsTotal = 0,
|
||
recordsFiltered = 0,
|
||
data = "",
|
||
error = "服务器异常~" + ex.Message
|
||
});
|
||
}
|
||
}
|
||
#endregion
|
||
|
||
}
|