陈嘉乐
2021-03-31 564c60519d425617fcc482e10100e427ecb7b8d9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
using System;
using HDL_ON.DAL.Server;
using HDL_ON.UI.UI2.PersonalCenter.PirDevice;
using System.Collections.Generic;
using Shared;
 
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 MainView();
                        MainPage.BasePageView.AddChidren(mainView);
                        mainView.Show(listESVideoInfo, listCall, video);
                        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="id"></param>
        public List<CallView> getCall(string id)
        {
            List<CallView> callViewList = new List<CallView>();
            try
            {
                
                List<Call> listCall = new List<Call>();
                var responsePackNew = VideoSend.GetCall(id);
                if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                {
                    var jobject = Newtonsoft.Json.Linq.JObject.Parse(responsePackNew.Data.ToString());
                    string list = jobject["list"].ToString();
                    listCall = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Call>>(list);
 
                }
                List<string> strYear = new List<string>();
                //查询年份
                for (int i = 0; i < listCall.Count; i++)
                {
                    var call = listCall[i];
                    if (string.IsNullOrEmpty(call.callTime))
                    {
                        continue;
                    }
                    var dd = Convert.ToDateTime(call.callTime);
                    var year = dd.ToString("yyyy");
                    if (null == strYear.Find((c) => c == year))
                    {
                        strYear.Add(year);
 
                    }
 
                }
                //重新存储
                for (int j = 0; j < strYear.Count; j++)
                {
                    var year = strYear[j];
                    CallView callView = new CallView();
                    callView.year = year;
                    for (int i = 0; i < listCall.Count; i++)
                    {
                        var call = listCall[i];
                        if (string.IsNullOrEmpty(call.callTime))
                        {
                            continue;
                        }
                        var dd = Convert.ToDateTime(call.callTime);
                        var y = dd.ToString("yyyy");
                        if (y == year)
                        {
                            callView.callList.Add(call);
                        }
 
                    }
                    callViewList.Add(callView);
                }
            }
            catch { }
            return callViewList;
        }
        /// <summary>
        /// 发送命令线程
        /// </summary>
        /// <param name="videoObj">数据对象</param>
        /// <param name="action">回调函数</param>
        /// <param name="str">判断字符</param>
        /// <param name="view">判断log父控件</param>
        /// <param name="frame">log父控件</param>
        /// <param name="dialog">log父控件</param>
        /// <param name="tag">是否要显示log</param>
        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")
            {
                dialog.AddChidren(loading);
            }
            else
            {
                frame.AddChidren(loading);
            }
            if (tag)
            {
                loading.Start();
            }
            ResponsePackNew responsePackNew = null;
            new System.Threading.Thread(() =>
            {
                try
                {
                    if (str == "获取可视对讲")
                    {
                        responsePackNew = VideoSend.GetVideo();
                    }
                    else if (str == "获取通话记录")
                    {
                        responsePackNew = VideoSend.GetCall(videoObj.id);
                    }
 
                }
                catch { }
                finally
                {
                    Application.RunOnMainThread(() =>
                    {
 
                        if (tag)
                        {
                            loading.Hide();
                        }
                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
                        {
                            action(responsePackNew);
                        }
                        else
                        {
                            Method method = new Method();
                            //自定义错误提示文本
                            string eorroText = "";
                            if (str == "获取可视对讲")
                            {
                            }
                            method.ErrorShow(responsePackNew, eorroText);
                        }
 
                    });
                }
 
            })
            { IsBackground = true }.Start();
 
 
        }
        /// <summary>
        /// 随机密码6位
        /// </summary>
        /// <returns></returns>         public static string getCode()         {             Random rand = new Random();             string code = "";             for (int ctr = 0; ctr < 6; ctr++)             {                 code += rand.Next(10).ToString();             }             return code;         }
        /// <summary>         /// 获取当前时间戳         /// </summary>         /// <returns></returns>         public static string GetCurrentTimeStamp()         {             //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(); // 相差秒数
        }
        [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>
            ///记录主键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;
 
           public List<Call> callList = new List<Call>();
 
        }
        [Serializable]
        public class FlVideo
        {
            /// <summary>
            /// 设备名称
            /// </summary>
            public string aliasName = string.Empty;
            /// <summary>
            /// 设备类型:(1室内机,2室外机,3围墙机,4管理机,5二次确认机)
            /// </summary>
            public string devType = string.Empty;
            public string uuid = string.Empty;
        }
 
    }
}