毕设任务的评阅设置调整

dev_ec
cxt 5 years ago
parent cde399f97e
commit 0692caf427

@ -496,8 +496,8 @@ class ApplicationController < ActionController::Base
# 只看我的交叉评阅
if option[:cross_comment]
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 = work_list.where(id: graduation_work_id)
end

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

@ -308,7 +308,7 @@ class GraduationWorksController < ApplicationController
end
end
if @task.status == 3 && @task.graduation_work_comment_assignations.where(graduation_work_id: @work.id, user_id: current_user.id).count > 0
if @task.status == 3 && @task.formal_graduation_work_comment_assignations.where(graduation_work_id: @work.id, user_id: current_user.id).count > 0
new_score.reviewer_role = 2
else
new_score.reviewer_role = 1

@ -15,7 +15,7 @@ module GraduationTasksHelper
# 交叉评阅
def cross_comment task, user_id
if task.cross_comment && task.status >= 3
[{id: 1, name: "只看我的交叉评阅", count: task.graduation_work_comment_assignations.myself(user_id).count}]
[{id: 1, name: "只看我的交叉评阅", count: task.formal_graduation_work_comment_assignations.myself(user_id).count}]
else
[]
end

@ -6,32 +6,13 @@ class GraduationTaskCrossCommentJob < ApplicationJob
task = GraduationTask.find_by(id: graduation_task_id)
return if task.blank?
course = task.course
task.graduation_task_group_assignations.each do |assignation|
task.graduation_task_group_assignations.includes(:graduation_group, :graduation_work).each do |assignation|
graduation_group = assignation.graduation_group
assign_group = assignation.assign_group
if graduation_group.present? && assign_group.present?
course_group_ids = course.teacher_course_groups.where(course_member_id: graduation_group.course_members.pluck(:id)).pluck(:course_group_id)
graduation_works = task.graduation_works.where(user_id: course.course_members.where(:course_group_id => course_group_ids).map(&:user_id),
work_status: [1, 2])
if assign_group.course_members.count <= task.comment_num
graduation_works.each do |work|
assign_group.course_members.each do |member|
work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(
graduation_group_id: assign_group.id, user_id: member.user_id, graduation_task_id: task.id)
end
end
else
member_user_ids = assign_group.course_members.pluck(:user_id)
count = 0
graduation_works.each do |work|
for i in 1 .. task.comment_num
assign_user_id = member_user_ids[count % member_user_ids.size]
work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(
graduation_group_id: assign_group.id, user_id: assign_user_id, graduation_task_id: task.id)
count += 1
end
end
work = assignation.graduation_work
if graduation_group.present? && work.present?
member_ids = graduation_group.course_members.pluck(:user_id).uniq
member_ids.each do |user_id|
work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(user_id: user_id, graduation_task_id: task.id)
end
end
end

@ -13,8 +13,15 @@ class GraduationTask < ApplicationRecord
has_many :attachments, as: :container, dependent: :destroy
has_many :graduation_task_group_assignations, dependent: :destroy
has_many :graduation_work_comment_assignations, dependent: :destroy
has_many :formal_graduation_work_comment_assignations, -> { formal }, class_name: "GraduationWorkCommentAssignation"
has_many :temporary_graduation_work_comment_assignations, -> { temporary }, class_name: "GraduationWorkCommentAssignation"
has_many :delete_graduation_work_comment_assignations, -> { temporary_delete }, class_name: "GraduationWorkCommentAssignation"
has_many :graduation_task_group_assignations, dependent: :destroy
has_many :formal_graduation_task_group_assignations, -> { formal }, class_name: "GraduationTaskGroupAssignation"
has_many :temporary_graduation_task_group_assignations, -> { temporary }, class_name: "GraduationTaskGroupAssignation"
has_many :delete_graduation_task_group_assignations, -> { temporary_delete }, class_name: "GraduationTaskGroupAssignation"
has_many :graduation_works, -> { where("is_delete = 0") }
has_many :score_graduation_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "GraduationWork"

@ -1,6 +1,12 @@
class GraduationTaskGroupAssignation < ApplicationRecord
# temporary 0: 正式分配 1临时分配交叉评阅设置中临时分配的作品点取消时会删除 2: 删除标志
belongs_to :graduation_task
belongs_to :graduation_group
belongs_to :assign_group, class_name: 'GraduationGroup', foreign_key: :assign_graduation_group_id # 分配的互评组
belongs_to :assign_group, class_name: 'GraduationGroup', foreign_key: :assign_graduation_group_id, optional: true # 分配的互评组
belongs_to :graduation_work, optional: true
scope :temporary, -> {where(temporary: 1)}
scope :formal, -> {where(temporary: 0)}
scope :temporary_delete, -> {where(temporary: 2)}
scope :temporary_formal, -> {where(temporary: [0, 1])}
end

