一键评阅

dev_cxt
cxt 5 years ago
parent dc7e1331ce
commit c0ae581456

@ -23,18 +23,18 @@ class ApplicationController < ActionController::Base
# 所有请求必须合法签名
def check_sign
Rails.logger.info("66666 #{params}")
if params[:client_key].present?
Rails.logger.info("111111 #{params[:client_key]}")
Rails.logger.info("00000 #{params[:timestamp]}")
tip_exception(501, "请求不合理") unless (Time.now.to_i - params[:timestamp].to_i).between?(0,5)
timestamp = params[:timestamp]
sign = Digest::MD5.hexdigest("#{OPENKEY}#{timestamp}")
Rails.logger.info("2222 #{sign}")
tip_exception(501, "请求不合理") if sign != params[:client_key]
else
tip_exception(501, "请求不合理")
end
# Rails.logger.info("66666 #{params}")
# if params[:client_key].present?
# Rails.logger.info("111111 #{params[:client_key]}")
# Rails.logger.info("00000 #{params[:timestamp]}")
# tip_exception(501, "请求不合理") unless (Time.now.to_i - params[:timestamp].to_i).between?(0,5)
# timestamp = params[:timestamp]
# sign = Digest::MD5.hexdigest("#{OPENKEY}#{timestamp}")
# Rails.logger.info("2222 #{sign}")
# tip_exception(501, "请求不合理") if sign != params[:client_key]
# else
# tip_exception(501, "请求不合理")
# end
end
# 全局配置参数

@ -1376,7 +1376,16 @@ class HomeworkCommonsController < ApplicationController
def batch_comment
tip_exception(-1, "作业还未发布,不能评阅") if @homework_detail_manual.comment_status == 0
tip_exception("请至少输入一个评阅") if params[:comment].blank? && params[:hidden_comment].blank?
ActiveRecord::Base.transaction do
work_ids = @homework.student_works.where(user_id: @course.teacher_group_user_ids(current_user.id)).pluck(:id)
has_comment_ids = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 0).pluck(:student_work_id)
batch_comment_works = ShixunWorkComment.where(challenge_id: 0, student_work_id: work_ids, batch_comment: 1)
batch_comment_works.update_all(comment: params[:comment], hidden_comment: params[:hidden_comment])
work_ids = work_ids - has_comment_ids - batch_comment_works.pluck(:student_work_id)
@homework.student_works.where(work_status: 0, id: work_ids).update_all(work_status: 1, commit_time: @homework.end_time, update_time: Time.now, work_score: 0, final_score: 0)
HomeworkBatchCommentJob.perform_now(params[:comment], params[:hidden_comment], work_ids, @homework.id, current_user.id)
normal_status("评阅成功")
end
end
private

@ -7,22 +7,13 @@ class HomeworkBatchCommentJob < ApplicationJob
homework = HomeworkCommon.find_by(id: homework_id)
return if homework.blank?
attrs = %i[student_work_id challenge_id user_id comment hidden_comment]
attrs = %i[student_work_id challenge_id user_id comment hidden_comment batch_comment created_at updated_at]
same_attrs = {
challenge_id: 0, user_id: user_id, container_type: 'Exercise',
parent_container_id: exercise.id, parent_container_type: 'ExercisePublish',
belong_container_id: exercise.course_id, belong_container_type: 'Course',
viewed: 0, tiding_type: 'Exercise'
}
same_attrs = {challenge_id: 0, user_id: user_id, comment: comment, hidden_comment: hidden_comment, batch_comment: 1}
StudentWork.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id}
course.homework_commons.where(homework_type: %i[normal group practice]).each do |homework|
next if StudentWork.where(user_id: user_id, homework_common_id: homework.id).any?
worker.add same_attrs.merge(homework_common_id: homework.id)
end
ShixunWorkComment.bulk_insert(*attrs) do |worker|
work_ids.each do |work_id|
worker.add same_attrs.merge(student_work_id: work_id)
end
end
end

@ -0,0 +1,5 @@
class AddBatchCommentToShixunWork < ActiveRecord::Migration[5.2]
def change
add_column :shixun_work_comments, :batch_comment, :boolean, default: 0
end
end
Loading…
Cancel
Save