黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
ZigbeeApp/Shared/Phone/Common/Logic/HdlGatewayReceiveLogic.cs
File was renamed from ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Logic/HdlGatewayReceiveLogic.cs
@@ -4,7 +4,7 @@
using Newtonsoft.Json.Linq;
using ZigBee.Device;
namespace Shared.Phone.UserCenter
namespace Shared.Phone
{
    /// <summary>
    /// 全局接收网关推送的的逻辑(为了执行速度,尽可能的别加耗时的操作)
@@ -73,10 +73,9 @@
                {
                    //登录密匙已经过期,请重新登录
                    string msg = Language.StringByID(R.MyInternationalizationString.uTokenIsOldAndLoginAgain);
                    var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                    contr.Show();
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
                    UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                    HdlAccountLogic.Current.ReLoginAgain(HdlUserCenterResourse.UserInfo.Account, false);
                });
                return;
            }
@@ -86,10 +85,9 @@
                {
                    //此帐号已在别处登录,您被迫下线
                    string msg = Language.StringByID(R.MyInternationalizationString.uHadBeenLoginAndOffLine);
                    var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                    contr.Show();
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
                    UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                    HdlAccountLogic.Current.ReLoginAgain(HdlUserCenterResourse.UserInfo.Account, false);
                });
                return;
            }
@@ -99,10 +97,9 @@
                {
                    //您当前的IP及端口在云端不存在,请重新登录!
                    string msg = Language.StringByID(R.MyInternationalizationString.uYouIpAndPortNoRecord);
                    var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                    contr.Show();
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
                    UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                    HdlAccountLogic.Current.ReLoginAgain(HdlUserCenterResourse.UserInfo.Account, false);
                });
                return;
            }
@@ -112,10 +109,9 @@
                {
                    //分享住宅已更改,请联系管理员!
                    string msg = Language.StringByID(R.MyInternationalizationString.uShardResidenceHadDeletePleaseTakeToAdmin);
                    var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                    contr.Show();
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
                    UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                    HdlAccountLogic.Current.ReLoginAgain(HdlUserCenterResourse.UserInfo.Account, false);
                });
                return;
            }
@@ -125,14 +121,13 @@
                {
                    //您的权限已经变更,请重新登陆
                    string msg = Language.StringByID(R.MyInternationalizationString.uYouAccessHadChangedPleaseTakeToAdmin);
                    var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                    contr.Show();
                    HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
                    UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                    HdlAccountLogic.Current.ReLoginAgain(HdlUserCenterResourse.UserInfo.Account, false);
                });
                return;
            }
            else if (UserCenterResourse.UserInfo.AuthorityNo == 3)
            else if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 3)
            {
                if (topic == "ZigbeeGateWayToClient/" + Common.Config.Instance.Guid + "/Push/Deleted"
                || topic == "ZigbeeGateWayToClient/" + Common.Config.Instance.Guid + "/Push/DeletedShareData")
@@ -141,10 +136,9 @@
                    {
                        //分享数据已经变更,请重新登陆
                        string msg = Language.StringByID(R.MyInternationalizationString.uShardDataIsChangedPleaseLoginAgain);
                        var contr = new ShowMsgControl(ShowMsgType.Tip, msg);
                        contr.Show();
                        HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, msg);
                        UserCenterLogic.ReLoginAgain(UserCenterResourse.UserInfo.Account, false);
                        HdlAccountLogic.Current.ReLoginAgain(HdlUserCenterResourse.UserInfo.Account, false);
                    });
                    return;
                }
