xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
HDL_ON/UI/UI2/FuntionControlView/Video/VideoMethod.cs
@@ -3,78 +3,93 @@
using HDL_ON.UI.UI2.PersonalCenter.PirDevice;
using System.Collections.Generic;
using Shared;
using HDL_ON.Entity;
using Newtonsoft.Json;
namespace HDL_ON.UI.UI2.FuntionControlView.Video
{
    public class VideoMethod
    {
        ///// <summary>
        ///// 程序主入口
        ///// </summary>
        ///// <param name="frameLayout">log父控件</param>
        ///// <param name="video">可视对讲对象</param>
        //public void MianView(FrameLayout frameLayout, VideoClouds video)
        //{
        //    //加载log
        //    Loading loading = new Loading();
        //    frameLayout.AddChidren(loading);
        //    loading.Start();
        //    List<VideoMethod.FlVideo> listESVideoInfo = new List<VideoMethod.FlVideo>();
        //    List<CallView> listCall = new List<CallView>();
        //    new System.Threading.Thread(() =>
        //    {
        //        try
        //        {
        //            listESVideoInfo = VideoSend.GetVideoInfoList(video);
        //            listCall = getCall(video.id);
        //        }
        //        catch
        //        {
        //        }
        //        finally
        //        {
        //            Application.RunOnMainThread(() =>
        //            {
        //                loading.Hide();
        //                var mainView = new HDL_ON.UI.UI2.FuntionControlView.Video.MainView();
        //                MainPage.BasePageView.AddChidren(mainView);
        //                mainView.Show();
        //                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
        //            });
        //        }
        //    })
        //    { IsBackground = true }.Start();
        //}
        ///// <summary>
        ///// 获取可视对讲
        ///// </summary>
        ///// <param name="action">回调函数</param>
        ///// <param name="frame">log父控件</param>
        //public void getVideo(Action<VideoClouds> action, FrameLayout frame, bool tag)
        //{
        //    ThreadSend(null, (responsePackNew) =>
        //     {
        //         try
        //         {
        //             var str = responsePackNew.Data.ToString();
        //             var videoObj = Newtonsoft.Json.JsonConvert.DeserializeObject<VideoClouds>(str);
        //             action(videoObj);
        //         }
        //         catch { }
        //     }, "获取可视对讲", "fram", frame, null, tag);
        //}
        /// <summary>
        /// 程序主入口
        /// </summary>
        /// <param name="frameLayout">log父控件</param>
        /// <param name="video">可视对讲对象</param>
        public void MianView(FrameLayout frameLayout)
        {
            //加载log
            Loading loading = new Loading();
            frameLayout.AddChidren(loading);
            loading.Start();
            List<CallView> listCall = new List<CallView>();
            new System.Threading.Thread(() =>
            {
                try
                {
                    // 这里再获取一次设备列表(更新数据)
                    var videoInfo = VideoSend.GetVideoInfoList();
                    if (videoInfo.Code == StateCode.SUCCESS)
                    {
                        string data_str = videoInfo.Data.ToString();
                        FunctionList.List.videoIntercom = JsonConvert.DeserializeObject<List<UI.UI2.FuntionControlView.Video.Video>>(data_str);
                    }
                    // 获取通话记录
                    listCall = GetCall();
                }
                catch
                {
                    //
                }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
                        loading.Hide();
                        var mainView = new VideoMainView();
                        MainPage.BasePageView.AddChidren(mainView);
                        mainView.Show(listCall, FunctionList.List.videoIntercom);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    });
                }
            })
            { IsBackground = true }.Start();
        }
        /// <summary>
        /// 获取可视对讲
        /// </summary>
        /// <param name="action">回调函数</param>
        /// <param name="frame">log父控件</param>
        /// <param name="tag">是否要显示log(默认显示tag=true)</param>
        public void GetVideo(Action<VideoClouds> action, FrameLayout frame, bool tag)
        {
            VideoClouds videoObj =null;
            ThreadSend(null, (responsePackNew) =>
             {
                 try
                 {
                     var str = responsePackNew.Data.ToString();
                     videoObj = Newtonsoft.Json.JsonConvert.DeserializeObject<VideoClouds>(str);
                     action(videoObj);
                 }
                 catch {
                     action(videoObj);
                 }
             }, "获取可视对讲", "fram", frame, null, tag);
        }
        /// <summary>
        /// 获取历史通话记录
        /// </summary>
        /// <param name="id"></param>
        public List<CallView> getCall(string id)
        public List<CallView> GetCall()
        {
            List<CallView> callViewList = new List<CallView>();
            try
            {
                List<Call> listCall = new List<Call>();
                var responsePackNew = VideoSend.GetCall(id);
                var responsePackNew = VideoSend.GetCall();
                if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                {
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(responsePackNew.Data.ToString());
@@ -126,7 +141,8 @@
            }
            catch { }
            return callViewList;
        }
        }
        /// <summary>
        /// 发送命令线程
        /// </summary>
