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

dev_forum
daiao 5 years ago
commit 42bbeb1ef8

@ -223,7 +223,6 @@ class ExerciseQuestionsController < ApplicationController
end end
end end
#试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案 #试卷未发布时,当标准答案存在时,可修改标准答案内容,可增删标准答案,否则只能修改标准答案,不能增删标准答案
st_count = 0
@exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案 @exercise_answers_array = @exercise_question.exercise_standard_answers #问卷的全部标准答案
if standard_answer.present? if standard_answer.present?
if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个 if @exercise_question.question_type <= 2 #选择题/判断题,标准答案为一个或多个
@ -232,7 +231,6 @@ class ExerciseQuestionsController < ApplicationController
old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉 old_left_standard_choices = exercise_standard_choices - common_standard_choices # 以前的差集共同的,剩余的表示需要删掉
new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建 new_left_standard_choices = standard_answer - common_standard_choices # 传入的标准答案差集共同的,剩余的表示需要新建
if old_left_standard_choices.count > 0 if old_left_standard_choices.count > 0
st_count += 1
@exercise_answers_array.standard_by_ids(old_left_standard_choices).destroy_all @exercise_answers_array.standard_by_ids(old_left_standard_choices).destroy_all
end end
if new_left_standard_choices.count > 0 #新建标准答案 if new_left_standard_choices.count > 0 #新建标准答案
@ -258,7 +256,6 @@ class ExerciseQuestionsController < ApplicationController
#删除多余的选项 #删除多余的选项
if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空 if old_ex_answer_choice_ids.count > new_ex_answer_choice_ids.count #有减少的填空
st_count += 1
delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids delete_ex_answer_choice_ids = old_ex_answer_choice_ids - new_ex_answer_choice_ids
old_ex_answer.standard_by_ids(delete_ex_answer_choice_ids).destroy_all old_ex_answer.standard_by_ids(delete_ex_answer_choice_ids).destroy_all
end end
@ -284,7 +281,6 @@ class ExerciseQuestionsController < ApplicationController
ex_answer_pre[n-1].update(standard_option) ex_answer_pre[n-1].update(standard_option)
end end
if new_add_choice.count > 0 #表示有新增的 if new_add_choice.count > 0 #表示有新增的
st_count += 1
new_add_choice.each do |i| new_add_choice.each do |i|
standard_option = { standard_option = {
:exercise_question_id => @exercise_question.id, :exercise_question_id => @exercise_question.id,
@ -306,7 +302,6 @@ class ExerciseQuestionsController < ApplicationController
ex_answer_pre[index].update(standard_option) ex_answer_pre[index].update(standard_option)
end end
if new_delete_choice.count > 0 #表示填空题的答案有删减的 if new_delete_choice.count > 0 #表示填空题的答案有删减的
st_count += 1
new_delete_choice.each do |d| new_delete_choice.each do |d|
ex_answer_pre[d-1].destroy ex_answer_pre[d-1].destroy
end end
@ -350,18 +345,30 @@ class ExerciseQuestionsController < ApplicationController
@exercise_question.shixun_name = shixun_name @exercise_question.shixun_name = shixun_name
end end
#当标准答案修改时,如有已提交的学生,需重新计算分数 #当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数.
if st_count > 0
ex_users_committed = @exercise.exercise_users.exercise_user_committed # if @exercise.exercise_status == 2
if ex_users_committed.size > 0 # ex_users_committed = @exercise.exercise_users.exercise_user_committed
ex_users_committed.each do |ex_user| # if ex_users_committed.size > 0
user = ex_user.user # ex_users_committed.each do |ex_user|
objective_score = calculate_student_score(@exercise,user)[:total_score] # user = ex_user.user
subjective_score = ex_user.subjective_score # objective_score = calculate_student_score(@exercise,user)[:total_score]
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score # subjective_score = ex_user.subjective_score
total_score = objective_score + total_score_subjective_score # total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
ex_user.update_attributes(objective_score:objective_score,score:total_score) # total_score = objective_score + total_score_subjective_score
end # ex_user.update_attributes(objective_score:objective_score,score:total_score)
# end
# end
# end
ex_users_committed = @exercise.exercise_users.exercise_user_committed
if ex_users_committed.size > 0
ex_users_committed.each do |ex_user|
user = ex_user.user
objective_score = calculate_student_score(@exercise,user)[:total_score]
subjective_score = ex_user.subjective_score
total_score_subjective_score = subjective_score < 0.0 ? 0.0 : subjective_score
total_score = objective_score + total_score_subjective_score
ex_user.update_attributes(objective_score:objective_score,score:total_score)
end end
end end
@ -587,15 +594,15 @@ class ExerciseQuestionsController < ApplicationController
if @exercise_question.present? if @exercise_question.present?
@exercise = @exercise_question.exercise @exercise = @exercise_question.exercise
if @exercise.blank? if @exercise.blank?
tip_exception(404) tip_exception(404,"试卷不存在")
else else
@course = @exercise.course @course = @exercise.course
if @course.blank? if @course.blank?
tip_exception(404) tip_exception(404,"课堂不存在")
end end
end end
else else
tip_exception(404) tip_exception(404,"试卷问题不存在")
end end
end end

@ -3,7 +3,7 @@ class FilesController < ApplicationController
before_action :require_login, except: %i[index] before_action :require_login, except: %i[index]
before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project] before_action :find_course, except: %i[public_with_course_and_project mine_with_course_and_project]
before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public] before_action :find_ids, only: %i[bulk_delete bulk_send bulk_move bulk_public bulk_publish]
before_action :file_validate_sort_type, only: :index before_action :file_validate_sort_type, only: :index
before_action :validate_send_message_to_course_params, only: :bulk_send before_action :validate_send_message_to_course_params, only: :bulk_send
before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project] before_action :set_pagination, only: %i[index public_with_course_and_project mine_with_course_and_project]
@ -40,6 +40,12 @@ class FilesController < ApplicationController
@attachments = @attachments.page(@page).per(@page_size) @attachments = @attachments.page(@page).per(@page_size)
end end
def bulk_publish
return normal_status(403, "您没有权限进行操作") if current_user.course_identity(@course) >= 5
@course.attachments.by_ids(@attachment_ids).unpublish.update_all(is_publish: 1, publish_time: Time.now)
render_ok
end
def bulk_delete def bulk_delete
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin

