fix error

This commit is contained in:
邱博亞 2022-01-03 21:53:41 +08:00
parent 919025b9b7
commit d324d141d0
2 changed files with 15 additions and 5 deletions

View File

@ -48,12 +48,15 @@ private
cache = RulingBusCache.where(bus_info_id: bus_info_id).first cache = RulingBusCache.where(bus_info_id: bus_info_id).first
if (cache.nil? || cache.updated_at < @time_thresh) if (cache.nil? || cache.updated_at < @time_thresh)
tmp = RulingBusesHelper.get_stop_time(bus_info,@bus_locale) tmp = RulingBusesHelper.get_stop_time(bus_info,@bus_locale)
if !tmp.nil?
if cache.nil? if cache.nil?
RulingBusCache.create(dict: tmp, bus_info_id: bus_info_id) RulingBusCache.create(dict: tmp, bus_info_id: bus_info_id)
else else
cache.update_attributes(dict: tmp) cache.update_attributes(dict: tmp, updated_at: Time.now)
end
else
tmp = cache.dict
end end
tmp
else else
tmp = cache.dict tmp = cache.dict
end end

View File

@ -126,6 +126,9 @@ module RulingBusesHelper
end.join(' or ') end.join(' or ')
url = "/Bus/EstimatedTimeOfArrival/City/#{city}?$select=Direction,RouteName,NextBusTime&$filter=#{filters}&$format=JSON&$orderby=RouteName/#{locale}" url = "/Bus/EstimatedTimeOfArrival/City/#{city}?$select=Direction,RouteName,NextBusTime&$filter=#{filters}&$format=JSON&$orderby=RouteName/#{locale}"
bus_data = JSON.parse(self.get(url).body) bus_data = JSON.parse(self.get(url).body)
if bus_data.class==Hash
return nil
end
if !cache_data_pbus.blank? if !cache_data_pbus.blank?
filters = cache_data_pbus.map do |k,v| filters = cache_data_pbus.map do |k,v|
("((StopName/#{locale} eq '#{k[0][locale]}') and Direction eq #{k[2]} and " + ("((StopName/#{locale} eq '#{k[0][locale]}') and Direction eq #{k[2]} and " +
@ -136,8 +139,12 @@ module RulingBusesHelper
else else
pbus_data = [] pbus_data = []
end end
if pbus_data.class==Hash
bus_data
else
bus_data + pbus_data bus_data + pbus_data
end end
end
def get_input_name def get_input_name
"ruling_bus_info" "ruling_bus_info"