初始化
This commit is contained in:
566
WebUI/Controllers/ApiController.cs
Normal file
566
WebUI/Controllers/ApiController.cs
Normal file
@@ -0,0 +1,566 @@
|
||||
using COMMON;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Models;
|
||||
using Models.Models.DEBUGGER_DB;
|
||||
using Models.Models.LOGDB;
|
||||
using Newtonsoft.Json;
|
||||
using Quartz;
|
||||
using SERVER;
|
||||
using SERVER.DataServer;
|
||||
using SERVER.LIB;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TcpServer;
|
||||
using WebUI.LIB;
|
||||
using static Models.TCPDATA;
|
||||
|
||||
namespace WebUI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// api控制器
|
||||
/// </summary>
|
||||
public class ApiController : BaseController
|
||||
{
|
||||
private IScheduler _scheduler;
|
||||
|
||||
private readonly LOG_DBContext _logdb;
|
||||
private readonly HotelServiceContext _db;
|
||||
private readonly DEBUGGER_DB _DEBUGGER_DB;
|
||||
private readonly ISchedulerFactory _schedulerFactory;
|
||||
|
||||
/// <summary>
|
||||
/// 注入定时器等服务
|
||||
/// </summary>
|
||||
/// <param name="logdb"></param>
|
||||
/// <param name="schedulerFactory"></param>
|
||||
/// <param name="_DB"></param>
|
||||
/// <param name="db"></param>
|
||||
public ApiController(HotelServiceContext db, LOG_DBContext logdb, ISchedulerFactory schedulerFactory, DEBUGGER_DB _DB)
|
||||
{
|
||||
_db = db;
|
||||
_schedulerFactory = schedulerFactory;
|
||||
_logdb = logdb;
|
||||
_DEBUGGER_DB = _DB;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下发固件、配置
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult SendCmd(int type = 1,params string[] mac)
|
||||
{
|
||||
try
|
||||
{
|
||||
foreach (var item in mac)
|
||||
{
|
||||
XC_Redis.Redis.Remove(item);
|
||||
}
|
||||
return Json(Send_Cmd.Send_File(type,mac));
|
||||
}
|
||||
catch (Exception EX)
|
||||
{
|
||||
LogHelp.Error(EX.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 下发 固件、配置 进度条
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult Send_Schedule(int type = 1, params string[] mac)
|
||||
{
|
||||
try
|
||||
{
|
||||
Dictionary<string,string> macData = new Dictionary<string,string>();
|
||||
foreach (var item in mac)
|
||||
{
|
||||
var rd = XC_Redis.Redis.GetKey<double>(item);
|
||||
macData.Add(item, rd+"%");
|
||||
}
|
||||
return Json(macData);
|
||||
}
|
||||
catch (Exception EX)
|
||||
{
|
||||
LogHelp.Error(EX.ToString());
|
||||
return Content(EX.Message); ;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 酒店信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult HOTELINFO()
|
||||
{
|
||||
try
|
||||
{
|
||||
IList<HotelDataItem> RESHotels = new List<HotelDataItem>();
|
||||
|
||||
foreach (var item in CacheData.TBL_HOTEL_BASIC_INFO.GroupBy(X=>X.HOTEL_OLD_GROUP))
|
||||
{
|
||||
var GROUP = CacheData.TBL_HOTEL_GROUP_INFO.FirstOrDefault(X=>X.HOTEL_GROUP_OLD_ID == item.First().HOTEL_OLD_GROUP);
|
||||
if (GROUP == null)
|
||||
{
|
||||
LogHelp.Error(item.First().HOTEL_OLD_GROUP + "酒店组信息为null~");
|
||||
continue;
|
||||
}
|
||||
RESHotels.Add(new HotelDataItem() {HotelGroupsName = GROUP.HOTEL_GROUP_NAME,HotelGroupsId = GROUP.HOTEL_GROUP_OLD_ID,Hotels = item.Select(X => new HotelsItem() { Auth = null, Code = X.PROJECT_NUMBER, HotelId = X.IDOLD, HotelName = X.HOTEL_NAME_CN }).ToList() });
|
||||
RESHotels.Add(new HotelDataItem() {HotelGroupsName = GROUP.HOTEL_GROUP_NAME,HotelGroupsId = GROUP.HOTEL_GROUP_OLD_ID,Hotels = item.Select(X => new HotelsItem() { Auth = null, Code = X.PROJECT_NUMBER, HotelId = X.IDOLD, HotelName = X.HOTEL_NAME_CN }).ToList() });
|
||||
}
|
||||
// var RES = Hotels.ToArray();
|
||||
//for(int i = 0; i < RES.Count();i++)
|
||||
//{
|
||||
// for (int J = 0; J < RES[i].Hotels.Count; J++)
|
||||
// {
|
||||
// RES[i].Hotels[J].Auth = null;
|
||||
// }
|
||||
//}
|
||||
return Json(RESHotels);
|
||||
}
|
||||
catch (Exception EX)
|
||||
{
|
||||
LogHelp.Error(EX.ToString());
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 房间信息
|
||||
/// </summary>
|
||||
/// <param name="HotelId">酒店id</param>
|
||||
/// <param name="GroupId">酒店组id</param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult ROOMINFO(int HotelId = 0,int GroupId = 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
// 这里是进行了权限判断 以及数据的简单校验
|
||||
//if ((HotelId <= 0 && GroupId<=0) || (HotelId > 0 && Hoteldata.FirstOrDefault(X=>X.HotelId == HotelId)==null ))
|
||||
// return Json(null);
|
||||
List<int> HotelDATA = HotelDATA = _db.TBL_HOTEL_BASIC_INFOS.Where(X => (GroupId ==0 || X.HOTEL_OLD_GROUP == GroupId) && (HotelId==0 || X.IDOLD == HotelId)).Select(X=>X.IDOLD).ToList();
|
||||
return Json(_db.TBL_ROOM_BASIC_INFOS.Where(x => HotelDATA.Contains(x.HOTEL_OLD_ID)).Select(x => new { text = x.ROOM_NUMBER, val = x.ROOM_OLD_ID,mac=x.MAC }));
|
||||
}
|
||||
catch (Exception EX)
|
||||
{
|
||||
LogHelp.Error(EX.ToString());
|
||||
return Json(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取文件数据列表
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult SelModelFile(int start = 0, int length = 15, int draw = 0, string type = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
int count = 0;
|
||||
int count_ = 0;
|
||||
var data = ModelFile.GetFtp(out count, out count_, start, length, type);
|
||||
return Json(new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = count,
|
||||
recordsFiltered = count_,
|
||||
data = data
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加文件数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult AddModelFile(List<IFormFile> files, int type = -1)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Json(ModelFile.AddModelFile(type, files, TOken, _db).Result);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
return Json(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 删除文件数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult DelModelFile(int id)
|
||||
{
|
||||
try
|
||||
{
|
||||
return Json(ModelFile.DelModelFile(id, _db));
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
return Json(false);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 刷新token 同时也返回服务器服务状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult Token()
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
Get();
|
||||
|
||||
BaseController.SXTOKEN(this, HttpContext);
|
||||
return Json(new ReturnData<int[]> { IsSuccess = true, Result = new int[] { XC_Redis.Redis.GetKey<int>("udpserver"), TestingServices.ISok("BLV RUCS") } });
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
return Json(new ReturnData<String> { IsSuccess = false, Result = ex.Message });
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 刷新udp log 数
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult Getudplogcount()
|
||||
{
|
||||
try
|
||||
{
|
||||
return Json(new
|
||||
{
|
||||
udp = CacheData.UDPcount,
|
||||
// ruc 是没有直接跟房间绑定的 只能酒店房间 反推 ruc rcu数量 等于房间绑定的rcu 数量
|
||||
rcu = SelHotel == null ? 0 : _db.TBL_ROOM_BASIC_INFOS.Where(x => x.HOTEL_OLD_ID == SelHotel.HotelId && x.MAC.Length > 0).Count()
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
return Json(new
|
||||
{
|
||||
udp = 0,
|
||||
// ruc 是没有直接跟房间绑定的 只能酒店房间 反推 ruc
|
||||
rcu = 0
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取rcu列表 分页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetRCU(int start,int draw, int length, int room_online_satatus, string roomnumber,int room_type)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
||||
if (SelHotel != null)
|
||||
{
|
||||
|
||||
int COUNT, COUNT_ = 0;
|
||||
var macdata = RcuServer.SetRucServer(out COUNT, out COUNT_,SelHotel.HotelId, start, length,room_online_satatus, roomnumber, room_type, _db);
|
||||
return Json(new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = COUNT,
|
||||
recordsFiltered = COUNT_,
|
||||
data = macdata
|
||||
});
|
||||
}
|
||||
else
|
||||
return null;
|
||||
}
|
||||
catch (Exception EX)
|
||||
{
|
||||
LogHelp.Error(EX.ToString());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 切换酒店
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult Sel(int id)
|
||||
{
|
||||
HotelsItem hotels = Hoteldata.FirstOrDefault(x => x.HotelId == id);
|
||||
if (hotels != null)
|
||||
{
|
||||
Response.Cookies.Append("old_host_" + TOken, id.ToString());
|
||||
COMMON.XC_Redis.Redis.SetKey(TOken_rom + "_sel", hotels);
|
||||
}
|
||||
return Json(new ReturnData<string> { IsSuccess = hotels != null, Result = null });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 退出登录
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult signout()
|
||||
{
|
||||
Response.Cookies.Delete("CurrentUser");
|
||||
// 删除会话用户标识
|
||||
XC_Redis.Redis.Remove(TOken + Cookie.Substring(Cookie.Length - 8) + "_rom");
|
||||
// 删除会话用户选择的 酒店
|
||||
XC_Redis.Redis.Remove(TOken_rom + "_sel");
|
||||
// 删除 随机截取的token 下标数组
|
||||
XC_Redis.Redis.Remove(TOken_rom);
|
||||
if (ConfigEntity.Instance.IsMore == false)
|
||||
{
|
||||
XC_Redis.Redis.Remove(TOken);
|
||||
XC_Redis.Redis.Remove(TOken + "__hoteldata");
|
||||
}
|
||||
return RedirectToAction("Index", "Login");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RUCS_CMD
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpGet]
|
||||
public IActionResult RUCS_CMD()
|
||||
{
|
||||
return Json(new { Send_RUCS_RCU_LIST = SendHelp.Send_RUCS_RCU_LIST().ToString() });
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取酒店组视图
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetGroup(int group = 0, string search = "")
|
||||
{
|
||||
for (int i = 0; i < Hotels.Count; i++)
|
||||
{
|
||||
if (Hotels[i].HotelGroupsId == group)
|
||||
{
|
||||
ViewData["HotelGroup"] = Hotels[i];
|
||||
}
|
||||
}
|
||||
ViewData["Hotel"] = SelHotel.HotelId;
|
||||
ViewData["search"] = string.IsNullOrEmpty(search) ? "" : search;
|
||||
return View(Hotels);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取酒店视图 未用到
|
||||
/// </summary>
|
||||
/// <returns> 未用到 </returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetHotels(int GroupId)
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取UDPINFO 通讯包数统计
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetCHARTS(int[] TX, int[] RX, string startDate, string endDate)
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetCHARTS(_logdb, TX, RX, startDate, endDate);
|
||||
return Json(res);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取UDPINFO 统计 通讯字节流量统计
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetErrorSucess(int[] TX, int[] RX, string startDate, string endDate)
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetErrorSucess(_logdb, startDate, endDate);
|
||||
return Json(res);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取UDPINFO 端口数据使用情况
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetProt(string startDate, string endDate)
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetProt(_logdb, startDate, endDate);
|
||||
return Json(res);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取UDPINFO 处理耗时
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetPROCESSINGTIME(string startDate, string endDate)
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetPROCESSINGTIME(_logdb, startDate, endDate);
|
||||
return Json(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取UDPINFO 处理耗时
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetRevDelayDateTime(string startDate, string endDate)
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetRevDelayDateTime(_logdb, startDate, endDate);
|
||||
return Json(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取UDPINFO 命令饼图 tx rx
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetCMDpie(string startDate, string endDate, string type = "TX")
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetCMDpie_(_logdb, startDate, endDate, type);
|
||||
return Json(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取UDPINFO 重发饼图 tx rx
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetRETRY_COUNT(string startDate, string endDate, string type = "TX")
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetRETRY_COUNT(_logdb, startDate, endDate, type);
|
||||
return Json(res);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更改服务状态
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult Changerserver(int type)
|
||||
{
|
||||
return Json(TestingServices.ISok("BLV RUCS", type));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 同步数据
|
||||
/// </summary>
|
||||
public void Get()
|
||||
{
|
||||
if (Client.dateTime == string.Empty) { return; }
|
||||
lock (Client.dateTimelocks)
|
||||
{
|
||||
if (Client.dateTime == null)
|
||||
{
|
||||
Client.dateTime = "000000000";
|
||||
Thread thread = new Thread(async () =>
|
||||
{
|
||||
|
||||
//1、通过调度工厂获得调度器
|
||||
_scheduler = await _schedulerFactory.GetScheduler();
|
||||
//2、开启调度器
|
||||
await _scheduler.Start();
|
||||
//3、创建一个触发器
|
||||
var trigger = TriggerBuilder.Create()
|
||||
.WithCronSchedule("0/3 * * * * ?")//间隔3秒 检测 tcp 是否在运行
|
||||
.Build();
|
||||
//3、创建一个触发器
|
||||
var trigger1 = TriggerBuilder.Create()
|
||||
.WithCronSchedule("0 00 00 * * ? *")// 每日 0 点触发 同步数据
|
||||
.Build();
|
||||
//3、创建一个触发器
|
||||
var trigger2 = TriggerBuilder.Create()
|
||||
.WithCronSchedule("4 20 * * * ?")//每个小时 10min 统计字节流量等
|
||||
.Build();
|
||||
//4、创建任务
|
||||
// 检测tcp 是否在运行
|
||||
var jobDetail = JobBuilder.Create<Jobs>()
|
||||
.Build();
|
||||
//4、创建任务
|
||||
// 同步数据
|
||||
var jobDetail1 = JobBuilder.Create<JobsOne>()
|
||||
.Build();
|
||||
//4、创建任务
|
||||
// 统计字数数量等
|
||||
var jobDetai2 = JobBuilder.Create<JobsTwo>()
|
||||
.Build();
|
||||
//5、将触发器和任务器绑定到调度器中
|
||||
await _scheduler.ScheduleJob(jobDetail, trigger);
|
||||
await _scheduler.ScheduleJob(jobDetail1, trigger1);
|
||||
await _scheduler.ScheduleJob(jobDetai2, trigger2);
|
||||
|
||||
});
|
||||
thread.Start();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#region BLV_UdpDebug 数据统计图
|
||||
/// <summary>
|
||||
/// 数据统计图
|
||||
/// </summary>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult GetBLV_UdpDebugImg(string startDate, string endDate)
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetBLV_UdpDebugImg(_DEBUGGER_DB, startDate, endDate);
|
||||
return Json(res);
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region BLV_UdpDebug 数据统计饼图
|
||||
/// <summary>
|
||||
/// 数据统计饼图 通讯命令 数据统计接收耗时条形统计图
|
||||
/// </summary>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult GetBLV_UdpDebugImg_PIE(string startDate, string endDate)
|
||||
{
|
||||
ECHARTS res = CHARTSSERVER.GetBLV_UdpDebugImg_RevDelayDateTime(_DEBUGGER_DB, startDate, endDate);
|
||||
return Json(res);
|
||||
}
|
||||
#endregion
|
||||
|
||||
}
|
||||
}
|
||||
205
WebUI/Controllers/BaseController.cs
Normal file
205
WebUI/Controllers/BaseController.cs
Normal file
@@ -0,0 +1,205 @@
|
||||
using Microsoft.AspNetCore.Http.Extensions;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Filters;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Models;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using System.Security.Claims;
|
||||
using System.Linq;
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using SERVER;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Quartz;
|
||||
using System.Threading.Tasks;
|
||||
using WebUI.LIB;
|
||||
using COMMON;
|
||||
using SERVER.LIB;
|
||||
|
||||
namespace WebUI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 基础控制器 判定权限
|
||||
/// </summary>
|
||||
public class BaseController : Controller
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 用户 权限酒店原始数据 有分组
|
||||
/// </summary>
|
||||
public IList<HotelDataItem> Hotels = new List<HotelDataItem>();
|
||||
/// <summary>
|
||||
/// 用户 当前选择的酒店 这里的id 等于库里面 的 oLDid
|
||||
/// </summary>
|
||||
public HotelsItem SelHotel = new HotelsItem { };
|
||||
|
||||
/// <summary>
|
||||
/// 用户 权限酒店
|
||||
/// </summary>
|
||||
public List<HotelsItem> Hoteldata = new List<HotelsItem>();
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
public Datainfo data { get; set; } = null;
|
||||
|
||||
/// <summary>
|
||||
/// TOken 是用户名
|
||||
/// </summary>
|
||||
public string TOken { get; set; } = string.Empty;
|
||||
public string TOken_rom { get; set; } = string.Empty;
|
||||
public string Cookie { get; set; } = string.Empty;
|
||||
//复写父类的该方法。执行控制器中的方法之前先执行该方法。从而实现过滤的功能。
|
||||
public override void OnActionExecuting(ActionExecutingContext filterContext)
|
||||
{
|
||||
base.OnActionExecuting(filterContext); //调用父类的该方法。
|
||||
Cookie = Request.Cookies["CurrentUser"];
|
||||
if (Cookie != null)
|
||||
{
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.Instance.SecurityKey));
|
||||
//校验token
|
||||
var validateParameter = new TokenValidationParameters()
|
||||
{
|
||||
ValidateLifetime = true,
|
||||
ValidateAudience = true,
|
||||
ValidateIssuer = true,
|
||||
ValidateIssuerSigningKey = true,
|
||||
ValidIssuer = JwtConst.Instance.Domain,
|
||||
ValidAudience = JwtConst.Instance.Domain,
|
||||
IssuerSigningKey = key
|
||||
};
|
||||
//不校验,直接解析token
|
||||
//jwtToken = new JwtSecurityTokenHandler().ReadJwtToken(token1);
|
||||
try
|
||||
{
|
||||
//校验并解析token
|
||||
var claimsPrincipal = new JwtSecurityTokenHandler().ValidateToken(Request.Cookies["CurrentUser"], validateParameter, out SecurityToken validatedToken);//validatedToken:解密后的对象
|
||||
//var jwtPayload = ((JwtSecurityToken)validatedToken).Payload.SerializeToJson(); //获取payload中的数据
|
||||
TOken = claimsPrincipal.Identities.First().Name;
|
||||
int[] rom = XC_Redis.Redis.GetKey<int[]>(TOken + Cookie.Substring(Cookie.Length - 8) + "_rom");
|
||||
TOken_rom = TOken;
|
||||
if (rom == null)
|
||||
{
|
||||
rom = XC_Redis.Redis.GetKey<int[]>(TOken + Cookie.Substring(Cookie.Length - 8) + "_rom_old");
|
||||
};
|
||||
if (rom == null)
|
||||
{
|
||||
throw new Exception();
|
||||
};
|
||||
foreach (var item in rom)
|
||||
{
|
||||
TOken_rom += Cookie[item];
|
||||
}
|
||||
data = XC_Redis.Redis.GetKey<Datainfo>(TOken);
|
||||
if (data == null)
|
||||
{
|
||||
throw new Exception();
|
||||
}
|
||||
SelHotel = XC_Redis.Redis.GET(TOken_rom + "_sel", () =>
|
||||
{
|
||||
if (data.HotelData == null || data.HotelData.Count <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
// 账号其他地方 登录 更新权限信息
|
||||
// 同一账号 权限信息 共享 不会因为先登录而多用有某些权限
|
||||
XC_Redis.Redis.Remove(TOken + "_Hoteldata");
|
||||
return data.HotelData.FirstOrDefault().Hotels.FirstOrDefault();
|
||||
});
|
||||
Hotels = data.HotelData;
|
||||
|
||||
Hoteldata = XC_Redis.Redis.GET(TOken + "_Hoteldata", () =>
|
||||
{
|
||||
foreach (var item in Hotels)
|
||||
{
|
||||
Hoteldata.AddRange(item.Hotels);
|
||||
}
|
||||
return Hoteldata;
|
||||
});
|
||||
|
||||
ViewBag.SelHotel = SelHotel;
|
||||
|
||||
ViewBag.Uname = TOken;
|
||||
|
||||
ViewBag.HeadImg = data.Userinfo.HeadImg;
|
||||
|
||||
string keys = data.Userinfo.Uid;
|
||||
|
||||
|
||||
}
|
||||
catch (SecurityTokenExpiredException ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
//表示过期
|
||||
filterContext.Result = Redirect("/Login/index?REURL=" + HttpContext.Request.GetDisplayUrl());
|
||||
}
|
||||
catch (SecurityTokenException ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
//表示token错误
|
||||
filterContext.Result = Redirect("/Login/index?REURL=" + HttpContext.Request.GetDisplayUrl());
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
filterContext.Result = Redirect("/Login/index?REURL=" + HttpContext.Request.GetDisplayUrl());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
//这种跳转方式直接返回一个ActionResult,不会继续向下执行,而是直接跳转。速度快。
|
||||
filterContext.Result = Redirect("/Login/index?REURL=" + HttpContext.Request.GetDisplayUrl());
|
||||
}
|
||||
}
|
||||
|
||||
public static void SXTOKEN(BaseController baseController, HttpContext httpContext)
|
||||
{
|
||||
|
||||
var keys = baseController.TOken;
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtRegisteredClaimNames.Nbf,$"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}") ,
|
||||
new Claim (JwtRegisteredClaimNames.Exp,$"{new DateTimeOffset(DateTime.Now.AddMinutes(20)).ToUnixTimeSeconds()}"),
|
||||
new Claim(ClaimTypes.Name,keys)
|
||||
};
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.Instance.SecurityKey));
|
||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: JwtConst.Instance.Domain,
|
||||
audience: JwtConst.Instance.Domain,
|
||||
claims: claims,
|
||||
expires: DateTime.Now.AddMinutes(20),
|
||||
signingCredentials: creds);
|
||||
var RES = new ReturnData<string> { IsSuccess = true };
|
||||
string toke = new JwtSecurityTokenHandler().WriteToken(token);
|
||||
|
||||
httpContext.Response.Cookies.Append("CurrentUser", toke);
|
||||
|
||||
int[] rom = {
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
};
|
||||
|
||||
XC_Redis.Redis.SetKey(keys + baseController.Cookie.Substring(baseController.Cookie.Length - 8) + "_rom_old",
|
||||
|
||||
XC_Redis.Redis.GetKey<int[]>(keys + baseController.Cookie.Substring(baseController.Cookie.Length - 8) + "_rom"), 10);
|
||||
|
||||
XC_Redis.Redis.Remove(keys + baseController.Cookie.Substring(baseController.Cookie.Length - 8) + "_rom");
|
||||
|
||||
XC_Redis.Redis.SetKey(keys + toke.Substring(toke.Length - 8) + "_rom", rom, 20);
|
||||
|
||||
foreach (var item in rom)
|
||||
{
|
||||
keys += toke[item];
|
||||
}
|
||||
XC_Redis.Redis.SetKey(baseController.TOken, baseController.data, 20);
|
||||
XC_Redis.Redis.SetKey(keys + "_sel", baseController.SelHotel,20);
|
||||
XC_Redis.Redis.SetKey(baseController.TOken_rom + "_sel", baseController.SelHotel,10);
|
||||
}
|
||||
}
|
||||
}
|
||||
67
WebUI/Controllers/HomeController.cs
Normal file
67
WebUI/Controllers/HomeController.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Models;
|
||||
using Models.Models.LOGDB;
|
||||
using Quartz;
|
||||
using SERVER;
|
||||
using SERVER.LIB;
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using TcpServer;
|
||||
using WebUI.LIB;
|
||||
|
||||
namespace WebUI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 首页默认控制器
|
||||
/// </summary>
|
||||
public class HomeController : BaseController
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// 首页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 同步数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
var res = SYNC_DATA.SYNC_DATA_ALL();
|
||||
string Result = "不能频繁刷新~";
|
||||
if (res)
|
||||
{
|
||||
Result = "刷新成功,大概一分钟左右生效~";
|
||||
}
|
||||
return Json(new ReturnData<string>() { IsSuccess = res, Result = Result });
|
||||
}
|
||||
/// <summary>
|
||||
/// 错误页面
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View(new ErrorViewModel { RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier });
|
||||
}
|
||||
/// <summary>
|
||||
/// 暂时未使用
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[Produces("text/event-stream")]
|
||||
public IActionResult Demo()
|
||||
{
|
||||
return Content(String.Empty);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
122
WebUI/Controllers/LoginController.cs
Normal file
122
WebUI/Controllers/LoginController.cs
Normal file
@@ -0,0 +1,122 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.IdentityModel.Tokens;
|
||||
using Models;
|
||||
using SERVER;
|
||||
using System;
|
||||
using System.IdentityModel.Tokens.Jwt;
|
||||
using System.Security.Claims;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
using SERVER.LIB;
|
||||
using System.IO;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Imaging;
|
||||
using COMMON;
|
||||
using System.Linq;
|
||||
|
||||
namespace WebUI.Controllers
|
||||
{
|
||||
[AllowAnonymous]
|
||||
public class LoginController : Controller
|
||||
{
|
||||
protected readonly IHttpContextAccessor _httpContextAccessor;
|
||||
|
||||
|
||||
|
||||
public LoginController(IHttpContextAccessor httpContextAccessor)
|
||||
{
|
||||
_httpContextAccessor = httpContextAccessor;
|
||||
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult LSH_TEST(string REURL = "")
|
||||
{
|
||||
Random random = new Random();
|
||||
ViewBag.ReURL = REURL;
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
[HttpGet]
|
||||
public IActionResult Index(string REURL = "")
|
||||
{
|
||||
ViewBag.ReURL = REURL;
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Logon(string userName, string pwd)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(userName) && !string.IsNullOrEmpty(pwd))
|
||||
{
|
||||
//内网地址就 传空值
|
||||
string ipaddress = _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.ToString();
|
||||
string UserAgent = _httpContextAccessor.HttpContext.Request.Headers["User-Agent"];
|
||||
|
||||
var res = SYNC_DATA.SYNC_GetUserinfo(ipaddress, UserAgent, userName, pwd);
|
||||
if (res.Status == 200)
|
||||
{
|
||||
string keys = res.Data.Userinfo.Uid;
|
||||
//+ DateTime.Now.ToString("yyyyMMddhmmssfff") + UtilsSharp.RandomHelper.NumberAndLetters(5);
|
||||
|
||||
if (ConfigEntity.Instance.IsMore == false && XC_Redis.Redis.IsExists(keys))
|
||||
{
|
||||
return Json(new ReturnData<string> { IsSuccess = false, Result = "已经在其他地方登录~" });
|
||||
}
|
||||
|
||||
var claims = new[]
|
||||
{
|
||||
new Claim(JwtRegisteredClaimNames.Nbf,$"{new DateTimeOffset(DateTime.Now).ToUnixTimeSeconds()}") ,
|
||||
new Claim (JwtRegisteredClaimNames.Exp,$"{new DateTimeOffset(DateTime.Now.AddMinutes(30)).ToUnixTimeSeconds()}"),
|
||||
new Claim(ClaimTypes.Name,keys)
|
||||
};
|
||||
|
||||
var key = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(JwtConst.Instance.SecurityKey));
|
||||
var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);
|
||||
var token = new JwtSecurityToken(
|
||||
issuer: JwtConst.Instance.Domain,
|
||||
audience: JwtConst.Instance.Domain,
|
||||
claims: claims,
|
||||
expires: DateTime.Now.AddMinutes(20),
|
||||
signingCredentials: creds);
|
||||
var RES = new ReturnData<string> { IsSuccess = true };
|
||||
string toke = new JwtSecurityTokenHandler().WriteToken(token);
|
||||
HttpContext.Response.Cookies.Append("CurrentUser", toke);
|
||||
// 权限信息 同一用户 不用地点登录 共享 最后登录会更新该数据
|
||||
XC_Redis.Redis.SetKey(keys, res.Data, 20);
|
||||
|
||||
int[] rom = {
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
new Random(int.Parse(UtilsSharp.RandomHelper.Number(4))).Next(0, toke.Length),
|
||||
};
|
||||
|
||||
// 当前会话用户的 标识 同账号不同地点登录区别使用 用户名 加 token 后7未
|
||||
XC_Redis.Redis.SetKey(keys + toke.Substring(toke.Length-8) + "_rom", rom, 20);
|
||||
|
||||
foreach (var item in rom)
|
||||
{
|
||||
keys += toke[item];
|
||||
}
|
||||
return Json(RES);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new ReturnData<string> { IsSuccess = false, Result = null });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return Json(new ReturnData<string> { IsSuccess = false, Result = null });
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
19
WebUI/Controllers/ModelFileController.cs
Normal file
19
WebUI/Controllers/ModelFileController.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebUI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 模型文件管理
|
||||
/// </summary>
|
||||
public class ModelFileController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// Model文件管理
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
WebUI/Controllers/RCUServerController.cs
Normal file
19
WebUI/Controllers/RCUServerController.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebUI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// rcu管理控制器
|
||||
/// </summary>
|
||||
public class RCUServerController : BaseController
|
||||
{
|
||||
/// <summary>
|
||||
/// RCU 管理首页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
476
WebUI/Controllers/ServerController.cs
Normal file
476
WebUI/Controllers/ServerController.cs
Normal file
@@ -0,0 +1,476 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Models;
|
||||
using Models.Models.LOGDB;
|
||||
using Microsoft.Data.SqlClient;
|
||||
using System.Linq;
|
||||
using DB_Server;
|
||||
using static Models.TCPDATA;
|
||||
using SERVER;
|
||||
using System.Collections.Generic;
|
||||
using SERVER.LIB;
|
||||
using System;
|
||||
using Models.Models.DEBUGGER_DB;
|
||||
using COMMON;
|
||||
using Models.Models;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace WebUI.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// 服务器管理
|
||||
/// </summary>
|
||||
public class ServerController : BaseController
|
||||
{
|
||||
//~ServerController()
|
||||
//{
|
||||
// LogHelp.Warning($"志祥教的折构函数~");
|
||||
//}
|
||||
private readonly LOG_DBContext _logdb;
|
||||
private readonly HotelServiceContext _db;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="db"></param>
|
||||
/// <param name="logdb"></param>
|
||||
public ServerController(LOG_DBContext logdb, HotelServiceContext db)
|
||||
{
|
||||
_logdb = logdb;
|
||||
_db = db;
|
||||
}
|
||||
|
||||
public IActionResult LOGFILENAME(string type = "0", int length = 100, int start = 0, string name = null, string startDate = null, string endDate = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
DateTime starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
DateTime endtime = DateTime.Now;
|
||||
if (!DateTime.TryParse(startDate, out starttime) && starttime < ConfigEntity.Instance.STARTTIME)
|
||||
starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
if (!DateTime.TryParse(endDate, out endtime))
|
||||
endtime = DateTime.Now;
|
||||
// 阿里云查询出的mac
|
||||
var DATA = new ASLS().GetLogs_(2, @$" * | select * where lower(logfilename) like '%{name.ToLower()}%'{(string.IsNullOrEmpty(type) || type.Trim() == "0" ? string.Empty : " and log_type = " + type.Trim() + "")} {" and createdatetime >= '" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "'"} {" and createdatetime < '" + endtime.ToString("yyyy-MM-dd HH:mm:ss")+ "'"} limit 10000").Result.ToArray();
|
||||
return Json(DATA);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelp.Error(ex.ToString());
|
||||
return Json(null);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UDP通讯日志
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult UDPLOG()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// UDP通讯统计
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult UDPINFO()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Rucs服务管理
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult RUCS()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 获取调试LOG数据
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult RUCS_Log()
|
||||
{
|
||||
return View(XC_Redis.Redis.GetKey<List<PARAs_Class>>("RUCS_DEBUGLOG") ?? new List<PARAs_Class>());
|
||||
}
|
||||
|
||||
#region TBL_RUCS_UDP_LOG 分页
|
||||
|
||||
/// <summary>
|
||||
/// 获取TBL_RUCS_UDP_LOG 分页信息
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="draw"></param>
|
||||
/// <param name="DESTINATION"></param>
|
||||
/// <param name="DATA_VALID"></param>
|
||||
/// <param name="SOURCE_PORT"></param>
|
||||
/// <param name="SOURCE_IP"></param>
|
||||
/// <param name="DIRECTION"></param>
|
||||
/// <param name="DESTINATION_PORT"></param>
|
||||
/// <param name="CONTENT_DECRYPT"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetUDPLog(
|
||||
int start,
|
||||
string endDate = "",
|
||||
string startDate = "",
|
||||
int length = 15,
|
||||
int draw = 1,
|
||||
string DESTINATION = "",
|
||||
string DATA_VALID = "",
|
||||
string SOURCE_PORT = "",
|
||||
string SOURCE_IP = "",
|
||||
string DIRECTION = "",
|
||||
string DESTINATION_PORT = "",
|
||||
string CONTENT_DECRYPT = ""
|
||||
|
||||
)
|
||||
{
|
||||
DateTime starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
DateTime endtime = DateTime.Now;
|
||||
if (!DateTime.TryParse(startDate, out starttime) && starttime < ConfigEntity.Instance.STARTTIME)
|
||||
starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
|
||||
if (!DateTime.TryParse(endDate, out endtime))
|
||||
endtime = DateTime.Now;
|
||||
|
||||
int count = CacheData.UDPcount, filtcount = 0;
|
||||
|
||||
string sql = $@"{(string.IsNullOrEmpty(DESTINATION) ? string.Empty : " and destination like '%" + DESTINATION + "%'")}{" and datetime < '" + endtime.ToString("yyyy-MM-dd HH:mm:ss") + "'"}{" and datetime >= '" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "'"}{(string.IsNullOrEmpty(CONTENT_DECRYPT) ? string.Empty : " and udp_cmd = '" + CONTENT_DECRYPT + " 0'")}{(string.IsNullOrEmpty(DESTINATION_PORT) ? string.Empty : " and destination_port = " + DESTINATION_PORT)}{(string.IsNullOrEmpty(DATA_VALID) ? string.Empty : " and data_valid = " + DATA_VALID)}{(string.IsNullOrEmpty(DIRECTION) ? string.Empty : " and direction = '" + DIRECTION + "'")}{(string.IsNullOrEmpty(SOURCE_PORT) ? string.Empty : " and source_port = " + SOURCE_PORT)}{(string.IsNullOrEmpty(SOURCE_IP) ? string.Empty : " and source_ip like '%" + SOURCE_IP + "%'")}";
|
||||
filtcount = int.Parse(new ASLS().GetLogs_(0, @$"* | select COUNT(*) sum where 1 = 1{sql}", starttime.AddHours(-1), endtime.AddHours(1)).Result[0]["sum"]);
|
||||
|
||||
|
||||
var DATE_WHERE = "";
|
||||
int _start = start;
|
||||
|
||||
while (_start + length >= 100000)
|
||||
{
|
||||
var S = new ASLS().GetLogs_(0, @$"* | select datetime where 1 = 1 {(DATE_WHERE == "" ? "" : "AND datetime > '" + DATE_WHERE + "'")} {sql} order by datetime LIMIT {(_start > 99999 ? "99999" : _start)},1", starttime.AddHours(-1), endtime.AddHours(1)).Result;
|
||||
DATE_WHERE = S[0]["datetime"];
|
||||
_start -= (_start > 99999 ? 99999 : _start);
|
||||
start = 0;
|
||||
}
|
||||
var new_data = new ASLS().GetLogs_(0, @$"* | select mac,data_valid,udp_id,direction,direction,content_decrypt,direction,source_port,source_ip,datetime,destination,destination_port where 1 = 1 {(DATE_WHERE == "" ? "" : "AND datetime > '" + DATE_WHERE + "'")} {sql} order by datetime limit {start},{length}", starttime.AddHours(-1), endtime.AddHours(1)).Result;
|
||||
|
||||
var DATA_ = DicObject<TBL_RUCS_UDP_LOG>.GetList(new_data.ToArray());
|
||||
|
||||
// throw new Exception("分页查询未完成!");
|
||||
// db.GetData<TBL_RUCS_UDP_LOG>(new string[,] {
|
||||
// { "DESTINATION"," like ",string.IsNullOrEmpty(DESTINATION)?"":DESTINATION,"DESTINATION"},
|
||||
// { "DATETIME"," <= ",(string.IsNullOrEmpty(endDate)?"":endDate) ,"endDate"},
|
||||
// { "UDP_CMD"," = ",(string.IsNullOrEmpty(CONTENT_DECRYPT)?"":CONTENT_DECRYPT+" 0") ,"CONTENT_DECRYPT"},
|
||||
// { "DATETIME"," >= ",string.IsNullOrEmpty(startDate)?"":startDate ,"startDate"},
|
||||
// { "DESTINATION_PORT"," like ", string.IsNullOrEmpty (DESTINATION_PORT)?"":DESTINATION_PORT,"DESTINATION_PORT" },
|
||||
// { "DATA_VALID"," like ", (string.IsNullOrEmpty(DATA_VALID)?"":DATA_VALID),"DATA_VALID" },
|
||||
// { "DIRECTION"," like ", (string.IsNullOrEmpty(DIRECTION)?"":DIRECTION),"DIRECTION" },
|
||||
// { "SOURCE_PORT"," like ", (string.IsNullOrEmpty(SOURCE_PORT)?"":SOURCE_PORT),"SOURCE_PORT" },
|
||||
// { "SOURCE_IP"," like ", (string.IsNullOrEmpty(SOURCE_IP)?"":SOURCE_IP),"SOURCE_IP" },
|
||||
// { "PackageTime"," > ", "2022-05-01","PackageTime" },
|
||||
//}, "TBL_RUCS_UDP_LOG", (start / length) + 1, length, out count, out filtcount, " order by id desc");
|
||||
return Json(new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = count,
|
||||
recordsFiltered = filtcount,
|
||||
data = DATA_
|
||||
});
|
||||
}
|
||||
#endregion TBL_RUCS_UDP_LOG 分页
|
||||
|
||||
|
||||
#region BLV_UdpDebug 数据查询
|
||||
/// <summary>
|
||||
/// 职业
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult BLV_UdpDebug()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region BLV_UdpDebug 分页
|
||||
/// <summary>
|
||||
/// BLV_UdpDebug 分页
|
||||
/// </summary>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="draw"></param>
|
||||
/// <param name="endDate"></param>
|
||||
/// <param name="startDate"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult GetBLV_UdpDebug(
|
||||
int start,
|
||||
int length = 15,
|
||||
int draw = 1,
|
||||
string endDate = "",
|
||||
string startDate = ""
|
||||
)
|
||||
{
|
||||
DateTime starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
DateTime endtime = DateTime.Now;
|
||||
if (!DateTime.TryParse(startDate, out starttime) && starttime < ConfigEntity.Instance.STARTTIME)
|
||||
starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
|
||||
if (!DateTime.TryParse(endDate, out endtime))
|
||||
endtime = DateTime.Now;
|
||||
DbHelperSQL db = new DbHelperSQL(DbHelperSQL.DBSel.DEBUGGER_DB);
|
||||
int count = 0, filtcount = 0;
|
||||
|
||||
var new_data = db.GetData<TBL_UDP_DEBUGGER>(new string[,] {
|
||||
{ "CreateDateTime"," <= ",(string.IsNullOrEmpty(endDate)?"":endDate) ,"endDate"},
|
||||
{ "CreateDateTime"," >= ",(string.IsNullOrEmpty(startDate)?"":startDate) ,"startDate"},
|
||||
}, "TBL_UDP_DEBUGGER", (start / length) + 1, length, out count, out filtcount, " order by id desc", sumhc: 30);
|
||||
|
||||
return Json(new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = count,
|
||||
recordsFiltered = filtcount,
|
||||
data = new_data
|
||||
});
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 调试信息饼图
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult BLV_UdpDebugImg()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件跟踪信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult EVENTLOGGING()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 事件跟踪信息 分页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <param name="startDate">查询起始时间</param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="endDate">查询结束时间</param>
|
||||
/// <param name="evenid">事件id</param>
|
||||
/// <param name="mac">mac地址</param>
|
||||
/// <param name="hotelid">巫工酒店id</param>
|
||||
/// <param name="roomid">房间</param>
|
||||
/// <param name="draw"></param>
|
||||
/// <returns></returns>
|
||||
public IActionResult EVENTLOGGING_(int start, int length, string startDate = null, string endDate = null, string mac = null, string evenid = "", string hotelid = "", string roomid = "", int draw = 0)
|
||||
{
|
||||
DateTime starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
DateTime endtime = DateTime.Now;
|
||||
if (!DateTime.TryParse(startDate, out starttime) && starttime < ConfigEntity.Instance.STARTTIME)
|
||||
starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
if (!DateTime.TryParse(endDate, out endtime))
|
||||
endtime = DateTime.Now;
|
||||
|
||||
int count = CacheData.UDPcount, filtcount = 0;
|
||||
|
||||
|
||||
string sql = $@"{(string.IsNullOrEmpty(mac) ? string.Empty : " and mac like '%" + mac + "%'")}{" and create_timemark < '" + endtime.ToString("yyyy-MM-dd HH:mm:ss") + "'"}{" and create_timemark >= '" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "'"}{(string.IsNullOrEmpty(evenid) ? string.Empty : " and evenid = '" + evenid + "'")}{(string.IsNullOrEmpty(hotelid) ? string.Empty : " and hotelid = " + hotelid)}{(string.IsNullOrEmpty(roomid) ? string.Empty : " and roomid = " + roomid)}";
|
||||
|
||||
filtcount = int.Parse(new ASLS().GetLogs_(1, @$"* | select COUNT(*) sum where 1 = 1 {sql}", starttime.AddHours(-1), endtime.AddHours(1)).Result[0]["sum"]);
|
||||
|
||||
var DATE_WHERE = "";
|
||||
int _start = start;
|
||||
|
||||
while (_start + length >= 100000)
|
||||
{
|
||||
var S = new ASLS().GetLogs_(1, @$"* | select create_timemark where 1 = 1 {(DATE_WHERE == "" ? "" : "AND create_timemark > '" + DATE_WHERE + "'")} {sql} order by create_timemark LIMIT {(_start > 99999 ? "99999" : _start)},1", starttime.AddHours(-1), endtime.AddHours(1)).Result;
|
||||
DATE_WHERE = S[0]["create_timemark"];
|
||||
_start -= (_start > 99999 ? 99999 : _start);
|
||||
start = 0;
|
||||
}
|
||||
|
||||
var new_data = new ASLS().GetLogs_(1, @$"* | select mac,data_valid,udp_id,direction,direction,content_decrypt,direction,source_port,source_ip,datetime,destination,destination_port where 1 = 1 {(DATE_WHERE == "" ? "" : "AND datetime > '" + DATE_WHERE + "'")} {sql} order by datetime limit {start},{length}", starttime.AddHours(-1), endtime.AddHours(1)).Result;
|
||||
|
||||
var DATA_ = DicObject<TBL_EVENTLOGGING>.GetList(new_data.ToArray());
|
||||
|
||||
|
||||
return Json(new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = count,
|
||||
recordsFiltered = filtcount,
|
||||
data = new { }
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 事件跟踪信息
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult RcuDataLog(string mac = "")
|
||||
{
|
||||
if (string.IsNullOrEmpty(mac))
|
||||
{
|
||||
return Content("window.history.back();location.reload();", "application/javascript");
|
||||
}
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询mac
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public IActionResult Find_Mac()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
/// <summary>
|
||||
/// 查询mac 分页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <param name="startDate">查询起始时间</param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="endDate">查询结束时间</param>
|
||||
/// <param name="mac">事件id</param>
|
||||
/// <param name="hotelid">巫工酒店id</param>
|
||||
/// <param name="draw"></param>
|
||||
[HttpPost]
|
||||
public IActionResult Find_Mac(int draw = 0, int start = 0, int length = 10, string mac = "", string startDate = null, string endDate = null, string hotelid = "")
|
||||
{
|
||||
try
|
||||
{
|
||||
if (string.IsNullOrEmpty(mac))
|
||||
mac = "";
|
||||
mac = mac.Replace("34D0", "").Trim();
|
||||
DateTime starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
DateTime endtime = DateTime.Now;
|
||||
if (!DateTime.TryParse(startDate, out starttime) && starttime < ConfigEntity.Instance.STARTTIME)
|
||||
starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
if (!DateTime.TryParse(endDate, out endtime))
|
||||
endtime = DateTime.Now;
|
||||
|
||||
int filtcount = int.Parse(new ASLS().GetLogs_(2, @$"* | select count(distinct mac) sum where lower(mac) like '%{mac.ToLower()}%' {" and createdatetime >= '" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "'"} {" and createdatetime < '" + endtime.ToString("yyyy-MM-dd HH:mm:ss") + $"'"}").Result[0]["sum"]), count = int.Parse(new ASLS().GetLogs_(2, @$"* | select count(distinct mac) sum").Result[0]["sum"]); ;
|
||||
|
||||
// 阿里云查询出的mac
|
||||
var DATA = new List<string>();
|
||||
DATA = DicObject<TBL_ROOM_BASIC_INFO>.GetList(new ASLS().GetLogs_(2, @$" * | select distinct lower(mac) mac where lower(mac) like '%{mac.ToLower()}%' {" and createdatetime >= '" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "'"} {" and createdatetime < '" + endtime.ToString("yyyy-MM-dd HH:mm:ss") + $"' limit {start},{length}"}").Result.ToArray()).Select(X => string.Join("-", Regex.Split(("34D0" + X.MAC).ToLower(), "(?<=\\G.{2})")).TrimEnd('-')).ToList();
|
||||
|
||||
// 查询权限酒店下的mac
|
||||
var macdata =
|
||||
(from val1 in _db.TBL_ROOM_BASIC_INFOS
|
||||
join val2 in _db.TBL_HOTEL_BASIC_INFOS on val1.HOTEL_OLD_ID equals val2.IDOLD
|
||||
where DATA.Contains(val1.MAC.ToLower())
|
||||
select new { mac = val1.MAC.ToUpper(), hotelname = val2.HOTEL_NAME_CN, hotelid = val2.IDOLD, room_number = val1.ROOM_NUMBER, id = val1.ROOM_OLD_ID }).ToList();
|
||||
// 这是sls 存在 但是 数据表没有的mac
|
||||
DATA = DATA.Where(x => macdata.FirstOrDefault(w => w.mac.ToLower() == x.ToLower()) == null).ToList();
|
||||
// 这是sls 存在但是没有酒店的mac
|
||||
foreach (var item in DATA)
|
||||
{
|
||||
macdata.Add(new { mac = item.ToUpper(), hotelname = "无酒店信息", hotelid = -1, room_number = "无", id = -1 });
|
||||
}
|
||||
return Json(new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = count,
|
||||
recordsFiltered = filtcount,
|
||||
data = macdata
|
||||
});
|
||||
}
|
||||
catch (Exception EX)
|
||||
{
|
||||
LogHelp.Error(EX.ToString());
|
||||
return Json(null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 事件跟踪信息 分页
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
/// <param name="startDate">查询起始时间</param>
|
||||
/// <param name="start"></param>
|
||||
/// <param name="length"></param>
|
||||
/// <param name="endDate">查询结束时间</param>
|
||||
/// <param name="mac">mac地址</param>
|
||||
/// <param name="hotelid">巫工酒店id</param>
|
||||
/// <param name="roomid">房间</param>
|
||||
/// <param name="draw"></param>
|
||||
/// <param name="type"></param>
|
||||
/// <returns></returns>
|
||||
[HttpPost]
|
||||
public IActionResult RcuDataLog_(int start, int length, string startDate = null, string endDate = null, string mac = null, string hotelid = "", string type = "", string roomid = "", int draw = 0)
|
||||
{
|
||||
DateTime starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
DateTime endtime = DateTime.Now;
|
||||
if (!DateTime.TryParse(startDate, out starttime) && starttime < ConfigEntity.Instance.STARTTIME)
|
||||
starttime = DateTime.Parse("2022-03-25 00:00:01");
|
||||
if (!DateTime.TryParse(endDate, out endtime))
|
||||
endtime = DateTime.Now;
|
||||
int count = CacheData.UDPcount, filtcount = 0;
|
||||
|
||||
string mac_new = string.Empty;
|
||||
//mac_new = "'"+string.Join("','",
|
||||
// // MAC 不为 null 并且 长度大于 0
|
||||
// _db.TBL_ROOM_BASIC_INFOS.Where(x => x.MAC != null && x.MAC.Length > 0
|
||||
// // 酒店 未传入时 取房间的值
|
||||
// && ((hotelid.Trim() == "0" && roomid.Trim()!="0" && "" + x.ROOM_OLD_ID == roomid)
|
||||
// ||
|
||||
// // 房间 未传入时 取酒店的值
|
||||
// (roomid.Trim() == "0" && hotelid.Trim() != "0" && "" + x.HOTEL_OLD_ID == hotelid)
|
||||
// ||
|
||||
// // 取房间 取酒店的值
|
||||
// ("" + x.HOTEL_OLD_ID == hotelid && "" + x.ROOM_OLD_ID == roomid)
|
||||
// )).Select(x => x.MAC))+ "'";
|
||||
|
||||
string sql = $@"{(string.IsNullOrEmpty(mac) ? string.Empty : " and lower(mac) = '" + mac.ToStringMac() + "'")}{" and createdatetime >= '" + starttime.ToString("yyyy-MM-dd HH:mm:ss") + "'"}{" and createdatetime < '" + endtime.ToString("yyyy-MM-dd HH:mm:ss") + "'"} {(string.IsNullOrEmpty(type) || type.Trim() == "0" ? string.Empty : " and log_type = " + type.Trim() + "")}{(mac_new.Length <= 2 ? "" : $" and mac in ({mac_new})")} ";
|
||||
|
||||
filtcount = int.Parse(new ASLS().GetLogs_(2, @$"* | select count(distinct logfilename) sum where 1 = 1 {sql}", starttime.AddHours(-1), endtime.AddHours(1)).Result[0]["sum"]);
|
||||
|
||||
var DATE_WHERE = "";
|
||||
|
||||
int _start = start;
|
||||
|
||||
// 这快代码待验证 错误
|
||||
while (_start + length >= 100000)
|
||||
{
|
||||
var S = new ASLS().GetLogs_(2, @$"* | select createdatetime where 1 = 1 {(DATE_WHERE == "" ? "" : "AND createdatetime > '" + DATE_WHERE + "'")} {sql} order by createdatetime LIMIT {(_start > 99999 ? "99999" : _start)},1", starttime.AddHours(-1), endtime.AddHours(1)).Result;
|
||||
DATE_WHERE = S[0]["createdatetime"];
|
||||
_start -= (_start > 99999 ? 99999 : _start);
|
||||
start = 0;
|
||||
}
|
||||
|
||||
var new_data = new ASLS().GetLogs_(2, @$"* | select logfilename,COUNT(*) sum where 1 = 1 {(DATE_WHERE == "" ? "" : "AND datetime > '" + DATE_WHERE + "'")} {sql} group by logfilename order by '__tag__:__receive_time__' desc limit {start},{length}", starttime.AddHours(-1), endtime.AddHours(1)).Result;
|
||||
|
||||
var DATA_ = DicObject<LOGFILENAME>.GetList(new_data.ToArray());
|
||||
|
||||
return Json(new
|
||||
{
|
||||
draw,
|
||||
recordsTotal = count,
|
||||
recordsFiltered = filtcount,
|
||||
data = DATA_
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
1626
WebUI/Controllers/publicApiController.cs
Normal file
1626
WebUI/Controllers/publicApiController.cs
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user