@@ -251,15 +245,8 @@
                return;
            }
            var tempList = Common.LocalDevice.Current.GetDevicesByMac(report.DeviceAddr, false);
            var res = Common.LocalDevice.Current.GetMyDeviceEnumInfo(tempList);
            if (res.ConcreteType == Common.DeviceConcreteType.Airer)
            {
                //晾衣架特殊处理,本地只存了端点1,其余2~5端点都不存
                deviceEpoint = 1;
            }
            //处理网关上报的数据,然后变更本地缓存
            var locadevice = Common.LocalDevice.Current.GetDevice(deviceAddr, deviceEpoint);
            var locadevice = HdlDeviceCommonLogic.Current.GetDevice(deviceAddr, deviceEpoint);
            if (locadevice != null)
            {
                //有反馈,这个设备肯定是在线的
@@ -267,88 +254,6 @@
                locadevice.LastDateTime = DateTime.Now;
                #region ■ 开关功能
                //晾衣架回路2,3,4,5都是CluterID是6 ,但是功能不是开关
                if (locadevice.Type == DeviceType.Airer)
                {
                    if (report.DeviceStatusReport.CluterID == 6)
                    {
                        foreach (var attData in report.DeviceStatusReport.AttriBute)
                        {
                            locadevice.DeviceStatusReport = report.DeviceStatusReport;
                            if (attData.AttributeId == 0)
                            {
                                //注意晾衣架回路上报都端点都是被替换为回路1,所以这里用上报都回路
                                switch (report.DeviceEpoint)
                                {
                                    //照明
                                    case 2:
                                        ((Airer)locadevice).OnOffStatus = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        break;
                                    //风干
                                    case 3:
                                        ((Airer)locadevice).WindOnOffStatus = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        break;
                                    //烘干
                                    case 4:
                                        ((Airer)locadevice).DryOnOffStatus = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        break;
                                    //消毒
                                    case 5:
                                        ((Airer)locadevice).DisinfectOnOffStatus = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                                        break;
                                }
                            }
                            //晾衣架(风干/烘干/消毒)设置的默认时间
                            // 注意,第一阶段时间设备不支持而暂停,没有处理剩余多少时间触发,直接上报回复一个属性ID的情况
                            //if (attData.AttributeId == 16385)
                            //{
                            //  //注意晾衣架回路上报都端点都是被替换为回路1,所以这里用上报都回路
                            //  switch (report.DeviceEpoint)
                            //  {
                            //    //风干
                            //    case 3:
                            //      ((Airer)locadevice).WindTime = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                            //      break;
                            //    //烘干
                            //    case 4:
                            //      ((Airer)locadevice).DryTime = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                            //      break;
                            //    //消毒
                            //    case 5:
                            //      ((Airer)locadevice).DisinfectTime = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                            //      break;
                            //  }
                            //}
                            //晾衣架(风干/烘干/消毒)设置的剩余多少时间触发
                            // 注意,第一阶段时间设备不支持而暂停,没有处理剩余多少时间触发,直接上报回复一个属性ID的情况
                            //if (attData.AttributeId == 16386)
                            //{
                            //  //注意晾衣架回路上报都端点都是被替换为回路1,所以这里用上报都回路
                            //  switch (report.DeviceEpoint)
                            //  {
                            //    //风干
                            //    case 3:
                            //      ((Airer)locadevice).WindRemainTime = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                            //      break;
                            //    //烘干
                            //    case 4:
                            //      ((Airer)locadevice).DryRemainTime = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                            //      break;
                            //    //消毒
                            //    case 5:
                            //      ((Airer)locadevice).DisinfectRemainTime = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                            //      break;
                            //  }
                            //}
                            //已经接收到状态
                            locadevice.HadReadDeviceStatu = true;
                        }
                    }
                }
                else
                {
                    //开关功能
                    if (report.DeviceStatusReport.CluterID == 6)
                    {
@@ -358,7 +263,6 @@
                            ((LightBase)locadevice).OnOffStatus = report.DeviceStatusReport.AttriBute[0].AttriButeData;
                            //已经接收到状态
                            locadevice.HadReadDeviceStatu = true;
                        }
                    }
                }
                #endregion
