gxc
2020-02-28 66a9965c44ecc32a6696abca876ab9d1cd091584
ZigbeeApp/Shared/Phone/ZigBee/Device/DoorLock.cs
old mode 100755 new mode 100644
@@ -20,17 +20,31 @@
        #region 门锁本地变量
        /// <summary>
        /// 门锁本地用户列表
        /// 本地门锁用户和账户列表
        /// key:门锁用户ID
        /// </summary>
        /// <returns></returns>
        public Dictionary<int, LocaDoorLockObj> localDoorLockUserList = new Dictionary<int, LocaDoorLockObj>();
        public string currentUserDisplayMethod = string.Empty;
        /// <summary>
        /// 本地门账户列表
        /// key:账户ID(主账户是GUID,子账户是分享过来的账户ID)
        /// </summary>
        /// <returns></returns>
        public Dictionary<string, LocaDoorLockObj> localDoorLockAccountList = new Dictionary<string, LocaDoorLockObj>();
        public string currentUserDisplayMethod = string.Empty;//当前用户显示方式
        //本地所有账户列表
        public List<Shared.Phone.UserCenter.MemberInfoRes> localAllAccountList = new List<Shared.Phone.UserCenter.MemberInfoRes> { };
        public string LocalTempPassword = string.Empty;//本地生成的临时密码
        public Dictionary<string, bool> IsFreezeAccount = new Dictionary<string, bool> { };//是否冻结子账户
        public Dictionary<string, bool> HasRemoteUnlockAccess = new Dictionary<string, bool> { };//是否给子账户拥有远程开锁的条件
        public Dictionary<string, bool> IsFailedToGetDoorLockInfo = new Dictionary<string, bool> { };//是否获取门锁数据失败
        public string RemoteUnlockPassword = string.Empty;//远程开锁密码
        public static int RemoteUnlockCount = 5;//远程开锁次数限制
        public static string RemoteUnlockPassword = string.Empty;//远程开锁密码
        public static int failedCount = 3;//远程开锁失败次数
        public static DateTime maxValue = DateTime.MaxValue;
        public static DateTime minValue = DateTime.MinValue;
        public string LocalTempPassword = string.Empty;//本地生成的临时密码
        #region 临时密码信息
        /// <summary>
@@ -170,10 +184,6 @@
            /// </summary>
            public string PrimaryId = "";
            /// <summary>
            /// 云端帐号Id -->键名 : CloudAccountId
            /// </summary>
            public string CloudAccountId = "";
            /// <summary>
            /// OpenLockMode 开锁方式(密码、指纹、IC卡) -->键名 : OpenLockMode (可选)
            /// </summary>
            public int OpenLockMode = 0;
@@ -209,6 +219,7 @@
            public string PrimaryId = "";
            /// <summary>
            /// 门锁Id -->键名 : DoorLockId (可选)
            /// DelDoorLockDelType 门锁删除类型(0: 根椐门锁主键(云端主键)删除(单条删除)、1:根椐门锁Id批量删除(凡是与门锁Id相同都会删除)、2:根椐门锁Id及门锁本地用户Id批量删除(这个门锁Id这个门锁本地用户Id均会被删除)) -->键名 : DelDoorLockDelType 默认值: 0
            /// </summary>
            public int DelDoorLockDelType;
        }
@@ -481,6 +492,25 @@
            /// 云端帐号Id -->键名 : CloudAccountId (可选)
            /// </summary>
            public string CloudAccountId = "";
            /// <summary>
            /// 第几页
            /// </summary>
            public PageSetting pageSetting = new PageSetting();
        }
        /// <summary>
        ///  获取门锁
        /// </summary>
        public class PageSetting
        {
            /// <summary>
            /// 第几页
            /// </summary>
            public int Page = 1;
            /// <summary>
            /// 第几页
            /// </summary>
            public int PageSize = 10;
        }
        [Serializable]
