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

dev_forum
cxt 5 years ago
commit 497eeec19e

@ -149,7 +149,11 @@ class ChallengesController < ApplicationController
def index
uid_logger("identifier: #{params}")
# 通过调试发现 这里includes(:games)性能会慢10倍
@challenges = @shixun.challenges.fields_for_list
# @challenges = @shixun.challenges.fields_for_list
@challenges = Challenge.fields_for_list.where(shixun_id: @shixun.id)
# @challenges = Challenge.includes(:games).where("games.user_id" => 12).where(shixun_id: @shixun.id)
@editable = current_user.manager_of_shixun?(@shixun) && @shixun.status == 0
@user = current_user
end
@ -247,7 +251,6 @@ class ChallengesController < ApplicationController
# 关卡位置被修改,需要修改脚本
script = modify_shixun_script @shixun, @shixun.evaluate_script
@shixun.update_column(:evaluate_script, script)
end
def index_up

@ -518,7 +518,7 @@ class ShixunsController < ApplicationController
ActiveRecord::Base.transaction do
begin
#cloud_bridge = edu_setting('cloud_bridge')
cloud_bridge = edu_setting('cloud_bridge')
myshixun_identifier = generate_identifier Myshixun, 10
myshixun = @shixun.myshixuns.create!(user_id: current_user.id, identifier: myshixun_identifier,
modify_time: @shixun.modify_time, reset_time: @shixun.reset_time,
@ -622,10 +622,16 @@ class ShixunsController < ApplicationController
end
def add_collaborators
raise("搜索内容不能为空") unless params[:search]
member_ids = "(" + @shixun.shixun_members.map(&:user_id).join(',') + ")"
condition = "%#{params[:search].strip}%".gsub(" ","")
@users = User.where("id not in #{member_ids} and status = 1 and LOWER(concat(lastname, firstname, login, mail, nickname)) LIKE '#{condition}'")
user_name = "%#{params[:user_name].strip}%"
school_name = "%#{params[:school_name].strip}%"
if user_name.present? || school_name.present?
@users = User.joins(user_extension: :school).where("users.id not in #{member_ids} AND users.status = 1 AND
LOWER(users.lastname) LIKE '#{user_name}' AND LOWER(schools.name) LIKE
'#{school_name}'")
else
@users = User.none
end
end
def shixun_members_added
@ -667,14 +673,14 @@ class ShixunsController < ApplicationController
limit = params[:limit] || 20
if params[:search]
search = "%#{params[:search].to_s.strip.downcase}%"
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9)
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m
WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0
AND c.name like '#{search}' ").map(&:id)
else
course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, members m, member_roles mr
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9)
course_ids = Course.find_by_sql("SELECT c.id, c.name FROM courses c, course_members m
WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id)
end
@ -686,7 +692,7 @@ class ShixunsController < ApplicationController
# 将实训发送到课程
def send_to_course
@course = Course.find(params[:course_id])
homework = HomeworksService.new.create_homework shixun, @course, nil, current_user
homework = HomeworksService.new.create_homework @shixun, @course, nil, current_user
end
# 二维码扫描下载

