修改新版协议主机 协议触发的机制,新增 缓存机制

This commit is contained in:
2026-04-09 13:37:09 +08:00
parent c13ab0cb56
commit 36c2fa4061
22 changed files with 484 additions and 1897 deletions

View File

@@ -178,6 +178,7 @@
<!--<property name="SysHotelRepository" ref="Repository.SysHotel" />-->
<property name="HostModalRepository" ref="Repository.HostModal" />
<property name="SysOauth2Repository" ref="Repository.SysOauth2" />
<property name="DeviceControlReceiver" ref="RCUHost.DeviceControlReceiver" />
</object>
<object id="RCUHost.TFTPReceiver" type="RCUHost.Implement.TFTPReceiver, RCUHost" parent="RCUHost.GenericReceiverBase" singleton="true">

View File

@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using Domain;
using RCUHost.Protocols;
using System.Net;
namespace RCUHost
{
@@ -15,6 +16,9 @@ namespace RCUHost
/// <param name="host"></param>
/// <param name="device"></param>
void Send(Host host, Device device);
void SendWithEndPoint( Device device,IPEndPoint endpoint);
void Send_Repeat(string Key,Host host, Device device);
/// <summary>

View File

@@ -7,6 +7,7 @@ using Common;
using Domain;
using RCUHost.Protocols;
using CommonEntity;
using System.Net;
namespace RCUHost.Implement
{
@@ -14,11 +15,21 @@ namespace RCUHost.Implement
{
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(DeviceControlReceiver));
public void SendWithEndPoint(Device device, IPEndPoint endpoint)
{
SendWithEndPoint(new List<Device> { device }, endpoint);
}
public void SendWithEndPoint(IList<Device> devices, IPEndPoint endpoint)
{
var data = CreateDeviceControlPacket(devices);
SendAndPushCommandQueueWithEndPoint(data, endpoint);// host.IP, host.Port);
}
public void Send(Host host, Device device)
{
Send(host, new List<Device> { device });
}
public void Send(Host host, IList<Device> devices)
{
var data = CreateDeviceControlPacket(devices);
@@ -33,9 +44,9 @@ namespace RCUHost.Implement
//string nnn = builder.ToString().Trim();
//logger.Error(string.Format("给酒店({0})客房({1})发送控制命令{2}", host.SysHotel.Code, host.RoomNumber,builder.ToString()));
}
public void Send_Repeat(string Key,Host host, Device device)
public void Send_Repeat(string Key, Host host, Device device)
{
Send_Repeat(Key,host, new List<Device> { device });
Send_Repeat(Key, host, new List<Device> { device });
}
public void Send_Repeat(string PrefixKey, Host host, IList<Device> devices)
{
@@ -223,5 +234,6 @@ namespace RCUHost.Implement
{
get { return CommandType.DeviceControl; }
}
}
}

View File

@@ -278,7 +278,7 @@ namespace RCUHost.Implement
}
catch (Exception ex)
{
logger.Error("发送:"+ex.Message);
logger.Error("发送:" + ex.Message);
logger.Error(ex.StackTrace);
}
}
@@ -304,6 +304,10 @@ namespace RCUHost.Implement
HostServer.SendAndPushCommandQueue(data, ipAndPort.ToString().Split(':')[0], Convert.ToInt32(ipAndPort.ToString().Split(':')[1]));
}
}
protected void SendAndPushCommandQueueWithEndPoint(byte[] data, IPEndPoint endpoint)
{
HostServer.SendAndPushCommandQueue(data, endpoint);
}
/// <summary>
/// 回复下位机命令
/// </summary>

View File

