diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 54c07d1c1..5ba0db363 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -451,7 +451,7 @@ class ApplicationController < ActionController::Base cpu_limit = config.cpu_limit.presence || 1 cpu_request = config.lower_cpu_limit.presence || 0.1 memory_limit = config.memory_limit.presence || 1024 - request_limit = config.resource_limit.presence || 10 + request_limit = config.request_limit.presence || 10 resource_limit = config.resource_limit.presence || 10000 container << {:image => mirror.name, :cpuLimit => cpu_limit, diff --git a/app/controllers/courses_controller.rb b/app/controllers/courses_controller.rb index 5c3f2e743..bfd7a4464 100644 --- a/app/controllers/courses_controller.rb +++ b/app/controllers/courses_controller.rb @@ -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 + normal_status(0, "移动成功") + rescue Exception => e + uid_logger(e.message) + tip_exception(e.message) + raise ActiveRecord::Rollback end - @task.update_attributes(position: params[:position]) - normal_status(0, "移动成功") - else - normal_status(-1, "位置没有变化") 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.*,( diff --git a/app/services/homeworks_service.rb b/app/services/homeworks_service.rb index a21614efc..78be3b8f9 100644 --- a/app/services/homeworks_service.rb +++ b/app/services/homeworks_service.rb @@ -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 diff --git a/db/migrate/20190820021047_migrate_course_task_position.rb b/db/migrate/20190820021047_migrate_course_task_position.rb index cf1b633bd..f32ac88b1 100644 --- a/db/migrate/20190820021047_migrate_course_task_position.rb +++ b/db/migrate/20190820021047_migrate_course_task_position.rb @@ -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 diff --git a/db/migrate/20190821072722_migrate_course_shixun_homework_position.rb b/db/migrate/20190821072722_migrate_course_shixun_homework_position.rb new file mode 100644 index 000000000..9a19b12e3 --- /dev/null +++ b/db/migrate/20190821072722_migrate_course_shixun_homework_position.rb @@ -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