Merge branch 'educoder' into develop

pre_develop
jingquan huang 6 years ago
commit b4d671be82

@ -3,60 +3,49 @@ class CnmoocsService
include GamesHelper
def get_resources_data params
page = params[:pageNo].to_i
limit = params[:pageSize] || 16
offset = page * limit.to_i
resources = []
if params[:level].to_s == "1"
subjects = Subject.find_by_sql("SELECT subjects.id, subjects.name, subjects.status, COUNT(myshixuns.id) AS myshixun_member_count
FROM myshixuns, stage_shixuns, subjects WHERE myshixuns.shixun_id = stage_shixuns.shixun_id
AND stage_shixuns.subject_id = subjects.id AND `subjects`.`hidden` = 0 AND `subjects`.`status` = 2
GROUP BY subjects.id ORDER BY myshixun_member_count DESC limit #{offset},#{limit}")
GROUP BY subjects.id ORDER BY myshixun_member_count DESC")
subjects.each do |subject|
resources << {resourceId: subject.id, parentId: nil, resourceName: subject.name, accessType: 0, nodeType: 0,
resourceType: 2}
end
totalCount = Subject.where(:status => 2, :hidden => 0).count
count = subjects.count
elsif params[:level].to_s == "2"
return {error: -1, messages: "请求二级及其更高目录时parentId不能为空"} if params[:parentId].blank?
stages = Stage.where(:subject_id => params[:parentId]).offset(offset).limit(limit)
stages = Stage.where(:subject_id => params[:parentId])
stages.each do |stage|
resources << {resourceId: stage.id, parentId: params[:parentId], resourceName: stage.name, accessType: 0, nodeType: 0,
resourceType: 2}
end
totalCount = Stage.where(:subject_id => params[:parentId]).count
count = stages.count
elsif params[:level].to_s == "3"
return {error: -1, messages: "请求二级及其更高目录时parentId不能为空"} if params[:parentId].blank?
shixun_ids = StageShixun.where(:stage_id => params[:parentId]).pluck(:shixun_id)
shixuns = Shixun.where(:id => shixun_ids).offset(offset).limit(limit)
shixuns = Shixun.where(:id => shixun_ids)
shixuns.each do |shixun|
resources << {resourceId: shixun.id, parentId: params[:parentId], resourceName: shixun.name, accessType: 2,
nodeType: 1, resourceType: 1}
end
totalCount = Shixun.where(:id => shixun_ids).count
count = shixuns.count
end
pageCount = ((totalCount / limit.to_f) == (totalCount / limit)) ? (totalCount / limit) : ((totalCount / limit) + 1)
{error: 0, messages: "请求成功",
page: {count: count, totalCount: totalCount, pageNo: page, pageSize: limit, pageCount: pageCount},
data: {resources: resources} }
end
def search_resources params
page = params[:pageNo].to_i
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]}%")
shixun_count = shixuns.count
pageCount = ((shixun_count / limit.to_f) == (shixun_count / limit)) ? (shixun_count / limit) : ((shixun_count / limit) + 1)
shixuns = shixuns.order("myshixuns_count desc").offset(offset).limit(limit)
shixuns = shixuns.order("myshixuns_count desc")
shixun_list = shixun_data shixuns
{error: 0, messages: "请求成功",
page: {count: shixuns.count, totalCount: shixun_count, pageNo: page, pageSize: limit, pageCount: pageCount},
data: shixun_list }
end

Loading…
Cancel
Save