@ -129,7 +129,7 @@ class GraduationTasksController < ApplicationController
if @user_course_identity >= Course::STUDENT if @user_course_identity >= Course::STUDENT
tip_exception(403, "无权限操作") tip_exception(403, "无权限操作")
elsif complete_works == 0 elsif complete_works == 0
normal_status(-1,"暂无用户提交") normal_status(-1,"暂无用户提交")
else else
respond_to do |format| respond_to do |format|
format.xlsx{ format.xlsx{
@ -164,7 +164,7 @@ class GraduationTasksController < ApplicationController
@work_count = @work_list.count @work_count = @work_list.count
@all_work_count = @work_list.count @all_work_count = @work_list.count
if params[:format] == "xlsx" || params[:format] == "zip" if params[:format] == "xlsx" || params[:format] == "zip"
normal_status(-1,"作业未发布") normal_status(-1,"毕设任务未发布")
end end
end end
end end

@ -106,7 +106,7 @@ class HomeworkCommonsController < ApplicationController
student_works = @homework.all_works student_works = @homework.all_works
@all_member_count = student_works.size @all_member_count = student_works.size
if @homework.publish_time.nil? || @homework.publish_time > Time.now if @homework.publish_time.blank? || (@homework.publish_time > Time.now)
@student_works = [] @student_works = []
if params[:format] == "xlsx" || params[:format] == "zip" if params[:format] == "xlsx" || params[:format] == "zip"
normal_status(-1,"作业未发布") normal_status(-1,"作业未发布")
@ -250,7 +250,7 @@ class HomeworkCommonsController < ApplicationController
challenge_settings = @homework.homework_challenge_settings challenge_settings = @homework.homework_challenge_settings
myshixuns.find_each(batch_size: 100) do |myshixun| myshixuns.find_each(batch_size: 100) do |myshixun|
work = student_works.select{|work| work.user_id == myshixun.user_id}.first work = student_works.select{|work| work.user_id == myshixun.user_id}.first
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max)
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings
end end
@ -271,7 +271,7 @@ class HomeworkCommonsController < ApplicationController
myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id) myshixun = Myshixun.find_by(shixun_id: params[:shixun_id], user_id: current_user.id)
ActiveRecord::Base.transaction do ActiveRecord::Base.transaction do
begin begin
if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.updated_at) if work && myshixun && (work.update_time.nil? || work.update_time < myshixun.games.pluck(:updated_at).max)
challenge_settings = @homework.homework_challenge_settings challenge_settings = @homework.homework_challenge_settings
games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id)) games = myshixun.games.where(challenge_id: challenge_settings.pluck(:challenge_id))
HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings HomeworksService.new.update_myshixun_work_score work, myshixun, games, @homework, challenge_settings

@ -275,7 +275,7 @@ class MyshixunsController < ApplicationController
message: message, message: message,
content: content, content: content,
author_name: author_name, author_name: author_name,
author_email: author_email) author_email: "53246666@qq.com")
end end
end end

@ -14,7 +14,7 @@ class Users::SubjectService
subjects = category_scope_subjects subjects = category_scope_subjects
subjects = user_policy_filter(subjects) subjects = user_policy_filter(subjects)
custom_sort(subjects, :updated_at, params[:sort_direction]) custom_sort(subjects.distinct, :updated_at, params[:sort_direction])
end end
private private

@ -256,6 +256,7 @@ Rails.application.routes.draw do
get :mine_with_course_and_project get :mine_with_course_and_project
post :import post :import
post :upload post :upload
put :bulk_publish
end end
member do member do
get :histories get :histories

@ -0,0 +1,23 @@
class AddOldExerciseTiankongChoiceId < ActiveRecord::Migration[5.2]
def up
#类型为3 的问题答案及标准答案更新exercise_choice_id 为1即表示第一空
exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id)
ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1)
ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: nil).update_all(exercise_choice_id:1)
exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id)
ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:1)
end
def down
#类型为3 的问题答案及标准答案更新exercise_choice_id 为1即表示第一空
exercise_question_ids = ExerciseQuestion.where("question_type = 3").pluck(:id)
ExerciseAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil)
ExerciseStandardAnswer.where(exercise_question_id: exercise_question_ids,exercise_choice_id: 1).update_all(exercise_choice_id:nil)
exercise_bank_question_ids = ExerciseBankQuestion.where("question_type =3").pluck(:id)
ExerciseBankStandardAnswer.where(exercise_bank_question_id: exercise_bank_question_ids).update_all(exercise_bank_choice_id:nil)
end
end
Loading…
Cancel
Save