| | |
| | | /// <summary> |
| | | /// APP上报GPS经纬度 |
| | | /// </summary> |
| | | public void AppLatAndLonEvent() |
| | | /// <param name="lon">APP GPS经度</param> |
| | | /// <param name="lat">APP GPS纬度</param> |
| | | public void AppLatAndLonEvent(double lon, double lat) |
| | | { |
| | | Application.LocationAction += (lon, lat) => |
| | | { |
| | | ////GPS坐标转成高德坐标 |
| | | //double out_lng, out_lat; |
| | | //this.WGS84_to_GCJ02(lon, lat, out out_lng, out out_lat); |
| | | //上报经纬度 |
| | | this.AutomatedGeofenceStatusReporting(lon, lat); |
| | | }; |
| | | Console.WriteLine($"GPS经度===={lon} \nGPS纬度===={lat}"); |
| | | //Application.LocationAction += (lon, lat) => |
| | | //{ |
| | | // Console.WriteLine($"GPS经度===={lon}"); |
| | | // Console.WriteLine($"GPS纬度===={lat}"); |
| | | // ////GPS坐标转成高德坐标 |
| | | // //double out_lng, out_lat; |
| | | // //this.WGS84_to_GCJ02(lon, lat, out out_lng, out out_lat); |
| | | // //上报经纬度 |
| | | // this.AutomatedGeofenceStatusReporting(lon, lat); |
| | | //}; |
| | | //上报经纬度<gps 上报条件大于30秒且移动距离大于100米,上报经纬度> |
| | | this.AutomatedGeofenceStatusReporting(lon, lat); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | { |
| | | List<LogicData> logicDataList = new List<LogicData>(); |
| | | logicDataList.Clear(); |
| | | //获取逻辑ID列表 |
| | | var idStr = Send.GetLogicIdList(); |
| | | if (idStr.Code == "0" && idStr.Data != null && idStr.Data.ToString() != "") |
| | | System.Threading.Tasks.Task.Run(() => |
| | | { |
| | | var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data); |
| | | logicDataList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogicData>>(date); |
| | | } |
| | | ///有自动列表才处理 |
| | | if (logicDataList.Count > 0) |
| | | { |
| | | ///遍历所有列表 |
| | | for (int i = 0; i < logicDataList.Count; i++) |
| | | try |
| | | { |
| | | var logicDate = logicDataList[i]; |
| | | ///自动化没有配置地理围栏不处理 |
| | | if (string.IsNullOrEmpty(logicDate.geo_fence.latitude) || string.IsNullOrEmpty(logicDate.geo_fence.longitude)) |
| | | //获取逻辑ID列表<备注:如果只针对当前手机的话,可以直接拿缓存数据自动化列表遍历> |
| | | var idStr = Send.GetLogicIdList(); |
| | | if (idStr.Code == "0" && idStr.Data != null && idStr.Data.ToString() != "") |
| | | { |
| | | //经纬度为空,认为自动化没有配置地理围栏,不处理; |
| | | continue; |
| | | var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data); |
| | | logicDataList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<LogicData>>(date); |
| | | } |
| | | //自动化配置输入条件纬度 |
| | | double lat = Convert.ToDouble(logicDate.geo_fence.latitude); |
| | | //自动化配置输入条件经度 |
| | | double lon = Convert.ToDouble(logicDate.geo_fence.longitude); |
| | | //自动化配置输入条件<地理围栏半径><单位,公里、千米.米> |
| | | 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) |
| | | ///有自动列表才处理 |
| | | if (logicDataList.Count > 0) |
| | | { |
| | | //到达某地 |
| | | direction = "arrive"; |
| | | } |
| | | else |
| | | { |
| | | //离开 |
| | | direction = "leave"; |
| | | } |
| | | 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); |
| | | if (push) |
| | | ///遍历所有列表 |
| | | for (int i = 0; i < logicDataList.Count; i++) |
| | | { |
| | | pushList.Add(new Push |
| | | var logicDate = logicDataList[i]; |
| | | ///自动化没有配置地理围栏不处理 |
| | | if (string.IsNullOrEmpty(logicDate.geo_fence.latitude) || string.IsNullOrEmpty(logicDate.geo_fence.longitude)) |
| | | { |
| | | homeId = HomeId, |
| | | userId = UserInfo.Current.ID, |
| | | userLogicId = logicDate.userLogicId, |
| | | arriveOnLeave = direction, |
| | | }); |
| | | //经纬度为空,认为自动化没有配置地理围栏,不处理; |
| | | continue; |
| | | } |
| | | //自动化配置输入条件纬度 |
| | | double lat = Convert.ToDouble(logicDate.geo_fence.latitude); |
| | | //自动化配置输入条件经度 |
| | | double lon = Convert.ToDouble(logicDate.geo_fence.longitude); |
| | | //自动化配置输入条件<地理围栏半径><单位,公里、千米.米> |
| | | 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"; |
| | | } |
| | | else |
| | | { |
| | | //离开 |
| | | direction = "leave"; |
| | | } |
| | | 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); |
| | | if (push) |
| | | { |
| | | ///添加到推送列表 |
| | | pushList.Add(new Push |
| | | { |
| | | homeId = HomeId, |
| | | userId = UserInfo.Current.ID, |
| | | userLogicId = logicDate.userLogicId, |
| | | sid = logicDate.sid, |
| | | arriveOnLeave = direction, |
| | | }); |
| | | } |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | catch { } |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// |
| | | /// 推送列表<这里数据已经推送过> |
| | | /// </summary> |
| | | private static List<Push> pushList = new List<Push>(); |
| | | |