初始化CRICS
This commit is contained in:
75
RCUHost/TimingHelper/Common.cs
Normal file
75
RCUHost/TimingHelper/Common.cs
Normal file
@@ -0,0 +1,75 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using CommonEntity;
|
||||
using RestSharp;
|
||||
using Common;
|
||||
using System.Configuration;
|
||||
using Domain;
|
||||
using Dao.Implement;
|
||||
|
||||
namespace RCUHost.TimingHelper
|
||||
{
|
||||
public class Common
|
||||
{
|
||||
|
||||
//public static Host GetByHostNumber(string hostno)
|
||||
//{
|
||||
// StringBuilder sb = new StringBuilder();
|
||||
// sb.Append("HostNumber_");
|
||||
// sb.Append(hostno);
|
||||
// string Key = sb.ToString();
|
||||
// object HOSTNO = MemoryCacheHelper.Get(Key);
|
||||
|
||||
// Host host = null;
|
||||
// if (HOSTNO == null)
|
||||
// {
|
||||
// host = HostRepository.GetByHostNumber(hostno);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// host = (Host)HOSTNO;
|
||||
// }
|
||||
// return host;
|
||||
//}
|
||||
|
||||
public static readonly string debug_log_report_url = ConfigurationManager.AppSettings["debug_log_report_url"];
|
||||
public static readonly string debug_log_report_mqtt_topic = ConfigurationManager.AppSettings["debug_log_report_mqtt_topic"];
|
||||
private static log4net.ILog logger = log4net.LogManager.GetLogger(typeof(Common));
|
||||
|
||||
public static void SendLog(string MyCommandType, long hotel_code, int host_id, string roomnumber, string hostnumber, string WWW_IP, int WWW_Port, string lan_ip, int lan_port, string mac, string dataHex)
|
||||
{
|
||||
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
|
||||
MonitorLog mm = new MonitorLog();
|
||||
mm.HotelCode = hotel_code;
|
||||
mm.HostID = host_id;
|
||||
mm.HostNumber = hostnumber;
|
||||
mm.RoomNo = roomnumber;
|
||||
|
||||
mm.LanIP = lan_ip;
|
||||
mm.LanPort = lan_port;
|
||||
mm.WWW_IP = WWW_IP;
|
||||
mm.WWW_Port = WWW_Port;
|
||||
|
||||
mm.MAC = mac;
|
||||
mm.SendOrReceive = "Receive";
|
||||
mm.CommandType = MyCommandType;
|
||||
mm.Data = dataHex;
|
||||
mm.CreateTime = ti;
|
||||
|
||||
|
||||
string str = Newtonsoft.Json.JsonConvert.SerializeObject(mm);
|
||||
var client1 = new RestClient(debug_log_report_url);
|
||||
var request1 = new RestRequest("/", Method.POST);
|
||||
|
||||
//注意方法是POST
|
||||
//两个参数名字必须是 topic 和payload ,区分大小写的
|
||||
request1.AddParameter("topic", debug_log_report_mqtt_topic);
|
||||
request1.AddParameter("payload", str);
|
||||
|
||||
|
||||
client1.ExecuteAsync(request1, (response) => { });
|
||||
}
|
||||
}
|
||||
}
|
||||
159
RCUHost/TimingHelper/HostTimingControlHelper.cs
Normal file
159
RCUHost/TimingHelper/HostTimingControlHelper.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Data;
|
||||
using Domain;
|
||||
using Dao;
|
||||
using RCUHost;
|
||||
using RCUHost.Protocols;
|
||||
using Spring.Context;
|
||||
using Spring.Context.Support;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace RCUHost.TimingHelper
|
||||
{
|
||||
public sealed class HostTimingControlHelper
|
||||
{
|
||||
private static IHostRepository HostRepository { get; set; }
|
||||
private static IHostTimingControlRepository HostTimingControlRepository { get; set; }
|
||||
private static IRoomTypeSceneModalRepository RoomTypeSceneModalRepository { get; set; }
|
||||
private static IRoomTypeSceneRepository RoomTypeSceneRepository { get; set; }
|
||||
private static IDeviceControlReceiver _DeviceControlReceiver;
|
||||
|
||||
public static void HostTimingControl(IDeviceControlReceiver deviceControlReceiver)
|
||||
{
|
||||
System.Threading.Tasks.Task.Factory.StartNew(() =>
|
||||
{
|
||||
_DeviceControlReceiver = deviceControlReceiver;
|
||||
using (DataTable dt = HostTimingControlRepository.LoadHostTimingToExec())
|
||||
{
|
||||
foreach (DataRow row in dt.Rows)
|
||||
{
|
||||
DateTime now = DateTime.Now;
|
||||
switch (Convert.ToInt16(row["TimingType"]))
|
||||
{
|
||||
case 0://每天定时发送场景
|
||||
ExecHostTiming(row, now);
|
||||
break;
|
||||
case 1://每周
|
||||
foreach (string week in row["TimingDay"].ToString().Split(','))
|
||||
{
|
||||
if (Convert.ToInt16(week) == Convert.ToInt16(now.DayOfWeek))
|
||||
{
|
||||
ExecHostTiming(row, now);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 2://每月
|
||||
foreach (string day in row["TimingDay"].ToString().Split(','))
|
||||
{
|
||||
if (Convert.ToInt16(day) == now.Day)
|
||||
{
|
||||
ExecHostTiming(row, now);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}, System.Threading.CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default);
|
||||
}
|
||||
/// <summary>
|
||||
/// 处理定时任务
|
||||
/// </summary>
|
||||
/// <param name="row"></param>
|
||||
/// <param name="now"></param>
|
||||
private static void ExecHostTiming(DataRow row, DateTime now)
|
||||
{
|
||||
foreach (string timing in row["Timing"].ToString().Split(','))
|
||||
{
|
||||
DateTime dtTiming = Convert.ToDateTime(now.ToString("yyyy-MM-dd") + " " + timing);// row["Timing"].ToString());
|
||||
double totalMinutes = (now - dtTiming).TotalMinutes;
|
||||
if (totalMinutes >= 0 && totalMinutes < 6)//6分钟以内执行,超过不执行
|
||||
{
|
||||
foreach (string hostID in row["HostIDs"].ToString().Split(','))
|
||||
{
|
||||
SendSceneToHost(Convert.ToInt32(hostID), Convert.ToInt32(row["RoomTypeSceneID"]), Convert.ToInt16(row["RoomStatusID"]), Convert.ToInt16(row["RoomCardTypeID"]));
|
||||
}
|
||||
HostTimingControl htc = HostTimingControlRepository.Get(Convert.ToInt32(row["ID"]));
|
||||
htc.ExecStatus = true;
|
||||
htc.ExecTime = now;
|
||||
HostTimingControlRepository.Update(htc);
|
||||
}
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// 发送场景指令
|
||||
/// </summary>
|
||||
/// <param name="hostID"></param>
|
||||
/// <param name="roomTypeSceneID">场景ID</param>
|
||||
/// <param name="roomStatusID">房态ID</param>
|
||||
/// <param name="roomCardTypeID">房卡类型ID</param>
|
||||
private static void SendSceneToHost(Int32 hostID, Int32 roomTypeSceneID, int roomStatusID, int roomCardTypeID)
|
||||
{
|
||||
Host host = HostRepository.Get(hostID);
|
||||
if (null == host)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (roomStatusID > 0 && host.RoomStatus == null)//房态空的情况
|
||||
{
|
||||
//return;
|
||||
}
|
||||
if (roomStatusID > 0 && host.RoomStatus != null && host.RoomStatus.ID != roomStatusID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
//出租无人的情况下也要
|
||||
if (roomCardTypeID > -1 && host.RoomCard == null)//房卡是空的情况
|
||||
{
|
||||
//所以下面的要注释掉
|
||||
//return;
|
||||
}
|
||||
if (roomCardTypeID > -1 && host.RoomCard != null && host.RoomCard.RoomCardType.ID != roomCardTypeID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
RoomTypeScene rts = RoomTypeSceneRepository.Get(roomTypeSceneID);
|
||||
|
||||
if (rts.Type == SceneType.Custom)
|
||||
{
|
||||
var sceneModals = RoomTypeSceneModalRepository.LoadAll(rts);
|
||||
if (sceneModals.Count > 0)
|
||||
{
|
||||
var devices = new List<Device>();
|
||||
foreach (var sceneModal in sceneModals)
|
||||
{
|
||||
Device device = new Device();
|
||||
device.Address = sceneModal.Modal.ModalAddress;
|
||||
device.AddressType = AddressType.DeviceAddress;
|
||||
device.Type = sceneModal.Modal.Type;
|
||||
device.Status = (byte)sceneModal.Status;
|
||||
device.Brightness = (byte)sceneModal.Brightness;
|
||||
device.Temperature = (byte)sceneModal.CurrentTemp;
|
||||
device.FanSpeed = (byte)sceneModal.FanSpeed;
|
||||
device.Mode = (byte)sceneModal.Mode;
|
||||
device.Valve = (byte)sceneModal.Valve;
|
||||
device.AirExecMode = (sceneModal.Status << 14) + (sceneModal.Mode << 12) + (sceneModal.FanSpeed << 10) + (sceneModal.Valve << 8) + sceneModal.CurrentTemp;//空调执行方式和内容
|
||||
device.FloorHotExecMode = (sceneModal.Status << 12) + (sceneModal.Mode << 8) + (sceneModal.Valve << 6) + sceneModal.CurrentTemp;//地暖执行方式和内容
|
||||
device.MusicExecMode = sceneModal.Status + (sceneModal.Brightness << 12) + (sceneModal.Mode << 8);//背景音乐执行方式和内容
|
||||
devices.Add(device);
|
||||
}
|
||||
_DeviceControlReceiver.Send(host, devices);
|
||||
}
|
||||
}
|
||||
else if (rts.Type == SceneType.Command)
|
||||
{
|
||||
Device device = new Device();
|
||||
device.Address = rts.GroupAddress;
|
||||
device.AddressType = AddressType.GroupAddress;
|
||||
device.Status = 0x01;
|
||||
_DeviceControlReceiver.Send(host, device);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user