mac
2024-07-25 f9181a9c8125136f597add7c30cb2ff508d54ba7
HDL_ON/UI/UI2/3-Intelligence/Automation/Send.cs
@@ -23,6 +23,7 @@
            }
        }
        public List<Face> faceList = new List<Face>();
        public List<Face> VideoDoorLockUserListInfo = new List<Face>();
        /// <summary>
        /// 调用获取住宅子账号列表
        /// </summary>
@@ -46,7 +47,7 @@
        /// 获取逻辑ID列表
        /// </summary>
        /// <returns></returns>
        public ResponsePackNew GetLogicIdList(bool isTip = false)
        public List<LogicIdData> GetLogicIdList(bool isTip = false)
        {
            var jObject = new JObject { { "homeId", LogicMethod.Current.HomeId } };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_List, "获取逻辑ID列表");
@@ -60,14 +61,22 @@
            {
                return null;
            }
            return responsePackNew;
            List<LogicIdData> dateList = new List<LogicIdData>();
            try
            {
                dateList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogicIdData>>(responsePackNew.Data.ToString());
            }catch (Exception ex)
            {
                MainPage.Log($"获取逻辑ID列表异常:{ex.Message}");
            }
            return dateList;
        }
        /// <summary>
        /// 获取自动化详情
        /// </summary>
        /// <param name="listIdList">自动化ID列表</param>
        /// <returns></returns>
        public  ResponsePackNew GetLogic(List<string> listIdList, bool isTip = false)
        public  ResponsePackNew GetLogic1(List<string> listIdList, bool isTip = false)
        {
            var jArray = new JArray { };
            for (int i = 0; i < listIdList.Count; i++)
@@ -88,6 +97,35 @@
            }
            return responsePackNew;
        }
        /// <summary>
        /// 获取自动化详情
        /// </summary>
        /// <param name="listIdList">自动化ID列表</param>
        /// <returns></returns>
        public List<Logic> GetLogic(List<string> listIdList, bool isTip = false)
        {
            var jArray = new JArray { };
            for (int i = 0; i < listIdList.Count; i++)
            {
                jArray.Add(listIdList[i]);
            }
            var jObject = new JObject { { "userLogicIds", jArray } };
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Info, "获取自动化详情");
            //如果是token过期则刷新token
            if (responsePackNew.Code == StateCode.TOKEN_EXPIRED)
            {
                RefreshToken();
                GetLogic(listIdList, isTip);
            }
            if (Check(responsePackNew, isTip) == false)
            {
                return null;
            }
            var logicList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Logic>>(responsePackNew.Data.ToString());
            return logicList;
        }
        /// <summary>
        /// 添加自动化命令 
        /// </summary>
