毕设调整

dev_forum
cxt 5 years ago
parent c746667796
commit 39b87564fe

@ -432,11 +432,11 @@ class GraduationWorksController < ApplicationController
# 交叉评阅分配老师
def assign_teacher
tip_exception(-1, "user_id不能为空") if params[:user_id].nil?
@work_assign_teacher = @work.graduation_work_comment_assignations.first
@work_assign_teacher = @work.graduation_work_comment_assignations.find_by(user_id: params[:user_id])
if @work_assign_teacher
if @work_assign_teacher.present?
# graduation_group_id: 已经是答辩组的需要 将答辩组清空
@work_assign_teacher.update_attributes(user_id: params[:user_id], graduation_group_id: 0)
@work_assign_teacher.update_attributes(graduation_group_id: 0)
else
@work.graduation_work_comment_assignations << GraduationWorkCommentAssignation.new(graduation_task_id: @task.id,
user_id: params[:user_id],

@ -0,0 +1,39 @@
# 毕设任务的交叉评阅分配
class GraduationTaskCrossCommentJob < ApplicationJob
queue_as :evaluation_comment
def perform(graduation_task_id)
task = GraduationTask.find_by(id: graduation_task_id)
return if task.blank?
course = task.course
task.graduation_task_group_assignations.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
end
end
end
end
end

@ -18,8 +18,8 @@ class GraduationTaskPublishNotifyJob < ApplicationJob
viewed: 0, tiding_type: 'GraduationTask'
}
Tiding.bulk_insert(*attrs) do |worker|
task.course.students.find_each do |student|
worker.add same_attrs.merge(user_id: student.user_id)
task.course.course_members.pluck(:user_id).uniq.find_each do |user_id|
worker.add same_attrs.merge(user_id: user_id)
end
end
end

@ -1,3 +1,4 @@
# 匿评申诉开启时给分配了匿评的学生发消息
class HomeworkAnonymousAppealStartNotifyJob < ApplicationJob
queue_as :notify

@ -5,27 +5,9 @@ namespace :graduation_task do
tasks = GraduationTask.where("publish_time is not null and publish_time <= '#{Time.now}' and status = 0")
tasks.each do |task|
task.update_attributes(status: 1)
course = task.course
members = course.course_members
if !course.nil? && !members.empty?
tid_str = ""
members.find_each do |member|
tid_str += "," if tid_str != ""
tid_str += "(#{member.user_id}, #{task.user_id}, #{task.id}, 'GraduationTask', #{task.id}, 'TaskPublish',
#{course.id}, 'Course', 0, 'GraduationTask', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}',
'#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
end
if tid_str != ""
tid_sql = "insert into tidings (user_id, trigger_user_id, container_id, container_type, parent_container_id,
parent_container_type, belong_container_id, belong_container_type, viewed, tiding_type, created_at,
updated_at) values" + tid_str
ActiveRecord::Base.connection.execute tid_sql
end
end
GraduationTaskPublishNotifyJob.perform_later(task.id)
if task.course_acts.size == 0
task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id)
end
task.course_acts << CourseActivity.new(user_id: task.user_id, course_id: task.course_id) if task.course_acts.exists?
end
end
@ -62,37 +44,11 @@ namespace :graduation_task 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
course = task.course
task.graduation_task_group_assignations.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
end
end
end
GraduationTaskCrossCommentJob.perform_later(task.id)
end
task.update_attributes(status: 3)
# 给老师发消息
tid_str = ""
task.course.teachers.find_each do |member|
tid_str += "," if tid_str != ""

@ -44,9 +44,8 @@ namespace :homework_publishtime do
ActiveRecord::Base.connection.execute tid_sql
end
end
if homework.course_acts.size == 0
homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
end
homework.course_acts << CourseActivity.new(user_id: homework.user_id, course_id: homework.course_id) if homework.course_acts.exists?
end
# 分组设置发布时间的作业

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe GraduationTaskCrossCommentJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
end

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe GraduationTaskPublishNotifyJob, type: :job do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save