好大学代码问题

pre_develop
daiao 6 years ago
parent e662286174
commit d56728da62

@ -7,10 +7,12 @@ class CnmoocsService
limit = params[:pageSize] || 16 limit = params[:pageSize] || 16
offset = page * limit.to_i offset = page * limit.to_i
shixuns = Shixun.select([:id, :identifier, :name, :myshixuns_count, :averge_star, :challenges_count, :trainee]). shixuns = Shixun.select([:id, :identifier, :name, :myshixuns_count, :averge_star, :challenges_count, :trainee]).
where(status: 0, hidden: 0).order("myshixun_count desc") where(status: 0, hidden: 0)
shixun_count = shixuns.count shixun_count = shixuns.count
pageCount = ((shixun_count / limit.to_f) == (shixun_count / limit)) ? (shixun_count / limit) : ((shixun_count / limit) + 1) pageCount = ((shixun_count / limit.to_f) == (shixun_count / limit)) ? (shixun_count / limit) : ((shixun_count / limit) + 1)
shixuns = shixuns.offset(offset).limit(limit) Rails.logger.info("#####{pageCount}")
Rails.logger.info("#####{limit}")
shixuns = shixuns.order("myshixuns_count desc").offset(offset).limit(limit)
shixun_list = shixun_data shixuns shixun_list = shixun_data shixuns
{error: 0, messages: "请求成功", {error: 0, messages: "请求成功",
page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount}, page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount},
@ -22,10 +24,10 @@ class CnmoocsService
limit = params[:pageSize] || 16 limit = params[:pageSize] || 16
offset = page * limit.to_i offset = page * limit.to_i
shixuns = Shixun.select([:id, :identifier, :name, :myshixuns_count, :averge_star, :challenges_count, :trainee]). shixuns = Shixun.select([:id, :identifier, :name, :myshixuns_count, :averge_star, :challenges_count, :trainee]).
where(status: 2, hidden: 0).where("name like ?", "%#{params[:name]}%").offset(offset).limit(limit) where(status: 2, hidden: 0).where("name like ?", "%#{params[:name]}%")
shixun_count = shixuns.count shixun_count = shixuns.count
pageCount = ((shixun_count / limit.to_f) == (shixun_count / limit)) ? (shixun_count / limit) : ((shixun_count / limit) + 1) pageCount = ((shixun_count / limit.to_f) == (shixun_count / limit)) ? (shixun_count / limit) : ((shixun_count / limit) + 1)
shixuns = shixuns.offset(offset).limit(limit) shixuns = shixuns.order("myshixuns_count desc").offset(offset).limit(limit)
shixun_list = shixun_data shixuns shixun_list = shixun_data shixuns
{error: 0, messages: "请求成功", {error: 0, messages: "请求成功",
page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount}, page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount},
@ -69,7 +71,7 @@ class CnmoocsService
private private
def shixun_data shixuns def shixun_data shixuns
shixun_list = [] shixun_list = []
shixuns.includes(:tag_repertoires).find_each do |shixun| shixuns.includes(:tag_repertoires).each do |shixun|
tag_name = shixun.tag_repertoires.first.try(:name) tag_name = shixun.tag_repertoires.first.try(:name)
level = %W(初级 中级 高级 顶级)[shixun.trainee - 1] level = %W(初级 中级 高级 顶级)[shixun.trainee - 1]
shixun_list << {identifier: shixun.identifier, name: shixun.name, students_count: shixun.myshixuns_count, shixun_list << {identifier: shixun.identifier, name: shixun.name, students_count: shixun.myshixuns_count,

Loading…
Cancel
Save