merge aliyun

dev_static
tangjiang 5 years ago
commit 51205c9056

@ -25,9 +25,9 @@ class ApplicationController < ActionController::Base
def check_sign
if !Rails.env.development? && EduSetting.get("host_name") != "https://test-newweb.educoder.net"
Rails.logger.info("66666 #{params}")
suffix = request.url.split(".").last.split("?").first
suffix_arr = ["xls", "xlsx", "pdf"] # excel文件先注释
unless suffix_arr.include?(suffix)
# suffix = request.url.split(".").last.split("?").first
# suffix_arr = ["xls", "xlsx", "pdf", "zip"] # excel文件先注释
# unless suffix_arr.include?(suffix)
if params[:client_key].present?
randomcode = params[:randomcode]
# tip_exception(501, "请求不合理") unless (Time.now.to_i - randomcode.to_i).between?(0,5)
@ -38,7 +38,7 @@ class ApplicationController < ActionController::Base
else
tip_exception(501, "请求不合理")
end
end
# end
end
end

@ -46,6 +46,12 @@ module GitHelper
content: content, author_name: username, author_email: mail)
end
def update_file_base64_content(content, repo_path, path, mail, username, message)
content = Base64.encode64(content)
GitService.update_file_base64(repo_path: repo_path, file_path: path, message: message,
content: content, author_name: username, author_email: mail)
end
# 添加目录
def git_add_folder(folder_path, author_name, author_email, message)
GitService.add_tree(file_path: folder_path, message: message, author_name: author_name, author_email: author_email)

@ -21,7 +21,7 @@ class CourseSecondCategoriesController < ApplicationController
else
@course_module.course_second_categories.where("position > #{@category.position} and position <= ?", params[:position]).update_all("position = position - 1")
end
@category.update_attributes(position: params[:position])
@category.update!(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")

@ -292,8 +292,8 @@ class CoursesController < ApplicationController
if next_inform.blank?
render_error('已经到达最顶部')
else
inform.update_attribute(:position, (inform.position + 1))
next_inform.update_attribute(:position, inform.position - 1)
inform.update!(position: (inform.position + 1))
next_inform.update!(position: inform.position - 1)
render_ok
end
end
@ -306,8 +306,8 @@ class CoursesController < ApplicationController
if last_inform.blank?
render_error('已经到达最底部')
else
inform.update_attribute(:position, (inform.position - 1))
last_inform.update_attribute(:position, inform.position + 1)
inform.update!(position: (inform.position - 1))
last_inform.update!(position: inform.position + 1)
render_ok
end
end
@ -353,7 +353,7 @@ class CoursesController < ApplicationController
# 邀请码停用/启用
def set_invite_code_halt
begin
@course.update_attribute('invite_code_halt', @course.invite_code_halt == 0 ? 1 : 0)
@course.update!(invite_code_halt: @course.invite_code_halt == 0 ? 1 : 0)
normal_status(0, "成功")
rescue => e
uid_logger_error(e.message)
@ -364,7 +364,7 @@ class CoursesController < ApplicationController
# 设置课堂私有/公有
def set_public_or_private
begin
@course.update_attribute('is_public', @course.is_public == 1 ? 0 : 1)
@course.update!(is_public: @course.is_public == 1 ? 0 : 1)
normal_status(0, "成功")
rescue => e
uid_logger_error(e.message)
@ -394,6 +394,7 @@ class CoursesController < ApplicationController
# 教师列表以及教师搜索
def teachers
tip_exception(403, "无权限访问") if @course.excellent && @user_course_identity > Course::ASSISTANT_PROFESSOR
@search_str = params[:search].present? ? params[:search].strip : ""
if @course.try(:id) != 1309 || current_user.admin_or_business? || current_user.try(:id) == 15582
@ -551,7 +552,7 @@ class CoursesController < ApplicationController
graduation_group_id = GraduationGroup.find(params[:graduation_group_id].to_i).id
@course_member_list.each do |course_member|
course_member = CourseMember.find(course_member[:course_member_id].to_i)
course_member.update_attributes(graduation_group_id: graduation_group_id)
course_member.update!(graduation_group_id: graduation_group_id)
end
normal_status(0, "成功")
rescue => e
@ -711,7 +712,7 @@ class CoursesController < ApplicationController
CourseDeleteStudentNotifyJob.perform_later(@course.id, [course_member.user_id], current_user.id)
course_member.destroy!
course_student.update_attributes(is_active: 1) if course_student.present? && !course_student.is_active
course_student.update!(is_active: 1) if course_student.present? && !course_student.is_active
normal_status(0, "删除成功")
rescue => e
uid_logger_error(e.message)
@ -726,8 +727,8 @@ class CoursesController < ApplicationController
tip_exception("切换失败") unless course_member.STUDENT?
course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[CREATOR PROFESSOR], course_id: @course.id)
course_member.update_attributes(is_active: 0)
course_teacher.update_attributes(is_active: 1)
course_member.update!(is_active: 0)
course_teacher.update!(is_active: 1)
normal_status(0, "切换成功")
rescue => e
uid_logger_error(e.message)
@ -742,8 +743,8 @@ class CoursesController < ApplicationController
tip_exception("切换失败") unless course_member.STUDENT?
course_teacher = CourseMember.find_by!(user_id: current_user.id, role: %i[ASSISTANT_PROFESSOR], course_id: @course.id)
course_member.update_attributes(is_active: 0)
course_teacher.update_attributes(is_active: 1)
course_member.update!(is_active: 0)
course_teacher.update!(is_active: 1)
normal_status(0, "切换成功")
rescue => e
uid_logger_error(e.message)
@ -782,7 +783,7 @@ class CoursesController < ApplicationController
# 课堂如果还有其他身份的用户则更新is_active
course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id)
course_student.destroy!
course_teacher.update_attributes(is_active: 1) if course_teacher.present? && !course_teacher.is_active
course_teacher.update!(is_active: 1) if course_teacher.present? && !course_teacher.is_active
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
normal_status(0, "退出成功")
end
@ -850,6 +851,8 @@ class CoursesController < ApplicationController
# 学生列表(包括各个子分班的学生列表)及搜索
def students
tip_exception(403, "无权限访问") if @course.excellent && @user_course_identity > Course::ASSISTANT_PROFESSOR
search = params[:search].present? ? params[:search].strip : nil
order = params[:order].present? ? params[:order].to_i : 1
sort = params[:sort].present? ? params[:sort] : "asc"
@ -959,7 +962,7 @@ class CoursesController < ApplicationController
member_teacher = CourseMember.find_by(user_id: course_member.user_id, course_id: @course.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR])
student_ids << course_member.user_id
course_member.destroy!
member_teacher.update_attributes(is_active: 1) if member_teacher.present?
member_teacher.update!(is_active: 1) if member_teacher.present?
end
end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
@ -990,7 +993,7 @@ class CoursesController < ApplicationController
if existing_course_member.present?
if existing_course_member.STUDENT?
existing_course_member.update_attributes(course_group_id: course_group_id)
existing_course_member.update!(course_group_id: course_group_id)
else
new_student.is_active = 0 if existing_course_member.is_active
new_student.save!
@ -1142,7 +1145,7 @@ class CoursesController < ApplicationController
existing_student = CourseMember.find_by(course_id: course.id, role: %i[STUDENT], user_id: current_user.id)
if existing_student.present?
# 如果在该课堂已经存在学生身份,且邀请码为分班邀请码,则将其直接加入分班
existing_student.update_attributes(course_group_id: course_group.id) if course_group.present?
existing_student.update!(course_group_id: course_group.id) if course_group.present?
else
correspond_teacher_exist = current_user.none_admin_teacher_of_course? course
new_student = CourseMember.new(user_id: current_user.id, course_id: course.id, role: 4)

@ -2,7 +2,7 @@ class ExaminationBanksController < ApplicationController
include PaginateHelper
before_action :require_login
before_action :find_exam, except: [:index, :create]
before_action :edit_auth, only: [:update, :destroy, :set_public]
before_action :edit_auth, only: [:update, :destroy, :set_public, :revoke_item]
def index
exams = ExaminationBankQuery.call(params)
@ -65,6 +65,15 @@ class ExaminationBanksController < ApplicationController
render_ok
end
def revoke_item
item = @exam.examination_items.find_by!(item_bank_id: params[:item_id])
ActiveRecord::Base.transaction do
@exam.examination_items.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1")
item.destroy!
end
render_ok
end
private
def form_params

@ -0,0 +1,102 @@
class ExaminationIntelligentSettingsController < ApplicationController
before_action :require_login
before_action :find_exam, only: [:exchange_one_item, :exchange_items, :save_exam]
def optinal_items
sub_discipline_id = params[:sub_discipline_id]
tag_discipline_id = params[:tag_discipline_id]
difficulty = params[:difficulty]
source = params[:source]
items = OptionalItemQuery.call(sub_discipline_id, tag_discipline_id, difficulty, source)
@single_question_count = items.select{ |item| item.item_type == "SINGLE" }.size
@multiple_question_count = items.select{ |item| item.item_type == "MULTIPLE" }.size
@judgement_question_count = items.select{ |item| item.item_type == "JUDGMENT" }.size
@program_question_count = items.select{ |item| item.item_type == "PROGRAM" }.size
end
def create
ActiveRecord::Base.transaction do
exam = ExaminationIntelligentSetting.new(user: current_user)
# 保存试卷基础信息
exam = ExaminationIntelligentSettings::SaveSettingService.call(exam, form_params)
render_ok({exam_setting_id: exam.id})
end
rescue ApplicationService::Error => ex
render_error(ex.message)
end
def save_exam
new_exam = ExaminationBank.new(user: current_user)
# 保存试卷基础信息
ExaminationIntelligentSettings::SaveExaminationService.call(new_exam, save_params, @exam)
render_ok
rescue ApplicationService::Error => ex
render_error(ex.message)
end
def exchange_one_item
item = @exam.item_baskets.find_by!(id: params[:item_id])
exam_type_setting = @exam.examination_type_settings.find_by!(item_type: item.item_type)
# 获取可选的题
items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public)
type_items = items.select{ |t_item| t_item.item_type == item.item_type }
# 如果可选的题数小于等于设置的题数则提示无可换的题
tip_exception("无可换的题") if type_items.size <= exam_type_setting.count
# 可选题中去掉已组卷的同题型试题
optional_item_ids = type_items.pluck(:id) - @exam.item_baskets.where(item_type: item.item_type).pluck(:item_bank_id)
new_item = ItemBank.find optional_item_ids.sample(1).first
ActiveRecord::Base.transaction do
@exam.item_baskets << ItemBasket.new(item_bank_id: new_item.id, position: item.position, score: item.score, item_type: new_item.item_type)
item.destroy!
end
render_ok
end
def exchange_items
exam_type_setting = @exam.examination_type_settings.find_by!(item_type: params[:item_type])
choosed_items = @exam.item_baskets.where(item_type: params[:item_type])
# 获取可选的题
items = OptionalItemQuery.call(@exam.sub_discipline_id, @exam.tag_discipline_containers.pluck(:tag_discipline_id), @exam.difficulty, @exam.public)
type_items = items.select{ |t_item| t_item.item_type == params[:item_type] }
# 如果可选的题数小于等于设置的题数则提示无可换的题
tip_exception("无可换的题") if type_items.size <= exam_type_setting.count
# 可选题中去掉已组卷的同题型试题
choosed_item_ids = choosed_items.pluck(:item_bank_id)
optional_item_ids = type_items.pluck(:id) - choosed_item_ids
# 如果可选题数小于设置的题数n则在原来的选题中随机选n个确保换题时能选到新的题
if optional_item_ids.size < exam_type_setting.count
absence_count = exam_type_setting.count - optional_item_ids.size
optional_item_ids = optional_item_ids + choosed_item_ids.sample(absence_count)
end
ActiveRecord::Base.transaction do
# 取试题分数
score = choosed_items.first&.score || (params[:item_type] == "PROGRAM" ? 10 : 5)
choosed_items.destroy_all
optional_item_ids.sample(exam_type_setting.count).each_with_index do |item_id, index|
new_item = ItemBank.find item_id
@exam.item_baskets << ItemBasket.new(item_bank_id: new_item.id, position: index+1, score: score, item_type: new_item.item_type)
end
end
render_ok
end
private
def find_exam
@exam = ExaminationIntelligentSetting.find_by!(id: params[:id])
tip_exception(403,"无权限编辑") unless current_user.admin_or_business? || @exam.user_id == current_user.id
end
def form_params
params.permit(:discipline_id, :sub_discipline_id, :difficulty, :source, tag_discipline_id: [], question_settings: %i[item_type count])
end
def save_params
params.permit(:name, :duration)
end
end