@@ -21,6 +21,7 @@ using System.Threading;
using System.Collections;
using Newtonsoft.Json;
using Microsoft.IO;
using System.Reflection;
namespace RCUHost.Implement
{
@@ -649,14 +650,15 @@ namespace RCUHost.Implement
//如果不存在就处理
else
{
//GaiXie g = new GaiXie();
//g.Data = receiveBuffer111;
//g.IPEndPoint = remoteEP111.ToString();
//var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
string s1 = Tools.ByteToString(receiveBuffer111);
string data = s1 + "#" + remoteEP111.ToString();
if (VVV.CmdType == 0x0E || VVV.CmdType == 0x01 || VVV.CmdType == 0x36)
{
ushort MyFrameNO = context.SystemHeader.Value.FrameNo;
byte[] framenolist = BitConverter.GetBytes(MyFrameNO);
Reply(context, framenolist);
}
//ProcessData(data);
CSRedisCacheHelper.StreamAdd(1, UDPAllDataKey, data);
@@ -676,15 +678,15 @@ namespace RCUHost.Implement
}
else
{
//GaiXie g = new GaiXie();
//g.Data = receiveBuffer111;
//g.IPEndPoint = remoteEP111.ToString();
//var data = Newtonsoft.Json.JsonConvert.SerializeObject(g);
string s1 = Tools.ByteToString_NoWhiteSpace(receiveBuffer111);
string data = s1 + "#" + remoteEP111.ToString();
//ProcessData(data);
if (VVV.CmdType == 0x0E || VVV.CmdType == 0x01 || VVV.CmdType == 0x36)
{
ushort MyFrameNO = context.SystemHeader.Value.FrameNo;
byte[] framenolist = BitConverter.GetBytes(MyFrameNO);
Reply(context, framenolist);
}
CSRedisCacheHelper.StreamAdd(1, UDPAllDataKey, data);
}
}
@@ -1221,8 +1223,6 @@ namespace RCUHost.Implement
/// 处理数据
/// </summary>
/// <param name="context"></param>
//private void ProcessData(ReceiverContext context111, string hotelCode)
//private void ProcessData(GaiXie gga)
private void ProcessData(string gga)
{
//GaiXie gga = new GaiXie();
@@ -1337,12 +1337,13 @@ namespace RCUHost.Implement
#region 0E 01
//36 就是新版本的0E
if (cmdType == 0x0E || cmdType == 0x01 || cmdType == 0x36)
{
StepTongJi.SendInfo(1.1, "0E 01指令回复开始", context111.MessageID, context111.IsMonitor);
Reply(context111, framenolist);
StepTongJi.SendInfo(1.2, "0E 01指令回复结束", context111.MessageID, context111.IsMonitor);
}
//回复放到上面
//if (cmdType == 0x0E || cmdType == 0x01 || cmdType == 0x36)
//{
//StepTongJi.SendInfo(1.1, "0E 01指令回复开始", context111.MessageID, context111.IsMonitor);
//Reply(context111, framenolist);
//StepTongJi.SendInfo(1.2, "0E 01指令回复结束", context111.MessageID, context111.IsMonitor);
//}
#endregion
///注册指令 也要推送
@@ -1743,7 +1744,8 @@ namespace RCUHost.Implement
}
}
public IDeviceControlReceiver DeviceControlReceiver { get; set; }
public static System.Reflection.PropertyInfo[] properties = typeof(HotelSeason).GetProperties();//获取所有属性
public static byte[] nocard_enum = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
public static object oo = new object();
private void NewXieYi(ReceiverContext context_1, string hotelCode_1, string HostNNN_1, byte[] framenolist_1, byte cmdType_1, string EndPoint_1, ushort MyFrameNO)
@@ -1836,6 +1838,8 @@ namespace RCUHost.Implement
if (qudian == 0x01)
{
VoiceRobotTrigger(1, hotelCode, HostNNN);
}
else if (qudian == 0x02)
{
@@ -1846,6 +1850,18 @@ namespace RCUHost.Implement
}
#region
try
{
JiJieChuLi(hotelCode, HostNNN, EndPoint, qudian);
}
catch (Exception ex)
{
logger.Error("季节出错了:"+ex.Message);
}
#endregion
NewVersionHexData ns = new NewVersionHexData();
ns.CmdType = 0x35;
ns.HotelCode = hotelCode;
@@ -2029,7 +2045,7 @@ namespace RCUHost.Implement
//给宝镜发送完整的数据
string hexdata = Tools.ByteToString(context111.Data);
CSRedisCacheHelper.Publish("redis-baojing-powerdata", hexdata);
//CSRedisCacheHelper.Publish("redis-baojing-powerdata", hexdata);
try
@@ -2762,6 +2778,73 @@ namespace RCUHost.Implement
}, tuple);
}
/// <summary>
/// 季节处理
/// </summary>
/// <param name="hotelCode"></param>
/// <param name="HostNNN"></param>
/// <param name="EndPoint"></param>
/// <param name="qudian"></param>
private void JiJieChuLi(string hotelCode, string HostNNN, string EndPoint, byte qudian)
{
//3、取电或断电时季节空调处理
HotelSeason hotelSeason = QuanJuVar.HotelSeaon.FirstOrDefault(A => A.SysHotel.Code.Equals(hotelCode));
if (hotelSeason != null)
{
int conditonType = (qudian == 1 ? 2 : 3);
List<HotelAirControl> list = QuanJuVar.HotelAirControl.Where(A => A.SysHotel!=null&&!string.IsNullOrEmpty(A.SysHotel.Code)&& A.SysHotel.Code.Equals(hotelCode) && A.ConditionType == conditonType && A.ActiveIndicator).ToList();
string ttt = CSRedisCacheHelper.HMGet<string>(5, CacheKey.HostId_HostNumber, HostNNN)[0];
if (string.IsNullOrEmpty(ttt))
{
return;
}
string[] NNN111 = ttt.Split('#');
string HostID = NNN111[0];
string RoomTypeID = NNN111[1];
int room_type_id = int.Parse(RoomTypeID);
var hostModals = QuanJuVar.RoomTypeDeviceModal.Where(A => A.RoomType.ID == room_type_id && A.Type == DeviceType.AirConditioner && A.ActiveIndicator).ToList();
if (list.Count > 0 && hostModals.Count > 0)
{
//System.Reflection.PropertyInfo[] properties = typeof(HotelSeason).GetProperties();//获取所有属性
foreach (HotelAirControl item in list)
{
foreach (PropertyInfo prop in properties)//遍历属性
{
if (prop.Name == "Month" + DateTime.Now.Month.ToString() && Convert.ToInt16(prop.GetValue(hotelSeason, null)) == item.Season)//当前月份所属该季节则发送命令给rcu设置空调
{
var D2 = item;
Task.Factory.StartNew(() =>
{
System.Threading.Thread.Sleep(item.DelayTime * 1000);//延迟执行
foreach (RoomTypeModal hostModal1 in hostModals)
{
Device device1 = new Device();
device1.Address = hostModal1.ModalAddress;
device1.AddressType = AddressType.DeviceAddress;
device1.Type = DeviceType.AirConditioner;
device1.Status = (byte)D2.Status;
device1.Brightness = 0;
device1.Temperature = (byte)D2.SettingTemp;
device1.FanSpeed = (byte)D2.FanSpeed;
device1.Mode = (byte)D2.Mode;
device1.Valve = 0;
device1.AirExecMode = (D2.Status << 14) + (D2.Mode << 12) + (D2.FanSpeed << 10) + (0 << 8) + D2.SettingTemp;//空调执行方式和内容
var span = EndPoint.Split(':');
string ip = span[0];
string port = span[1];
IPEndPoint eee = new IPEndPoint(IPAddress.Parse(ip), int.Parse(port));
DeviceControlReceiver.SendWithEndPoint(device1, eee);
}
});
break;
}
}
}
}
}
}
/// <summary>
/// 碳达人上报
/// </summary>

