mac
2024-07-25 f9181a9c8125136f597add7c30cb2ff508d54ba7
HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/GroupControl.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using HDL_ON.Common;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using Shared;
namespace HDL_ON.Entity
@@ -10,7 +11,7 @@
    {
        public GroupControl()
        {
            spk = "GroupControl";
            spk = "groupControl";
        }
        /// <summary>
        /// 群控ID
@@ -25,7 +26,7 @@
        /// </summary>
        public string NewGroupControlSid()
        {
            string sceneId = "";
            string Id = "";
            try
            {
                string sOidBeginsWith = "000101";//厂商 + 通讯方式
@@ -52,23 +53,23 @@
                    //sTimeSpan = "00000000";
                }
                sceneId = sOidBeginsWith + sTimeSpan;
                Id = sOidBeginsWith + sTimeSpan;
                sceneId += "AA";
                sceneId += "AA01";
                Id += "AA";
                Id += "AA01";
                int maxId = 1;
                Random random = new Random(Guid.NewGuid().GetHashCode());
                maxId = random.Next(10);
                sceneId += (maxId + 1).ToString("X4");
                sceneId += "0000";
                Id += (maxId + 1).ToString("X4");
                Id += "0000";
            }
            catch
            {
                return sceneId;
                return Id;
            }
            return sceneId;
            return Id;
        }
        /// <summary>
        /// 群控名称
@@ -81,64 +82,78 @@
        /// <summary>
        /// 房间uid
        /// </summary>
        public List<String> uids = 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()
        //{
        //    string roomNameList = "";
        //    foreach (var roomId in roomIds)
        //    {
        //        var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId);
        //        if (findRoom == null)
        //        {
        //            continue;
        //        }
        //        if (roomNameList != "")
        //        {
        //            roomNameList += ",";
        //        }
        //        roomNameList += findRoom.floorName + "-" + findRoom.roomName;
        //    }
        //    if (roomNameList == "")
        //    {
        //        roomNameList = Language.StringByID(StringId.WholeZone);
        //    }
        //    return roomNameList;
        //}
        /// <summary>
        /// 获取设备添加到房间的房间名称
        /// </summary>
        /// <returns></returns>
        public string GetUidListName()
        {
            string roomNameList = "";
            foreach (var roomId in uids)
            {
                var findRoom = SpatialInfo.CurrentSpatial.RoomList.Find(obj => obj.roomId == roomId);
                if (findRoom == null)
                {
                    continue;
                }
                if (roomNameList != "")
                {
                    roomNameList += ",";
                }
                roomNameList += findRoom.floorName + "-" + findRoom.roomName;
            }
            if (roomNameList == "")
            {
                roomNameList = Language.StringByID(StringId.WholeZone);
            }
            return roomNameList;
        }
        /// <summary>
        /// 群控控制
        /// </summary>
        /// <param name="pairs"></param>
        public void Control(Dictionary<string,object> pairs)
        public void Control(Dictionary<string,string> pairs)
        {
            try
            {
                var controlValues = new Dictionary<string, object>();
                foreach(var p in pairs)
                if (DriverLayer.Control.Ins.GatewayOnline_Local)
                {
                    controlValues.Add("key", p.Key);
                    controlValues.Add("value", p.Value);
                    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($"本地通讯 发送HDL-Link数据:{functionControlDataJson}");
                }
                var pack = ApiUtlis.Ins.HttpRequest.ControlGroupControl(userDeviceGroupControlId, controlValues);
                if (pack != null)
                else
                {
                    if (pack.Code == StateCode.SUCCESS)
                    var controlValues = new Dictionary<string, object>();
                    foreach (var p in pairs)
                    {
                        //DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl.
                        controlValues.Add("key", p.Key);
                        controlValues.Add("value", p.Value);
                    }
                    else
                    var pack = ApiUtlis.Ins.HttpRequest.ControlGroupControl(userDeviceGroupControlId, controlValues);
                    if (pack != null)
                    {
                        MainPage.Log($"群控控制失败,Code: {pack.Code}");
                        if (pack.Code == StateCode.SUCCESS)
                        {
                            //DB_ResidenceData.Instance.HomeGateway.isSupportGroupControl.
                        }
                        else
                        {
                            MainPage.Log($"群控控制失败,Code: {pack.Code}");
                        }
                    }
                }
            }
@@ -146,6 +161,32 @@
                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