wjc
2022-07-22 d538cbe6f5e307122c37cde69b999dc9df30731a
HDL_ON/UI/UI2/3-Intelligence/Automation/LogicMethod.cs
@@ -147,7 +147,9 @@
        /// <returns></returns>
        public List<HDL_ON.Entity.Room> GetGatewayRoomList()
        {
            return HDL_ON.Entity.SpatialInfo.CurrentSpatial.RoomList;
            return   HDL_ON.Entity.SpatialInfo.CurrentSpatial.RoomList;
        }
        /// <summary>
        /// 获取网关房间列表
@@ -180,7 +182,9 @@
        /// <returns></returns>
        public List<HDL_ON.Entity.Function> GetGatewayDeviceList()
        {
            return Entity.FunctionList.List.GetDeviceFunctionList();
            var list = Entity.FunctionList.List.GetDeviceFunctionList();
            return GetTestDevice(list, true);
            //return list;
        }
        /// <summary>
        /// 获取场景列表
@@ -586,7 +590,7 @@
            ///门锁类
            else if (deviceType == Language.StringByID(StringId.DoorLock))
            {
                functionTypeList.Add(SPK.DoorLock);
                functionTypeList.Add(SPK.DoorLock);
            }
            else
            {
@@ -943,57 +947,57 @@
            {
                try
                {
              //获取逻辑ID列表,目前针对所有<备注:如果只针对当前手机的话,可以直接拿缓存数据自动化列表遍历>
              var idStr = Send.GetLogicIdList();
                    //获取逻辑ID列表,目前针对所有<备注:如果只针对当前手机的话,可以直接拿缓存数据自动化列表遍历>
                    var idStr = Send.GetLogicIdList();
                    if (idStr.Code == "0" && idStr.Data != null && idStr.Data.ToString() != "")
                    {
                        var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data);
                        logicDataList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogicData>>(date);
                    }
              ///有自动列表才处理
              if (logicDataList.Count > 0)
                    ///有自动列表才处理
                    if (logicDataList.Count > 0)
                    {
                  ///遍历所有列表
                  for (int i = 0; i < logicDataList.Count; i++)
                        ///遍历所有列表
                        for (int i = 0; i < logicDataList.Count; i++)
                        {
                            var logicDate = logicDataList[i];
                      ///自动化没有配置地理围栏不处理
                      if (string.IsNullOrEmpty(logicDate.geo_fence.latitude) || string.IsNullOrEmpty(logicDate.geo_fence.longitude))
                            ///自动化没有配置地理围栏不处理
                            if (string.IsNullOrEmpty(logicDate.geo_fence.latitude) || string.IsNullOrEmpty(logicDate.geo_fence.longitude))
                            {
                          //经纬度为空,认为自动化没有配置地理围栏,不处理;
                          continue;
                                //经纬度为空,认为自动化没有配置地理围栏,不处理;
                                continue;
                            }
                      //自动化配置输入条件纬度
                      double lat = Convert.ToDouble(logicDate.geo_fence.latitude.Replace(",", "."));
                      //自动化配置输入条件经度
                      double lon = Convert.ToDouble(logicDate.geo_fence.longitude.Replace(",", "."));
                      //自动化配置输入条件<地理围栏半径><单位,公里、千米.米>
                      int radius = int.Parse(logicDate.geo_fence.radius);
                      //计算2个经纬度之间的距离
                      int r = Infrastructure.Service.Helper.CalculatedDistance.Distance(out_lat, out_lng, lat, lon);
                      //定义一个局部变量
                      string direction = string.Empty;
                      //两点距离小于配置距离<既自动化配置输入条件地理围栏半径>,说明进入区域
                      if (r < radius)
                            //自动化配置输入条件纬度
                            double lat = Convert.ToDouble(logicDate.geo_fence.latitude.Replace(",", "."));
                            //自动化配置输入条件经度
                            double lon = Convert.ToDouble(logicDate.geo_fence.longitude.Replace(",", "."));
                            //自动化配置输入条件<地理围栏半径><单位,公里、千米.米>
                            int radius = int.Parse(logicDate.geo_fence.radius);
                            //计算2个经纬度之间的距离
                            int r = Infrastructure.Service.Helper.CalculatedDistance.Distance(out_lat, out_lng, lat, lon);
                            //定义一个局部变量
                            string direction = string.Empty;
                            //两点距离小于配置距离<既自动化配置输入条件地理围栏半径>,说明进入区域
                            if (r < radius)
                            {
                          //到达某地
                          direction = "arrive";
                                //到达某地
                                direction = "arrive";
                            }
                            else
                            {
                          //离开
                          direction = "leave";
                                //离开
                                direction = "leave";
                            }
                      ///遍历缓存列表<不为空说明数据已经推送过,不再推送>
                      var isPush = pushList.Find((o) => o.homeId == HomeId && o.userId == UserInfo.Current.ID && o.userLogicId == logicDate.userLogicId && o.arriveOnLeave == direction);
                            ///遍历缓存列表<不为空说明数据已经推送过,不再推送>
                            var isPush = pushList.Find((o) => o.homeId == HomeId && o.userId == UserInfo.Current.ID && o.userLogicId == logicDate.userLogicId && o.arriveOnLeave == direction);
                            if (isPush == null)
                            {
                          //推送给云端是否成功
                          bool push = Send.GeoFenceStateReport(logicDate.userLogicId, logicDate.sid, direction);
                                //推送给云端是否成功
                                bool push = Send.GeoFenceStateReport(logicDate.userLogicId, logicDate.sid, direction);
                                if (push)
                                {
                              ///添加到推送列表
                              pushList.Add(new Push
                                    ///添加到推送列表
                                    pushList.Add(new Push
                                    {
                                        homeId = HomeId,
                                        userId = UserInfo.Current.ID,
@@ -1014,6 +1018,27 @@
        /// 推送列表<这里数据已经推送过>
        /// </summary>
        private static List<Push> pushList = new List<Push>();
        /// <summary>
        /// 获取模拟的设备列表
        /// </summary>
        /// <param name="isBool">是否开启</param>
        /// <returns></returns>
        private List<Entity.Function> GetTestDevice(List<HDL_ON.Entity.Function> list, bool isBool)
        {
            if (isBool)
            {
                Entity.Function function = new Entity.Function { sid = "0123456789", name = "超声波传感器", spk = Entity.SPK.SensorUtrasonic };
                var device = list.Find((o) => { return o.sid == function.sid; });
                if (device == null)
                {
                    list.Add(function);
                }
            }
            return list;
        }
    }
    public class Push