View File

@@ -418,21 +418,32 @@ namespace RCUHost.Implement
else
{
//这里有点问题如果一个Model删除了又更新了那它的ID就变了。但是内存中记录的没变所以这里会出问题
var hostModal_old = HostModalRepository.Get(host.ID, device.Value.Address);
//var hostModal_old = HostModalRepository.Get(host.ID, device.Value.Address);
string HostID_O = CSRedisCacheHelper.HMGet<string>(5, CacheKey.HostId_HostNumber, HOSTNUMBER)[0];
if (string.IsNullOrEmpty(HostID_O))
{
return;
}
string[] NNN111 = HostID_O.Split('#');
string HostID = NNN111[0];
string RoomTypeID = NNN111[1];
int room_type_id = int.Parse(RoomTypeID);
var hostModal_old = QuanJuVar.RoomTypeDeviceModal.FirstOrDefault(A => A.RoomType.ID == room_type_id && A.ModalAddress.Equals(device.Value.Address));
if (hostModal_old != null)
{
HostModal_Cache c = new HostModal_Cache();
c.HostID = hostModal_old.HostID;
c.ModalType = hostModal_old.Modal.Type;
c.HostID = host.ID;
c.ModalType = hostModal_old.Type;
c.AirConditionData = new AirConditionData();
c.Modal = new RoomTypeModalCache()
{
RoomTypeID = hostModal_old.Modal.RoomType.ID,
ID = hostModal_old.Modal.ID,
Name = hostModal_old.Modal.Name,
ModalAddress = hostModal_old.Modal.ModalAddress,
ActiveIndicator = hostModal_old.Modal.ActiveIndicator,
Sort = hostModal_old.Modal.Sort
RoomTypeID = hostModal_old.RoomType.ID,
ID = hostModal_old.ID,
Name = hostModal_old.Name,
ModalAddress = hostModal_old.ModalAddress,
ActiveIndicator = hostModal_old.ActiveIndicator,
Sort = hostModal_old.Sort
};
hostModal = c;
}
@@ -735,93 +746,6 @@ namespace RCUHost.Implement
{
}
#region
//3、取电或断电时季节空调处理
HotelSeason hotelSeason = null;
string KKKAAA = "Season_" + host.SysHotel.ID;
string KongZhi = "Season_WuKong" + host.SysHotel.ID;
object ShiFouWeiKong = MemoryCacheHelper.Get(KongZhi);
int bf = 1;
if (ShiFouWeiKong != null)
{
bf = (int)ShiFouWeiKong;
}
if (bf == 0)
{
var UIO = MemoryCacheHelper.Get(KKKAAA);
if (UIO != null)
{
hotelSeason = (HotelSeason)UIO;
}
else
{
hotelSeason = HotelSeasonRepository.LoadByHotelID(host.SysHotel.ID);//获取该酒店下季节设置记录
if (hotelSeason != null)
{
MemoryCacheHelper.Set(KongZhi, 0, DateTimeOffset.Now.AddMinutes(20));
MemoryCacheHelper.Set(KKKAAA, hotelSeason, DateTimeOffset.Now.AddMinutes(20));
}
else
{
MemoryCacheHelper.Set(KongZhi, 1, DateTimeOffset.Now.AddMinutes(20));
}
}
}
else
{
hotelSeason = HotelSeasonRepository.LoadByHotelID(host.SysHotel.ID);//获取该酒店下季节设置记录
if (hotelSeason != null)
{
MemoryCacheHelper.Set(KongZhi, 0, DateTimeOffset.Now.AddMinutes(20));
MemoryCacheHelper.Set(KKKAAA, hotelSeason, DateTimeOffset.Now.AddMinutes(20));
}
else
{
MemoryCacheHelper.Set(KongZhi, 1, DateTimeOffset.Now.AddMinutes(20));
}
}
if (hotelSeason != null)
{
int conditonType = (hostModal.Status == 1 ? 2 : 3);
List<HotelAirControl> list = HotelAirControlRepository.LoadAll(host.SysHotel.ID, conditonType, true);
List<HostModal> hostModals = HostModalRepository.LoadByHostID(host.ID).Where(r => r.Modal.Type == DeviceType.AirConditioner && r.Modal.ActiveIndicator).ToList();//获取启用的空调回路
if (list.Count > 0 && hostModals.Count > 0)
{
System.Reflection.PropertyInfo[] properties = typeof(HotelSeason).GetProperties();//获取所有属性
foreach (HotelAirControl item in list)
{
foreach (System.Reflection.PropertyInfo prop in properties)//遍历属性
{
if (prop.Name == "Month" + DateTime.Now.Month.ToString() && Convert.ToInt16(prop.GetValue(hotelSeason, null)) == item.Season)//当前月份所属该季节则发送命令给rcu设置空调
{
System.Threading.Thread.Sleep(item.DelayTime * 1000);//延迟执行
var D2 = item;
foreach (HostModal hostModal1 in hostModals)
{
Device device1 = new Device();
device1.Address = hostModal1.Modal.ModalAddress;
device1.AddressType = AddressType.DeviceAddress;
device1.Type = DeviceType.AirConditioner;
device1.Status = (byte)D2.Status;
device1.Brightness = 0;
device1.Temperature = (byte)D2.SettingTemp;
device1.FanSpeed = (byte)D2.FanSpeed;
device1.Mode = (byte)D2.Mode;
device1.Valve = 0;
device1.AirExecMode = (D2.Status << 14) + (D2.Mode << 12) + (D2.FanSpeed << 10) + (0 << 8) + D2.SettingTemp;//空调执行方式和内容
//这里只需要host的mac和number或者 ip
DeviceControlReceiver.Send(host, device1);
}
break;
}
}
}
}
}
#endregion
#endregion
break;
}
@@ -1187,7 +1111,7 @@ namespace RCUHost.Implement
//电量0-100
ushort dianliang = (ushort)f2;
string DLKey = CacheKey.DianLiang + "_" + HOSTNUMBER;
CSRedisCacheHelper.Set_PartitionWithForever(DLKey,dianliang.ToString(),5);
CSRedisCacheHelper.Set_PartitionWithForever(DLKey, dianliang.ToString(), 5);
}
//更新主机主表
if (hostModal.Modal.Sort == 1)//.ModalAddress == "020001000")
@@ -1230,123 +1154,129 @@ namespace RCUHost.Implement
if (hostModal.ModalType == DeviceType.ServiceInfo)
//if (isonly_serviceinfo)
{
int StatusFlag = hostModal.Status;
HostModal FinallyData = new HostModal();
FinallyData.HostID = hostModal.HostID;
FinallyData.Status = hostModal.Status;
FinallyData.Brightness = hostModal.Brightness;
FinallyData.CurrentTemp = hostModal.AirConditionData.CurrentTemp;
FinallyData.FanSpeed = hostModal.AirConditionData.FanSpeed;
FinallyData.Mode = hostModal.AirConditionData.Mode;
FinallyData.SettingTemp = hostModal.AirConditionData.SettingTemp;
FinallyData.UpdateTime = hostModal.UpdateTime;
FinallyData.Valve = hostModal.AirConditionData.Valve;
FinallyData.Modal = new RoomTypeModal()
if (!string.IsNullOrEmpty(hostModal.Modal.Name))
{
ID = hostModal.Modal.ID,
Name = hostModal.Modal.Name,
ModalAddress = hostModal.Modal.ModalAddress,
ActiveIndicator = hostModal.Modal.ActiveIndicator,
Sort = hostModal.Modal.Sort
};
FinallyData.Modal.RoomType = new RoomType()
{
ID = hostModal.Modal.RoomTypeID
};
FinallyData.Modal.ID = hostModal.Modal.ID;
FinallyData.UpdateTime = now;
#region
try
{
HostModalRecord hostModalRecord;
switch (StatusFlag)
bool bbbaaa = hostModal.Modal.Name.Contains("红外") || hostModal.Modal.Name.Contains("infrared") || hostModal.Modal.Name.Contains("雷达") || hostModal.Modal.Name.Contains("radar");
if (bbbaaa == false)
{
case 2://关闭设备
if (hostModal.UpdateTime.HasValue)
{
hostModal.Time += Convert.ToInt32((now - hostModal.UpdateTime.Value).TotalMinutes);
}
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
//阿宝添加内存
try
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 2;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
int StatusFlag = hostModal.Status;
HostModal FinallyData = new HostModal();
FinallyData.HostID = hostModal.HostID;
FinallyData.Status = hostModal.Status;
FinallyData.Brightness = hostModal.Brightness;
FinallyData.CurrentTemp = hostModal.AirConditionData.CurrentTemp;
FinallyData.FanSpeed = hostModal.AirConditionData.FanSpeed;
FinallyData.Mode = hostModal.AirConditionData.Mode;
FinallyData.SettingTemp = hostModal.AirConditionData.SettingTemp;
FinallyData.UpdateTime = hostModal.UpdateTime;
FinallyData.Valve = hostModal.AirConditionData.Valve;
}
}
break;
case 1://1打开设备
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
FinallyData.Modal = new RoomTypeModal()
{
ID = hostModal.Modal.ID,
Name = hostModal.Modal.Name,
ModalAddress = hostModal.Modal.ModalAddress,
ActiveIndicator = hostModal.Modal.ActiveIndicator,
Sort = hostModal.Modal.Sort
};
FinallyData.Modal.RoomType = new RoomType()
{
ID = hostModal.Modal.RoomTypeID
};
FinallyData.Modal.ID = hostModal.Modal.ID;
FinallyData.UpdateTime = now;
//阿宝这里修改
try
#region
try
{
HostModalRecord hostModalRecord;
switch (StatusFlag)
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception ex)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 1;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
case 2://关闭设备
if (hostModal.UpdateTime.HasValue)
{
hostModal.Time += Convert.ToInt32((now - hostModal.UpdateTime.Value).TotalMinutes);
}
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
//阿宝添加内存
try
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 2;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
}
}
}
break;
case 1://1打开设备
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
//阿宝这里修改
try
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception ex)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 1;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
}
}
break;
default:
break;
}
break;
default:
break;
string StatusKey = "RoomStatus_ServerInfo";
RCUHost.RCUHostCommon.tools.LanJieData(StatusKey, HOTEL_CODE);
CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
}
catch (Exception ex)
{
logger.Error("数据处理error: " + ex.Message);
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
#endregion
}
string StatusKey = "RoomStatus_ServerInfo";
RCUHost.RCUHostCommon.tools.LanJieData(StatusKey, HOTEL_CODE);
CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
}
catch (Exception ex)
{
logger.Error("数据处理error: " + ex.Message);
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
#endregion
}
#region kafka队列

