Files
Web_Faces_Prod/Face.Web/Global.asax.cs
2025-11-25 17:41:57 +08:00

321 lines
14 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using Face.Domain.Entities;
using Face.Services.Manager;
using Face.SystemTask;
using Face.Web.Areas.App.Controllers;
using Face.Web.Areas.App.Models;
using FluentScheduler;
using MySql.Data.MySqlClient;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net.NetworkInformation;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
using System.Web.Http;
using System.Web.Mvc;
using System.Web.Optimization;
using System.Web.Routing;
using TencentCloud.Common.Profile;
using TencentCloud.Common;
using WebServer;
using static Face.Web.Areas.App.Models.Roominfo;
using System.Text;
using WebSocketToolsConsole;
namespace Face.Web
{
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
MyRegistry.GoWork();
AreaRegistration.RegisterAllAreas();
GlobalConfiguration.Configure(WebApiConfig.Register);
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
//定时器
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new System.Timers.ElapsedEventHandler(aTimer_Elapsed);
//设置引发时间的时间间隔 此处设置为1秒
aTimer.Interval = 1000 * 10;//3600秒也就是1小时每1小时刷新一次就是每1小时执行方法一次
aTimer.Enabled = true;
//自定义定时作业计划
JobManager.Initialize(new TimingPlanRegistry());
//timingOut();
//注册UDP监视
//Services.UDPHelp.StartReceive();
//(new System.Threading.Thread(new System.Threading.ThreadStart(Services.UDPHelp.CreatSocket))).Start(); //开辟一个新线程
//(new System.Threading.Thread(new System.Threading.ThreadStart(Services.UDPHelp_New.CreatSocket))).Start(); //开辟一个新线程
//Services.UDP.UDPHelp.RecevieAndSend();
//Thread t = new Thread(timingOut);
//t.Start();
//Thread S = new Thread(UdpCommunication.UdpStateinfo);
//S.Start();
//timingOut();
}
protected void Session_OnStart()
{
Session.Timeout = 60 * 4;
}
public void timingOut() //预约退房
{
List<Result> relist = null;
Result result = new Result();
try
{
using (var db = SqlSugarBase.GesmartDb())
{
var list = db.Queryable<CheckinTest>().Where(s => s.testState != 2 && s.testState != 3).ToList();
foreach (var item in list)
{
var timeOut = DateTime.Parse(item.predictCheckIn.ToString()).AddMinutes(Convert.ToDouble(item.checkInduration.ToString()));
var hotellist = SqlSugarBase.authoriydb.Queryable<Hotels>().First(s => s.Id == item.hotelid);
GetRoomInterface.test te = new GetRoomInterface.test
{
code = hotellist.Code.ToString(),
creatDate = hotellist.CreateTime.ToString("yyyy-MM-dd")
};
var geiRoomShow = GetRoomInterface.Roomport(te);
if (geiRoomShow.IsSuccess == true)
{
relist = geiRoomShow.Result;
result = relist.FirstOrDefault(x => x.ID == item.Roomid);
}
var dqsj = timeOut - DateTime.Now;
if (item.testState != 1)
{
if (item.predictCheckIn <= DateTime.Now)//立刻开房
{
List<TestUser> tu = new List<TestUser>();
using (var sx = SqlSugarBase.GesmartDb())
{
var dingdan = sx.Queryable<subtabulation>().Where(s => s.masterid == item.id).ToList();
foreach (var info in dingdan)
{
var user = sx.Queryable<TestUser>().First(x => x.id == info.Lodgerid);
if (user != null)
{
tu.Add(user);
}
}
bool isok = true;
List<WebServer.UserInfo> users = new List<WebServer.UserInfo>();
for (int i = 0; i < tu.Count; i++)
{
WebServer.UserInfo fo = new WebServer.UserInfo()
{
idcard = tu[i].idNumber,
customer = tu[i].name,
sex = tu[i].sex == 1 ? "男" : "女",
photoUrl = "http://face.blv-oa.com/ImgServer/FileImage?url=" + tu[i].picture,
};
users.Add(fo);
int uid = tu[i].id;
var sm = SqlSugarBase.Db.Queryable<TestUser>().First(x => x.id == uid);
isok = WebHelp.Send(new SendInfo { code = hotellist.Code.ToString(), roomNumber = result.RoomNumber, idNumber = sm.idNumber, phoneNumber = sm.phone }, users.ToArray());
users.Clear();
int states = 4;
if (isok)
{
states = 1;
}
SqlSugarBase.Db.Updateable<CheckinTest>().SetColumns(s => s.testState == states).Where(x => x.id == item.id).ExecuteCommand();
}
}
}
else
{
//预约开房
Task.Factory.StartNew(() =>
{
var dqdate = Convert.ToDateTime(item.predictCheckIn.ToString()) - DateTime.Now;
var sun = (DateTime.Now + dqdate);
if (sun < DateTime.Now.AddMinutes(20))
{
Task.Delay(dqdate).Wait();
List<TestUser> tu = new List<TestUser>();
using (var sx = SqlSugarBase.GesmartDb())
{
var dingdan = sx.Queryable<subtabulation>().Where(s => s.masterid == item.id).ToList();
foreach (var info in dingdan)
{
var user = sx.Queryable<TestUser>().First(x => x.id == info.Lodgerid);
tu.Add(user);
}
bool isok = true;
List<WebServer.UserInfo> users = new List<WebServer.UserInfo>();
for (int i = 0; i < tu.Count; i++)
{
WebServer.UserInfo fo = new WebServer.UserInfo()
{
idcard = tu[i].idNumber,
customer = tu[i].name,
sex = tu[i].sex == 1 ? "男" : "女",
photoUrl = "http://face.blv-oa.com/ImgServer/FileImage?url=" + tu[i].picture,
};
users.Add(fo);
int uid = tu[i].id;
var sm = SqlSugarBase.Db.Queryable<TestUser>().First(x => x.id == uid);
isok = WebHelp.Send(new SendInfo { code = hotellist.Code.ToString(), roomNumber = result.RoomNumber, idNumber = sm.idNumber, phoneNumber = sm.phone }, users.ToArray());
users.Clear();
}
int states = 4;
if (isok)
{
states = 1;
}
SqlSugarBase.Db.Updateable<CheckinTest>().SetColumns(x => x.testState == states).Where(x => x.id == item.id).ExecuteCommand();
}
}
});
}
}
{
//var dates = item.predictCheckIn - DateTime.Now;
}
if (dqsj <= TimeSpan.FromMinutes(0))//立刻退房
{
Logs.WriteTimingUDPLog("全局异步立刻退房操作");
if (item.checkInduration != 0)
{
FJHelp.outinfos(item.id.ToString());
Logs.WriteTimingUDPLog("全局异步立刻退房成功");
}
}
else//预约退房
{
if (item.checkInduration != 0)
{
Task.Factory.StartNew(() =>
{
Task.Delay(dqsj).Wait();
Logs.WriteTimingUDPLog("全局异步预约退房操作");
FJHelp.outinfos(item.id.ToString());
Logs.WriteTimingUDPLog("全局异步预约退房成功");
});
}
}
}
}
}
catch (Exception)
{
Logs.WriteTimingUDPLog("全局错误");
}
}
void aTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{
}
protected void Application_Error(Object sender, EventArgs e)
{
Exception lastError = Server.GetLastError();//获取异常
if (lastError != null)
{
//异常信息
string strExceptionMessage = string.Empty;
//对HTTP 404做额外处理其他错误全部当成500服务器错误
HttpException httpError = lastError as HttpException;
//得到错误信息,可以写到日志里
LogHelp.WriteExceptionLog(lastError);
//一定要调用Server.ClearError()否则会触发错误详情页(就是黄页)
//Server.ClearError();
}
}
}
public class MyRegistry : Registry
{
//无参构造函数
public MyRegistry()
{
//每天2点
Schedule(() =>
{
string fname = "移海";
List<DeviceManage> tbl = SqlSugarBase.GesmartDb().Queryable<DeviceManage>().Where(x=>x.Status==true && x.Factory== fname).ToList();
for (int i = 0; i < tbl.Count; i++)
{
if (tbl[i].Status == true)
{
Entity.Rootinfo info = new Entity.Rootinfo();
info.pmsid = -1;
Entity.msgx msgx = new Entity.msgx();
StringBuilder sbperson = new StringBuilder();
sbperson.Append("key=abc");
//sbperson.Append("&number=50");
//sbperson.Append("&offset=0");
msgx.msgid = Guid.NewGuid().ToString();
msgx.sn = tbl[i].SerialNo;
msgx.cmd = "getDeviceInfo";//得到设备信息
msgx.msg = System.Web.HttpUtility.HtmlDecode(sbperson.ToString());
info.msgx = msgx;
info.pmsid = -1;
string sendMsg = Newtonsoft.Json.JsonConvert.SerializeObject(info);
UdpCommunication.QueueSend(sendMsg);
Task.Delay(10000);
}
}
using (var db = SqlSugarBase.GesmartDb())
{
//string sn = tbl[i].SerialNo;
//var dbt = db.Queryable<DeviceManage>().First(x => x.SerialNo == sn);
ULog uLog = new ULog
{
Uname = "oy" /*Session["username"].ToString()*/,
faceSN = "所以在线的人脸机"/*tbl[i].SerialNo*/,
operatetype = "得到设备基本信息,每天晚上2点执行一次",
hotelcode = 0 /*int.Parse(Session["hotelCode"].ToString())*/,//
roomid = 0,
Creationtime = DateTime.Now
};
SqlSugarBase.Db.Insertable(uLog).ExecuteCommand();
}
//if (!SyncHotelServer.SyncHotelGroups())
// Logs.WriteTimingUDPLog("2:00执行定时任务--清除酒店失败~");
}).ToRunEvery(0).Days().At(2, 00);
}
public static void GoWork()
{
JobManager.Initialize(new MyRegistry());
}
}
}