diff --git a/CRICS_V3_1124.suo b/CRICS_V3_1124.suo index 4ad139b..4407d5e 100644 Binary files a/CRICS_V3_1124.suo and b/CRICS_V3_1124.suo differ diff --git a/Common/CSRedisCacheHelper.cs b/Common/CSRedisCacheHelper.cs index 2f4349a..24d762a 100644 --- a/Common/CSRedisCacheHelper.cs +++ b/Common/CSRedisCacheHelper.cs @@ -21,6 +21,8 @@ namespace Common public static CSRedisClient redis4; public static CSRedisClient redis5; public static CSRedisClient redis6; + public static CSRedisClient redis7; + public static CSRedisClient redis8; public static CSRedisClient redis_webchat; //private static readonly string[] redisHosts = null; private static int SessionExpireMinutes = int.Parse(ConfigurationManager.AppSettings["session_expire_minutes"]); @@ -59,6 +61,8 @@ namespace Common redis4 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=4"); redis5 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=5"); redis6 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=6"); + redis7 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=7"); + redis8 = new CSRedisClient(redisHostStr + ",password=,defaultDatabase=8"); redis_webchat = new CSRedisClient(string.Format(webchat_redisstr + ",password={0},defaultDatabase=0",webchat_redis_pwd)); //Native subscribe @@ -205,6 +209,14 @@ namespace Common { client = redis6; } + else if (SliceNo == 7) + { + client = redis7; + } + else if (SliceNo == 8) + { + client = redis8; + } else { client = redis; diff --git a/Common/Tools.cs b/Common/Tools.cs index 8bc48f2..36b22fc 100644 --- a/Common/Tools.cs +++ b/Common/Tools.cs @@ -772,6 +772,12 @@ namespace Common long current_timestamp = Convert.ToInt64(ts.TotalSeconds); return current_timestamp; } + public static long GetCurrentTimeStamp_MS(DateTime dt) + { + TimeSpan ts = dt - new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Local); + long current_timestamp = Convert.ToInt64(ts.TotalMilliseconds); + return current_timestamp; + } public static DateTime GetCurrentDateTime(long timestampMilliseconds) { DateTime epoch = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Local); diff --git a/CommonEntity/LMRegisterInfo.cs b/CommonEntity/LMRegisterInfo.cs index 79700e4..cde2830 100644 --- a/CommonEntity/LMRegisterInfo.cs +++ b/CommonEntity/LMRegisterInfo.cs @@ -78,5 +78,10 @@ namespace CommonEntity public string central_control_name { get; set; } public string configure_hotel_name { get; set; } public string configure_room_type_name { get; set; } + + /// + /// 最后一次升级时间 + /// + public long upgrade_ts_ms { get; set; } } } diff --git a/ConsoleApplication4/Program.cs b/ConsoleApplication4/Program.cs index eca8855..374dacc 100644 --- a/ConsoleApplication4/Program.cs +++ b/ConsoleApplication4/Program.cs @@ -1,50 +1,130 @@ using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Net.Sockets; using System.Net; +using System.Net.Sockets; +using System.Text; +using System.Threading; namespace ConsoleApplication4 { internal class UdpState { - private UdpClient udpClient; + public UdpClient UdpClient { get; set;} + public IPEndPoint RemoteEndPoint { get; set; } + public UdpState(UdpClient client) { - this.udpClient = client; - } - public UdpClient UdpClient - { - get { return this.udpClient; } + this.UdpClient = client; } } + class Program { + private static bool _isRunning = true; + static void Main(string[] args) { - var udpClient = new UdpClient(3340); - udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024; - udpClient.BeginReceive(ReceiveCallback, new UdpState(udpClient)); - Console.ReadLine(); + Console.CancelKeyPress += (sender, e) => + { + _isRunning = false; + e.Cancel = true; + }; + + try + { + var udpClient = new UdpClient(3340); + udpClient.Client.ReceiveBufferSize = 3 * 1024 * 1024; + + // 开始接收 + udpClient.BeginReceive(ReceiveCallback, new UdpState(udpClient)); + + Console.WriteLine("UDP服务器已启动,按Ctrl+C停止..."); + + // 保持程序运行 + while (_isRunning) + { + Thread.Sleep(100); + } + + udpClient.Close(); + Console.WriteLine("服务器已停止"); + } + catch (Exception ex) + { + Console.WriteLine($"启动失败: {ex.Message}"); + } } public static void ReceiveCallback(IAsyncResult ar) { UdpState state = ar.AsyncState as UdpState; - // 1. 结束异步接收,获取数据和远程端点 - IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); - byte[] receivedData = state.UdpClient.EndReceive(ar, ref remoteEndPoint); - - state.UdpClient.BeginReceive(ReceiveCallback, state); + try { - Console.WriteLine(11111111111111); + // 1. 先获取接收到的数据 + IPEndPoint remoteEndPoint = new IPEndPoint(IPAddress.Any, 0); + byte[] receivedData = state.UdpClient.EndReceive(ar, ref remoteEndPoint); + + // 2. 立即开始下一次接收(不等待数据处理完成) + state.UdpClient.BeginReceive(ReceiveCallback, state); + + // 3. 异步处理数据,避免阻塞接收 + ThreadPool.QueueUserWorkItem(_ => + { + ProcessData(receivedData, remoteEndPoint, state.UdpClient); + }); } - catch (Exception) + catch (ObjectDisposedException) { - + // 正常关闭,忽略 + } + catch (SocketException ex) + { + //Console.WriteLine($"网络错误: {ex.SocketErrorCode} - {ex.Message}"); + + //// 尝试重新开始接收 + //if (_isRunning && state?.UdpClient?.Client != null) + //{ + // try + // { + // state.UdpClient.BeginReceive(ReceiveCallback, state); + // } + // catch { } + //} + } + catch (Exception ex) + { + //Console.WriteLine($"接收回调错误: {ex.Message}"); + } + } + + private static void ProcessData(byte[] data, IPEndPoint remoteEP, UdpClient udpClient) + { + try + { + //// 这里是您的数据处理逻辑 + //Console.WriteLine($"收到来自 {remoteEP} 的数据,长度: {data.Length} 字节"); + + //// 示例:解码为字符串 + //if (data.Length > 0) + //{ + // string text = Encoding.UTF8.GetString(data); + // Console.WriteLine($"内容: {text}"); + //} + + //// 这里可以处理复杂的业务逻辑 + //// 例如:数据库操作、文件处理、复杂计算等 + + //// 如果需要回复 + //if (data.Length > 0) + //{ + // byte[] response = Encoding.UTF8.GetBytes($"已收到: {data.Length} 字节"); + // udpClient.Send(response, response.Length, remoteEP); + //} + } + catch (Exception ex) + { + //Console.WriteLine($"数据处理失败: {ex.Message}"); } } } -} +} \ No newline at end of file diff --git a/RCUHost/Implement/HostRegisterReceiver.cs b/RCUHost/Implement/HostRegisterReceiver.cs index e8ff2dd..cf073a3 100644 --- a/RCUHost/Implement/HostRegisterReceiver.cs +++ b/RCUHost/Implement/HostRegisterReceiver.cs @@ -297,10 +297,17 @@ namespace RCUHost.Implement mcu_name = core, central_control_name = model, configure_hotel_name = hotel_name, - configure_room_type_name = roomtype_remark + configure_room_type_name = roomtype_remark, }; + if (host.UpgradeTime.HasValue) + { + var upgrade_ts_ms = Tools.GetCurrentTimeStamp_MS(host.UpgradeTime.Value); + rsg.upgrade_ts_ms = upgrade_ts_ms; + } + + string N1N = Newtonsoft.Json.JsonConvert.SerializeObject(rsg); CSRedisCacheHelper.Publish("redis-0XB1", N1N); diff --git a/RCUHost/Implement/HostServer.cs b/RCUHost/Implement/HostServer.cs index 8a3c95a..a35cf40 100644 --- a/RCUHost/Implement/HostServer.cs +++ b/RCUHost/Implement/HostServer.cs @@ -1321,9 +1321,13 @@ namespace RCUHost.Implement DateTime SSS = DateTime.Now; DateTime.TryParse(dtstart, out SSS); TimeSpan ssspan = DateTime.Now - SSS; - if (string.IsNullOrEmpty(EEE) && ssspan.TotalMinutes > 5) + //var TTT111= CSRedisCacheHelper.Get_Partition(HostNNN,7); + //if ((string.IsNullOrEmpty(EEE) && ssspan.TotalMinutes > 5)||string.IsNullOrEmpty(TTT111)) + //if ((string.IsNullOrEmpty(EEE) && ssspan.TotalMinutes > 5)) + if (string.IsNullOrEmpty(EEE)) { CSRedisCacheHelper.Publish("redis-on_off_line", n); + //CSRedisCacheHelper.Set_PartitionWithForever(HostNNN,"1",7); } //6号分区 做离在线数据 //但是离线的时候,只能得到Key值 @@ -2382,36 +2386,8 @@ namespace RCUHost.Implement ///碳达人状态更新 if (!string.IsNullOrEmpty(HostID)) { - string KKey = CacheKey.HostModalStatus_Prefix + "_" + HostID + "_" + "054000001"; - var OldHostModal = CSRedisCacheHelper.Get_Partition(KKey); - if (OldHostModal != null) - { - OldHostModal.Status = CarbonVIP; - CSRedisCacheHelper.Set_Partition(KKey, OldHostModal); - } - - - StringBuilder sb = new StringBuilder(); - sb.Append(CacheKey.CarbonVIP_Prefix); - sb.Append("_"); - sb.Append(HostID.ToString()); - string Key = sb.ToString(); - - string current_status_new = ""; - if (CarbonVIP == 0x01) - { - current_status_new = "open"; - } - else if (CarbonVIP == 0x02) - { - current_status_new = "close"; - } - else - { - current_status_new = "unknow"; - } - - CSRedisCacheHelper.Set(Key, current_status_new); + CarbonVIPReport(HostID, CarbonVIP,"054001000"); + CarbonVIPReport(HostID, CarbonVIP,"054000001"); } var DeviceCount = reader.ReadByte(); @@ -2757,6 +2733,46 @@ namespace RCUHost.Implement }, tuple); } + + /// + /// 碳达人上报 + /// + /// + /// + /// + private static void CarbonVIPReport(string HostID, byte CarbonVIP,string Address) + { + string KKey = CacheKey.HostModalStatus_Prefix + "_" + HostID + "_" +Address; + var OldHostModal = CSRedisCacheHelper.Get_Partition(KKey); + if (OldHostModal != null) + { + OldHostModal.Status = CarbonVIP; + CSRedisCacheHelper.Set_Partition(KKey, OldHostModal); + } + + + StringBuilder sb = new StringBuilder(); + sb.Append(CacheKey.CarbonVIP_Prefix); + sb.Append("_"); + sb.Append(HostID.ToString()); + string Key = sb.ToString(); + + string current_status_new = ""; + if (CarbonVIP == 0x01) + { + current_status_new = "open"; + } + else if (CarbonVIP == 0x02) + { + current_status_new = "close"; + } + else + { + current_status_new = "unknow"; + } + + CSRedisCacheHelper.Set(Key, current_status_new); + } public struct JiNamTongPaiTeShu { public string HostNumber { get; set; } diff --git a/WebSite/Global.asax.cs b/WebSite/Global.asax.cs index 7aecf97..7985b0b 100644 --- a/WebSite/Global.asax.cs +++ b/WebSite/Global.asax.cs @@ -160,7 +160,7 @@ namespace WebSite { RedisTongJiData tq1 = new RedisTongJiData(); tq1.url = "api/CaiJiData"; - tq1.cron_exp = string.Format("*/{0} * * * *", 10); + tq1.cron_exp = string.Format("*/{0} * * * *", 1); tq1.mission_key = MvcApplication.IntervalKey; CSRedisCacheHelper.Forever(IntervalKey, tq1); } diff --git a/WebSite/Scripts/simon-room-status-index.js b/WebSite/Scripts/simon-room-status-index.js index 603230d..b1872ef 100644 --- a/WebSite/Scripts/simon-room-status-index.js +++ b/WebSite/Scripts/simon-room-status-index.js @@ -199,22 +199,30 @@ function loadRooms(opts, callback) { type: "POST", cache: false, data: { page: page, rows: rows, groupId: options.group, isAirDetect: $("#chkAirDetect").is(':checked') }, - success: function (r) { - if (r.IsSuccess) { + success: function (r) + { + if (r.IsSuccess) + { var tdCount = Math.floor(document.documentElement.clientWidth / 124); $('#rooms').html(""); var strHtml = ""; - for (var i = 0; i < r.Data.length; i++) { - for (var j = 0; j < r.Data[i].FloorRooms.length; j++) { - if (j == 0) { + for (var i = 0; i < r.Data.length; i++) + { + for (var j = 0; j < r.Data[i].FloorRooms.length; j++) + { + if (j == 0) + { strHtml += ""; - } else if ($("#chkSwitchLine").is(':checked') && (j + 1) % tdCount == 1) { + } else if ($("#chkSwitchLine").is(':checked') && (j + 1) % tdCount == 1) + { strHtml += ""; } var strRoomTemp = ""; //室内温度:大于28°显示红色,小于22°显示蓝色,默认显示绿色 - if (r.Data[i].FloorRooms[j].RoomTemp > 28) { + if (r.Data[i].FloorRooms[j].RoomTemp > 28) + { strRoomTemp = ""; - } else if (r.Data[i].FloorRooms[j].RoomTemp < 22) { + } else if (r.Data[i].FloorRooms[j].RoomTemp < 22) + { strRoomTemp = ""; } strHtml += "
  • "; + console.log("VIP:"+CarbonVIP_Status); + if (CarbonVIP_Status == "open") + { + strHtml += "" + r.Data[i].FloorRooms[j].RoomNumber + ""; } - else if (CarbonVIP_Status == "close") { - strHtml += ""+r.Data[i].FloorRooms[j].RoomNumber+""; + else if (CarbonVIP_Status == "close") + { + strHtml += "" + r.Data[i].FloorRooms[j].RoomNumber + ""; } - else if (CarbonVIP_Status == "exists_nostatus") { - strHtml += ""+r.Data[i].FloorRooms[j].RoomNumber+""; + else if (CarbonVIP_Status == "exists_nostatus") + { + strHtml += "" + r.Data[i].FloorRooms[j].RoomNumber + ""; } - else { + else + { } - + //strHtml += "
    "; - if ($("#chkAirDetect").is(':checked') && r.Data[i].FloorRooms[j].AirDetects.length > 0) {//显示空气质量检测 - for (var k = 0; k < r.Data[i].FloorRooms[j].AirDetects.length; k++) { + if ($("#chkAirDetect").is(':checked') && r.Data[i].FloorRooms[j].AirDetects.length > 0) + {//显示空气质量检测 + for (var k = 0; k < r.Data[i].FloorRooms[j].AirDetects.length; k++) + { strHtml += "
    " + r.Data[i].FloorRooms[j].AirDetects[k].Name + ":" + r.Data[i].FloorRooms[j].AirDetects[k].Value + "
    "; } strHtml += "
    "; } - else { + else + { //strHtml += "
    " + r.Data[i].FloorRooms[j].Power + "
    "; - strHtml += "
    " + r.Data[i].FloorRooms[j].RoomStatus + " "+r.Data[i].FloorRooms[j].Power+"
    "; + strHtml += "
    " + r.Data[i].FloorRooms[j].RoomStatus + " " + r.Data[i].FloorRooms[j].Power + "
    "; strHtml += "
    " + lang.Identity + ":" + r.Data[i].FloorRooms[j].Identity + " " + r.Data[i].FloorRooms[j].PowerSupplyName + "
    "; strHtml += "
    " + r.Data[i].FloorRooms[j].AirStatusName + " " + strRoomTemp + r.Data[i].FloorRooms[j].RoomTemp + "℃ " + r.Data[i].FloorRooms[j].SettingTemp + "℃" + "
    "; strHtml += "
    " + r.Data[i].FloorRooms[j].ValveName + " " + airMode(r.Data[i].FloorRooms[j].Mode) + " " + fanSpeed(r.Data[i].FloorRooms[j].FanSpeed) + "
    "; - if (r.Data[i].FloorRooms[j].Peripheral != "") { + if (r.Data[i].FloorRooms[j].Peripheral != "") + { strHtml += "
    " + r.Data[i].FloorRooms[j].Peripheral + "
    "; } strHtml += "
    " + lang.CurrentService + ":" + r.Data[i].FloorRooms[j].Services.length + "
    "; strHtml += "
    "; - for (var k = 0; k < r.Data[i].FloorRooms[j].Services.length; k++) { + for (var k = 0; k < r.Data[i].FloorRooms[j].Services.length; k++) + { strHtml += "" + r.Data[i].FloorRooms[j].Services[k].Name + ""; } strHtml += "
    "; @@ -270,7 +288,8 @@ function loadRooms(opts, callback) { !options.timeRefresh && $.tools.ajaxLoadEnd(); callback && callback(); }, - error: function () { + error: function () + { !options.timeRefresh && $.tools.ajaxLoadEnd(); callback && callback(); }