Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_course
daiao 5 years ago
commit d142c14743

@ -284,7 +284,7 @@ class CoursesController < ApplicationController
@is_admin = @user_course_identity < Course::PROFESSOR
@applications= CourseMessage.unhandled_join_course_requests_by_course(@course)
@applications = @is_admin ? CourseMessage.unhandled_join_course_requests_by_course(@course) : CourseMessage.none
page = params[:page] || 1
limit = params[:limit] || 20
@ -548,6 +548,7 @@ class CoursesController < ApplicationController
course_teacher = CourseMember.find_by(user_id: current_user.id, role: %i[CREATOR PROFESSOR ASSISTANT_PROFESSOR], course_id: @course.id)
course_student.destroy!
course_teacher.update_attributes(is_active: 1) if course_teacher.present? && !course_teacher.is_active
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, [current_user.id])
normal_status(0, "退出成功")
end
@ -684,11 +685,16 @@ class CoursesController < ApplicationController
ActiveRecord::Base.transaction do
begin
students = params[:students]
student_ids = []
students.each do |student|
course_member = CourseMember.find_by!(id: student[:course_member_id].to_i, course_id: @course.id)
course_member.destroy!
course_member = CourseMember.find_by(id: student[:course_member_id].to_i, course_id: @course.id)
if course_member.present?
student_ids << course_member.user_id
course_member.destroy!
end
end
CourseDeleteStudentDeleteWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
normal_status(0, "操作成功")
rescue => e
uid_logger(e.message)
@ -711,7 +717,7 @@ class CoursesController < ApplicationController
student_ids = []
user_ids.each do |user_id|
existing_course_member = CourseMember.find_by(user_id: user_id.to_i, course_id: @course.id)
existing_course_member = @course.course_members.find_by(user_id: user_id.to_i)
new_student = CourseMember.new(user_id: user_id.to_i, course_id: @course.id, course_group_id: course_group_id, role: 4)
if existing_course_member.present?
@ -720,6 +726,7 @@ class CoursesController < ApplicationController
else
new_student.is_active = 0 if existing_course_member.is_active
new_student.save!
student_ids << user_id
end
else
new_student.save!
@ -727,6 +734,7 @@ class CoursesController < ApplicationController
end
end
CourseAddStudentCreateWorksJob.perform_later(@course.id, student_ids) if student_ids.present?
TeacherInviteJoinCourseNotifyJob.perform_later(current_user.id, @course.id, 10, student_ids) if student_ids.present?
normal_status(0, "添加成功")
rescue => e
@ -868,6 +876,7 @@ class CoursesController < ApplicationController
new_student.course_group_id = course_group.id if course_group.present?
new_student.save!
CourseAddStudentCreateWorksJob.perform_later(course.id, [current_user.id])
StudentJoinCourseNotifyJob.perform_later(current_user.id, course.id)
end
end

