diff --git a/CRICS_V3_1124.suo b/CRICS_V3_1124.suo index d144369..1030c1f 100644 Binary files a/CRICS_V3_1124.suo and b/CRICS_V3_1124.suo differ diff --git a/Common/UDPPackageCount.cs b/Common/UDPPackageCount.cs index 0af65b4..e921157 100644 --- a/Common/UDPPackageCount.cs +++ b/Common/UDPPackageCount.cs @@ -6,6 +6,30 @@ using System.Text; using System.Collections.Concurrent; namespace Common { + public class WebAPI_TongJi + { + public static long GetRoomAirList = 0; + public static long SetRCUAir = 0; + public static long GetRoomSceneList = 0; + public static long SetRCUScene = 0; + public static long GetRoomLightList =0; + public static long SetRCULight = 0; + public static long GetRoomCurtainList = 0; + public static long SetRCUCurtain = 0; + public static long GetRoomServiceList = 0; + public static long SetRCUService = 0; + public static long GetOperationLog = 0; + public static long GetRoomMusicList = 0; + public static long SetRCUMusic = 0; + public static long GetRCUStatus = 0; + public static long GetAirDetectList = 0; + public static long GetHostFaultList = 0; + public static long GetRoomTypeAndModalsList = 0; + public static long GetRCUInfoForPDU = 0; + public static long GetSessionKey = 0; + public static long GetPhoneNumber = 0; + public static long GetHotelInfoForWX = 0; + } public class YUANZI_TongJi { public static long TotalReceiveCount = 0; diff --git a/Common/XuanZhuOperation.cs b/Common/XuanZhuOperation.cs index 4485345..590762d 100644 --- a/Common/XuanZhuOperation.cs +++ b/Common/XuanZhuOperation.cs @@ -64,8 +64,8 @@ namespace Common } catch (Exception ex) { - string Key = "HttpRequest_" + resp.code + "_" + resp.roomNumber; - MemoryCacheHelper.Set(Key, 1, DateTimeOffset.Now.AddMinutes(10)); + //string Key = "HttpRequest_" + resp.code + "_" + resp.roomNumber; + //MemoryCacheHelper.Set(Key, 1, DateTimeOffset.Now.AddMinutes(10)); logger.Error(string.Format("酒店({0})客房({1})调用设备状态或异常推送接口({2})失败:{3},数据:{4}", resp.code, resp.roomNumber, url, ex.Message, param)); return false; } diff --git a/CommonEntity/CacheKey.cs b/CommonEntity/CacheKey.cs index 18443fe..abc50dc 100644 --- a/CommonEntity/CacheKey.cs +++ b/CommonEntity/CacheKey.cs @@ -122,6 +122,7 @@ namespace CommonEntity public static string KongTiaoAlert = "KT#Alert"; public static string WebChatDeviceFault = "WXFault"; + public static string DuOSToken = "DuOSToken"; } public class ChangLiangValue { diff --git a/RCUHost/Config/Receiver.xml b/RCUHost/Config/Receiver.xml index 2dd36b3..24e5eb2 100644 --- a/RCUHost/Config/Receiver.xml +++ b/RCUHost/Config/Receiver.xml @@ -177,6 +177,7 @@ + diff --git a/RCUHost/Implement/HostServer.cs b/RCUHost/Implement/HostServer.cs index 2a84b20..d14d71f 100644 --- a/RCUHost/Implement/HostServer.cs +++ b/RCUHost/Implement/HostServer.cs @@ -1514,7 +1514,8 @@ namespace RCUHost.Implement //添加统计信息 StepTongJi.SendInfo(3, "Task分配成功,即将开始执行", context.MessageID, context.IsMonitor); - if (cmdType == 0x36) + byte cmdTypeTTT = context.SystemHeader.Value.CmdType; + if (cmdTypeTTT == 0x36) { IReceiver receiver = receivers[(CommandType)0x36]; if (receiver != null) diff --git a/RCUHost/Implement/RoomStatusReceiver.cs b/RCUHost/Implement/RoomStatusReceiver.cs index 3463f72..b73f0f7 100644 --- a/RCUHost/Implement/RoomStatusReceiver.cs +++ b/RCUHost/Implement/RoomStatusReceiver.cs @@ -1035,8 +1035,14 @@ namespace RCUHost.Implement var d = hhh.RoomNumber; foreach (string cuid in a)//多个英文逗号隔开 { - TianMaoOperation.PostWebRequestToTianMao("CheckoutWithAK", - Newtonsoft.Json.JsonConvert.SerializeObject(new { HotelId = cuid.Split('&')[0], RoomNo = cuid.Split('&')[1] }), c, d);//重置天猫精灵 + + string c1 = cuid.Split('&')[0]; + string c2 = cuid.Split('&')[1]; + if (!string.IsNullOrEmpty(c1) && !string.IsNullOrEmpty(c2)) + { + TianMaoOperation.PostWebRequestToTianMao("CheckoutWithAK", + Newtonsoft.Json.JsonConvert.SerializeObject(new { HotelId = c1, RoomNo = c2 }), c, d);//重置天猫精灵 + } Interface3Log w1 = new Interface3Log(); w1.HotelCode = c; diff --git a/Service/Implement/HostManager.cs b/Service/Implement/HostManager.cs index 815b9f0..39a0f86 100644 --- a/Service/Implement/HostManager.cs +++ b/Service/Implement/HostManager.cs @@ -565,28 +565,41 @@ namespace Service.Implement { if (!string.IsNullOrEmpty(host.XiaoDuCUID)) { - string accessToken = SysOauth2Repository.GetXiaoDuToken(); + string accessToken = ""; + string KKK = CacheKey.DuOSToken; + var ooo = MemoryCacheHelper.Get(KKK); + if (ooo != null) + { + accessToken = ooo.ToString(); + } + else + { + accessToken = SysOauth2Repository.GetXiaoDuToken(); + MemoryCacheHelper.Set(KKK,accessToken,DateTimeOffset.Now.AddMinutes(20)); + } if (!string.IsNullOrEmpty(accessToken) && host.SysHotel.IsPowerOffResetXiaoDu) { - System.Threading.Tasks.Task.Factory.StartNew(() => + + foreach (string cuid in host.XiaoDuCUID.Split(','))//多个小度英文逗号隔开 { - foreach (string cuid in host.XiaoDuCUID.Split(','))//多个小度英文逗号隔开 - { - XiaoDuOperation.PostWebRequestToXiaoDu(accessToken, cuid, new XiaoDuParamJson() { method = "reset" }, host.SysHotel.Code, host.RoomNumber);//重置小度 - } - }); + XiaoDuOperation.PostWebRequestToXiaoDu(accessToken, cuid, new XiaoDuParamJson() { method = "reset" }, host.SysHotel.Code, host.RoomNumber);//重置小度 + } + //Task.Factory.StartNew(() => + //{ + //}); } } if (!string.IsNullOrEmpty(host.TianMaoCUID)) { - System.Threading.Tasks.Task.Factory.StartNew(() => + + foreach (string cuid in host.TianMaoCUID.Split(','))//多个英文逗号隔开 { - foreach (string cuid in host.TianMaoCUID.Split(','))//多个英文逗号隔开 - { - TianMaoOperation.PostWebRequestToTianMao("CheckoutWithAK", - Newtonsoft.Json.JsonConvert.SerializeObject(new { HotelId = cuid.Split('&')[0], RoomNo = cuid.Split('&')[1] }), host.SysHotel.Code, host.RoomNumber);//重置天猫精灵 - } - }); + TianMaoOperation.PostWebRequestToTianMao("CheckoutWithAK", + Newtonsoft.Json.JsonConvert.SerializeObject(new { HotelId = cuid.Split('&')[0], RoomNo = cuid.Split('&')[1] }), host.SysHotel.Code, host.RoomNumber);//重置天猫精灵 + } + //Task.Factory.StartNew(() => + //{ + //}); } } @@ -595,12 +608,34 @@ namespace Service.Implement if (roomStatus.ID == 8) { #region 退房后空调控制 - HotelSeason hotelSeason = HotelSeasonRepository.LoadByHotelID(host.SysHotel.ID);//获取该酒店下季节设置记录 + HotelSeason hotelSeason = null; + string KKKOne = "HotelSeason_" + host.SysHotel.ID; + var ooss = MemoryCacheHelper.Get(KKKOne); + if (ooss != null) + { + hotelSeason = ooss as HotelSeason; + } + else + { + hotelSeason = HotelSeasonRepository.LoadByHotelID(host.SysHotel.ID);//获取该酒店下季节设置记录 + MemoryCacheHelper.Set(KKKOne, hotelSeason, DateTimeOffset.Now.AddMinutes(20)); + } if (hotelSeason != null) { //条件:1出租后,2取电后,3断电后 List list = HotelAirControlRepository.LoadAll(host.SysHotel.ID, 4, true); - List hostModals = HostModalRepository.LoadByHostID(host.ID).Where(r => r.Modal.Type == DeviceType.AirConditioner && r.Modal.ActiveIndicator).ToList();//获取启用的空调回路 + string KKK = "HostModalRepository_" + host.ID; + List hostModals = null; + var ooo = MemoryCacheHelper.Get(KKK); + if (ooo != null) + { + hostModals = ooo as List; + } + else + { + hostModals = HostModalRepository.LoadByHostID(host.ID).Where(r => r.Modal.Type == DeviceType.AirConditioner && r.Modal.ActiveIndicator).ToList();//获取启用的空调回路 + MemoryCacheHelper.Set(KKK, hostModals, DateTimeOffset.Now.AddMinutes(20)); + } if (list.Count > 0 && hostModals.Count > 0) { System.Reflection.PropertyInfo[] properties = typeof(HotelSeason).GetProperties();//获取所有属性 diff --git a/WebSite/Controllers/ApiController.cs b/WebSite/Controllers/ApiController.cs index d812e24..f29592f 100644 --- a/WebSite/Controllers/ApiController.cs +++ b/WebSite/Controllers/ApiController.cs @@ -604,6 +604,7 @@ namespace WebSite.Controllers //return Json(new { IsSuccess = false, Result = "接口修改调整" }, JsonRequestBehavior.AllowGet); try { + Interlocked.Increment(ref WebAPI_TongJi.GetRoomAirList); WebApiInvoke_FenXi("GetRoomAirList"); string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); @@ -646,7 +647,7 @@ namespace WebSite.Controllers }; list.Add(air); } - HttpContext.Cache.Insert(KKK, list, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration); + HttpContext.Cache.Insert(KKK, list, null, DateTime.Now.AddHours(1), Cache.NoSlidingExpiration); } string end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); @@ -703,6 +704,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { + Interlocked.Increment(ref WebAPI_TongJi.SetRCUAir); WebApiInvoke_FenXi("SetRCUAir"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); @@ -798,32 +800,45 @@ namespace WebSite.Controllers public ActionResult GetRoomSceneList(string jsonData) { + Interlocked.Increment(ref WebAPI_TongJi.GetRoomSceneList); string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { WebApiInvoke_FenXi("GetRoomSceneList"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); - Host host = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, roomNumber); - if (host == null) - { - return Json(new { IsSuccess = false, Result = msg }, JsonRequestBehavior.AllowGet); - } - IList modals = RoomTypeSceneManager.LoadAll().Where(r => r.RoomType.ID == host.RoomType.ID && r.ActiveIndicator).OrderBy(r => r.Sort).ToList(); - if (modals == null || modals.Count < 1) - { - return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置场景" }, JsonRequestBehavior.AllowGet); - } + string code = jData["code"].ToString(); + string cd = jData["creatDate"].ToString(); List list = new List(); - foreach (var modal in modals) + string KKK = "GetRoomSceneList_" + code + "_" + roomNumber + "_" + cd; + var ooo = HttpContext.Cache.Get(KKK); + if (ooo != null) { - SceneState sceneState = new SceneState + list = ooo as List; + } + else + { + Host host = CheckRoomNumber(code, cd, ref msg, ref hotelID, roomNumber); + if (host == null) { - SceneID = modal.ID, - Name = modal.Name, - Icon = modal.Icon - }; - list.Add(sceneState); + return Json(new { IsSuccess = false, Result = msg }, JsonRequestBehavior.AllowGet); + } + IList modals = RoomTypeSceneManager.LoadAll().Where(r => r.RoomType.ID == host.RoomType.ID && r.ActiveIndicator).OrderBy(r => r.Sort).ToList(); + if (modals == null || modals.Count < 1) + { + return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置场景" }, JsonRequestBehavior.AllowGet); + } + foreach (var modal in modals) + { + SceneState sceneState = new SceneState + { + SceneID = modal.ID, + Name = modal.Name, + Icon = modal.Icon + }; + list.Add(sceneState); + } + HttpContext.Cache.Insert(KKK, list, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0)); } string end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); @@ -846,6 +861,7 @@ namespace WebSite.Controllers public ActionResult SetRCUScene(string jsonData) { + Interlocked.Increment(ref WebAPI_TongJi.SetRCUScene); string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { @@ -864,7 +880,18 @@ namespace WebSite.Controllers string sceneID = jData["sceneID"].ToString();//场景ID:1、2、3 //string status = jData["status"].ToString();//状态:1开,2关 - var scene = RoomTypeSceneManager.Get(int.Parse(sceneID)); + RoomTypeScene scene = null; + string KKK = "SetSceneData_" + sceneID; + var ooo = HttpContext.Cache.Get(KKK); + if (ooo != null) + { + scene = ooo as RoomTypeScene; + } + else + { + scene = RoomTypeSceneManager.Get(int.Parse(sceneID)); + HttpContext.Cache.Insert(KKK, scene, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0)); + } if (scene == null) { return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]无效的场景" }, JsonRequestBehavior.AllowGet); @@ -892,58 +919,72 @@ namespace WebSite.Controllers /// public ActionResult GetRoomLightList(string jsonData) { + string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); //return Json(new { IsSuccess = false, Result = "接口修改调整" }, JsonRequestBehavior.AllowGet); try { + Interlocked.Increment(ref WebAPI_TongJi.GetRoomLightList); WebApiInvoke_FenXi("GetRoomLightList"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); - Host host = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, roomNumber); + string code = jData["code"].ToString(); + string cd = jData["creatDate"].ToString(); + Host host = CheckRoomNumber(code, cd, ref msg, ref hotelID, roomNumber); if (host == null) { return Json(new { IsSuccess = false, Result = msg }, JsonRequestBehavior.AllowGet); } - //IList hostModals = HostModalManager.LoadAll().Where(r => (r.Modal.Type == DeviceType.Relay || r.Modal.Type == DeviceType.Dimmer - // || r.Modal.Type == DeviceType.PWMDimmer || r.Modal.Type == DeviceType.Traic || r.Modal.Type == DeviceType.PWMExpand || r.Modal.Type == DeviceType.PBLED) - // && r.HostID == host.ID && r.Modal.ActiveIndicator == true).ToList(); - IList hostModals = HostModalManager.LoadByHostID(host.ID).Where(r => r.Modal.WXActiveIndicator).ToList(); - //if ((hostModals1 == null || hostModals1.Count < 1) && (hostModals2 == null || hostModals2.Count < 1)) - //{ - // return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置灯光或调光" }, JsonRequestBehavior.AllowGet); - //} IList list = new List(); - foreach (HostModal modal in hostModals) + + string KKK = "GetRoomLightList_" + code + "_" + roomNumber + "_" + cd; + var QQQ = HttpContext.Cache.Get(KKK); + if (QQQ != null) { - switch (modal.Modal.Type) + list = QQQ as IList; + } + else + { + //IList hostModals = HostModalManager.LoadAll().Where(r => (r.Modal.Type == DeviceType.Relay || r.Modal.Type == DeviceType.Dimmer + // || r.Modal.Type == DeviceType.PWMDimmer || r.Modal.Type == DeviceType.Traic || r.Modal.Type == DeviceType.PWMExpand || r.Modal.Type == DeviceType.PBLED) + // && r.HostID == host.ID && r.Modal.ActiveIndicator == true).ToList(); + IList hostModals = HostModalManager.LoadByHostID(host.ID).Where(r => r.Modal.WXActiveIndicator).ToList(); + //if ((hostModals1 == null || hostModals1.Count < 1) && (hostModals2 == null || hostModals2.Count < 1)) + //{ + // return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置灯光或调光" }, JsonRequestBehavior.AllowGet); + //} + foreach (HostModal modal in hostModals) { - case DeviceType.Relay://主机继电器 - case DeviceType.Dimmer://LED调光 - case DeviceType.PWMDimmer://PWM调光 - case DeviceType.PWMExpand://PWM扩展 - case DeviceType.PBLED: - case DeviceType.Traic://可控硅调光 - case DeviceType.Strip://灯带调光 - case DeviceType.A9IORelay: - case DeviceType.LVout://弱电输出 - case DeviceType.Expand://扩展继电器 - case DeviceType.PB20: - case DeviceType.PB20_LD: - case DeviceType.PB20_LS: - Light light = new Light - { - Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), - ModalAddress = modal.Modal.ModalAddress, - Status = modal.Status, - Brightness = modal.Brightness - }; - list.Add(light); - break; + switch (modal.Modal.Type) + { + case DeviceType.Relay://主机继电器 + case DeviceType.Dimmer://LED调光 + case DeviceType.PWMDimmer://PWM调光 + case DeviceType.PWMExpand://PWM扩展 + case DeviceType.PBLED: + case DeviceType.Traic://可控硅调光 + case DeviceType.Strip://灯带调光 + case DeviceType.A9IORelay: + case DeviceType.LVout://弱电输出 + case DeviceType.Expand://扩展继电器 + case DeviceType.PB20: + case DeviceType.PB20_LD: + case DeviceType.PB20_LS: + Light light = new Light + { + Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), + ModalAddress = modal.Modal.ModalAddress, + Status = modal.Status, + Brightness = modal.Brightness + }; + list.Add(light); + break; + } } + HttpContext.Cache.Insert(KKK, list, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0)); } string end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); - TongJi(jsonData, start_time, end_time, jData, "GetRoomLightList"); //SaveSystemLog(AuthorityID, HttpContext.InnerLanguage("LightControl"), "获取客房" + roomNumber + "灯光信息", true, "api", hotelID); return Json(new { IsSuccess = true, Result = list }, JsonRequestBehavior.AllowGet); @@ -964,6 +1005,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { + Interlocked.Increment(ref WebAPI_TongJi.SetRCULight); WebApiInvoke_FenXi("SetRCULight"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); @@ -1014,29 +1056,42 @@ namespace WebSite.Controllers //return Json(new { IsSuccess = false, Result = "接口修改调整" }, JsonRequestBehavior.AllowGet); try { + Interlocked.Increment(ref WebAPI_TongJi.GetRoomCurtainList); WebApiInvoke_FenXi("GetRCUStatus"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); - Host host = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, roomNumber); + string code = jData["code"].ToString(); + string cd = jData["creatDate"].ToString(); + Host host = CheckRoomNumber(code, cd, ref msg, ref hotelID, roomNumber); if (host == null) { return Json(new { IsSuccess = false, Result = msg }, JsonRequestBehavior.AllowGet); } - IList hostModals = HostModalManager.Load(host.ID, DeviceType.Curtain).Where(r => r.Modal.WXActiveIndicator).ToList(); - if (hostModals == null || hostModals.Count < 1) - { - return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置窗帘" }, JsonRequestBehavior.AllowGet); - } IList list = new List(); - foreach (HostModal modal in hostModals) + string KKK = "GetRoomCurtainList_" + code + "_" + roomNumber + "_" + code; + var data = HttpContext.Cache.Get(KKK); + if (data != null) { - Curtain curtain = new Curtain + list = data as IList; + } + else + { + IList hostModals = HostModalManager.Load(host.ID, DeviceType.Curtain).Where(r => r.Modal.WXActiveIndicator).ToList(); + if (hostModals == null || hostModals.Count < 1) { - Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), - ModalAddress = modal.Modal.ModalAddress, - Status = modal.Status - }; - list.Add(curtain); + return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置窗帘" }, JsonRequestBehavior.AllowGet); + } + foreach (HostModal modal in hostModals) + { + Curtain curtain = new Curtain + { + Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), + ModalAddress = modal.Modal.ModalAddress, + Status = modal.Status + }; + list.Add(curtain); + } + HttpContext.Cache.Insert(KKK, list, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0)); } string end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); @@ -1062,6 +1117,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { + Interlocked.Increment(ref WebAPI_TongJi.SetRCUCurtain); WebApiInvoke_FenXi("SetRCUCurtain"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); @@ -1111,6 +1167,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { + Interlocked.Increment(ref WebAPI_TongJi.GetRoomMusicList); WebApiInvoke_FenXi("GetRoomMusicList"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); @@ -1161,6 +1218,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { + Interlocked.Increment(ref WebAPI_TongJi.SetRCUMusic); WebApiInvoke_FenXi("SetRCUMusic"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); @@ -1251,31 +1309,44 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { - + Interlocked.Increment(ref WebAPI_TongJi.GetRoomServiceList); WebApiInvoke_FenXi("GetRoomServiceList"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); - Host host = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, roomNumber); + string code = jData["code"].ToString(); + string cd = jData["creatDate"].ToString(); + Host host = CheckRoomNumber(code, cd, ref msg, ref hotelID, roomNumber); if (host == null) { return Json(new { IsSuccess = false, Result = msg }, JsonRequestBehavior.AllowGet); } - IList hostModals = HostModalManager.Load(host.ID, DeviceType.ServiceInfo).Where(r => r.Modal.WXActiveIndicator).ToList(); - if (hostModals == null || hostModals.Count < 1) - { - return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置服务信息" }, JsonRequestBehavior.AllowGet); - } - //logger.Error(string.Format("api获取酒店{0}客房{1}服务列表,来自{2}", jData["code"].ToString(), roomNumber, GetClientIP())); IList list = new List(); - foreach (HostModal modal in hostModals) + + string KKK = "GetRoomServiceList_" + code + "_" + roomNumber + "_" + cd; + var data = HttpContext.Cache.Get(KKK); + if (data != null) { - Light light = new Light + list = data as IList; + } + else + { + IList hostModals = HostModalManager.Load(host.ID, DeviceType.ServiceInfo).Where(r => r.Modal.WXActiveIndicator).ToList(); + if (hostModals == null || hostModals.Count < 1) { - Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), - ModalAddress = modal.Modal.ModalAddress, - Status = modal.Status - }; - list.Add(light); + return Json(new { IsSuccess = false, Result = "房号[" + roomNumber + "]未配置服务信息" }, JsonRequestBehavior.AllowGet); + } + //logger.Error(string.Format("api获取酒店{0}客房{1}服务列表,来自{2}", jData["code"].ToString(), roomNumber, GetClientIP())); + foreach (HostModal modal in hostModals) + { + Light light = new Light + { + Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), + ModalAddress = modal.Modal.ModalAddress, + Status = modal.Status + }; + list.Add(light); + } + HttpContext.Cache.Insert(KKK, list, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0)); } string end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); @@ -1299,6 +1370,7 @@ namespace WebSite.Controllers { try { + Interlocked.Increment(ref WebAPI_TongJi.SetRCUService); WebApiInvoke_FenXi("SetRCUService"); string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); @@ -1389,7 +1461,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { - + Interlocked.Increment(ref WebAPI_TongJi.GetOperationLog); WebApiInvoke_FenXi("GetOperationLog"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); Host host = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, ""); @@ -1444,26 +1516,39 @@ namespace WebSite.Controllers try { - + Interlocked.Increment(ref WebAPI_TongJi.GetAirDetectList); WebApiInvoke_FenXi("GetAirDetectList"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); - Host host = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, roomNumber); - if (host == null) - { - return Json(new { IsSuccess = false, Result = msg }, JsonRequestBehavior.AllowGet); - } + string code = jData["code"].ToString(); + string cd = jData["creatDate"].ToString(); IList list = new List(); - var hostModals = HostModalManager.Load(host.ID, DeviceType.AirDetect).Where(r => r.Modal.WXActiveIndicator); - foreach (HostModal modal in hostModals) + + string KKK = "GetAirDetectList_" + code + "_" + roomNumber + "_" + cd; + var ooo = HttpContext.Cache.Get(KKK); + if (ooo != null) { - Light light = new Light + list = ooo as IList; + } + else + { + Host host = CheckRoomNumber(code, cd, ref msg, ref hotelID, roomNumber); + if (host == null) { - Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), - ModalAddress = modal.Modal.ModalAddress, - Brightness = modal.Brightness - }; - list.Add(light); + return Json(new { IsSuccess = false, Result = msg }, JsonRequestBehavior.AllowGet); + } + var hostModals = HostModalManager.Load(host.ID, DeviceType.AirDetect).Where(r => r.Modal.WXActiveIndicator); + foreach (HostModal modal in hostModals) + { + Light light = new Light + { + Name = ReturnNameByLanguage(modal.Modal.Name, modal.Modal.EnglishName, modal.Modal.TWName), + ModalAddress = modal.Modal.ModalAddress, + Brightness = modal.Brightness + }; + list.Add(light); + } + HttpContext.Cache.Insert(KKK, list, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 30, 0)); } string end_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); @@ -1494,7 +1579,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { - + Interlocked.Increment(ref WebAPI_TongJi.GetHostFaultList); WebApiInvoke_FenXi("GetHostFaultList"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string roomNumber = jData["roomNumber"].ToString(); @@ -1623,7 +1708,7 @@ namespace WebSite.Controllers string start_time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff"); try { - + Interlocked.Increment(ref WebAPI_TongJi.GetRoomTypeAndModalsList); WebApiInvoke_FenXi("GetRoomTypeAndModalsList"); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); Host host1 = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, ""); @@ -2465,6 +2550,7 @@ namespace WebSite.Controllers { try { + Interlocked.Increment(ref WebAPI_TongJi.GetSessionKey); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string code = jData["code"].ToString(); string appid = jData["appid"].ToString(); @@ -2501,6 +2587,7 @@ namespace WebSite.Controllers { try { + Interlocked.Increment(ref WebAPI_TongJi.GetPhoneNumber); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string encryptedData = jData["encrypted_data"].ToString(); string iv = jData["iv"].ToString(); @@ -2539,6 +2626,7 @@ namespace WebSite.Controllers { try { + Interlocked.Increment(ref WebAPI_TongJi.GetHotelInfoForWX); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); string phone = jData["phone"].ToString(); if (string.IsNullOrEmpty(phone)) @@ -3210,6 +3298,7 @@ namespace WebSite.Controllers { try { + Interlocked.Increment(ref WebAPI_TongJi.GetRCUInfoForPDU); JObject jData = (JObject)JsonConvert.DeserializeObject(jsonData); Host host1 = CheckRoomNumber(jData["code"].ToString(), jData["creatDate"].ToString(), ref msg, ref hotelID, ""); if (host1 == null && hotelID == 0) @@ -5284,6 +5373,76 @@ namespace WebSite.Controllers string mns3 = Newtonsoft.Json.JsonConvert.SerializeObject(ux2); CSRedisCacheHelper.redis3.Publish("redis-udppackage", mns3); + + long l1 = Interlocked.Read(ref WebAPI_TongJi.GetRoomAirList); + long l2 = Interlocked.Read(ref WebAPI_TongJi.SetRCUAir); + long l3 = Interlocked.Read(ref WebAPI_TongJi.GetRoomSceneList); + long l4 = Interlocked.Read(ref WebAPI_TongJi.SetRCUScene); + long l5 = Interlocked.Read(ref WebAPI_TongJi.GetRoomLightList); + long l6 = Interlocked.Read(ref WebAPI_TongJi.SetRCULight); + long l7 = Interlocked.Read(ref WebAPI_TongJi.GetRoomCurtainList); + long l8 = Interlocked.Read(ref WebAPI_TongJi.SetRCUCurtain); + long l9 = Interlocked.Read(ref WebAPI_TongJi.GetRoomServiceList); + long l10 = Interlocked.Read(ref WebAPI_TongJi.SetRCUService); + long l11 = Interlocked.Read(ref WebAPI_TongJi.GetOperationLog); + long l12 = Interlocked.Read(ref WebAPI_TongJi.GetRoomMusicList); + long l13 = Interlocked.Read(ref WebAPI_TongJi.SetRCUMusic); + long l14 = Interlocked.Read(ref WebAPI_TongJi.GetRCUStatus); + long l15 = Interlocked.Read(ref WebAPI_TongJi.GetAirDetectList); + long l16 = Interlocked.Read(ref WebAPI_TongJi.GetHostFaultList); + long l17 = Interlocked.Read(ref WebAPI_TongJi.GetRoomTypeAndModalsList); + long l18 = Interlocked.Read(ref WebAPI_TongJi.GetRCUInfoForPDU); + long l19 = Interlocked.Read(ref WebAPI_TongJi.GetSessionKey); + long l20 = Interlocked.Read(ref WebAPI_TongJi.GetPhoneNumber); + long l21 = Interlocked.Read(ref WebAPI_TongJi.GetHotelInfoForWX); + + Dictionary dicwebapidata = new Dictionary(); + dicwebapidata.Add("GetRoomAirList", l1); + dicwebapidata.Add("SetRCUAir", l2); + dicwebapidata.Add("GetRoomSceneList", l3); + dicwebapidata.Add("SetRCUScene", l4); + dicwebapidata.Add("GetRoomLightList", l5); + dicwebapidata.Add("SetRCULight", l6); + dicwebapidata.Add("GetRoomCurtainList", l7); + dicwebapidata.Add("SetRCUCurtain", l8); + dicwebapidata.Add("GetRoomServiceList", l9); + dicwebapidata.Add("SetRCUService", l10); + dicwebapidata.Add("GetOperationLog", l11); + dicwebapidata.Add("GetRoomMusicList", l12); + dicwebapidata.Add("SetRCUMusic", l13); + dicwebapidata.Add("GetRCUStatus", l14); + dicwebapidata.Add("GetAirDetectList", l15); + dicwebapidata.Add("GetHostFaultList", l16); + dicwebapidata.Add("GetRoomTypeAndModalsList", l17); + dicwebapidata.Add("GetRCUInfoForPDU", l18); + dicwebapidata.Add("GetSessionKey", l19); + dicwebapidata.Add("GetPhoneNumber", l20); + dicwebapidata.Add("GetHotelInfoForWX", l21); + + CSRedisCacheHelper.Publish("webapidata_consumer", JsonConvert.SerializeObject(dicwebapidata)); + + + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomAirList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUAir, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomSceneList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUScene, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomLightList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCULight, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomCurtainList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUCurtain, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomServiceList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUService, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetOperationLog, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomMusicList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUMusic, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRCUStatus, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetAirDetectList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetHostFaultList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomTypeAndModalsList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRCUInfoForPDU, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetSessionKey, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetPhoneNumber, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetHotelInfoForWX, 0); //logger.Error("推送的走到这里了"); //DataTongJi.TotalCount.Clear(); Interlocked.Exchange(ref YUANZI_TongJi.TotalReceiveCount, 0); @@ -5540,6 +5699,75 @@ namespace WebSite.Controllers string mns3 = Newtonsoft.Json.JsonConvert.SerializeObject(ux2); CSRedisCacheHelper.redis3.Publish("redis-udppackage", mns3); + long l1 = Interlocked.Read(ref WebAPI_TongJi.GetRoomAirList); + long l2 = Interlocked.Read(ref WebAPI_TongJi.SetRCUAir); + long l3 = Interlocked.Read(ref WebAPI_TongJi.GetRoomSceneList); + long l4 = Interlocked.Read(ref WebAPI_TongJi.SetRCUScene); + long l5 = Interlocked.Read(ref WebAPI_TongJi.GetRoomLightList); + long l6 = Interlocked.Read(ref WebAPI_TongJi.SetRCULight); + long l7 = Interlocked.Read(ref WebAPI_TongJi.GetRoomCurtainList); + long l8 = Interlocked.Read(ref WebAPI_TongJi.SetRCUCurtain); + long l9 = Interlocked.Read(ref WebAPI_TongJi.GetRoomServiceList); + long l10 = Interlocked.Read(ref WebAPI_TongJi.SetRCUService); + long l11 = Interlocked.Read(ref WebAPI_TongJi.GetOperationLog); + long l12 = Interlocked.Read(ref WebAPI_TongJi.GetRoomMusicList); + long l13 = Interlocked.Read(ref WebAPI_TongJi.SetRCUMusic); + long l14 = Interlocked.Read(ref WebAPI_TongJi.GetRCUStatus); + long l15 = Interlocked.Read(ref WebAPI_TongJi.GetAirDetectList); + long l16 = Interlocked.Read(ref WebAPI_TongJi.GetHostFaultList); + long l17 = Interlocked.Read(ref WebAPI_TongJi.GetRoomTypeAndModalsList); + long l18 = Interlocked.Read(ref WebAPI_TongJi.GetRCUInfoForPDU); + long l19 = Interlocked.Read(ref WebAPI_TongJi.GetSessionKey); + long l20 = Interlocked.Read(ref WebAPI_TongJi.GetPhoneNumber); + long l21 = Interlocked.Read(ref WebAPI_TongJi.GetHotelInfoForWX); + + Dictionary dicwebapidata = new Dictionary(); + dicwebapidata.Add("GetRoomAirList", l1); + dicwebapidata.Add("SetRCUAir", l2); + dicwebapidata.Add("GetRoomSceneList", l3); + dicwebapidata.Add("SetRCUScene", l4); + dicwebapidata.Add("GetRoomLightList", l5); + dicwebapidata.Add("SetRCULight", l6); + dicwebapidata.Add("GetRoomCurtainList", l7); + dicwebapidata.Add("SetRCUCurtain", l8); + dicwebapidata.Add("GetRoomServiceList", l9); + dicwebapidata.Add("SetRCUService", l10); + dicwebapidata.Add("GetOperationLog", l11); + dicwebapidata.Add("GetRoomMusicList", l12); + dicwebapidata.Add("SetRCUMusic", l13); + dicwebapidata.Add("GetRCUStatus", l14); + dicwebapidata.Add("GetAirDetectList", l15); + dicwebapidata.Add("GetHostFaultList", l16); + dicwebapidata.Add("GetRoomTypeAndModalsList", l17); + dicwebapidata.Add("GetRCUInfoForPDU", l18); + dicwebapidata.Add("GetSessionKey", l19); + dicwebapidata.Add("GetPhoneNumber", l20); + dicwebapidata.Add("GetHotelInfoForWX", l21); + + CSRedisCacheHelper.Publish("webapidata_consumer", JsonConvert.SerializeObject(dicwebapidata)); + + + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomAirList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUAir, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomSceneList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUScene, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomLightList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCULight, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomCurtainList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUCurtain, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomServiceList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUService, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetOperationLog, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomMusicList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.SetRCUMusic, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRCUStatus, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetAirDetectList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetHostFaultList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRoomTypeAndModalsList, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetRCUInfoForPDU, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetSessionKey, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetPhoneNumber, 0); + Interlocked.Exchange(ref WebAPI_TongJi.GetHotelInfoForWX, 0); //logger.Error("推送的走到这里了"); //DataTongJi.TotalCount.Clear(); Interlocked.Exchange(ref YUANZI_TongJi.TotalReceiveCount, 0); @@ -5742,8 +5970,17 @@ namespace WebSite.Controllers [HttpPost()] public ActionResult GetRCUStatus(string host_number, string mac) { - bool is_online = CSRedisCacheHelper.Contains(host_number, mac); - return Json(is_online, JsonRequestBehavior.AllowGet); + + Interlocked.Increment(ref WebAPI_TongJi.GetRCUStatus); + try + { + bool is_online = CSRedisCacheHelper.Contains(host_number, mac); + return Json(is_online, JsonRequestBehavior.AllowGet); + } + catch (Exception ex) + { + return Json(false, JsonRequestBehavior.AllowGet); + } } #endregion diff --git a/WebSite/Global.asax.cs b/WebSite/Global.asax.cs index 64dd7de..6e9e1fd 100644 --- a/WebSite/Global.asax.cs +++ b/WebSite/Global.asax.cs @@ -786,6 +786,9 @@ namespace WebSite Exception ex = Server.GetLastError(); logger.Error("IIS:" + ex.Message); logger.Error(ex.StackTrace); + + // 清理可能导致循环异常的资源 + HttpContext.Current.ClearError(); } catch (Exception ex) { @@ -802,9 +805,9 @@ namespace WebSite var ip = Request.UserHostAddress; var url = Request.Url.AbsolutePath.ToLower(); - // 定期清理恶意IP记录,避免字典无限增长 - var nowUtc = DateTime.UtcNow; - CleanupIpRecordIfNeeded(nowUtc); + // 定期清理恶意IP记录,避免字典无限增长 + var nowUtc = DateTime.UtcNow; + CleanupIpRecordIfNeeded(nowUtc); // 定义要拦截的路径模式 var maliciousPatterns = new[] diff --git a/WebSite/Web.config b/WebSite/Web.config index 30ae184..d931d6f 100644 --- a/WebSite/Web.config +++ b/WebSite/Web.config @@ -1,119 +1,114 @@ - - + - -
-
+
+
-
-
-
+
+
+
-
+
- - + - - - + + + - + - + - + - - - - - - - + + + + + + + - + - + - + - + - - + + - - - + + - + - - + + - + - - - + + - - - + + + - - - - + + + + - + - - + + @@ -121,29 +116,28 @@ - - - - - + + + + + - - - - - - - - - - - - - - + + + + + + + + + + + + + - - + + - - - - - - - - - - - - + + + + + + + - - - - + - - - - - - - - + + + + + + - - + - + - - + - + - - - - - + + - - - + + + - - + - - - - - + + + + - - + - - + - - + - + - + - - + + - - - + + - - + + - - + + - - + + - - - - - - + + + + + - - - - - + + + + + \ No newline at end of file