Merge branch 'dev_item_bank' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_item_bank
commit
e2ec78101f
@ -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,38 @@
|
||||
class ExaminationIntelligentSettings::SaveExaminationService < ApplicationService
|
||||
attr_reader :exam, :params, :exam_setting
|
||||
|
||||
def initialize(exam, params, exam_setting)
|
||||
@exam = exam
|
||||
@params = params
|
||||
@exam_setting = exam_setting
|
||||
end
|
||||
|
||||
def call
|
||||
ExaminationIntelligentSettings::SaveExamForm.new(params).validate!
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
exam.name = params[:name].to_s.strip
|
||||
exam.difficulty = exam_setting.difficulty
|
||||
exam.duration = params[:duration].present? ? params[:duration].to_i : nil
|
||||
exam.sub_discipline_id = exam_setting.sub_discipline_id
|
||||
exam.intelligent = 1
|
||||
exam.save!
|
||||
|
||||
# 知识点的创建
|
||||
exam_setting.tag_discipline_containers.each do |tag|
|
||||
exam.tag_discipline_containers << TagDisciplineContainer.new(tag_discipline_id: tag.tag_discipline_id)
|
||||
end
|
||||
|
||||
# 试题的复制
|
||||
exam_setting.item_baskets.includes(:item_bank).each do |basket|
|
||||
item = basket.item_bank
|
||||
if item.present?
|
||||
new_item = ExaminationItem.new
|
||||
new_item.new_item(item, exam, basket.score, basket.position)
|
||||
end
|
||||
end
|
||||
|
||||
exam_setting.destroy!
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,5 @@
|
||||
class AddIntelligentToExam < ActiveRecord::Migration[5.2]
|
||||
def change
|
||||
add_column :examination_banks, :intelligent, :boolean, default: false
|
||||
end
|
||||
end
|
Loading…
Reference in new issue