实训作业的排序调整

dev_hs
cxt 5 years ago
parent b039fd5839
commit bdd02b3dbd

@ -41,7 +41,6 @@ class CoursesController < ApplicationController
before_action :find_board, only: :board_list
before_action :validate_page_size, only: :mine
before_action :course_tasks, only: [:tasks_list, :update_task_position]
before_action :find_container, only: [:update_task_position]
if RUBY_PLATFORM =~ /linux/
require 'simple_xlsx_reader'
@ -1150,17 +1149,20 @@ class CoursesController < ApplicationController
end
def update_task_position
tip_exception("缺少position参数") if params[:position].blank?
unless params[:position].to_i == @task.position
if params[:position].to_i < @task.position
@tasks.where("position < #{@task.position} and position >= ?", params[:position]).update_all("position = position + 1")
else
@tasks.where("position > #{@task.position} and position <= ?", params[:position]).update_all("position = position - 1")
Rails.logger.info("#######task_ids_length#{params[:task_ids].uniq.length}#########task_count:#{@tasks.count}")
tip_exception("task_ids参数有误") if params[:task_ids].blank? || params[:task_ids].uniq.length != @tasks.count
ActiveRecord::Base.transaction do
begin
@tasks.each do |task|
position = params[:task_ids].reverse.index(task.id).to_i + 1
task.update_attributes!(position: position)
end
@task.update_attributes(position: params[:position])
normal_status(0, "移动成功")
else
normal_status(-1, "位置没有变化")
rescue Exception => e
uid_logger(e.message)
tip_exception(e.message)
raise ActiveRecord::Rollback
end
end
end
@ -1247,24 +1249,24 @@ class CoursesController < ApplicationController
end
end
def find_container
case params[:container_type]
when 'shixun_homework', 'common_homework', 'group_homework'
@task = HomeworkCommon.find_by(id: params[:container_id])
when 'exercise'
@task = Exercise.find_by(id: params[:container_id])
when 'poll'
@task = Poll.find_by(id: params[:container_id])
when 'graduation_topic'
@task = GraduationTopic.find_by(id: params[:container_id])
when 'graduation_task'
@task = GraduationTask.find_by(id: params[:container_id])
when 'attachment'
@task = Attachment.find_by(id: params[:container_id])
else
tip_exception("container_type参数有误")
end
end
# def find_container
# case params[:container_type]
# when 'shixun_homework', 'common_homework', 'group_homework'
# @task = HomeworkCommon.find_by(id: params[:container_id])
# when 'exercise'
# @task = Exercise.find_by(id: params[:container_id])
# when 'poll'
# @task = Poll.find_by(id: params[:container_id])
# when 'graduation_topic'
# @task = GraduationTopic.find_by(id: params[:container_id])
# when 'graduation_task'
# @task = GraduationTask.find_by(id: params[:container_id])
# when 'attachment'
# @task = Attachment.find_by(id: params[:container_id])
# else
# tip_exception("container_type参数有误")
# end
# end
def student_act_score group_id, search
sql_select = %Q{SELECT cm.*,(

@ -9,6 +9,7 @@ class HomeworksService
homework_detail_manual = HomeworkDetailManual.new
homework.homework_detail_manual = homework_detail_manual
homework.position = course.practice_homeworks.first&.position.to_i + 1
if homework.save!
homework_detail_manual.save! if homework_detail_manual

@ -1,13 +1,5 @@
class MigrateCourseTaskPosition < ActiveRecord::Migration[5.2]
def change
add_column :homework_commons, :position, :integer, :default => 0
Course.find_each do |course|
puts course.id
course.practice_homeworks.order("IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC,
homework_commons.created_at DESC").reverse.each_with_index do |homework, index|
homework.update_columns(position: index + 1)
end
end
end
end

@ -0,0 +1,11 @@
class MigrateCourseShixunHomeworkPosition < ActiveRecord::Migration[5.2]
def change
Course.find_each do |course|
puts course.id
course.practice_homeworks.order("IF(ISNULL(homework_commons.publish_time),0,1), homework_commons.publish_time DESC,
homework_commons.created_at DESC").reverse.each_with_index do |homework, index|
homework.update_columns(position: index + 1)
end
end
end
end
Loading…
Cancel
Save