@ -4,83 +4,77 @@ class ExerciseAnswersController < ApplicationController
include ExercisesHelper
def create #每一次答案的点击,请求一次,实训题不在这里回答
begin
q_type = @exercise_question.question_type #试卷的类型
choice_id = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : ""
answer_text = params[:answer_text].present? ? params[:answer_text].strip : "" #为字符串
if q_type < Exercise::SUBJECTIVE && (q_type != Exercise::MULTIPLE) && choice_id.blank?
normal_status(-1,"请选择序号")
else
ea = @exercise_question.exercise_answers.search_answer_users("user_id",current_user.id) #试卷的当前用户的答案
if q_type == Exercise::SINGLE || q_type == Exercise::JUDGMENT #选择题(单选)/判断题
if ea.exists?
ea.first.update_attribute(:exercise_choice_id,choice_id )
else
answer_option = {
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => choice_id,
:answer_text => ""
}
ex_a = ExerciseAnswer.new(answer_option)
ex_a.save!
end
elsif q_type == Exercise::MULTIPLE #多选题的
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).uniq # 新增的id
old_ids = (ea_ids - common_answer_ids).uniq #没有选择的,则删掉
if new_ids.size > 0
new_ids.each do |e|
answer_option = {
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => e,
:answer_text => ""
}
ex_a = ExerciseAnswer.new(answer_option)
ex_a.save!
end
end
if old_ids.size > 0
ea_answer = ea.search_answer_users("exercise_choice_id",old_ids)
ea_answer.destroy_all
end
elsif q_type == Exercise::COMPLETION #填空题
answer_option = {
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => choice_id,
:answer_text => answer_text
}
ea_answer = ea.search_answer_users("exercise_choice_id",choice_id)
if ea.present? && ea_answer.present?
ea_answer.update(answer_option)
else
ex_new = ExerciseAnswer.new(answer_option)
ex_new.save!
end
elsif q_type == Exercise::SUBJECTIVE #简答题
q_type = @exercise_question.question_type #试卷的类型
choice_id = params[:exercise_choice_id].present? ? params[:exercise_choice_id] : ""
answer_text = params[:answer_text].present? ? params[:answer_text].strip : "" #为字符串
if q_type < Exercise::SUBJECTIVE && (q_type != Exercise::MULTIPLE) && choice_id.blank?
normal_status(-1,"请选择序号")
else
ea = @exercise_question.exercise_answers.search_answer_users("user_id",current_user.id) #试卷的当前用户的答案
if q_type == Exercise::SINGLE || q_type == Exercise::JUDGMENT #选择题(单选)/判断题
if ea.exists?
ea.first.update!(exercise_choice_id: choice_id )
else
answer_option = {
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => choice_id,
:answer_text => ""
}
if ea.present? #已经回答了的,
ea.first.update_attribute("answer_text",answer_text)
else
answer_option.merge!(answer_text:answer_text)
ex_a = ExerciseAnswer.new(answer_option)
ex_a.save!
end
elsif q_type == Exercise::MULTIPLE #多选题的
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).uniq # 新增的id
old_ids = (ea_ids - common_answer_ids).uniq #没有选择的,则删掉
if new_ids.size > 0
new_ids.each do |e|
answer_option = {
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => e,
:answer_text => ""
}
ex_a = ExerciseAnswer.new(answer_option)
ex_a.save!
end
end
normal_status(0,"回答成功")
if old_ids.size > 0
ea_answer = ea.search_answer_users("exercise_choice_id",old_ids)
ea_answer.destroy_all
end
elsif q_type == Exercise::COMPLETION #填空题
answer_option = {
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id,
:exercise_choice_id => choice_id,
:answer_text => answer_text
}
ea_answer = ea.search_answer_users("exercise_choice_id",choice_id)
if ea.present? && ea_answer.present?
ea_answer.first.update!(answer_option)
else
ex_new = ExerciseAnswer.new(answer_option)
ex_new.save!
end
elsif q_type == Exercise::SUBJECTIVE #简答题
answer_option = {
:user_id => current_user.id,
:exercise_question_id => @exercise_question.id
}
if ea.present? #已经回答了的,
ea.first.update!(answer_text: answer_text)
else
answer_option.merge!(answer_text:answer_text)
ex_a = ExerciseAnswer.new(answer_option)
ex_a.save!
end
end
rescue Exception => e
uid_logger_error(e.message)
tip_exception("页面调用失败!")
raise ActiveRecord::Rollback
normal_status(0,"回答成功")
end
end
@ -116,7 +110,7 @@ class ExerciseAnswersController < ApplicationController
:score => total_score,
:subjective_score => subjective_score
}
@exercise_user.update_attributes(commit_option)
@exercise_user.update!(commit_option)
normal_status(-1,"试卷提交时间已截止!")
end
end

@ -44,7 +44,7 @@ class ExerciseQuestionsController < ApplicationController
end
end
if @exercise_question.save
if @exercise_question.save!
#为选择题(包括单选和多选)的时候,创建问题选项
ques_type = @exercise_question.question_type
if ques_type <= Exercise::MULTIPLE
@ -59,7 +59,7 @@ class ExerciseQuestionsController < ApplicationController
:choice_text => choice.strip
}
question_choices = @exercise_question.exercise_choices.new(choice_option)
question_choices.save
question_choices.save!
end
#标准答案的存储,如:["1","2","3"..]等1对应A2对应B3对应C。。。
standard_answer.each do |a|
@ -69,7 +69,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id => choice_id #即为选择的位置参数
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
if standard_answer.count > 1 && ques_type == Exercise::SINGLE #当标准答案数大于1且不为多选时修改为多选
@exercise_question.update_attribute("question_type",Exercise::MULTIPLE)
elsif standard_answer.count == 1 && ques_type == Exercise::MULTIPLE
@ -85,8 +85,8 @@ class ExerciseQuestionsController < ApplicationController
:choice_position => c,
:choice_text => choice.strip
}
question_choices = @exercise_question.exercise_choices.create(choice_option)
question_choices.save
question_choices = @exercise_question.exercise_choices.create!(choice_option)
question_choices.save!
end
standard_answer = params[:standard_answers] #对应选项的id
standard_option = {
@ -94,7 +94,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id => standard_answer.first.to_i
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
elsif ques_type == Exercise::COMPLETION #填空题,每空的参考答案有多个,那么以位置对应
standard_answer = params[:standard_answers]
standard_answer.each do |a|
@ -107,7 +107,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => n
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
elsif ques_type == Exercise::SUBJECTIVE #简答题
@ -119,7 +119,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => a,
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
elsif ques_type == Exercise::PRACTICAL #实训题
@ -135,10 +135,10 @@ class ExerciseQuestionsController < ApplicationController
:position => (index + 1),
:question_score => shixun_scores[index].present? ? shixun_scores[index].to_f.round(1) : 5
}
ex_shixun_challenge = ExerciseShixunChallenge.create(shixun_option)
ex_shixun_challenge = ExerciseShixunChallenge.create!(shixun_option)
question_score += ex_shixun_challenge.question_score # 问题的分数,为各个关卡分数的总和
end
@exercise_question.update_attributes(:question_score => question_score,:shixun_name=> shixun_name)
@exercise_question.update!(:question_score => question_score,:shixun_name=> shixun_name)
end
end
rescue Exception => e
@ -188,7 +188,7 @@ class ExerciseQuestionsController < ApplicationController
choices_array = params[:question_choices]
stan_answer_params = params[:standard_answers]
standard_answer = stan_answer_params.present? ? stan_answer_params.uniq.reject(&:blank?) : []
@exercise_question.update_attributes(question_options)
@exercise_question.update!(question_options)
#当选项存在时,可修改选项内容,但是不能更改选项的位置(即不能增删选项)
if choices_array.present?
ex_choices = @exercise_question.exercise_choices
@ -218,7 +218,7 @@ class ExerciseQuestionsController < ApplicationController
:choice_text => choices_array[i-1].strip
}
question_choices = @exercise_question.exercise_choices.new(choice_option)
question_choices.save
question_choices.save!
end
end
end
@ -243,7 +243,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_choice_id => s.to_i #即为选择的位置参数
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
@ -296,7 +296,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => null_choice_text[i-1]
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
else
@ -323,7 +323,7 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => n
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
end
end
@ -340,19 +340,19 @@ class ExerciseQuestionsController < ApplicationController
:answer_text => main_standard_answer,
}
question_standard_answer = ExerciseStandardAnswer.new(standard_option)
question_standard_answer.save
question_standard_answer.save!
end
elsif @exercise_question.question_type == Exercise::PRACTICAL
question_score = 0
shixun_name = params[:shixun_name] || @exercise_question.shixun_name
@exercise_question.exercise_shixun_challenges.each_with_index do |challenge, index|
challenge.question_score = params[:question_scores][index].to_f.round(1)
challenge.save
challenge.save!
question_score += params[:question_scores][index].to_f.round(1)
end
@exercise_question.question_score = question_score
@exercise_question.shixun_name = shixun_name
@exercise_question.save
@exercise_question.save!
end
#当试卷已发布时(试卷的总状态),当标准答案修改时,如有已提交的学生,需重新计算分数.
@ -397,7 +397,7 @@ class ExerciseQuestionsController < ApplicationController
new_objective_score = objective_score + update_objective_score
total_score = ex_user.score + update_objective_score
total_score = total_score < 0.0 ? 0.0 : total_score
ex_user.update_attributes(objective_score:new_objective_score,score:total_score)
ex_user.update!(objective_score:new_objective_score,score:total_score)
end
end
end
@ -526,7 +526,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:answer_text => ""
}
ExerciseAnswer.create(answer_option)
ExerciseAnswer.create!(answer_option)
ex_answer_old = 0
end
if ex_obj_score <= 0.0
@ -545,7 +545,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score => new_obj_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
elsif @exercise_question.question_type == Exercise::COMPLETION #当为填空题,更新问题的总分,
@ -561,7 +561,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:answer_text => ""
}
ExerciseAnswer.create(answer_option)
ExerciseAnswer.create!(answer_option)
new_obj_score = ex_obj_score + @c_score
end
@ -575,7 +575,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score => new_obj_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
elsif @exercise_question.question_type == Exercise::SUBJECTIVE #当为主观题时
if ex_answers.exists?
ex_answers_old_score = ex_answers.first.score > 0.0 ? ex_answers.first.score : 0.0 #原分数小于0取0
@ -588,7 +588,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:answer_text => ""
}
ExerciseAnswer.create(answer_option)
ExerciseAnswer.create!(answer_option)
new_sub_score = ex_subj_score + @c_score
end
total_scores = ex_obj_score + new_sub_score
@ -601,7 +601,7 @@ class ExerciseQuestionsController < ApplicationController
:subjective_score => new_sub_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
elsif @exercise_question.question_type == Exercise::PRACTICAL
ex_answers = @exercise_question.exercise_shixun_answers.where(user_id:@user_id,exercise_shixun_challenge_id:@shixun_a_id)
@ -618,7 +618,7 @@ class ExerciseQuestionsController < ApplicationController
:score => @c_score,
:status => 0
}
ExerciseShixunAnswer.create(ex_shixun_option)
ExerciseShixunAnswer.create!(ex_shixun_option)
new_obj_score = ex_obj_score + @c_score
end
total_scores = new_obj_score + ex_subj_score
@ -631,7 +631,7 @@ class ExerciseQuestionsController < ApplicationController
:objective_score => new_obj_score,
:score => total_scores
}
@exercise_current_user.update_attributes(ex_scores)
@exercise_current_user.update!(ex_scores)
end
comments = params[:comment]
question_comment = @exercise_question.exercise_answer_comments&.first
@ -643,7 +643,7 @@ class ExerciseQuestionsController < ApplicationController
:exercise_answer_id => ex_answers.present? ? ex_answers.first.id : nil,
:user_id => current_user.id
}
question_comment.update_attributes(comment_option)
question_comment.update!(comment_option)
@exercise_comments = question_comment
else
ex_answer_comment_id = @exercise_question.exercise_answers.find_by(user_id: @user_id).try(:id)

