黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
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
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using ZigBee.Device;
 
namespace Shared.Phone.UserCenter.UserMain
{
    /// <summary>
    /// 消息中心
    /// </summary>
    public class MessageManagementForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalFrameRefreshControl listView = null;
        /// <summary>
        /// 全部的行,主键是自动递增的东西
        /// </summary>
        private Dictionary<string, RowLayoutControl> dicAllRow = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //左滑使能
            this.ScrollEnabled = false;
 
            Common.CommonPage.Instance.IsDrawerLockMode = true;
 
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uMessageCenter));
 
            //初始化右上角菜单
            this.InitTopRightMenu();
 
            listView = new VerticalFrameRefreshControl(35);
            listView.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listView);
            listView.BeginHeaderRefreshingAction += () =>
            {
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //初始化中部信息
                    this.InitMiddleData(false);
                });
            };
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //打开进度条
                this.ShowProgressBar();
 
                //初始化中部信息
                this.InitMiddleData(true);
            });
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleData(bool showReload)
        {
            //获取数据
            var dicData = this.GetMessageData();
            if (dicData == null)
            {
                if (showReload == true)
                {
                    //关闭进度条
                    this.CloseProgressBar(ShowReLoadMode.YES);
                }
                else
                {
                    //关闭进度条
                    this.CloseProgressBar();
                }
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //关闭刷新特效
                    listView?.EndHeaderRefreshing();
                    //清空
                    listView.RemoveAll();
                });
                //数据异常
                return;
            }
            if (this.Parent == null)
            {
                return;
            }
 
            HdlThreadLogic.Current.RunMain(() =>
            {
                //清空
                listView.RemoveAll();
            });
            if (dicData.Count == 0)
            {
                //关闭进度条
                this.CloseProgressBar();
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //关闭刷新特效
                    listView.EndHeaderRefreshing();
                    listView.frameTable.Height = listView.Height;
                });
                return;
            }
            //初始化中部控件
            this.InitMiddleFrame(dicData);
        }
 
        /// <summary>
        /// 初始化中部控件(要使用线程调用)
        /// </summary>
        /// <param name="dicData"></param>
        private void InitMiddleFrame(Dictionary<string, List<List<MessageRecordInfo>>> dicData)
        {
            int dateIndex = 0;
            FrameListControl framBack = null;
            string oldKeys = string.Empty;
 
            int maxCount = 0;
            int countIndex = 0;
            foreach (var data in dicData.Values)
            {
                //获取循环的总次数
                maxCount += data.Count;
            }
 
            int waiTime = 500;
            foreach (var keys in dicData.Keys)
            {
                var listGroup = dicData[keys];
                foreach (var listData in listGroup)
                {
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        countIndex++;
                        //当日期不一样时,重新建立桌布
                        if (oldKeys != keys)
                        {
                            oldKeys = keys;
                            dateIndex++;
                            //容器
                            framBack = new FrameListControl(23);
                            framBack.Name = dateIndex.ToString();
                            framBack.Height = Application.GetRealHeight(100);
                            framBack.BackgroundColor = UserCenterColor.Current.White;
                            listView.AddChidren(framBack);
 
                            //日期
                            string strMonth = Language.StringByID(R.MyInternationalizationString.Month);
                            string strDate = Language.StringByID(R.MyInternationalizationString.Day);
                            var frameDate = new FrameLayout();
                            frameDate.Height = Application.GetRealHeight(118);
                            framBack.AddChidren(frameDate);
                            var btnDate = new NormalViewControl(500, 60, true);
                            btnDate.TextSize = 15;
                            btnDate.X = HdlControlResourse.XXLeft;
                            btnDate.Y = Application.GetRealHeight(35);
                            btnDate.Text = HdlCommonLogic.Current.ConvertUtcTimeToLocalTime2(listGroup[0][0].CreateTime).ToString("MM" + strMonth + "dd" + strDate);
                            frameDate.AddChidren(btnDate);
                        }
 
                        for (int i = 0; i < listData.Count; i++)
                        {
                            //一条信息里面,它可能包含多个报警
                            for (int j = 0; j < listData[i].listMsg.Count; j++)
                            {
                                //设置已读的初始值
                                listData[i].ListReading.Add(listData[i].IsRead);
                                //添加信息行
                                bool addLine = i != listData.Count - 1 || j != listData[i].listMsg.Count - 1;
                                this.AddMsgRowControl(framBack, listData[i], j, addLine);
                            }
                        }
                        //调整高度
                        listView.AdjustChidrenFrameHeight(framBack, Application.GetRealHeight(23));
                        if (countIndex == maxCount)
                        {
                            //调整桌布
                            listView.AdjustTableHeight();
                            //关闭刷新特效
                            listView.EndHeaderRefreshing();
                            //关闭进度条
                            this.CloseProgressBar();
                        }
                    });
                    //第一次的时候,等待的时候久一点
                    System.Threading.Thread.Sleep(waiTime);
                    waiTime = 300;
                }
            }
        }
 
        #endregion
 
        #region ■ 右上角菜单_________________________
 
        /// <summary>
        /// 初始化右上角菜单
        /// </summary>
        private void InitTopRightMenu()
        {
            var btnIcon = new MostRightIconControl(69, 69);
            btnIcon.UnSelectedImagePath = "Item/More.png";
            topFrameLayout.AddChidren(btnIcon);
            btnIcon.InitControl();
            btnIcon.ButtonClickEvent += ((sender, e) =>
            {
                //显示底部菜单界面
                this.ShowBottomMenu();
            });
        }
 
        /// <summary>
        /// 显示底部菜单界面
        /// </summary>
        private void ShowBottomMenu()
        {
            bool authority = HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1 || HdlUserCenterResourse.ResidenceOption.AuthorityNo == 2;
 
            var menuContr = new BottomMenuSelectForm();
            menuContr.AddForm(authority == true ? 2 : 1);
            //全部已读
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllRead), () =>
            {
                //设置全部为已读
                this.SetAllTickIsRead();
            });
            if (authority == true)
            {
                //全部删除
                menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.uAllDelete), () =>
                {
                    //删除全部的消息
                    this.DeleteAllMsg();
                });
            }
        }
 
        #endregion
 
        #region ■ 添加信息行_________________________
 
        /// <summary>
        /// 添加信息行
        /// </summary>
        /// <param name="frameList"></param>
        /// <param name="recordInfo"></param>
        /// <param name="msgIndex">报警消息的下标</param>
        /// <param name="addLine"></param>
        private void AddMsgRowControl(FrameListControl frameList, MessageRecordInfo recordInfo, int msgIndex, bool addLine)
        {
            var rowControl = new RowLayoutControl(frameList.rowSpace / 2);
            frameList.AddChidren(rowControl);
            rowControl.Name = frameList.ChildrenCount.ToString();
            rowControl.MainKeys = recordInfo.Id;
            this.dicAllRow[frameList.Name + "-" + rowControl.Name] = rowControl;
 
            //图标
            var btnIcon = rowControl.frameTable.AddLeftIcon(81);
            btnIcon.UnSelectedImagePath = recordInfo.IconPath;
            //消息类型
            var btnMsgObject = rowControl.frameTable.AddLeftCaption(recordInfo.MsgObjectText, 600);
 
            //消息
            var btnMsg = rowControl.frameTable.AddMostRightView(recordInfo.listMsg[msgIndex], 600, 60);
            btnMsg.TextColor = UserCenterColor.Current.TextGrayColor3;
            btnMsg.Y = Application.GetRealHeight(5) + rowControl.frameTable.chidrenYaxis;
            rowControl.frameTable.AddChidren(btnMsg, ChidrenBindMode.BindEvent);
            //时间
            var btnTime = rowControl.frameTable.AddMostRightView("", 200, 50);
            btnTime.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnTime.Y = btnMsg.Bottom + Application.GetRealHeight(12);
            var convertTime = HdlCommonLogic.Current.ConvertUtcTimeToLocalTime2(recordInfo.CreateTime);
            btnTime.Text = convertTime.ToString("HH:mm");
            rowControl.frameTable.AddChidren(btnTime, ChidrenBindMode.BindEvent);
            //底线
            if (addLine == true)
            {
                rowControl.frameTable.AddBottomLine();
            }
            //已读
            if (recordInfo.ListReading[msgIndex] == true)
            {
                rowControl.frameTable.UseClickStatu = false;
                //消息类型
                btnMsgObject.TextColor = UserCenterColor.Current.TextGrayColor1;
                //消息
                btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
            }
            //调整宽度
            btnMsgObject.Width = btnMsgObject.GetRealWidthByText();
 
            //新消息
            PicViewControl btnNewTip = null;
            if (recordInfo.ListReading[msgIndex] == false)
            {
                btnNewTip = new PicViewControl(78, 55);
                btnNewTip.UnSelectedImagePath = "Item/NewVersion.png";
                btnNewTip.Y = Application.GetRealHeight(9) + rowControl.frameTable.chidrenYaxis;
                btnNewTip.X = btnMsgObject.Right + Application.GetRealWidth(10);
                rowControl.frameTable.AddChidren(btnNewTip, ChidrenBindMode.BindEvent);
            }
 
            //主要主人和管理员能够删除
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1 || HdlUserCenterResourse.ResidenceOption.AuthorityNo == 2)
            {
                //删除
                var btnDelete = rowControl.AddDeleteControl();
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //确认删除消息?
                    string msg = Language.StringByID(R.MyInternationalizationString.uDeleteMessageMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        this.DeleteMsg(recordInfo.Id, frameList, rowControl);
                    });
                };
            }
 
            //点击
            rowControl.frameTable.ButtonClickEvent += (sender, e) =>
            {
                if (recordInfo.ListReading[msgIndex] == true)
                {
                    return;
                }
                recordInfo.ListReading[msgIndex] = true;
                rowControl.frameTable.UseClickStatu = false;
                //消息类型
                btnMsgObject.TextColor = UserCenterColor.Current.TextGrayColor1;
                //消息
                btnMsg.TextColor = UserCenterColor.Current.TextGrayColor1;
                btnNewTip.RemoveFromParent();
                if (sender != null)
                {
                    //标记已读(不管它成功不成功)
                    this.SetTickIsRead(recordInfo.Id);
                }
            };
        }
 
        #endregion
 
        #region ■ 标记已读___________________________
 
        /// <summary>
        /// 标记已读
        /// </summary>
        /// <param name="strId"></param>
        private bool SetTickIsRead(string strId)
        {
            return HdlMessageLogic.Current.SetTickIsRead(strId);
        }
 
        /// <summary>
        /// 设置全部为已读
        /// </summary>
        private void SetAllTickIsRead()
        {
            if (dicAllRow.Count == 0)
            {
                return;
            }
            //确认标记全部消息为已读?
            this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uUnTipAllMessageMsg), () =>
            {
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //打开进度条
                    this.ShowProgressBar();
 
                    var result = HdlMessageLogic.Current.SetAllTickIsRead();
 
                    //关闭进度条
                    this.CloseProgressBar();
                    if (result == false)
                    {
                        return;
                    }
 
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //设置全部状态
                        foreach (var contr in this.dicAllRow.Values)
                        {
                            contr.frameTable.ButtonClickEvent?.Invoke(null, null);
                        }
                    });
                });
            });
        }
 
        #endregion
 
        #region ■ 删除信息___________________________
 
        /// <summary>
        /// 删除信息
        /// </summary>
        /// <param name="strId"></param>
        /// <param name="frameList"></param>
        /// <param name="rowContr"></param>
        private bool DeleteMsg(string strId, FrameListControl frameList, RowLayoutControl rowContr)
        {
            var result = HdlMessageLogic.Current.DeleteCloundMessage(strId);
            if (result == false)
            {
                return false;
            }
 
            //云端是不会返回东西的
            if (frameList != null)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //移除缓存
                    this.dicAllRow.Remove(frameList.Name + "-" + rowContr.Name);
                    //调整控件位置
                    this.AdjustControlLocation(frameList, rowContr);
                });
            }
            return true;
        }
 
        /// <summary>
        /// 删除全部的消息
        /// </summary>
        private void DeleteAllMsg()
        {
            if (dicAllRow.Count == 0)
            {
                return;
            }
            //确认删除全部消息?
            this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteAllMessageMsg), () =>
            {
                HdlThreadLogic.Current.RunThread(() =>
                {
                    //打开进度条
                    this.ShowProgressBar();
 
                    var result = HdlMessageLogic.Current.DeleteAllCloundMessage();
                    if (result == false)
                    {
                        //关闭进度条
                        this.CloseProgressBar();
                        return;
                    }
                    //初始化中部信息
                    this.InitMiddleData(true);
                });
            });
        }
 
        #endregion
 
        #region ■ 调整控件位置_______________________
 
        /// <summary>
        /// 调整控件位置
        /// </summary>
        /// <param name="frameList"></param>
        private void AdjustControlLocation(FrameListControl frameList, RowLayoutControl removeRow)
        {
            int changedHeight = frameList.GetChildren(frameList.ChildrenCount - 1).Height;
            if (frameList.ChildrenCount <= 2)
            {
                //已经删完了,只剩下标题日期了
                changedHeight = frameList.Height;
            }
            //先调整各自容器的Y轴坐标
            bool canChangedLoaction = false;
            for (int i = 0; i < this.listView.frameTable.ChildrenCount; i++)
            {
                var myView = this.listView.frameTable.GetChildren(i);
                if (myView.Name == frameList.Name)
                {
                    //它之后的控件全部往上移动
                    canChangedLoaction = true;
                    continue;
                }
                if (canChangedLoaction == true)
                {
                    myView.Y -= changedHeight;
                }
            }
            //调整父容器大小
            this.listView.AdjustTableHeight();
 
 
            if (frameList.ChildrenCount <= 2)
            {
                //已经删完了,只剩下标题日期了
                frameList.RemoveFromParent();
            }
            else
            {
                //这个容器里面被移除的行的下面的全部行,往上移动
                bool changedFlage = false;
                for (int i = 0; i < frameList.ChildrenCount; i++)
                {
                    var myView = frameList.GetChildren(i);
                    if (myView.Name == removeRow.Name)
                    {
                        //它之后的控件全部往上移动
                        changedFlage = true;
                        continue;
                    }
                    if (changedFlage == true)
                    {
                        myView.Y -= changedHeight;
                    }
                }
                //移除指定的行
                removeRow.RemoveFromParent();
                //容器大小减少
                frameList.Height -= changedHeight;
            }
        }
 
        #endregion
 
        #region ■ 获取数据___________________________
 
        /// <summary>
        /// 获取消息记录
        /// </summary>
        /// <returns></returns>
        private Dictionary<string, List<List<MessageRecordInfo>>> GetMessageData()
        {
            this.dicAllRow = new Dictionary<string, RowLayoutControl>();
 
            var listData = new List<MessageRecordInfo>();
            var listMsg = HdlMessageLogic.Current.GetListMessageFromDb();
            if (listMsg == null)
            {
                return new Dictionary<string, List<List<MessageRecordInfo>>>();
            }
 
            for (int i = 0; i < listMsg.Count; i++)
            {
                try
                {
                    var data = listMsg[i];
                    //处理消息类型
                    if (this.AdjustMsgContent(ref data) == true)
                    {
                        listData.Add(data);
                    }
                }
                catch { continue; }
            }
 
            //合并数据
            return this.MergeMessageRecordData(listData);
        }
 
        /// <summary>
        /// 合并数据(同一天之内,会分组)
        /// </summary>
        /// <param name="dataInfo"></param>
        /// <returns></returns>
        private Dictionary<string, List<List<MessageRecordInfo>>> MergeMessageRecordData(List<MessageRecordInfo> dataInfo)
        {
            var dicData = new Dictionary<string, List<List<MessageRecordInfo>>>();
 
            //首先先排序一下,时间大的放在前面
            var dicTemp = new Dictionary<string, List<MessageRecordInfo>>();
            var listSortKeys = new List<string>();
            foreach (var data in dataInfo)
            {
                if (dicTemp.ContainsKey(data.CreateTime) == false)
                {
                    dicTemp[data.CreateTime] = new List<MessageRecordInfo>();
                    listSortKeys.Add(data.CreateTime);
                }
                dicTemp[data.CreateTime].Add(data);
            }
            listSortKeys.Sort();
 
            var listGroup = new List<MessageRecordInfo>();
            for (int i = listSortKeys.Count - 1; i >= 0; i--)
            {
                var listData = dicTemp[listSortKeys[i]];
                foreach (var data2 in listData)
                {
                    try
                    {
                        if (data2.MessageTitle == "/DoorLock/DoorLockOperatingEventNotificationCommand")
                        {
                            //暂时不处理这个主题
                            continue;
                        }
                        string strDay = HdlCommonLogic.Current.ConvertUtcTimeToLocalTime2(data2.CreateTime).ToString("yyyy/MM/dd");
                        //按每天分组
                        if (dicData.ContainsKey(strDay) == false)
                        {
                            listGroup = new List<MessageRecordInfo>();
                            dicData[strDay] = new List<List<MessageRecordInfo>>();
                            dicData[strDay].Add(listGroup);
                        }
                        if (listGroup.Count > 20)
                        {
                            //每20个一组
                            listGroup = new List<MessageRecordInfo>();
                            dicData[strDay].Add(listGroup);
                        }
                        listGroup.Add(data2);
                    }
                    catch { }
                }
            }
            return dicData;
        }
 
        #endregion
 
        #region ■ 处理消息类型_______________________
 
        /// <summary>
        /// 处理消息类型
        /// </summary>
        /// <param name="recordInfo">消息数据</param>
        private bool AdjustMsgContent(ref MessageRecordInfo recordInfo)
        {
            //传感器上报
            if (recordInfo.MessageTitle == "/IASInfoReport")
            {
                var jobject = JObject.Parse(recordInfo.MessageExpand);
                this.SensorDeviceReportPush(jobject, ref recordInfo);
            }
            //门锁上报
            else if (recordInfo.MessageTitle == "/Alarms/SendAlarmInform")
            {
                var jobject = JObject.Parse(recordInfo.MessageExpand);
                this.DoorLockDeviceReportPush(jobject, ref recordInfo);
            }
            //撤防
            else if (recordInfo.MessageTitle == "/Security/WithdrawMode_Respon")
            {
                var jobject = JObject.Parse(recordInfo.MessageExpand);
                this.RemoveSafetyGarrisonPush(jobject, ref recordInfo);
            }
            //布防
            else if (recordInfo.MessageTitle == "/Security/EnableMode_Respon")
            {
                var jobject = JObject.Parse(recordInfo.MessageExpand);
                this.SetSafetyGarrisonPush(jobject, ref recordInfo);
            }
            //逻辑触发上报
            else if (recordInfo.MessageTitle == "/Logic/Execute_Respon")
            {
                var jobject = JObject.Parse(recordInfo.MessageExpand);
                this.LogicExecutePush(jobject, ref recordInfo);
            }
            //场景触发上报
            else if (recordInfo.MessageTitle == "/Scene/Exec_Respon")
            {
                var jobject = JObject.Parse(recordInfo.MessageExpand);
                this.SceneExecPush(jobject, ref recordInfo);
            }
            else
            {
                //不处理的主题
                return false;
            }
            return true;
        }
 
        #endregion
 
        #region ■ 传感器上报_________________________
 
        /// <summary>
        /// 传感器设备上报
        /// </summary>
        /// <param name="receiveData"></param>
        private bool SensorDeviceReportPush(JObject receiveData, ref MessageRecordInfo recordInfo)
        {
            var ias = new IASZone() { DeviceAddr = receiveData.Value<string>("DeviceAddr"), DeviceEpoint = receiveData.Value<int>("Epoint") };
            ias.iASInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<IASZone.IASInfoData>(receiveData["Data"].ToString());
            //图标
            var localDevice = HdlDeviceCommonLogic.Current.GetDevice(ias.DeviceAddr, ias.DeviceEpoint);
            if (localDevice == null)
            {
                recordInfo.IconPath = "Device/Sensor.png";
                //消息类型:传感器
                var infoContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo("A402");
                recordInfo.MsgObjectText = infoContent != null ? infoContent.A官方名字 : string.Empty;
            }
            else
            {
                string selectPath = string.Empty;
                string unselecPath = string.Empty;
                HdlDeviceCommonLogic.Current.GetDeviceIcon(localDevice, ref unselecPath, ref selectPath);
                recordInfo.IconPath = unselecPath;
                //消息类型
                recordInfo.MsgObjectText = HdlDeviceCommonLogic.Current.GetDeviceEpointName(localDevice);
            }
 
            //消息
            var info = HdlAlarmsLogic.Current.GetSensorAlarmInfo(ias);
            if (info == null)
            {
                //非在册的消息记录
                recordInfo.listMsg.Add(Language.StringByID(R.MyInternationalizationString.uSensorAlarmHadTriggered));
                return true;
            }
 
            if (string.IsNullOrEmpty(info.AlarmMsg) == false)
            {
                recordInfo.listMsg.Add(info.AlarmMsg);
            }
            if (info.BatteryMsg != null)
            {
                recordInfo.listMsg.Add(info.BatteryMsg);
            }
            if (info.DemolishmenMsg != null)
            {
                recordInfo.listMsg.Add(info.DemolishmenMsg);
            }
 
            //触发传感器报警
            if (recordInfo.listMsg.Count == 0)
            {
                recordInfo.listMsg.Add(Language.StringByID(R.MyInternationalizationString.uSensorAlarmHadTriggered));
            }
            return true;
        }
 
        #endregion
 
        #region ■ 门锁上报___________________________
 
        /// <summary>
        /// 门锁上报
        /// </summary>
        /// <param name="receiveData"></param>
        private void DoorLockDeviceReportPush(JObject receiveData, ref MessageRecordInfo recordInfo)
        {
            //图标
            var device = HdlDeviceCommonLogic.Current.GetDevice(receiveData.Value<string>("DeviceAddr"), receiveData.Value<int>("Epoint"));
            if (device == null)
            {
                recordInfo.IconPath = "Device/IntelligentLocks.png";
                //消息类型:智能门锁
                var infoContent = HdlDeviceCommonLogic.Current.GetDeviceModelIdNameInfo("A405");
                recordInfo.MsgObjectText = infoContent != null ? infoContent.A官方名字 : string.Empty;
            }
            else
            {
                string selectPath = string.Empty;
                string unselecPath = string.Empty;
                HdlDeviceCommonLogic.Current.GetDeviceIcon(device, ref unselecPath, ref selectPath);
                recordInfo.IconPath = unselecPath;
                //消息类型
                recordInfo.MsgObjectText = HdlDeviceCommonLogic.Current.GetDeviceEpointName(device);
            }
            //消息
            var msgInfo = HdlAlarmsLogic.Current.GetDoorLockAlarmInfo(receiveData);
            string MsgText = msgInfo != null ? msgInfo.AlarmMsg : Language.StringByID(R.MyInternationalizationString.uDoorLocksAlarmHadTriggered);
            recordInfo.listMsg.Add(MsgText);
        }
 
        #endregion
 
        #region ■ 布防_______________________________
 
        /// <summary>
        /// 布防推送
        /// </summary>
        /// <param name="receiveData"></param>
        private void SetSafetyGarrisonPush(JObject receiveData, ref MessageRecordInfo recordInfo)
        {
            //图标
            recordInfo.IconPath = "Item/Safety.png";
 
            var data = Newtonsoft.Json.JsonConvert.DeserializeObject<Safeguard.EnableModeResponseData>(receiveData["Data"].ToString());
            if (data.Result == 0)
            {
                //离家布防
                if (data.ModeId == 2)
                {
                    //离家布防
                    recordInfo.MsgObjectText = Language.StringByID(R.MyInternationalizationString.uRemoveHomeGarrison);
                    //已执行
                    recordInfo.listMsg.Add(Language.StringByID(R.MyInternationalizationString.uExecuted));
                }
                else
                {
                    //已执行
                    recordInfo.listMsg.Add(Language.StringByID(R.MyInternationalizationString.uExecuted));
                    //没有内部防区
                    if (HdlSafeguardLogic.Current.IsHadInternalDefenseArea() == false)
                    {
                        //布防
                        recordInfo.MsgObjectText = Language.StringByID(R.MyInternationalizationString.uGarrison);
                    }
                    else
                    {
                        //在家布防
                        recordInfo.MsgObjectText = Language.StringByID(R.MyInternationalizationString.uAtHomeGarrison);
                    }
                }
            }
            else
            {
                //布防设置失败
                recordInfo.MsgObjectText = Language.StringByID(R.MyInternationalizationString.uSetGarrisonFail);
            }
        }
 
        #endregion
 
        #region ■ 撤防_______________________________
 
        /// <summary>
        /// 撤防推送
        /// </summary>
        /// <param name="receiveData"></param>
        private void RemoveSafetyGarrisonPush(JObject receiveData, ref MessageRecordInfo recordInfo)
        {
            //图标
            recordInfo.IconPath = "Item/Safety.png";
 
            var data = Newtonsoft.Json.JsonConvert.DeserializeObject<Safeguard.WithdrawModeResponseData>(receiveData["Data"].ToString());
            if (data.Result == 0)
            {
                //已执行
                recordInfo.listMsg.Add(Language.StringByID(R.MyInternationalizationString.uExecuted));
                //撤防
                recordInfo.MsgObjectText = Language.StringByID(R.MyInternationalizationString.uWithdrawGarrison);
            }
            else
            {
                //撤防失败
                recordInfo.MsgObjectText = Language.StringByID(R.MyInternationalizationString.uRemoveGarrisonFail);
            }
        }
 
        #endregion
 
        #region ■ 逻辑触发上报_______________________
 
        /// <summary>
        /// 逻辑触发上报
        /// </summary>
        /// <param name="receiveData"></param>
        private void LogicExecutePush(JObject receiveData, ref MessageRecordInfo recordInfo)
        {
            //图标
            recordInfo.IconPath = "Item/LogicMsgIcon.png";
            //类型:逻辑名字
            recordInfo.MsgObjectText = receiveData["Data"]["LogicName"].ToString();
            //已执行
            recordInfo.listMsg.Add(Language.StringByID(R.MyInternationalizationString.uExecuted));
        }
 
        #endregion
 
        #region ■ 场景触发上报_______________________
 
        /// <summary>
        /// 场景触发上报
        /// </summary>
        /// <param name="receiveData"></param>
        private void SceneExecPush(JObject receiveData, ref MessageRecordInfo recordInfo)
        {
            //图标
            recordInfo.IconPath = "Item/SceneMsgIcon.png";
            //类型:场景名字
            recordInfo.MsgObjectText = receiveData["Data"]["ScenesName"].ToString();
            //已执行
            recordInfo.listMsg.Add(Language.StringByID(R.MyInternationalizationString.uExecuted));
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            var userPageForm = UserView.UserPage.Instance.GetNowActionForm();
            if (userPageForm != null && userPageForm.FormID == "UserMainForm")
            {
                Common.CommonPage.Instance.IsDrawerLockMode = false;
            }
            base.CloseFormBefore();
        }
 
        #endregion
    }
}