NameL3ss

selected-stops

Apr 23rd, 2021
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.71 KB | None | 0 0
  1. route_ids = ::Planner::PlanSolution.find_by(id: plan_solution_id).try(:planner_routes).try(:pluck, :id)
  2. stop_ids = get_stops_ids(route_id)
  3. byebug
  4. route_stops = Planner::RouteStop.where(stop_id: stop_ids, planner_route_id: route_ids)
  5.  
  6. unassigned_stop_ids = stop_ids.map(&:to_i) - route_stops.pluck(:stop_id)
  7.  
  8. #unplanned_stop_ids.each do |u_stop|
  9. # ::Planner::RouteStop.new(
  10. # stop_id: u_stop
  11. # )
  12. #end
  13.  
  14. def index
  15. collection = collection_sort(collection_filter.preload(:entity_tags, tags: :tag_type)
  16. .active)
  17.  
  18. trucks = Trucks::TruckContextQuery.new(trucks: collection,
  19. start_place: collection_filters[:start_place],
  20. geolocated: collection_filters[:geolocated]).call
  21.  
  22. truck_contexts = TruckContext.where(truck_id: trucks.pluck(:id))
  23. serializer_options = { meta: { truck_ids: trucks.pluck(:id) } }
  24.  
  25. paginated = PaginationService.new(params, trucks)
  26. jsonapi_response(paginated, 200, serializer_options.merge(params: { truck_contexts: truck_contexts}))
  27. end
  28.  
  29. def index
  30. #stops = ::Planner::Plan.find(params[:planner_plan_id]).stop_groups.map(&:stops)
  31. stops = ::Planner::PlanStop.selected_stops_ids(plan_id: params['planner_plan_id'])
  32. stop_ids_not_selected = []
  33. stop_ids_selected = []
  34.  
  35. stops.each do |stop|
  36. elements = stop.last ? stop_ids_selected : stop_ids_not_selected
  37. elements << stop.first
  38. end
  39.  
  40. stop_ids = ::Planner::Plan.find(params[:planner_plan_id]).stop_groups.pluck(:id)
  41. data = Stop.eager_load([:stop_group, :contact, :delivery_times, :items, :plan_stops, :entity_tags, tags: %i[tag_type]])
  42. .select(fields_for_join)
  43. .joins(:plan_stops)
  44. .where(stop_group_id: stop_ids)
  45. .where.not(latitude: nil)
  46. .where.not(longitude: nil)
  47. .where('delivery_times.min_delivery_time >= ?', Time.zone.now.beginning_of_day)
  48. not_selected = ::Planner::Plan.find(params[:planner_plan_id]).stop_groups.map(&:stops).map(&:ids).flatten
  49. n_s = not_selected - ::Planner::Plan.find(params[:planner_plan_id]).stops.ids
  50. serializer_options = { meta: { stop_ids_not_selected: n_s, stop_ids_selected: stop_ids_not_selected } }
  51. #serializer_options = { meta: { stop_ids_not_selected: stop_ids_not_selected, stop_ids_selected: stop_ids_selected } }
  52. #byebug
  53. jsonapi_response(PaginationService.new(params, data), 200, serializer_options)
  54. end
Advertisement
Add Comment
Please, Sign In to add comment