@ -9,7 +9,14 @@ class GraduationWork < ApplicationRecord
has_many :attachments, as: :container, dependent: :destroy
has_many :tidings, as: :container, dependent: :destroy
has_many :graduation_work_scores, dependent: :destroy
has_many :graduation_work_comment_assignations, dependent: :destroy
has_many :formal_graduation_work_comment_assignations, -> { formal }, class_name: "GraduationWorkCommentAssignation"
has_many :temporary_graduation_work_comment_assignations, -> { temporary }, class_name: "GraduationWorkCommentAssignation"
has_many :graduation_task_group_assignations, dependent: :destroy
has_many :formal_graduation_task_group_assignations, -> { formal }, class_name: "GraduationTaskGroupAssignation"
has_many :temporary_graduation_task_group_assignations, -> { temporary }, class_name: "GraduationTaskGroupAssignation"
validates :description, length: { maximum: 5000 }
@ -108,11 +115,21 @@ class GraduationWork < ApplicationRecord
end
end
# 作品被交叉评阅的次数
def cross_comment_num
graduation_work_scores.where(reviewer_role: 2).group_by(&:user_id).count
end
# 作品是否被评阅过
def scored?
graduation_work_scores.where.not(reviewer_role: 3).exists?
graduation_work_scores.where.not(core: nil).exists?
end
def work_cross_teachers
User.where(id: graduation_work_comment_assignations.temporary_formal.pluck(:user_id)).map(&:real_name).join("")
end
def work_cross_groups
course.graduation_groups.where(id: graduation_task_group_assignations.temporary_formal.pluck(:graduation_group_id)).pluck(:name).join("")
end
end

@ -1,8 +1,13 @@
class GraduationWorkCommentAssignation < ApplicationRecord
# temporary 0: 正式分配 1临时分配交叉评阅设置中临时分配的作品点取消时会删除 2: 删除标志
belongs_to :graduation_work
belongs_to :graduation_task
belongs_to :user
belongs_to :graduation_group
belongs_to :graduation_group, optional: true
scope :temporary, -> {where(temporary: 1)}
scope :formal, -> {where(temporary: 0)}
scope :temporary_delete, -> {where(temporary: 2)}
scope :temporary_formal, -> {where(temporary: [0, 1])}
scope :myself, ->(user_id) {where(user_id: user_id)}
end

@ -1,4 +1,5 @@
class GraduationWorkScore < ApplicationRecord
# reviewer_role 1 老师评分 2 交叉评分
belongs_to :graduation_work
belongs_to :user
belongs_to :graduation_task

@ -192,7 +192,7 @@ class StudentWork < ApplicationRecord
end
def scored?
student_works_scores.where.not(reviewer_role: 3).exists?
student_works_scores.where.not(reviewer_role: 3, score: nil).exists?
end
def work_challenge_score game, score
@ -201,7 +201,7 @@ class StudentWork < ApplicationRecord
if adjust_score.present?
game_score = adjust_score.score
else
setting = homework_common.homework_group_setting user_id
setting = homework_common.homework_group_setting game.user_id
if game.status == 2 && ((game.end_time && game.end_time < setting.end_time) || (homework_common.allow_late && game.end_time && game.end_time < homework_common.late_time))
answer_open_evaluation = homework_common.homework_detail_manual.answer_open_evaluation
game_score = answer_open_evaluation ? score : (game.final_score > 0 ? game.real_score(score) : 0)

@ -0,0 +1,26 @@
json.work_users @work_list do |work|
json.work_id work.id
json.user_name work.user&.real_name
json.student_id work.user&.student_id
json.course_group_name @students.select{|member| member.user_id == work.user_id}.first.try(:course_group_name)
if @comment_status.to_i == 2
json.cross_teachers work.work_cross_teachers
elsif @comment_status.to_i == 4
json.cross_groups work.work_cross_groups
end
end
json.course_groups @course_groups do |group|
json.(group, :id, :name)
end
if @comment_status.to_i == 2
json.teachers @course.teachers.includes(:user) do |teacher|
json.user_id teacher.user_id
json.user_name teacher.user&.real_name
end
elsif @comment_status.to_i == 4
json.graduation_groups @course.graduation_groups do |group|
json.(group, :id, :name)
end
end

@ -537,6 +537,8 @@ Rails.application.routes.draw do
get 'tasks_list'
get :show_comment
get :cross_comment_setting
post :assign_works
post :commit_comment_setting
end
collection do

@ -0,0 +1,7 @@
class AddGraduationWorkIdToGroupAssignations < ActiveRecord::Migration[5.2]
def change
add_column :graduation_task_group_assignations, :graduation_work_id, :integer, default: 0
add_index :graduation_task_group_assignations, :graduation_work_id
end
end

@ -0,0 +1,6 @@
class AddTemporaryToGraduation < ActiveRecord::Migration[5.2]
def change
add_column :graduation_task_group_assignations, :temporary, :integer, default: 0
add_column :graduation_work_comment_assignations, :temporary, :integer, default: 0
end
end

@ -43,9 +43,10 @@ namespace :graduation_task do
task :cross_comment_start => :environment do
tasks = GraduationTask.where("cross_comment = 1 and comment_time is not null and comment_time <= '#{Time.now}' and status = 2")
tasks.each do |task|
if task.comment_status == 4
GraduationTaskCrossCommentJob.perform_later(task.id)
end
# 改成设置时都实时分配
# if task.comment_status == 4
# GraduationTaskCrossCommentJob.perform_later(task.id)
# end
task.update_attributes(status: 3)
# 给老师发消息

Loading…
Cancel
Save