初始化项目
This commit is contained in:
658
UI/Controllers/ApiController.cs
Normal file
658
UI/Controllers/ApiController.cs
Normal file
@@ -0,0 +1,658 @@
|
||||
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
|
||||
|
||||
}
|
||||
27
UI/Controllers/AppController.cs
Normal file
27
UI/Controllers/AppController.cs
Normal file
@@ -0,0 +1,27 @@
|
||||
using Services.Cache;
|
||||
using Services.Manager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
public class AppController : BaseController
|
||||
{
|
||||
// GET: App
|
||||
public ActionResult Index(int id)
|
||||
{
|
||||
ViewBag.Select = 2;
|
||||
ViewBag.SelectApp = id;
|
||||
ViewBag.App = CacheHelp.cacheSysApp.FirstOrDefault(u => u.Id == id );
|
||||
ViewBag.AuthoType = CacheHelp.cacheSysAuthoStatusType;
|
||||
return View();
|
||||
}
|
||||
public ActionResult List()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
165
UI/Controllers/BaseController.cs
Normal file
165
UI/Controllers/BaseController.cs
Normal file
@@ -0,0 +1,165 @@
|
||||
using Models.View;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Services.Manager;
|
||||
using Services.Cache;
|
||||
using Newtonsoft.Json;
|
||||
using Services.Tool;
|
||||
using Models;
|
||||
using System.IO.Compression;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
|
||||
public class BaseController : Controller
|
||||
{
|
||||
public View_UserInfo Umodel { get; set; }
|
||||
|
||||
public object ActPacket { get; set; }
|
||||
|
||||
public string ActMessage { get; set; }
|
||||
|
||||
public string ActType { get; set; }
|
||||
|
||||
public int ActLevel { get; set; }
|
||||
|
||||
protected override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
base.OnActionExecuting(filterContext);
|
||||
var Token = HttpContext.Request.QueryString["Token"];
|
||||
if (!string.IsNullOrEmpty(Token))
|
||||
Token = "?Token=" + Token;
|
||||
string homeurl = ConfigHelper.GetConfigString("Homeurl") ?? "";
|
||||
if (string.IsNullOrEmpty(homeurl))
|
||||
ConfigHelper.UpdatetConfig("Homeurl", Request.Url.ToString());
|
||||
View_UserInfo model = UserLoginHelper.CurrentUser();
|
||||
|
||||
string controllerName = filterContext.RouteData.Values["controller"].ToString().ToLower();//获得控制器名
|
||||
//string actionName = filterContext.RouteData.Values["action"].ToString().ToLower();//方式一 action名
|
||||
string actionName = filterContext.ActionDescriptor.ActionName.ToLower();//方式二 action名
|
||||
|
||||
if ((controllerName == "home" && actionName == "indexinfo" && !string.IsNullOrEmpty(Token)) || model == null)
|
||||
{
|
||||
|
||||
ContentResult contentResult = (ContentResult)(filterContext.Result = new ContentResult
|
||||
{
|
||||
Content = string.Format("<script type='text/javascript'>top.location.href='{0}';</script>", "/Login/Index" + Token)
|
||||
});
|
||||
return;
|
||||
}
|
||||
//if (!string.IsNullOrEmpty(Token))
|
||||
//{
|
||||
// string Ip = IPHelper.GetIP();
|
||||
// RedisHelper.RemoveKey(Token + Ip);
|
||||
//}
|
||||
Umodel = CacheHelp.cacheSysUserInfo.FirstOrDefault((View_UserInfo X) => X.Uid == model.Uid);
|
||||
if (Umodel != null)
|
||||
{
|
||||
//公共属性
|
||||
base.ViewBag.Umodel = Umodel;
|
||||
base.ViewBag.Usersum = CacheHelp.cacheSysUserInfo.Count;
|
||||
base.ViewBag.logsum = CacheHelp.cacheDbLogs;
|
||||
base.ViewBag.Apps = CacheHelp.cacheSysApp;
|
||||
base.ViewBag.Orgs = CacheHelp.cacheSysOrganization.Where(x => x.IsValid == 0).ToList();
|
||||
//酒店信息
|
||||
base.ViewBag.HoteldGroups = CacheHelp.gh;
|
||||
base.ViewBag.HoteldGroupsinfo = CacheHelp.HoteldGroupsinfo;
|
||||
ViewBag.BaseDataGroups = JsonConvert.SerializeObject(CacheHelp.cacheHoteldGroups);
|
||||
ViewBag.BaseData = JsonConvert.SerializeObject(CacheHelp.cacheHotels.GroupBy(x => x.GroupId).ToList());
|
||||
return ;
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnActionExecuted(ActionExecutedContext filterContext)
|
||||
{
|
||||
|
||||
base.OnActionExecuted(filterContext);
|
||||
base.ViewBag.Title = ActMessage;
|
||||
View_UserInfo view_UserInfo = UserLoginHelper.CurrentUser();
|
||||
if (view_UserInfo != null)
|
||||
{
|
||||
Umodel = view_UserInfo;
|
||||
if (!string.IsNullOrEmpty(ActMessage))
|
||||
{
|
||||
string text = filterContext.RouteData.Values["controller"].ToString().ToLower();
|
||||
string text2 = filterContext.RouteData.Values["action"].ToString().ToLower();
|
||||
if (base.ViewBag.mFormUrl != null)
|
||||
{
|
||||
base.ViewBag.FormUrl = base.ViewBag.mFormUrl;
|
||||
}
|
||||
else if (base.Request.UrlReferrer != null)
|
||||
{
|
||||
base.ViewBag.FormUrl = base.Request.UrlReferrer.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ContentResult contentResult = (ContentResult)(filterContext.Result = new ContentResult
|
||||
{
|
||||
Content = $"/Login/Index"
|
||||
});
|
||||
}
|
||||
//压缩
|
||||
var acceptEncoding = filterContext.HttpContext.Request.Headers["Accept-Encoding"];
|
||||
if (!string.IsNullOrEmpty(acceptEncoding))
|
||||
{
|
||||
acceptEncoding = acceptEncoding.ToLower();
|
||||
var response = filterContext.HttpContext.Response;
|
||||
if (acceptEncoding.Contains("gzip"))
|
||||
{
|
||||
response.AppendHeader("Content-encoding", "gzip");
|
||||
response.Filter = new GZipStream(response.Filter, CompressionMode.Compress);
|
||||
}
|
||||
else if (acceptEncoding.Contains("deflate"))
|
||||
{
|
||||
response.AppendHeader("Content-encoding", "deflate");
|
||||
response.Filter = new DeflateStream(response.Filter, CompressionMode.Compress);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
protected NameValueCollection FormatQueryString(NameValueCollection nameValues)
|
||||
{
|
||||
NameValueCollection nameValueCollection = new NameValueCollection();
|
||||
string[] allKeys = nameValues.AllKeys;
|
||||
foreach (string text in allKeys)
|
||||
{
|
||||
if (text.Equals("datefiled"))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nameValues["dateform"]) && !string.IsNullOrEmpty(nameValues["dateto"]))
|
||||
{
|
||||
string[] array = nameValues["dateform"].Split('/');
|
||||
string[] array2 = nameValues["dateto"].Split('/');
|
||||
string s = array[2] + "-" + array[0] + "-" + array[1];
|
||||
string s2 = array2[2] + "-" + array2[0] + "-" + array2[1];
|
||||
DateTime dateTime = DateTime.Parse(s).ToDateTime();
|
||||
DateTime dateTime2 = DateTime.Parse(s2).ToDateTime();
|
||||
nameValueCollection.Add(nameValues[text] + ">=", dateTime.ToString());
|
||||
nameValueCollection.Add(nameValues[text] + "<=", dateTime2.ToString());
|
||||
}
|
||||
}
|
||||
else if (text.Equals("numberfiled"))
|
||||
{
|
||||
if (!string.IsNullOrEmpty(nameValues["numberform"]) && !string.IsNullOrEmpty(nameValues["numberto"]))
|
||||
{
|
||||
double num = nameValues["numberform"].ToDouble();
|
||||
double num2 = nameValues["numberto"].ToDouble();
|
||||
nameValueCollection.Add(nameValues[text] + ">=", num.ToString());
|
||||
nameValueCollection.Add(nameValues[text] + "<=", num2.ToString());
|
||||
}
|
||||
}
|
||||
else if (text.Equals("keyfiled") && !string.IsNullOrEmpty(nameValues["keyword"]))
|
||||
{
|
||||
nameValueCollection.Add(nameValues[text], nameValues["keyword"]);
|
||||
}
|
||||
}
|
||||
return nameValueCollection;
|
||||
}
|
||||
}
|
||||
}
|
||||
117
UI/Controllers/HomeController.cs
Normal file
117
UI/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,117 @@
|
||||
using System;
|
||||
using System.Web.Mvc;
|
||||
using Services.Cache;
|
||||
using Services.Manager;
|
||||
using UI.Controllers;
|
||||
using System.Linq;
|
||||
using Services.Extensions;
|
||||
using Newtonsoft.Json;
|
||||
using Services.Tool;
|
||||
using Models.ModelItems;
|
||||
using Models;
|
||||
using UH_CENTER;
|
||||
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
|
||||
public HomeController()
|
||||
{
|
||||
base.ViewBag.Select = 0;
|
||||
}
|
||||
#region <EFBFBD>û<EFBFBD><EFBFBD><EFBFBD>Ϣ
|
||||
public ActionResult Index()
|
||||
{
|
||||
try
|
||||
{
|
||||
return View();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
HttpContext.Response.StatusCode = 500;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region <EFBFBD>û<EFBFBD>Ȩ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||
public ActionResult UAuthority(string id)
|
||||
{
|
||||
try
|
||||
{
|
||||
ViewBag.Appversions = CacheHelp.cacheAppversions;
|
||||
//<2F>û<EFBFBD>Ȩ<EFBFBD><C8A8>
|
||||
var info = CacheHelp.cacheSysUserInfo.FirstOrDefault(x => x.Uid.TrimEnd().ToLower() == id.TrimEnd().ToLower());
|
||||
if (info == null)
|
||||
throw new CustomException("<22><><EFBFBD>û<EFBFBD><C3BB><EFBFBD><EFBFBD>Ƿ<EFBFBD><C7B7><EFBFBD><EFBFBD><EFBFBD>~");
|
||||
ViewBag.info = info;
|
||||
ViewBag.HotelList = JsonConvert.SerializeObject(
|
||||
UH_CENTER_Help.Sel_Hotel(info).Select(X=>X.id)
|
||||
);
|
||||
return View();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
HttpContext.Response.StatusCode = 500;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>
|
||||
public ActionResult AddUser()
|
||||
{
|
||||
try
|
||||
{
|
||||
ViewBag.publicYS = (Session["ras"] as Services.Tool.RSA).ToPEM().ToPEM_PKCS8(convertToPublic: true).Replace("\r\n", "")
|
||||
.Replace(Convert.ToChar(10).ToString(), "")
|
||||
.Replace(Convert.ToChar(13).ToString(), "") ?? throw new Exception();
|
||||
return View();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return Content(ex.Message);
|
||||
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
#region <EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>
|
||||
public ActionResult EditUser(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
var userinfo = CacheHelp.cacheSysUserInfo.FirstOrDefault(x => x.Id == id);
|
||||
if (userinfo == null || (Umodel.IsValid <= userinfo.IsValid && Umodel.Id != 1 && Umodel.Uid != userinfo.Uid))
|
||||
throw new CustomException("<22><>Ȩ<EFBFBD><C8A8><EFBFBD>ʣ<EFBFBD>");
|
||||
ViewBag.Uinfo = userinfo;
|
||||
RSA rSA = new RSA(512);
|
||||
base.Session["ras"] = rSA;
|
||||
ViewBag.publicYS = (Session["ras"] as Services.Tool.RSA).ToPEM().ToPEM_PKCS8(convertToPublic: true).Replace("\r\n", "")
|
||||
.Replace(Convert. ToChar(10).ToString(), "")
|
||||
.Replace(Convert.ToChar(13).ToString(), "") ?? throw new Exception();
|
||||
return View();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
HttpContext.Response.StatusCode = 500;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
public ActionResult IndexInfo(string Token = "")
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Token))
|
||||
{
|
||||
string Ip = IPHelper.GetIP();
|
||||
var userinfo = RedisHelper.StringGet<UserInfo>(Token + Ip);
|
||||
RedisHelper.RemoveKey(Token + Ip);
|
||||
}
|
||||
base.ViewBag.Select = -1;
|
||||
base.ViewBag.LogData = SqlSugarBase.Db.Ado.SqlQuery<DbLog>("SELECT * FROM DbLog ORDER BY ID DESC limit 1, 50").ToList();
|
||||
//CacheHelp.Removesys(CacheHelp.syskey.sysDbLogListKey);
|
||||
//ViewBag.LogData =
|
||||
//CacheHelp.cacheDbLogs.OrderByDescending(x => x.Id).Take(50).ToList();
|
||||
return View();
|
||||
}
|
||||
}
|
||||
58
UI/Controllers/HotelController.cs
Normal file
58
UI/Controllers/HotelController.cs
Normal file
@@ -0,0 +1,58 @@
|
||||
using Services.Cache;
|
||||
using Services.Manager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
using Models.ModelItems;
|
||||
using Services.Extensions;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
public class HotelController : BaseController
|
||||
{
|
||||
public HotelController()
|
||||
{
|
||||
base.ViewBag.Select = 3;
|
||||
}
|
||||
// GET: Hotel
|
||||
public ActionResult Index(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
HotelGroups hotelGroups = CacheHelp.cacheHoteldGroups.FirstOrDefault(x=>x.Id == id);
|
||||
if(hotelGroups == null)
|
||||
throw new CustomException("无酒店组信息!");
|
||||
ViewBag.SelHoteldGroup = id;
|
||||
var data = CacheHelp.cacheHoteldGroups.Where(x => x.ParentId == id).ToList();
|
||||
data.Insert(0,hotelGroups);
|
||||
ViewBag.DataGroups = JsonConvert.SerializeObject(data);
|
||||
ViewBag.Data = JsonConvert.SerializeObject(
|
||||
CacheHelp.cacheHotels.Where(x=> data.FirstOrDefault(y=>y.Id == x.GroupId)!=null ).GroupBy(x=>x.GroupId).ToList());
|
||||
ViewBag.HoteldGroupName = hotelGroups.Name;
|
||||
return View();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
HttpContext.Response.StatusCode = 500;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
public ActionResult Hotellist()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
[HttpPost]
|
||||
/// <summary>
|
||||
/// 查看酒店 下方人员信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ActionResult HotelInfo()
|
||||
{
|
||||
return Json(HotelServer.FindUserinfo());
|
||||
}
|
||||
}
|
||||
}
|
||||
558
UI/Controllers/ImgServerController.cs
Normal file
558
UI/Controllers/ImgServerController.cs
Normal file
@@ -0,0 +1,558 @@
|
||||
using Models;
|
||||
using Services.Manager;
|
||||
using Services.Tool;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Security;
|
||||
using System.Security.Cryptography.X509Certificates;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Hosting;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
public class ImgServerController : Controller
|
||||
{
|
||||
public JsonResult UpdateIcon()
|
||||
{
|
||||
try
|
||||
{
|
||||
string TimePath = HostingEnvironment.MapPath("~/Upload/APPicon/");//保存路径
|
||||
var oFile = Request.Files[0];//获得上传的文件
|
||||
if (oFile.ContentType.IndexOf("image/") < 0)
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
code = 1,//0表示成功
|
||||
msg = "文件格式不对~",//
|
||||
});
|
||||
}
|
||||
string ext = oFile.ContentType.Replace("image/", ".");
|
||||
string fullPath = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss fff") + ext;
|
||||
if (!Directory.Exists(TimePath))//判断文件夹是否存在
|
||||
{
|
||||
Directory.CreateDirectory(TimePath);//不存在则创建文件夹
|
||||
}
|
||||
oFile.SaveAs(TimePath + fullPath);
|
||||
string ftpURLTwo = "uts-svr2.qicp.net:50/uts_Manager/am_FTP/APPicon/";
|
||||
string filename = FtpUpload(TimePath + fullPath, ftpURLTwo);
|
||||
return Json(filename);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return Json("");
|
||||
}
|
||||
}
|
||||
public JsonResult Update()
|
||||
{
|
||||
try
|
||||
{
|
||||
string TimePath = HostingEnvironment.MapPath("~/Upload/Image/");//保存路径
|
||||
|
||||
TimePath += DateTime.Now.ToString("yyyy-MM-dd");
|
||||
TimePath += "\\";
|
||||
var oFile = Request.Files[0];//获得上传的文件
|
||||
//获取后缀名
|
||||
if (oFile.ContentType.IndexOf("image/") < 0)
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
code = 1,//0表示成功
|
||||
msg = "文件格式不对~",//
|
||||
});
|
||||
}
|
||||
string ext = oFile.ContentType.Replace("image/", ".");
|
||||
|
||||
//string fullPath = Guid.NewGuid().ToString() + ext;
|
||||
string fullPath = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss fff") + ext;
|
||||
if (!Directory.Exists(TimePath))//判断文件夹是否存在
|
||||
{
|
||||
Directory.CreateDirectory(TimePath);//不存在则创建文件夹
|
||||
}
|
||||
oFile.SaveAs(TimePath + fullPath);
|
||||
//int c = oFile.ContentLength;//字节长度
|
||||
FileInfo file = new FileInfo(TimePath + fullPath);
|
||||
string imgUrl = TimePath + fullPath;
|
||||
string UPUrl = HostingEnvironment.MapPath("~/Upload/Imgs/");//压缩后保存路径
|
||||
string littleUrl = HostingEnvironment.MapPath("~/Upload/Img/");//压缩后保存路径
|
||||
if (!Directory.Exists(UPUrl))//判断文件夹是否存在
|
||||
{
|
||||
Directory.CreateDirectory(UPUrl);//不存在则创建文件夹
|
||||
}
|
||||
string ur;//传递URL给前端
|
||||
long size;
|
||||
//缩略图
|
||||
string urltwo = MakeThumbnail(imgUrl, littleUrl, 85, 85, "Cut");
|
||||
|
||||
if (CompressImage(imgUrl, UPUrl + file.Name))
|
||||
{
|
||||
using (FileStream fs = new FileStream(UPUrl + file.Name, FileMode.OpenOrCreate, FileAccess.Read))
|
||||
{
|
||||
size = fs.Length;
|
||||
//异步压缩图
|
||||
string ftpURL = "uts-svr2.qicp.net:50/uts_Manager/am_FTP/Image";
|
||||
ur = FtpUpload(UPUrl + file.Name, ftpURL);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
string ftpURLTwo = "uts-svr2.qicp.net:50/uts_Manager/am_FTP/Img";
|
||||
ur = FtpUpload(urltwo, ftpURLTwo);
|
||||
//删除本地文件
|
||||
string issave = ConfigHelper.GetConfigString("IsSaveImg") ?? "0";
|
||||
if (issave != "0")
|
||||
{
|
||||
System.IO.File.Delete(urltwo);
|
||||
System.IO.File.Delete(UPUrl + fullPath);
|
||||
}
|
||||
var data1 = new
|
||||
{
|
||||
src = ur,
|
||||
sizes = size
|
||||
|
||||
};
|
||||
var Person = new
|
||||
{
|
||||
code = 0,//0表示成功
|
||||
msg = "",//
|
||||
data = data1
|
||||
};
|
||||
return Json(Person);//
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(e, this.GetType().Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 图片上传到ftp
|
||||
/// </summary>
|
||||
/// <param name="filename">源文件路径</param>
|
||||
public string FtpUpload(string filename, string ftpServerIP)
|
||||
{
|
||||
string ftpUserID = "uts_manager";//ftp账号
|
||||
string ftpPassword = "uts_Inhaos@all";//ftp密码
|
||||
FileInfo fileInf = new FileInfo(filename);
|
||||
FtpWebRequest reqFTP;
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
new RemoteCertificateValidationCallback(ValidateServerCertificate);
|
||||
try
|
||||
{
|
||||
// 根据uri创建FtpWebRequest对象
|
||||
reqFTP = (FtpWebRequest)FtpWebRequest.Create(new Uri("ftp://" + ftpServerIP + "/" + fileInf.Name));
|
||||
// ftp用户名和密码
|
||||
reqFTP.Credentials = new NetworkCredential(ftpUserID, ftpPassword);
|
||||
// 默认为true,连接不会被关闭
|
||||
// 在一个命令之后被执行
|
||||
reqFTP.KeepAlive = true;
|
||||
//如果要连接的 FTP 服务器要求凭据并支持安全套接字层 (SSL),则应将 EnableSsl 设置为 true。如果不写会报出421错误(服务不可用)
|
||||
reqFTP.EnableSsl = true;
|
||||
// 指定执行什么命令
|
||||
reqFTP.Method = WebRequestMethods.Ftp.UploadFile;
|
||||
// 指定数据传输类型
|
||||
reqFTP.UseBinary = true;
|
||||
// 上传文件时通知服务器文件的大小
|
||||
reqFTP.ContentLength = fileInf.Length;
|
||||
// 缓冲大小设置为 10kb
|
||||
int buffLength = 10480;
|
||||
byte[] buff = new byte[buffLength];
|
||||
int contentLen;
|
||||
// 打开一个文件流 (System.IO.FileStream) 去读上传的文件
|
||||
FileStream fs = fileInf.OpenRead();
|
||||
try
|
||||
{
|
||||
// 把上传的文件写入流
|
||||
Stream strm = reqFTP.GetRequestStream();
|
||||
// 每次读文件流的buffLength kb
|
||||
contentLen = fs.Read(buff, 0, buffLength);
|
||||
// 流内容没有结束
|
||||
while (contentLen != 0)
|
||||
{
|
||||
// 把内容从file stream 写入 upload stream
|
||||
strm.Write(buff, 0, contentLen);
|
||||
contentLen = fs.Read(buff, 0, buffLength);
|
||||
}
|
||||
// 关闭两个流
|
||||
strm.Close();
|
||||
fs.Close();
|
||||
return fileInf.Name ;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Response.Write("Upload Error:" + ex.Message);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Response.Write("Upload Error:" + e.Message);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 从ftp获取图片
|
||||
/// </summary>
|
||||
/// <param name="url">路径</param>
|
||||
/// <returns></returns>
|
||||
public ActionResult FileImage(string url, string ftp = "")
|
||||
{
|
||||
//Logs.WriteLog("222获取图片开始"+DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"));
|
||||
if (ftp != "")
|
||||
{
|
||||
if (ftp == "app")
|
||||
url = "ftp://uts-svr2.qicp.net:50/uts_Manager/am_FTP/APPicon/" + url;
|
||||
else
|
||||
url = "ftp://uts-svr2.qicp.net:50/uts_Manager/am_FTP/Image/" + url;
|
||||
}
|
||||
else
|
||||
url = "ftp://uts-svr2.qicp.net:50/uts_Manager/am_FTP/Img/" + url;
|
||||
FtpWebRequest ftpWeb;
|
||||
try
|
||||
{
|
||||
ServicePointManager.ServerCertificateValidationCallback =
|
||||
new RemoteCertificateValidationCallback(ValidateServerCertificate);
|
||||
try
|
||||
{
|
||||
ftpWeb = (FtpWebRequest)FtpWebRequest.Create(url);//创建ftp连接
|
||||
ftpWeb.Credentials = new NetworkCredential("uts_manager", "uts_Inhaos@all");//账号,密码
|
||||
ftpWeb.KeepAlive = false;
|
||||
ftpWeb.Timeout = 2000;
|
||||
ftpWeb.ReadWriteTimeout = 2000;
|
||||
ftpWeb.EnableSsl = true;
|
||||
ftpWeb.Method = WebRequestMethods.Ftp.DownloadFile;
|
||||
ftpWeb.UseBinary = true;
|
||||
|
||||
ftpWeb.UsePassive = true;
|
||||
//AUTS.Services.Manager.Logs.WriteLog("获取图片数据开始" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"));
|
||||
WebResponse ftpResponse = (FtpWebResponse)ftpWeb.GetResponse();
|
||||
//AUTS.Services.Manager.Logs.WriteLog("获取图片数据结束" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff"));
|
||||
Stream ftpStream = ftpResponse.GetResponseStream();//获取图片流
|
||||
|
||||
MemoryStream outstream = new MemoryStream();//转成MS流
|
||||
int bufferLen = 4096;//缓冲区
|
||||
byte[] buffer = new byte[bufferLen];
|
||||
int count = 0;
|
||||
while ((count = ftpStream.Read(buffer, 0, bufferLen)) > 0)
|
||||
{
|
||||
outstream.Write(buffer, 0, count);
|
||||
}
|
||||
|
||||
//var img = outstream.ToArray();
|
||||
//Logs.WriteLog(img.ToString());
|
||||
var img = outstream.ToArray();
|
||||
|
||||
ftpResponse.Close();
|
||||
ftpStream.Close();
|
||||
outstream.Close();
|
||||
return File(img, "image/jpeg");//转成图片格式
|
||||
//return new Task<byte[]>(() => outstream.ToArray());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(e, this.GetType().Name);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex, this.GetType().Name);
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// 无证书时跳过不报错
|
||||
/// </summary>
|
||||
/// <param name="sender"></param>
|
||||
/// <param name="certificate"></param>
|
||||
/// <param name="chain"></param>
|
||||
/// <param name="sslPolicyErrors"></param>
|
||||
/// <returns></returns>
|
||||
public static bool ValidateServerCertificate
|
||||
(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
/// <summary>
|
||||
/// 压缩图片至n Kb以下
|
||||
/// </summary>
|
||||
/// <param name="img">图片</param>
|
||||
/// <param name="format">图片格式</param>
|
||||
/// <param name="targetLen">压缩后大小</param>
|
||||
/// <param name="srcLen">原始大小</param>
|
||||
/// <returns>压缩后的图片内存流</returns>
|
||||
|
||||
public static MemoryStream Zip(Image img, ImageFormat format, long targetLen, long srcLen = 0)
|
||||
{
|
||||
|
||||
//设置允许大小偏差幅度 默认10kb
|
||||
const long nearlyLen = 10240;
|
||||
|
||||
//返回内存流 如果参数中原图大小没有传递 则使用内存流读取
|
||||
var ms = new MemoryStream();
|
||||
if (0 == srcLen)
|
||||
{
|
||||
img.Save(ms, format);
|
||||
srcLen = ms.Length;
|
||||
}
|
||||
//单位 由Kb转为byte 若目标大小高于原图大小,则满足条件退出
|
||||
targetLen *= 1024;
|
||||
if (targetLen >= srcLen)
|
||||
{
|
||||
ms.SetLength(0);
|
||||
ms.Position = 0;
|
||||
img.Save(ms, format);
|
||||
return ms;
|
||||
}
|
||||
//获取目标大小最低值
|
||||
var exitLen = targetLen - nearlyLen;
|
||||
//初始化质量压缩参数 图像 内存流等
|
||||
var quality = (long)Math.Floor(100.00 * targetLen / srcLen);
|
||||
var parms = new EncoderParameters(1);
|
||||
//获取编码器信息
|
||||
ImageCodecInfo formatInfo = null;
|
||||
var encoders = ImageCodecInfo.GetImageEncoders();
|
||||
foreach (ImageCodecInfo icf in encoders)
|
||||
{
|
||||
if (icf.FormatID == format.Guid)
|
||||
{
|
||||
formatInfo = icf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
//使用二分法进行查找 最接近的质量参数
|
||||
long startQuality = quality;
|
||||
long endQuality = 100;
|
||||
quality = (startQuality + endQuality) / 2;
|
||||
while (true)
|
||||
{
|
||||
//设置质量
|
||||
parms.Param[0] = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, quality);
|
||||
//清空内存流 然后保存图片
|
||||
ms.SetLength(0);
|
||||
ms.Position = 0;
|
||||
|
||||
}
|
||||
}
|
||||
#region 缩略图
|
||||
/// <summary>
|
||||
/// 生成缩略图
|
||||
/// </summary>
|
||||
/// <param name="originalImagePath">源图路径(物理路径)</param>
|
||||
/// <param name="thumbnailPath">缩略图路径(物理路径)</param>
|
||||
/// <param name="width">缩略图宽度</param>
|
||||
/// <param name="height">缩略图高度</param>
|
||||
/// <param name="mode">生成缩略图的方式</param>
|
||||
public string MakeThumbnail(string originalImagePath, string thumbnailPath, int width, int height, string mode)
|
||||
{
|
||||
ReturnResult result = new ReturnResult();
|
||||
FileInfo info = new FileInfo(originalImagePath);
|
||||
Image originalImage = Image.FromFile(originalImagePath);
|
||||
int towidth = width;
|
||||
int toheight = height;
|
||||
int x = 0;
|
||||
int y = 0;
|
||||
int ow = originalImage.Width;
|
||||
int oh = originalImage.Height;
|
||||
switch (mode)
|
||||
{
|
||||
case "HW"://指定高宽缩放(可能变形)
|
||||
break;
|
||||
case "W"://指定宽,高按比例
|
||||
toheight = originalImage.Height * width / originalImage.Width;
|
||||
break;
|
||||
case "H"://指定高,宽按比例
|
||||
towidth = originalImage.Width * height / originalImage.Height;
|
||||
break;
|
||||
case "Cut"://指定高宽裁减(不变形)
|
||||
if ((double)originalImage.Width / (double)originalImage.Height > (double)towidth / (double)toheight)
|
||||
{
|
||||
oh = originalImage.Height;
|
||||
ow = originalImage.Height * towidth / toheight;
|
||||
y = 0;
|
||||
x = (originalImage.Width - ow) / 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
ow = originalImage.Width;
|
||||
oh = originalImage.Width * height / towidth;
|
||||
x = 0;
|
||||
y = (originalImage.Height - oh) / 2;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
//新建一个bmp图片
|
||||
Image bitmap = new System.Drawing.Bitmap(towidth, toheight);
|
||||
//新建一个画板
|
||||
Graphics g = System.Drawing.Graphics.FromImage(bitmap);
|
||||
//设置高质量插值法
|
||||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.High;
|
||||
//设置高质量,低速度呈现平滑程度
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
//清空画布并以透明背景色填充
|
||||
g.Clear(Color.Transparent);
|
||||
//在指定位置并且按指定大小绘制原图片的指定部分
|
||||
g.DrawImage(originalImage, new Rectangle(0, 0, towidth, toheight),
|
||||
new Rectangle(x, y, ow, oh),
|
||||
GraphicsUnit.Pixel);
|
||||
try
|
||||
{
|
||||
|
||||
if (!Directory.Exists(thumbnailPath))
|
||||
{
|
||||
Directory.CreateDirectory(thumbnailPath);
|
||||
}
|
||||
//以jpg格式保存缩略图
|
||||
bitmap.Save(thumbnailPath + info.Name);
|
||||
return thumbnailPath + info.Name;
|
||||
//return thumbnailPath + info.Name;
|
||||
}
|
||||
catch (System.Exception e)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(e, this.GetType().Name);
|
||||
return null;
|
||||
}
|
||||
finally
|
||||
{
|
||||
originalImage.Dispose();
|
||||
bitmap.Dispose();
|
||||
g.Dispose();
|
||||
}
|
||||
|
||||
}
|
||||
#endregion
|
||||
/// <summary>
|
||||
/// 无损压缩图片
|
||||
/// </summary>
|
||||
/// <param name="originalFileFullName">原图片地址</param>
|
||||
/// <param name="afterConversionFileFullName">压缩后保存图片地址</param>
|
||||
/// <param name="flag">压缩质量(数字越小压缩率越高)1-100</param>
|
||||
/// <param name="size">压缩后图片的最大大小</param>
|
||||
/// <param name="isFirst">是否是第一次调用</param>
|
||||
/// <returns></returns>
|
||||
public static bool CompressImage(string originalFileFullName, string afterConversionFileFullName, int flag = 90, int size = 100, bool isFirst = true)
|
||||
{
|
||||
Image iSource = Image.FromFile(originalFileFullName);
|
||||
ImageFormat tFormat = iSource.RawFormat;
|
||||
//如果是第一次调用,原始图像的大小小于要压缩的大小,则直接复制文件,并且返回true
|
||||
FileInfo firstFileInfo = new FileInfo(originalFileFullName);
|
||||
if (isFirst == true && firstFileInfo.Length < size * 1024)
|
||||
{
|
||||
firstFileInfo.CopyTo(afterConversionFileFullName);
|
||||
return true;
|
||||
}
|
||||
|
||||
int dHeight = iSource.Height / 2;
|
||||
int dWidth = iSource.Width / 2;
|
||||
int sW = 0, sH = 0;
|
||||
//按比例缩放
|
||||
Size tem_size = new Size(iSource.Width, iSource.Height);
|
||||
if (tem_size.Width > dHeight || tem_size.Width > dWidth)
|
||||
{
|
||||
if ((tem_size.Width * dHeight) > (tem_size.Width * dWidth))
|
||||
{
|
||||
sW = dWidth;
|
||||
sH = (dWidth * tem_size.Height) / tem_size.Width;
|
||||
}
|
||||
else
|
||||
{
|
||||
sH = dHeight;
|
||||
sW = (tem_size.Width * dHeight) / tem_size.Height;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sW = tem_size.Width;
|
||||
sH = tem_size.Height;
|
||||
}
|
||||
|
||||
Bitmap ob = new Bitmap(dWidth, dHeight);
|
||||
Graphics g = Graphics.FromImage(ob);
|
||||
|
||||
g.Clear(Color.WhiteSmoke);
|
||||
g.CompositingQuality = System.Drawing.Drawing2D.CompositingQuality.HighQuality;
|
||||
g.SmoothingMode = System.Drawing.Drawing2D.SmoothingMode.HighQuality;
|
||||
g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
|
||||
|
||||
g.DrawImage(iSource, new Rectangle((dWidth - sW) / 2, (dHeight - sH) / 2, sW, sH), 0, 0, iSource.Width, iSource.Height, GraphicsUnit.Pixel);
|
||||
|
||||
g.Dispose();
|
||||
|
||||
//以下代码为保存图片时,设置压缩质量
|
||||
EncoderParameters ep = new EncoderParameters();
|
||||
long[] qy = new long[1];
|
||||
qy[0] = flag;//设置压缩的比例1-100
|
||||
EncoderParameter eParam = new EncoderParameter(System.Drawing.Imaging.Encoder.Quality, qy);
|
||||
ep.Param[0] = eParam;
|
||||
|
||||
try
|
||||
{
|
||||
ImageCodecInfo[] arrayICI = ImageCodecInfo.GetImageEncoders();
|
||||
ImageCodecInfo jpegICIinfo = null;
|
||||
for (int x = 0; x < arrayICI.Length; x++)
|
||||
{
|
||||
if (arrayICI[x].FormatDescription.Equals("JPEG"))
|
||||
{
|
||||
jpegICIinfo = arrayICI[x];
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (jpegICIinfo != null)
|
||||
{
|
||||
ob.Save(afterConversionFileFullName, jpegICIinfo, ep);
|
||||
FileInfo fi = new FileInfo(afterConversionFileFullName);
|
||||
if (fi.Length > 1024 * size)
|
||||
{
|
||||
var str = afterConversionFileFullName.Split('.').ToList();
|
||||
var path = str.LastOrDefault();
|
||||
path = HostingEnvironment.MapPath($"~/Upload/Image/{new Random().Next()}{DateTime.Now.ToString("yyyy_MM_dd_HH_mm_ss")}.{path}");
|
||||
ob.Save(path, jpegICIinfo, ep);
|
||||
//flag = flag - 10;
|
||||
return CompressImage(path, afterConversionFileFullName, flag, size, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
ob.Save(afterConversionFileFullName, jpegICIinfo, ep);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ob.Save(afterConversionFileFullName, tFormat);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
catch(Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
return false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
iSource.Dispose();
|
||||
ob.Dispose();
|
||||
//不是第一次就删除源文件
|
||||
if (!isFirst)
|
||||
{
|
||||
System.IO.File.Delete(originalFileFullName);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
21
UI/Controllers/LogController.cs
Normal file
21
UI/Controllers/LogController.cs
Normal file
@@ -0,0 +1,21 @@
|
||||
using Services.Cache;
|
||||
using Services.Manager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
public class LogController : BaseController
|
||||
{
|
||||
public ActionResult Index()
|
||||
{
|
||||
//CacheHelp.Removesys(CacheHelp.syskey.sysDbLogListKey);
|
||||
ViewBag.Select = 4;
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
130
UI/Controllers/LoginController.cs
Normal file
130
UI/Controllers/LoginController.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.Security;
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using Models.View;
|
||||
using Services.Api;
|
||||
using Services.Cache;
|
||||
using Services.Extensions;
|
||||
using Services.Manager;
|
||||
using Services.Tool;
|
||||
using Newtonsoft.Json;
|
||||
using static Services.Tool.HttpRequestHelp;
|
||||
|
||||
public class LoginController : Controller
|
||||
{
|
||||
public ActionResult Index(string Token = "")
|
||||
{
|
||||
|
||||
//SqlSugarBase.Db.Queryable<View_AppAutho>().ToList();
|
||||
//HotelServer.FindGSQX(45);
|
||||
Logs.WriteLog("Token_________" + Token);
|
||||
|
||||
try
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Token))
|
||||
{
|
||||
string Ip = IPHelper.GetIP();
|
||||
var userinfo = RedisHelper.StringGet<UserInfo>(Token);
|
||||
RedisHelper.RemoveKey(Token);
|
||||
if (userinfo != default(UserInfo)) {
|
||||
ReturnResult returnResult = new ReturnResult();
|
||||
DL(ref returnResult, userinfo.Uid, userinfo.Pwd,1);
|
||||
if(returnResult.Status == 200)
|
||||
{
|
||||
return Redirect("/");
|
||||
}
|
||||
}
|
||||
}
|
||||
View_UserInfo view_UserInfo = UserLoginHelper.CurrentUser();
|
||||
if (view_UserInfo != null)
|
||||
{
|
||||
Logs.WriteLog("<22><>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>"+view_UserInfo.Uid);
|
||||
base.Response.Redirect("/");
|
||||
//return View();
|
||||
}
|
||||
RSA rSA = new RSA(512);
|
||||
base.ViewBag.publicYS = rSA.ToPEM().ToPEM_PKCS8(convertToPublic: true).Replace("\r\n", "")
|
||||
.Replace(Convert.ToChar(10).ToString(), "")
|
||||
.Replace(Convert.ToChar(13).ToString(), "");
|
||||
base.Session["ras"] = rSA;
|
||||
return View();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.WriteLog("<22><>¼<EFBFBD><C2BC>ҳ<EFBFBD><D2B3><EFBFBD><EFBFBD>"+ex.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
public ActionResult Logout()
|
||||
{
|
||||
UserLoginHelper.UserLogout();
|
||||
Response.Redirect("/Login/Index");
|
||||
return null;
|
||||
}
|
||||
[HttpPost]
|
||||
public ActionResult AuthorityLogin(string Uid, string Pwd)
|
||||
{
|
||||
try
|
||||
{
|
||||
Logs.WriteLog("<22><>¼<EFBFBD>ɹ<EFBFBD>");
|
||||
ReturnResult returnResult = new ReturnResult();
|
||||
DL(ref returnResult, Uid, Pwd);
|
||||
return Json(returnResult);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logs.WriteLog(ex.ToString());
|
||||
return null;
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
private void DL(ref ReturnResult returnResult, string Uid, string Pwd,int TYPE=0) {
|
||||
DbLog log = new DbLog() { Uid = Uid, Ip = IPHelper.GetIP(), Client = HttpContext.Request.UserAgent };
|
||||
try
|
||||
{
|
||||
View_UserInfo userLoginBy = UserLoginHelper.GetUserLoginBy(Uid, Pwd, TYPE);
|
||||
ViewBag.ToNone = userLoginBy.CreatedBy;
|
||||
returnResult.Status = 200;
|
||||
var session = Session;
|
||||
Task.Run(() =>
|
||||
{
|
||||
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (loc.status == 0)
|
||||
{
|
||||
if (loc.data.Count > 0)
|
||||
{
|
||||
log.location = loc.data[0].location;
|
||||
}
|
||||
}
|
||||
session["log"] = log;
|
||||
DbLogServer.WriteDbLog((TYPE == 0 ? "" : "ͨ<><CDA8><EFBFBD><EFBFBD>ת")+$"<22><>¼<EFBFBD><C2BC>ϵͳ~", 0, log);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (loc.status == 0)
|
||||
{
|
||||
if (loc.data.Count > 0)
|
||||
{
|
||||
log.location = loc.data[0].location;
|
||||
}
|
||||
}
|
||||
DbLogServer.WriteDbLog($"<22><>¼ϵͳʧ<CDB3><CAA7>~", 0, log);
|
||||
});
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
returnResult.Message = ex.Message;
|
||||
returnResult.Status = 500;
|
||||
}
|
||||
Logs.WriteTimingUDPLog(JsonConvert.SerializeObject(returnResult));
|
||||
}
|
||||
}
|
||||
39
UI/Controllers/OrgController.cs
Normal file
39
UI/Controllers/OrgController.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Newtonsoft.Json;
|
||||
using Services.Cache;
|
||||
using Services.Manager;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
public class OrgController : BaseController
|
||||
{
|
||||
public OrgController()
|
||||
{
|
||||
base.ViewBag.Select = 1;
|
||||
}
|
||||
public ActionResult Index(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
ViewBag.SelectOrg = id;
|
||||
var org = CacheHelp.cacheSysOrganization.FirstOrDefault(x => x.Id == id && x.IsValid == 0);
|
||||
if (org == null)
|
||||
throw new Exception();
|
||||
ViewBag.OrgName = org.OrganizationName;
|
||||
ViewBag.HotelList = JsonConvert.SerializeObject(SyncHotelServer.FindGroup(org));
|
||||
return View();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
HttpContext.Response.StatusCode = 500;
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
546
UI/Controllers/OtherApiController.cs
Normal file
546
UI/Controllers/OtherApiController.cs
Normal file
@@ -0,0 +1,546 @@
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using Services.Api;
|
||||
using Services.Manager;
|
||||
using Services.Tool;
|
||||
using StackExchange.Redis;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web;
|
||||
using System.Web.Mvc;
|
||||
using System.Web.UI.WebControls;
|
||||
using static Services.Tool.HttpRequestHelp;
|
||||
using static System.Runtime.CompilerServices.RuntimeHelpers;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
//给第三方调用的Api
|
||||
public class OtherApiController : Controller
|
||||
{
|
||||
|
||||
[HttpPost]
|
||||
[Route("OTApi/SynAuthority")]
|
||||
public ActionResult Synchronization()
|
||||
{
|
||||
ApiController api = new ApiController();
|
||||
return api.Clear2();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 登录
|
||||
/// </summary>
|
||||
/// <param name="Uid"></param>
|
||||
/// <param name="Pwd"></param>
|
||||
/// <param name="appid"></param>
|
||||
/// <param name="Ip"></param>
|
||||
/// <param name="moreLogin">是否多点登录</param>
|
||||
/// <param name="UserAgent"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("OTApi/Login")]
|
||||
public ActionResult Index(string Uid, string Pwd, int appid, string Ip = "", bool moreLogin = false, string UserAgent = "")
|
||||
{
|
||||
var resdata = new ReturnResult<dynamic>();
|
||||
try
|
||||
{
|
||||
Ip = Ip == "" ? IPHelper.GetIP() : Ip;
|
||||
var res = OTApi.GetUserLoginByApi(Uid, Pwd, appid);
|
||||
DbLog log = new DbLog() { Uid = Uid, Ip = Ip, Client = UserAgent == "" ? HttpContext.Request.UserAgent : UserAgent };
|
||||
var Message = res.Message;
|
||||
Task.Run(() =>
|
||||
{
|
||||
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (loc != null && loc.status == 0)
|
||||
{
|
||||
if (loc.data.Count > 0)
|
||||
{
|
||||
log.location = loc.data[0].location;
|
||||
}
|
||||
}
|
||||
DbLogServer.WriteDbLog($"{Uid}请求应用 {Message[3]}({appid}) 授权" + (res.Status == 200 ? "请求成功~" : "请求失败~"), 0, log);
|
||||
if (res.Status == 200)
|
||||
DBlog.WirtDB(Message[2], Message[0], appid);
|
||||
res.Message = "请求成功~";
|
||||
});
|
||||
resdata.Status = res.Status;
|
||||
if (res.Status == 200)
|
||||
{
|
||||
var token = (Uid + Pwd + DateTime.Now);
|
||||
var md5 = new MD5CryptoServiceProvider();
|
||||
token = (BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(token)), 4, 8)).Replace("-", "");
|
||||
if (moreLogin == true)
|
||||
{
|
||||
RedisHelper.StringSet(token, new UserInfo() { Pwd = Pwd, Uid = Uid }, TimeSpan.FromMinutes(20));
|
||||
}
|
||||
resdata.Data = new
|
||||
{
|
||||
Userinfo = new
|
||||
{
|
||||
Uid = Uid,
|
||||
HeadImg = Message[1]
|
||||
},
|
||||
HotelData = res.Data,
|
||||
Token = moreLogin ? token : string.Empty
|
||||
};
|
||||
resdata.Message = "请求成功~";
|
||||
}
|
||||
else
|
||||
resdata.Message = res.Message;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resdata.Data = "";
|
||||
resdata.Status = 500;
|
||||
resdata.Message = ex.Message;
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
return Json(resdata);
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("OTApi/Apps")]
|
||||
public ActionResult Apps(string Uid, int appid = 0, string Ip = "", string UserAgent = "")
|
||||
{
|
||||
var resdata = new ReturnResult<dynamic>();
|
||||
var app = new ApplicationDomain() { AppName = "全部", Id = appid };
|
||||
if (appid != 0)
|
||||
{
|
||||
app = Services.Cache.CacheHelp.cacheSysApp.FirstOrDefault(x => x.Id == appid);
|
||||
}
|
||||
try
|
||||
{
|
||||
DbLog log = new DbLog() { Uid = Uid, Ip = Ip == "" ? IPHelper.GetIP() : Ip, Client = UserAgent == "" ? HttpContext.Request.UserAgent : UserAgent };
|
||||
var user = Services.Cache.CacheHelp.cacheSysUserInfo.FirstOrDefault(x => x.Uid == Uid);
|
||||
if (user == null || app == null)
|
||||
{
|
||||
new ApplicationDomain() { AppName = "全部", Id = appid };
|
||||
resdata.Status = 100;
|
||||
resdata.Message = "用户或app不存在~";
|
||||
resdata.Data = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
//返回 查询的app 正常的权限
|
||||
resdata.Data = AppServer.GetAppInfo(appid, 0, 1, false);
|
||||
resdata.Status = 200;
|
||||
}
|
||||
Task.Run(() =>
|
||||
{
|
||||
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (loc.status == 0)
|
||||
{
|
||||
if (loc.data.Count > 0)
|
||||
{
|
||||
log.location = loc.data[0].location;
|
||||
}
|
||||
}
|
||||
DbLogServer.WriteDbLog($"{Uid}查询 {app.AppName} App信息 {(resdata.Status == 200 ? "成功" : "失败")}", 0, log);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resdata.Status = 500;
|
||||
resdata.Data = "";
|
||||
resdata.Message = ex.Message;
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
return Json(resdata);
|
||||
}
|
||||
/// <summary>
|
||||
/// 全局登录 退出登录 通过链接点入无法登录
|
||||
/// </summary>
|
||||
/// <param name="Token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("OTApi/OutLogin")]
|
||||
public ActionResult OutLogin(string Token, string Ip, bool IsNew = false)
|
||||
{
|
||||
var resdata = new ReturnResult<dynamic>();
|
||||
try
|
||||
{
|
||||
var userinfo = RedisHelper.StringGet<UserInfo>(Token);
|
||||
if (IsNew)
|
||||
{
|
||||
Ip = Ip == "" ? IPHelper.GetIP() : Ip;
|
||||
if (userinfo == default(UserInfo))
|
||||
{
|
||||
resdata.Status = 100;
|
||||
resdata.Data = "";
|
||||
return Json(resdata);
|
||||
}
|
||||
var token = (userinfo.Uid + userinfo.Pwd + DateTime.Now);
|
||||
var md5 = new MD5CryptoServiceProvider();
|
||||
token = (BitConverter.ToString(md5.ComputeHash(Encoding.Default.GetBytes(token)), 4, 8)).Replace("-", "");
|
||||
RedisHelper.StringSet(token, userinfo);
|
||||
resdata.Data = new { Token = token };
|
||||
resdata.Status = 200;
|
||||
}
|
||||
RedisHelper.StringSet(Token, userinfo, TimeSpan.FromSeconds(10));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resdata.Data = "";
|
||||
resdata.Status = 500;
|
||||
resdata.Message = ex.Message;
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
return Json(resdata);
|
||||
}
|
||||
/// <summary>
|
||||
/// 全局登录 登录 通过链接点入登录 返回用户信息
|
||||
/// </summary>
|
||||
/// <param name="Token"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("OTApi/MoreLogin")]
|
||||
public ActionResult MoreLogin(string Token, int appid, string Ip = "", string UserAgent = "", bool IsData = true)
|
||||
{
|
||||
var resdata = new ReturnResult<dynamic>();
|
||||
try
|
||||
{
|
||||
Logs.WriteTimingUDPLog($"传入token {Token}");
|
||||
Ip = Ip == "" ? IPHelper.GetIP() : Ip;
|
||||
var userinfo = RedisHelper.StringGet<UserInfo>(Token);
|
||||
RedisHelper.RemoveKey(Token);
|
||||
if (userinfo == default(UserInfo))
|
||||
{
|
||||
if (IsData == false)
|
||||
{
|
||||
resdata.Status = 200;
|
||||
resdata.Message = "清除成功~";
|
||||
return Json(resdata);
|
||||
}
|
||||
resdata.Status = 100;
|
||||
resdata.Message = "无效凭证~";
|
||||
return Json(resdata);
|
||||
}
|
||||
var res = OTApi.GetUserLoginByApi(userinfo.Uid, userinfo.Pwd, appid);
|
||||
DbLog log = new DbLog() { Uid = userinfo.Uid, Ip = Ip == "" ? IPHelper.GetIP() : Ip, Client = UserAgent == "" ? HttpContext.Request.UserAgent : UserAgent };
|
||||
var Message = res.Message;
|
||||
Task.Run(() =>
|
||||
{
|
||||
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (loc.status == 0)
|
||||
{
|
||||
if (loc.data.Count > 0)
|
||||
{
|
||||
log.location = loc.data[0].location;
|
||||
}
|
||||
}
|
||||
DbLogServer.WriteDbLog($"{userinfo.Uid}请求应用 {Message[3]}({appid}) 授权" + (res.Status == 200 ? "请求成功~" : "请求失败~"), 0, log);
|
||||
if (res.Status == 200)
|
||||
DBlog.WirtDB(Message[2], Message[0], appid);
|
||||
res.Message = "请求成功~";
|
||||
//AppServer.AddDown(appid, 1);
|
||||
});
|
||||
resdata.Status = res.Status;
|
||||
if (res.Status == 200)
|
||||
{
|
||||
resdata.Data = new
|
||||
{
|
||||
Userinfo = new
|
||||
{
|
||||
Uid = userinfo.Uid,
|
||||
HeadImg = Message[1]
|
||||
},
|
||||
HotelData = res.Data
|
||||
};
|
||||
resdata.Message = "请求成功~";
|
||||
}
|
||||
else
|
||||
resdata.Message = res.Message;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resdata.Data = null;
|
||||
resdata.Status = 500;
|
||||
resdata.Message = ex.Message;
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
return Json(resdata);
|
||||
}
|
||||
[HttpPost]
|
||||
#region 下载量统计
|
||||
[Route("OTApi/AppDownSum")]
|
||||
public ActionResult DownSum(int appid = 0, string Token = "", string Ip = "", string UserAgent = "", int sum = 1)
|
||||
{
|
||||
var resdata = new ReturnResult<dynamic>();
|
||||
var app = new ApplicationDomain() { AppName = "全部", Id = appid };
|
||||
if (appid != 0)
|
||||
{
|
||||
app = Services.Cache.CacheHelp.cacheSysApp.FirstOrDefault(x => x.Id == appid);
|
||||
}
|
||||
try
|
||||
{
|
||||
DbLog log = new DbLog() { Ip = Ip == "" ? IPHelper.GetIP() : Ip, Client = UserAgent == "" ? HttpContext.Request.UserAgent : UserAgent };
|
||||
var userinfo = RedisHelper.StringGet<UserInfo>(Token);
|
||||
string Uid = userinfo.Uid;
|
||||
if (userinfo == null)
|
||||
{
|
||||
resdata.Status = 100;
|
||||
resdata.Message = "TOKEN_ERROR~";
|
||||
resdata.Data = string.Empty;
|
||||
Uid = "非法用户";
|
||||
}
|
||||
else
|
||||
{
|
||||
Uid = userinfo.Uid;
|
||||
|
||||
var user = Services.Cache.CacheHelp.cacheSysUserInfo.FirstOrDefault(x => x.Uid == Uid);
|
||||
if (user == null || app == null)
|
||||
{
|
||||
resdata.Status = 100;
|
||||
resdata.Message = "用户或app不存在~";
|
||||
resdata.Data = string.Empty;
|
||||
}
|
||||
else
|
||||
{
|
||||
//返回 查询的app
|
||||
resdata.Data = AppServer.AddDown(appid, sum);
|
||||
resdata.Status = 200;
|
||||
}
|
||||
}
|
||||
log.Uid = Uid;
|
||||
Task.Run(() =>
|
||||
{
|
||||
Data loc = HttpRequestHelp.GetIp($@"https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query={log.Ip}&co=&resource_id=6006&oe=utf8");
|
||||
if (loc.status == 0)
|
||||
{
|
||||
if (loc.data.Count > 0)
|
||||
{
|
||||
log.location = loc.data[0].location;
|
||||
}
|
||||
}
|
||||
DbLogServer.WriteDbLog($"{Uid}点击跳转了 {app.AppName} App统计数量{(resdata.Status == 200 ? "成功" : "失败")}", 0, log);
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
resdata.Status = 500;
|
||||
resdata.Data = "";
|
||||
resdata.Message = ex.Message;
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
return Json(resdata);
|
||||
}
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 同步数据
|
||||
/// </summary>
|
||||
/// <param name="Pwd"></param>
|
||||
/// <param name="stepid"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
[Route("OuterSyncApi/SyncData")]
|
||||
public ActionResult OuterSyncApi(string Pwd, int stepid = 0)
|
||||
{
|
||||
DbLogServer.WriteDbLog($"从巫工数据库同步数据到mysql数据库");
|
||||
|
||||
if (Pwd == "fs%sd")
|
||||
{
|
||||
var res = SyncAllFromOutterDB.SYNC_DATA.SYNC_DATA_ALL(stepid);
|
||||
string erMsg = SyncAllFromOutterDB.GlobalSyncLockTest.recentErrMsg;
|
||||
//return Json(res);
|
||||
if (res)
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
messages = "同步成功",
|
||||
Status = true
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
messages = erMsg,
|
||||
Status = false
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
messages = "同步密码错误",
|
||||
Status = false
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
[HttpPost]
|
||||
[Route("OuterSyncApi/GetRoomTypeAndRoomInfo")]
|
||||
public ActionResult GetRoomTypeAndRoomInfo(string HotelCode)
|
||||
{
|
||||
ReturnInfo ri = new ReturnInfo();
|
||||
try
|
||||
{
|
||||
DbLog dlog = new DbLog
|
||||
{
|
||||
location = "",
|
||||
Ip = "::1",
|
||||
Client = "",
|
||||
CreateTime = DateTime.Now,
|
||||
Uid = "宝镜",
|
||||
Type = 0,
|
||||
Content = "宝镜获取酒店" + HotelCode + "的房型和房间信息"
|
||||
};
|
||||
SqlSugarBase.Db.Insertable(dlog).ExecuteCommand();
|
||||
TBL_HOTEL_BASIC_INFO hotel = SqlSugarBase.RcuDb.Queryable<TBL_HOTEL_BASIC_INFO>().First(it => it.PROJECT_NUMBER == HotelCode && it.IsDel != 1);
|
||||
if (hotel != null)
|
||||
{
|
||||
List<TBL_ROOM_TYPE_LIST> roomList = SqlSugarBase.RcuDb.Queryable<TBL_ROOM_TYPE_LIST>().Where(it => it.HOTEL_OLD_ID == hotel.IDOLD && it.IsDel != 1).ToList();
|
||||
if (roomList.Count > 0)
|
||||
{
|
||||
dlog = new DbLog
|
||||
{
|
||||
location = "",
|
||||
Ip = "::1",
|
||||
Client = "",
|
||||
CreateTime = DateTime.Now,
|
||||
Uid = "宝镜",
|
||||
Type = 0,
|
||||
Content = "宝镜获取酒店" + HotelCode + "的房型和房间信息,成功"
|
||||
};
|
||||
SqlSugarBase.Db.Insertable(dlog).ExecuteCommand();
|
||||
ri.ErrMsg = "成功";
|
||||
ri.ErrCode = 0;
|
||||
ri.HotelCode = HotelCode;
|
||||
ri.RoomTypeCnt = roomList.Count;
|
||||
ri.RoomNoCnt = 0;
|
||||
ri.HotelNane = hotel.HOTEL_NAME_CN;
|
||||
foreach (var item in roomList)
|
||||
{
|
||||
RoomTypeAllinfo rmt = new RoomTypeAllinfo();
|
||||
rmt.RoomTypeID = item.ROOM_TYPE_OLD_ID;
|
||||
rmt.RoomTypeName = item.ROOM_TYPE_NAME;
|
||||
//房间集合
|
||||
List<TBL_ROOM_BASIC_INFO> roominfo = SqlSugarBase.RcuDb.Queryable<TBL_ROOM_BASIC_INFO>().Where(it => it.ROOM_TYPE_OLD_ID == item.ROOM_TYPE_OLD_ID && it.IsDel != 1).ToList();
|
||||
if (roominfo.Count > 0)
|
||||
{
|
||||
rmt.RoomCnt = roominfo.Count;
|
||||
foreach (var items in roominfo)
|
||||
{
|
||||
RoomAllInfo rmtinfo = new RoomAllInfo();
|
||||
rmtinfo.RoomNoID = items.ROOM_OLD_ID;
|
||||
rmtinfo.RoomNumber = items.ROOM_NUMBER;
|
||||
rmt.RoomList.Add(rmtinfo);
|
||||
ri.RoomNoCnt++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rmt.RoomCnt = 0;
|
||||
rmt.RoomList = null;
|
||||
}
|
||||
|
||||
ri.RoomTypelist.Add(rmt);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
dlog = new DbLog
|
||||
{
|
||||
location = "",
|
||||
Ip = "::1",
|
||||
Client = "",
|
||||
CreateTime = DateTime.Now,
|
||||
Uid = "宝镜",
|
||||
Type = 0,
|
||||
Content = "宝镜获取酒店" + HotelCode + "的房型和房间信息,成功"
|
||||
};
|
||||
SqlSugarBase.Db.Insertable(dlog).ExecuteCommand();
|
||||
ri.ErrMsg = "成功";
|
||||
ri.ErrCode = 0;
|
||||
ri.HotelCode = HotelCode;
|
||||
ri.RoomTypeCnt = 0;
|
||||
ri.RoomNoCnt = 0;
|
||||
ri.RoomTypelist = null;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
dlog = new DbLog
|
||||
{
|
||||
location = "",
|
||||
Ip = "::1",
|
||||
Client = "",
|
||||
CreateTime = DateTime.Now,
|
||||
Uid = "宝镜",
|
||||
Type = 0,
|
||||
Content = "宝镜获取酒店" + HotelCode + "的房型和房间信息,未查询到指定code的酒店"
|
||||
};
|
||||
SqlSugarBase.Db.Insertable(dlog).ExecuteCommand();
|
||||
ri.ErrMsg = "未查询到指定code的酒店";
|
||||
ri.ErrCode = 4040;
|
||||
ri.HotelCode = HotelCode;
|
||||
ri.RoomTypeCnt = 0;
|
||||
ri.RoomNoCnt = 0;
|
||||
ri.RoomTypelist = null;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
DbLog dlog = new DbLog
|
||||
{
|
||||
location = "",
|
||||
Ip = "::1",
|
||||
Client = "",
|
||||
CreateTime = DateTime.Now,
|
||||
Uid = "宝镜",
|
||||
Type = 0,
|
||||
Content = "宝镜获取酒店" + HotelCode + "的房型和房间信息,服务器繁忙,请稍后再查询"
|
||||
};
|
||||
SqlSugarBase.Db.Insertable(dlog).ExecuteCommand();
|
||||
ri.ErrMsg = "服务器繁忙,请稍后再查询";
|
||||
ri.ErrCode = 5050;
|
||||
ri.HotelCode = HotelCode;
|
||||
ri.RoomTypeCnt = 0;
|
||||
ri.RoomNoCnt = 0;
|
||||
ri.RoomTypelist = null;
|
||||
LogHelp.WriteExceptionLog(ex);
|
||||
}
|
||||
|
||||
//房型集合
|
||||
return Json(ri, JsonRequestBehavior.AllowGet);
|
||||
}
|
||||
}
|
||||
|
||||
public class ReturnInfo
|
||||
{
|
||||
public ReturnInfo()
|
||||
{
|
||||
RoomTypelist = new List<RoomTypeAllinfo>();
|
||||
}
|
||||
public int ErrCode { get; set; }
|
||||
public string ErrMsg { get; set; }
|
||||
public string HotelCode { get; set; }
|
||||
public string HotelNane { get; set; }
|
||||
public int RoomTypeCnt { get; set; }
|
||||
public int RoomNoCnt { get; set; }
|
||||
public List<RoomTypeAllinfo> RoomTypelist { get; set; }
|
||||
|
||||
}
|
||||
public class RoomTypeAllinfo
|
||||
{
|
||||
public RoomTypeAllinfo()
|
||||
{
|
||||
RoomList = new List<RoomAllInfo>();
|
||||
}
|
||||
public string RoomTypeName { get; set; }
|
||||
public int RoomTypeID { get; set; }
|
||||
public int RoomCnt { get; set; }
|
||||
public List<RoomAllInfo> RoomList { get; set; }
|
||||
}
|
||||
public class RoomAllInfo
|
||||
{
|
||||
public int RoomNoID { get; set; }
|
||||
public string RoomNumber { get; set; }
|
||||
}
|
||||
}
|
||||
527
UI/Controllers/UpgradeController.cs
Normal file
527
UI/Controllers/UpgradeController.cs
Normal file
@@ -0,0 +1,527 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Linq;
|
||||
using System.Net;
|
||||
using System.Net.Http;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Mvc;
|
||||
using Models;
|
||||
using Models.ModelItems;
|
||||
using Services.Manager;
|
||||
using static Services.Manager.SyncAllFromOutterDB;
|
||||
using Newtonsoft.Json;
|
||||
using Models.ApiModei;
|
||||
using NLog;
|
||||
|
||||
namespace UI.Controllers
|
||||
{
|
||||
public class UpgradeController : Controller
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础URL
|
||||
/// </summary>
|
||||
private readonly string baseUrl = "https://www.boonlive-rcu.com/api/";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 新添加的方法,用于获取设备信息
|
||||
/// </summary>
|
||||
/// <param name="hotelId"></param>
|
||||
/// <param name="roomTypeId"></param>
|
||||
/// <param name="roomNumber"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
public async Task<ActionResult> GetDeviceInfo(int hotelId, int roomTypeId, string roomNumber)
|
||||
{
|
||||
// 初始化HttpClient
|
||||
using (var httpClient = new HttpClient())
|
||||
{
|
||||
// 构建请求URL
|
||||
var url = baseUrl + "webChatLoadHostByRoomType";
|
||||
|
||||
|
||||
// 构建表单数据
|
||||
FormUrlEncodedContent formData = null;
|
||||
|
||||
if (!string.IsNullOrEmpty(roomNumber))
|
||||
{
|
||||
formData = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("hotelid", hotelId.ToString()),
|
||||
new KeyValuePair<string, string>("roomTypeID", roomTypeId.ToString()),
|
||||
new KeyValuePair<string, string>("roomNumber", roomNumber)
|
||||
});
|
||||
}
|
||||
else
|
||||
{
|
||||
formData = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("hotelid", hotelId.ToString()),
|
||||
new KeyValuePair<string, string>("roomTypeID", roomTypeId.ToString())
|
||||
});
|
||||
}
|
||||
|
||||
// 发送POST请求
|
||||
HttpResponseMessage response = await httpClient.PostAsync(url, formData);
|
||||
|
||||
// 确保请求成功
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
// 读取返回的字符串
|
||||
string responseString = await response.Content.ReadAsStringAsync();
|
||||
|
||||
// 将字符串转换为ActionResult并返回
|
||||
return Content(responseString, "application/json");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 如果请求失败,返回错误信息
|
||||
return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "检索设备信息失败。");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static Logger logger= LogManager.GetCurrentClassLogger();
|
||||
/// <summary>
|
||||
/// 调用微信升级接口
|
||||
/// </summary>
|
||||
/// <param name="roomTypeID">房型ID</param>
|
||||
/// <param name="hostidLists">升级的设备ID列表</param>
|
||||
/// <param name="upgradefileName">升级文件名字</param>
|
||||
/// <returns>返回调用结果</returns>
|
||||
[HttpPost]
|
||||
public async Task<string> WebChatUpgrade(int roomTypeID, string hostidLists, string upgradefileName)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
var parameters = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("roomTypeID", roomTypeID.ToString()),
|
||||
new KeyValuePair<string, string>("hostid_lists", hostidLists),
|
||||
new KeyValuePair<string, string>("upgradefileName", upgradefileName)
|
||||
});
|
||||
//logger.Error("hostlist:"+hostidLists);
|
||||
var response = await client.PostAsync(baseUrl + "WebChatUpgrade", parameters);
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("调用升级接口失败,状态码:" + response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 查询升级进度
|
||||
/// </summary>
|
||||
/// <param name="hostUpdateID">升级的设备ID号</param>
|
||||
/// <returns>返回查询结果</returns>
|
||||
[HttpPost]
|
||||
public async Task<string> QueryUpdateHostStatus(int hotelID, int roomTypeID)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 构建带参数的 URL
|
||||
var queryParams = new Dictionary<string, string>
|
||||
{
|
||||
{ "HotelID", hotelID.ToString() },
|
||||
{ "roomTypeID", roomTypeID.ToString() }
|
||||
};
|
||||
string requestUrl = $"{baseUrl}QueryUpdateHostStatus";
|
||||
var encodedContent = new FormUrlEncodedContent(queryParams);
|
||||
var response = await client.PostAsync(requestUrl, encodedContent);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception($"调用接口失败,状态码:{response.StatusCode}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件名
|
||||
/// </summary>
|
||||
/// <param name="hotel_id"></param>
|
||||
/// <param name="room_type_id"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost()]
|
||||
public ActionResult GetFileName(int hotel_id, int room_type_id)
|
||||
{
|
||||
|
||||
var db = SqlSugarBase.RcuDb;
|
||||
List<TBL_ROOM_TYPE_LIST> roomList = SqlSugarBase.RcuDb.Queryable<TBL_ROOM_TYPE_LIST>().Where(it => it.HOTEL_OLD_ID == hotel_id && it.ROOM_TYPE_OLD_ID == room_type_id && it.IsDel != 1).ToList();
|
||||
|
||||
List<FileName_DTO> files = new List<FileName_DTO>();
|
||||
FileName_DTO dto = new FileName_DTO();
|
||||
if (roomList != null && roomList.Count > 0)
|
||||
{
|
||||
foreach (var item in roomList)
|
||||
{
|
||||
dto.HOTEL_OLD_ID = item.HOTEL_OLD_ID;
|
||||
dto.ROOM_TYPE_OLD_ID = item.ROOM_TYPE_OLD_ID;
|
||||
dto.CONFIG_BIN = item.CONFIG_BIN;
|
||||
dto.App_Cfg_For_L2 = item.App_Cfg_For_L2;
|
||||
dto.App_Cfg_For_L4 = item.App_Cfg_For_L4;
|
||||
dto.Hex_Code_For_L2 = item.Hex_Code_For_L2;
|
||||
dto.Hex_Code_For_L4 = item.Hex_Code_For_L4;
|
||||
dto.APPTYPE = item.APPTYPE;
|
||||
dto.Cfg_Type = item.Cfg_Type;
|
||||
dto.LUNCHER_HEX = item.LUNCHER_HEX;
|
||||
files.Add(dto);
|
||||
}
|
||||
}
|
||||
return Json(files);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 查询更新主机进度条接口
|
||||
/// </summary>
|
||||
/// <param name="hostIDList">主机ID列表</param>
|
||||
/// <returns>返回调用结果</returns>
|
||||
[HttpPost]
|
||||
public async Task<ActionResult> ForwardQueryUpdateHostProgressBar(string hostIDList)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 将hostIDList字符串反序列化为List<int>,因为你的原始方法接受的是List<int>
|
||||
|
||||
// 创建参数字典
|
||||
var parameters = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("HostIDList", hostIDList)
|
||||
});
|
||||
|
||||
// 发送POST请求
|
||||
var response = await client.PostAsync(baseUrl + "QueryUpdateHostProgressBar", parameters);
|
||||
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
// 读取响应内容并返回
|
||||
string responseBody = await response.Content.ReadAsStringAsync();
|
||||
return Content(responseBody, "application/json");
|
||||
}
|
||||
else
|
||||
{
|
||||
// 处理错误情况
|
||||
throw new Exception("调用查询更新主机进度条接口失败,状态码:" + response.StatusCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 微信调用灯光控制接口
|
||||
/// </summary>
|
||||
/// <param name="jsonData">灯光控制参数对象</param>
|
||||
/// <returns>返回原始接口的JSON响应</returns>
|
||||
[HttpPost]
|
||||
public async Task<string> SetRCULight(RCULight jsonData)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 将对象序列化为JSON字符串
|
||||
string jsonString = JsonConvert.SerializeObject(jsonData);
|
||||
|
||||
|
||||
// 发送POST请求
|
||||
var response = await client.GetAsync(baseUrl + "SetRCULight?jsonData=" + jsonString);
|
||||
|
||||
// 处理响应
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
throw new Exception($"接口调用失败,状态码:{response.StatusCode},错误信息:{errorContent}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取房间类型和模组列表
|
||||
/// </summary>
|
||||
/// <param name="jsonData"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpPost]
|
||||
public async Task<string> GetRoomTypeAndModalsListLog(HostInfo jsonData)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 将对象序列化为JSON字符串
|
||||
string jsonString = JsonConvert.SerializeObject(jsonData);
|
||||
|
||||
|
||||
// 发送POST请求
|
||||
var response = await client.GetAsync(baseUrl + "GetRoomTypeAndModalsListLog?jsonData=" + jsonString);
|
||||
|
||||
// 处理响应
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
throw new Exception($"接口调用失败,状态码:{response.StatusCode},错误信息:{errorContent}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件名
|
||||
/// </summary>
|
||||
/// <param name="Data">参数对象</param>
|
||||
/// <returns>返回原始接口的JSON响应</returns>
|
||||
[HttpPost]
|
||||
public async Task<string> GetFirmwareName(UpLoadRoom Data)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 将对象序列化为JSON字符串
|
||||
//string jsonString = JsonConvert.SerializeObject(jsonData);
|
||||
//var response0 = await client.PostAsync("http://rcu-data.blv-oa.com/OTApi/GainFileName" + PostAsync);
|
||||
var parameters1 = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("RoomTypeid", Data.RoomTypeID.ToString()),
|
||||
new KeyValuePair<string, string>("DataType", "1")
|
||||
});
|
||||
// 发送POST请求
|
||||
var response1 = await client.PostAsync("http://rcu-data.blv-oa.com/OTApi/GainFileName", parameters1);
|
||||
var parameters2 = new FormUrlEncodedContent(new[]
|
||||
{
|
||||
new KeyValuePair<string, string>("RoomTypeid", Data.RoomTypeID.ToString()),
|
||||
new KeyValuePair<string, string>("DataType", "2")
|
||||
});
|
||||
var response2 = await client.PostAsync("http://rcu-data.blv-oa.com/OTApi/GainFileName", parameters2);
|
||||
|
||||
// 处理响应
|
||||
if (response1.IsSuccessStatusCode && response2.IsSuccessStatusCode)
|
||||
{
|
||||
|
||||
return await response1.Content.ReadAsStringAsync() + "@" + await response2.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorContent = await response1.Content.ReadAsStringAsync() + await response2.Content.ReadAsStringAsync();
|
||||
throw new Exception($"接口调用失败,状态码:{response1.StatusCode.ToString() + response2.StatusCode.ToString()},错误信息:{errorContent}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调用RCU空调接口
|
||||
/// </summary>
|
||||
/// <param name="requestData"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="Exception"></exception>
|
||||
[HttpPost]
|
||||
public async Task<string> SetRCUAir(RCUAirRequest requestData)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 1. 序列化请求对象为JSON
|
||||
string jsonString = JsonConvert.SerializeObject(requestData);
|
||||
|
||||
// 2. 正确编码JSON字符串
|
||||
string encodedJson = Uri.EscapeDataString(jsonString);
|
||||
|
||||
// 3. 构建完整的GET请求URL
|
||||
string apiUrl = $"{baseUrl}SetRCUAir?jsonData={encodedJson}";
|
||||
|
||||
try
|
||||
{
|
||||
// 4. 发送GET请求
|
||||
var response = await client.GetAsync(apiUrl);
|
||||
|
||||
// 5. 处理响应
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
throw new Exception($"接口调用失败: HTTP {response.StatusCode} - {errorContent}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"请求发送失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调用SetRCUService接口
|
||||
/// </summary>
|
||||
/// <param name="requestData">服务控制请求参数</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost]
|
||||
public async Task<string> SetRCUService(RCUServiceRequest requestData)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 1. 序列化请求对象为JSON
|
||||
string jsonString = JsonConvert.SerializeObject(requestData);
|
||||
|
||||
// 2. 正确编码JSON字符串
|
||||
string encodedJson = Uri.EscapeDataString(jsonString);
|
||||
|
||||
// 3. 构建完整的GET请求URL
|
||||
string apiUrl = $"{baseUrl}SetRCUService?jsonData={encodedJson}";
|
||||
|
||||
try
|
||||
{
|
||||
// 4. 发送GET请求
|
||||
var response = await client.GetAsync(apiUrl);
|
||||
|
||||
// 5. 处理响应
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
throw new Exception($"服务控制失败: HTTP {response.StatusCode} - {errorContent}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"请求发送失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 调用SetRCUCurtain接口控制窗帘
|
||||
/// </summary>
|
||||
/// <param name="requestData">窗帘控制请求参数</param>
|
||||
/// <returns>操作结果</returns>
|
||||
[HttpPost]
|
||||
public async Task<string> SetRCUCurtain(RCUCurtainRequest requestData)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
// 1. 序列化请求对象为JSON
|
||||
string jsonString = JsonConvert.SerializeObject(requestData);
|
||||
|
||||
// 2. 正确编码JSON字符串
|
||||
string encodedJson = Uri.EscapeDataString(jsonString);
|
||||
|
||||
// 3. 构建完整的GET请求URL
|
||||
string apiUrl = $"{baseUrl}SetRCUCurtain?jsonData={encodedJson}";
|
||||
|
||||
try
|
||||
{
|
||||
// 4. 发送GET请求
|
||||
var response = await client.GetAsync(apiUrl);
|
||||
|
||||
// 5. 处理响应
|
||||
if (response.IsSuccessStatusCode)
|
||||
{
|
||||
return await response.Content.ReadAsStringAsync();
|
||||
}
|
||||
else
|
||||
{
|
||||
var errorContent = await response.Content.ReadAsStringAsync();
|
||||
throw new Exception($"窗帘控制失败: HTTP {response.StatusCode} - {errorContent}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw new Exception($"请求发送失败: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 服务控制请求参数类
|
||||
public class RCUServiceRequest
|
||||
{
|
||||
public string roomNumber { get; set; } // 房号
|
||||
public string code { get; set; } // 编号
|
||||
public string creatDate { get; set; } // 创建日期
|
||||
public string modalAddress { get; set; } // 设备地址
|
||||
public int status { get; set; } // 状态:1=开,2=关
|
||||
}
|
||||
|
||||
|
||||
// 空调控制
|
||||
public class RCUAirRequest
|
||||
{
|
||||
public string roomNumber { get; set; }
|
||||
public string code { get; set; }
|
||||
public string creatDate { get; set; }
|
||||
public string modalAddress { get; set; }
|
||||
public int? onOff { get; set; } // 使用可空类型表示可选参数
|
||||
public int? temperature { get; set; } // 16~32
|
||||
public int? fanSpeed { get; set; } // 0自动,1低速,2中速,3高速
|
||||
public int? mode { get; set; } // 0自动,1制冷,2制热,3送风
|
||||
public int? valve { get; set; } // 1开,2关
|
||||
}
|
||||
|
||||
// 窗帘控制请求参数类
|
||||
public class RCUCurtainRequest
|
||||
{
|
||||
public string roomNumber { get; set; } // 房号
|
||||
public string code { get; set; } // 编号
|
||||
public string creatDate { get; set; } // 创建日期
|
||||
public string modalAddress { get; set; } // 回路地址
|
||||
public int status { get; set; } // 状态:1=开,2=关,6=停止
|
||||
}
|
||||
|
||||
public class UpLoadRoom
|
||||
{
|
||||
public int RoomTypeID { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 灯光控制参数对象
|
||||
/// </summary>
|
||||
public class RCULight
|
||||
{
|
||||
public string roomNumber { get; set; }
|
||||
public string code { get; set; }
|
||||
public string creatDate { get; set; }
|
||||
public string status { get; set; }
|
||||
public string modalAddress { get; set; }
|
||||
public string brightness { get; set; }
|
||||
}
|
||||
|
||||
public class HostInfo
|
||||
{
|
||||
public string code { get; set; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 文件名数据传输对象
|
||||
/// </summary>
|
||||
public class FileName_DTO
|
||||
{
|
||||
public int HOTEL_OLD_ID { get; set; }
|
||||
public int ROOM_TYPE_OLD_ID { get; set; }
|
||||
public string CONFIG_BIN { get; set; }
|
||||
public string App_Cfg_For_L2 { get; set; }
|
||||
public string App_Cfg_For_L4 { get; set; }
|
||||
public string Hex_Code_For_L2 { get; set; }
|
||||
public string Hex_Code_For_L4 { get; set; }
|
||||
public string APPTYPE { get; set; }
|
||||
public string Cfg_Type { get; set; }
|
||||
public string LUNCHER_HEX { get; set; }
|
||||
}
|
||||
}
|
||||
1662
UI/Controllers/WxController.cs
Normal file
1662
UI/Controllers/WxController.cs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user