diff --git a/app/controllers/homework_commons_controller.rb b/app/controllers/homework_commons_controller.rb index 4abada488..83bfd29fc 100644 --- a/app/controllers/homework_commons_controller.rb +++ b/app/controllers/homework_commons_controller.rb @@ -121,23 +121,26 @@ class HomeworkCommonsController < ApplicationController @work = @homework.user_work(current_user.id) # 学生已提交作品且补交(提交)已截止、作品公开、非匿评阶段 - if @work.work_status > 0 && @homework.work_public && + if @work&.work_status.to_i > 0 && @homework.work_public && ((!@homework.anonymous_comment && @homework.end_or_late) || @homework_detail_manual.comment_status > 4) - @student_works = student_works.where("user_id != #{@work.id}") + @student_works = student_works.where("user_id != #{@work.user_id}") # 匿评、申诉阶段只能看到分配给自己的匿评作品 - elsif @work.work_status > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 + elsif @work&.work_status.to_i > 0 && @homework.anonymous_comment && @homework_detail_manual.comment_status > 2 @is_evaluation = true @student_works = student_works.joins(:student_works_evaluation_distributions).where( "student_works_evaluation_distributions.user_id = #{@current_user.id}") else @student_works = [] end + @score_open = @homework.score_open && @work&.work_status.to_i > 0 elsif @user_course_identity < Course::STUDENT @student_works = @homework.teacher_works(@member) @all_member_count = @student_works.size + @score_open = true elsif @user_course_identity > Course::STUDENT && @homework.work_public @student_works = student_works + @score_open = false else @student_works = [] end diff --git a/app/jobs/homework_absence_penalty_calculation_job.rb b/app/jobs/homework_absence_penalty_calculation_job.rb new file mode 100644 index 000000000..87f78f311 --- /dev/null +++ b/app/jobs/homework_absence_penalty_calculation_job.rb @@ -0,0 +1,33 @@ +class HomeworkAbsencePenaltyCalculationJob < ApplicationJob + queue_as :score + + def perform(homework_common_id) + homework_common = HomeworkCommon.find_by(id: homework_common_id) + return if homework_common.blank? + + #计算缺评扣分 参与匿评 + work_ids = homework_common.student_works.has_committed.pluck(:id) + homework_detail_manual = homework_common.homework_detail_manual + + homework_common.student_works.where("work_status != 0").each do |student_work| + absence_penalty_count = student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count - + student_work.user.student_works_scores.where(student_work_id: work_ids, reviewer_role: 3).group_by(:student_work_id).count + + student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 + student_work.save + end + + # 未参与匿评 + if homework_detail_manual.no_anon_penalty == 0 + all_dis_eva = StudentWorksEvaluationDistribution.where(student_work_id: work_ids) + has_sw_count = all_dis_eva.select("distinct user_id").count + anon_count = all_dis_eva.count / has_sw_count + homework_common.student_works.where("work_status != 0").each do |student_work| + if student_work.user.student_works_evaluation_distributions.where(student_work_id: work_ids).count == 0 + student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count + student_work.save + end + end + end + end +end diff --git a/app/jobs/homework_anonymous_appeal_start_notify_job.rb b/app/jobs/homework_anonymous_appeal_start_notify_job.rb new file mode 100644 index 000000000..97c369846 --- /dev/null +++ b/app/jobs/homework_anonymous_appeal_start_notify_job.rb @@ -0,0 +1,27 @@ +class HomeworkAnonymousAppealStartNotifyJob < ApplicationJob + queue_as :notify + + def perform(homework_common_id) + homework = HomeworkCommon.find_by(id: homework_common_id) + return if homework.blank? + eva_distribution = StudentWorksEvaluationDistribution.where(student_work_id: homework.student_works.pluck(:id)) + + attrs = %i[ + 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 + ] + + same_attrs = { + trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', + parent_container_id: homework.id, parent_container_type: 'AnonymousAppeal', + belong_container_id: homework.course_id, belong_container_type: 'Course', + viewed: 0, tiding_type: 'HomeworkCommon' + } + Tiding.bulk_insert(*attrs) do |worker| + + eva_distribution.pluck(:user_id).uniq.each do |user_id| + worker.add same_attrs.merge(user_id: user_id) + end + end + end +end diff --git a/app/jobs/homework_common_push_notify_job.rb b/app/jobs/homework_common_push_notify_job.rb index 961face58..47956a14c 100644 --- a/app/jobs/homework_common_push_notify_job.rb +++ b/app/jobs/homework_common_push_notify_job.rb @@ -24,7 +24,7 @@ class HomeworkCommonPushNotifyJob < ApplicationJob same_attrs = { trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', parent_container_id: homework.id, parent_container_type: 'HomeworkPublish', - belong_container_id: task.course_id, belong_container_type: 'Course', + belong_container_id: homework.course_id, belong_container_type: 'Course', viewed: 0, tiding_type: 'HomeworkCommon' } Tiding.bulk_insert(*attrs) do |worker| diff --git a/app/jobs/homework_evaluation_comment_assgin_job.rb b/app/jobs/homework_evaluation_comment_assgin_job.rb new file mode 100644 index 000000000..2579ea18b --- /dev/null +++ b/app/jobs/homework_evaluation_comment_assgin_job.rb @@ -0,0 +1,48 @@ +class HomeworkEvaluationCommentAssginJob < ApplicationJob + queue_as :evaluation_comment + + def get_assigned_homeworks(student_works, n, index) + student_works += student_works + student_works[index + 1..index + n] + end + + def perform(homework_common_id) + homework_common = HomeworkCommon.find_by(id: homework_common_id) + return if homework_common.blank? + homework_detail_manual = homework_common.homework_detail_manual + + if homework_common.homework_type == "group" + student_works = homework_common.student_works.where("work_status != 0").group(:group_id) + student_work_projects = homework_common.student_works.where("work_status != 0").shuffle + student_work_projects.each do |pro_work| + n = homework_detail_manual.evaluation_num + n = (n < student_works.size && n != -1) ? n : student_works.size - 1 + work_index = -1 + student_works.each_with_index do |stu_work, stu_index| + if stu_work.group_id.to_i == pro_work.group_id.to_i + work_index = stu_index + end + end + assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + + else + student_works = homework_common.student_works.has_committed + student_works = student_works.shuffle + student_works.each_with_index do |work, index| + user = work.user + n = homework_detail_manual.evaluation_num + n = (n < student_works.size && n != -1) ? n : student_works.size - 1 + assigned_homeworks = get_assigned_homeworks(student_works, n, index) + assigned_homeworks.each do |h| + student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) + student_works_evaluation_distributions.save + end + end + end + end +end diff --git a/app/jobs/homework_evaluation_start_notify_job.rb b/app/jobs/homework_evaluation_start_notify_job.rb new file mode 100644 index 000000000..709c37b32 --- /dev/null +++ b/app/jobs/homework_evaluation_start_notify_job.rb @@ -0,0 +1,30 @@ +class HomeworkEvaluationStartNotifyJob < ApplicationJob + queue_as :notify + + def perform(homework_common_id, content) + homework = HomeworkCommon.find_by(id: homework_common_id) + return if homework.blank? + course = homework.course + members = content.blank? ? course.course_members : course.teachers + tiding_type = content.blank? ? "HomeworkCommon" : "System" + + attrs = %i[ + user_id trigger_user_id container_id container_type parent_container_id parent_container_type + belong_container_id belong_container_type viewed tiding_type extra created_at updated_at + ] + + same_attrs = { + trigger_user_id: homework.user_id, container_id: homework.id, container_type: 'HomeworkCommon', + parent_container_id: homework.id, parent_container_type: 'AnonymousComment', + belong_container_id: homework.course_id, belong_container_type: 'Course', + viewed: 0, tiding_type: tiding_type, extra: content + } + Tiding.bulk_insert(*attrs) do |worker| + member_ids = members.pluck(:user_id).uniq + + member_ids.each do |user_id| + worker.add same_attrs.merge(user_id: user_id) + end + end + end +end diff --git a/app/jobs/homework_publish_update_work_status_job.rb b/app/jobs/homework_publish_update_work_status_job.rb index 0060ab270..fe03a3ac5 100644 --- a/app/jobs/homework_publish_update_work_status_job.rb +++ b/app/jobs/homework_publish_update_work_status_job.rb @@ -1,6 +1,6 @@ class HomeworkPublishUpdateWorkStatusJob < ApplicationJob # 作业发布时更新学生(发布前已开启过实训)的作业状态和成绩 - queue_as :default + queue_as :score def perform(group_ids, homework_id) # Do something later diff --git a/app/views/homework_commons/works_list.json.jbuilder b/app/views/homework_commons/works_list.json.jbuilder index 716b12190..60441909b 100644 --- a/app/views/homework_commons/works_list.json.jbuilder +++ b/app/views/homework_commons/works_list.json.jbuilder @@ -33,19 +33,19 @@ elsif @user_course_identity == Course::STUDENT json.late_penalty @work.late_penalty if @homework.allow_late json.cost_time @work.myshixun.try(:total_cost_time) - json.work_score work_score_format(@work.work_score, true, @homework.score_open) - json.final_score work_score_format(@work.final_score, true, @homework.score_open) - json.efficiency work_score_format(@work.efficiency, true, @homework.score_open) - json.eff_score work_score_format(@work.eff_score, true, @homework.score_open) + json.work_score work_score_format(@work.work_score, true, @score_open) + json.final_score work_score_format(@work.final_score, true, @score_open) + json.efficiency work_score_format(@work.efficiency, true, @score_open) + json.eff_score work_score_format(@work.eff_score, true, @score_open) json.complete_count @work.myshixun.try(:passed_count) else json.(@work, :id, :work_status, :update_time, :ultimate_score) - json.work_score work_score_format(@work.work_score, true, @homework.score_open) - json.final_score work_score_format(@work.final_score, true, @homework.score_open) - json.teacher_score work_score_format(@work.teacher_score, true, @homework.score_open) - json.student_score work_score_format(@work.student_score, true, @homework.score_open) - json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @homework.score_open) + json.work_score work_score_format(@work.work_score, true, @score_open) + json.final_score work_score_format(@work.final_score, true, @score_open) + json.teacher_score work_score_format(@work.teacher_score, true, @score_open) + json.student_score work_score_format(@work.student_score, true, @score_open) + json.teaching_asistant_score work_score_format(@work.teaching_asistant_score, true, @score_open) json.ta_comment_count @work.ta_comment_count @@ -84,10 +84,10 @@ if @homework.homework_type == "practice" json.(work, :id, :work_status, :update_time, :ultimate_score) json.late_penalty work.late_penalty if @homework.allow_late - json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) - json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) - json.efficiency work_score_format(work.efficiency, @current_user == work.user, @homework.score_open) - json.eff_score work_score_format(work.eff_score, @current_user == work.user, @homework.score_open) + json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) + json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open) + json.efficiency work_score_format(work.efficiency, @current_user == work.user, @score_open) + json.eff_score work_score_format(work.eff_score, @current_user == work.user, @score_open) json.cost_time work.myshixun.try(:total_cost_time) json.complete_count work.myshixun.try(:passed_count) @@ -117,11 +117,11 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal" :teaching_asistant_score, :ultimate_score) json.late_penalty work.late_penalty if @homework.allow_late - json.work_score work_score_format(work.work_score, @current_user == work.user, @homework.score_open) - json.final_score work_score_format(work.final_score, @current_user == work.user, @homework.score_open) - json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @homework.score_open) - json.student_score work_score_format(work.student_score, @current_user == work.user, @homework.score_open) - json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @homework.score_open) + json.work_score work_score_format(work.work_score, @current_user == work.user, @score_open) + json.final_score work_score_format(work.final_score, @current_user == work.user, @score_open) + json.teacher_score work_score_format(work.teacher_score, @current_user == work.user, @score_open) + json.student_score work_score_format(work.student_score, @current_user == work.user, @score_open) + json.teaching_asistant_score work_score_format(work.teaching_asistant_score, @current_user == work.user, @score_open) # 助教评分次数 json.ta_comment_count work.ta_comment_count diff --git a/config/sidekiq.yml b/config/sidekiq.yml index a2b3fc0be..5bd9dad23 100644 --- a/config/sidekiq.yml +++ b/config/sidekiq.yml @@ -3,4 +3,6 @@ :logfile: log/sidekiq.log :queues: - [default, 3] + - [score, 4] + - [evaluation_comment, 5] - [notify, 100] \ No newline at end of file diff --git a/lib/tasks/homework_evaluation.rake b/lib/tasks/homework_evaluation.rake index cb7b51fae..d1fad8f14 100644 --- a/lib/tasks/homework_evaluation.rake +++ b/lib/tasks/homework_evaluation.rake @@ -23,59 +23,11 @@ namespace :homework_evaluation do else student_works = homework_common.student_works.has_committed end - if student_works.present? && student_works.length >= 2 - if homework_common.homework_type == "group" - student_work_projects = homework_common.student_works.where("work_status != 0").shuffle - student_work_projects.each_with_index do |pro_work, pro_index| - n = homework_detail_manual.evaluation_num - n = (n < student_works.size && n != -1) ? n : student_works.size - 1 - work_index = -1 - student_works.each_with_index do |stu_work, stu_index| - if stu_work.group_id.to_i == pro_work.group_id.to_i - work_index = stu_index - end - end - assigned_homeworks = get_assigned_homeworks(student_works, n, work_index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: pro_work.user_id, student_work_id: h.id) - student_works_evaluation_distributions.save - end - #更新CourseHomeworkStatistics中该学生的待匿评数 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, pro_work.user_id) - # course_statistics.update_attribute('un_evaluation_work_num', course_statistics.un_evaluation_work_num + n) if course_statistics - end - else - student_works = student_works.shuffle - student_works.each_with_index do |work, index| - user = work.user - n = homework_detail_manual.evaluation_num - n = (n < student_works.size && n != -1) ? n : student_works.size - 1 - assigned_homeworks = get_assigned_homeworks(student_works, n, index) - assigned_homeworks.each do |h| - student_works_evaluation_distributions = StudentWorksEvaluationDistribution.new(user_id: user.id, student_work_id: h.id) - student_works_evaluation_distributions.save - end + if student_works.size >= 2 + HomeworkEvaluationCommentAssginJob.perform_later(homework_common.id) - #更新CourseHomeworkStatistics中该学生的待匿评数 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, user.id) - # course_statistics.update_attribute('un_evaluation_work_num', course_statistics.un_evaluation_work_num + n) if course_statistics - end - end homework_detail_manual.update_column('comment_status', 3) - # 匿评开启消息邮件通知,# 所有人 - str = "" - homework_common.course.course_members.pluck(:user_id).uniq.each do |user_id| - str += "," if str != "" - str += "('#{user_id}', '#{homework_common.user_id}', '#{homework_common.id}','HomeworkCommon','#{homework_common.id}', - 'AnonymousComment',#{homework_common.course_id},'Course',0,'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - 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" + str - ActiveRecord::Base.connection.execute sql - end else #作业数小于2,启动失败, 只给老师和助教发 extra = "作品数量低于两个,无法开启匿评" @@ -83,20 +35,8 @@ namespace :homework_evaluation do else extra = "存在尚未截止的分班,无法开启匿评" end + HomeworkEvaluationStartNotifyJob.perform_later(homework_common.id, extra) if extra.present? - str = '' - homework_common.course.teachers.each do |mem| - str += "," if str != "" - str += "('#{mem.user.id}', '#{homework_common.user_id}', '#{homework_common.id}','HomeworkCommon','#{homework_common.id}', - 'AnonymousCommentFail',#{homework_common.course_id},'Course',0,'System','#{extra}', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - 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, extra, created_at, - updated_at) values" + str - ActiveRecord::Base.connection.execute sql - end homework_detail_manual.update_attributes(:evaluation_start => nil, :evaluation_end => nil, :absence_penalty => 0, :evaluation_num => 0, :appeal_time => nil, :appeal_penalty => 0) homework_common.update_attributes(:anonymous_comment => 0, :anonymous_appeal => 0) @@ -114,63 +54,15 @@ namespace :homework_evaluation do homework_detail_manuals.each do |homework_detail_manual| homework_common = homework_detail_manual.homework_common if homework_common.anonymous_comment #开启匿评状态才可关闭匿评 - #计算缺评扣分 参与匿评 - work_ids = "(" + homework_common.student_works.has_committed.map(&:id).join(",") + ")" - - homework_common.student_works.where("work_status != 0").each do |student_work| - absence_penalty_count = student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count - - student_work.user.student_works_scores.where("student_work_id IN #{work_ids} and reviewer_role = 3").count - - student_work.absence_penalty = absence_penalty_count > 0 ? absence_penalty_count * homework_detail_manual.absence_penalty : 0 - student_work.save - - #更新CourseHomeworkStatistics中该学生的待匿评数和缺评数 - # absence_penalty_count = absence_penalty_count > 0 ? absence_penalty_count : 0 - # course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework_common.course_id, student_work.user_id) - # course_statistics.update_attribute('un_evaluation_work_num', (course_statistics.un_evaluation_work_num - absence_penalty_count) < 0 ? 0 : - # (course_statistics.un_evaluation_work_num - absence_penalty_count)) if course_statistics - # course_statistics.update_attribute('absence_evaluation_work_num', course_statistics.absence_evaluation_work_num + absence_penalty_count) if course_statistics - end - - # 未参与匿评 - if homework_common.homework_detail_manual.no_anon_penalty == 0 - all_dis_eva = StudentWorksEvaluationDistribution.where("student_work_id IN #{work_ids}") - has_sw_count = all_dis_eva.select("distinct user_id").count - anon_count = all_dis_eva.count / has_sw_count - homework_common.student_works.where("work_status != 0").each do |student_work| - if student_work.user.student_works_evaluation_distributions.where("student_work_id IN #{work_ids}").count == 0 - student_work.absence_penalty = homework_detail_manual.absence_penalty * anon_count - student_work.save - end - end - end - if homework_common.anonymous_appeal homework_detail_manual.update_column('comment_status', 4) - # 申诉开启 - eva_distribution = StudentWorksEvaluationDistribution.where(:student_work_id => homework_common.student_works.pluck(:id)) - str = "" - eva_distribution.pluck(:user_id).uniq.each do |user_id| - str += "," if str != "" - str += "(#{user_id}, #{homework_common.user_id}, #{homework_common.id}, 'HomeworkCommon', #{homework_common.id}, - 'AnonymousAppeal', #{homework_common.course_id}, 'Course', 0, 'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - if str != "" - 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" + str - ActiveRecord::Base.connection.execute sql - end + # 申诉开启发送消息 + HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id) else homework_detail_manual.update_column('comment_status', 5) end - # 匿评关闭消息通知 给所有人发 - # course = homework_common.course - # course.members.each do |m| - # homework_common.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => 3) - # end - # 邮件通知 - # Mailer.send_mail_anonymous_comment_close(homework_common).deliver + + HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id) end end end diff --git a/lib/tasks/homework_publishtime.rake b/lib/tasks/homework_publishtime.rake index 0e45b0224..cbfd4413a 100644 --- a/lib/tasks/homework_publishtime.rake +++ b/lib/tasks/homework_publishtime.rake @@ -21,34 +21,29 @@ namespace :homework_publishtime do homework_commons.each do |homework| homework_detail_manual = homework.homework_detail_manual homework_detail_manual.update_column('comment_status', 1) - course = homework.course - students = course.students - if !course.nil? && !students.empty? + # 统一设置的作业在这发消息,非统一设置的只给有全部分班权限的老师发 + if homework.unified_setting + HomeworkPublishUpdateWorkStatusJob.perform_later(nil, homework.id) + HomeworkCommonPushNotifyJob.perform_later(homework.id, nil) + else + course = homework.course + teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id)) + tid_str = "" - course.teachers.find_each do |member| + teachers.find_each do |member| tid_str += "," if tid_str != "" tid_str += "(#{member.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, 'HomeworkPublish', #{course.id}, 'Course', 0, 'HomeworkCommon', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" end - if homework.unified_setting - students.each do |student| - tid_str += "," if tid_str != "" - tid_str += "(#{student.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, - 'HomeworkPublish', #{course.id}, 'Course', 0, 'HomeworkCommon', - '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')" - end - HomeworkPublishUpdateWorkStatusJob.perform_now(nil, homework.id) - 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 - + end if homework.course_acts.size == 0 homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id) end @@ -59,27 +54,8 @@ namespace :homework_publishtime do homework_group_settings.each do |homework_group| homework = homework_group.homework_common if homework.present? - course = homework.course - homework_detail_manual = homework.homework_detail_manual - homework_detail_manual.update_column('comment_status', 1) if homework_detail_manual.comment_status == 0 - - tid_str = "" - members = course.students.where(:course_group_id => homework_group.course_group_id) - members.find_each do |member| - tid_str += "," if tid_str != "" - tid_str += "(#{member.user_id}, #{homework.user_id}, #{homework.id}, 'HomeworkCommon', #{homework.id}, 'HomeworkPublish', - #{course.id}, 'Course', 0, 'HomeworkCommon', '#{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 - HomeworkPublishUpdateWorkStatusJob.perform_now([homework_group.id], homework.id) - + HomeworkCommonPushNotifyJob.perform_later(homework.id, [homework_group.id]) end end Rails.logger.info("log--------------------------------homework_publish end") @@ -98,11 +74,10 @@ namespace :homework_publishtime do student_works = homework.student_works.where("work_status != 0") # none_student_works = homework.student_works.where("work_status = 0") else - setting = homework.homework_group_settings.where(:end_time => homework.end_time) + setting = homework.homework_group_settings.where(end_time: homework.end_time) unless setting.blank? - users = homework.course.students.where(:course_group_id => setting.map(&:course_group_id)) - user_ids = users.blank? ? "(-1)" : "(" + users.map(&:user_id).join(",") + ")" - student_works = homework.student_works.where("work_status != 0 and user_id in #{user_ids}") + users = homework.course.students.where(course_group_id: setting.pluck(:course_group_id)) + student_works = homework.student_works.where("work_status != 0").where(user_id: users.pluck(:user_id)) # none_student_works = homework.student_works.where("work_status = 0 and user_id in #{user_ids}") end end @@ -172,8 +147,7 @@ namespace :homework_publishtime do # homework_challenge_settings = homework.homework_challenge_settings users = homework.course.students.where(:course_group_id => homework_setting.course_group_id) - user_ids = users.blank? ? "(-1)" : "(" + users.map(&:user_id).join(",") + ")" - student_works = homework.student_works.where("work_status != 0 and user_id in #{user_ids}") + student_works = homework.student_works.where("work_status != 0").where(user_id: users.pluck(:user_id)) student_works.joins(:myshixun).where("myshixuns.status != 1").update_all(late_penalty: homework.late_penalty) if student_works.present? else # HomeworksService.new.update_student_eff_score homework # 分班设置的不需要另外算效率分 diff --git a/spec/jobs/homework_absence_penalty_calculation_job_spec.rb b/spec/jobs/homework_absence_penalty_calculation_job_spec.rb new file mode 100644 index 000000000..b347086ce --- /dev/null +++ b/spec/jobs/homework_absence_penalty_calculation_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkAbsencePenaltyCalculationJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb b/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb new file mode 100644 index 000000000..bd5db1e69 --- /dev/null +++ b/spec/jobs/homework_anonymous_appeal_start_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkAnonymousAppealStartNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb b/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb new file mode 100644 index 000000000..7a31a825f --- /dev/null +++ b/spec/jobs/homework_evaluation_comment_assgin_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEvaluationCommentAssginJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end diff --git a/spec/jobs/homework_evaluation_start_notify_job_spec.rb b/spec/jobs/homework_evaluation_start_notify_job_spec.rb new file mode 100644 index 000000000..b347ea1f5 --- /dev/null +++ b/spec/jobs/homework_evaluation_start_notify_job_spec.rb @@ -0,0 +1,5 @@ +require 'rails_helper' + +RSpec.describe HomeworkEvaluationStartNotifyJob, type: :job do + pending "add some examples to (or delete) #{__FILE__}" +end