Exemplo n.º 1
0
        public void IsInPolygonTest()
        {
            var point = new Location(22.409439, 113.735414);

            // 深圳市南山区
            var points = new List <Location>();

            points.Add(new Location(22.506303, 113.997266));
            points.Add(new Location(22.513987, 114.006482));
            points.Add(new Location(22.529682, 113.999479));
            points.Add(new Location(22.539055, 114.003994));
            points.Add(new Location(22.55302, 114.00266));
            points.Add(new Location(22.555931, 114.006308));
            points.Add(new Location(22.560939, 114.003886));
            points.Add(new Location(22.562909, 114.012577));
            points.Add(new Location(22.570114, 114.00892));
            points.Add(new Location(22.582217, 114.012039));
            points.Add(new Location(22.589529, 114.030786));
            points.Add(new Location(22.606064, 114.029787));
            points.Add(new Location(22.612017, 114.019419));
            points.Add(new Location(22.63413, 114.009938));
            points.Add(new Location(22.635255, 114.001227));
            points.Add(new Location(22.643759, 113.997029));
            points.Add(new Location(22.644023, 113.981667));
            points.Add(new Location(22.648414, 113.974815));
            points.Add(new Location(22.656977, 113.973232));
            points.Add(new Location(22.658642, 113.956087));
            points.Add(new Location(22.655666, 113.949057));
            points.Add(new Location(22.643623, 113.943025));
            points.Add(new Location(22.640058, 113.936492));
            points.Add(new Location(22.613872, 113.937102));
            points.Add(new Location(22.604535, 113.931339));
            points.Add(new Location(22.598716, 113.933979));
            points.Add(new Location(22.593551, 113.930993));
            points.Add(new Location(22.58658, 113.936156));
            points.Add(new Location(22.579901, 113.933197));
            points.Add(new Location(22.571698, 113.922604));
            points.Add(new Location(22.562977, 113.922503));
            points.Add(new Location(22.547586, 113.900917));
            points.Add(new Location(22.531673, 113.857115));
            points.Add(new Location(22.516216, 113.836299));
            points.Add(new Location(22.409449, 113.735253));
            points.Add(new Location(22.398465, 113.764399));
            points.Add(new Location(22.371004, 113.79039));
            points.Add(new Location(22.347731, 113.802364));
            points.Add(new Location(22.290004, 113.813838));
            points.Add(new Location(22.240159, 113.837116));
            points.Add(new Location(22.270685, 113.850441));
            points.Add(new Location(22.276198, 113.858777));
            points.Add(new Location(22.336642, 113.880412));
            points.Add(new Location(22.432119, 113.880408));
            points.Add(new Location(22.475107, 113.959233));
            points.Add(new Location(22.506303, 113.997266));

            Assert.True(LocationUtility.IsInPolygon(point, points));
        }
Exemplo n.º 2
0
        public static AssignOrderPushContent PushAddAssignOrderPushContent(long orderID)
        {
            using (var db = new DataContext())
            {
                var legworkOrder = db.Legwork_Order.Where(q => q.OrderID == orderID).FirstOrDefault();
                if (legworkOrder != null)
                {
                    var deliveryModel = GetAddress(legworkOrder.RequiredDeliveryAddressID);

                    #region 计算区域ID

                    var  listAreaID = db.Legwork_AreaConfig.Select(q => q.AreaID).ToArray();
                    bool result     = false;
                    int  AreaID     = 0;

                    foreach (var i in listAreaID)
                    {
                        //获取开通跑腿区域
                        var openAreas = db.Legwork_AreaConfig.Where(p => p.AreaID == i).Select(t => t.OpenAreas).FirstOrDefault().Split(',').Select(p => p.ToInt32());

                        if (!openAreas.HasValue())
                        {
                            return(null);
                        }

                        //获取区域经纬度
                        try
                        {
                            var listArea = db.System_Area.Where(q => openAreas.Contains(q.AreaID)).Select(t => t.Points).Select(p => Newtonsoft.Json.JsonConvert.DeserializeObject <List <List <AreaModel> > >(p));

                            if (!listArea.HasValue())
                            {
                                return(null);
                            }

                            foreach (var list1 in listArea)
                            {
                                foreach (var list2 in list1)
                                {
                                    result = LocationUtility.IsInPolygon(new Location(deliveryModel.Latitude, deliveryModel.Longitude), list2.Select(p => new Location(p.lat, p.lng)).ToList());

                                    if (result)
                                    {
                                        AreaID = i;
                                        break;
                                        ;
                                    }
                                }
                                if (result)
                                {
                                    break;
                                }
                            }
                            if (result)
                            {
                                break;
                            }
                        }
                        catch
                        {
                            continue;
                        }
                    }

                    #endregion

                    string PushCode = "";
                    var    userList = (from a in db.Worker_Account
                                       join b in db.Worker_BusinessRelation on a.WorkerID equals b.WorkerID
                                       where a.AccountStatus == (short)WorkerAccountStatus.Normal && a.WorkingState == (short)WorkingState.Enabled && a.DefaultAreaID == AreaID && b.AuditStatus == (int)WorkerBusinessAuditStatus.Passed && b.BusinessType == (int)BusinessType.LegworkService
                                       select new
                    {
                        a.PushCode
                    }).ToArray();

                    if (!userList.Any())
                    {
                        return(null);
                    }
                    foreach (var item in userList)
                    {
                        if (!string.IsNullOrWhiteSpace(item.PushCode))
                        {
                            PushCode += item.PushCode + ",";
                        }
                    }
                    AssignOrderPushContent assignOrder = new AssignOrderPushContent()
                    {
                        PushCode = PushCode.TrimEnd(new char[]
                        {
                            ','
                        }),
                        CreateTime = legworkOrder.SubmitTime,
                        OrderID    = legworkOrder.OrderID,
                        OrderType  = legworkOrder.OrderType,
                        OrderCode  = legworkOrder.OrderCode,
                    };

                    return(assignOrder);
                }
                return(null);
            }
        }