|
|
|
@ -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]
|
|
|
|
|
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]
|
|
|
|
|
: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
|
|
|
|
@ -104,6 +107,15 @@ class GraduationTasksController < ApplicationController
|
|
|
|
|
@work_list = @task.graduation_works.where(id: graduation_work_id)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 组员、组长作品的筛选
|
|
|
|
|
if @task.task_type == 2 && !params[:member_work].blank?
|
|
|
|
|
if params[:member_work].to_i == 1
|
|
|
|
|
@work_list = @work_list.where("user_id = commit_user_id")
|
|
|
|
|
elsif params[:member_work].to_i == 0
|
|
|
|
|
@work_list = @work_list.where("user_id != commit_user_id")
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 输入姓名和学号搜索
|
|
|
|
|
# TODO user_extension 如果修改 请调整
|
|
|
|
|
unless params[:search].blank?
|
|
|
|
@ -453,22 +465,27 @@ class GraduationTasksController < ApplicationController
|
|
|
|
|
tip_exception("评阅时间应当大于截止时间") if @task.cross_comment && params[:comment_time] <= @task.end_time
|
|
|
|
|
|
|
|
|
|
@task.comment_time = @task.cross_comment ? params[:comment_time] : nil
|
|
|
|
|
@task.comment_num = @task.cross_comment ? params[:comment_num].to_i : 3
|
|
|
|
|
@task.comment_status = @task.cross_comment ? params[:comment_status] : 0
|
|
|
|
|
if @task.cross_comment && params[:comment_status].to_i == 4
|
|
|
|
|
tip_exception("评阅数不能为空") if params[:comment_num].blank?
|
|
|
|
|
tip_exception("评阅数应大于0") if params[:comment_num].to_i < 1
|
|
|
|
|
|
|
|
|
|
@course.graduation_groups.each_with_index do |group, index|
|
|
|
|
|
ass_group = @task.graduation_task_group_assignations.find_by(graduation_group_id: group.id)
|
|
|
|
|
if ass_group.present? && params[:comment_group][index].present? && params[:comment_group][index] != "0"
|
|
|
|
|
ass_group.update_attributes(assign_graduation_group_id: params[:comment_group][index])
|
|
|
|
|
else
|
|
|
|
|
@task.graduation_task_group_assignations << GraduationTaskGroupAssignation.new(graduation_group_id: group.id,
|
|
|
|
|
assign_graduation_group_id: params[:comment_group][index])
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
@task.comment_status = 2 if @task.cross_comment && @task.comment_status == 0
|
|
|
|
|
|
|
|
|
|
@task.graduation_work_comment_assignations.destroy_all if !@task.cross_comment
|
|
|
|
|
# 去掉评阅设置
|
|
|
|
|
# @task.comment_num = @task.cross_comment ? params[:comment_num].to_i : 3
|
|
|
|
|
# @task.comment_status = @task.cross_comment ? params[:comment_status] : 0
|
|
|
|
|
# if @task.cross_comment && params[:comment_status].to_i == 4
|
|
|
|
|
# tip_exception("评阅数不能为空") if params[:comment_num].blank?
|
|
|
|
|
# tip_exception("评阅数应大于0") if params[:comment_num].to_i < 1
|
|
|
|
|
#
|
|
|
|
|
# @course.graduation_groups.each_with_index do |group, index|
|
|
|
|
|
# ass_group = @task.graduation_task_group_assignations.find_by(graduation_group_id: group.id)
|
|
|
|
|
# if ass_group.present? && params[:comment_group][index].present? && params[:comment_group][index] != "0"
|
|
|
|
|
# ass_group.update_attributes(assign_graduation_group_id: params[:comment_group][index])
|
|
|
|
|
# else
|
|
|
|
|
# @task.graduation_task_group_assignations << GraduationTaskGroupAssignation.new(graduation_group_id: group.id,
|
|
|
|
|
# assign_graduation_group_id: params[:comment_group][index])
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
# end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 公开设置
|
|
|
|
@ -493,6 +510,107 @@ class GraduationTasksController < ApplicationController
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def cross_comment_setting
|
|
|
|
|
@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].map(&:to_i) unless params[:group_ids].blank?
|
|
|
|
|
page = params[:page] ? params[:page].to_i : 1
|
|
|
|
|
limit = params[:limit] ? params[:limit].to_i : 10
|
|
|
|
|
|
|
|
|
|
# 取所有课堂的作品
|
|
|
|
|
if group_ids.sort == @course.course_groups.pluck(:id).sort
|
|
|
|
|
@work_list = @task.graduation_works
|
|
|
|
|
else
|
|
|
|
|
@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})
|
|
|
|
|
end
|
|
|
|
|
@user_count = @work_list.size
|
|
|
|
|
@work_list = @work_list.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?
|
|
|
|
|
@task.update_attributes(comment_status: 2)
|
|
|
|
|
works.each do |work|
|
|
|
|
|
# 之前分配的老师但现在未分配时需要删除
|
|
|
|
|
work.graduation_work_comment_assignations.where.not(user_id: params[:user_ids]).destroy_all
|
|
|
|
|
@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)
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
# 答辩组分配:分配答辩组
|
|
|
|
|
elsif !params[:graduation_group_ids].blank?
|
|
|
|
|
@task.update_attributes(comment_status: 4)
|
|
|
|
|
works.each do |work|
|
|
|
|
|
work.graduation_task_group_assignations.where.not(graduation_group_id: params[:graduation_group_ids]).destroy_all
|
|
|
|
|
@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)
|
|
|
|
|
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
|
|
|
|
|
def find_task
|
|
|
|
|
begin
|
|
|
|
@ -533,6 +651,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
|
|
|
|
|