You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
educoder/app/queries/admins/shixun_query.rb

38 lines
909 B

class Admins::ShiXunQuery < ApplicationQuery
include CustomSortable
attr_reader :params
sort_columns :updated_at, default_by: :updated_at, default_direction: :desc
def initialize(params)
@params = params
end
def call
status =
case params[:status]
when "editing" then [0]
when "pending" then [1]
when "processed" then [2]
else
[0,1,2]
end
applies = LibraryApply.where(status: status) if status.present?
look_name = params[:look_name]
if look_name.present?
applies = applies.where()
end
# 关键字模糊查询
keyword = params[:keyword].to_s.strip
if keyword.present?
applies = applies.joins(:library)
.where('title LIKE :keyword OR uuid LIKE :keyword', keyword: "%#{keyword}%")
end
custom_sort(applies, params[:sort_by], params[:sort_direction])
end
end