|
|
|
@ -1,13 +1,16 @@
|
|
|
|
|
class GraduationTasksController < ApplicationController
|
|
|
|
|
before_action :require_login, :check_auth, except: [:index]
|
|
|
|
|
before_action :find_course, except: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment]
|
|
|
|
|
before_action :find_task, only: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment, :cross_comment_setting]
|
|
|
|
|
before_action :find_course, except: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment,
|
|
|
|
|
:cross_comment_setting, :assign_works, :commit_comment_setting]
|
|
|
|
|
before_action :find_task, only: [:edit, :update, :settings, :update_settings, :tasks_list, :show, :show_comment,
|
|
|
|
|
:cross_comment_setting, :assign_works, :commit_comment_setting]
|
|
|
|
|
before_action :user_course_identity
|
|
|
|
|
before_action :task_publish, only: [:show, :show_comment, :tasks_list, :settings]
|
|
|
|
|
before_action :teacher_allowed, only: [:new, :create, :edit, :update, :set_public,:multi_destroy, :publish_task, :end_task,
|
|
|
|
|
:update_settings, :add_to_bank, :cross_comment_setting]
|
|
|
|
|
:update_settings, :add_to_bank, :cross_comment_setting, :assign_works, :commit_comment_setting]
|
|
|
|
|
before_action :require_id_params, only: [:set_public ,:multi_destroy, :publish_task, :end_task, :add_to_bank]
|
|
|
|
|
before_action :valid_params, only: [:update_settings]
|
|
|
|
|
before_action :allow_cross_comment, only: [:cross_comment_setting, :assign_works, :commit_comment_setting]
|
|
|
|
|
include ExportHelper
|
|
|
|
|
|
|
|
|
|
def index
|
|
|
|
@ -99,8 +102,8 @@ class GraduationTasksController < ApplicationController
|
|
|
|
|
|
|
|
|
|
# 只看我的交叉评阅
|
|
|
|
|
unless params[:cross_comment].blank?
|
|
|
|
|
graduation_work_id = @task.graduation_work_comment_assignations.where(:user_id =>current_user.id)
|
|
|
|
|
.pluck(:graduation_work_id).uniq if @task.graduation_work_comment_assignations
|
|
|
|
|
graduation_work_id = @task.formal_graduation_work_comment_assignations.where(:user_id =>current_user.id)
|
|
|
|
|
.pluck(:graduation_work_id).uniq if @task.formal_graduation_work_comment_assignations
|
|
|
|
|
@work_list = @task.graduation_works.where(id: graduation_work_id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
@ -499,9 +502,94 @@ class GraduationTasksController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cross_comment_setting
|
|
|
|
|
@comment_status = @task.cross_comment ? @task.comment_status : (params[:comment_status] || 2)
|
|
|
|
|
user_ids = @course.teacher_group_user_ids(current_user.id)
|
|
|
|
|
@work_list = @task.graduation_works.where(user_id: user_ids).includes(user: [:user_extension])
|
|
|
|
|
@comment_status = params[:comment_status] || (@task.cross_comment ? @task.comment_status : 2)
|
|
|
|
|
group_ids = @course.charge_group_ids(current_user)
|
|
|
|
|
@course_groups = @course.course_groups.where(id: group_ids)
|
|
|
|
|
|
|
|
|
|
# 如果传了分班id则取合集
|
|
|
|
|
group_ids = group_ids & params[:group_ids] unless params[:group_ids].blank?
|
|
|
|
|
page = params[:page] ? params[:page].to_i : 1
|
|
|
|
|
limit = params[:limit] ? params[:limit].to_i : 10
|
|
|
|
|
@work_list = @task.graduation_works.joins("join course_members on graduation_works.user_id=course_members.user_id").
|
|
|
|
|
where(course_members: {course_group_id: group_ids}).page(page).per(limit).includes(user: [:user_extension])
|
|
|
|
|
@students = @course.students.where(user_id: @work_list.pluck(:user_id))
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def assign_works
|
|
|
|
|
tip_exception("请先选择作品") if params[:work_ids].blank?
|
|
|
|
|
tip_exception("请指定要分配的老师或答辩组") if params[:user_ids].blank? && params[:graduation_group_ids].blank?
|
|
|
|
|
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
works = @task.graduation_works.where(id: params[:work_ids])
|
|
|
|
|
# 手动分配:分配给老师
|
|
|
|
|
if !params[:user_ids].blank?
|
|
|
|
|
works.each do |work|
|
|
|
|
|
# 之前分配的老师但现在未分配时,置为删除位,点取消时需要还原,点确认时再删除
|
|
|
|
|
work.graduation_work_comment_assignations.where.not(user_id: params[:user_ids]).update_all(temporary: 2)
|
|
|
|
|
@course.teachers.where(user_id: params[:user_ids]).pluck(:user_id).uniq.each do |user_id|
|
|
|
|
|
unless work.graduation_work_comment_assignations.exists?(user_id: user_id)
|
|
|
|
|
GraduationWorkCommentAssignation.create!(graduation_task_id: @task.id, graduation_work_id: work.id,
|
|
|
|
|
user_id: user_id, temporary: 1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 答辩组分配:分配答辩组
|
|
|
|
|
elsif !params[:graduation_group_ids].blank?
|
|
|
|
|
works.each do |work|
|
|
|
|
|
work.graduation_task_group_assignations.where.not(graduation_group_id: params[:graduation_group_ids]).update_all(temporary: 2)
|
|
|
|
|
@course.graduation_groups.where(id: params[:graduation_group_ids]).pluck(:id).uniq.each do |graduation_group_id|
|
|
|
|
|
unless work.graduation_task_group_assignations.exists?(graduation_group_id: graduation_group_id)
|
|
|
|
|
GraduationTaskGroupAssignation.create!(graduation_task_id: @task.id, graduation_work_id: work.id,
|
|
|
|
|
graduation_group_id: graduation_group_id, temporary: 1)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
normal_status("分配成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def commit_comment_setting
|
|
|
|
|
tip_exception("type参数有误") if params[:type].blank? || !["commit", "cancel"].include?(params[:type])
|
|
|
|
|
ActiveRecord::Base.transaction do
|
|
|
|
|
begin
|
|
|
|
|
# 提交弹框
|
|
|
|
|
if params[:type] == "commit"
|
|
|
|
|
tip_exception("comment_status参数有误") if params[:comment_status].blank? || ![2, 4].include?(params[:comment_status].to_i)
|
|
|
|
|
@task.update_attributes(comment_status: params[:comment_status])
|
|
|
|
|
if params[:comment_status].to_i == 2
|
|
|
|
|
@task.temporary_graduation_work_comment_assignations.update_all(temporary: 0) # 临时数据转正
|
|
|
|
|
@task.delete_graduation_work_comment_assignations.destroy_all # 删除置了删除位的数据
|
|
|
|
|
@task.graduation_task_group_assignations.destroy_all # 删除答辩组分配数据
|
|
|
|
|
else
|
|
|
|
|
@task.temporary_graduation_task_group_assignations.update_all(temporary: 0)
|
|
|
|
|
@task.delete_graduation_task_group_assignations.destroy_all
|
|
|
|
|
@task.graduation_work_comment_assignations.destroy_all
|
|
|
|
|
|
|
|
|
|
GraduationTaskCrossCommentJob.perform_later(@task.id)
|
|
|
|
|
end
|
|
|
|
|
else
|
|
|
|
|
# 取消时删除临时数据,恢复删除位数据
|
|
|
|
|
@task.temporary_graduation_work_comment_assignations.destroy_all # 删除临时数据
|
|
|
|
|
@task.delete_graduation_work_comment_assignations.update_all(temporary: 0) # 恢复置了删除位的数据
|
|
|
|
|
|
|
|
|
|
@task.temporary_graduation_task_group_assignations.destroy_all # 删除临时数据
|
|
|
|
|
@task.delete_graduation_task_group_assignations.update_all(temporary: 0) # 恢复置了删除位的数据
|
|
|
|
|
end
|
|
|
|
|
normal_status("操作成功")
|
|
|
|
|
rescue Exception => e
|
|
|
|
|
uid_logger(e.message)
|
|
|
|
|
tip_exception(e.message)
|
|
|
|
|
raise ActiveRecord::Rollback
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
private
|
|
|
|
@ -544,6 +632,11 @@ class GraduationTasksController < ApplicationController
|
|
|
|
|
tip_exception("最大人数不能小于最小人数要求") if params[:min_num].to_i > params[:max_num].to_i
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def allow_cross_comment
|
|
|
|
|
tip_exception("请先开启交叉评阅再设置") unless @task.cross_comment
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
#
|
|
|
|
|
# def graduation_work_to_xls items
|
|
|
|
|
# xls_report = StringIO.new
|
|
|
|
|