@@ -622,12 +652,12 @@
        {
            DoorLockAccountList.Clear();
            return await System.Threading.Tasks.Task.Run((Func<System.Threading.Tasks.Task<List<Shared.Phone.UserCenter.MemberInfoRes>>>)(async () =>
           {
               var pra = new Shared.Phone.UserCenter.MemberListInfoPra();
               string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra);
               var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Shared.Phone.UserCenter.MemberInfoRes>>(result);
               return listInfo;
           }));
            {
                var pra = new Shared.Phone.UserCenter.MemberListInfoPra();
                string result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeUsers/GetSubAccountByDistributedMark", false, pra);
                var listInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Shared.Phone.UserCenter.MemberInfoRes>>(result);
                return listInfo;
            }));
        }
        /// <summary>
@@ -667,7 +697,7 @@
            ///不常用:
            /// 1:RF(Zigbee无线);2:Manual(手动);255:Indeterminate(不确定)
            /// </summary>
            public int OperationEventSource;
            public int OperationEventSoure;
            /// <summary>
            /// 事件码
            /// 常用:
@@ -1122,7 +1152,7 @@
                            result = new DefaultControlResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
                        {
                            if (gatewayTemp.clientDataPassthroughResponseData?.PassData != null)
                            {
                                var data = gatewayTemp.clientDataPassthroughResponseData.PassData;
@@ -1173,6 +1203,109 @@
                return result;
            });
        }
        /// <summary>
        /// 用户管理发送数据
        /// userIdList:个数不能超过10个
        /// </summary>
        public string FreezeAccountData(List<int> userIdList, AccessType accessType)
        {
            string data = "";
            string dataLength = "";
            string dataComand1 = "50";
            string dataComand2 = "04";
            string dataSerialNum = "01";
            string addDataLength = "";
            string delUserTypeStr = "";
            string userIdStr = "";
            try
            {
                if (userIdList.Count == 0)
                {
                    return null;
                }
                if (userIdList.Count > 9)
                {
                    return null;
                }
                var tempLength = 5 + userIdList.Count * 2;
                string tempLength1 = Convert.ToString(tempLength, 16);
                switch (tempLength1.Length)
                {
                    case 1:
                        dataLength = "0" + tempLength1.ToUpper();
                        break;
                    case 2:
                        dataLength = tempLength1.ToUpper();
                        break;
                }
                var tempAddDataLength = 1 + userIdList.Count * 2;
                string tempAddDataLength1 = Convert.ToString(tempAddDataLength, 16);
                switch (tempAddDataLength1.Length)
                {
                    case 1:
                        addDataLength = "0" + tempAddDataLength1.ToUpper();
                        break;
                    case 2:
                        addDataLength = tempAddDataLength1.ToUpper();
                        break;
                }
                switch ((int)accessType)
                {
                    case 0:
                        delUserTypeStr = "00";
                        break;
                    case 1:
                        delUserTypeStr = "01";
                        break;
                    case 2:
                        delUserTypeStr = "20";
                        break;
                    case 3:
                        delUserTypeStr = "21";
                        break;
                    case 4:
                        delUserTypeStr = "10";
                        break;
                    case 5:
                        delUserTypeStr = "30";
                        break;
                    case 6:
                        delUserTypeStr = "31";
                        break;
                }
                var sbString = new System.Text.StringBuilder();
                foreach (var userId in userIdList)
                {
                    string temp = Convert.ToString(userId, 16);
                    switch (temp.Length)
                    {
                        case 1:
                            userIdStr = "0" + temp + "00";
                            break;
                        case 2:
                            userIdStr = temp + "00";
                            break;
                        case 3:
                            var thirdBit = temp.Substring(temp.Length - 2, 1);
                            userIdStr = temp + "0" + thirdBit;
                            break;
                        case 4:
                            userIdStr = temp;
                            break;
                    }
                    sbString.Append(userIdStr.ToString().ToUpper());
                }
                data = dataLength + dataComand1 + dataComand2 + dataSerialNum + addDataLength +
                   delUserTypeStr + sbString;
            }
            catch { };
            return data;
        }
        /// <summary>
@@ -1282,7 +1415,7 @@
        public enum AccessType
        {
            /// <summary>
            /// 0x00 删除全部单次用户
            /// 0x00 删除全部临时用户
            /// </summary>
            DelAllUsers = 0,
            /// <summary>
@@ -1297,6 +1430,18 @@
            /// 0x21 解冻指定用户
            /// </summary>
            Enable = 3,
            /// <summary>
            /// 0x10 多个指定用户删除
            /// </summary>
            DelMoreUsers = 4,
            /// <summary>
            /// 0x30 多个指定用户冻结
            /// </summary>
            DisEnableMoreUsers = 5,
            /// <summary>
            /// 0x31 多个指定用户解冻
            /// </summary>
            EnableMoreUsers = 6,
        }
        #endregion
