diff --git a/CRICS_V3_1124.suo b/CRICS_V3_1124.suo index db114a0..fd26002 100644 Binary files a/CRICS_V3_1124.suo and b/CRICS_V3_1124.suo differ diff --git a/CommonEntity/CacheKey.cs b/CommonEntity/CacheKey.cs index ba3bfee..7fb01f8 100644 --- a/CommonEntity/CacheKey.cs +++ b/CommonEntity/CacheKey.cs @@ -85,6 +85,7 @@ namespace CommonEntity /// public static string XiaoDuYuYin = "XiaoDuYuYin"; public static string TCLYuYin = "TCLYuYin"; + public static string ETV_YuYin = "ETV_YuYin"; public static string PublicKeyboard = "PublicKeyboard"; diff --git a/Dao/ISysHotelRepository.cs b/Dao/ISysHotelRepository.cs index 49eb799..e29ff13 100644 --- a/Dao/ISysHotelRepository.cs +++ b/Dao/ISysHotelRepository.cs @@ -17,6 +17,8 @@ namespace Dao SysHotel GetByDomainUrl(string domainUrl); + SysHotel GetByETV_HotelId(string hotelid); + IList GetByGroup(SysHotelGroup group); List GetNeedData(); diff --git a/Dao/Implement/SysHotelRepository.cs b/Dao/Implement/SysHotelRepository.cs index fe4866e..a568922 100644 --- a/Dao/Implement/SysHotelRepository.cs +++ b/Dao/Implement/SysHotelRepository.cs @@ -201,5 +201,11 @@ namespace Dao.Implement return list; } } + + + public SysHotel GetByETV_HotelId(string hotelid) + { + return LoadAll().Where(r => r.ETV_HotelID.Equals(hotelid) && r.IsDeleted != true).OrderBy(r => r.Sort).FirstOrDefault(); + } } } diff --git a/Domain/SysHotel.cs b/Domain/SysHotel.cs index 153157f..3cebbf4 100644 --- a/Domain/SysHotel.cs +++ b/Domain/SysHotel.cs @@ -439,5 +439,6 @@ namespace Domain ///// ///// //public virtual string TCLAppSecret { get; set; } + public virtual string ETV_HotelID { get; set; } } } diff --git a/Domain/SysHotel.hbm.xml b/Domain/SysHotel.hbm.xml index 8c4f94a..8cacd5b 100644 --- a/Domain/SysHotel.hbm.xml +++ b/Domain/SysHotel.hbm.xml @@ -73,6 +73,7 @@ + diff --git a/RCUHost/Implement/HostServer.cs b/RCUHost/Implement/HostServer.cs index d14d71f..46e61cf 100644 --- a/RCUHost/Implement/HostServer.cs +++ b/RCUHost/Implement/HostServer.cs @@ -188,7 +188,7 @@ namespace RCUHost.Implement { logger.Error("Host Server启动失败,端口:3339"); Close(); - throw ex;//不能去掉,否则重启iis服务,通讯服务不会再次启动 + //throw ex;//不能去掉,否则重启iis服务,通讯服务不会再次启动 } } /// @@ -1517,10 +1517,13 @@ namespace RCUHost.Implement byte cmdTypeTTT = context.SystemHeader.Value.CmdType; if (cmdTypeTTT == 0x36) { - IReceiver receiver = receivers[(CommandType)0x36]; - if (receiver != null) + if (receivers.ContainsKey((CommandType)0x36)) { - (receiver as GenericReceiverBase).Process(context);//处理业务逻辑 + IReceiver receiver = receivers[((CommandType)0x36)]; + if (receiver != null) + { + (receiver as GenericReceiverBase).Process(context);//处理业务逻辑 + } } } else diff --git a/Service/ISysHotelManager.cs b/Service/ISysHotelManager.cs index 1a8de8d..fb2b8a6 100644 --- a/Service/ISysHotelManager.cs +++ b/Service/ISysHotelManager.cs @@ -19,6 +19,7 @@ namespace Service SysHotel GetByAssociatedAccount(string associatedAccount); SysHotel GetByDomainUrl(string domainUrl); + SysHotel GetByETV_HotelId(string ETVHotelID); void UpdateDayTime(SysHotel entity); diff --git a/Service/Implement/HostManager.cs b/Service/Implement/HostManager.cs index 717f888..4112966 100644 --- a/Service/Implement/HostManager.cs +++ b/Service/Implement/HostManager.cs @@ -791,6 +791,16 @@ namespace Service.Implement { if (prop.Name == "Month" + DateTime.Now.Month.ToString() && Convert.ToInt16(prop.GetValue(hotelSeason, null)) == item.Season)//当前月份所属该季节,则发送命令给rcu设置空调 { + //System.Threading.Thread.Sleep(item.DelayTime * 1000);//延迟执行 + //foreach (HostModal hostModal in hostModals) + //{ + // //host 只需要hostnumber和mac + // //hostmodal只需要 address //和type + // //device.Address = hostModal.Modal.ModalAddress; + // //device.Type = hostModal.Modal.Type; + // HostModalManager.SetDevice(host, hostModal, item.Status, 0, item.SettingTemp, item.FanSpeed, item.Mode, 0);//0表示不变 + //} + var TTT = new Tuple>(host, item, hostModals); Task.Factory.StartNew((state) => { @@ -810,8 +820,8 @@ namespace Service.Implement HostModalManager.SetDevice(QQ0, hostModal, QQ1.Status, 0, QQ1.SettingTemp, QQ1.FanSpeed, QQ1.Mode, 0);//0表示不变 } }, TTT); - try - { + //try + //{ //这段代码在生产环境中不管用,很奇怪 //string KeyMission = System.Guid.NewGuid().ToString("N"); @@ -835,12 +845,12 @@ namespace Service.Implement //CSRedisCacheHelper.Set_Partition(MKey, m, 1); //DelayExe_Task(host, item.DelayTime, KeyMission); - break; - } - catch (Exception) - { + // break; + //} + //catch (Exception) + //{ - } + //} } } } diff --git a/Service/Implement/SysHotelManager.cs b/Service/Implement/SysHotelManager.cs index 4a8b459..e91e5d0 100644 --- a/Service/Implement/SysHotelManager.cs +++ b/Service/Implement/SysHotelManager.cs @@ -162,5 +162,11 @@ namespace Service.Implement { return ((ISysHotelRepository)(this.CurrentRepository)).LoadAll().Where(A=>!A.IsDeleted&&A.FCSPushEnable).ToList(); } + + + public SysHotel GetByETV_HotelId(string hotelid) + { + return ((ISysHotelRepository)(this.CurrentRepository)).GetByETV_HotelId(hotelid); + } } } diff --git a/WebSite/Controllers/IoTController.cs b/WebSite/Controllers/IoTController.cs index 16b09e8..3645f9d 100644 --- a/WebSite/Controllers/IoTController.cs +++ b/WebSite/Controllers/IoTController.cs @@ -6751,7 +6751,7 @@ namespace WebSite.Controllers else { hostModal = HostModalManager.GetByModalAddress(host.ID, modalAddress);//设备控制 - HttpContext.Cache.Insert(MKey,hostModal,null,DateTime.Now.AddMinutes(30),Cache.NoSlidingExpiration); + HttpContext.Cache.Insert(MKey, hostModal, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration); } if (hostModal == null) { @@ -7177,6 +7177,444 @@ namespace WebSite.Controllers // return Json(ex.Message, JsonRequestBehavior.AllowGet); // } //} + + + /// + /// ETV-艺龙酒店(绥化北林店)728893 + /// 授权接口 + /// + /// + [HttpPost()] + public ActionResult ETV_Auth() + { + Request.InputStream.Position = 0; + byte[] reqBody = new byte[Request.InputStream.Length]; + Request.InputStream.Read(reqBody, 0, reqBody.Length); + string reqData = System.Text.Encoding.UTF8.GetString(reqBody); + var ttt = JsonConvert.DeserializeObject(reqData); + + //clientId: a6f3270f77b545a087daa1caed816b3b + //clientSecret:8854e0b8261b49d6989b5b2f39bd157a + if (ttt.clientId.Equals("a6f3270f77b545a087daa1caed816b3b") && ttt.clientSecret.Equals("8854e0b8261b49d6989b5b2f39bd157a")) + { + var token = Guid.NewGuid().ToString("N"); + string kkk = "ETVKey"; + CSRedisCacheHelper.Set_PartitionWithTime(kkk, token, 7 * 24 * 60, 5); + + TV_ResponseData c = new TV_ResponseData(); + c.code = 200; + c.msg = null; + c.data = new TTT_Data() + { + token = token, + expiresIn = 7 * 24 * 60 * 60 + }; + //{ + // "code": 200, + // "msg": null, + // "data": { + // "token": "74b87337454200d4d33f80c4663dc5e5", + // "expiresIn": 154589 + // } + //} + + return Json(c, JsonRequestBehavior.AllowGet); + } + else + { + + TV_ResponseData c = new TV_ResponseData(); + c.code = 500; + c.msg = "鉴权数据错误"; + c.data = null; + return Json(c, JsonRequestBehavior.AllowGet); + } + } + /// + /// 两天时间要对接完,时间紧迫,数据先写死 + /// + public static Dictionary ETVDic = new Dictionary() + { + //艺龙酒店(绥化北林万达广场店) + {"1668326697184","1213"} + }; + + [HttpPost()] + public ActionResult ETV_Controller() + { + try + { + string IP = ""; + string PPP = Request.UserHostAddress; + string III = Request.ServerVariables["REMOTE_ADDR"]; + if (string.IsNullOrEmpty(III)) + { + IP = PPP; + } + else + { + IP = III; + } + var token = Request.Headers["Authorization"]; + string kkk = "ETVKey"; + var t_take = CSRedisCacheHelper.Get_Partition(kkk, 5); + //t_take = "abc"; + if (t_take == null || !t_take.Equals(token)) + { + return Json(new { code = 500, msg = "token已经过期" }, JsonRequestBehavior.AllowGet); + } + Request.InputStream.Position = 0; + byte[] reqBody = new byte[Request.InputStream.Length]; + Request.InputStream.Read(reqBody, 0, reqBody.Length); + string reqData = System.Text.Encoding.UTF8.GetString(reqBody); + + var ttt = JsonConvert.DeserializeObject(reqData); + + string hotelid_WANBU = ttt.hotelId; + + //var hotelid = ETVDic[hotelid_WANBU]; + string hotelid = ""; + int hotelid_int = 0; + //int.TryParse(hotelid, out hotelid_int); + + SysHotel hotel_sys = null; + string KKKHotel = "HotelInfoETV_" + hotelid_WANBU; + var hotel_ooo = HttpContext.Cache.Get(KKKHotel); + if (hotel_ooo != null) + { + hotel_sys = hotel_ooo as SysHotel; + } + else + { + hotel_sys = SysHotelManager.GetByETV_HotelId(hotelid_WANBU); + HttpContext.Cache.Insert(KKKHotel, hotel_sys, null, Cache.NoAbsoluteExpiration, new TimeSpan(0, 20, 0)); + } + if (hotel_sys != null) + { + hotelid_int = hotel_sys.ID; + hotelid = hotel_sys.ID.ToString(); + } + else + { + return Json(new { code = 500, msg = "找不到此酒店" }, JsonRequestBehavior.AllowGet);//"小度音箱(" + request.payload.cuid + ")尚未绑定客房主机" + } + + string msgid = Guid.NewGuid().ToString("N"); + string roomNo = ttt.roomNo; + string traceId = ttt.traceId; + string domain = ttt.domain; + string intent = ttt.intent; + List slots = ttt.slots; + + + bool is_monitor = true; + if (is_monitor) + { + IOTMonitorData i = new IOTMonitorData(); + i.RemoteIP = IP; + i.Step = 0; + string ti =DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff"); + i.CreateTime = DateTime.Now; + i.TriggerTime = ti; + i.HotelId = hotelid; + i.HotelCode = int.Parse(hotel_sys.Code); + i.RoomNumber = roomNo; + i.RequestId = msgid; + i.Platform = "ETV"; + i.CommandDescription = reqData; + SendMQTTData.Send(i); + } + Host host = null; + string ETVKongZhiKey = CacheKey.ETV_YuYin + "_" + hotelid + "_" + roomNo; + var UXV = HttpContext.Cache.Get(ETVKongZhiKey); + if (UXV != null) + { + host = UXV as Host; + } + else + { + // host = HostManager.GetByXiaoDuCUID(XiaoDuCUID);//根据小度音箱序列号获取对应RCU主机 + host = HostManager.GetByRoomNumber(roomNo, hotelid_int); + if (host != null) + { + string code = host.SysHotel.Code; + string roomno = host.RoomNumber; + HttpContext.Cache.Insert(ETVKongZhiKey, host, null, DateTime.Now.AddMinutes(20), Cache.NoSlidingExpiration); + } + } + + if (host == null) + { + return Json(new { code = 500, msg = "找不到此房间" }, JsonRequestBehavior.AllowGet);//"小度音箱(" + request.payload.cuid + ")尚未绑定客房主机" + } + + int hotelcode = 0; + int.TryParse(host.SysHotel.Code, out hotelcode); + + bool is_online = Common.CSRedisCacheHelper.Contains(host.HostNumber, host.MAC); + + if (true) + { + string sss = "酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")房间号:(" + host.RoomNumber + ") is_online: " + is_online.ToString(); + IOTMonitorData i = new IOTMonitorData(); + i.ControlClass = ControlClass_KongZhiSheBei; + i.Step = 1; + i.CreateTime = DateTime.Now; + string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff"); + i.TriggerTime = ti; + i.HotelId = hotelid; + i.HotelCode = int.Parse(host.SysHotel.Code); + i.RoomNumber = roomNo; + i.RequestId = msgid; + i.Platform = "ETV"; + i.CommandDescription = sss; + SendMQTTData.Send(i); + } + if (!is_online) + { + logger.Error("ETV当前访问酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")客房rcu(" + host.RoomNumber + ")不在线"); + return Json(new { code = 500, msg = "当前客户已经离线" }, JsonRequestBehavior.AllowGet); + } + + + bool is_take_card = CheckGetPower(host); + + if (true) + { + string sss = "酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")房间号:(" + host.RoomNumber + ") 取电: " + is_take_card.ToString(); + IOTMonitorData i = new IOTMonitorData(); + i.Step = 2; + i.CreateTime = DateTime.Now; + string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff"); + i.TriggerTime = ti; + i.HotelId = hotelid; + i.HotelCode = hotelcode; + i.RoomNumber = roomNo; + i.RequestId = msgid; + i.Platform = "ETV"; + i.CommandDescription = sss; + SendMQTTData.Send(i); + } + if (!is_take_card) + { + logger.Error("ETV当前访问酒店(" + host.SysHotel.Name + host.SysHotel.Code + ")客房rcu(" + host.RoomNumber + ")尚未取电"); + return Json(new { code = 500, msg = "只有取电后才能控制" }, JsonRequestBehavior.AllowGet); + } + + IList hostModals = null; + + string Hkey = "ETVIOT_" + host.ID; + var dataH = HttpContext.Cache.Get(Hkey); + if (dataH != null) + { + hostModals = dataH as IList; + } + else + { + hostModals = HostModalManager.LoadByHostID(host.ID).Where(r => r.Modal.WXActiveIndicator).ToList(); + if (hostModals != null && hostModals.Count > 0) + { + HttpContext.Cache.Insert(Hkey, hostModals, null, DateTime.Now.AddMinutes(30), Cache.NoSlidingExpiration); + } + } + // hostmodal只需要 address 和type + // device.Address = hostModal.Modal.ModalAddress; + // device.Type = hostModal.Modal.Type + if (intent.Equals("IOT.Light") || intent.Equals("IOT.Switch") || intent.Equals("IOT.Curtain")) + { + foreach (var item in slots) + { + var action = item.action; + var name = item.applianceName; + List q1 = new List(); + if (name.Equals("灯")) + { + q1 = hostModals.Where(A => A.Modal.Name.Contains("灯")).ToList(); + } + else + { + q1 = hostModals.Where(A => A.Modal.Name.Equals(name)||A.Modal.AliasName.Equals(name)).ToList(); + } + if (q1 != null && q1.Count > 0) + { + foreach (var item_inter in q1) + { + int status = 0; + int brightness = 0; + if (action.Equals("TurnOnRequest")) + { + status = 1; + brightness = 100; + } + else if (action.Equals("TurnOffRequest")) + { + status = 2; + brightness = 0; + } + Thread.Sleep(50); + HostModalManager.SetDevice(host, item_inter, status, brightness); + } + } + } + } + if (intent.Equals("IOT.AirCondition")) + { + foreach (var item in slots) + { + var action = item.action; + var name = item.applianceName; + var value = item.value; + var q1 = hostModals.Where(A => A.Modal.Type == DeviceType.AirConditioner && A.Modal.Name.Equals(name)); + foreach (var item_inter in q1) + { + int status = 0; + int temperature = 25; + int fanSpeed = 0; + int mode = 0; + int dianci_famen = 0; + int brightness = 0; + if (action.Equals("TurnOnRequest")) + { + status = 1; + } + if (action.Equals("TurnOffRequest")) + { + status = 2; + } + if (action.Equals("setTemperature")) + { + int v = 25; + int.TryParse(value, out v); + temperature = v; + } + if (action.Equals("setFanSpeed")) + { + //value=high(高),middle(中),low(低),auto(自动) + //空调风速:自动0,低1,中2,高3 + if (value.Equals("high")) + { + fanSpeed = 3; + } + else if (value.Equals("middle")) + { + fanSpeed = 2; + } + else if (value.Equals("low")) + { + fanSpeed = 1; + } + else if (value.Equals("auto")) + { + fanSpeed = 0; + } + } + if (action.Equals("setMode")) + { + //value=cool(制冷),heat(制热),fan=(通风),auto(自动) + //自动0,制冷1,制热2,送风3 + if (value.Equals("cool")) + { + mode = 1; + } + else if (value.Equals("heat")) + { + mode = 2; + } + else if (value.Equals("fan")) + { + mode = 3; + } + else if (value.Equals("auto")) + { + mode = 0; + } + } + HostModalManager.SetDevice(host, item_inter, status, brightness, temperature, fanSpeed, mode); + } + if (q1 != null) + { + } + } + } + if (intent.Equals("IOT.SceneTrigger")) + { + + foreach (var item in slots) + { + var action = item.action; + var name = item.applianceName; + int hid = int.Parse(hotelid); + var scene = RoomTypeSceneManager.LoadAll().Where(A => A.HotelID == hid && A.Name.Equals(name)).FirstOrDefault(); + if (scene != null) + { + if (action.Equals("TurnOnRequest")) + { + LightControlManager.ApplyScene(host, scene); + } + if (action.Equals("TurnOffRequest")) + { + LightControlManager.ApplyScene(host, scene); + } + } + } + } + if (is_monitor) + { + IOTMonitorData i = new IOTMonitorData(); + i.Step = 4; + string ti = CPUData.GetNowPrecise().ToString("yyyy-MM-dd HH:mm:ss.ffffff"); + i.CreateTime = DateTime.Now; + i.TriggerTime = ti; + i.HotelId = hotelid; + i.HotelCode = hotelcode; + i.RoomNumber = roomNo; + i.RequestId = msgid; + i.Platform = "ETV"; + i.CommandDescription = "success"; + SendMQTTData.Send(i); + } + return Json(new { code = 200, msg = "控制成功" }, JsonRequestBehavior.AllowGet); + } + catch (Exception ex) + { + return Json(new { code = 500, msg = ex.Message }, JsonRequestBehavior.AllowGet); + } + } + } + public class ETV_ControllerData + { + public string hotelId { get; set; } + public string roomNo { get; set; } + public string traceId { get; set; } + public string domain { get; set; } + public string intent { get; set; } + public List slots { get; set; } + } + public class ETV_CanShu + { + public string applianceType { get; set; } + public string action { get; set; } + public string applianceName { get; set; } + public string value { get; set; } + } + public class TV_ResponseData + { + public int code { get; set; } + public object msg { get; set; } + public TTT_Data data { get; set; } + } + public class TTT_Data + { + public string token { get; set; } + /// + /// 时间为秒 + /// + public long expiresIn { get; set; } + } + public class TV_AuthData + { + public string clientId { get; set; } + public string clientSecret { get; set; } } public class HiWeiToken { diff --git a/WebSite/Controllers/SysHotelController.cs b/WebSite/Controllers/SysHotelController.cs index c54d6dd..4384b60 100644 --- a/WebSite/Controllers/SysHotelController.cs +++ b/WebSite/Controllers/SysHotelController.cs @@ -305,6 +305,7 @@ namespace WebSite.Controllers sysHotel.IsUseQianLiMa = entity.IsUseQianLiMa; sysHotel.IsPushPMSData = entity.IsPushPMSData; sysHotel.HeTongNumber = entity.HeTongNumber; + sysHotel.ETV_HotelID = entity.ETV_HotelID; //sysHotel.TCLAppId = entity.TCLAppId; //sysHotel.TCLAppSecret = entity.TCLAppSecret; SysHotelManager.Update(sysHotel); @@ -388,6 +389,7 @@ namespace WebSite.Controllers TakeOut.SysHotel.IsUseQianLiMa = entity.IsUseQianLiMa;//断电重置小度 TakeOut.SysHotel.IsPushPMSData = entity.IsPushPMSData; TakeOut.SysHotel.HeTongNumber = entity.HeTongNumber; + TakeOut.SysHotel.ETV_HotelID = entity.ETV_HotelID; //TakeOut.SysHotel.TCLAppId = entity.TCLAppId; //TakeOut.SysHotel.TCLAppSecret = entity.TCLAppSecret; diff --git a/WebSite/Global.asax.cs b/WebSite/Global.asax.cs index d961b9c..dadc4a7 100644 --- a/WebSite/Global.asax.cs +++ b/WebSite/Global.asax.cs @@ -474,7 +474,8 @@ namespace WebSite hostServer.AddReceiver(new RCUHost.Implement.UpgradeProgressBar()); hostServer.AddReceiver(new RCUHost.Implement.RoomStatusChangedReceiver()); hostServer.AddReceiver(new RCUHost.Implement.AskRoomStatusChangedReceiver()); - hostServer.AddReceiver((IReceiver)new RCUHost.Implement.New_RoomStatusReceiver()); + //hostServer.AddReceiver((IReceiver)new RCUHost.Implement.New_RoomStatusReceiver()); + hostServer.AddReceiver(new RCUHost.Implement.New_RoomStatusReceiver()); } /// diff --git a/WebSite/Views/SysHotel/EditDockingInfo.ascx b/WebSite/Views/SysHotel/EditDockingInfo.ascx index dd0dc8a..e7f86e6 100644 --- a/WebSite/Views/SysHotel/EditDockingInfo.ascx +++ b/WebSite/Views/SysHotel/EditDockingInfo.ascx @@ -319,6 +319,18 @@ value="true" <%: Model.IsUseTCLTV ? "checked='checked'" : "" %> /> + + + + + + + + + + +