Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_course
jingquan huang 6 years ago
commit a88f27af31

@ -45,12 +45,14 @@ gem 'rqrcode_png'
gem 'acts-as-taggable-on', '~> 6.0'
group :'development.rb.example', :test do
group :development, :test do
#group :'development.rb.example', :test do
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw]
gem 'rspec-rails', '~> 3.8'
end
group :'development.rb.example' do
group :development do
#group :'development.rb.example' do
gem 'awesome_print'
gem 'web-console', '>= 3.3.0'
gem 'listen', '>= 3.0.5', '< 3.2'

@ -16,4 +16,8 @@ module RenderHelper
render json: { status: 403, message: message }
# render status: 403, json: { errors: errors }
end
def render_unauthorized(message = I18n.t('error.unauthorized'))
render json: { status: 401, message: message }
end
end

@ -912,8 +912,8 @@ class CoursesController < ApplicationController
def left_banner
@user = current_user
@is_teacher = @user.teacher_of_course?(@course)
@course_modules = @course.course_modules.where.not(module_type: "activity").where(hidden: 0)
@is_teacher = @user_course_identity < Course::ASSISTANT_PROFESSOR
@course_modules = @course.course_modules.where(hidden: 0)
@hidden_modules = @course.course_modules.where(hidden: 1)
@second_category_type = ["shixun_homework", "graduation", "attachment", "board", "course_group"]
end

@ -94,7 +94,7 @@ class ExerciseAnswersController < ApplicationController
def get_exercise_question
@exercise_question = ExerciseQuestion.find_by_id(params[:exercise_question_id])
@exercise = @exercise_question.exercise.includes(:exercise_users)
@exercise = @exercise_question.exercise
@course = @exercise.course
@exercise_user = @exercise.exercise_users.find_by(user_id: current_user.id) #当前用户
@exercise_user_status = @exercise.get_exercise_status(current_user.id)