@@ -137,9 +153,8 @@
        /// <param name="frame">log父控件</param>
        /// <param name="dialog">log父控件</param>
        /// <param name="tag">是否要显示log</param>
        public void ThreadSend(VideoClouds videoObj, Action<ResponsePackNew> action, string str, string view, FrameLayout frame, Dialog dialog, bool tag = true)
        public static void ThreadSend(VideoClouds videoObj, Action<ResponsePackNew> action, string str, string view, FrameLayout frame, Dialog dialog, bool tag = true)
        {
            //加载log
            Loading loading = new Loading();
            if (view == "dialog")
@@ -161,11 +176,12 @@
                {
                    if (str == "获取可视对讲")
                    {
                        responsePackNew = VideoSend.GetVideo();
                        // responsePackNew = VideoSend.GetVideo();
                        responsePackNew = VideoSend.GetVideoInfoList();
                    }
                    else if (str == "获取通话记录")
                    {
                        responsePackNew = VideoSend.GetCall(videoObj.id);
                        responsePackNew = VideoSend.GetCall();
                    }
                }
@@ -185,7 +201,7 @@
                        }
                        else
                        {
                            Method method = new Method();
                            PirMethod method = new PirMethod();
                            //自定义错误提示文本
                            string eorroText = "";
                            if (str == "获取可视对讲")
@@ -202,113 +218,48 @@
        }
        [Serializable]
        public class VideoClouds
        {
            /// <summary>
            /// 丰林绑定id(flBindId)(userKey)
            /// </summary>
            public string id = string.Empty;
            /// <summary>
            /// 住宅id
            /// </summary>
            public string homeId = string.Empty;
            /// <summary>
            /// 虚拟手机号
            /// </summary>
            public string phone = string.Empty;
            /// <summary>
            /// 虚拟身份证号码
            /// </summary>
            public string idCard = string.Empty;
            /// <summary>
            /// 社区主键Id
            /// </summary>
            public string communtiyId = string.Empty;
            /// <summary>
            /// 丰林楼栋号
            /// </summary>
            public string flBuildingId = string.Empty;
            /// <summary>
            /// 丰林楼栋名称
            /// </summary>
            public string flBuildingName = string.Empty;
            /// <summary>
            /// 丰林房间名称
            /// </summary>
            public string flRoomId = string.Empty;
            /// <summary>
            /// 丰林安全密钥
            /// </summary>
            public string flSecretKey = string.Empty;
            /// <summary>
            /// 丰林的小区Id
            /// </summary>
            public string flCmtId = string.Empty;
        }
        [Serializable]
        public class Call
        /// <summary>
        /// 随机密码6位
        /// </summary>
        /// <returns></returns>
        public static string GetCode()
        {
            /// <summary>
            ///记录主键Id
            /// </summary>
            public string id = string.Empty;
            /// <summary>
            /// 住宅id
            /// </summary>
            public string homeId = string.Empty;
            /// <summary>
            /// 呼叫时间
            /// </summary>
            public string callTime = string.Empty;
            /// <summary>
            /// 通话时长
            /// </summary>
            public string callDuration = string.Empty;
            /// <summary>
            /// 呼叫状态(0:未接;1:已接;2:拒接)
            /// </summary>
            public string callStatus = string.Empty;
            /// <summary>
            /// 是否开锁
            /// </summary>
            public bool isUnlock;
            /// <summary>
            /// 截图地址
            /// </summary>
            public string screenshotUrl = string.Empty;
            /// <summary>
            ///丰林绑定主键id(门口机主键Id)
            /// </summary>
            public string flBindId = string.Empty;
        }
        [Serializable]
        public class CallView
        {
            /// <summary>
            ///年
            /// </summary>
            public string year = string.Empty;
            Random rand = new Random();
            string code = "";
            for (int ctr = 0; ctr < 6; ctr++)
            {
                code += rand.Next(10).ToString();
            }
            return code;
        }
           public List<Call> callList = new List<Call>();
        }
        [Serializable]
        public class FlVideo
        /// <summary>
        /// 获取当前时间戳
        /// </summary>
        /// <returns></returns>
        public static string GetCurrentTimeStamp()
        {
            /// <summary>
            /// 设备名称
            /// </summary>
            public string aliasName = string.Empty;
            /// <summary>
            /// 设备类型:(1室内机,2室外机,3围墙机,4管理机,5二次确认机)
            /// </summary>
            public string devType = string.Empty;
            public string uuid = string.Empty;
            //TimeSpan ts = DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            //return Convert.ToInt64(ts.TotalSeconds).ToString();
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            return ((long)(DateTime.Now - startTime).TotalSeconds).ToString(); // 相差秒数
        }
        /// <summary>
        /// 获取当前时间戳
        /// </summary>
        /// <returns></returns>
        public static string GetTomorrowTimeStamp()
        {
            //当前时间的后一天
            //TimeSpan ts = DateTime.Now.AddDays(1) - new DateTime(1970, 1, 1, 0, 0, 0, 0);
            //return Convert.ToInt64(ts.TotalSeconds).ToString();
            System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 当地时区
            return ((long)(DateTime.Now.AddDays(1) - startTime).TotalSeconds).ToString(); // 相差秒数
        }
    }