@ -477,10 +477,8 @@ class ExercisesController < ApplicationController
params_end_time = params[:end_time].to_time
end
if exercise_status == 2 && @exercise.publish_time != params_publish_time
normal_status(-1,"已发布,不允许修改发布时间")
elsif exercise_status == 3 && (@exercise.end_time != params_end_time || @exercise.publish_time != params_publish_time)
normal_status(-1,"已截止,不允许修改时间")
if (exercise_status != 1) && (@exercise.publish_time != params_publish_time)
normal_status(-1,"已发布/已截止,不允许修改发布时间")
elsif params_publish_time.present? && params_end_time.present? && params_end_time < params_publish_time
normal_status(-1,"截止时间不能小于发布时间")
else
@ -523,12 +521,7 @@ class ExercisesController < ApplicationController
end
# exercise_end_time = t[:end_time].present? ? t[:end_time].to_time : nil
exercise_group = exercise_groups.find_in_exercise_group("course_group_id",course_id) #判断该分班是否存在
if exercise_group.present? && exercise_group.first.end_time <= Time.now &&
(exercise_end_time != exercise_group.first.end_time || exercise_publish_time != exercise_group.first.publish_time) #已截止且时间改变的,则提示错误
error_count += 1
end
if exercise_group.present? && exercise_group.first.publish_time <
Time.now && exercise_publish_time != exercise_group.first.publish_time
if exercise_group.present? && (exercise_group.first.publish_time < Time.now) && (exercise_publish_time != exercise_group.first.publish_time)
error_count += 1
end
if error_count == 0
@ -1639,36 +1632,9 @@ class ExercisesController < ApplicationController
@answer_committed_user = @exercise.exercise_users.exercise_commit_users(current_user.id)&.first
if @answer_committed_user.blank?
normal_status(404,"答题用户不存在")
# elsif @exercise.get_exercise_status(current_user.id) == 2 && @answer_committed_user.commit_status == 1 #当试卷截止时,会自动提交
# normal_status(-1,"提交错误,试卷用户已提交!")
end
end
# def commit_user_exercise
# @exercise_user_current = @exercise.exercise_users.exercise_commit_users(@exercise_current_user_id)&.first #查找当前用户是否有过答题
# if @user_course_identity == Course::STUDENT
# if @exercise_user_current.present?
# if @exercise.time > 0 && @exercise_user_current.start_at.present? && (@exercise_user_current.commit_status == 0) &&
# ((@exercise_user_current.start_at + (@exercise.time.to_i + 1).minutes) < Time.now)
# #当前用户存在,且已回答,且试卷时间已过,且未提交,则自动提交。最好是前端控制
# objective_score = calculate_student_score(@exercise,current_user)[:total_score]
# subjective_score = @exercise_user_current.subjective_score < 0.0 ? 0.0 : @exercise_user_current.subjective_score
# total_score = objective_score + subjective_score
# commit_option = {
# :status => 1,
# :commit_status => 1,
# :end_at => Time.now,
# :objective_score => objective_score,
# :score => total_score,
# :subjective_score => subjective_score
# }
# @exercise_user_current.update_attributes(commit_option)
# normal_status(0,"已交卷成功!")
# end
# end
# end
# end
#打回重做时的初步判断
def check_exercise_status
@exercise_users = @exercise.all_exercise_users(current_user.id).commit_exercise_by_status(1) #当前教师所在分班的全部已提交的学生数

@ -208,9 +208,11 @@ class HomeworkCommonsController < ApplicationController
student_work_to_xlsx(@work_excel,@homework)
exercise_export_name = current_user.real_name + "_" + @course.name + "_" + @homework.name + "_" + Time.now.strftime('%Y%m%d_%H%M%S')
render xlsx: "#{exercise_export_name.strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
render xlsx: "#{exercise_export_name.encode(Encoding.default_external,"UTF-8", :invalid => :replace, :undef => :replace, :replace => " ").strip.first(30)}",template: "homework_commons/works_list.xlsx.axlsx",locals:
{table_columns: @work_head_cells,task_users: @work_cells_column}
}
# .encode(Encoding.default_external, 'gb2312')
end
end
elsif params[:format] == "zip"

@ -1282,8 +1282,6 @@ class PollsController < ApplicationController
else
normal_status(-1,"请选择分班!")
end
# elsif (@poll.poll_status != 1) && (params[:publish_time].to_time != @poll.publish_time) && (@user_course_identity > Course::CREATOR)
# normal_status(-1,"已发布/已截止的不能修发布时间!") #课堂管理员和超级管理员才有权限
end
end

