Files
Web_CRICS_Server_VS2010_Prod/ConsoleApplication2/Program.cs

698 lines
23 KiB
C#
Raw Normal View History

2025-12-11 09:17:16 +08:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Jose;
using System.Timers;
using Common;
using System.IO;
using System.Threading.Tasks;
using System.Threading;
using FluentScheduler;
using System.Xml;
using System.Xml.Linq;
using System.Collections;
using System.Security.Cryptography.X509Certificates;
using System.Diagnostics;
using System.Runtime.InteropServices;
using RCUHost.Protocols;
using RestSharp;
using Domain.IoTFerErEntity;
using System.Net;
using System.Collections.Concurrent;
using RCUHost.Implement;
using Domain;
using Newtonsoft.Json;
using CommonEntity;
using Newtonsoft.Json.Linq;
namespace ConsoleApplication2
{
class Program
{
public static string NormalizeVersion(string version, int desiredParts = 3)
{
// 移除末尾的冗余点并分割
var parts = version.TrimEnd('.').Split(new[] { '.' }, StringSplitOptions.RemoveEmptyEntries);
// 补零到目标位数
while (parts.Length < desiredParts)
{
parts = parts.Concat(new[] { "0" }).ToArray();
}
return string.Join(".", parts);
}
public struct A
{
public string id { get; set; }
public string name { get; set; }
}
static System.Timers.Timer t = null;
public enum Fruit
{
Apple, Bear
}
public class GA
{
public string NNN { get; set; }
public Fruit FFF { get; set; }
}
public class GGG
{
public string Name { get; set; }
}
[DllImport("kernel32.dll")]
private static extern void GetSystemTimePreciseAsFileTime(out long fileTime);
// 将 FILETIME (long) 转换为 DateTime
public static DateTime GetNowPrecise()
{
long fileTime;
GetSystemTimePreciseAsFileTime(out fileTime);
DateTime localTime = DateTime.FromFileTimeUtc(fileTime).ToLocalTime();
return localTime;
}
static byte[] GetBytesFromString(string hexString)
{
byte[] bytes = new byte[hexString.Length / 2]; // 计算字节数组的长度
for (int i = 0; i < bytes.Length; i++)
{
bytes[i] = Convert.ToByte(hexString.Substring(i * 2, 2), 16); // 每次取两个字符转换为字节
}
return bytes;
}
static void JieXi()
{
string strnn1 = "AA 55 2F 00 54 33 53 41 02 34 80 EB 03 6B 24 34 D0 B8 11 6B 24 01 01 01 39 01 01 00 10 F0 55 E8 03 E8 03 00 00 E8 03 00 00 E8 03 00 00 9E 00";
//AA 55 2F 00 54 33 53 41 02 34 80 EB 03 6B 24
//34 D0 B8 11 6B 24
//01 解析版本
//01 取电
//01 设备数量
//39
//01
//01
//00
//10 ///长度
//F0 55 //电压
//E8 03 //电流
//E8 03 00 00 功率
//E8 03 00 00 能耗
//E8 03 00 00 总能耗
//9E 00
byte[] nnnafd = GetBytesFromString(strnn1.Replace(" ", ""));
byte[] Data = GetBytesFromString(strnn1.Replace(" ", ""));
byte[] MAC = Data.Skip(15).Take(6).ToArray();
byte Version = Data.Skip(21).Take(1).FirstOrDefault();
//从第21个数据开始
byte TakeCard = Data.Skip(22).Take(1).FirstOrDefault();
//设备数量
byte DeviceCount = Data.Skip(23).Take(1).FirstOrDefault();
byte LeiXing = Data.Skip(24).Take(1).FirstOrDefault();
byte Address = Data.Skip(25).Take(1).FirstOrDefault();
byte[] Num = Data.Skip(26).Take(2).ToArray();
List<byte> lll = new List<byte>();
lll.Add(LeiXing);
lll.Add(Address);
lll.AddRange(Num);
string address = new DeviceAddress(lll.ToArray()).ToString();
byte Len = Data.Skip(28).Take(1).FirstOrDefault();
byte[] DianYa = Data.Skip(29).Take(2).ToArray();
byte[] DianLiu = Data.Skip(31).Take(2).ToArray();
byte[] Power = Data.Skip(33).Take(4).ToArray();
byte[] PowerUsed = Data.Skip(37).Take(4).ToArray();
byte[] TotalPowerUsed = Data.Skip(41).Take(4).ToArray();
int dianya = BitConverter.ToUInt16(DianYa, 0);
int dianliu = BitConverter.ToInt16(DianLiu, 0);
int gonglv = BitConverter.ToInt32(Power, 0);
int nenghao = BitConverter.ToInt32(PowerUsed, 0);
int zongnenghao = BitConverter.ToInt32(TotalPowerUsed, 0);
int V = dianya * 10 / 1000;
int A = dianliu * 10 / 1000;
int P = gonglv * 10 / 1000;
decimal KW_H = nenghao / 1000;
decimal Sum_KW_H = zongnenghao / 1000;
}
public class VVV
{
public DateTime ddd { get; set; }
public VVV()
{
this.ddd = DateTime.Now;
}
}
public class AUser
{
public string username { get; set; }
public string password { get; set; }
public int oauth_id { get; set; }
}
public static void FCSLLL()
{
try
{
//ssl 协议不兼容
var A = (SecurityProtocolType)48;
var B = (SecurityProtocolType)192;
var C = (SecurityProtocolType)768;
var D = (SecurityProtocolType)3072;
var E = (SecurityProtocolType)12288;
ServicePointManager.SecurityProtocol = A | B | C | D | E;
string FCSLoginUrl = "https://api.fcs1cloud.com";
string FCSLoginUserName = "hb.rcu";
string FCSLoginPassWord = "P@1234";
var client1 = new RestClient(FCSLoginUrl);
var request1 = new RestRequest("/api/security/authenticate", Method.POST);
//request1.AddHeader("Content-Type", "application/json");
AUser us = new AUser();
us.username = FCSLoginUserName;
us.password = FCSLoginPassWord;
us.oauth_id = 1;
request1.AddJsonBody(us);
//request1.AddBody(Newtonsoft.Json.JsonConvert.SerializeObject(us), DataFormat.Json);
var QQQ = client1.Execute(request1);
var UUN = QQQ.Content;
HttpStatusCode HHH = QQQ.StatusCode;
if (HHH == HttpStatusCode.Created || HHH == HttpStatusCode.OK)
{
string ddd = QQQ.Content;
}
}
catch (Exception ex)
{
}
}
public static ConcurrentQueue<string> ssslist = new ConcurrentQueue<string>();
public class A1
{
public string id { get; set; }
public string name { get; set; }
}
2025-12-17 10:51:23 +08:00
public struct Tiao
{
public string Nsa { get; set; }
}
public static void Data()
{
XuanZhuResponse resp = new XuanZhuResponse();
resp.code = "1085";
resp.roomNumber = "1001";
resp.address = "";
resp.name = "";
resp.status = 1;
if (resp.status == 1)
{
resp.brightness = 0;
resp.currentTemp = 25;
resp.settingTemp = 25;
resp.mode = 1;
resp.fanSpeed = 1;
resp.valve = 0;
}
MyHttp.SendHttpData("http://f-xcx.blv-oa.com/rcu/report", resp);
2025-12-17 10:51:23 +08:00
}
2025-12-11 09:17:16 +08:00
static void Main(string[] args)
{
Data();
Console.ReadLine();
string uuawer = string.Concat("h", "eeeelll");
2025-12-11 09:17:16 +08:00
string QQQQSSS = File.ReadAllText("3.txt", Encoding.UTF8);
var FFF = JsonConvert.DeserializeObject<FCS_Response>(QQQQSSS);
JObject jsonObject = JObject.Parse(QQQQSSS);
var error = jsonObject.SelectToken("error");
2025-12-11 09:17:16 +08:00
var JJJ = FFF.data.FirstOrDefault();
if (JJJ != null)
{
string orderuuid = JJJ.job_uuid;
FCS_OrderData f = new FCS_OrderData();
f.OrderUUID = orderuuid;
f.PropertyID = "";
f.ItemType = "Clean";
f.OrderNo = JJJ.job_no;
f.ItemUUID = "";
f.LocationUUID = "";
f.HotelCode = "";
f.RoomNUMBER = "";
string fsa = Newtonsoft.Json.JsonConvert.SerializeObject(f);
//这个是 供轮循的时候调用使用
CSRedisCacheHelper.HMSet(3, 60 * 24, CacheKey.FCSOrder, "aaa", fsa);
//这个是供 取消订单的时候使用的
//这个只 支持 取消 清理
//logger.Error("记录入循环:"+orderuuid);
CSRedisCacheHelper.Set_PartitionWithTime(CacheKey.FCSRoom_Mapping_Order + "_" + "", orderuuid, 24 * 60, 3);
}
//string orderuuid = JJJ.job_uuid;
2025-12-11 09:17:16 +08:00
AskRoomStatusChangedReceiver h = new AskRoomStatusChangedReceiver();
RoomStatus vv = new RoomStatus();
vv.ID = 0x10;
h.SendRoomStatusSelfNew("123", "321", vv, new byte[] { 0xee, 0xff }, 0x70);
string NNU11232 = Guid.NewGuid().ToString("N");
List<A1> list112 = new List<A1>(){new A1{id="1",name="A"},
new A1(){id="2",name="B"}};
List<string> flattenedList = list112.SelectMany(a => new[] { a.id, a.name }).ToList();
string result3432432 = string.Join(",", flattenedList); // 输出 "1,A,2,B"
CSRedisCacheHelper.HMSet(5, "UUU", "1", "333333", "2", "3434342");
int afdfdsa = 1;
string fdfd = afdfdsa.ToString("000");
ssslist.Enqueue("aaaaaa");
string wer = "233003112125";
var nnha = Tools.HostNumberToHotelCode(wer);
bool isNumeric = wer.All(char.IsDigit);
byte Chaka = CSRedisCacheHelper.Get_Partition<byte>("NNNNNNNNNNN", 5);
CSRedisCacheHelper.HMSet(5, "A", "1", "333333");
CSRedisCacheHelper.HMSet(5, "A", "2", "2222222222");
CSRedisCacheHelper.HMSet(5, "A", "3", "1111111111111");
var nnafdssfd = CSRedisCacheHelper.HMGetAll(5, "A");
var nnafdssfd1 = CSRedisCacheHelper.HMGet<string>(5, "A", "3");
var bb = new byte[] { 0x00, 0x01, 0x02, 0x03 };
var KKKFFF = BitConverter.ToString(bb);
VVV vva = new VVV();
Console.WriteLine(vva.ddd);
uint yua = 30;
double ddaf = (double)yua / 1000;
double dddjkl = Math.Round(13.722);
System.Timers.Timer timer2 = new System.Timers.Timer(1000);//每20秒扫描一次
timer2.Elapsed += new ElapsedEventHandler(timer2_Elapsed); ;//定时同步PMS房态
timer2.Enabled = true;
timer2.AutoReset = true;
long lln = Tools.GetUnixTime();
DateTime nd = Tools.GetTimeFromUnixTime(lln);
// 小端数字节数组(低位在前,高位在后)
byte[] littleEndianBytes = { 0xE8, 0x03, 0x00, 0x00 }; // 表示1000
// 直接转换为intBitConverter会自动处理端序
int result = BitConverter.ToInt32(littleEndianBytes, 0);
JieXi();
DateTime ddd = GetNowPrecise();
string tii = ddd.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
Console.WriteLine(tii);
Console.ReadLine();
List<GGG> lllus = new List<GGG>();
for (int i = 0; i < 10; i++)
{
GGG g = new GGG();
g.Name = i.ToString();
lllus.Add(g);
}
//Tuple<List<GGG>> lllaf = new Tuple<List<GGG>>(lllus);
List<GGG> newlist = lllus;
foreach (var item in lllus)
{
Task.Factory.StartNew(() =>
{
Console.WriteLine(item.Name);
});
}
Console.ReadLine();
System.Collections.Concurrent.ConcurrentQueue<string> NNA = new System.Collections.Concurrent.ConcurrentQueue<string>();
Task.Factory.StartNew(() =>
{
}).ContinueWith((mytask) =>
{
});
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
Console.WriteLine(ti);
byte[] b1 = new byte[] { 0x01, 0x02, 0x03, 0x04 };
byte[] b2 = new byte[] { 0x01, 0x02, 0x03, 0x04, 0x05 };
bool bbbnfm = b1.SequenceEqual<byte>(b2);
foreach (var name in Enum.GetNames(typeof(Domain.DeviceType)))
{
Console.WriteLine(name);
}
long lll = Tools.GetCurrentTimeStamp(DateTime.Now);
DateTime ddf = Tools.GetCurrentDateTime(lll);
var payload = new Dictionary<string, object>()
{
//{ "sub", "mr.x@contoso.com" },
//{ "exp", 1300819380 }
//iss发行人
//exp到期时间
//sub主题
//aud用户
//nbf在此之前不可用
//iat发布时间
//jtiJWT ID用于标识该JWT
};
var secretKey = Encoding.UTF8.GetBytes("#myemqtt123");
string token = Jose.JWT.Encode(payload, secretKey, JwsAlgorithm.HS256);
token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJtci54QGNvbnRvc28uY29tIiwiZXhwIjoxMzAwODE5MzgwfQ.nch1wu8T_rsT_bywCOm2W-qO2jcv69RsrrmpWU6fdDE";
//var MMU = Jose.JWT.DecodeBytes(token, secretKey, JwsAlgorithm.HS256);
//var NNN = Jose.JWT.Decode(token, secretKey);
//var n1 = Jose.JWT.Verify(token, secretKey);
var privateKey = new X509Certificate2("mycert.p12", "123456").PrivateKey;
string token3 = Jose.JWT.Encode(payload, privateKey, JwsAlgorithm.RS256);
Console.WriteLine(token);
GA gvb = new GA();
gvb.NNN = "fdfdf";
gvb.FFF = Fruit.Apple;
string qwerty = Newtonsoft.Json.JsonConvert.SerializeObject(gvb);
var QQR = Newtonsoft.Json.JsonConvert.DeserializeObject<GA>(qwerty);
var JK = new A { id = "1", name = "1" };
var JJ = new A { id = "1", name = "1" };
Console.WriteLine(JK.Equals(JJ));
List<A> lla = new List<A>() {
new A{id="1",name="1"},
new A{id="2",name="2"}
};
List<A> llb = new List<A>() {
new A{id="1",name="1"},
new A{id="3",name="3"},
};
var QQQ = llb.Except<A>(lla).ToList();
t = new System.Timers.Timer();
t.Interval = 1000;
t.Elapsed += new ElapsedEventHandler(t_Elapsed);
t.Start();
do
{
Console.WriteLine("输入时间");
string nnn = Console.ReadLine();
int a = int.Parse(nnn);
t.Interval = a;
} while (true);
//XmlDocument xmlDoc = new XmlDocument();
//XmlElement element = xmlDoc.CreateElement("item"); // 创建元素
//element.SetAttribute("id", "1"); // 设置属性
//element.InnerText = "示例文本"; // 设置文本内容
//xmlDoc.DocumentElement.AppendChild(element); // 将元素添加到根元素下
//xmlDoc.Save("example.xml"); // 保存XML文件
XElement xelement = new XElement("interface",
new XAttribute[]
{
new XAttribute("orderno",""),
new XAttribute("cost",""),
new XAttribute("roomtype",""),
new XAttribute("breakfast",""),
new XAttribute("occupancy",""),
new XAttribute("deposit","")
},
new XElement("item",
new XAttribute[]
{
new XAttribute("idtype", "1"),
new XAttribute("idcard", "1"),
new XAttribute("customer", "1"),
new XAttribute("sex", "1"),
new XAttribute("country", "1"),
new XAttribute("checkindate", "1"),
new XAttribute("checkoutdate", "1")
},
"示例文本")
);
string hhh = xelement.ToString();
List<int> lllg = new List<int>();
lllg = null;
lllg.DefaultIfEmpty();
double aaq = double.Parse("10.0");
int gh = Convert.ToInt32(aaq);
// 调用示例
string input = "15.0.1";
string output = NormalizeVersion(input); // 输出 "15.0.0"
// 添加调度任务
JobManager.AddJob(
// 调度业务
() => Console.WriteLine("5 minutes just passed."),
// 触发时间
s => s.ToRunEvery(5).Seconds()
);
//// 立即停止
//JobManager.Stop();
//// 在任务完成后等待或者停止
//JobManager.StopAndBlock();
Console.ReadLine();
for (int i = 0; i < 10000; i++)
{
Task.Factory.StartNew(() =>
{
Thread.Sleep(5000);
Console.WriteLine("iiiii");
});
}
Console.ReadKey();
string aaa = File.ReadAllText("1.txt", Encoding.UTF8);
aaa = aaa.Replace("\\\\\\", "\\");
int? bba1 = null;
Console.WriteLine(bba1);
bool bba = SmartRobotDisable();
ChuangWeiCommandData mmm = new ChuangWeiCommandData();
mmm.nlp_namespace = "hotelcontrol";
mmm.nlp_name = "LocalDDD";
mmm.query = "打开房灯";
mmm.resourcePackage = new PackageData()
{
skillSource = "智能家居",
domain = "iot",
aiState = 0,
voiceprint = "",
skillTitle = "",
tips = "你可以对我说,小度小度"
};
List<MessageData> c = new List<MessageData>();
MessageData mc = new MessageData();
mc.header = new header()
{
messageId = "3432423423",
name = "",
@namespace = "",
payloadVersion = "0.1.1"
};
mc.payload = new payload()
{
accessToken = "33434343",
appliance = new Appliance()
{
applianceId = "id",
additionalApplianceDetails = new Device()
{
deviceId = "lightid_0_01",
deviceName = "走廊灯",
deviceType = "LIGHT",
type = "Device"
}
}
};
c.Add(mc);
chuangweidata c12 = new chuangweidata();
c12.data = c;
mmm.nlp_cmd = c12;
var YU = Newtonsoft.Json.JsonConvert.SerializeObject(mmm);
Console.ReadKey();
}
static void timer2_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("111111111111");
}
public static bool SmartRobotDisable()
{
string st = "23:00";
string et = "08:00";
string[] st_a = st.Split(':');
string[] et_a = et.Split(':');
int h_st = int.Parse(st_a[0]);
int M_st = int.Parse(st_a[1]);
int h_et = int.Parse(et_a[0]);
int M_et = int.Parse(et_a[1]);
int y = DateTime.Now.Year;
int m = DateTime.Now.Month;
int d = DateTime.Now.Day;
int hh = DateTime.Now.Hour;
int mm = DateTime.Now.Minute;
int ss = DateTime.Now.Second;
var t1 = new DateTime(y, m, d, h_st, M_st, ss);
var t2 = new DateTime(y, m, d, h_et, M_et, ss);
bool ShiJian = false;
//正常逻辑
if (t2 >= t1)
{
var ti = DateTime.Now;
//如果当前时间大于 起 小于 至,就代表 确实是 禁用
if (ti >= t1 && ti <= t2)
{
ShiJian = true;
}
}
else
{
var ti = DateTime.Now;
var zero_ti = new DateTime(y, m, d, 23, 59, 59);
var zero_ti_0 = new DateTime(y, m, d, 0, 0, 0);
//var t3 = t2.AddDays(1);
//如果当前时间 小于0点
//或者说 当前时间 大于
if ((ti > t1 && ti < zero_ti) || ti >= zero_ti_0 && ti <= t2)
{
ShiJian = true;
}
}
return ShiJian;
}
static void t_Elapsed(object sender, ElapsedEventArgs e)
{
Console.WriteLine("1111111111111");
}
static void t_Elapsed1(object sender, ElapsedEventArgs e)
{
Console.WriteLine("22222222222222");
}
}
public class FFFA : IEquatable<FFFA>
{
public bool Equals(FFFA other)
{
throw new NotImplementedException();
}
}
public class Device
{
public string deviceType { get; set; }
public string type { get; set; }
public string deviceId { get; set; }
public string deviceName { get; set; }
}
public class Appliance
{
public string applianceId { get; set; }
public Device additionalApplianceDetails { get; set; }
}
public class header
{
public string messageId { get; set; }
public string @namespace { get; set; }
public string name { get; set; }
public string payloadVersion { get; set; }
}
public class payload
{
public string accessToken { get; set; }
public Appliance appliance { get; set; }
}
public class MessageData
{
public header header { get; set; }
public payload payload { get; set; }
}
public class chuangweidata
{
public List<MessageData> data { get; set; }
}
public class ChuangWeiCommandData
{
public string nlp_namespace { get; set; }
public string nlp_name { get; set; }
public string query { get; set; }
public chuangweidata nlp_cmd { get; set; }
public PackageData resourcePackage { get; set; }
}
public class PackageData
{
public string skillTitle { get; set; }
public string domain { get; set; }
public int aiState { get; set; }
public string voiceprint { get; set; }
public string skillSource { get; set; }
public string tips { get; set; }
}
}