wjc
2023-03-10 e66503d70f26a3109fbadf47abcb8ba31d619e3c
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
using System;
using System.Collections.Generic;
using System.Threading;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using Shared;
using static HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock.CommonMethod;
 
 
namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock
{
    /// <summary>
    /// 萤石视频门锁数据发送
    /// </summary>
    public class VideDoorLockSend
    {
 
        private static VideDoorLockSend send = null;
        /// <summary>
        /// 获取当前的对象 
        /// </summary>
        public static VideDoorLockSend Current
        {
            get
            {
                if (send == null)
                {
                    send = new VideDoorLockSend();
                }
 
                return send;
            }
        }
        /// <summary>
        /// 解绑设备(萤石视频门锁)
        /// </summary>
        /// <param name="function">当前的设备</param>
        /// <param name="action">回调结果</param>
        public void DelDevice(Function function, Action<bool> action)
        {
            new Thread(() =>
            {
                try
                {
                    Dictionary<string, object> d = new Dictionary<string, object>();
                    d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
                    d.Add("deviceSerial", function.sid);//等同门锁序列号
                        d.Add("platform", 1);//平台
                        var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_DeleteDevice, "删除萤石门锁设备");
                    if (!this.DataChecking(responsePackNew))
                    {
                        return;
                    }
 
                    if (function != null)
                    {
                        action?.Invoke(false);
                    }
                }
                catch (Exception s)
                {
                }
            })
            { IsBackground = true }.Start();
 
        }
        /// <summary>
        /// 获取门锁状态(萤石视频门锁)
        /// </summary>
        /// <param name="function">当前的设备</param>
        /// <param name="return">返回结果不会为null</param>
        public VideoDoorLockInfo GetVideoDoorLockState(Function function, TipType tipType = TipType.flicker)
        {
 
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
            d.Add("deviceId", function.deviceId);
            var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_Lockstatus, "删除萤石视频门锁状态");
            if (!this.DataChecking(responsePackNew))
            {
                return new VideoDoorLockInfo();
            }
 
            var videoDoorLockInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<VideoDoorLockInfo>(responsePackNew.Data.ToString());
            if (videoDoorLockInfo == null)
            {
                return new VideoDoorLockInfo();
            }
            return videoDoorLockInfo;
 
 
 
        }
        /// <summary>
        /// 获取电池电量(萤石视频门锁)
        /// </summary>
        /// <param name="function">当前的设备</param>
        /// <param name="return">返回结果不会为null</param>
        public CellInfo GetCellValue(Function function, TipType tipType = TipType.flicker)
        {
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
            d.Add("deviceId", function.deviceId);
            var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_Details, "获取萤石门锁设备电量");
            if (!this.DataChecking(responsePackNew))
            {
                return new CellInfo();
            }
            var cellInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<CellInfo>(responsePackNew.Data.ToString());
            if (cellInfo == null)
            {
                return new CellInfo();
            }
 
            return cellInfo;
 
        }
        /// <summary>
        /// 获取门锁用户列表(萤石视频门锁)
        /// </summary>
        /// <param name="function">当前的设备</param>
        ///    /// <param name="return">返回结果不会为null</param>
        public List<UserInfo> GetVideoDoorLockUserListInfo(Function function, TipType tipType = TipType.flicker)
        {
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
            d.Add("deviceId", function.deviceId);
            var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_UserList, "获取萤石门锁用户列表");
            if (!this.DataChecking(responsePackNew))
            {
                return new List<UserInfo>();
            }
            var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<UserInfo>>(responsePackNew.Data.ToString());
            if (list == null)
            {
                return new List<UserInfo>();
            }
            return list;
        }
        /// <summary>
        /// 获取门锁设备列表(萤石视频门锁)
        /// </summary>
        /// <param name="spk">指定spk获取</param>
        /// <returns></returns>
        public List<Function> GetVideoDoorLockDeviceList(string spk)
        {
 
            Dictionary<string, object> d = new Dictionary<string, object>();
            d.Add("homeId", DB_ResidenceData.Instance.CurrentRegion.id);
            d.Add("spk", spk);
            var responsePackNew = UI.Music.SendMethod.Current.RequestServerhomeId(d, NewAPI.Api_Post_UserList, "获取萤石门锁设备列表");
            if (!this.DataChecking(responsePackNew))
            {
                return new List<Function>();
            }
            var list = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Function>>(responsePackNew.Data.ToString());
            if (list == null)
            {
                return new List<Function>();
            }
            return list;
        }
        /// <summary>
        /// 检验数据回复成功或者失败
        /// </summary>
        /// <param name="responsePackNew">回复数据对象</param>
        /// <param name="tipType">是否需要提示,默认提示</param>
        /// <returns></returns>
        private bool DataChecking(ResponsePackNew responsePackNew, TipType tipType = TipType.flicker)
        {
            if (responsePackNew.Data == null || responsePackNew.Code != "0" || responsePackNew.Data.ToString() == "")
            {
                if (TipType.flicker == tipType)
                {
                    if (responsePackNew == null)
                    {
                        responsePackNew = new ResponsePackNew { message = "没回复,请确认网络是否正常.", Code = "-1", };
 
                    }
                    //new Tip()
                    //{
                    //    CloseTime = 1,
                    //    Text = responsePackNew.message + "(" + responsePackNew.Code + ")",
                    //    Direction = AMPopTipDirection.None,
                    //}.Show(MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1));
                }
                return false;
            }
            return true;
        }
 
 
    }
}