修改 在线离线的判断逻辑
This commit is contained in:
Binary file not shown.
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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; }
|
||||
|
||||
/// <summary>
|
||||
/// 最后一次升级时间
|
||||
/// </summary>
|
||||
public long upgrade_ts_ms { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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<string>(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<HostModal_Cache>(KKey);
|
||||
if (OldHostModal != null)
|
||||
{
|
||||
OldHostModal.Status = CarbonVIP;
|
||||
CSRedisCacheHelper.Set_Partition<HostModal_Cache>(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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 碳达人上报
|
||||
/// </summary>
|
||||
/// <param name="HostID"></param>
|
||||
/// <param name="CarbonVIP"></param>
|
||||
/// <param name="Address"></param>
|
||||
private static void CarbonVIPReport(string HostID, byte CarbonVIP,string Address)
|
||||
{
|
||||
string KKey = CacheKey.HostModalStatus_Prefix + "_" + HostID + "_" +Address;
|
||||
var OldHostModal = CSRedisCacheHelper.Get_Partition<HostModal_Cache>(KKey);
|
||||
if (OldHostModal != null)
|
||||
{
|
||||
OldHostModal.Status = CarbonVIP;
|
||||
CSRedisCacheHelper.Set_Partition<HostModal_Cache>(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; }
|
||||
|
||||
@@ -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<RedisTongJiData>(IntervalKey, tq1);
|
||||
}
|
||||
|
||||
@@ -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 = "<tbody>";
|
||||
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 += "<tr>";
|
||||
} else if ($("#chkSwitchLine").is(':checked') && (j + 1) % tdCount == 1) {
|
||||
} else if ($("#chkSwitchLine").is(':checked') && (j + 1) % tdCount == 1)
|
||||
{
|
||||
strHtml += "</tr><tr>";
|
||||
}
|
||||
var strRoomTemp = "<font style='color:green'>"; //室内温度:大于28°显示红色,小于22°显示蓝色,默认显示绿色
|
||||
if (r.Data[i].FloorRooms[j].RoomTemp > 28) {
|
||||
if (r.Data[i].FloorRooms[j].RoomTemp > 28)
|
||||
{
|
||||
strRoomTemp = "<font style='color:red'>";
|
||||
} else if (r.Data[i].FloorRooms[j].RoomTemp < 22) {
|
||||
} else if (r.Data[i].FloorRooms[j].RoomTemp < 22)
|
||||
{
|
||||
strRoomTemp = "<font style='color:blue'>";
|
||||
}
|
||||
strHtml += "<td><ul><li oncontextmenu='showContextMenu(" + r.Data[i].FloorRooms[j].ID + ",null);return false;'";
|
||||
@@ -223,37 +231,47 @@ function loadRooms(opts, callback) {
|
||||
|
||||
strHtml += "<dl><dt>" + r.Data[i].FloorRooms[j].RoomNumber;
|
||||
var CarbonVIP_Status = r.Data[i].FloorRooms[j].CarbonVIP;
|
||||
if (CarbonVIP_Status == "open") {
|
||||
strHtml += "<img src='../../Images/ECO/eco_g.png' width='16' height='16' style='margin-right:5px;'/>"+r.Data[i].FloorRooms[j].RoomNumber+"</dt>";
|
||||
console.log("VIP:"+CarbonVIP_Status);
|
||||
if (CarbonVIP_Status == "open")
|
||||
{
|
||||
strHtml += "<img src='../../Images/ECO/eco_g.png' width='16' height='16' style='margin-right:5px;'/>" + r.Data[i].FloorRooms[j].RoomNumber + "</dt>";
|
||||
}
|
||||
else if (CarbonVIP_Status == "close") {
|
||||
strHtml += "<img src='../../Images/ECO/eco_p.png' width='16' height='16' style='margin-right:5px;'/>"+r.Data[i].FloorRooms[j].RoomNumber+"</dt>";
|
||||
else if (CarbonVIP_Status == "close")
|
||||
{
|
||||
strHtml += "<img src='../../Images/ECO/eco_p.png' width='16' height='16' style='margin-right:5px;'/>" + r.Data[i].FloorRooms[j].RoomNumber + "</dt>";
|
||||
}
|
||||
else if (CarbonVIP_Status == "exists_nostatus") {
|
||||
strHtml += "<img src='../../Images/ECO/eco_p.png' width='16' height='16' style='margin-right:5px;'/>"+r.Data[i].FloorRooms[j].RoomNumber+"</dt>";
|
||||
else if (CarbonVIP_Status == "exists_nostatus")
|
||||
{
|
||||
strHtml += "<img src='../../Images/ECO/eco_p.png' width='16' height='16' style='margin-right:5px;'/>" + r.Data[i].FloorRooms[j].RoomNumber + "</dt>";
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
//strHtml += "<dl><dt>";
|
||||
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 += "<dd>" + r.Data[i].FloorRooms[j].AirDetects[k].Name + ":" + r.Data[i].FloorRooms[j].AirDetects[k].Value + "</dd>";
|
||||
}
|
||||
strHtml += "</dl>";
|
||||
}
|
||||
else {
|
||||
else
|
||||
{
|
||||
//strHtml += "<dd>" + r.Data[i].FloorRooms[j].Power + "</dd>";
|
||||
strHtml += "<dd>" + r.Data[i].FloorRooms[j].RoomStatus + " "+r.Data[i].FloorRooms[j].Power+"</dd>";
|
||||
strHtml += "<dd>" + r.Data[i].FloorRooms[j].RoomStatus + " " + r.Data[i].FloorRooms[j].Power + "</dd>";
|
||||
strHtml += "<dd>" + lang.Identity + ":" + r.Data[i].FloorRooms[j].Identity + " " + r.Data[i].FloorRooms[j].PowerSupplyName + "</dd>";
|
||||
strHtml += "<dd>" + r.Data[i].FloorRooms[j].AirStatusName + " " + strRoomTemp + r.Data[i].FloorRooms[j].RoomTemp + "℃</font> " + r.Data[i].FloorRooms[j].SettingTemp + "℃" + "</dd>";
|
||||
strHtml += "<dd>" + r.Data[i].FloorRooms[j].ValveName + " " + airMode(r.Data[i].FloorRooms[j].Mode) + " " + fanSpeed(r.Data[i].FloorRooms[j].FanSpeed) + "</dd>";
|
||||
if (r.Data[i].FloorRooms[j].Peripheral != "") {
|
||||
if (r.Data[i].FloorRooms[j].Peripheral != "")
|
||||
{
|
||||
strHtml += "<dd>" + r.Data[i].FloorRooms[j].Peripheral + "</dd>";
|
||||
}
|
||||
strHtml += "<dd>" + lang.CurrentService + ":" + r.Data[i].FloorRooms[j].Services.length + "</dd></dl>";
|
||||
strHtml += "<div class='service-list' style='display:" + (r.Data[i].FloorRooms[j].HostStatus ? "block" : "none") + "'>";
|
||||
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 += "<span style='background:" + r.Data[i].FloorRooms[j].Services[k].Color + ";'>" + r.Data[i].FloorRooms[j].Services[k].Name + "</span>";
|
||||
}
|
||||
strHtml += "</div>";
|
||||
@@ -270,7 +288,8 @@ function loadRooms(opts, callback) {
|
||||
!options.timeRefresh && $.tools.ajaxLoadEnd();
|
||||
callback && callback();
|
||||
},
|
||||
error: function () {
|
||||
error: function ()
|
||||
{
|
||||
!options.timeRefresh && $.tools.ajaxLoadEnd();
|
||||
callback && callback();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user