using System;
|
using System.Collections.Generic;
|
namespace HDL_ON.UI.UI2.Intelligence.Automation
|
{
|
/// <summary>
|
/// 逻辑存储数据对象
|
/// </summary>
|
public class Logic
|
{
|
/// <summary>
|
/// 逻辑唯一标识
|
/// </summary>
|
public string sid = "";
|
/// <summary>
|
/// 逻辑名称
|
/// </summary>
|
public string name = "逻辑一";
|
/// <summary>
|
/// 逻辑条件关系(与and:,或:or)
|
/// </summary>
|
public string relation = "or";
|
/// <summary>
|
/// 逻辑状态(true,false)
|
/// </summary>
|
public string enable = "true";
|
/// <summary>
|
/// 逻辑执行循环周期(执行一次,每天,每月,星期)
|
/// </summary>
|
public Cycle cycle = new Cycle();
|
/// <summary>
|
/// 逻辑输入条件数组
|
/// </summary>
|
public List<Input> input = new List<Input>();
|
/// <summary>
|
/// 逻辑输出目标数组
|
/// </summary>
|
public List<Output> output = new List<Output>();
|
/// <summary>
|
/// 生成逻辑sid方法
|
/// </summary>
|
public string NewSid()
|
{
|
string logicId = "";
|
try
|
{
|
string sOidBeginsWith = "000101";//厂商 + 通讯方式
|
DateTime dt = DateTime.Now;
|
DateTime startTime = TimeZoneInfo.ConvertTimeToUtc(new DateTime(2020, 1, 1));
|
long m = (long)((dt - startTime).TotalMilliseconds / 10);
|
string sTimeSpan = "00000000";
|
|
byte[] arry = new byte[4];
|
arry[0] = (byte)(m & 0xFF);
|
arry[1] = (byte)((m & 0xFF00) >> 8);
|
arry[2] = (byte)((m & 0xFF0000) >> 16);
|
arry[3] = (byte)((m >> 24) & 0xFF);
|
sTimeSpan = arry[0].ToString("X2") + arry[1].ToString("X2") + arry[2].ToString("X2") + arry[3].ToString("X2");
|
|
|
if (sTimeSpan.Length > 8)
|
{
|
sTimeSpan = sTimeSpan.Substring(0, 8);
|
}
|
else
|
{
|
sTimeSpan = "00000000";
|
}
|
|
logicId = sOidBeginsWith + sTimeSpan;
|
|
logicId += "0A";
|
logicId += "0A01";
|
//0A01 物模型为逻辑, 0001 表示 1 号逻辑功能
|
int iTopLogicId = 1;
|
|
Random random = new Random();
|
iTopLogicId = random.Next(0, 255);
|
iTopLogicId += random.Next(0, 255);
|
|
logicId += iTopLogicId.ToString("X4");//逻辑号 两个byte
|
logicId += "1100";
|
}
|
catch
|
{
|
return logicId;
|
}
|
return logicId;
|
}
|
|
}
|
/// <summary>
|
/// 执行周期对象
|
/// </summary>
|
public class Cycle
|
{
|
/// <summary>
|
/// 时间类型
|
/// (执行一次:once,每天:day,每月:mon,星期:week,日期段:date_to_date)
|
/// </summary>
|
public string type = "";
|
public List<string> value = new List<string>();
|
}
|
/// <summary>
|
/// 输入条件对象
|
/// </summary>
|
public class Input
|
{
|
/// <summary>
|
/// 逻辑输入条件唯一标识
|
/// </summary>
|
public string sid = "";
|
/// <summary>
|
/// 逻辑输入条件类型
|
/// 时间点条件=1;
|
/// 时间段条件=2;
|
/// 设备状态变化条件=3;
|
/// 环境信息条件=4;
|
/// 安防条件=5;
|
/// 云端天气条件=6;
|
/// 某个逻辑/场景的输出条件=7;
|
/// 地理围栏=8;
|
/// </summary>
|
public string condition_type = "";
|
public List<Dictionary<string, string>> condition = new List<Dictionary<string, string>>();
|
}
|
/// <summary>
|
/// 输出目标对象
|
/// </summary>
|
public class Output
|
{
|
/// <summary>
|
/// 逻辑输出目标唯一标识
|
/// </summary>
|
public string sid = "";
|
/// <summary>
|
/// 逻辑输出目标类型
|
/// 设备=1;
|
/// 场景=2;
|
/// 安防=3;
|
/// </summary>
|
public string target_type = "";
|
public List<Dictionary<string, string>> status = new List<Dictionary<string, string>>();
|
}
|
|
|
}
|