diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index b1e23071b..4b94676e5 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -107,7 +107,7 @@ class ExerciseAnswersController < ApplicationController normal_status(-1,"已提交/已结束的试卷不允许修改!") else if (@exercise_user_status == Exercise::DEADLINE && @exercise_user.commit_status == 0) || (@exercise.time > 0 && @exercise_user.start_at.present? && ((@exercise_user.start_at + @exercise.time.to_i.minutes) < Time.now)) - objective_score = calculate_student_score(@exercise,current_user)[:total_score] + objective_score = calculate_student_score(@exercise,current_user,Time.now)[:total_score] subjective_score = @exercise_user.subjective_score < 0.0 ? 0.0 : @exercise_user.subjective_score total_score = objective_score + subjective_score commit_option = { diff --git a/app/controllers/exercises_controller.rb b/app/controllers/exercises_controller.rb index 784bb9c9a..64215f78f 100644 --- a/app/controllers/exercises_controller.rb +++ b/app/controllers/exercises_controller.rb @@ -886,7 +886,7 @@ class ExercisesController < ApplicationController ex_user_ids = exercise_users.pluck(:id) - EndExerciseCalculateJob.perform_later(ex_user_ids,exercise) + EndExerciseCalculateJob.perform_later(ex_user_ids,exercise,Time.now) # exercise_users.each do |user| # if user.commit_status == 0 && user.start_at.present? # objective_score = calculate_student_score(exercise,user.user)[:total_score] @@ -1019,59 +1019,57 @@ class ExercisesController < ApplicationController #学生开始答题页面 def start_answer - ActiveRecord::Base.transaction do - begin - ex_users_current = ExerciseUser.where(user_id:@exercise_current_user_id,exercise_id:@exercise.id) #不能用@exercise.exercise_users,因为exercise_users删除时,只是状态改变,未删除 - @exercise_user_current = ex_users_current&.first - if ex_users_current.exists? - if @exercise_user_current.start_at.blank? - @exercise_user_current.update_attribute("start_at",Time.now) - end - else - if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建exercise_user表,理论上老师是不能进入答题的 - exercise_user_params = { - :user_id => @exercise_current_user_id, - :exercise_id => @exercise.id, - :start_at => Time.now - } - exercise_user_current = ExerciseUser.new(exercise_user_params) - exercise_user_current.save - end + begin + ex_users_current = ExerciseUser.where(user_id:@exercise_current_user_id,exercise_id:@exercise.id) #不能用@exercise.exercise_users,因为exercise_users删除时,只是状态改变,未删除 + @exercise_user_current = ex_users_current&.first + if ex_users_current.exists? + if @exercise_user_current.start_at.blank? + @exercise_user_current.update_attribute("start_at",Time.now) end - @t_user_exercise_status = @exercise.get_exercise_status(current_user) - - @user_left_time = nil - if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || - (ex_users_current.exists? && @exercise_user_current.commit_status == 1) - @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 - else - @user_left_time = get_exercise_left_time(@exercise,current_user) - @user_exercise_status = 0 #可编辑 + else + if @user_course_identity > Course::ASSISTANT_PROFESSOR #当为老师的时候,不创建exercise_user表,理论上老师是不能进入答题的 + exercise_user_params = { + :user_id => @exercise_current_user_id, + :exercise_id => @exercise.id, + :start_at => Time.now + } + exercise_user_current = ExerciseUser.new(exercise_user_params) + exercise_user_current.save end + end + @t_user_exercise_status = @exercise.get_exercise_status(current_user) - @exercise_questions = @exercise.exercise_questions - - if @exercise.question_random - @exercise_questions = @exercise_questions.order("RAND()") - else - @exercise_questions = @exercise_questions.order("question_number ASC") - end - # 判断问题是否已回答还是未回答 - @exercise_questions = @exercise_questions.includes(:exercise_shixun_challenges, - :exercise_shixun_answers, - :exercise_answers, - :exercise_standard_answers) + @user_left_time = nil + if @user_course_identity < Course::STUDENT || (@t_user_exercise_status == 3) || + (ex_users_current.exists? && @exercise_user_current.commit_status == 1) + @user_exercise_status = 1 #当前用户为老师/试卷已截止/试卷已提交不可编辑 + else + @user_left_time = get_exercise_left_time(@exercise,current_user) + @user_exercise_status = 0 #可编辑 + end - if @t_user_exercise_status == Exercise::DEADLINE - get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) - end - get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,@t_user_exercise_status) + @exercise_questions = @exercise.exercise_questions - rescue Exception => e - uid_logger_error(e.message) - tip_exception("页面调用失败!") - raise ActiveRecord::Rollback + if @exercise.question_random + @exercise_questions = @exercise_questions.order("RAND()") + else + @exercise_questions = @exercise_questions.order("question_number ASC") + end + # 判断问题是否已回答还是未回答 + @exercise_questions = @exercise_questions.includes(:exercise_shixun_challenges, + :exercise_shixun_answers, + :exercise_answers, + :exercise_standard_answers) + + if @t_user_exercise_status == Exercise::DEADLINE + get_each_student_exercise(@exercise.id,@exercise_questions,@exercise_current_user_id) end + get_user_answer_status(@exercise_questions,@exercise_current_user_id,@exercise,@t_user_exercise_status) + + rescue Exception => e + uid_logger_error(e.message) + tip_exception("页面调用失败!") + raise ActiveRecord::Rollback end end @@ -1125,6 +1123,7 @@ class ExercisesController < ApplicationController # 学生提交试卷 def commit_exercise + tip_exception(-1, "试卷已提交") if @answer_committed_user.commit_status == 1 ActiveRecord::Base.transaction do begin can_commit_exercise = false @@ -1140,7 +1139,7 @@ class ExercisesController < ApplicationController can_commit_exercise = true end if can_commit_exercise - objective_score = calculate_student_score(@exercise,current_user)[:total_score] + objective_score = calculate_student_score(@exercise,current_user,Time.now)[:total_score] subjective_score = @answer_committed_user.subjective_score total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score total_score = objective_score + total_score_subjective_score @@ -1204,7 +1203,6 @@ class ExercisesController < ApplicationController #答题列表 def exercise_lists - ActiveRecord::Base.transaction do begin @current_user_id = current_user.id exercise_ids = [@exercise.id] @@ -1278,81 +1276,80 @@ class ExercisesController < ApplicationController if params[:review].present? review_type = params[:review].first.to_i #已评,则数据为1,未评,则数据为0,前端传过来的为数组 if review_type == 1 - @exercise_users_list = teacher_reviews - else - @exercise_users_list = teacher_unreviews - end + @exercise_users_list = teacher_reviews + else + @exercise_users_list = teacher_unreviews end + end - #答题状态的选择 - if params[:commit_status].present? - choose_type = params[:commit_status] - @exercise_users_list = @exercise_users_list.commit_exercise_by_status(choose_type) - end + #答题状态的选择 + if params[:commit_status].present? + choose_type = params[:commit_status] + @exercise_users_list = @exercise_users_list.commit_exercise_by_status(choose_type) + end - #班级的选择 - if params[:exercise_group_id].present? - group_id = params[:exercise_group_id] - exercise_students = @course_all_members.course_find_by_ids("course_group_id",group_id) #试卷所分班的全部人数 - user_ids = exercise_students.pluck(:user_id).reject(&:blank?) - @exercise_users_list = @exercise_users_list.exercise_commit_users(user_ids) - end + #班级的选择 + if params[:exercise_group_id].present? + group_id = params[:exercise_group_id] + exercise_students = @course_all_members.course_find_by_ids("course_group_id",group_id) #试卷所分班的全部人数 + user_ids = exercise_students.pluck(:user_id).reject(&:blank?) + @exercise_users_list = @exercise_users_list.exercise_commit_users(user_ids) + end - #搜索 - if params[:search].present? - @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") - end + #搜索 + if params[:search].present? + @exercise_users_list = @exercise_users_list.joins(user: :user_extension).where("CONCAT(lastname, firstname) like ? OR student_id like ?", "%#{params[:search]}%", "%#{params[:search]}%") + end - exercise_user_joins = @exercise_users_list.joins(user: :user_extension) + exercise_user_joins = @exercise_users_list.joins(user: :user_extension) - if order == "student_id" - @exercise_users_list = exercise_user_joins.order("user_extensions.student_id #{order_type}") - elsif order == "score" - @exercise_users_list = exercise_user_joins.order("#{order} #{order_type}") - else - @exercise_users_list = exercise_user_joins.order("end_at #{order_type}, start_at #{order_type}") - end + if order == "student_id" + @exercise_users_list = exercise_user_joins.order("user_extensions.student_id #{order_type}") + elsif order == "score" + @exercise_users_list = exercise_user_joins.order("#{order} #{order_type}") + else + @exercise_users_list = exercise_user_joins.order("end_at #{order_type}, start_at #{order_type}") + end - @export_ex_users = @exercise_users_list + @export_ex_users = @exercise_users_list - @exercise_users_size = @exercise_users_list.size + @exercise_users_size = @exercise_users_list.size - # 分页 - @page = params[:page] || 1 - @limit = params[:limit] || 20 - @exercise_users_list = @exercise_users_list.page(@page).per(@limit) - else - @exercise_users_list = [] - @export_ex_users = @exercise_users_list - @exercise_users_size = 0 - end + # 分页 + @page = params[:page] || 1 + @limit = params[:limit] || 20 + @exercise_users_list = @exercise_users_list.page(@page).per(@limit) + else + @exercise_users_list = [] + @export_ex_users = @exercise_users_list + @exercise_users_size = 0 + end - if params[:format] == "xlsx" - if @user_course_identity > Course::ASSISTANT_PROFESSOR - tip_exception(403,"无权限操作") - elsif @exercise_status == Exercise::UNPUBLISHED - normal_status(-1,"试卷未发布") - elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) - normal_status(-1,"暂无用户提交") - elsif params[:export].present? && params[:export] - normal_status(0,"正在下载中") - else - respond_to do |format| - format.xlsx{ - set_export_cookies - 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')}" - render xlsx: "#{exercise_export_name_.strip}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} - } - end + if params[:format] == "xlsx" + if @user_course_identity > Course::ASSISTANT_PROFESSOR + tip_exception(403,"无权限操作") + elsif @exercise_status == Exercise::UNPUBLISHED + normal_status(-1,"试卷未发布") + elsif (@exercise_users_size == 0) || ( @export_ex_users&.exercise_user_committed.size == 0) + normal_status(-1,"暂无用户提交") + elsif params[:export].present? && params[:export] + normal_status(0,"正在下载中") + else + respond_to do |format| + format.xlsx{ + set_export_cookies + 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')}" + render xlsx: "#{exercise_export_name_.strip}",template: "exercises/exercise_lists.xlsx.axlsx",locals: {table_columns:@table_columns,exercise_users:@user_columns} + } end end - rescue Exception => e - uid_logger_error(e.message) - tip_exception(e.message) - raise ActiveRecord::Rollback end + rescue Exception => e + uid_logger_error(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback end end @@ -1391,101 +1388,99 @@ class ExercisesController < ApplicationController #学生的统计结果 def exercise_result - ActiveRecord::Base.transaction do - begin - exercise_ids = [@exercise.id] - @exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).size #判断是否有已发布的分班 - @exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).size #判断是否有未发布的分班 - @course_all_members = @course.students #课堂的全部学生 - @exercise_all_users = @exercise.exercise_users - ex_common_ids = @exercise.common_published_ids(current_user.id) - @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) - - #班级的选择 - if params[:exercise_group_id].present? - group_id = params[:exercise_group_id] - exercise_students = @course_all_members.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 - user_ids = exercise_students.pluck(:user_id).reject(&:blank?) - @exercise_all_users = @exercise.exercise_users.exercise_commit_users(user_ids) - @course_all_members_count = @exercise_all_users.size - else - @exercise_users_list = @exercise.all_exercise_users(current_user.id) - @course_all_members_count = @exercise_users_list.size - end - @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 - @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id - @exercise_commit_user_counts = @exercise_commit_users.size #试卷的已提交用户人数 - @exercise_status = @exercise.get_exercise_status(current_user) - - #提交率 - if @course_all_members_count == 0 - commit_percent = 0.00 - min_score = 0.0 - max_score = 0.0 - average_score = 0.0 - fail_counts = 0 - pass_counts = 0 - good_counts = 0 - best_counts = 0 - else - commit_percent = (@exercise_commit_user_counts / @course_all_members_count.to_f).round(3) - exercise_scores = @exercise_commit_users.pluck(:score).reject(&:blank?) - min_score = exercise_scores.min.present? ? exercise_scores.min : 0.0 - max_score = exercise_scores.max.present? ? exercise_scores.max : 0.0 - total_score = exercise_scores.sum.present? ? exercise_scores.sum : 0.0 - average_score = @exercise_commit_user_counts > 0 ? (total_score.round(1) / @exercise_commit_user_counts).round(1) : 0.0 - question_scores = @exercise.question_scores - fail_score = question_scores * 0.6.round(2) - pass_score = question_scores * 0.7.round(2) - good_score = question_scores * 0.9.round(2) - - fail_counts = exercise_scores.count{|a| a < fail_score} - pass_counts = exercise_scores.count{|a| a < pass_score && a >= fail_score} - good_counts = exercise_scores.count{|a| a < good_score && a >= pass_score} - best_counts = exercise_scores.count{|a| a >= good_score && a <= question_scores} - end - @counts_array = { - :commit_percent => commit_percent, - :min_score => min_score.to_s, - :max_score => max_score.to_s, - :average_score => average_score.to_s, - :fail_counts => fail_counts, - :pass_counts => pass_counts, - :good_counts => good_counts, - :best_counts => best_counts, - } - - @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers) + begin + exercise_ids = [@exercise.id] + @exercise_publish_count = get_user_permission_course(exercise_ids,Exercise::PUBLISHED).size #判断是否有已发布的分班 + @exercise_unpublish_count = get_user_permission_course(exercise_ids,Exercise::UNPUBLISHED).size #判断是否有未发布的分班 + @course_all_members = @course.students #课堂的全部学生 + @exercise_all_users = @exercise.exercise_users + ex_common_ids = @exercise.common_published_ids(current_user.id) + @exercise_course_groups = @course.get_ex_published_course(ex_common_ids) + + #班级的选择 + if params[:exercise_group_id].present? + group_id = params[:exercise_group_id] + exercise_students = @course_all_members.course_find_by_ids("course_group_id",group_id) # 试卷所分班的全部人数 + user_ids = exercise_students.pluck(:user_id).reject(&:blank?) + @exercise_all_users = @exercise.exercise_users.exercise_commit_users(user_ids) + @course_all_members_count = @exercise_all_users.size + else + @exercise_users_list = @exercise.all_exercise_users(current_user.id) + @course_all_members_count = @exercise_users_list.size + end + @exercise_commit_users = @exercise_all_users.commit_exercise_by_status(1) #试卷的已提交用户 + @exercise_commit_user_ids = @exercise_commit_users.pluck(:user_id).uniq #已提交试卷的全部用户id + @exercise_commit_user_counts = @exercise_commit_users.size #试卷的已提交用户人数 + @exercise_status = @exercise.get_exercise_status(current_user) + + #提交率 + if @course_all_members_count == 0 + commit_percent = 0.00 + min_score = 0.0 + max_score = 0.0 + average_score = 0.0 + fail_counts = 0 + pass_counts = 0 + good_counts = 0 + best_counts = 0 + else + commit_percent = (@exercise_commit_user_counts / @course_all_members_count.to_f).round(3) + exercise_scores = @exercise_commit_users.pluck(:score).reject(&:blank?) + min_score = exercise_scores.min.present? ? exercise_scores.min : 0.0 + max_score = exercise_scores.max.present? ? exercise_scores.max : 0.0 + total_score = exercise_scores.sum.present? ? exercise_scores.sum : 0.0 + average_score = @exercise_commit_user_counts > 0 ? (total_score.round(1) / @exercise_commit_user_counts).round(1) : 0.0 + question_scores = @exercise.question_scores + fail_score = question_scores * 0.6.round(2) + pass_score = question_scores * 0.7.round(2) + good_score = question_scores * 0.9.round(2) + + fail_counts = exercise_scores.count{|a| a < fail_score} + pass_counts = exercise_scores.count{|a| a < pass_score && a >= fail_score} + good_counts = exercise_scores.count{|a| a < good_score && a >= pass_score} + best_counts = exercise_scores.count{|a| a >= good_score && a <= question_scores} + end + @counts_array = { + :commit_percent => commit_percent, + :min_score => min_score.to_s, + :max_score => max_score.to_s, + :average_score => average_score.to_s, + :fail_counts => fail_counts, + :pass_counts => pass_counts, + :good_counts => good_counts, + :best_counts => best_counts, + } - percent_sort = "desc" + @exercise_questions = @exercise.exercise_questions&.includes(:exercise_choices,:exercise_answers,:exercise_standard_answers,:exercise_shixun_challenges,:exercise_shixun_answers) - if params[:sort].present? - percent_sort = params[:sort] - end - # @paging_type = "percent" - # # 按题型排序 - # if params[:sort].present? - # @paging_type = params[:sort].to_s - # end + percent_sort = "desc" - ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) + if params[:sort].present? + percent_sort = params[:sort] + end + # @paging_type = "percent" + # # 按题型排序 + # if params[:sort].present? + # @paging_type = params[:sort].to_s + # end - #默认降序排列 - if percent_sort == "desc" - @question_result_hash = ques_result_all.sort_by{|s| s[:percent]}.reverse - else - @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} - end + ques_result_all = exercise_commit_result(@exercise_questions,@exercise_commit_user_ids) - @exercise_questions_count = @exercise_questions.size - @page = params[:page] || 1 - @limit = params[:limit] || 10 - @question_result_hash = Kaminari.paginate_array(@question_result_hash).page(@page).per(@limit) - rescue Exception => e - uid_logger_error(e.message) - tip_exception("没有权限") - raise ActiveRecord::Rollback + #默认降序排列 + if percent_sort == "desc" + @question_result_hash = ques_result_all.sort_by{|s| s[:percent]}.reverse + else + @question_result_hash = ques_result_all.sort_by{|s| s[:percent]} end + + @exercise_questions_count = @exercise_questions.size + @page = params[:page] || 1 + @limit = params[:limit] || 10 + @question_result_hash = Kaminari.paginate_array(@question_result_hash).page(@page).per(@limit) + rescue Exception => e + uid_logger_error(e.message) + tip_exception("没有权限") + raise ActiveRecord::Rollback end end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 2302272bf..c1e08d440 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -125,6 +125,9 @@ class MessagesController < ApplicationController @message.message_detail_attributes = {content: params[:content]} @message.save! Attachment.associate_container(params[:attachment_ids], @message.id, @message.class.name) + if @board.course.email_notify && params[:email_notify] + notify_course_students @message, @board.course + end rescue Exception => e uid_logger_error(e.message) tip_exception(e.message) @@ -201,4 +204,10 @@ class MessagesController < ApplicationController def message_params params.require(:message).permit(:subject, :sticky) end + + def notify_course_students message, course + course.students.includes(:user).each do |student| + UserMailer.course_message_email(student&.user&.mail, message.id).deliver_now if student&.user&.mail + end + end end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 323bad3cf..44c341d6e 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -412,12 +412,13 @@ module ExercisesHelper end #计算试卷的总分和试卷的答题状态 - def calculate_student_score(exercise,user) + def calculate_student_score(exercise,user,end_time) score1 = 0.0 #选择题/判断题 score2 = 0.0 #填空题 score5 = 0.0 #实训题 ques_stand = [] #问题是否正确 - exercise_questions = exercise.exercise_questions.includes(:exercise_answers,:exercise_shixun_answers,:exercise_standard_answers,:exercise_shixun_challenges) + exercise_end_time = end_time || Time.now + exercise_questions = exercise.exercise_questions.includes(:exercise_standard_answers,:exercise_shixun_challenges) exercise_questions&.each do |q| begin if q.question_type != 5 @@ -505,7 +506,7 @@ module ExercisesHelper exercise_cha_score = 0.0 answer_status = 0 # if game.status == 2 && game.final_score >= 0 - if game.final_score > 0 + if game.final_score > 0 && game.end_time && game.end_time < exercise_end_time exercise_cha_score = game.real_score(exercise_cha.question_score) # exercise_cha_score = exercise_cha.question_score #每一关卡的得分 answer_status = 1 diff --git a/app/jobs/end_exercise_calculate_job.rb b/app/jobs/end_exercise_calculate_job.rb index b6d8e491e..35c6ded57 100644 --- a/app/jobs/end_exercise_calculate_job.rb +++ b/app/jobs/end_exercise_calculate_job.rb @@ -5,11 +5,11 @@ class EndExerciseCalculateJob < ApplicationJob queue_as :default - def perform(ex_user_ids,exercise) + def perform(ex_user_ids,exercise,end_time) exercise_users = ExerciseUser.where(id: ex_user_ids) exercise_users.each do |user| if user.commit_status == 0 && user.start_at.present? - objective_score = calculate_student_score(exercise,user.user)[:total_score] + objective_score = calculate_student_score(exercise,user.user,end_time)[:total_score] user_sub_score = user.subjective_score subjective_score = user_sub_score < 0.0 ? 0.0 : user_sub_score total_score = objective_score + subjective_score diff --git a/app/mailers/user_mailer.rb b/app/mailers/user_mailer.rb index 03ef63bb2..5cd9d787c 100644 --- a/app/mailers/user_mailer.rb +++ b/app/mailers/user_mailer.rb @@ -7,4 +7,11 @@ class UserMailer < ApplicationMailer @code = code mail(to: mail, subject: '验证你的电子邮件') end + + # 课堂讨论区的邮件通知 + def course_message_email(mail, message_id) + @message = Message.find_by(id: message_id) + @course = @message&.board&.course + mail(to: mail, subject: '课堂通知') if @message.present? && @course.present? + end end diff --git a/app/models/course.rb b/app/models/course.rb index 16700428b..6c470d63f 100644 --- a/app/models/course.rb +++ b/app/models/course.rb @@ -376,7 +376,7 @@ class Course < ApplicationRecord case type when 'activity' then '动态' when 'announcement' then '公告栏' - when 'online_learning' then '在线学习' + when 'online_learning' then '课程学习' when 'shixun_homework' then '实训作业' when 'common_homework' then '普通作业' when 'group_homework' then '分组作业' diff --git a/app/models/exercise.rb b/app/models/exercise.rb index 0b9963eee..177c0ac88 100644 --- a/app/models/exercise.rb +++ b/app/models/exercise.rb @@ -70,7 +70,7 @@ class Exercise < ApplicationRecord if unified_setting self&.end_time else - user_course_group = course.course_members.find_by(user_id: user_id)&.course_group_id + user_course_group = course.students.find_by(user_id: user_id)&.course_group_id exercise_group_settings.find_by(course_group_id:user_course_group)&.end_time end end diff --git a/app/tasks/exercise_publish_task.rb b/app/tasks/exercise_publish_task.rb index 04e37d126..8e206b3dd 100644 --- a/app/tasks/exercise_publish_task.rb +++ b/app/tasks/exercise_publish_task.rb @@ -41,20 +41,21 @@ class ExercisePublishTask puts "--------------------------------exercise_publish end" end + def end Rails.logger.info("log--------------------------------exercise_end start") puts "--------------------------------exercise_end start" # 1。统一设置的试卷 - exercises = Exercise.includes(:exercise_users,:exercise_questions).where("exercise_status = 2 AND - unified_setting = true AND end_time <= ?",Time.now + 900) - exercises&.each do |exercise| - ex_type = exercise.exercise_questions.pluck(:question_type).uniq - exercise.update_column('exercise_status', 3) - exercise.exercise_users&.each do |exercise_user| - begin - Rails.logger.info("true: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}") - if (exercise_user&.commit_status == 0) && (exercise_user&.start_at.present?) - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] + exercises = Exercise.includes(:exercise_questions).where("exercise_status = 2 AND end_time <= ?",Time.now + 900) + exercises.each do |exercise| + Rails.logger.info("end_exercise_id: #{exercise.id}") + exercise.update_attributes!('exercise_status', 3) + if exercise.unified_setting + ex_type = exercise.exercise_questions.pluck(:question_type).uniq + exercise.exercise_users.where("commit_status = 0 and start_at is not null").each do |exercise_user| + begin + Rails.logger.info("true: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}") + s_score = calculate_student_score(exercise, exercise_user.user, exercise.end_time)[:total_score] if ex_type.include?(4) #是否包含主观题 subjective_score = exercise_user.subjective_score else @@ -66,72 +67,61 @@ class ExercisePublishTask Rails.logger.info("true: user_id:#{exercise_user.user_id}--s_score:#{s_score}") Rails.logger.info("true: user_id:#{exercise_user.user_id}--commit_method:#{exercise_user.commit_method}") commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score, - :commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3 + :status => 1, + :commit_status => 1, + :end_at => exercise.end_time, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score, + :commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3 } exercise_user.update_attributes(commit_option) + rescue Exception => e + Rails.logger.info("rescue errors ___________________________#{e}") + next end - rescue Exception => e - Rails.logger.info("rescue errors ___________________________#{e}") - next end - end end - # 2.非统一的试卷 - all_exercises = Exercise.includes(:exercise_group_settings,:exercise_users,:exercise_questions).where("unified_setting = false AND exercise_status = 2 AND end_time > ?",Time.now + 900) - exercise_ids = all_exercises.blank? ? "(-1)" : "(" + all_exercises.map(&:id).join(",") + ")" - ex_group_settings = ExerciseGroupSetting.where("end_time <= '#{Time.now}' and exercise_id in #{exercise_ids}") - ex_group_settings&.each do |exercise_setting| + ExerciseGroupSetting.where("end_time < ? and end_time > ?", Time.now + 900, Time.now - 900).each do |exercise_setting| exercise = exercise_setting.exercise - if exercise.end_time <= Time.now - exercise.update_column('exercise_status', 3) - end + Rails.logger.info("exercise_group_setting: exercise_id:#{exercise.id}--group_settings_id:#{exercise_setting.id}") + users = exercise.course.course_members.where(:course_group_id => exercise_setting.course_group_id) + exercise_users = exercise.exercise_users.where(user_id: users.pluck(:user_id)).where("commit_status = 0 and start_at is not null") ex_types = exercise.exercise_questions.pluck(:question_type).uniq - users = exercise.course.students.where(:course_group_id => exercise_setting.course_group_id) - exercise_users = exercise.exercise_users.where(:user_id => users.pluck(:user_id)) - exercise_users&.each do |exercise_user| + exercise_users.each do |exercise_user| + Rails.logger.info("false: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}") begin - Rails.logger.info("false: user_id:#{exercise_user.user_id}--commit_status:#{exercise_user.commit_status}") - if exercise_user.commit_status == 0 && !exercise_user.start_at.nil? - if ex_types.include?(4) #是否包含主观题 - subjective_score = exercise_user.subjective_score - else - subjective_score = -1.0 - end - s_score = calculate_student_score(exercise, exercise_user.user)[:total_score] - total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score - total_score = s_score + total_score_subjective_score - Rails.logger.info("false: user_id:#{exercise_user.user_id}--s_score:#{s_score}") - Rails.logger.info("false: user_id:#{exercise_user.user_id}--subjective_score:#{subjective_score}") - Rails.logger.info("false: user_id:#{exercise_user.user_id}--commit_method:#{exercise_user.commit_method}") - commit_option = { - :status => 1, - :commit_status => 1, - :end_at => Time.now, - :objective_score => s_score, - :score => total_score, - :subjective_score => subjective_score, - :commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3 - } - exercise_user.update_attributes(commit_option) + if ex_types.include?(4) #是否包含主观题 + subjective_score = exercise_user.subjective_score + else + subjective_score = -1.0 end + s_score = calculate_student_score(exercise, exercise_user.user, exercise_setting.end_time)[:total_score] + total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score + total_score = s_score + total_score_subjective_score + Rails.logger.info("false: user_id:#{exercise_user.user_id}--s_score:#{s_score}") + Rails.logger.info("false: user_id:#{exercise_user.user_id}--subjective_score:#{subjective_score}") + Rails.logger.info("false: user_id:#{exercise_user.user_id}--commit_method:#{exercise_user.commit_method}") + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => exercise_setting.end_time, + :objective_score => s_score, + :score => total_score, + :subjective_score => subjective_score, + :commit_method => exercise_user&.commit_method.to_i > 0 ? exercise_user&.commit_method.to_i : 3 + } + exercise_user.update_attributes(commit_option) rescue Exception => e Rails.logger.info("unified_setting_false_rescue errors ___________________________#{e}") next end - end end Rails.logger.info("log--------------------------------exercise_end end") puts "--------------------------------exercise_end end" end - end \ No newline at end of file diff --git a/app/views/courses/board_list.json.jbuilder b/app/views/courses/board_list.json.jbuilder index e8961e380..2115f1752 100644 --- a/app/views/courses/board_list.json.jbuilder +++ b/app/views/courses/board_list.json.jbuilder @@ -6,4 +6,5 @@ json.data do json.boards do json.array! @boards, :id, :name end + json.email_notify @course.email_notify end diff --git a/app/views/graduation_topics/_graduation_comments.json.jbuilder b/app/views/graduation_topics/_graduation_comments.json.jbuilder index 51551d95d..b9314aa25 100644 --- a/app/views/graduation_topics/_graduation_comments.json.jbuilder +++ b/app/views/graduation_topics/_graduation_comments.json.jbuilder @@ -3,7 +3,7 @@ json.author do end json.id message.id -json.content message.contents_show(identity) +json.content content_safe(message.contents_show(identity)) json.time time_from_now(message.created_at) json.hidden message.hidden # 主贴与子贴不一致 diff --git a/app/views/user_mailer/course_message_email.html.erb b/app/views/user_mailer/course_message_email.html.erb new file mode 100644 index 000000000..66c75414b --- /dev/null +++ b/app/views/user_mailer/course_message_email.html.erb @@ -0,0 +1,62 @@ + +
+ ++ 您好! +
++ 您正在注册Educoder,请在10分钟内在注册页输入此验证码,并进行下一步操作。 + 如非你本人操作,请忽略此邮件。 +
+<%= @code %>
++ 如果您并未发过此请求,则可能是因为其他用户在注册时误输了您的邮件地址,而使您收到了这封邮件,那么您可以放心的忽略此邮件,无需进一步采取任何操作。 +
+