Merge branch 'dev_aliyun' into develop

dev_tj
daiao 5 years ago
commit 4a9e5fc85f

@ -23,7 +23,7 @@ class ApplicationController < ActionController::Base
# 所有请求必须合法签名
def check_sign
if !Rails.env.development?
if !Rails.env.development? ||
Rails.logger.info("66666 #{params}")
# suffix = request.url.split(".").last.split("?").first
# suffix_arr = ["xls", "xlsx", "pdf", "zip"] # excel文件先注释

@ -26,6 +26,7 @@ class ExerciseAnswersController < ApplicationController
end
elsif q_type == Exercise::MULTIPLE #多选题的
choice_ids = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : []
question_choice_ids = @exercise_question.exercise_choices.pluck(:id)
ea_ids = ea.pluck(:exercise_choice_id)
common_answer_ids = choice_ids & ea_ids #已经存在的试卷选项id
@ -37,7 +38,8 @@ class ExerciseAnswersController < ApplicationController
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => e,
:answer_text => ""
:answer_text => "",
:choice_index => question_choice_ids.index(e).to_i + 1 # choice的序号
}
ex_a = ExerciseAnswer.new(answer_option)
ex_a.save!
@ -52,7 +54,8 @@ class ExerciseAnswersController < ApplicationController
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => choice_id,
:answer_text => answer_text
:answer_text => answer_text,
:choice_index => choice_id
}
ea_answer = ea.search_answer_users("exercise_choice_id",choice_id)
if ea.present? && ea_answer.present?

@ -316,7 +316,8 @@ class ExercisesController < ApplicationController
:question_number => q.question_number,
:question_score => q.question_score,
:shixun_id => q.shixun_id,
:shixun_name => q.shixun_name
:shixun_name => q.shixun_name,
:is_ordered => q.is_ordered
}
exercise_bank_question = current_ex_bank.exercise_bank_questions.new option
exercise_bank_question.save!

@ -259,7 +259,8 @@ class QuestionBanksController < ApplicationController
:question_number => q.question_number,
:question_score => q.question_score,
:shixun_name => q.shixun_name,
:shixun_id => q.shixun_id
:shixun_id => q.shixun_id,
:is_ordered => q.is_ordered
}
exercise_question = new_exercise.exercise_questions.new option
# question_type5实训题其他是非实训题

@ -108,7 +108,7 @@ class Weapps::CoursesController < Weapps::BaseController
def change_member_roles
@course = current_course
tip_exception("请至少选择一个角色") if params[:roles].reject(&:blank?).blank?
tip_exception("不能具有老师、助教两种角色") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR")
tip_exception("教师、助教角色只能二选一") if params[:roles].include?("PROFESSOR") && params[:roles].include?("ASSISTANT_PROFESSOR")
params[:user_ids].each do |user_id|
course_members = @course.course_members.where(user_id: user_id)

@ -2,9 +2,11 @@ module ExerciseQuestionsHelper
def get_exercise_question_info(question,exercise,ex_user,ex_answerer_id)
answered_content = []
exercise_answers = question.exercise_answers.search_exercise_answer("user_id",ex_answerer_id) #试卷用户的回答
if question.question_type <= 2
if question.question_type == Exercise::SINGLE || question.question_type == Exercise::JUDGMENT
answered_content << exercise_answers.last&.exercise_choice_id if exercise_answers.present?
elsif question.question_type == Exercise::MULTIPLE
answered_content = exercise_answers.pluck(:exercise_choice_id)
elsif question.question_type == 3
elsif question.question_type == Exercise::COMPLETION
exercise_answers.each do |a|
u_answer = {
"choice_id": a.exercise_choice_id,
@ -12,10 +14,10 @@ module ExerciseQuestionsHelper
}
answered_content.push(u_answer)
end
elsif question.question_type == 4
elsif question.question_type == Exercise::SUBJECTIVE
answered_content = exercise_answers.pluck(:answer_text)
end
if question.question_type == 5 && ex_user.present? && ex_user.commit_status == 1 #存在实训题,且用户已提交了的,如果实训题只做了一半就关闭,则相当于不要了
if question.question_type == Exercise::PRACTICAL && ex_user.present? && ex_user.commit_status == 1 #存在实训题,且用户已提交了的,如果实训题只做了一半就关闭,则相当于不要了
if exercise.exercise_status == 3 #如果试卷已截止,则可以看到分数,否则不能查看分数
shixun_type = 2
else

