示例#1
0
        public async void OrderOnTheWay(List <location> locationsOrder, List <location> locationsAcceptOrder, List <Order> orders, SqlCoommandTaxiApi sqlCoommandTaxiApi, bool isNew = true, OrderMobile orderMobile = null)
        {
            if (connectorApiMaps == null)
            {
                connectorApiMaps        = new ConnectorApiMaps();
                this.sqlCoommandTaxiApi = sqlCoommandTaxiApi;
            }
            int numberOfSeats = 4;

            orderMobile = new OrderMobile();
            orderMobile.OnePointForAddressOrders = new List <OnePointForAddressOrder>();
            orderMobile.Status = "New";
            Order order = orders.Find(o => o.ID.ToString() == locationsAcceptOrder[1].ID);

            orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order.ID, locationsAcceptOrder[1].lat, locationsAcceptOrder[1].lng, order.TimeOfPickup, order.Date, "Start", order.FromAddress));
            orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order.ID, locationsAcceptOrder[1].latE, locationsAcceptOrder[1].lngE, order.TimeOfAppointment, order.Date, "End", order.ToAddress));
            orderMobile.Orders   = new List <Order>();
            orderMobile.IdDriver = locationsAcceptOrder[0].ID;
            orderMobile.Orders.Add(order);
            numberOfSeats -= orders.Find(o => o.ID.ToString() == locationsAcceptOrder[1].ID).CountCustomer;
            List <Steps> steps = connectorApiMaps.GetGetDirections($"{ConvertTOString(locationsAcceptOrder[1].lat)},{ConvertTOString(locationsAcceptOrder[1].lng)}", $"{ConvertTOString(locationsAcceptOrder[1].latE)},{ConvertTOString(locationsAcceptOrder[1].lngE)}");

            if (orderMobile.Orders == null)
            {
                orderMobile.Orders = new List <Order>();
            }
            if (numberOfSeats > 0)
            {
                for (int i = 0; i < locationsOrder.Count; i++)
                {
                    if (locationsOrder[i].CountCusstomer > numberOfSeats)
                    {
                        continue;
                    }
                    bool   isAddOrder      = true;
                    bool   isOnTheWay      = false;
                    int    positionS       = 0;
                    int    positionE       = 0;
                    bool   isOnTheWayStart = false;
                    double lat             = 0;
                    double lng             = 0;
                    double latF            = locationsOrder[i].lat;
                    double lngF            = locationsOrder[i].lng;
                    foreach (Steps step in steps)
                    {
                        if (locationsOrder[i].CountCusstomer > numberOfSeats)
                        {
                            break;
                        }
                        List <OnePointForAddressOrder> onePointForAddressOrders = new List <OnePointForAddressOrder>();
                        onePointForAddressOrders.AddRange(orderMobile.OnePointForAddressOrders);
                        double tmpLoc = Convert.ToDouble(step.end_location.lat - step.start_location.lat);
                        lat    = step.start_location.lat + tmpLoc;
                        tmpLoc = step.end_location.lng - step.start_location.lng;
                        lng    = step.start_location.lng + tmpLoc;
                        if ((latF - 0.013 < lat && lat + 0.013 > latF) &&
                            (lngF - 0.013 < lng && lng + 0.013 > lngF) && !isOnTheWayStart)
                        {
                            location locationNewS = new location(locationsOrder[i].lat, locationsOrder[i].lng);
                            location locationNewE = new location(locationsOrder[i].latE, locationsOrder[i].lngE);
                            GetPositionLocation(onePointForAddressOrders, locationNewS, locationsAcceptOrder[0], ref positionS);
                            Order order1 = orders.Find(o => o.ID.ToString() == locationsOrder[i].ID);
                            onePointForAddressOrders.Insert(positionS, new OnePointForAddressOrder(order1.ID, locationsOrder[i].lat, locationsOrder[i].lng, order1.TimeOfPickup, order1.Date, "Start", order1.FromAddress));
                            if (GetEndOrderOnTheWay(steps.GetRange(steps.IndexOf(step), (steps.Count - 1) - steps.IndexOf(step)), locationsOrder[i]))
                            {
                                GetPositionLocation(onePointForAddressOrders, locationNewE, locationsAcceptOrder[0], ref positionE);
                                onePointForAddressOrders.Insert(positionE, new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                            }
                            else
                            {
                                onePointForAddressOrders.Add(new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                                isOnTheWay = true;
                            }
                            int duration = connectorApiMaps.GetGetDuration($"{ConvertTOString(locationsAcceptOrder[0].lat)},{ConvertTOString(locationsAcceptOrder[0].lng)}", $"{ConvertTOString(onePointForAddressOrders[0].Lat)},{ConvertTOString(onePointForAddressOrders[0].Lng)}");
                            if (DateTime.Now.AddSeconds(duration).AddMinutes(-20) < DateTime.Parse($"{GetDFormat(onePointForAddressOrders[0].Date)} {onePointForAddressOrders[0].PTime}"))
                            {
                                for (int j = 1; j < onePointForAddressOrders.Count; j++)
                                {
                                    DateTime dateTime  = new DateTime();
                                    DateTime dateTime1 = new DateTime();
                                    int      duration1 = connectorApiMaps.GetGetDuration($"{ConvertTOString(onePointForAddressOrders[j - 1].Lat)},{ConvertTOString(onePointForAddressOrders[j - 1].Lng)}", $"{ConvertTOString(onePointForAddressOrders[j].Lat)},{ConvertTOString(onePointForAddressOrders[j].Lng)}");
                                    if (duration1 < 60 * 10)
                                    {
                                        continue;
                                    }
                                    if (onePointForAddressOrders[j - 1].Type == "Start")
                                    {
                                        dateTime = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j - 1].Date)} {onePointForAddressOrders[j - 1].PTime}");
                                    }
                                    else if (onePointForAddressOrders[j - 1].Type == "End")
                                    {
                                        var    date  = orders.Find(o => o.ID == onePointForAddressOrders[j - 1].IDorder);
                                        string date1 = date.TimeOfAppointment != null ? date.TimeOfAppointment : DateTime.Parse($"{GetDFormat(date.Date)} {date.TimeOfPickup}").AddSeconds(duration1).AddMinutes(30).ToShortTimeString();
                                        dateTime = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j - 1].Date)} {date1}");
                                    }
                                    if (onePointForAddressOrders[j].Type == "Start")
                                    {
                                        dateTime1 = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j].Date)} {onePointForAddressOrders[j].PTime}");
                                    }
                                    else if (onePointForAddressOrders[j].Type == "End")
                                    {
                                        var    date  = orders.Find(o => o.ID == onePointForAddressOrders[j].IDorder);
                                        string date1 = date.TimeOfAppointment != null ? date.TimeOfAppointment : DateTime.Parse($"{GetDFormat(date.Date)} {date.TimeOfPickup}").AddMinutes(90).ToShortTimeString();
                                        dateTime1 = DateTime.Parse($"{GetDFormat(onePointForAddressOrders[j].Date)} {date1}");
                                        onePointForAddressOrders[j].PTime = date1;
                                    }
                                    if (onePointForAddressOrders[j].Type == "Start" &&
                                        !(dateTime.AddSeconds(duration1) < dateTime1.AddMinutes(20) &&
                                          dateTime1.AddMinutes(-20) < dateTime.AddSeconds(duration1)))
                                    {
                                        isAddOrder = false;
                                        break;
                                    }
                                    else if (onePointForAddressOrders[j].Type == "End" &&
                                             !(dateTime.AddSeconds(duration1) < dateTime1))
                                    {
                                        isAddOrder = false;
                                        break;
                                    }
                                }
                                if (isAddOrder)
                                {
                                    break;
                                }
                            }
                            else
                            {
                                return;
                            }
                        }
                    }
                    if (isAddOrder)
                    {
                        Order order1 = orders.Find(o => o.ID.ToString() == locationsOrder[i].ID);
                        if (order1.CountCustomer <= numberOfSeats)
                        {
                            orderMobile.OnePointForAddressOrders.Insert(positionS, new OnePointForAddressOrder(order1.ID, locationsOrder[i].lat, locationsOrder[i].lng, order1.TimeOfPickup, order1.Date, "Start", order1.FromAddress));
                            if (isOnTheWay)
                            {
                                orderMobile.OnePointForAddressOrders.Add(new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                            }
                            else
                            {
                                orderMobile.OnePointForAddressOrders.Insert(positionE, new OnePointForAddressOrder(order1.ID, locationsOrder[i].latE, locationsOrder[i].lngE, order1.TimeOfAppointment, order1.Date, "End", order1.ToAddress));
                            }
                            orderMobile.Orders.Add(order1);
                            locationsOrder.Remove(locationsOrder.Find(l => l.ID == order1.ID.ToString()));
                            numberOfSeats -= order1.CountCustomer;
                        }
                    }
                }
                await sqlCoommandTaxiApi.SetOrederMobile(orderMobile, locationsAcceptOrder[0].ID, isNew);

                ManagerNotifyMobileApi managerNotifyMobileApi = new ManagerNotifyMobileApi();
                string tokenShope = sqlCoommandTaxiApi.GetTokenShope(orderMobile.IdDriver);
                if (isNew)
                {
                    managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", "New order for you", "System gave you a new order, The system gave you a new order, accept the order if possible, if you have no orders, accept the order within 5 minutes");
                }
                else
                {
                    managerNotifyMobileApi.SendNotyfyStatusPickup(tokenShope, "Order", "Next order for you", "your next order is created, it will be available after the completion of the current order");
                }
            }
        }
示例#2
0
 public void Execute()
 {
     sqlCoommandTaxiApi = new SqlCoommandTaxiApi();
     connectorApiMaps   = new ConnectorApiMaps();
     Task.Run(() => SetOrderForDrivers());
 }