@ -53,8 +53,11 @@ class ExercisesController < ApplicationController
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting : []
else #已分班级的成员,可以查看统一设置和单独设置(试卷是发布在该班级)试卷
# 已发布 当前用户班级分组的 试卷id
exercise_settings_ids = @course.exercise_group_settings.exercise_group_published.where(course_group_id: member_group_id).pluck(:exercise_id).uniq
@exercises = member_show_exercises.present? ? member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids)) : []
exercise_settings_ids = @course.exercise_group_settings.exercise_group_published
.where(course_group_id: member_group_id).pluck(:exercise_id).uniq
@exercises = member_show_exercises.present? ?
member_show_exercises.unified_setting.or(member_show_exercises.where(id: exercise_settings_ids))
: []
end
else #用户未登陆或不是该课堂成员,仅显示统一设置的(已发布的/已截止的),如有公开,则不显示锁,不公开,则显示锁
@is_teacher_or = 0
@ -65,13 +68,20 @@ class ExercisesController < ApplicationController
choose_type = params[:type].to_i
member_group_id = @current_student.first.try(:course_group_id).to_i
if @is_teacher_or == 2 && member_group_id > 0
exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id).exercise_group_published
exercise_groups_sets = @course.exercise_group_settings.where(course_group_id: member_group_id)
.exercise_group_published
exercise_settings_ids = exercise_groups_sets.pluck(:exercise_id)
exercise_ended_ids = exercise_groups_sets.exercise_group_ended.pluck(:exercise_id).uniq
if choose_type == 2
@exercises = @exercises_all.present? ? @exercises_all.exercise_by_status(2).unified_setting.or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq)) : []
@exercises = @exercises_all.present? ?
@exercises_all.exercise_by_status(2).unified_setting
.or(@exercises_all.where(id: (exercise_settings_ids - exercise_ended_ids).uniq))
: []
elsif choose_type == 3
@exercises = @exercises_all.present? ? @exercises_all.exercise_by_status(3).unified_setting.or(@exercises_all.where(id: exercise_ended_ids)) : []
@exercises = @exercises_all.present? ?
@exercises_all.exercise_by_status(3).unified_setting
.or(@exercises_all.where(id: exercise_ended_ids))
: []
end
else
@exercises = @exercises.exercise_by_status(choose_type)
@ -412,7 +422,8 @@ class ExercisesController < ApplicationController
@user_permission = 2
@user_course_groups = @course.teacher_group(current_user.id) #当前老师的分班
@being_setting_course_ids = @exercise.common_published_ids(current_user.id) #当前用户已发布的班级的id
@user_published_setting = @exercise.exercise_group_settings.find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置
@user_published_setting = @exercise.exercise_group_settings
.find_in_exercise_group("course_group_id",@being_setting_course_ids) #当前用户已发布班级的试卷设置
exercise_ids = [@exercise.id]
@exercise_publish_count = get_user_permission_course(exercise_ids,2).count #判断当前用户是否有试卷已发布的分班,用于显示立即截止/撤销发布
@exercise_unpublish_count = get_user_permission_course(exercise_ids,1).count #判断当前用户是否有试卷未发布的分班,用户显示立即发布
@ -451,7 +462,7 @@ class ExercisesController < ApplicationController
# 统一设置或者分班为0则更新试卷并删除试卷分组
if unified_setting || (course_group_ids.size == 0)
params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time
params_publish_time = params[:publish_time].blank? ? nil : params[:publish_time].to_time
params_end_time = nil
if params[:end_time].blank?
if params_publish_time.present?
@ -507,10 +518,12 @@ class ExercisesController < ApplicationController
end
# exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil
exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在
if exercise_group.present? && exercise_group.first.end_time <= Time.now && (exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误
if exercise_group.present? && exercise_group.first.end_time <= Time.now &&
(exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误
error_count += 1
end
if exercise_group.present? && exercise_group.first.publish_time < Time.now && exercise_publish_time != exercise_group.first.publish_time
if exercise_group.present? && exercise_group.first.publish_time <
Time.now && exercise_publish_time != exercise_group.first.publish_time
error_count += 1
end
if error_count == 0
@ -692,7 +705,8 @@ class ExercisesController < ApplicationController
if exercise.unified_setting
ex_status = exercise.exercise_status #则为试卷的状态
else
ex_status = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",params[:group_ids]).exercise_group_not_published.present? ? 1 : 0
ex_status = exercise.exercise_group_settings.find_in_exercise_group("course_group_id",params[:group_ids])
.exercise_group_not_published.present? ? 1 : 0
end
if ex_status == 1 #如果试卷存在已发布的,或者是已截止的,那么则直接跳过
g_course = params[:group_ids] #表示是否传入分班参数,如果传入分班的参数,那么试卷的统一设置需修改
@ -891,11 +905,13 @@ class ExercisesController < ApplicationController
if exercise_user.present?
if exercise_user.commit_status == 1 && @exercise.get_exercise_status(current_user.id) == 2 #用户已提交且试卷提交中
if @exercise.time == -1 || ((Time.now.to_i - exercise_user.start_at.to_i) < @exercise.time.to_i * 60)
exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0, :objective_score => 0.0, :subjective_score => -1.0)
exercise_user.update_attributes(:score => nil, :end_at => nil, :status => nil, :commit_status => 0,
:objective_score => 0.0, :subjective_score => -1.0)
exercise_user.user.exercise_shixun_answers.search_shixun_answers("exercise_question_id",ex_question_ids).destroy_all
exercise_answers = exercise_user.user.exercise_answers.search_answer_users("exercise_question_id",ex_question_ids)
exercise_answers.update_all(:score => -1.0)
all_answer_comment = ExerciseAnswerComment.search_answer_comments("exercise_question_id",ex_question_ids).search_answer_comments("exercise_answer_id",exercise_answers.pluck(:id))
all_answer_comment = ExerciseAnswerComment.search_answer_comments("exercise_question_id",ex_question_ids)
.search_answer_comments("exercise_answer_id",exercise_answers.pluck(:id))
all_answer_comment.destroy_all
normal_status(0,"撤销回答成功")
else
@ -923,11 +939,13 @@ class ExercisesController < ApplicationController
if params[:realname].present?
search_name = params[:realname]
#搜索用户的nickname,如果存在则返回,否则继续查询用户的真实姓名或学生号
@exercise_users = @exercise_users.includes(:user).where("LOWER(concat(users.lastname, users.firstname)) like ?","%#{search_name}%")
@exercise_users = @exercise_users.includes(:user).where("LOWER(concat(users.lastname, users.firstname)) like ?",
"%#{search_name}%")
end
if params[:student_id].present?
search_st_id = params[:student_id].to_i
@exercise_users = @exercise_users.includes(user: [:user_extension]).where('user_extensions.student_id like ?',"%#{search_st_id}%")
@exercise_users = @exercise_users.includes(user: [:user_extension])
.where('user_extensions.student_id like ?',"%#{search_st_id}%")
end
sort = params[:sort] ? params[:sort] : "asc"
@exercise_users = @exercise_users.order("score #{sort}")
@ -962,8 +980,10 @@ class ExercisesController < ApplicationController
redo_exercise_users = @exercise_users.exercise_commit_users(user_ids)
redo_exercise_users.update_all(redo_option)
exercise_question_ids = @exercise.exercise_questions.pluck(:id).uniq
ExerciseAnswer.search_answer_users("user_id",user_ids).search_answer_users("exercise_question_id",exercise_question_ids).destroy_all
ExerciseShixunAnswer.search_shixun_answers("user_id",user_ids).search_shixun_answers("exercise_question_id",exercise_question_ids).destroy_all
ExerciseAnswer.search_answer_users("user_id",user_ids)
.search_answer_users("exercise_question_id",exercise_question_ids).destroy_all
ExerciseShixunAnswer.search_shixun_answers("user_id",user_ids)
.search_shixun_answers("exercise_question_id",exercise_question_ids).destroy_all
normal_status(0,"已成功打回重做!")
else
@ -1005,13 +1025,17 @@ class ExercisesController < ApplicationController
@t_user_exercise_status = @exercise.get_exercise_status(current_user.id)
if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || (@exercise_user_current.present? && @exercise_user_current.commit_status == 1)
if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) ||
(@exercise_user_current.present? && @exercise_user_current.commit_status == 1)
@user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑
else
@user_exercise_status = 0 #可编辑
end
@exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,:exercise_shixun_answers,:exercise_answers,:exercise_standard_answers)
@exercise_questions = @exercise.exercise_questions.includes(:exercise_shixun_challenges,
:exercise_shixun_answers,
:exercise_answers,
:exercise_standard_answers)
if @exercise.question_random
@exercise_questions = @exercise_questions.order("RAND()")
@ -1266,7 +1290,8 @@ class ExercisesController < ApplicationController
tip_exception(403,"无权限操作")
else
get_export_users(@exercise,@course,@export_ex_users)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @exercise.exercise_name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
exercise_export_name =
"#{current_user.real_name}_#{@course.name}_#{@exercise.exercise_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns}
end
}
@ -1426,7 +1451,8 @@ class ExercisesController < ApplicationController
def validates_exercise_params
normal_status(-1, "试卷标题不能为空!") if params[:exercise_name].blank?
normal_status(-1, "试卷标题不能超过60个字符") if (params[:exercise_name].length > 60)
normal_status(-1, "试卷须知不能超过100个字符") if (params[:exercise_description].present? && params[:exercise_description].length > 100)
normal_status(-1, "试卷须知不能超过100个字符") if (params[:exercise_description].present? &&
params[:exercise_description].length > 100)
end
#判断设置的时间是否合理
@ -1619,7 +1645,8 @@ class ExercisesController < ApplicationController
@exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id).first #查找当前用户是否有过答题
if @user_course_identity == Course::STUDENT
if @exercise_user_current.present?
if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) && ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) &&
((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
#当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
objective_score = calculate_student_score(@exercise,current_user)[:total_score]
subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score
@ -1669,7 +1696,8 @@ class ExercisesController < ApplicationController
def check_exercise_public
if @user_course_identity > Course::ASSISTANT_PROFESSOR #当前为学生,试卷公开统计,且已截止,且已提交
ex_user = @exercise.exercise_users.exercise_commit_users(current_user.id).first
unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 && @exercise.show_statistic
unless @exercise.get_exercise_status(current_user.id) == 3 && ex_user.present? && ex_user.commit_status == 1 &&
@exercise.show_statistic
normal_status(-1,"学生暂不能查看")
end
end

@ -109,8 +109,8 @@ class GraduationTasksController < ApplicationController
end
# 排序
rorder = params[:order] || "updated_at"
b_order = params[:b_order] || "desc"
rorder = params[:order].blank? ? "updated_at" : params[:order]
b_order = params[:b_order].blank? ? "desc" : params[:b_order]
if rorder == "created_at" || rorder == "work_score"
@work_list = @work_list.order("graduation_works.#{rorder} #{b_order}")
elsif rorder == "student_id"

@ -582,6 +582,9 @@ class StudentWorksController < ApplicationController
score_appeal.tidings.update_all(status: 1)
if params[:status].to_i == 3
# 申诉成功后该评分失效
score.update_attributes(is_invalid: 1)
# 申诉成功后 扣匿评学生的违规匿评扣分
sw = @homework.student_works.find_by(user_id: score.user_id)
sw.update_attribute("appeal_penalty", @homework.homework_detail_manual.appeal_penalty + sw.appeal_penalty) if sw.present?

@ -1,4 +1,5 @@
class TrialAppliesController < ApplicationController
before_action :require_user_login
def create
Users::ApplyTrailService.call(current_user, create_params)
@ -12,4 +13,10 @@ class TrialAppliesController < ApplicationController
def create_params
params.permit(:phone, :code, :reason).merge(remote_ip: request.remote_ip)
end
def require_user_login
return if User.current.logged?
render_unauthorized
end
end

@ -326,9 +326,9 @@ module ExercisesHelper
if exercise_status == 2 && exercise_end_time.present?
ex_left_time = how_much_time(exercise_end_time)
elsif exercise_status == 3 && course.end_date.present?
ex_left_time = how_much_time(course.end_date.to_time)
else
# elsif exercise_status == 3 && course.end_date.present?
# ex_left_time = how_much_time(course.end_date.to_time)
else #已截止后不显示时间
ex_left_time = nil
end

@ -41,7 +41,7 @@ module StudentWorksHelper
def student_efficiency(homework_common, work)
myshixun_ids = homework_common.student_works.pluck(:myshixun_id)
myshixuns = Myshixun.where(id: myshixun_ids).includes(games: [:outputs])
myshixuns = Myshixun.where(id: myshixun_ids).includes(:games)
#student_works_user_id = homework_common.student_works.pluck(:user_id).uniq
#shixun = homework_common.shixuns.first
#logger.info("#########shixun_id: ###{shixun.id}")
@ -54,13 +54,13 @@ module StudentWorksHelper
objects =
myshixuns.map do |myshixun|
# 评测次数
evaluate_count = myshixun.games.inject(0) {|sum, g| sum + g.outputs.pluck(:query_index).first.to_i}
evaluate_count = myshixun.games.sum(:evaluate_count)
# 获取最大评测次数
max_evaluate_count = (evaluate_count > max_evaluate_count ? evaluate_count : max_evaluate_count)
# 通关耗时
pass_consume_time = (myshixun.games.where(status: 2).pluck(:cost_time).sum / 60.0)
# 总耗时
all_time = (myshixun.games.pluck(:cost_time).sum / 60.0)
all_time = (myshixun.games.sum(:cost_time) / 60.0)
# 通关得分
user_total_score = myshixun.total_score.to_i
# 耗时,保留2位小数

@ -7,7 +7,7 @@ class Course < ApplicationRecord
has_many :course_infos, dependent: :destroy
# 课堂左侧导航栏的模块
has_many :course_modules, -> {where hidden: 0}, dependent: :destroy
has_many :course_modules, dependent: :destroy
has_many :board_course_modules, -> { board_module }, class_name: "CourseModule"
has_many :attachment_course_modules, -> { attachment_module }, class_name: "CourseModule"
has_many :common_course_modules, -> { common_homework_module }, class_name: "CourseModule"

@ -7,6 +7,7 @@ class CourseModule < ApplicationRecord
validates :module_name, length: { maximum: 20 }
scope :not_hidden, -> { where(hidden: 0) }
scope :graduation_module, -> { where(module_type: "graduation") }
scope :graduation_module_not_hidden, -> { graduation_module.where(hidden: 0) }
scope :board_module, -> { where(module_type: 'board') }

@ -119,6 +119,7 @@ class Exercise < ApplicationRecord
else
status = exercise_status
end
Rails.logger.info("#################__________status___________####################{status}")
status
end

@ -241,7 +241,7 @@ p{
position: absolute;
display: inline-block;
bottom: 9px;
left: 0;
left: 1px;
}
table{
width:100%;

@ -12,7 +12,7 @@ json.courses do
json.is_public course.is_public
json.is_accessible course.is_public == 1 || @user.course_identity(course) < Course::NORMAL
json.is_end course.is_end
json.first_category_url module_url(course.course_modules.first, course)
json.first_category_url module_url(course.course_modules.not_hidden.first, course)
end
end
json.courses_count @courses_count

@ -4,7 +4,7 @@ json.members_count course.members_count
json.homework_commons_count course.homework_commons_count
json.attachments_count course.attachments.count
json.first_category_url module_url(course.course_modules.where.not(module_type: "activity").where(hidden: 0).order(position: :desc).first, course)
json.first_category_url module_url(course.course_modules.where(hidden: 0).order(position: :desc).first, course)
json.is_public course.is_public
json.can_visited observed_logged_user? || course.can_visited?

@ -1,4 +1,5 @@
en:
error:
record_not_found: Record not found
forbidden: Forbidden
forbidden: Forbidden
unauthorized: Unauthorized

@ -1,4 +1,5 @@
'zh-CN':
error:
record_not_found: 您访问的页面不存在或已被删除
forbidden: 您没有权限进行该操作
forbidden: 您没有权限进行该操作
unauthorized: 未登录
Loading…
Cancel
Save