File diff suppressed because it is too large Load Diff

@ -606,10 +606,10 @@ class GraduationTasksController < ApplicationController
end
def graduation_task_params
tip_exception("task_type参数不能为空") if params[:task_type].blank?
tip_exception("name参数不能为空") if params[:name].blank?
tip_exception("name参数不能超过60个字符") if params[:name].length > 60 #6.11 -hs
tip_exception("description参数不能为空") if params[:description].blank?
tip_exception("类型参数不能为空") if params[:task_type].blank?
tip_exception("名称不能为空") if params[:name].blank?
tip_exception("名称不能超过60个字符") if params[:name].length > 60 #6.11 -hs
tip_exception("描述不能为空") if params[:description].blank?
params.require(:graduation_task).permit(:task_type, :name, :description)
end

@ -52,7 +52,7 @@ class GraduationWorksController < ApplicationController
begin
work = @task.graduation_works.find_by!(user_id: params[:user_id])
tip_exception("只有组长才能删除组员") if work.commit_user_id != current_user.id
work.update_attributes(description: nil, project_id: 0, late_penalty: 0, work_status: 0, commit_time: nil,
work.update!(description: nil, project_id: 0, late_penalty: 0, work_status: 0, commit_time: nil,
update_time: nil, group_id: 0, commit_user_id: nil, final_score: nil, work_score: nil,
teacher_score: nil, teaching_asistant_score: nil, update_user_id: nil)
work.attachments.destroy_all
@ -89,12 +89,12 @@ class GraduationWorksController < ApplicationController
GraduationWork.create(user_id: current_user.id, graduation_task_id: @task.id, course_id: @task.course_id)
if work.work_status == 0 && work.project_id == 0
work.update_attributes(project_id: project.id, update_time: Time.now)
work.update!(project_id: project.id, update_time: Time.now)
# 将老师加入项目
project_member = project.members.where(user_id: @task.user_id).first
if project_member.present?
project_member.member_roles.first.update_attributes(role_id: 3) if project_member.member_roles.first.present?
project_member.member_roles.first.update!(role_id: 3) if project_member.member_roles.first.present?
else
member = Member.create(user_id: @task.user_id, project_id: project.id)
member.member_roles << MemberRole.new(role_id: 3)
@ -127,7 +127,7 @@ class GraduationWorksController < ApplicationController
Tiding.where(user_id: @task.user_id, trigger_user_id: current_user.id, container_id: work.project.id,
container_type: 'ManagerJoinProject').destroy_all
work.update_attributes(project_id: 0)
work.update!(project_id: 0)
normal_status("取消关联成功")
rescue Exception => e
@ -177,7 +177,7 @@ class GraduationWorksController < ApplicationController
student_ids += members
for i in 0 .. members.count-1
stu_work = @task.graduation_works.where(user_id: members[i].to_i).first || GraduationWork.new
stu_work.update_attributes(user_id: members[i].to_i, description: graduation_work.description,
stu_work.update!(user_id: members[i].to_i, description: graduation_work.description,
graduation_task_id: @task.id, project_id: graduation_work.project_id,
late_penalty: graduation_work.late_penalty, work_status: graduation_work.work_status,
commit_time: Time.now, update_time: Time.now, group_id: graduation_work.group_id,
@ -238,7 +238,7 @@ class GraduationWorksController < ApplicationController
# 原成员更新描述、更新时间以及附件
@task.graduation_works.where(group_id: @work.group_id, user_id: (work_user_ids & params_user_ids)).each do |work|
work.update_attributes(update_time: Time.now, description: @work.description, update_user_id: current_user.id)
work.update!(update_time: Time.now, description: @work.description, update_user_id: current_user.id)
work.attachments.destroy_all
@work.attachments.each do |attachment|
att = attachment.copy
@ -264,7 +264,7 @@ class GraduationWorksController < ApplicationController
(params_user_ids - work_user_ids).each do |user_id|
stu_work = @task.graduation_works.where(user_id: user_id).empty? ? GraduationWork.new :
@task.graduation_works.where(user_id: user_id).first
stu_work.update_attributes(user_id: user_id, description: @work.description, graduation_task_id: @task.id,
stu_work.update!(user_id: user_id, description: @work.description, graduation_task_id: @task.id,
project_id: @work.project_id, late_penalty: @work.late_penalty,
work_status: @work.work_status, commit_time: Time.now, update_time: Time.now,
group_id: @work.group_id, commit_user_id: @work.commit_user_id, update_user_id: current_user.id)
@ -323,9 +323,9 @@ class GraduationWorksController < ApplicationController
# 如果作品是未提交的状态则更新为已提交
if !new_score.score.nil? && @work.work_status == 0
@work.update_attributes(work_status: 1, commit_time: Time.now)
@work.update!(work_status: 1, commit_time: Time.now)
if @task.task_type == 2
@work.update_attributes(group_id: @task.graduation_works.where("work_status != 0").select("distinct group_id").count + 1)
@work.update!(group_id: @task.graduation_works.where("work_status != 0").select("distinct group_id").count + 1)
end
end
@ -392,7 +392,7 @@ class GraduationWorksController < ApplicationController
graduation_task_id: @task.id, comment: "使用调分功能调整了作业最终成绩:#{params[:comment]}",
user_id: User.current.id, reviewer_role: 1, is_ultimate: 1)
new_score.save!
@work.update_attributes(ultimate_score: 1, work_score: params[:score].to_f)
@work.update!(ultimate_score: 1, work_score: params[:score].to_f)
Tiding.create!(user_id: @work.user_id, trigger_user_id: current_user.id, container_id: new_score.id,
container_type: "AdjustScore", parent_container_id: @task.id,
@ -445,9 +445,9 @@ class GraduationWorksController < ApplicationController
end
Attachment.associate_container(params[:attachment_ids], @work.id, @work.class, 7)
revise_attachment = Attachment.where(attachtype: 7, container_id: @work.id, container_type: "GraduationWork").last
revise_attachment.update_attributes(description: params[:description]) if revise_attachment.present?
revise_attachment.update!(description: params[:description]) if revise_attachment.present?
@work.update_attributes(update_time: Time.now)
@work.update!(update_time: Time.now)
normal_status("提交成功")
rescue Exception => e
@ -465,7 +465,7 @@ class GraduationWorksController < ApplicationController
if @work_assign_teacher.present?
# graduation_group_id: 已经是答辩组的需要 将答辩组清空
@work_assign_teacher.update_attributes(graduation_group_id: 0)
@work_assign_teacher.update!(graduation_group_id: 0)
else
@work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id,
user_id: params[:user_id],

@ -62,9 +62,9 @@ class HacksController < ApplicationController
ItemBank.create!(new_item_params)
end
render_ok({identifier: hack.identifier})
rescue Exception => e
rescue => e
logger.error("########create_hack_error: #{e.message}")
render_error("创建失败")
render_error("创建失败: #{e.message}")
end
end
@ -96,7 +96,7 @@ class HacksController < ApplicationController
render_ok
rescue Exception => e
logger.error("####update_hack_error: #{e.message}")
render_error("更新失败")
render_error("更新失败: #{e.message}")
end
end
@ -232,7 +232,11 @@ class HacksController < ApplicationController
hacks = Hack.select(select_sql).mine(current_user.id)
else
# 全部包括已经发布的,和我的未发布的
hacks = Hack.select(select_sql).published.opening.or(Hack.select(select_sql).unpublish.mine(current_user.id))
if current_user.admin_or_business?
hacks = Hack.select(select_sql)
else
hacks = Hack.select(select_sql).published.opening.or(Hack.select(select_sql).unpublish.mine(current_user.id))
end
end
# 搜索
if params[:search]

@ -26,14 +26,14 @@ class HelpsController < ApplicationController
def feedback
if params[:url].blank?
content = "<p>[#{params[:question_kind]}]</p></p>#{params[:description]}"
content = "[#{params[:question_kind]}]<br>#{params[:description]}<br>"
if params[:attachment_ids]
params[:attachment_ids].each do |attachment_id|
content += "![](/api/attachments/#{attachment_id})"
content += "![](/api/attachments/#{attachment_id})<br>"
end
end
else
content = "<p>[#{params[:question_kind]}]</p><p>问题页面网址:#{params[:url]}</p>#{params[:description]}"
content = "[#{params[:question_kind]}]<br>问题页面网址:#{params[:url]}<br>#{params[:description]}"
end
ActiveRecord::Base.transaction do

@ -306,7 +306,7 @@ class HomeworkCommonsController < ApplicationController
def alter_name
tip_exception("作业名称不能为空") if params[:name].blank?
@homework.update_attributes(name: params[:name].strip)
@homework.update_attributes!(name: params[:name].strip)
normal_status("更新成功")
end
@ -348,7 +348,7 @@ class HomeworkCommonsController < ApplicationController
end
def update_explanation
@homework.update_attributes(explanation: params[:explanation])
@homework.update_attributes!(explanation: params[:explanation])
normal_status(0, "更新成功")
end
@ -416,7 +416,7 @@ class HomeworkCommonsController < ApplicationController
ActiveRecord::Base.transaction do
begin
@homework.update_attributes(homework_params)
@homework.update_attributes!(homework_params)
if @homework.homework_type == "group"
homework_detail_group = @homework.homework_detail_group
@ -521,7 +521,7 @@ class HomeworkCommonsController < ApplicationController
score = challenge[:challenge_score]
if setting && setting.score != score
score_change = true
setting.update_attributes(score: score)
setting.update_attributes!(score: score)
elsif setting.blank?
score_change = true
HomeworkChallengeSetting.create!(homework_common_id: @homework.id, challenge_id: challenge[:challenge_id],
@ -976,7 +976,7 @@ class HomeworkCommonsController < ApplicationController
elsif homework.max_group_end_time
homework.end_time = homework.max_group_end_time
end
homework.homework_detail_manual.update_attribute('comment_status', 1)
homework.homework_detail_manual.update_attributes!(comment_status: 1)
if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id)
@ -1004,7 +1004,7 @@ class HomeworkCommonsController < ApplicationController
if homework.end_time > Time.now && homework.homework_detail_manual.try(:comment_status) > 1
homework.homework_detail_manual.update_attribute("comment_status", 1)
homework.homework_detail_manual.update_attributes!(comment_status: 1)
end
# 补交结束时间
@ -1071,7 +1071,7 @@ class HomeworkCommonsController < ApplicationController
homework.end_time = homework.max_group_end_time
if homework.end_time > time && homework_detail_manual.try(:comment_status) > 1
homework_detail_manual.update_attribute("comment_status", 1)
homework_detail_manual.update_attributes!(comment_status: 1)
end
# 统一设置
@ -1080,7 +1080,7 @@ class HomeworkCommonsController < ApplicationController
homework.end_time = time
end
homework_detail_manual.update_attribute("comment_status", 2) if homework.end_time <= time
homework_detail_manual.update_attributes!(comment_status: 2) if homework.end_time <= time
# 实训作业的作品需要计算是否迟交
if homework.homework_type == "practice"
@ -1159,11 +1159,11 @@ class HomeworkCommonsController < ApplicationController
if homework_bank.present?
# 如果作业加入过题库则更新参数
if homework_bank.homework_type == 1
homework_bank.update_attributes(name: homework.name, description: homework.description,
homework_bank.update_attributes!(name: homework.name, description: homework.description,
reference_answer: homework.reference_answer, course_list_id: @course.course_list_id)
elsif homework_bank.homework_type == 3
homework_detail_group = homework.homework_detail_group
homework_bank.update_attributes(name: homework.name, description: homework.description,
homework_bank.update_attributes!(name: homework.name, description: homework.description,
reference_answer: homework.reference_answer, course_list_id: @course.course_list_id,
min_num: homework_detail_group.min_num, max_num: homework_detail_group.max_num,
base_on_project: homework_detail_group.base_on_project)
@ -1449,9 +1449,9 @@ class HomeworkCommonsController < ApplicationController
# 如果用户已有查重记录则更新相似度 否则新建一条记录
user_review = homework.homework_review_results.find_by(:user_id => user)
if user_review.present?
user_review.update_attributes(:code_rate => user_rate)
user_review.update_attributes!(:code_rate => user_rate)
else
homework.homework_review_results.create(:user_id => user, :code_rate => user_rate)
homework.homework_review_results.create!(:user_id => user, :code_rate => user_rate)
end
end
nuser_ids = results.user_lists.map(&:user_id).uniq

@ -8,7 +8,15 @@ class ItemBanksController < ApplicationController
items = ItemBankQuery.call(params)
@items_count = items.size
@items = paginate items.includes(:item_analysis, :user, :container)
@item_basket_ids = current_user.item_baskets.pluck(:item_bank_id)
exam = ExaminationBank.find_by(id: params[:exam_id]) if params[:exam_id].present?
exam_setting = ExaminationIntelligentSetting.find_by(id: params[:exam_setting_id]) if params[:exam_setting_id].present?
@item_basket_ids = if exam
exam.examination_items.pluck(:item_bank_id)
elsif exam_setting
exam_setting.item_baskets.pluck(:item_bank_id)
else
current_user.item_baskets.pluck(:item_bank_id)
end
end
def create

@ -4,7 +4,7 @@ class ItemBasketsController < ApplicationController
helper_method :current_basket
def index
@item_baskets = current_user.item_baskets
@item_baskets = basket_items
@single_questions = @item_baskets.where(item_type: "SINGLE")
@multiple_questions = @item_baskets.where(item_type: "MULTIPLE")
@judgement_questions = @item_baskets.where(item_type: "JUDGMENT")
@ -22,41 +22,41 @@ class ItemBasketsController < ApplicationController
end
def create
ItemBaskets::SaveItemBasketService.call(current_user, create_params)
ItemBaskets::SaveItemBasketService.call(current_user, create_params, exam_setting)
render_ok
rescue ApplicationService::Error => ex
render_error(ex.message)
end
def destroy
item = current_user.item_baskets.find_by!(item_bank_id: params[:id])
item = basket_items.find_by!(item_bank_id: params[:id])
ActiveRecord::Base.transaction do
current_user.item_baskets.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1")
basket_items.where(item_type: item.item_type).where("position > #{item.position}").update_all("position = position -1")
item.destroy!
end
render_ok
end
def delete_item_type
baskets = ItemBasket.where(item_type: params[:item_type])
baskets = basket_items.where(item_type: params[:item_type])
baskets.destroy_all
render_ok
end
def set_score
current_basket.update_attributes!(score: params[:score])
@questions_score = current_user.item_baskets.where(item_type: current_basket.item_type).pluck(:score).sum
@all_score = current_user.item_baskets.pluck(:score).sum
@questions_score = basket_items.where(item_type: current_basket.item_type).pluck(:score).sum
@all_score = basket_items.pluck(:score).sum
end
def batch_set_score
current_user.item_baskets.where(item_type: params[:item_type]).update_all(score: params[:score])
@questions_score = current_user.item_baskets.where(item_type: params[:item_type]).pluck(:score).sum
@all_score = current_user.item_baskets.pluck(:score).sum
basket_items.where(item_type: params[:item_type]).update_all(score: params[:score])
@questions_score = basket_items.where(item_type: params[:item_type]).pluck(:score).sum
@all_score = basket_items.pluck(:score).sum
end
def adjust_position
same_items = current_user.item_baskets.where(item_type: current_basket.item_type)
same_items = basket_items.where(item_type: current_basket.item_type)
max_position = same_items.size
tip_exception("position超出范围") unless params[:position].present? && params[:position].to_i <= max_position && params[:position].to_i >= 1
ActiveRecord::Base.transaction do
@ -79,8 +79,19 @@ class ItemBasketsController < ApplicationController
params.permit(item_ids: [])
end
def exam_setting
@_exam_setting = ExaminationIntelligentSetting.find_by(id: params[:exam_setting_id])
end
def basket_items
@_items = params[:exam_setting_id] ? exam_setting.item_baskets : current_user.item_baskets
end
def current_basket
@_current_basket = current_user.item_baskets.find_by!(id: params[:id])
@_current_basket = ItemBasket.find_by!(id: params[:id])
tip_exception(403, "无权限编辑") unless current_user.admin_or_business? || @_current_basket.user_id.to_i == current_user.id ||
@_current_basket.examination_intelligent_setting&.user_id.to_i == current_user.id
@_current_basket
end
def validate_score

@ -1,6 +1,6 @@
class MemosController < ApplicationController
before_action :require_login, except: [:show, :index]
before_action :check_account, only: [:new, :create]
before_action :check_account, only: [:new, :create, :reply]
before_action :set_memo, only: [:show, :edit, :update, :destroy, :sticky_or_cancel, :hidden, :more_reply]
before_action :validate_memo_params, only: [:create, :update]
before_action :owner_or_admin, only: [:edit, :update, :destroy]
@ -144,7 +144,7 @@ class MemosController < ApplicationController
def reply
tip_exception("parent_id不能为空") if params[:parent_id].blank?
tip_exception("content不能为空") if params[:content].blank?
tip_exception("content不能超过1000字符") if params[:content].length > 1000
tip_exception("内容不能超过2000字符") if params[:content].length > 2000
ActiveRecord::Base.transaction do
begin

@ -62,8 +62,8 @@ class MessagesController < ApplicationController
end
def reply
return normal_status(2, "回复内容不能为空") if params[:content].blank?
return normal_status(2, "回复内容不能超过1000字符") if params[:content].length > 1000
return normal_status(-1, "回复内容不能为空") if params[:content].blank?
return normal_status(-1, "回复内容不能超过2000字符") if params[:content].length > 2000
@reply = Message.create!(board: @message.board, root_id: @message.root_id || @message.id,
author: current_user, parent: @message,
message_detail_attributes: {

@ -3,7 +3,7 @@ class MyshixunsController < ApplicationController
before_action :find_myshixun, :except => [:training_task_status, :code_runinng_message]
before_action :find_repo_name, :except => [:training_task_status, :code_runinng_message]
skip_before_action :verify_authenticity_token, :only => [:html_content]
skip_before_action :check_sign, only: [:training_task_status, :code_runinng_message]
skip_before_action :check_sign, only: [:training_task_status, :code_runinng_message, :html_content]
## TPI关卡列表
def challenges

@ -44,7 +44,7 @@ class PollQuestionsController < ApplicationController
@poll.poll_questions.insert_question(ques_num).update_all("question_number = question_number + 1")
end
end
if @poll_question.save
if @poll_question.save!
if params[:question_type] != 3
p_answer = params[:question_answers]
p_other_answer = params[:question_other_answer]
@ -56,7 +56,7 @@ class PollQuestionsController < ApplicationController
:answer_text => answer
}
poll_answers = @poll_question.poll_answers.new question_option
poll_answers.save
poll_answers.save!
end
# 新增答案的其他选项
if p_other_answer
@ -65,7 +65,7 @@ class PollQuestionsController < ApplicationController
:answer_text => ''
}
poll_answers = @poll_question.poll_answers.new question_option
poll_answers.save
poll_answers.save!
end
end
end
@ -118,7 +118,7 @@ class PollQuestionsController < ApplicationController
if answer # 判断该位置的answer是否存在存在则更新.不存在则跳到下一步
answer.answer_text = p_answer[i-1]
answer.answer_position = i
answer.save
answer.save!
else
answer_options = {
:answer_position => i,
@ -137,12 +137,12 @@ class PollQuestionsController < ApplicationController
@poll_question.poll_answers.new question_option
else
other_answer.answer_position = p_answer_count + 1
other_answer.save
other_answer.save!
end
end
end
@poll_question.update_attributes(poll_questions_params)
@poll_question.update!(poll_questions_params)
rescue Exception => e
uid_logger_error(e.message)
tip_exception("更新失败")
@ -198,8 +198,8 @@ class PollQuestionsController < ApplicationController
if opr.to_s == "up"
last_q_p = @poll.poll_questions.find_by(question_number: (current_q_p-1)) #当前问题的前一个问题
if last_q_p.present?
@poll_question.update_attribute("question_number", (current_q_p - 1))
last_q_p.update_attribute("question_number", current_q_p) # 重新获取当前问题的位置
@poll_question.update!(question_number: (current_q_p - 1))
last_q_p.update!(question_number: current_q_p) # 重新获取当前问题的位置
normal_status(0, "问题上移成功!")
else
normal_status(-1, "移动失败,已经是第一个问题了!")
@ -207,8 +207,8 @@ class PollQuestionsController < ApplicationController
elsif opr.to_s == "down"
next_q_p = @poll.poll_questions.find_by(question_number: (current_q_p+1)) #当前问题的后一个问题
if next_q_p.present?
@poll_question.update_attribute("question_number", (current_q_p + 1))
next_q_p.update_attribute("question_number", current_q_p)
@poll_question.update!(question_number: (current_q_p + 1))
next_q_p.update!(question_number: current_q_p)
normal_status(0, "问题下移成功!")
else

@ -31,24 +31,24 @@ class PollVotesController < ApplicationController
current_user_answer = user_votes.first
if current_user_answer&.poll_answer_id != question_answer_id #如果说更换了答案,则以前的答案删除,并新建记录
current_user_answer.destroy
PollVote.create(vote_answer_params)
PollVote.create!(vote_answer_params)
else
if question_answer_text.present?
current_user_answer.update_attribute("vote_text", question_answer_text)
current_user_answer.update!(vote_text: question_answer_text)
end
end
else
PollVote.create(vote_answer_params)
PollVote.create!(vote_answer_params)
end
elsif question_type == 2 #多选题的话答案应该是1个以上
question_answer_ids = params[:poll_answer_id] ? params[:poll_answer_id] : [] #该答案的id
if question_answer_ids.present?
if question_answer_text.present? #有文字输入,但是不存在其他选项的
ques_vote_id = question_answer_ids.map(&:to_i).max
if user_votes.find_vote_text.present?
current_vote_text = user_votes.find_vote_text.first
current_vote_text.update_attribute("vote_text", question_answer_text)
ques_vote = user_votes.find_by(poll_answer_id: ques_vote_id)
if ques_vote.present?
ques_vote.update!(vote_text: question_answer_text)
else
answer_option = {
:user_id => current_user.id,
@ -56,7 +56,9 @@ class PollVotesController < ApplicationController
:poll_answer_id => ques_vote_id,
:vote_text => question_answer_text
}
PollVote.create(answer_option)
PollVote.create!(answer_option)
# 重新取一次poll_votes
user_votes = @poll_question.poll_votes.find_current_vote("user_id",current_user.id)
end
# if current_vote_text.present? #已有其他输入文字的选项
# current_vote_text.update_attribute("vote_text", question_answer_text)
@ -91,14 +93,14 @@ class PollVotesController < ApplicationController
else #主观题的输入
# current_vote_text = user_votes.find_vote_text
if user_votes.present?
user_votes.first.update_attribute("vote_text", question_answer_text)
user_votes.first.update!(vote_text: question_answer_text)
# if question_answer_text.present?
# user_votes.first.update_attribute("vote_text", question_answer_text)
# else
# user_votes.destroy_all
# end
else
PollVote.create(vote_answer_params)
PollVote.create!(vote_answer_params)
end
end
@current_question_number = @poll_question.question_number

@ -137,7 +137,7 @@ class PollsController < ApplicationController
:polls_status => 1,
:polls_type => "Course",
}
@poll = Poll.create(poll_options)
@poll = Poll.create!(poll_options)
rescue Exception => e
uid_logger_error(e.message)
tip_exception("问卷创建失败!")
@ -167,7 +167,7 @@ class PollsController < ApplicationController
:polls_name => poll_name,
:polls_description => poll_des
}
@poll.update_attributes(poll_params)
@poll.update!(poll_params)
normal_status(0,"问卷更新成功!")
rescue Exception => e
uid_logger_error(e.message)
@ -297,7 +297,7 @@ class PollsController < ApplicationController
poll_group_setting = poll.poll_group_settings.find_in_poll_group("course_group_id",i).first #根据课堂分班的id寻找问卷所在的班级
group_end_time = params[:detail] ? group_end_times[index] : ex_end_time
if poll_group_setting.present? #如果该问卷分组存在,则更新,否则新建
poll_group_setting.update_attributes!(publish_time: Time.now, end_time: group_end_time)
poll_group_setting.update!(publish_time: Time.now, end_time: group_end_time)
else
p_course_group = {
:poll_id => poll.id,
@ -326,7 +326,7 @@ class PollsController < ApplicationController
:polls_status => poll_status,
:unified_setting => poll_unified
}
poll.update_attributes(poll_params)
poll.update!(poll_params)
if poll.course_acts.size == 0
poll.course_acts << CourseActivity.new(:user_id => poll.user_id,:course_id => poll.course_id)
end
@ -390,10 +390,10 @@ class PollsController < ApplicationController
new_end_time = poll_group_setting.end_time_present.map(&:end_time) # 问卷结束时间不为空的
new_end_time_s = new_end_time.size > 0 ? new_end_time.max : Time.now
new_poll_status = set_poll_status(poll.publish_time,new_end_time_s)
poll.update_attributes(:end_time => new_end_time_s,:polls_status => new_poll_status,:unified_setting => poll_unified)
poll.update!(:end_time => new_end_time_s,:polls_status => new_poll_status,:unified_setting => poll_unified)
elsif poll.unified_setting
poll_users = poll.poll_users
poll.update_attributes(:polls_status => 3, :end_time => Time.now)
poll.update!(:polls_status => 3, :end_time => Time.now)
end
poll_users = poll_users.where("commit_status = 0 and start_at is not null")
poll_users.update_all(:commit_status => 1, :end_at => Time.now)
@ -470,7 +470,7 @@ class PollsController < ApplicationController
:publish_time => p_time,
:end_time => e_time
}
@poll.update_attributes(poll_options)
@poll.update!(poll_options)
normal_status(0,"分班问卷撤销发布成功!")
else
normal_status(-1,"请选择撤销发布班级!")
@ -490,7 +490,7 @@ class PollsController < ApplicationController
:end_time => nil,
:unified_setting => true
}
@poll.update_attributes(poll_new_params)
@poll.update!(poll_new_params)
@poll.poll_group_settings.destroy_all
normal_status(0,"问卷撤销发布成功!")
@ -531,7 +531,7 @@ class PollsController < ApplicationController
begin
check_ids = Poll.where(id:params[:check_ids])
check_ids.each do |poll|
poll.update_attribute('is_public', true)
poll.update!(is_public: true)
end
normal_status(0, "问卷已设为公开!")
rescue Exception => e
@ -555,13 +555,13 @@ class PollsController < ApplicationController
:description => poll.polls_description,
:course_list_id => poll.course.try(:course_list_id)
}
current_ex_bank.update_attributes(ex_params)
current_ex_bank.update!(ex_params)
question_bank = QuestionBank.ques_by_container(current_ex_bank.id,current_ex_bank.container_type) #该习题库是否存在于问题库里
ques_params = {
:name => current_ex_bank.name,
:course_list_id => current_ex_bank.course_list_id
}
question_bank.first.update_attributes(ques_params) if question_bank.present?
question_bank.first.update!(ques_params) if question_bank.present?
current_ex_bank.exercise_bank_questions.destroy_all # 更新后,习题库的问题全部删除,后续重新再建
else
ex_params = {
@ -575,7 +575,7 @@ class PollsController < ApplicationController
:quotes => 1
}
current_ex_bank= ExerciseBank.new ex_params
if current_ex_bank.save #如果习题库保存成功则会创建问题库question_bank
if current_ex_bank.save! #如果习题库保存成功则会创建问题库question_bank
ques_params = {
:name => current_ex_bank.name,
:container_id => current_ex_bank.id,
@ -586,9 +586,9 @@ class PollsController < ApplicationController
:course_list_id => current_ex_bank.course_list_id
}
question_bank = QuestionBank.new ques_params
question_bank.save
question_bank.save!
end
poll.update_attributes!(exercise_bank_id: current_ex_bank.id)
poll.update!(exercise_bank_id: current_ex_bank.id)
end
# 问卷的问题的输入
poll.poll_questions.each do |f|
@ -601,7 +601,7 @@ class PollsController < ApplicationController
:min_choices => f.min_choices
}
exercise_bank_question = current_ex_bank.exercise_bank_questions.new option
exercise_bank_question.save
exercise_bank_question.save!
## 问卷答案的输入
f.poll_answers.each do |a|
choice_option = {
@ -609,7 +609,7 @@ class PollsController < ApplicationController
:choice_text => a.answer_text
}
exercise_bank_c = exercise_bank_question.exercise_bank_choices.new choice_option
exercise_bank_c.save
exercise_bank_c.save!
end
end
end
@ -746,7 +746,7 @@ class PollsController < ApplicationController
:publish_time => params_publish_time,
:end_time => params_end_time
}
@poll.update_attributes(poll_params)
@poll.update!(poll_params)
@poll.poll_group_settings.destroy_all
normal_status(0, "问卷设置成功!")
end
@ -800,7 +800,7 @@ class PollsController < ApplicationController
:end_time => poll_end_time
}
end
the_group_setting.update_attributes(poll_group_params)
the_group_setting.update!(poll_group_params)
end
end
if new_group_ids.size > 0
@ -813,7 +813,7 @@ class PollsController < ApplicationController
:end_time => poll_end_time
}
new_poll_group = PollGroupSetting.new(poll_group_params)
new_poll_group.save
new_poll_group.save!
end
end
end
@ -848,7 +848,7 @@ class PollsController < ApplicationController
:publish_time => p_time,
:end_time => e_time
}
@poll.update_attributes(poll_params)
@poll.update!(poll_params)
if @poll.polls_status == 2
if @poll.course_acts.size == 0
@poll.course_acts << CourseActivity.new(:user_id => @poll.user_id,:course_id => @poll.course_id)
@ -880,10 +880,10 @@ class PollsController < ApplicationController
:start_at => Time.now,
:commit_status => 0
}
PollUser.create(poll_user_params)
PollUser.create!(poll_user_params)
end
elsif poll_user_current.start_at.nil?
poll_user_current.update_attributes(:start_at => Time.now)
poll_user_current.update!(:start_at => Time.now)
end
if @user_course_identity < Course::STUDENT || (@poll_status == 3) || (poll_user_current.present? && poll_user_current.commit_status == 1)
@ -963,7 +963,7 @@ class PollsController < ApplicationController
:commit_status => 1,
:end_at => Time.now
}
poll_user_current.update_attributes(poll_user_params)
poll_user_current.update!(poll_user_params)
CommitPollNotifyJobJob.perform_later(@poll.id, current_user.id)
normal_status(0, "问卷提交成功!")
end