@ -16,8 +16,8 @@ module ExercisesHelper
end
if q_type <= Exercise::JUDGMENT
if answers_content.present? #学生有回答时,分数已经全部存到exercise_answer 表,所以可以直接取第一个值
ques_score = answers_content.first.score
if answers_content.present? #学生有回答时,分数已经全部存到exercise_answer 表,多选题直接取第一个值,单选题和判断题选最后一个值(考虑并发)
ques_score = q_type == Exercise::MULTIPLE ? answers_content.first.score : answers_content.last.score
ques_score = ques_score < 0 ? 0.0 : ques_score
# answer_choice_array = []
# answers_content.each do |a|
@ -441,6 +441,17 @@ module ExercisesHelper
end
if q.question_type <= 2 #为选择题或判断题时
if answers_content.present? #学生有回答时
if q.question_type == 0 || q.question_type == 2 ## 单选、判断题的算分与多选题分开计算
user_answer = answers_content.last.exercise_choice.choice_position
standard_answer = q.exercise_standard_answers.first&.exercise_choice_id
if standard_answer.present? && user_answer == standard_answer
q_score_1 = q.question_score
score1 = score1 + q.question_score
else
q_score_1 = -1.0
end
answers_content.last.update!(score: q_score_1)
else
answer_choice_array = []
answers_content.each do |a|
answer_choice_array.push(a.exercise_choice.choice_position) #学生答案的位置
@ -466,6 +477,7 @@ module ExercisesHelper
answers_content.update_all(:score => -1.0)
score1 += 0.0
end
end
else
score1 += 0.0
end

@ -1,12 +1,12 @@
module ShixunsHelper
def level_to_s(level)
%W(初级 中级 高级 顶)[level-1]
%W(初级 中级 中高级 高)[level-1]
end
#难度
def diff_to_s(trainee)
%W(初级学员 中级学员 高级学员 顶级学员)[trainee-1]
%W(初级学员 中级学员 中高级学员 高级学员)[trainee-1]
end
#1. 未发布
@ -24,6 +24,8 @@ module ShixunsHelper
"已发布"
when 3
"已关闭"
when -1
"已删除"
end
end

@ -276,8 +276,8 @@ class Shixun < ApplicationRecord
case trainee
when 1 then '初级学员'
when 2 then '中级学员'
when 3 then '高级学员'
when 4 then '级学员'
when 3 then '高级学员'
when 4 then '级学员'
else ''
end
end
@ -286,8 +286,8 @@ class Shixun < ApplicationRecord
case trainee
when 1 then '初级'
when 2 then '中级'
when 3 then '高级'
when 4 then '级'
when 3 then '高级'
when 4 then '级'
else ''
end
end

@ -43,7 +43,6 @@ class ShixunSearchService < ApplicationService
@shixuns = @shixuns.where(trainee: params[:diff])
end
Rails.logger.info("search_shixun_ids: #{@shixuns.pluck(:id)}")
Shixun.search(keyword, search_options)
end
@ -53,7 +52,7 @@ class ShixunSearchService < ApplicationService
order =
if sort_str == "wechat_myshixuns_count"
{"is_wechat_support" => "desc", sort_str => order_str}
{"is_wechat_support" => "desc", "myshixuns_count" => order_str}
else
{sort_str => order_str}
end

@ -0,0 +1,17 @@
class AddChoiceIndexToExerciseAnswers < ActiveRecord::Migration[5.2]
def change
add_column :exercise_answers, :choice_index, :integer, default: 1
multi_questions = ExerciseQuestion.where(question_type: 1)
multi_questions.includes(:exercise_choices, :exercise_answers).find_each do |question|
exercise_answers = question.exercise_answers
exercise_answers.find_each do |answer|
choice_index = question.exercise_choices.pluck(:id).index(answer.exercise_choice_id).to_i + 1
answer.update_column('choice_index', choice_index)
end
puts "multi_questions: #{question.id}"
end
ExerciseAnswer.joins(:exercise_question).where(exercise_questions: {question_type: 3}).update_all("choice_index = exercise_choice_id")
end
end

@ -0,0 +1,13 @@
class AddChoiceIndexUniqIndexToExerciseAnswers < ActiveRecord::Migration[5.2]
def change
sql = %Q(delete from exercise_answers where (exercise_question_id, user_id, choice_index) in
(select * from (select exercise_question_id, user_id, choice_index from exercise_answers group by exercise_question_id, user_id, choice_index having count(*) > 1) a)
and id not in (select * from (select max(id) from exercise_answers group by exercise_question_id, user_id, choice_index having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :exercise_answers, [:exercise_question_id, :user_id, :choice_index], name: 'exercise_user_choice_index', unique: true
remove_index :exercise_answers, name: :exercise_choice_index
end
end
Loading…
Cancel
Save