@@ -1455,12 +1600,12 @@
        ///远程开锁
        ///<para>inputPassword: 输入密码/para>
        /// </summary>
        public async System.Threading.Tasks.Task<TempPasswordResponseAllData> RemoteControlAsync(string inputPassword)
        public async System.Threading.Tasks.Task<RemoteResponseAllData> RemoteControlAsync(string inputPassword)
        {
            TempPasswordResponseAllData result = null;
            RemoteResponseAllData result = null;
            if (Gateway == null)
            {
                result = new TempPasswordResponseAllData { errorMessageBase = "当前没有网关" };
                result = new RemoteResponseAllData { errorMessageBase = "当前没有网关" };
                return result;
            }
            return await System.Threading.Tasks.Task.Run(async () =>
@@ -1477,22 +1622,33 @@
                        if (temp == null)
                        {
                            result = new TempPasswordResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                            result = new RemoteResponseAllData { errorMessageBase = "网关错误回复,且数据是空" };
                        }
                        else
                        {
                            result = new TempPasswordResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                            result = new RemoteResponseAllData { errorResponData = temp, errorMessageBase = ErrorMess(temp.Error) };
                        }
                    }
                    if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    else if (topic == $"{gatewayID}/DoorLock/DoorLockOperatingEventNotificationCommand")
                    {
                        var OperatingEventNotificationDatad = Newtonsoft.Json.JsonConvert.DeserializeObject<ZigBee.Device.DoorLock.DoorLockOperatingEventNotificationCommand>(jobject["Data"].ToString());
                        if (OperatingEventNotificationDatad != null)
                        {
                            if (OperatingEventNotificationDatad.OperationEventSoure == 1 && OperatingEventNotificationDatad.OperationEventCode == 5)
                            {
                                result = new RemoteResponseAllData { IsPawDispear = true };
                            }
                        }
                    }
                    else if (topic == gatewayID + "/" + "ZbDataPassthrough")
                    {
                        var gatewayTemp = new ZbGateway() { DataID = jobject.Value<int>("Data_ID") };
                        gatewayTemp.clientDataPassthroughResponseData = Newtonsoft.Json.JsonConvert.DeserializeObject<ClientDataPassthroughResponseData>(jobject["Data"].ToString());
                        if (gatewayTemp.clientDataPassthroughResponseData == null)
                        {
                            result = new TempPasswordResponseAllData { errorMessageBase = "网关返回的数据为空" };
                            result = new RemoteResponseAllData { errorMessageBase = "网关返回的数据为空" };
                        }
                        else
                        {
@@ -1504,10 +1660,10 @@
                                    var command = data[4].ToString() + data[5].ToString() + data[2].ToString() + data[3].ToString();
                                    if (command == "0002")
                                    {
                                        var tempD = new TempPasswordResponseData();
                                        var tempD = new RemoteResponseData();
                                        tempD.command = data[12].ToString() + data[13].ToString() + data[10].ToString() + data[11].ToString();
                                        tempD.status = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                        result = new TempPasswordResponseAllData { responseData = tempD };
                                        result = new RemoteResponseAllData { responseData = tempD };
                                        DebugPrintLog($"UI收到通知后的主题_command:0462_{ topic}");
                                    }
                                }
@@ -1515,7 +1671,6 @@
                        }
                    }
                };
                Gateway.Actions += action;
                DebugPrintLog("ClientDataPassthrough_Actions 启动" + System.DateTime.Now.ToString());