@ -888,13 +888,15 @@ class ShixunsController < ApplicationController
def upload_git_file
upload_file = params["file"]
uid_logger("#########################file_params####{params["#{params[:file]}"]}")
uid_logger("#########################file_params##: #{params["file"]}")
raise "未上传文件" unless upload_file
content = upload_file.tempfile.read
uid_logger("#########################content####{content}")
author_name = current_user.real_name
author_email = current_user.git_mail
message = params[:message] || "upload file by browser"
update_file_content(content, @repo_path, @path, author_email, author_name, message)
uid_logger("-----author_email: #{author_email}")
update_file_base64_content(content, @repo_path, @path, author_email, author_name, message)
render_ok
end

@ -68,7 +68,7 @@ class StudentWorksController < ApplicationController
begin
work = @homework.student_works.find_by!(user_id: params[:user_id])
tip_exception("只有组长才能删除组员") if work.commit_user_id != current_user.id
work.update_attributes(description: nil, project_id: 0,
work.update_attributes!(description: nil, project_id: 0,
late_penalty: 0, work_status: 0,
commit_time: nil, update_time: nil, group_id: 0,
commit_user_id: nil, final_score: nil, work_score: nil, teacher_score: nil, teaching_asistant_score: nil)
@ -112,7 +112,7 @@ class StudentWorksController < ApplicationController
student_ids += members
for i in 0 .. members.count-1
stu_work = @homework.student_works.find_or_initialize_by(user_id: members[i].to_i)
stu_work.update_attributes(user_id: members[i].to_i, description: student_work.description,
stu_work.update_attributes!(user_id: members[i].to_i, description: student_work.description,
homework_common_id: @homework.id, project_id: student_work.project_id,
late_penalty: student_work.late_penalty, work_status: student_work.work_status,
commit_time: Time.now, update_time: Time.now, group_id: student_work.group_id,
@ -177,7 +177,7 @@ class StudentWorksController < ApplicationController
# 原成员更新描述、更新时间以及附件
@homework.student_works.where(group_id: @work.group_id, user_id: (work_user_ids & params_user_ids)).each do |work|
# work.update_attributes(update_time: Time.now, description: @work.description, commit_user_id: current_user.id)
work.update_attributes(update_time: Time.now, description: @work.description, update_user_id: current_user.id)
work.update_attributes!(update_time: Time.now, description: @work.description, update_user_id: current_user.id)
work.attachments.destroy_all
@work.attachments.each do |attachment|
att = attachment.copy
@ -202,7 +202,7 @@ class StudentWorksController < ApplicationController
# 新增加的成员
(params_user_ids - work_user_ids).each do |user_id|
stu_work = @homework.student_works.find_or_initialize_by(user_id: user_id)
stu_work.update_attributes(user_id: user_id, description: @work.description, homework_common_id: @homework.id,
stu_work.update_attributes!(user_id: user_id, description: @work.description, homework_common_id: @homework.id,
project_id: @work.project_id, late_penalty: @work.late_penalty,
work_status: @work.work_status, commit_time: Time.now, update_time: Time.now,
group_id: @work.group_id, commit_user_id: @work.commit_user_id, update_user_id: current_user.id)
@ -257,14 +257,14 @@ class StudentWorksController < ApplicationController
work = @homework.student_works.find_or_create_by(user_id: current_user.id)
if work.work_status == 0 && work.project_id == 0
work.update_attributes(project_id: project.id, update_time: Time.now)
work.update_attributes!(project_id: project.id, update_time: Time.now)
# 将老师加入项目
project_member = project.members.find_by_user_id(@homework.user_id)
if project_member.present?
project_member.member_roles.take.update_attributes(role_id: 3) if project_member.member_roles.take.present?
project_member.member_roles.take.update_attributes!(role_id: 3) if project_member.member_roles.take.present?
else
member = Member.create(user_id: @homework.user_id, project_id: project.id)
member = Member.create!(user_id: @homework.user_id, project_id: project.id)
member.member_roles << MemberRole.new(role_id: 3)
Tiding.create(user_id: @homework.user_id, trigger_user_id: current_user.id, container_id: project.id,
container_type: 'ManagerJoinProject', belong_container_id: project.id,
@ -295,7 +295,7 @@ class StudentWorksController < ApplicationController
Tiding.where(user_id: @homework.user_id, trigger_user_id: current_user.id, container_id: work.project.id,
container_type: 'ManagerJoinProject').destroy_all
work.update_attributes(project_id: 0)
work.update_attributes!(project_id: 0)
normal_status(0,"取消关联成功")
rescue Exception => e
@ -329,9 +329,9 @@ class StudentWorksController < ApplicationController
# end
Attachment.associate_container(params[:attachment_ids], @work.id, @work.class, 7)
revise_attachment = Attachment.where(attachtype: 7, container_id: @work.id, container_type: "StudentWork").last
revise_attachment.update_attributes(description: params[:description]) if revise_attachment.present?
revise_attachment.update_attributes!(description: params[:description]) if revise_attachment.present?
@work.update_attributes(update_time: Time.now)
@work.update_attributes!(update_time: Time.now)
# 补交附件时给评阅过作品的教师、助教发消息
unless @work.student_works_scores.where.not(score: nil).where(reviewer_role: [1, 2]).pluck(:user_id).uniq.blank?
@ -376,9 +376,9 @@ class StudentWorksController < ApplicationController
# 如果作品是未提交的状态则更新为已提交
if @user_course_identity < Course::STUDENT && !new_score.score.nil? && @work.work_status == 0
@work.update_attributes(work_status: 1, commit_time: Time.now)
@work.update_attributes!(work_status: 1, commit_time: Time.now)
# 分组作业更新分组id
@work.update_attributes(group_id: @homework.max_group_id) if @homework.homework_type == "group"
@work.update_attributes!(group_id: @homework.max_group_id) if @homework.homework_type == "group"
end
new_score.reviewer_role = reviewer_role
@ -442,7 +442,7 @@ class StudentWorksController < ApplicationController
# 实训作品的总结
def update_des
@work.update_attributes(des_params)
@work.update_attributes!(des_params)
tip_exception(0, "提交成功")
end
@ -590,7 +590,7 @@ class StudentWorksController < ApplicationController
begin
score = @work.student_works_scores.find_by!(id: params[:score_id])
jour = score.journals_for_messages.new(user_id: current_user.id, notes: params[:comment], reply_id: score.user_id)
jour.save
jour.save!
normal_status(0,"回复成功")
rescue Exception => e
uid_logger(e.message)
@ -624,7 +624,7 @@ class StudentWorksController < ApplicationController
score_appeal = nil
ActiveRecord::Base.transaction do
begin
score.update_attributes(appeal_status: 1)
score.update_attributes!(appeal_status: 1)
score_appeal = StudentWorksScoresAppeal.create!(user_id: current_user.id, student_works_score_id: score.id,
comment: params[:comment], appeal_status: 1)
@ -645,9 +645,9 @@ class StudentWorksController < ApplicationController
if score.present? && score.appeal_status == 1
ActiveRecord::Base.transaction do
begin
score.update_attributes(appeal_status: 2)
score.update_attributes!(appeal_status: 2)
score_appeal = score.student_works_scores_appeal
score_appeal.update_attributes(appeal_status: 2)
score_appeal.update_attributes!(appeal_status: 2)
score_appeal.tidings.destroy_all
normal_status(0,"撤销成功")
rescue Exception => e
@ -670,18 +670,18 @@ class StudentWorksController < ApplicationController
ActiveRecord::Base.transaction do
begin
# 更新appeal_status的值
score.update_attributes(appeal_status: params[:status].to_i)
score.update_attributes!(appeal_status: params[:status].to_i)
score_appeal = score.student_works_scores_appeal
score_appeal.update_attributes(appeal_status: params[:status].to_i)
score_appeal.update_attributes!(appeal_status: params[:status].to_i)
score_appeal.tidings.update_all(status: 1)
if params[:status].to_i == 3
# 申诉成功后该评分失效
score.update_attributes(is_invalid: 1)
score.update_attributes!(is_invalid: 1)
# 申诉成功后 扣匿评学生的违规匿评扣分
sw = @homework.student_works.find_by(user_id: score.user_id)
sw.update_attribute("appeal_penalty", @homework.homework_detail_manual.appeal_penalty + sw.appeal_penalty) if sw.present?
sw.update_attributes!(appeal_penalty: @homework.homework_detail_manual.appeal_penalty + sw.appeal_penalty) if sw.present?
# 申诉成功 重新计算申诉者的匿评分
if @work.student_works_scores.where("reviewer_role = 3 AND appeal_status != 3").count > 0
@ -689,7 +689,7 @@ class StudentWorksController < ApplicationController
else
@work.student_score = nil
end
@work.save
@work.save!
end
# todo tiding
@ -737,7 +737,7 @@ class StudentWorksController < ApplicationController
else
comment = "根据实训报告中最终提交的代码调整第#{challenge.position}关分数"
end
challenge_score = @work.challenge_work_scores.create(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score],
challenge_score = @work.challenge_work_scores.create!(challenge_id: params[:challenge_id], user_id: current_user.id, score: params[:score],
comment: comment)
challenge_score.create_tiding current_user.id
if @work.work_status != 0 && @work.myshixun
@ -862,7 +862,7 @@ class StudentWorksController < ApplicationController
else
st_work.student_score = student_work.student_score
end
st_work.save
st_work.save!
Tiding.create(user_id: st_work.user_id, trigger_user_id: current_user.id, container_id: st_score.id,
container_type: "StudentWorksScore", parent_container_id: st_work.id, parent_container_type: "StudentWork",

@ -5,7 +5,7 @@ class SubjectsController < ApplicationController
before_action :find_subject, except: [:index, :create, :new, :append_to_stage, :add_shixun_to_stage]
before_action :allowed, only: [:update, :edit, :destroy, :publish, :cancel_publish, :cancel_has_publish,
:search_members, :add_subject_members, :statistics, :shixun_report, :school_report,
:up_member_position, :down_member_position, :update_team_title]
:up_member_position, :down_member_position, :update_team_title, :statistics_info]
before_action :require_admin, only: [:copy_subject]
before_action :shixun_marker, only: [:add_shixun_to_stage]
@ -13,6 +13,7 @@ class SubjectsController < ApplicationController
include ApplicationHelper
include SubjectsHelper
include GitCommon
include CustomSortable
def index
@tech_system = current_laboratory.subject_repertoires
@ -92,7 +93,7 @@ class SubjectsController < ApplicationController
@is_creator = current_user.creator_of_subject?(@subject)
@is_manager = @user.manager_of_subject?(@subject)
# 合作团队
@shixuns = @subject.shixuns.published.pluck(:id)
# @shixuns = @subject.shixuns.published.pluck(:id)
@courses = @subject.courses if @subject.excellent
@members = @subject.subject_members.includes(:user)
@ -456,7 +457,7 @@ class SubjectsController < ApplicationController
end
end
def statistics_new
def statistics_info
# data = Subjects::DataStatisticService.new(@subject)
# Rails.logger.info("study_count: #{data.study_count}")
# Rails.logger.info("course_study_count: #{ data.course_study_count}")
@ -470,9 +471,19 @@ class SubjectsController < ApplicationController
# data_2 = Subjects::ShixunUsedInfoService.call(@subject)
# Rails.logger.info("study_count: #{data_2}")
data_3 = Subjects::UserUsedInfoService.call(@subject)
Rails.logger.info("study_count: #{data_3}")
render_ok()
# data_3 = Subjects::UserUsedInfoService.call(@subject)
# Rails.logger.info("study_count: #{data_3}")
@data =
if params[:type] == "shixun_info"
@subject.subject_shixun_infos
elsif params[:type] == "user_info"
@subject.subject_user_infos
else
@subject.subject_course_records
end
@data = paginate custom_sort(@data, params[:sort_by], params[:sort_direction])
end
def shixun_report

@ -2,7 +2,10 @@ class TagDisciplinesController < ApplicationController
before_action :require_login
def create
tip_exception("请输入知识点") if params[:name].blank?
tip_exception("输入字符长度限制在15个以内") if params[:name].length > 15
sub_discipline = SubDiscipline.find_by!(id: params[:sub_discipline_id])
tip_exception("重复的知识点") if sub_discipline.tag_disciplines.exists?(name: params[:name].to_s.strip)
tag_discipline = TagDiscipline.create!(name: params[:name].to_s.strip, sub_discipline: sub_discipline, user_id: current_user.id)
render_ok({tag_discipline_id: tag_discipline.id})
end

@ -9,18 +9,18 @@ class Users::InterestsController < Users::BaseController
extension = current_user.user_extension || current_user.build_user_extension
return render_error('请选择职业') unless %w(teacher student professional).include?(identity)
interest_ids = Array.wrap(params[:interest_ids]).map(&:to_i)
return render_error('请选择兴趣') if interest_ids.blank?
# interest_ids = Array.wrap(params[:interest_ids]).map(&:to_i)
# return render_error('请选择兴趣') if interest_ids.blank?
ActiveRecord::Base.transaction do
extension.update_column(:identity, identity)
# 兴趣
UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker|
(Repertoire.pluck(:id) & interest_ids).each do |repertoire_id|
worker.add(user_id: current_user.id, repertoire_id: repertoire_id)
end
end
# UserInterest.bulk_insert(:user_id, :repertoire_id) do |worker|
# (Repertoire.pluck(:id) & interest_ids).each do |repertoire_id|
# worker.add(user_id: current_user.id, repertoire_id: repertoire_id)
# end
# end
end
render_ok

@ -19,11 +19,10 @@ class Weapps::VerificationCodesController < Weapps::BaseController
return render_error('请输入正确的邮箱或手机号')
end
code = %W(0 1 2 3 4 5 6 7 8 9)
verification_code = code.sample(6).join
send_type = login =~ /^1\d{10}$/ ? 1 : 8
# 记录验证码
check_verification_code(verification_code, send_type, login)
# 发送验证码
send_code(send_type, login)
render_ok
end
@ -40,12 +39,21 @@ class Weapps::VerificationCodesController < Weapps::BaseController
return render_error('请输入正确的邮箱或手机号')
end
send_type = login =~ /^1\d{10}$/ ? 2 : 3
# 发送验证码
send_code(send_type, login)
render_ok
end
def send_code send_type, login
code = %W(0 1 2 3 4 5 6 7 8 9)
verification_code = code.sample(6).join
send_type = login =~ /^1\d{10}$/ ? 2 : 3
# 记录验证码
check_verification_code(verification_code, send_type, login)
sign = Digest::MD5.hexdigest("#{OPENKEY}#{login}")
tip_exception(501, "请求不合理") if sign != params[:smscode]
render_ok
check_verification_code(verification_code, send_type, login)
end
end

@ -6,7 +6,7 @@ class ExaminationBanks::SaveExamForm
validates :discipline_id, presence: true
validates :sub_discipline_id, presence: true
validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
validates :name, presence: true, length: { maximum: 60 }
validates :name, presence: true, length: { maximum: 60, too_long: "不能超过60个字符" }
validate :validate_duration
def validate_duration

@ -0,0 +1,12 @@
class ExaminationIntelligentSettings::SaveExamForm
include ActiveModel::Model
attr_accessor :name, :duration
validates :name, presence: true, length: { maximum: 60 }
validate :validate_duration
def validate_duration
raise '时长应为大于0的整数' if duration.present? && duration.to_i < 1
end
end

@ -0,0 +1,11 @@
class ExaminationIntelligentSettings::SaveExamSettingForm
include ActiveModel::Model
attr_accessor :discipline_id, :sub_discipline_id, :source, :difficulty, :tag_discipline_id, :question_settings
validates :discipline_id, presence: true
validates :sub_discipline_id, presence: true
validates :source, presence: true
validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
validates :question_settings, presence: true
end

@ -7,17 +7,17 @@ class ItemBanks::SaveItemForm
validates :sub_discipline_id, presence: true
validates :item_type, presence: true, inclusion: {in: %W(SINGLE MULTIPLE JUDGMENT COMPLETION SUBJECTIVE PRACTICAL PROGRAM)}
validates :difficulty, presence: true, inclusion: {in: 1..3}, numericality: { only_integer: true }
validates :name, presence: true, length: { maximum: 1000 }
validates :analysis, length: { maximum: 1000 }
validates :name, presence: true, length: { maximum: 1000, too_long: "不能超过1000个字符" }
validates :analysis, length: { maximum: 1000, too_long: "不能超过1000个字符" }
def validate!
super
return unless errors.blank?
choices.each { |item| SubForm.new(item).validate! } if %W(SINGLE MULTIPLE JUDGMENT).include?(item_type)
return unless errors.blank?
if [0, 2].include?(item_type) && choices.pluck(:is_answer).select{|item| item == 1}.length > 1
if ["SINGLE", "JUDGMENT"].include?(item_type) && choices.pluck(:is_answer).select{|item| item == 1}.length > 1
raise("正确答案只能有一个")
elsif item_type == 1 && choices.pluck(:is_answer).select{|item| item == 1}.length <= 1
elsif item_type == "MULTIPLE" && choices.pluck(:is_answer).select{|item| item == 1}.length <= 1
raise("多选题至少有两个正确答案")
end
end
@ -27,7 +27,7 @@ class ItemBanks::SaveItemForm
attr_accessor :choice_text, :is_answer
validates :choice_text, presence: true, length: { maximum: 100 }
validates :choice_text, presence: true, length: { maximum: 500, too_long: "不能超过500个字符" }
validates :is_answer, presence: true, inclusion: {in: 0..1}, numericality: { only_integer: true }
end
end

@ -4,7 +4,7 @@ module Validate
attr_accessor :nickname, :lastname
validates :nickname, presence: true, length: { maximum: 10 }
validates :nickname, presence: true, length: { maximum: 10, too_long: "不能超过10个字符" }
validates :lastname, presence: true
end
end

@ -530,7 +530,7 @@ module ExercisesHelper
exercise_cha_score = 0.0
answer_status = 0
# if game.status == 2 && game.final_score >= 0
if game.final_score > 0 && game.end_time && game.end_time < exercise_end_time
if game.final_score > 0 && (game.end_time.nil? || 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

@ -851,7 +851,8 @@ module ExportHelper
def make_zip_name(work, file_name="")
Rails.logger.info("######################file_name: #{file_name}")
# name = file_name === "" ? "" : (file_name[0, file_name.rindex('.')]+"_")
"#{work&.homework_common.course&.user_group_name(work.user_id)}_#{work&.user&.student_id}_#{work&.user&.real_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
course = work.is_a?(StudentWork) ? work&.homework_common&.course : work&.graduation_task&.course
"#{course&.user_group_name(work.user_id)}_#{work&.user&.student_id}_#{work&.user&.real_name}_#{Time.now.strftime('%Y%m%d_%H%M%S')}"
end
def zipping(zip_name_refer, files_paths, output_path, is_attachment=false, not_exist_file=[])

@ -1,10 +1,10 @@
module SubjectsHelper
# 实训路径的发布状态
def publish_status subject, is_manager, user, shixuns
def publish_status subject, is_manager, user
status = -1
if is_manager
status = 0 if subject.status == 0 && shixuns.count > 0
status = 0 if subject.status == 0
status = 1 if subject.status == 1
status = 2 if subject.status == 2 && user.admin?
end

@ -25,7 +25,7 @@ class Attachment < ApplicationRecord
scope :search_by_container, -> (ids) {where(container_id: ids)}
scope :unified_setting, -> {where("unified_setting = ? ", 1)}
validates_length_of :description, maximum: 100
validates_length_of :description, maximum: 100, message: "不能超过100个字符"
DCODES = %W(2 3 4 5 6 7 8 9 a b c f e f g h i j k l m n o p q r s t u v w x y z)

@ -28,7 +28,7 @@ class Challenge < ApplicationRecord
scope :fields_for_list, -> { select([:id, :subject, :st, :score, :position, :shixun_id]) }
validates :task_pass, length: { maximum: 10000 }
validates :task_pass, length: { maximum: 10000, too_long: "不能超过10000个字符" }
after_commit :create_diff_record

@ -3,7 +3,7 @@ class ChallengeAnswer < ApplicationRecord
belongs_to :challenge
has_many :game_answers, :dependent => :destroy
validates :contents, length: { maximum: 5000 }
validates :contents, length: { maximum: 5000 , too_long: "不能超过5000个字符"}
def view_answer_time(user_id)
game_answers.where(user_id: user_id).last&.view_time

@ -4,6 +4,6 @@ class ChallengeChoose < ApplicationRecord
has_many :challenge_tags, :dependent => :destroy
has_many :challenge_questions, dependent: :destroy
validates :subject, length: { maximum: 1000 }
validates :subject, length: { maximum: 1000, too_long: "不能超过1000个字符" }
end

@ -1,6 +1,6 @@
class ChallengeQuestion < ApplicationRecord
belongs_to :challenge_choose
validates :option_name, length: { maximum: 500 }
validates :option_name, length: { maximum: 500, too_long: "不能超过500个字符" }
end

@ -4,6 +4,8 @@ class ChallengeWorkScore < ApplicationRecord
belongs_to :challenge
has_many :tidings, as: :container, dependent: :destroy
validates :comment, length: { maximum: 500, too_long: "不能超过500个字符" }
def create_tiding trigger_user_id
tidings << Tiding.new(user_id: student_work.user_id, trigger_user_id: trigger_user_id, container_id: id,
container_type: "ChallengeWorkScore", parent_container_id: student_work_id,

@ -2,5 +2,5 @@ class ChartRule < ApplicationRecord
belongs_to :competition
belongs_to :competition_stage, optional: true
validates :content, length: { maximum: 1000 }
validates :content, length: { maximum: 1000, too_long: "不能超过1000个字符" }
end

@ -33,7 +33,7 @@ class Competition < ApplicationRecord
has_many :competition_prizes, dependent: :destroy
has_many :competition_prize_users, dependent: :destroy
validates :introduction, length: { maximum: 500 }
validates :introduction, length: { maximum: 500, too_long: "不能超过500个字符" }
before_save :set_laboratory
after_create :create_competition_modules

@ -5,6 +5,6 @@ class CompetitionModuleMdContent < ApplicationRecord
# validates :name, presence: true
validates :content, presence: true
validates :content, length: { maximum: 10000 }
validates :content, length: { maximum: 10000 , too_long: "不能超过10000个字符"}
end

@ -108,7 +108,7 @@ class Course < ApplicationRecord
NORMAL = 6 # 普通用户
Anonymous = 7 # 普未登录
validates :name, presence: true, length: { maximum: 60 }
validates :name, presence: true, length: { maximum: 60, too_long: "不能超过60个字符" }
before_save :set_laboratory
after_create :create_board_sync, :act_as_course_activity, :send_tiding

@ -9,7 +9,7 @@ class CourseGroup < ApplicationRecord
has_many :homework_group_settings, :dependent => :destroy
scope :by_group_ids, lambda { |ids| where(id: ids)}
validates :name, length: { maximum: 60 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates_uniqueness_of :name, scope: :course_id, message: "不能创建相同名称的分班"
after_create :generate_invite_code

@ -5,7 +5,7 @@ class CourseModule < ApplicationRecord
# 二级目录
has_many :course_second_categories
validates :module_name, length: { maximum: 20 }
validates :module_name, length: { maximum: 20, too_long: "不能超过20个字符" }
scope :not_hidden, -> { where(hidden: 0) }
scope :graduation_module, -> { where(module_type: "graduation") }

@ -5,7 +5,7 @@ class CourseSecondCategory < ApplicationRecord
belongs_to :course_module
has_many :homework_commons
validates :name, length: { maximum: 60 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
def category_type_str
category_type == "graduation" && name == "毕设选题" ? "graduation_topics" : (

@ -4,6 +4,6 @@ class CourseStage < ApplicationRecord
has_many :course_stage_shixuns, -> { order("course_stage_shixuns.position ASC") }, dependent: :destroy
has_many :shixuns, :through => :course_stage_shixuns
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 300 }
validates :name, length: { maximum: 60 , too_long: "不能超过60个字符"}
validates :description, length: { maximum: 1000, too_long: "不能超过1000个字符" }
end

@ -13,7 +13,7 @@ class Discuss < ApplicationRecord
belongs_to :challenge, optional: true
validate :validate_sensitive_string
validates :content, length: { maximum: 1000 }
validates :content, length: { maximum: 2000, too_long: "不能超过2000个字符" }
after_create :send_tiding

@ -7,6 +7,10 @@ class ExaminationBank < ApplicationRecord
has_many :examination_items, -> {order(position: :asc)}, dependent: :destroy
def apply?
!public && ApplyAction.where(container_type: "ExaminationBank", container_id: id, status: 0).exists?
end
def question_count
examination_items.size
end

@ -0,0 +1,7 @@
class ExaminationIntelligentSetting < ApplicationRecord
belongs_to :sub_discipline
belongs_to :user
has_many :examination_type_settings, dependent: :destroy
has_many :tag_discipline_containers, as: :container, dependent: :destroy
has_many :item_baskets, dependent: :destroy
end

@ -0,0 +1,4 @@
class ExaminationTypeSetting < ApplicationRecord
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
belongs_to :examination_intelligent_setting
end

@ -19,8 +19,8 @@ class Exercise < ApplicationRecord
scope :exercise_search, lambda { |keywords|
where("exercise_name LIKE ?", "%#{keywords}%") unless keywords.blank?}
validates :exercise_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" }
validates :exercise_description, length: { maximum: 100 }
validates :exercise_name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :exercise_description, length: { maximum: 100, too_long: "不能超过100个字符" }
after_create :create_exercise_list

@ -11,6 +11,6 @@ class ExerciseAnswer < ApplicationRecord
scope :exercise_answer_is_right, -> {where("score > ?",0.0)} #判断答案是否正确根据分数总和大于0
scope :score_reviewed, lambda {where("score >= ?",0.0)} #是否评分,用于判断主观题的
validates :answer_text, length: { maximum: 5000 }
validates :answer_text, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end

@ -7,5 +7,5 @@ class ExerciseAnswerComment < ApplicationRecord
scope :search_answer_comments, lambda {|name,ids| where("#{name}":ids)}
validates :comment, length: { maximum: 100 }
validates :comment, length: { maximum: 100, too_long: "不能超过100个字符" }
end

@ -18,7 +18,7 @@ class ExerciseBank < ApplicationRecord
scope :exercise_bank_search, lambda { |keywords|
where("name LIKE ?", "%#{keywords}%") unless keywords.blank?}
validates :name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" }
validates :description, length: { maximum: 100, too_long: "100 characters is the maximum allowed" }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 100, too_long: "不能超过100个字符" }
end

@ -5,6 +5,6 @@ class ExerciseBankChoice < ApplicationRecord
scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
validates :choice_text, length: { maximum: 500 }
validates :choice_text, length: { maximum: 500, too_long: "不能超过500个字符" }
end

@ -11,7 +11,7 @@ class ExerciseBankQuestion < ApplicationRecord
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
validates :question_title, length: { maximum: 1000 }
validates :question_title, length: { maximum: 1000, too_long: "不能超过1000个字符" }
def question_type_name
case self.question_type

@ -4,6 +4,6 @@ class ExerciseBankStandardAnswer < ApplicationRecord
#attr_accessible :answer_text
scope :standard_by_ids, lambda { |s| where(exercise_bank_choice_id: s) }
validates :answer_text, length: { maximum: 5000 }
validates :answer_text, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end

@ -7,6 +7,6 @@ class ExerciseChoice < ApplicationRecord
scope :find_choice_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :left_choice_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
validates :choice_text, length: { maximum: 500 }
validates :choice_text, length: { maximum: 500, too_long: "不能超过500个字符" }
end

@ -16,7 +16,7 @@ class ExerciseQuestion < ApplicationRecord
scope :left_question_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
scope :find_objective_questions, -> {where("question_type != ?",4)} #查找全部客观题
validates :question_title, length: { maximum: 1000 }
validates :question_title, length: { maximum: 1000, too_long: "不能超过1000个字符" }
def question_type_name

@ -6,5 +6,5 @@ class ExerciseStandardAnswer < ApplicationRecord
scope :find_standard_answer_custom, lambda {|k,v| where("#{k} = ?",v)} #根据传入的参数查找问题
scope :standard_by_ids, lambda { |s| where(exercise_choice_id: s) }
validates :answer_text, length: { maximum: 5000 }
validates :answer_text, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end

@ -29,8 +29,8 @@ class GraduationTask < ApplicationRecord
belongs_to :gtask_bank, optional: true
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 5000 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
# 未提交
scope :unfinished, -> {where(status: 0)}

@ -19,10 +19,8 @@ class GraduationTopic < ApplicationRecord
#after_create :act_as_course_activity
# 课题名称和描述字段长度限制
validates :name, length: { maximum: 60,
too_long: "60 characters is the maximum allowed" }
validates :description, length: { maximum: 5000,
too_long: "5000 characters is the maximum allowed" }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
def status_name
case self.status

@ -19,7 +19,7 @@ class GraduationWork < ApplicationRecord
# has_many :formal_graduation_task_group_assignations, -> { formal }, class_name: "GraduationTaskGroupAssignation"
# has_many :temporary_graduation_task_group_assignations, -> { temporary }, class_name: "GraduationTaskGroupAssignation"
validates :description, length: { maximum: 5000 }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
scope :has_committed, lambda { where("work_status != 0") }

@ -5,5 +5,5 @@ class GraduationWorkScore < ApplicationRecord
belongs_to :graduation_task
has_many :attachments, as: :container, dependent: :destroy
validates :comment, length: { maximum: 1000 }
validates :comment, length: { maximum: 2000, too_long: "不能超过2000个字符" }
end

@ -9,6 +9,6 @@ class GtaskBank < ApplicationRecord
scope :myself, ->(user_id) { where(user_id: user_id)}
scope :is_public, -> { where(:is_public => true) }
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 5000 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end

@ -10,8 +10,6 @@ class GtopicBank < ApplicationRecord
# 课题名称和描述字段长度限制
validates :name, length: { maximum: 60,
too_long: "60 characters is the maximum allowed" }
validates :description, length: { maximum: 5000,
too_long: "5000 characters is the maximum allowed" }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end

@ -2,8 +2,8 @@ class Hack < ApplicationRecord
# status: 0 未发布; 1已发布
# diffcult: 难度 1简单2中等 3困难
# 编程题
validates_length_of :name, maximum: 60
validates_length_of :description, maximum: 5000
validates_length_of :name, maximum: 60, message: "不能超过60个字符"
validates_length_of :description, maximum: 5000, message: "不能超过5000个字符"
validates :description, presence: { message: "描述不能为空" }
validates :name, presence: { message: "名称不能为空" }
# 测试集

@ -1,6 +1,6 @@
class HackSet < ApplicationRecord
validates_length_of :input, maximum: 500
validates_length_of :output, maximum: 500
validates_length_of :input, maximum: 1000, message: "不能超过1000个字符"
validates_length_of :output, maximum: 1000, message: "不能超过1000个字符"
validates :input, presence: { message: "测试集输入不能为空" }
validates :output, presence: { message: "测试集输出不能为空" }
validates_uniqueness_of :input, scope: [:hack_id, :input], message: "多个测试集的输入不能相同"

@ -12,6 +12,6 @@ class HackUserLastestCode < ApplicationRecord
scope :mine_hack, ->(author_id){ where(user_id: author_id) }
scope :passed, -> {where(status: 1)}
validates_length_of :notes, maximum: 5000, message: "笔记不能超过5000个字"
validates_length_of :notes, maximum: 5000, message: "不能超过5000个字"
end

@ -10,7 +10,7 @@ class HomeworkBank < ApplicationRecord
scope :is_public, -> { where(is_public: true)}
scope :myself, ->(user_id) { where(user_id: user_id)}
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 15000 }
validates :reference_answer, length: { maximum: 15000 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 15000, too_long: "不能超过15000个字符" }
validates :reference_answer, length: { maximum: 15000, too_long: "不能超过15000个字符" }
end

@ -35,10 +35,10 @@ class HomeworkCommon < ApplicationRecord
# 学生的查重情况
has_many :homework_review_results, :dependent => :destroy
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 15000 }
validates :explanation, length: { maximum: 5000 }
validates :reference_answer, length: { maximum: 15000 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 15000, too_long: "不能超过15000个字符" }
validates :explanation, length: { maximum: 5000, too_long: "不能超过5000个字符" }
validates :reference_answer, length: { maximum: 15000, too_long: "不能超过15000个字符" }
# after_update :update_activity
before_destroy :update_homework_bank_quotes

@ -1,8 +1,8 @@
class Inform < ApplicationRecord
belongs_to :container, polymorphic: true, optional: true
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 5000 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
has_many :attachments, as: :container, dependent: :destroy

@ -1,3 +1,3 @@
class ItemAnalysis < ApplicationRecord
belongs_to :item_bank
belongs_to :item_bank, touch: true
end

@ -18,6 +18,10 @@ class ItemBank < ApplicationRecord
item_analysis&.analysis
end
def apply?
!public && ApplyAction.where(container_type: "ItemBank", container_id: id, status: 0).exists?
end
def type_string
result = case item_type
when "SINGLE"

@ -2,13 +2,6 @@ class ItemBasket < ApplicationRecord
enum item_type: { SINGLE: 0, MULTIPLE: 1, JUDGMENT: 2, COMPLETION: 3, SUBJECTIVE: 4, PRACTICAL: 5, PROGRAM: 6 }
belongs_to :item_bank
belongs_to :user
def all_score
User.current.item_baskets.map(&:score).sum
end
def question_count
User.current.item_baskets.size
end
belongs_to :user, optional: true
belongs_to :examination_intelligent_setting, optional: true
end

@ -1,3 +1,3 @@
class ItemChoice < ApplicationRecord
belongs_to :item_bank
belongs_to :item_bank, touch: true
end

@ -26,7 +26,7 @@ class JournalsForMessage < ApplicationRecord
# "is_comprehensive_evaluation", # 1 教师评论、2 匿评、3 留言
# "hidden", 隐藏、
validates :notes, length: { maximum: 1000 }
validates :notes, length: { maximum: 2000, too_long: "不能超过2000个字符" }
after_create :send_tiding

@ -13,7 +13,7 @@ class Library < ApplicationRecord
has_one :praise_tread_cache, foreign_key: :object_id
has_many :praise_treads, as: :praise_tread_object, dependent: :destroy
validates :content, length: { maximum: 5000 }
validates :content, length: { maximum: 5000, too_long: "不能超过5000个字符" }
validates :uuid, presence: true, uniqueness: true

@ -27,7 +27,7 @@ class Memo < ApplicationRecord
scope :hot, -> { order("all_replies_count desc, updated_at desc") }
scope :posts, -> { where(root_id: nil, forum_id: [3, 5]) }
validates :content, length: { maximum: 10000 }
validates :content, length: { maximum: 10000, too_long: "不能超过10000个字符" }
after_create :send_tiding

@ -33,7 +33,7 @@ class Message < ApplicationRecord
#转发表
# has_many :forwards, as: :from, dependent: :destroy
validates :subject, length: { maximum: 255 }
validates :subject, length: { maximum: 255, too_long: "不能超过255个字符" }
def update_content(content)
message_detail.update_attributes(content: content)

@ -1,5 +1,5 @@
class MessageDetail < ApplicationRecord
belongs_to :message, :touch => true
validates :content, length: { maximum: 5000 }
validates :content, length: { maximum: 10000, too_long: "内容不能超过10000个字符" }
end

@ -24,8 +24,8 @@ class Poll < ApplicationRecord
scope :poll_search, lambda { |keywords|
where("polls_name LIKE ?", "%#{keywords}%") unless keywords.blank?}
validates :polls_name, length: { maximum: 60, too_long: "60 characters is the maximum allowed" }
validates :polls_description, length: { maximum: 100 }
validates :polls_name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :polls_description, length: { maximum: 100, too_long: "不能超过100个字符" }
after_create :create_polls_list

@ -8,6 +8,6 @@ class PollAnswer < ApplicationRecord
scope :find_answer_by_custom, lambda {|k,v| where("#{k}":v)} #根据传入的参数查找问题
scope :left_answer_choose, lambda {|k,v| where("#{k} > ?",v)} #根据传入的参数查找问题
validates :answer_text, length: { maximum: 500 }
validates :answer_text, length: { maximum: 500, too_long: "不能超过500个字符" }
end

@ -9,7 +9,7 @@ class PollQuestion < ApplicationRecord
scope :ques_necessary, -> {where("is_necessary = ?",1)}
scope :insert_question, lambda {|k| where("question_number > ?",k)}
validates :question_title, length: { maximum: 1000 }
validates :question_title, length: { maximum: 1000, too_long: "不能超过1000个字符" }
def question_type_name
case self.question_type

@ -9,6 +9,6 @@ class PollVote < ApplicationRecord
scope :find_current_vote,lambda {|k,v| where("#{k}": v)}
scope :find_vote_text,-> {where("vote_text IS NOT NULL")}
validates :vote_text, length: { maximum: 5000 }
validates :vote_text, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end

@ -0,0 +1,34 @@
class ProgramBank < ApplicationRecord
def oj_language
result = case language
when '1'
then 'C'
when '2'
then 'C++'
when '3'
then 'Python'
when '4'
then 'Java'
end
result
end
def strip_description
strip_html description
end
def oj_sub_discipline_id
result = case language
when '1'
then 3
when '2'
then 4
when '3'
then 5
when '4'
then 2
end
result
end
end

@ -0,0 +1,2 @@
class ProgramBankTest < ApplicationRecord
end

@ -1,10 +1,10 @@
class ShixunInfo < ApplicationRecord
belongs_to :shixun
validates_uniqueness_of :shixun_id
validates_length_of :fork_reason, maximum: 60
validates_length_of :fork_reason, maximum: 60, message: "不能超过60个字符"
after_commit :create_diff_record
validates :description, length: { maximum: 5000 }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
private

@ -2,6 +2,6 @@ class ShixunWorkComment < ApplicationRecord
belongs_to :student_work
belongs_to :user
belongs_to :challenge, optional: true
validates :comment, length: { maximum: 500 }
validates :hidden_comment, length: { maximum: 500 }
validates :comment, length: { maximum: 500, too_long: "不能超过500个字符" }
validates :hidden_comment, length: { maximum: 500, too_long: "不能超过500个字符" }
end

@ -6,6 +6,6 @@ class Stage < ApplicationRecord
has_many :stage_shixuns, -> { order("stage_shixuns.position ASC") }, dependent: :destroy
has_many :shixuns, :through => :stage_shixuns
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 1000 }
validates :name, length: { maximum: 60 , too_long: "不能超过60个字符" }
validates :description, length: { maximum: 1000, too_long: "不能超过1000个字符" }
end

@ -19,7 +19,7 @@ class StudentWork < ApplicationRecord
before_save :set_work_score
validates :description, length: { maximum: 5000 }
validates :description, length: { maximum: 5000, too_long: "不能超过5000个字符" }
scope :has_committed, lambda { where("work_status != 0") }
# 未提交

@ -7,7 +7,7 @@ class StudentWorksScore < ApplicationRecord
has_many :tidings, as: :container, dependent: :destroy
has_many :attachments, as: :container, dependent: :destroy
validates :comment, length: { maximum: 1000 }
validates :comment, length: { maximum: 2000, too_long: "不能超过2000个字符" }
scope :shixun_comment, lambda { where(is_ultimate: 0) }

@ -31,9 +31,9 @@ class Subject < ApplicationRecord
has_many :subject_shixun_infos, dependent: :destroy
has_many :subject_user_infos, dependent: :destroy
validates :name, length: { maximum: 60 }
validates :description, length: { maximum: 8000 }
validates :learning_notes, length: { maximum: 2000 }
validates :name, length: { maximum: 60, too_long: "不能超过60个字符" }
validates :description, length: { maximum: 8000, too_long: "不能超过8000个字符" }
validates :learning_notes, length: { maximum: 2000, too_long: "不能超过2000个字符" }
scope :visible, lambda{where(status: 2)}
scope :published, lambda{where(status: 1)}

@ -1,5 +1,5 @@
class TagDisciplineContainer < ApplicationRecord
belongs_to :tag_discipline
belongs_to :container, polymorphic: true, optional: true
belongs_to :container, polymorphic: true, optional: true, touch: true
end

@ -1,7 +1,7 @@
class TestSet < ApplicationRecord
# match_rule: 匹配规则: full 完全匹配, last 末尾匹配
#
validates :input, length: { maximum: 5000 }
validates :input, length: { maximum: 5000 }
validates :input, length: { maximum: 5000, too_long: "不能超过5000个字符" }
validates :output, length: { maximum: 5000, too_long: "不能超过5000个字符" }
end

@ -1,5 +1,5 @@
class TrustieHack < ApplicationRecord
validates_length_of :description, maximum: 500
validates_length_of :description, maximum: 500, message: "不能超过500个字符"
has_many :hack_users, :dependent => :destroy
belongs_to :trustie_hackathon, counter_cache: true

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save