From f9181a9c8125136f597add7c30cb2ff508d54ba7 Mon Sep 17 00:00:00 2001
From: mac <user@users-MacBook-Pro.local>
Date: 星期四, 25 七月 2024 17:34:32 +0800
Subject: [PATCH] 2024年07月25日17:33:40

---
 HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/GroupControl.cs |  169 +++++++++++++++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 160 insertions(+), 9 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/GroupControl.cs b/HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/GroupControl.cs
index 28dea93..6a36845 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/GroupControl.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/GroupControl.cs
@@ -1,22 +1,80 @@
 锘縰sing System;
 using System.Collections.Generic;
+using HDL_ON.Common;
+using HDL_ON.DAL.Server;
+using HDL_ON.DriverLayer;
 using Shared;
 
 namespace HDL_ON.Entity
 {
-    public class GroupControl
+    public class GroupControl : Function
     {
         public GroupControl()
         {
+            spk = "groupControl";
         }
+        /// <summary>
+        /// 缇ゆ帶ID
+        /// </summary>
+        public string userDeviceGroupControlId = string.Empty;
         /// <summary>
         /// 缇ゆ帶sid
         /// </summary>
-        public string sid = string.Empty;
+        //public string sid = string.Empty;
+        /// <summary>
+        /// 鐢熸垚缇ゆ帶sid
+        /// </summary>
+        public string NewGroupControlSid()
+        {
+            string Id = "";
+            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 = Guid.NewGuid().ToString().Substring(0, 8);
+                    //sTimeSpan = "00000000";
+                }
+
+                Id = sOidBeginsWith + sTimeSpan;
+
+                Id += "AA";
+                Id += "AA01";
+                int maxId = 1;
+
+                Random random = new Random(Guid.NewGuid().GetHashCode());
+                maxId = random.Next(10);
+
+                Id += (maxId + 1).ToString("X4");
+                Id += "0000";
+            }
+            catch
+            {
+                return Id;
+            }
+            return Id;
+        }
         /// <summary>
         /// 缇ゆ帶鍚嶇О
         /// </summary>
-        public string name = string.Empty;
+        //public string name = string.Empty;
         /// <summary>
         /// 缇ゆ帶绫诲瀷
         /// </summary>
@@ -24,23 +82,22 @@
         /// <summary>
         /// 鎴块棿uid
         /// </summary>
-        public List<String> uids = new List<string>();
-        public List<String> roomIds = new List<string>();
+        [Newtonsoft.Json.JsonIgnore]
+        public List<string> uids = new List<string>();
+        //public List<String> roomIds = new List<string>();
         /// <summary>
         /// 缇ゆ帶鍔熻兘sid閰嶇疆
         /// </summary>
         public List<GroupControlFunction> sids = new List<GroupControlFunction>();
 
-
-
         /// <summary>
         /// 鑾峰彇璁惧娣诲姞鍒版埧闂寸殑鎴块棿鍚嶇О
         /// </summary>
         /// <returns></returns>
-        public string GetRoomListName()
+        public string GetUidListName()
         {
             string roomNameList = "";
-            foreach (var roomId in roomIds)
+            foreach (var roomId in uids)
             {
                 var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId);
                 if (findRoom == null)
@@ -59,6 +116,77 @@
             }
             return roomNameList;
         }
+
+        /// <summary>
+        /// 缇ゆ帶鎺у埗
+        /// </summary>
+        /// <param name="pairs"></param>
+        public void Control(Dictionary<string,string> pairs)
+        {
+            try
+            {
+               
+                if (DriverLayer.Control.Ins.GatewayOnline_Local)
+                {
+                    var functionControlDataObj = GetGatewayAlinkControlData(pairs);
+                    var functionControlDataJson = Newtonsoft.Json.JsonConvert.SerializeObject(functionControlDataObj);
+                    var sendBytes = DriverLayer.Control.Ins.ConvertSendBodyData(CommunicationTopic.ct.ControlGroupControlTopic, functionControlDataJson);
+                    new Control_Udp().SendLocalHdlLinkData(sendBytes, functionControlDataObj.id, 3);
+                    MainPage.Log($"鏈湴閫氳 鍙戦�丠DL-Link鏁版嵁:{functionControlDataJson}");
+                }
+                else
+                {
+                    
+                    var controlValues = new Dictionary<string, object>();
+                    foreach (var p in pairs)
+                    {
+                        controlValues.Add("key", p.Key);
+                        controlValues.Add("value", p.Value);
+                    }
+                    var pack = ApiUtlis.Ins.HttpRequest.ControlGroupControl(userDeviceGroupControlId, controlValues);
+                    if (pack != null)
+                    {
+                        if (pack.Code == StateCode.SUCCESS)
+                        {
+                            //DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl.
+                        }
+                        else
+                        {
+                            MainPage.Log($"缇ゆ帶鎺у埗澶辫触,Code: {pack.Code}");
+                        }
+                    }
+                }
+            }
+            catch (Exception ex){
+                MainPage.Log($"缇ゆ帶鎺у埗澶辫触: {ex.Message}");
+            }
+        }
+
+
+        public new List<FunctionAttributes> attributes {
+            get
+            {
+                var list = new List<FunctionAttributes>();
+
+                foreach (var temp in sids)
+                {
+                    var light = FunctionList.List.GetLightList().Find((obj) => obj.sid == temp.sid);
+                    if (light != null)
+                    {
+                        foreach(var attr in light.attributes)
+                        {
+                            if(list.Find((obj)=>obj.key == attr.key) == null)
+                            {
+                                list.Add(attr);
+                            }
+                        }
+                    }
+
+                }
+
+                return list;
+            }
+        }
     }
 
     public class GroupControlFunction
@@ -71,6 +199,29 @@
         /// 鍔熻兘spk
         /// </summary>
         public string spk = string.Empty;
+
+
+    }
+
+
+    public class GroupControlType
+    {
+        /// <summary>
+        /// 绫诲瀷
+        /// </summary>
+        public string type = string.Empty;
+        /// <summary>
+        /// 绫诲瀷鍚嶇О
+        /// </summary>
+        public string typeName = string.Empty;
+        /// <summary>
+        /// 缇ゆ帶鏀寔鐨剆pk
+        /// </summary>
+        public List<string> spks = new List<string>();
+        /// <summary>
+        /// 缇ゆ帶鏀寔鐨剆pk灞炴��
+        /// </summary>
+        public List<string> spkAttrs = new List<string>();
     }
 }
 

--
Gitblit v1.8.0