@ -334,7 +334,6 @@ class StudentWorksController < ApplicationController
ActiveRecord::Base.transaction do
begin
# 没传score则取上次评分成绩
score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id).last
new_score = StudentWorksScore.new
new_score.score = params[:score].blank? ? score.try(:score) : params[:score].to_f
new_score.comment = params[:comment] if params[:comment] && params[:comment].strip != ""
@ -348,7 +347,9 @@ class StudentWorksController < ApplicationController
@work.update_attributes(group_id: @homework.max_group_id) if @homework.homework_type == "group"
end
new_score.reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1
reviewer_role = @user_course_identity == Course::STUDENT ? 3 : @user_course_identity == Course::ASSISTANT_PROFESSOR ? 2 : 1
new_score.reviewer_role = reviewer_role
score = StudentWorksScore.where(user_id: current_user.id, student_work_id: @work.id, reviewer_role: reviewer_role).last
if new_score.save!
Attachment.associate_container(params[:attachment_ids], new_score.id, new_score.class)
@ -730,19 +731,19 @@ class StudentWorksController < ApplicationController
student_works.each do |st_work|
st_score = StudentWorksScore.new(user_id: new_score.user_id, score: new_score.score,
reviewer_role: new_score.reviewer_role, comment: new_score.comment)
st_work.student_works_scores << st_score
score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id).last
score = StudentWorksScore.where(user_id: new_score.user_id, student_work_id: st_work.id, reviewer_role: new_score.reviewer_role).last
# 该用户的历史评阅无效
score.update_column('is_invalid', true) if score.present? && score.score.present?
st_work.student_works_scores << st_score
if new_score.reviewer_role == 1
st_work.teacher_score = new_score.score
st_work.teacher_score = new_score.score if new_score.score.present?
elsif new_score.reviewer_role == 2
if homework.homework_detail_manual.ta_mode == 1
st_work.teaching_asistant_score = new_score.ta_score st_work.id
else
st_work.teaching_asistant_score = new_score.score
st_work.teaching_asistant_score = new_score.score if new_score.score.present?
end
else
st_work.student_score = student_work.student_score

@ -10,6 +10,7 @@ class ZipsController < ApplicationController
service = BatchExportShixunReportService.new(@homework, @all_student_works)
filename = filename_for_content_disposition(service.filename)
send_file service.zip, filename: filename, type: 'application/zip'
rescue BatchExportShixunReportService::Error => ex
normal_status(-1, ex.message)

@ -40,10 +40,17 @@ module ExportHelper
works.includes(user: :user_extension, student_works_scores: :user).each_with_index do |w, index|
w_user = w.user
w_1 = (index + 1)
w_2 = w_user.login
w_3 = w_user.real_name
w_3_1 = w_user.mail
w_4 = w_user.student_id.present? ? w_user.student_id : "--"
if w_user.present?
w_2 = w_user&.login
w_3 = w_user&.real_name
w_3_1 = w_user&.mail
w_4 = w_user.student_id.present? ? w_user.student_id : "--"
else
w_2 = "--"
w_3 = "--"
w_3_1 = "--"
w_4 = "--"
end
course_name = course.students.find_by(user_id: w.user_id).try(:course_group_name)
w_5 = course_name.present? ? course_name : "--"
#0 未提交, 1 按时提交, 2 延迟提交
@ -487,6 +494,8 @@ module ExportHelper
zipfile_name = "#{output_path}/#{rename_zipfile}"
# 同名文件重命名时用
index = 1
Dir.mkdir(File.dirname(zipfile_name)) unless File.exist?(File.dirname(zipfile_name))
Zip::File.open(zipfile_name, Zip::File::CREATE) do |zipfile|
files_paths.each do |filename|
@ -496,7 +505,11 @@ module ExportHelper
begin
zipfile.add(rename_file, filename)
rescue Exception => e
zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"}
rename_file = rename_same_file(rename_file, index)
index += 1
zipfile.add(rename_file, filename)
# zipfile.get_output_stream('FILE_NOTICE.txt'){|os| os.write "该作品中有重复命名文件,请通过文件名学号和姓名信息进入该作业详细界面手动下载"}
next
end
end
@ -516,4 +529,11 @@ module ExportHelper
def format_sheet_name name
name = name.gsub(":", "-")
end
def rename_same_file(name, index)
basename = File.basename(name, ".*")
new_basename = basename + "_" + index.to_s
extname = File.extname(name)
new_basename + extname
end
end