@@ -394,7 +298,7 @@
                else if (report.DeviceStatusReport.CluterID == 1282)
                {
                    //mini夜灯
                    if (Common.LocalDevice.Current.IsMiniLight(locadevice) == true)
                    if (HdlDeviceCommonLogic.Current.IsMiniLight(locadevice) == true)
                    {
                        foreach (var attData in report.DeviceStatusReport.AttriBute)
                        {
@@ -501,7 +405,7 @@
                    foreach (var attData in report.DeviceStatusReport.AttriBute)
                    {
                        //区分是空调还是新风
                        var device = Shared.Common.LocalDevice.Current.GetDevice(report.DeviceAddr, report.DeviceEpoint);
                        var device = HdlDeviceCommonLogic.Current.GetDevice(report.DeviceAddr, report.DeviceEpoint);
                        if (device.Type == DeviceType.FreshAir)
                        {
@@ -752,7 +656,7 @@
                else if (report.DeviceStatusReport.CluterID == 0)
                {
                    var listLocalDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr, false);
                    var listLocalDevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(deviceAddr, false);
                    //属性都是一样的
                    foreach (var myDevice in listLocalDevice)
                    {
@@ -765,7 +669,7 @@
                            {
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    var value = HdlCommonLogic.Current.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    if (myDevice.ManufacturerName != value)
                                    {
                                        //属性变更了
@@ -779,7 +683,7 @@
                            {
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    var value = HdlCommonLogic.Current.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    if (myDevice.ModelIdentifier != value)
                                    {
                                        //属性变更了
@@ -793,7 +697,7 @@
                            {
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    var value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    var value = HdlCommonLogic.Current.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    if (myDevice.ProductionDate != value)
                                    {
                                        //属性变更了
@@ -813,7 +717,7 @@
                                if (data.AttriButeDataHex.Length > 2)
                                {
                                    string value;
                                    if (Common.LocalDevice.Current.IsHdlDevice(myDevice) == false)
                                    if (HdlDeviceCommonLogic.Current.IsHdlDevice(myDevice) == false)
                                    {
                                        //第三方设备
                                        value = data.AttriButeDataHex.Substring(2);
@@ -821,7 +725,7 @@
                                    else
                                    {
                                        //河东设备
                                        value = UserCenterLogic.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                        value = HdlCommonLogic.Current.TranslateHexadecimalIntoText(data.AttriButeDataHex.Substring(2));
                                    }
                                    if (myDevice.SerialNumber != value)
                                    {
@@ -846,7 +750,7 @@
            }
            else if (deviceEpoint == 200)
            {
                var localOta = Common.LocalDevice.Current.GetOTADevice(deviceAddr);
                var localOta = HdlDeviceCommonLogic.Current.GetOTADevice(deviceAddr);
                if (localOta != null)
                {
                    #region ■ 固件版本
@@ -900,7 +804,7 @@
            }
            //处理网关上报的数据,然后变更本地缓存
            var locadevice = Common.LocalDevice.Current.GetDevice(ias.DeviceAddr, ias.DeviceEpoint);
            var locadevice = HdlDeviceCommonLogic.Current.GetDevice(ias.DeviceAddr, ias.DeviceEpoint);
            if (locadevice != null)
            {
                ((IASZone)locadevice).iASInfo = ias.iASInfo;
@@ -926,9 +830,9 @@
        /// <param name="receiveData"></param>
        private void DoorLockDeviceReportPush(JObject receiveData)
        {
            if (UserCenterResourse.UserInfo.AuthorityNo == 1)
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1)
            {
                var device = Common.LocalDevice.Current.GetDevice(receiveData.Value<string>("DeviceAddr"), receiveData.Value<int>("Epoint"));
                var device = HdlDeviceCommonLogic.Current.GetDevice(receiveData.Value<string>("DeviceAddr"), receiveData.Value<int>("Epoint"));
                if (device.Type != DeviceType.DoorLock)
                {
                    //它不是门锁
@@ -974,7 +878,7 @@
            tempDevice.IsOnline = Convert.ToInt32(receiveData["Data"]["IsOnline"].ToString());
            //处理网关上报的数据,然后变更本地缓存
            var locadevice = Common.LocalDevice.Current.GetDevicesByMac(tempDevice.DeviceAddr);
            var locadevice = HdlDeviceCommonLogic.Current.GetDevicesByMac(tempDevice.DeviceAddr);
            for (int i = 0; i < locadevice.Count; i++)
            {
                bool onlineChanged = locadevice[i].IsOnline != tempDevice.IsOnline;
@@ -1033,12 +937,11 @@
                //保存报警信息然后推送到界面上
                HdlAlarmsLogic.Current.SaveSafeguardAlarmInfo(garrison);
                if (UserCenterResourse.DicActionForm.ContainsKey("SafetyManagementMainForm") == true)
                {
                    //推送
                    var form = (Safety.SafetyManagementMainForm)UserCenterResourse.DicActionForm["SafetyManagementMainForm"];
                var form = HdlFormLogic.Current.GetFormByName("SafetyManagementMainForm") as UserCenter.Safety.SafetyManagementMainForm;
                    form?.GarrisonModePush(garrison);
                }
                //显示有新消息的特效
                this.ShowHadNewMessageAppeal();
            }
@@ -1059,12 +962,11 @@
            {
                //保存报警信息然后推送到界面上
                HdlAlarmsLogic.Current.SaveSafeguardAlarmInfo(GarrisonMode.RemoveGarrison);
                if (UserCenterResourse.DicActionForm.ContainsKey("SafetyManagementMainForm") == true)
                {
                    //推送
                    var form = (Safety.SafetyManagementMainForm)UserCenterResourse.DicActionForm["SafetyManagementMainForm"];
                var form = HdlFormLogic.Current.GetFormByName("SafetyManagementMainForm") as UserCenter.Safety.SafetyManagementMainForm;
                    form?.GarrisonModePush(GarrisonMode.RemoveGarrison);
                }
                //显示有新消息的特效
                this.ShowHadNewMessageAppeal();
            }
@@ -1106,12 +1008,11 @@
            //保存报警信息然后推送到界面上
            HdlAlarmsLogic.Current.SaveSafeguardAlarmInfo(garrison, appendText);
            if (UserCenterResourse.DicActionForm.ContainsKey("SafetyManagementMainForm") == true)
            {
                //推送
                var form = (Safety.SafetyManagementMainForm)UserCenterResourse.DicActionForm["SafetyManagementMainForm"];
            var form = HdlFormLogic.Current.GetFormByName("SafetyManagementMainForm") as UserCenter.Safety.SafetyManagementMainForm;
                form?.GarrisonModePush(garrison);
            }
            //显示有新消息的特效
            this.ShowHadNewMessageAppeal();
        }
@@ -1149,7 +1050,7 @@
            this.ShowHadNewMessageAppeal();
            // 逻辑执行常开模式失效的情况
            if (UserCenterResourse.UserInfo.AuthorityNo == 1)
            if (HdlUserCenterResourse.ResidenceOption.AuthorityNo == 1)
            {
                //自动化执行 常开关闭
                var data = Newtonsoft.Json.JsonConvert.DeserializeObject<LogicPushResult>(receiveData["Data"].ToString());
@@ -1158,7 +1059,7 @@
                    if (data.ActionData.Actiontype == 8 && data.ActionData.PassDataString == "055704010113")
                    {
                        var deviceAddr = data.ActionData.MacStr;
                        var device = Common.LocalDevice.Current.GetDevicesByMac(deviceAddr, false);
                        var device = HdlDeviceCommonLogic.Current.GetDevicesByMac(deviceAddr, false);
                        if (device.Count > 0 && device[0].Type != DeviceType.DoorLock)
                        {
                            return;
@@ -1334,7 +1235,7 @@
                    catch (Exception ex)
                    {
                        //Log出力
                        string msg = "推送错误! 当前激活的界面[" + UserCenterResourse.NowActionFormID + "]";
                        string msg = "推送错误! 当前激活的界面[" + HdlFormLogic.Current.NowActionFormID + "]";
                        HdlLogLogic.Current.WriteLog(ex, msg);
                    }
                }
@@ -1357,16 +1258,16 @@
        private void ShowHadNewMessageAppeal()
        {
            //有新消息(特效还在时,不需要再处理)
            if (ControlCommonResourse.HadNewMessage == false)
            if (HdlControlResourse.HadNewMessage == false)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    for (int i = 0; i < ControlCommonResourse.listMessageManaContr.Count; i++)
                    for (int i = 0; i < HdlControlResourse.listMessageManaContr.Count; i++)
                    {
                        //显示角标特效
                        ControlCommonResourse.listMessageManaContr[i].IsSelected = true;
                        HdlControlResourse.listMessageManaContr[i].IsSelected = true;
                    }
                    ControlCommonResourse.HadNewMessage = true;
                    HdlControlResourse.HadNewMessage = true;
                });
            }
        }