@ -164,8 +164,8 @@ class SubjectsController < ApplicationController
end
def choose_course
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, members m, member_roles mr
WHERE m.course_id = c.id AND m.id=mr.member_id AND mr.role_id in (3,7,9)
course_ids = Course.find_by_sql("SELECT c.id FROM courses c, course_members m
WHERE m.course_id = c.id AND m.role in (1,2,3)
AND m.user_id=#{current_user.id} AND c.is_delete = 0 AND c.is_end = 0").map(&:id)
@courses = Course.where(id: course_ids)
@none_shixun_ids = ShixunSchool.where("school_id != #{current_user.user_extension.try(:school_id)}").pluck(:shixun_id)

@ -46,7 +46,7 @@ module ExercisesHelper
sub_answer_score = sub_answer.first.score
else
stand_status = 0
sub_answer_score = 0.0
sub_answer_score = nil
end
sub_score = {
@ -54,7 +54,7 @@ module ExercisesHelper
"q_type":s.question_type,
"q_position":s.question_number,
"stand_status":stand_status,
"user_score":sub_answer_score.round(1).to_s
"user_score":sub_answer_score.present? ? sub_answer_score.round(1).to_s : nil
}
@ex_sub_array.push(sub_score)
end
@ -508,15 +508,14 @@ module ExercisesHelper
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 #不为教师,且试卷未截止;当前用户未提交 不显示分数
ex_object_score = nil
ex_subject_score = nil
score = nil
else
if (user_status == 0 && commit_status == 1) || (user_status == 1 && ex_user_exercise_status == 3 && commit_status == 1) #老师都可以看,学生,需在试卷已提交,且已截止的情况下看
ex_object_score = ex_user.objective_score < 0.0 ? 0.0 : ex_user.objective_score.round(1).to_s
ex_subject_score = ex_user.subjective_score < 0.0 ? nil : ex_user.subjective_score.round(1).to_s
score = ex_user.score.present? ? ex_user.score.round(1).to_s : 0.0.to_s
else
ex_object_score = nil
ex_subject_score = nil
score = nil
end
{
@ -628,7 +627,7 @@ module ExercisesHelper
#学生的分数状态及回答的内容
def user_question_answers(q,ex_answerer_id,student_status,is_teacher_or,ex_status,ques_type,ex_type)
answered_content = []
user_score = 0.0
user_score = nil
shixun_type = 0
question_comment = []
if q.question_type == 5
@ -639,6 +638,9 @@ module ExercisesHelper
if student_status == 2 #当前为老师,或为学生且已提交
user_score = exercise_answers.score_reviewed.pluck(:score).sum
end
if user_score.present? && (user_score > q.question_score)
user_score = q.question_score
end
if ques_type <= 2
answered_content = exercise_answers.pluck(:exercise_choice_id)
elsif ques_type == 3
@ -665,7 +667,7 @@ module ExercisesHelper
question_comment = q.exercise_answer_comments.search_answer_comments("exercise_answer_id",q_answer_id)
end
{
"user_score": user_score.round(1),
"user_score": user_score.present? ? user_score.round(1) : nil,
"answered_content":answered_content,
"shixun_type":shixun_type,
"question_comment":question_comment

@ -51,9 +51,8 @@ class Challenge < ApplicationRecord
end
# 开启挑战
def open_game(user_id)
game = self.games.select([:status, :identifier]).where(user_id: user_id).first
shixun = self.shixun
def open_game user_id, challenge_id, shixun
game = games.select{|game| game.challenge_id = challenge_id && game.user_id == user_id}.first
if game.present?
shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
else
@ -61,11 +60,24 @@ class Challenge < ApplicationRecord
end
end
# # 开启挑战
# def open_game(user_id, shixun)
#
#
# game = self.games.select([:status, :identifier]).where(user_id: user_id).first
# game = self.games.select{|game| game.user_id == user_id}
# if game.present?
# shixun.task_pass || game.status != 3 ? "/tasks/#{game.identifier}" : ""
# else
# "/api/shixuns/#{shixun.identifier}/shixun_exec"
# end
# end
## 用户关卡状态 0: 不能开启实训; 1:直接开启; 2表示已完成
def user_tpi_status user_id
# todo: 以前没加索引导致相同关卡,同一用户有多个games
game = self.games.where(user_id: user_id).last
status =
game = games.select{|game| game.user_id == user_id }.last
if game.blank?
self.position == 1 ? 1 : 0
elsif game.status == 2
@ -85,12 +97,12 @@ class Challenge < ApplicationRecord
# 关卡用户通关数
def user_passed_count
games.where(status: 2).count
games.select{|game| game.status == 2}.size
end
# 关卡用户正在挑战的人数
def playing_count
games.where(status: [0, 1]).count
games.select{|game| game.status == 0 || game.status == 1}.size
end
def last_challenge

@ -3,11 +3,11 @@ class Exercise < ApplicationRecord
belongs_to :exercise_bank, optional: true
belongs_to :user
has_many :exercise_users,:dependent => :destroy
has_many :exercise_questions,:dependent => :destroy
has_many :exercise_group_settings,:dependent => :destroy
has_many :exercise_users, :dependent => :delete_all
has_many :exercise_questions, :dependent => :delete_all
has_many :exercise_group_settings, :dependent => :delete_all
has_many :tidings, as: :container
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, :dependent => :delete_all
scope :is_exercise_published, -> { where("exercise_status > ? ",1)}
scope :unified_setting, -> { where("unified_setting = ?",true) }

@ -3,7 +3,7 @@ class ExerciseAnswer < ApplicationRecord
belongs_to :user
belongs_to :exercise_question
belongs_to :exercise_choice, optional: true
has_many :exercise_answer_comments, :dependent => :destroy
has_many :exercise_answer_comments, :dependent => :delete_all
scope :search_exercise_answer, lambda { |name,key| where("#{name} = ?",key)}
scope :search_answer_users, lambda {|name,ids| where("#{name}":ids)}

@ -1,9 +1,10 @@
class ExerciseChoice < ApplicationRecord
belongs_to :exercise_question
has_many :exercise_answers, :dependent => :destroy
has_many :exercise_standard_answers, :dependent => :destroy
has_many :exercise_answers, :dependent => :delete_all
has_many :exercise_standard_answers, :dependent => :delete_all
scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
end

@ -4,19 +4,18 @@ class ExerciseQuestion < ApplicationRecord
belongs_to :exercise
belongs_to :shixun, optional: true
has_many :exercise_choices, :dependent => :destroy
has_many :exercise_answers, :dependent => :destroy
has_many :exercise_shixun_challenges,:dependent => :destroy
has_many :exercise_shixun_answers, :dependent => :destroy
has_many :exercise_answer_comments, :dependent => :destroy
has_many :exercise_standard_answers, :dependent => :destroy
has_many :exercise_choices, :dependent => :delete_all
has_many :exercise_answers
has_many :exercise_shixun_challenges, :dependent => :delete_all
has_many :exercise_shixun_answers
has_many :exercise_answer_comments
has_many :exercise_standard_answers
scope :insert_question_ex, lambda {|k| where("question_number > ?",k)}
scope :find_by_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
# scope :next_exercise, lambda {|k| where("question_number > ?",k).first}
# scope :last_exercise, lambda {|k| where("question_number < ?",k).last}
def question_type_name
case self.question_type

@ -2,7 +2,7 @@ class ExerciseShixunAnswer < ApplicationRecord
belongs_to :exercise_question
belongs_to :user
belongs_to :exercise_shixun_challenge
has_many :exercise_answer_comments, :dependent => :destroy
has_many :exercise_answer_comments, :dependent => :delete_all
# status 0: 未通过, 1通过
# attr_accessible :answer_text, :score, :status
scope :search_shixun_answers, lambda {|name,ids| where("#{name}":ids)}

@ -4,13 +4,13 @@ class Poll < ApplicationRecord
belongs_to :exercise_bank, optional: true
# belongs_to :exercise_bank
has_many :poll_questions,dependent: :destroy
has_many :poll_users, :dependent => :destroy
has_many :poll_questions,dependent: :delete_all
has_many :poll_users, :dependent => :delete_all
has_many :users, :through => :poll_users #该文件被哪些用户提交答案过
has_many :poll_group_settings, :dependent => :destroy
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :destroy
has_many :poll_group_settings, :dependent => :delete_all
has_many :course_acts, class_name: 'CourseActivity', as: :course_act, dependent: :delete_all
has_many :tidings, as: :container, dependent: :destroy
has_many :tidings, as: :container, dependent: :delete_all
scope :publish_or_not, -> { where("polls_status > ? ",1)}
scope :only_public, -> {where("is_public = ?",true)}

@ -3,7 +3,7 @@ class PollAnswer < ApplicationRecord
# include Redmine::SafeAttributes
belongs_to :poll_question
has_many :poll_votes, :dependent => :destroy
has_many :poll_votes, :dependent => :delete_all
scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题
scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题

@ -1,9 +1,9 @@
class PollQuestion < ApplicationRecord
belongs_to :poll
has_many :poll_answers, :dependent => :destroy
has_many :poll_answers, :dependent => :delete_all
attr_accessor :question_answers, :question_other_anser
has_many :poll_votes, :dependent => :destroy
has_many :poll_votes
scope :ques_count, lambda {|k| where("question_type = ?",k)}
scope :ques_necessary, -> {where("is_necessary = ?",1)}

@ -17,7 +17,7 @@ if @challenges.present?
json.passed_count challenge.user_passed_count
json.playing_count challenge.playing_count
json.name_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.open_game challenge.open_game(@user.id)
json.open_game challenge.open_game(@user.id, challenge.id, @shixun)
if @editable
json.edit_url edit_shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)
json.delete_url shixun_challenge_path(challenge, shixun_identifier: @shixun.identifier)

@ -6,10 +6,11 @@ json.question_type question.question_type
json.question_score question.question_score.round(1).to_s
if question.question_type <= 2 #当为选择题或判断题时,只显示选项的位置
standard_answers_array = question.get_standard_answer_ids
exercise_choices = choices.order("choice_position ASC")
ex_choice_random_boolean = (exercise_type.present? && exercise_type == 3 && (question.exercise.choice_random)) ? true : false #问题的选项随机打乱
if ex_choice_random_boolean
exercise_choices = exercise_choices.order("RAND()")
exercise_choices = choices.order("RAND()")
else
exercise_choices = choices.order("choice_position ASC")
end
json.question_choices do
json.array! exercise_choices.each_with_index.to_a do |a,index|

@ -40,8 +40,8 @@ json.exercise_questions do
question_info = get_exercise_question_info(question,@exercise,@exercise_user_current,@ex_answerer.id)
# json.q_position q[:ques_number] #问题的序号,当问题为随机时,重新更新后的问题序号
if @t_user_exercise_status == 3
this_answer_status = "0.0"
user_score = "0.0"
this_answer_status = 0
user_score = nil
if all_question_status.size > 0
this_ques_status = all_question_status.detect {|f| f[:q_id] == question.id}
this_answer_status = this_ques_status[:stand_status]

@ -1,4 +1,3 @@
json.status 1
json.message "发送成功"
json.url course_homework_commons_path(@course.id, type: 4)
# json.url "#{Rails::configuration.educoder['old_edu_host']}/homework_common?course=#{@course.id}&homework_type=4"
json.course_id @course.id
Loading…
Cancel
Save