@@ -1531,18 +1686,25 @@
                catch { }
                var dateTime = DateTime.Now;
                while ((DateTime.Now - dateTime).TotalMilliseconds < 9000)// WaitReceiveDataTime)
                while ((DateTime.Now - dateTime).TotalMilliseconds < 5000)// WaitReceiveDataTime)
                {
                    await System.Threading.Tasks.Task.Delay(10);
                    if (result != null && result.responseData != null && result.responseData.command == "0462")
                    if (result == null)
                    {
                        continue;
                    }
                    if (result.responseData != null && result.responseData.command == "0462")
                    {
                        break;
                    }
                    if (result.IsPawDispear == true)
                    {
                        break;
                    }
                }
                if ((DateTime.Now - dateTime).TotalMilliseconds > WaitReceiveDataTime)
                {
                    result = new TempPasswordResponseAllData
                    { errorMessageBase = " 回复超时,请重新操作" };
                    result = new RemoteResponseAllData { errorMessageBase = " 回复超时,请重新操作" };
                }
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
@@ -1577,6 +1739,51 @@
            catch { };
            return data;
        }
        /// <summary>
        ///  远程回复数据
        /// </summary>
        public RemoteResponseAllData remoteResponseAllData;
        [System.Serializable]
        public class RemoteResponseAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
            /// <para>当网关接收到客户端信息后,出现以下异常情况将反馈错误。</para>
            /// </summary>
            public ErrorResponData errorResponData;
            /// <summary>
            /// 临时密码回复数据
            /// </summary>
            public RemoteResponseData responseData;
            /// <summary>
            /// 是否密码被删除
            /// </summary>
            public bool IsPawDispear = false;
        }
        /// <summary>
        /// 用户管理数据回复
        /// </summary>
        [System.Serializable]
        public class RemoteResponseData
        {
            /// <summary>
            ///响应操作码(0-ffff)
            /// </summary>
            public string command = "";
            /// <summary>
            /// 状态值
            /// <para>默认响应结果:
            ///<para>0 成功</para>
            ///<para>1 失败</para>
            /// </summary>
            public int status = -1;
        }
        #endregion
@@ -1727,13 +1934,13 @@
        /// <summary>
        /// 临时密码回复数据
        /// </summary>
        public TempPasswordResponseAllData keyColorDataResponseAllData;
        public TempPasswordResponseAllData tempPasswordResponseAllData;
        [System.Serializable]
        public class TempPasswordResponseAllData
        {
            /// <summary>
            /// 错误信息
            /// </summary>
            /// </summary>
            public string errorMessageBase;
            /// <summary>
            /// 网关信息错误反馈
@@ -1960,6 +2167,8 @@
        public async System.Threading.Tasks.Task<DoorlockUserInfo> GetDoorlockUserInfoAsync()
        {
            DoorlockUserInfo result = null;
            int totalNum = 0;
            int currentNum = -1;
            DoorLockUserDetailData doorLockUserDetailData = new DoorLockUserDetailData { };
            if (Gateway == null)
            {
@@ -2007,6 +2216,8 @@
                                    doorLockUserDetailData.userType = Convert.ToInt32(data[10].ToString() + data[11].ToString(), 16);
                                    doorLockUserDetailData.totalNum = Convert.ToInt32(data[12].ToString() + data[13].ToString(), 16);
                                    doorLockUserDetailData.currentNum = Convert.ToInt32(data[14].ToString() + data[15].ToString(), 16);
                                    totalNum = doorLockUserDetailData.totalNum;
                                    currentNum = doorLockUserDetailData.currentNum;
                                    result = new DoorlockUserInfo { doorLockUserDetailData = doorLockUserDetailData };
                                    DebugPrintLog($"UI收到通知后的主题_command:0451_{ topic}");
                                }
@@ -2028,12 +2239,19 @@
                }
                catch { }
                //接收一个包最多等5秒,没有收到就退出
                while ((DateTime.Now - dateTime).TotalMilliseconds < 5000)
                //接收一个包最多等3秒,没有收到就退出,单次数据包不超过30个用户
                while ((DateTime.Now - dateTime).TotalMilliseconds < 3000)
                {
                    await System.Threading.Tasks.Task.Delay(100);
                    if (totalNum == currentNum)
                    {
                        break;
                    }
                }
                //if ((DateTime.Now - dateTime).TotalMilliseconds > 3000)
                //{
                //    result = new DoorlockUserInfo { errorMessageBase = " 回复超时,请重新操作" };
                //}
                Gateway.Actions -= action;
                DebugPrintLog("ClientDataPassthrough_Actions 退出" + System.DateTime.Now.ToString());
@@ -2124,4 +2342,4 @@
        #endregion
    }
}
}