@@ -113,6 +151,14 @@
                {
                    var inputTypeJOb = new JObject { };
                    inputTypeJOb.Add("sid", dictionary.sid);
                    if (!string.IsNullOrEmpty(dictionary.hold_time))
                    {
                        inputTypeJOb.Add("hold_time", dictionary.hold_time);
                    }
                    if (!string.IsNullOrEmpty(dictionary.detect_type))
                    {
                        inputTypeJOb.Add("detect_type", dictionary.detect_type);
                    }
                    inputTypeJOb.Add("condition_type", dictionary.condition_type);
                    if (dictionary.condition_type=="9") {
                        inputTypeJOb.Add("identifier", dictionary.identifier);
@@ -197,6 +243,7 @@
                logicIfon.Add("pushConfigs", pushConfigsArray);
                logicjArray.Add(logicIfon);
                 var jObject = new JObject { { "homeId", LogicMethod.Current.HomeId }, { "logics", logicjArray } };
                string str = jObject.ToString();
                responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Add, "添加自动化", 5);
                //如果是token过期则刷新token
                if (responsePackNew.Code == StateCode.TOKEN_EXPIRED)
@@ -239,8 +286,19 @@
                {
                    var inputTypeJOb = new JObject { };
                    inputTypeJOb.Add("sid", dictionary.sid);
                    if (!string.IsNullOrEmpty(dictionary.hold_time))
                    {
                        inputTypeJOb.Add("hold_time", dictionary.hold_time);
                    }
                    if (!string.IsNullOrEmpty(dictionary.detect_type))
                    {
                        inputTypeJOb.Add("detect_type", dictionary.detect_type);
                    }
                    inputTypeJOb.Add("condition_type", dictionary.condition_type);
                    if (dictionary.condition_type == "9")
                    {
                        inputTypeJOb.Add("identifier", dictionary.identifier);
                    }
                    var conditionArray = new JArray { };
                    foreach (var dic in dictionary.condition)
                    {
@@ -327,7 +385,6 @@
                logicjArray.Add(logicIfon);
                var jObject = new JObject { { "homeId", LogicMethod.Current.HomeId }, { "logics", logicjArray } };
                string str = jObject.ToString();
                responsePackNew = RequestServerhomeId(jObject, NewAPI.API_POST_Logic_Update, "编辑更新自动化", 5);
                //如果是token过期则刷新token
@@ -378,7 +435,7 @@
        /// <param name="logic">当前对象</param>
        /// <param name="isTip">是否要提示</param>
        /// <returns></returns>
        public ResponsePackNew SwitchLogic(Logic logic,bool isTip=false)
        public ResponsePackNew EnableLogic(Logic logic,bool isTip=false)
        {
            var jArray = new JArray { };
            var job = new JObject { { "userLogicId", logic.userLogicId }, { "enable", logic.enable } };
@@ -389,14 +446,14 @@
            if (responsePackNew.Code == StateCode.TOKEN_EXPIRED)
            {
                RefreshToken();
                SwitchLogic(logic, isTip);
                EnableLogic(logic, isTip);
            }
            if (Check(responsePackNew, isTip) == false)
            {
                return null;
            }
            return responsePackNew;
        }
        }
        /// <summary> 
        /// 自动化地理围栏状态上报
        /// </summary>
@@ -459,16 +516,75 @@
        }
        /// <summary>
        /// 获取住宅已录入人脸信息
        /// </summary>
        /// <param name="deviceId">可视对讲设备id</param>
        /// <returns></returns>
        public List<Face> GetHomeFaceList(string deviceId, bool isTip)
        {
            var jObject = new JObject();
            jObject.Add("homeId", LogicMethod.Current.HomeId);
            jObject.Add("deviceId", deviceId);
            var responsePackNew = RequestServerhomeId(jObject, NewAPI.Api_Post_GetListHomeFace, "获取住宅已录入人脸信息");
            //如果是token过期则刷新token
            if (responsePackNew.Code == StateCode.TOKEN_EXPIRED)
            {
                RefreshToken();
                GetListHomeFace(deviceId, isTip);
            }
            if (Check(responsePackNew, isTip) == false)
            {
                return new List<Face>();
            }
            var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Face>>(responsePackNew.Data.ToString());
            if (list == null)
            {
                list = new List<Face>();
            }
            faceList.Clear();
            faceList.AddRange(list);
            return list;
        }
        /// <summary>
        ///  获取门锁用户列表(萤石视频门锁)
        /// </summary>
        /// <param name="deviceId">设备</param>
        /// <returns></returns>
        public List<Face> GetVideoDoorLockUserListInfo(Function device)
        {
            var userList = FuntionControlView.VideoDoorLock.VideDoorLockSend.Current.GetVideoDoorLockUserListInfo(device);
            List<Face> faceIdList = new List<Face>();
            for (int i = 0; i < userList.Count; i++)
            {
                Face face = new Face();
                var user = userList[i];
                face.userId = user.extUserId;
                face.userName = user.extUserName;
                faceIdList.Add(face);
            }
            VideoDoorLockUserListInfo.Clear();
            VideoDoorLockUserListInfo.AddRange(faceIdList);
            return faceIdList;
        }
        /// <summary>
        ///请求服务器(与住宅有关:例如;homeId) 
        /// </summary>
        /// <param name="o">发送数据</param>
        /// <param name="api_Url">请求地址(不是绝对地址)</param>
        /// <param name="tag">标记->描述接口(自定义)</param>
        /// <returns></returns>
        public  ResponsePackNew RequestServerhomeId(object o, string api_Url, string tag,int mTimeout = 3)
        public ResponsePackNew RequestServerhomeId(object o, string api_Url, string tag,int mTimeout = 8)
        {
            Log($"{DateTime.Now}->发送->{tag}", o.ToString());
            Log($"{DateTime.Now}->发送->{tag}", api_Url,o.ToString());
            var requestJson = HttpUtil.GetSignRequestJson(o);
            var r= HttpUtil.RequestHttpsPostFroHome(api_Url, requestJson, mTimeout);
            Log($"{DateTime.Now}->回复->{tag}", Newtonsoft.Json.JsonConvert.SerializeObject(r));
            Log($"{DateTime.Now}->回复->{tag}", "", Newtonsoft.Json.JsonConvert.SerializeObject(r));
            return r;
        }
@@ -481,10 +597,10 @@
        /// <returns></returns>
        public  ResponsePackNew RequestServer(object o, string api_Url,string tag)
        {
            Log($"发送->{tag}", o.ToString());
            Log($"发送数据->{tag}", api_Url, o.ToString());
            var requestJson = HttpUtil.GetSignRequestJson(o);
            var r = HttpUtil.RequestHttpsPost(api_Url, requestJson);
            Log($"回复->{tag}", Newtonsoft.Json.JsonConvert.SerializeObject(r));
            Log($"回复数据->{tag}", "", Newtonsoft.Json.JsonConvert.SerializeObject(r));
            return r;
        }
        /// <summary>
@@ -502,29 +618,32 @@
        /// <returns></returns>
        public bool Check(ResponsePackNew r, bool isTip)
        {
            if (r == null)
            {
                r = new ResponsePackNew { message = "没回复,请确认网络是否正常.", Code = "-1", };
            }
            if (r.Code == "0" && r.Data != null && r.Data.ToString() != "")
            {
                return true;
            }
            if (r.Code != "0")
            //失败时是否要提示
            if (isTip)
            {
                //失败时是否要提示
                if (isTip)
                {
                    new LogicView.TipPopView().FlashingBox(r.message + $"({r.Code})");
                }
                new LogicView.TipPopView().FlashingBox(r.message + $"({r.Code})");
            }
            return false;
        }
        /// <summary>
        /// 打印日志
        /// </summary>
        /// <param name="tag">打印标记</param>
        /// <param name="content">打印内容</param>
        public void Log(string tag, string content)
        public void Log(string tag,string url, string content)
        {
         #if DEBUG
            Console.WriteLine(tag + $"\r\n数据内容->->{content}");
            Console.WriteLine(tag + $"\r\n{url}\r\n{content}");
         #endif
        }