@ -0,0 +1,67 @@
# 学生加入课堂时创建相关任务作品
class CourseAddStudentCreateWorksJob < ApplicationJob
queue_as :course_member
def perform(course_id, student_ids)
course = Course.find_by(id: course_id)
return if course.blank?
# 如果之前存在相关作品则更新is_delete字段
student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 0)
exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 0)
poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id})
poll_users.update_all(is_delete: 0)
graduation_works = course.graduation_works.where(user_id: student_ids)
graduation_works.update_all(is_delete: 0)
attrs = %i[homework_common_id user_id created_at updated_at]
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 homework.student_works.where(user_id: user_id).any?
worker.add same_attrs.merge(homework_common_id: homework.id)
end
end
end
attrs = %i[exercise_id user_id created_at updated_at]
ExerciseUser.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id}
course.exercises.each do |exercise|
next if exercise.exercise_users.where(user_id: user_id).any?
worker.add same_attrs.merge(exercise_id: exercise.id)
end
end
end
attrs = %i[poll_id user_id created_at updated_at]
PollUser.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id}
course.polls.each do |poll|
next if poll.poll_users.where(user_id: user_id).any?
worker.add same_attrs.merge(poll_id: poll.id)
end
end
end
attrs = %i[graduation_task_id user_id course_id created_at updated_at]
GraduationWork.bulk_insert(*attrs) do |worker|
student_ids.each do |user_id|
same_attrs = {user_id: user_id, course_id: course.id}
course.graduation_tasks.each do |task|
next if task.graduation_works.where(user_id: user_id).any?
worker.add same_attrs.merge(graduation_task_id: task.id)
end
end
end
end
end

@ -0,0 +1,19 @@
class CourseDeleteStudentDeleteWorksJob < ApplicationJob
queue_as :course_member
def perform(course_id, student_ids)
course = Course.find_by(id: course_id)
return if course.blank?
student_works = StudentWork.joins(:homework_common).where(user_id: student_ids, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 1)
exercise_users = ExerciseUser.joins(:exercise).where(user_id: student_ids, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 1)
poll_users = PollUser.joins(:poll).where(user_id: student_ids, polls: {course_id: course.id})
poll_users.update_all(is_delete: 1)
course.graduation_works.where(user_id: student_ids).update_all(is_delete: 1)
end
end

@ -11,7 +11,7 @@ class HomeworkAbsencePenaltyCalculationJob < ApplicationJob
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.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

@ -20,8 +20,8 @@ class CourseMember < ApplicationRecord
# 未分班
scope :ungroup_students, -> { where(course_group_id: 0, role: 4) }
after_destroy :delete_works
after_create :work_operation
# after_destroy :delete_works
# after_create :work_operation
def delete_works
if self.role == "STUDENT"
course = self.course
@ -52,13 +52,13 @@ class CourseMember < ApplicationRecord
def recover_works
course = self.course
student_works = StudentWork.where(user_id: self.user_id, homework_common_id: course.homework_commons)
student_works = StudentWork.joins(:homework_common).where(user_id: self.user_id, homework_commons: {course_id: course.id})
student_works.update_all(is_delete: 0)
exercise_users = ExerciseUser.where(user_id: self.user_id, exercise_id: course.exercises)
exercise_users = ExerciseUser.joins(:exercise).where(user_id: self.user_id, exercises: {course_id: course.id})
exercise_users.update_all(is_delete: 0)
poll_users = PollUser.where(user_id: self.user_id, poll_id: course.polls)
poll_users = PollUser.joins(:poll).where(user_id: self.user_id, polls: {course_id: course.id})
poll_users.update_all(is_delete: 0)
graduation_works = course.graduation_works.where(user_id: self.user_id)

@ -36,7 +36,7 @@ class BatchExportShixunReportService
rescue => ex
Rails.logger.error(ex.message)
zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write('文件重复') }
zip.get_output_stream('FILE_NOTICE.txt'){|os| os.write("文件重复:#{export.filename}") }
next
end
end

@ -5,4 +5,5 @@
- [default, 3]
- [score, 4]
- [evaluation_comment, 5]
- [course_member, 6]
- [notify, 100]

@ -60,9 +60,9 @@ namespace :homework_evaluation do
HomeworkAnonymousAppealStartNotifyJob.perform_later(homework_common.id)
else
homework_detail_manual.update_column('comment_status', 5)
# 没有申诉阶段则直接计算缺评扣分 否则申诉结束时才计算
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id)
end
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_common.id)
end
end
end
@ -71,5 +71,8 @@ namespace :homework_evaluation do
task :end_appeal => :environment do
homework_detail_manuals = HomeworkDetailManual.where("appeal_time <= '#{Time.now}' and homework_detail_manuals.comment_status = 4")
homework_detail_manuals.update_all(:comment_status => 5)
homework_detail_manuals.each do |homework_detail_manual|
HomeworkAbsencePenaltyCalculationJob.perform_later(homework_detail_manual.homework_common_id)
end
end
end

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

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