dev_trainings
hjm 6 years ago
commit d7d6b220b6

@ -3,7 +3,7 @@
module Mobile
module Apis
class Cnmooc < Grape::API
before {cnmooc_access_key!}
# before {cnmooc_access_key!}
content_type :json, 'application/json;charset=UTF-8'
resources :cnmoocs do
@ -39,7 +39,7 @@ module Mobile
desc "获取资源访问地址"
params do
requires :userId, type: Integer, desc: "用户ID"
requires :resouceId, type: String, desc: "资源唯一标示"
requires :resourceId, type: String, desc: "资源唯一标示"
requires :accessType, type: Integer, desc: "资源类型"
end
get "source_url" do
@ -72,7 +72,7 @@ module Mobile
desc "资源学习情况查询"
params do
requires :userId, type: Integer, desc: "用户ID"
requires :resouceId, type: String, desc: "资源唯一标示"
requires :resourceId, type: String, desc: "资源唯一标示"
end
get 'get_students_data' do
CnmoocsService.new.get_students_data params

@ -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
@ -119,7 +108,7 @@ class CnmoocsService
if shixun.blank?
return { error: -1, messages: '资源不存在' }
end
{ error: 0, messages: '成功', accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}/challenges?authToken=#{token.value}" }
{ error: 0, messages: '成功', data: {accessUrl: "#{Redmine::Configuration['educoder_domain']}/shixuns/#{shixun.identifier}/challenges?authToken=#{token.value}" }}
end
def get_students_data params
@ -132,14 +121,12 @@ class CnmoocsService
myshixun.games.each do |game|
time += game.consumes_time_int
end
{error: 0, messages: '成功', data: {time: time, score: score * 10}}
{error: 0, messages: '成功', data: {experiment: {time: time, totalTime: score * 10}}}
else
{error: -1, messages: '用户还未开始学习此资源'}
end
end
private
def shixun_data shixuns
shixun_list = []

@ -533,6 +533,7 @@ class GamesService
# 更新评测次数
game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1))
shixun.increment!(:evaluate_count)
# 清空代码评测信息
msg = game.run_code_message
msg.update_attributes(:status => 0, :message => nil) if msg.present?
@ -693,6 +694,7 @@ class GamesService
:evaluate_count]).find_by_identifier(params[:identifier])
# 更新评测次数
game.update_column(:evaluate_count, (game.evaluate_count.to_i + 1))
game.challenge.shixun.increment!(:evaluate_count)
# 选择题如果通关了,则不让再评测
if game.status == 2

@ -52,7 +52,7 @@ module ZipService
members = exercise.course.members
exercise_users.each do |exercise_user|
member = members.where(:user_id => exercise_user.user_id).first
group_name = member.try(:course_group_id).to_i == 0 ? '未分班' : member.course_group.name
group_name = member.try(:course_group_id).to_i == 0 ? '未分班' : member.course_group.try(:name)
export_file_name = "#{group_name}-#{exercise.course_id}-#{exercise.exercise_name}-#{exercise_user.user.user_extensions.student_id}-#{exercise_user.user.show_real_name}" + ".pdf"
out_file = export_user_exercise(exercise, exercise_user, export_file_name)
file_name = File::expand_path(out_file)

@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><meta name="renderer" content="webkit"/><meta name="force-rendering" content="webkit"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>Educoder</title><script type="text/javascript">window.__isR=!0</script><link rel="stylesheet" href="/react/build/css/css_min_all.css"><link rel="stylesheet" href="/assets/iconfont/iconfont.css"><link href="/react/build/./static/css/main.e1b0d6a5.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="md_div" style="display:none"></div><div id="root" class="page -layout-v -fit"></div><div id="picture_display" style="display:none"></div><script type="text/javascript" src="/react/build/js/js_min_all.js"></script><script type="text/javascript" src="/assets/kindeditor/kindeditor.js"></script><script type="text/javascript" src="/react/build/js/create_kindeditor.js"></script><script type="text/javascript" src="/javascripts/educoder/edu_application.js"></script><script type="text/javascript" src="/react/build/./static/js/main.994eab16.js"></script></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no"><meta name="theme-color" content="#000000"><meta name="renderer" content="webkit"/><meta name="force-rendering" content="webkit"/><meta http-equiv="X-UA-Compatible" content="IE=edge"/><link rel="manifest" href="/manifest.json"><link rel="shortcut icon" href="/favicon.ico"><title>Educoder</title><script type="text/javascript">window.__isR=!0</script><link rel="stylesheet" href="/react/build/css/css_min_all.css"><link rel="stylesheet" href="/assets/iconfont/iconfont.css"><link href="/react/build/./static/css/main.e1b0d6a5.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="md_div" style="display:none"></div><div id="root" class="page -layout-v -fit"></div><div id="picture_display" style="display:none"></div><script type="text/javascript" src="/react/build/js/js_min_all.js"></script><script type="text/javascript" src="/assets/kindeditor/kindeditor.js"></script><script type="text/javascript" src="/react/build/js/create_kindeditor.js"></script><script type="text/javascript" src="/javascripts/educoder/edu_application.js"></script><script type="text/javascript" src="/react/build/./static/js/main.85df3a28.js"></script></body></html>
Loading…
Cancel
Save