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

dev_jupyter
杨树林 5 years ago
commit e2ec78101f

@ -1,6 +1,6 @@
class ExaminationIntelligentSettingsController < ApplicationController
before_action :require_login
before_action :find_exam, only: [:exchange_one_item, :exchange_items]
before_action :find_exam, only: [:exchange_one_item, :exchange_items, :save_exam]
def optinal_items
sub_discipline_id = params[:sub_discipline_id]
@ -26,6 +26,15 @@ class ExaminationIntelligentSettingsController < ApplicationController
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)
@ -86,4 +95,8 @@ class ExaminationIntelligentSettingsController < ApplicationController
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

@ -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

@ -102,6 +102,7 @@ Rails.application.routes.draw do
end
member do
post :save_exam
post :exchange_one_item
post :exchange_items
end

@ -0,0 +1,5 @@
class AddIntelligentToExam < ActiveRecord::Migration[5.2]
def change
add_column :examination_banks, :intelligent, :boolean, default: false
end
end
Loading…
Cancel
Save