匿评作业的学生评阅数

courseware
cxt 5 years ago
parent 9d059cf012
commit 49af0cc5cd

@ -374,6 +374,7 @@ class StudentWorksController < ApplicationController
new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != ""
new_score.user_id = current_user.id
new_score.student_work_id = @work.id
new_score.homework_common_id = @work.homework_common_id
# 如果作品是未提交的状态则更新为已提交
if @user_course_identity < Course::STUDENT && !new_score.score.nil? && @work.work_status == 0
@ -553,8 +554,10 @@ class StudentWorksController < ApplicationController
# 分数不为空的历史评阅都置为失效
@work.student_works_scores.where.not(score: nil).update_all(is_invalid: 1)
reviewer_role = @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1
new_score = StudentWorksScore.new(student_work_id: @work.id, score: params[:score].to_f, comment: "使用调分功能调整了作业最终成绩:#{params[:comment]}",
user_id: current_user.id, reviewer_role: reviewer_role, is_ultimate: 1)
new_score = StudentWorksScore.new(student_work_id: @work.id, score: params[:score].to_f,
comment: "使用调分功能调整了作业最终成绩:#{params[:comment]}",
homework_common_id: @work.homework_common_id, user_id: current_user.id,
reviewer_role: reviewer_role, is_ultimate: 1)
new_score.save!
# 如果作品是未提交的状态则更新为已提交
@ -844,7 +847,7 @@ class StudentWorksController < ApplicationController
def add_score_to_member student_work, homework, new_score
student_works = homework.student_works.where("group_id = #{student_work.group_id} and id != #{student_work.id} and ultimate_score = 0")
student_works.each do |st_work|
st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score,
st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score, homework_common_id: homework.id,
reviewer_role: new_score.reviewer_role, comment: new_score.comment)
score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id, reviewer_role: new_score.reviewer_role).last

@ -6,6 +6,7 @@ class HomeworkCommon < ApplicationRecord
has_many :student_works, -> { where(is_delete: 0) }
has_many :score_student_works, -> { where("is_delete = 0 and work_status != 0").order("work_score desc") }, class_name: "StudentWork"
has_one :homework_detail_manual, dependent: :destroy
has_many :student_works_scores
# 分组作业的设置
has_one :homework_detail_group, dependent: :destroy

@ -46,7 +46,17 @@ class StudentWork < ApplicationRecord
# 匿评次数
def student_comment_num
homework_common.homework_detail_manual.comment_status > 2 ? self.student_works_scores.select{|score| score.reviewer_role == 3}.group_by(&:user_id).count : 0
homework_common.homework_detail_manual.comment_status > 2 && work_status > 0 ? self.student_works_scores.select{|score| score.reviewer_role == 3}.group_by(&:user_id).count : 0
end
# 学生评阅作品数
def user_comment_num
if homework_common.homework_detail_manual.comment_status > 2 && work_status > 0
count = homework_common.student_works_scores.select{|score| score.reviewer_role == 3 && score.user_id == user_id}.group_by(&:student_work_id).count
else
count = 0
end
count
end
# 匿评申诉总条数

@ -2,6 +2,7 @@ class StudentWorksScore < ApplicationRecord
#appeal_status: 0正常1申诉中2撤销申诉3申诉成功4申诉被拒绝5申诉失效
belongs_to :student_work
belongs_to :user
belongs_to :homework_common, optional: true
has_many :journals_for_messages, -> { order('created_on desc') }, as: :jour, dependent: :destroy
has_one :student_works_scores_appeal, dependent: :destroy
has_many :tidings, as: :container, dependent: :destroy

@ -63,6 +63,7 @@ elsif @user_course_identity == Course::STUDENT
if @homework.anonymous_comment
json.student_comment_count @work.student_comment_num
json.user_comment_count @work.user_comment_num
json.absence_penalty @work.absence_penalty
end
@ -147,7 +148,8 @@ elsif @homework.homework_type == "group" || @homework.homework_type == "normal"
# 作品匿评条数
if @homework.anonymous_comment
json.student_comment_count @homework_detail_manual.comment_status > 2 ? work.student_comment_num : 0
json.student_comment_count @homework_detail_manual.comment_status > 2 && work.work_status > 0 ? work.student_comment_num : 0
json.user_comment_count @homework_detail_manual.comment_status > 2 && work.work_status > 0 ? work.user_comment_num : 0
json.absence_penalty work.absence_penalty
end

@ -0,0 +1,5 @@
class AddHomeworkCommonIdToStudentWorksScore < ActiveRecord::Migration[5.2]
def change
add_column :student_works_scores, :homework_common_id, :integer, default: 0, index: true
end
end

@ -0,0 +1,7 @@
class MigrateStudentWorksScoreHomework < ActiveRecord::Migration[5.2]
def change
StudentWorksScore.includes(:student_work).find_each do |score|
score.update_column("homework_common_id", score.student_work&.homework_common_id)
end
end
end
Loading…
Cancel
Save