From d56728da62240b50159773b858916cc4e70e1248 Mon Sep 17 00:00:00 2001 From: daiao <358551898@qq.com> Date: Mon, 27 May 2019 17:44:07 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A5=BD=E5=A4=A7=E5=AD=A6=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/services/cnmoocs_service.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/services/cnmoocs_service.rb b/app/services/cnmoocs_service.rb index 02e6d54b..fbb8d55c 100644 --- a/app/services/cnmoocs_service.rb +++ b/app/services/cnmoocs_service.rb @@ -7,10 +7,12 @@ class CnmoocsService limit = params[:pageSize] || 16 offset = page * limit.to_i 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 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 {error: 0, messages: "请求成功", page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount}, @@ -22,10 +24,10 @@ class CnmoocsService limit = params[:pageSize] || 16 offset = page * limit.to_i 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 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 {error: 0, messages: "请求成功", page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount}, @@ -69,7 +71,7 @@ class CnmoocsService private def shixun_data shixuns 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) level = %W(初级 中级 高级 顶级)[shixun.trainee - 1] shixun_list << {identifier: shixun.identifier, name: shixun.name, students_count: shixun.myshixuns_count,