View File

@@ -402,26 +402,6 @@ namespace RCUHost.Implement
}
//int hostid = host.ID;
//StringBuilder sb = new StringBuilder();
//sb.Append(CacheKey.CarbonVIP_Prefix);
//sb.Append("_");
//sb.Append(hostid.ToString());
//string Key = sb.ToString();
//CSRedisCacheHelper.Set<string>(Key, current_status);
//var data = CSRedisCacheHelper.Get<string>(Key);
//if (!string.IsNullOrEmpty(data))
//{
// if (!current_status.Equals(data))
// {
// CarbonDataSend(host, hhhg1);
// }
//}
//else
//{
// CarbonDataSend(host, hhhg1);
//}
CarbonDataSend(host, hhhg1);
var nfc = CarbonScene_SetRepository.GetDataBy(host.ID);
@@ -465,8 +445,6 @@ namespace RCUHost.Implement
}
string KKey = CacheKey.HostModalStatus_Prefix + "_" + host.ID + "_" + device.Value.Address;
var hostModal = CSRedisCacheHelper.Get_Partition<HostModal_Cache>(KKey);
if (hostModal != null)
{
@@ -475,21 +453,33 @@ namespace RCUHost.Implement
else
{
//这里有点问题如果一个Model删除了又更新了那它的ID就变了。但是内存中记录的没变所以这里会出问题
var hostModal_old = HostModalRepository.Get(host.ID, device.Value.Address);
//var hostModal_old = HostModalRepository.Get(host.ID, device.Value.Address);
string HostID_O = CSRedisCacheHelper.HMGet<string>(5, CacheKey.HostId_HostNumber, HOSTNUMBER)[0];
if (string.IsNullOrEmpty(HostID_O))
{
return;
}
string[] NNN111 = HostID_O.Split('#');
string HostID = NNN111[0];
string RoomTypeID = NNN111[1];
int room_type_id = int.Parse(RoomTypeID);
var hostModal_old= QuanJuVar.RoomTypeDeviceModal.FirstOrDefault(A=>A.RoomType.ID==room_type_id&&A.ModalAddress.Equals(device.Value.Address));
if (hostModal_old != null)
{
HostModal_Cache c = new HostModal_Cache();
c.HostID = hostModal_old.HostID;
c.ModalType = hostModal_old.Modal.Type;
c.HostID = host.ID;
c.ModalType = hostModal_old.Type;
c.AirConditionData = new AirConditionData();
c.Modal = new RoomTypeModalCache()
{
RoomTypeID = hostModal_old.Modal.RoomType.ID,
ID = hostModal_old.Modal.ID,
Name = hostModal_old.Modal.Name,
ModalAddress = hostModal_old.Modal.ModalAddress,
ActiveIndicator = hostModal_old.Modal.ActiveIndicator,
Sort = hostModal_old.Modal.Sort
RoomTypeID = hostModal_old.RoomType.ID,
ID = hostModal_old.ID,
Name = hostModal_old.Name,
ModalAddress = hostModal_old.ModalAddress,
ActiveIndicator = hostModal_old.ActiveIndicator,
Sort = hostModal_old.Sort
};
hostModal = c;
}
@@ -694,6 +684,7 @@ namespace RCUHost.Implement
}
else//设备关
{
#region
if (hostModal.Status != status)//设备有变化时才去更改状态窗帘6是停其他是关
{
flag = 0;
@@ -712,6 +703,7 @@ namespace RCUHost.Implement
hostModal.Status = status;
hostModal.Brightness = 0;
#endregion
}
}
catch (Exception ex)
@@ -721,7 +713,7 @@ namespace RCUHost.Implement
CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
#endregion
#region
#region ,
switch (hostModal.Modal.ModalAddress)
{
case "004000013"://门磁
@@ -748,13 +740,13 @@ namespace RCUHost.Implement
case "004000001"://取电
#region
//拨卡操作
if (flag == 0 && host.RoomCard != null)
{
//if (flag == 0 && host.RoomCard != null)
//{
//host.RoomCard = null;
//HostRepository.SetRoomCard(host, null);//拔卡操作
}
else if (flag == 1 && host.RoomCard == null)
{
//}
//else if (flag == 1 && host.RoomCard == null)
//{
//CSRedisCacheHelper.HMSet(CacheKey.TakeCardOnLine,host.SysHotel.Code+"###"+ host.RoomNumber);
//RoomCardType roomCardType = null;
@@ -801,7 +793,7 @@ namespace RCUHost.Implement
//}
//host.RoomCard = roomCard;
//HostRepository.SetRoomCard(host, roomCard);//插卡操作
}
//}
#region
if (flag != 2)//取电或断电时处理
@@ -1699,138 +1691,143 @@ namespace RCUHost.Implement
//只有服务信息才会入库
//bool isonly_serviceinfo = true;
bool bbbaaa = hostModal.Modal.Name.Contains("红外") || hostModal.Modal.Name.Contains("infrared") || hostModal.Modal.Name.Contains("雷达") || hostModal.Modal.Name.Contains("radar");
if (hostModal.ModalType == DeviceType.ServiceInfo && bbbaaa == false)
if (hostModal.ModalType == DeviceType.ServiceInfo)
{
HostModal FinallyData = new HostModal();
FinallyData.HostID = hostModal.HostID;
FinallyData.Status = hostModal.Status;
FinallyData.Brightness = hostModal.Brightness;
FinallyData.CurrentTemp = hostModal.AirConditionData.CurrentTemp;
FinallyData.FanSpeed = hostModal.AirConditionData.FanSpeed;
FinallyData.Mode = hostModal.AirConditionData.Mode;
FinallyData.SettingTemp = hostModal.AirConditionData.SettingTemp;
FinallyData.UpdateTime = hostModal.UpdateTime;
FinallyData.Valve = hostModal.AirConditionData.Valve;
FinallyData.Modal = new RoomTypeModal()
if (!string.IsNullOrEmpty(hostModal.Modal.Name))
{
ID = hostModal.Modal.ID,
Name = hostModal.Modal.Name,
ModalAddress = hostModal.Modal.ModalAddress,
ActiveIndicator = hostModal.Modal.ActiveIndicator,
Sort = hostModal.Modal.Sort
};
FinallyData.Modal.RoomType = new RoomType()
{
ID = hostModal.Modal.RoomTypeID
};
FinallyData.Modal.ID = hostModal.Modal.ID;
FinallyData.UpdateTime = now;
#region
try
{
HostModalRecord hostModalRecord;
switch (flag)
bool bbbaaa = hostModal.Modal.Name.Contains("红外") || hostModal.Modal.Name.Contains("infrared") || hostModal.Modal.Name.Contains("雷达") || hostModal.Modal.Name.Contains("radar");
if (bbbaaa == false)
{
case 0://0关闭设备
if (hostModal.UpdateTime.HasValue)
{
hostModal.Time += Convert.ToInt32((now - hostModal.UpdateTime.Value).TotalMinutes);
}
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
//阿宝添加内存
try
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
//CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 2;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
HostModal FinallyData = new HostModal();
FinallyData.HostID = hostModal.HostID;
FinallyData.Status = hostModal.Status;
FinallyData.Brightness = hostModal.Brightness;
FinallyData.CurrentTemp = hostModal.AirConditionData.CurrentTemp;
FinallyData.FanSpeed = hostModal.AirConditionData.FanSpeed;
FinallyData.Mode = hostModal.AirConditionData.Mode;
FinallyData.SettingTemp = hostModal.AirConditionData.SettingTemp;
FinallyData.UpdateTime = hostModal.UpdateTime;
FinallyData.Valve = hostModal.AirConditionData.Valve;
}
}
break;
case 1://1打开设备且当前设备处于关闭状态
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
//阿宝这里修改
try
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception ex)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
//CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 1;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
FinallyData.Modal = new RoomTypeModal()
{
ID = hostModal.Modal.ID,
Name = hostModal.Modal.Name,
ModalAddress = hostModal.Modal.ModalAddress,
ActiveIndicator = hostModal.Modal.ActiveIndicator,
Sort = hostModal.Modal.Sort
};
FinallyData.Modal.RoomType = new RoomType()
{
ID = hostModal.Modal.RoomTypeID
};
FinallyData.Modal.ID = hostModal.Modal.ID;
FinallyData.UpdateTime = now;
}
}
break;
case 2://2打开设备且当前设备处于打开状态
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
try
#region
try
{
HostModalRecord hostModalRecord;
switch (flag)
{
HostModalRepository.Update(FinallyData);
case 0://0关闭设备
if (hostModal.UpdateTime.HasValue)
{
hostModal.Time += Convert.ToInt32((now - hostModal.UpdateTime.Value).TotalMinutes);
}
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
//阿宝添加内存
try
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
//CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 2;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
}
}
break;
case 1://1打开设备且当前设备处于关闭状态
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
//阿宝这里修改
try
{
HostModalRepository.Update(FinallyData);//sbSQL.ToString());
}
catch (Exception ex)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
//CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
if (hostModal.Modal.ActiveIndicator)//处理回路状态记录,只记录启用的回路 add by wuzhuihui 20190918
{
hostModalRecord = new HostModalRecord();
hostModalRecord.HostID = host.ID;
hostModalRecord.RoomNumber = host.RoomNumber;
hostModalRecord.RoomTypeID = host.RoomType.ID;
hostModalRecord.RoomTypeModalID = hostModal.Modal.ID;
hostModalRecord.ModalAddress = hostModal.Modal.ModalAddress;
hostModalRecord.StartTime = now;
hostModalRecord.Status = 1;
try
{
HostModalRecordRepository.Save(hostModalRecord);
}
catch (Exception)
{
}
}
break;
case 2://2打开设备且当前设备处于打开状态
hostModal.UpdateTime = now;
FinallyData.UpdateTime = now;
try
{
HostModalRepository.Update(FinallyData);
}
catch (Exception ex)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
//CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
break;
}
catch (Exception ex)
{
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
//CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
break;
string StatusKey = "RoomStatus_ServerInfo";
RCUHost.RCUHostCommon.tools.LanJieData(StatusKey, HOTEL_CODE);
CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
}
catch (Exception ex)
{
logger.Error("数据处理error: " + ex.Message);
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
#endregion
}
string StatusKey = "RoomStatus_ServerInfo";
RCUHost.RCUHostCommon.tools.LanJieData(StatusKey, HOTEL_CODE);
CSRedisCacheHelper.Set_Partition<HostModal_Cache>(KKey, hostModal);
}
catch (Exception ex)
{
logger.Error("数据处理error: " + ex.Message);
logger.Error(FinallyData.HostID + ":" + host.SysHotel.Code + " " + hostModal.Modal.ModalAddress);
}
#endregion
}
else
{