From 363f5c67b97a0522874e86350ca1240345caeba2 Mon Sep 17 00:00:00 2001 From: SylorHuang Date: Thu, 20 Jun 2019 20:23:42 +0800 Subject: [PATCH 1/2] fix bug --- .../exercise_answers_controller.rb | 23 +++++++++++++++++++ app/helpers/exercises_helper.rb | 8 +++++-- app/helpers/polls_helper.rb | 14 +++++++---- 3 files changed, 39 insertions(+), 6 deletions(-) diff --git a/app/controllers/exercise_answers_controller.rb b/app/controllers/exercise_answers_controller.rb index c709980f9..81f117daf 100644 --- a/app/controllers/exercise_answers_controller.rb +++ b/app/controllers/exercise_answers_controller.rb @@ -1,6 +1,8 @@ class ExerciseAnswersController < ApplicationController before_action :require_login before_action :get_exercise_question + before_action :commit_exercise_time + include ExercisesHelper def create #每一次答案的点击,请求一次,实训题不在这里回答 ActiveRecord::Base.transaction do @@ -31,6 +33,7 @@ class ExerciseAnswersController < ApplicationController end elsif q_type == 1 #多选题的 choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : [] + ea_ids = ea.pluck(:exercise_choice_id) common_answer_ids = choice_ids & ea_ids #已经存在的试卷选项id new_ids = choice_ids - common_answer_ids # 新增的id @@ -113,4 +116,24 @@ class ExerciseAnswersController < ApplicationController end end + def commit_exercise_time + @exercise_user_current = @exercise.exercise_users.exercise_commit_users(current_user.id).first #查找当前用户是否有过答题 + if @exercise.exercise_status == 3 || (@exercise.time > 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 + total_score = objective_score + subjective_score + commit_option = { + :status => 1, + :commit_status => 1, + :end_at => Time.now, + :objective_score => objective_score, + :score => total_score, + :subjective_score => subjective_score + } + @exercise_user_current.update_attributes(commit_option) + normal_status(-1,"考试时间已到,已交卷成功!") + end + end + end diff --git a/app/helpers/exercises_helper.rb b/app/helpers/exercises_helper.rb index 4f4c015eb..95ec0ac24 100644 --- a/app/helpers/exercises_helper.rb +++ b/app/helpers/exercises_helper.rb @@ -478,8 +478,12 @@ module ExercisesHelper ex_user_end_at = ex_user.end_at course_member = course.students.course_find_by_ids("user_id",ex_user.user.id) current_user_group_id = course_member.first.course_group_id if course_member.present? - course_group = course.course_groups.by_group_ids(current_user_group_id) - current_user_group_name = course_group.first.name if course_group.present? + if current_user_group_id == 0 + current_user_group_name = "未分班" + else + course_group = course.course_groups.by_group_ids(current_user_group_id) + current_user_group_name = course_group.first.name if course_group.present? + end teacher_review = ex_user.subjective_score < 0.0 ? false : true if ex_user_exercise_status != 3 || commit_status != 1 #试卷未截止或用户未提交 # if (user_status != 0 && ex_user_exercise_status != 3)|| commit_status == 0 #不为教师,且试卷未截止;当前用户未提交 不显示分数 diff --git a/app/helpers/polls_helper.rb b/app/helpers/polls_helper.rb index 5b4702174..56bbb9b77 100644 --- a/app/helpers/polls_helper.rb +++ b/app/helpers/polls_helper.rb @@ -110,14 +110,20 @@ module PollsHelper poll_user_name = user.nickname end course_member = course_members.find_by(user_id:user.id) - current_user_group_id = course_members.present? ? course_member.course_group_id : nil - course_group = course.course_groups.find_by_id(current_user_group_id) + course_group_id = course_members.present? ? course_member.course_group_id : nil + if course_group_id == 0 + course_group_name = "未分班" + else + course_group = course.course_groups.find_by_id(course_group_id) + course_group_id = course_group&.id + course_group_name = course_group&.name + end { "user_name":poll_user_name, "user_id": user.id, "student_id":user_student_id, - "group_name":course_group.try(:name), - "group_id":course_group.try(:id), + "group_name":course_group_name, + "group_id":course_group_id, "login":user.login } end From a6ec81eac4ac8eef7f61763169304eb93fba5d03 Mon Sep 17 00:00:00 2001 From: cxt <853663049@qq.com> Date: Thu, 20 Jun 2019 20:24:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=B0=83=E6=95=B4=E8=BF=81=E7=A7=BB?= =?UTF-8?q?=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../20190309085449_migrate_course_members.rb | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/db/migrate/20190309085449_migrate_course_members.rb b/db/migrate/20190309085449_migrate_course_members.rb index 8e828610e..1d28eb5d1 100644 --- a/db/migrate/20190309085449_migrate_course_members.rb +++ b/db/migrate/20190309085449_migrate_course_members.rb @@ -1,21 +1,21 @@ class MigrateCourseMembers < ActiveRecord::Migration[5.2] def change - # add_column :course_groups, :position, :integer, default: 0 - # - # Course.find_each do |course| - # position = 1 - # course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| - # group.update_attribute(:position, position) - # position += 1 - # end - # end - # - # - # add_column :course_groups, :course_members_count, :integer, default: 0 - # - # CourseGroup.find_each do |g| - # CourseGroup.reset_counters g.id, :course_members - # end + add_column :course_groups, :position, :integer, default: 0 + + Course.find_each do |course| + position = 1 + course.course_groups.reorder("CONVERT(course_groups.name USING gbk) COLLATE gbk_chinese_ci ASC").find_each do |group| + group.update_attribute(:position, position) + position += 1 + end + end + + + add_column :course_groups, :course_members_count, :integer, default: 0 + + CourseGroup.find_each do |g| + CourseGroup.reset_counters g.id, :course_members + end ActiveRecord::Base.transaction do begin