|
|
@ -8,39 +8,24 @@ class ExercisePublishTask
|
|
|
|
exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
|
|
|
|
exercises = Exercise.includes(:exercise_users).where("publish_time is not null and exercise_status = 1 and publish_time <=?",Time.now)
|
|
|
|
exercises&.each do |exercise|
|
|
|
|
exercises&.each do |exercise|
|
|
|
|
exercise.update_column('exercise_status', 2)
|
|
|
|
exercise.update_column('exercise_status', 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if exercise.unified_setting
|
|
|
|
|
|
|
|
ExercisePublishNotifyJob.perform_later(exercise.id, nil)
|
|
|
|
|
|
|
|
else
|
|
|
|
course = exercise.course
|
|
|
|
course = exercise.course
|
|
|
|
|
|
|
|
teachers = course.teachers.where.not(id: course.teacher_course_groups.select(:course_member_id))
|
|
|
|
tid_str = ""
|
|
|
|
tid_str = ""
|
|
|
|
course.teachers.find_each do |member|
|
|
|
|
teachers.find_each do |member|
|
|
|
|
tid_str += "," if tid_str != ""
|
|
|
|
tid_str += "," if tid_str != ""
|
|
|
|
tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
|
|
tid_str += "(#{member.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if exercise.unified_setting
|
|
|
|
|
|
|
|
course.students.find_each do |student|
|
|
|
|
|
|
|
|
tid_str += "," if tid_str != ""
|
|
|
|
|
|
|
|
tid_str += "(#{student.user_id}, #{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if tid_str != ""
|
|
|
|
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
|
|
|
|
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
|
|
|
|
ActiveRecord::Base.connection.execute tid_sql
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if exercise.exercise_users.size == 0
|
|
|
|
|
|
|
|
str = ""
|
|
|
|
|
|
|
|
course.students.find_each do |student|
|
|
|
|
|
|
|
|
str += "," if str != ""
|
|
|
|
|
|
|
|
str += "(#{student.user_id}, #{exercise.id}, 0, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if str != ""
|
|
|
|
exercise.course_acts << CourseActivity.new(user_id: exercise.user_id, course_id: exercise.course_id) if !exercise.course_acts.exists?
|
|
|
|
sql = "insert into exercise_users (user_id, exercise_id, commit_status, created_at, updated_at) values" + str
|
|
|
|
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if exercise.course_acts.size == 0
|
|
|
|
|
|
|
|
exercise.course_acts << CourseActivity.new(:user_id => exercise.user_id,:course_id => exercise.course_id)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# 分组设置发布时间的测验
|
|
|
|
# 分组设置发布时间的测验
|
|
|
@ -48,18 +33,8 @@ class ExercisePublishTask
|
|
|
|
exercise_group_settings&.each do |exercise_group|
|
|
|
|
exercise_group_settings&.each do |exercise_group|
|
|
|
|
exercise = exercise_group.exercise
|
|
|
|
exercise = exercise_group.exercise
|
|
|
|
if exercise.present?
|
|
|
|
if exercise.present?
|
|
|
|
course = exercise.course
|
|
|
|
|
|
|
|
exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1
|
|
|
|
exercise.update_attributes(:exercise_status => 2) if exercise.exercise_status == 1
|
|
|
|
tid_str = ""
|
|
|
|
ExercisePublishNotifyJob.perform_later(exercise.id, [exercise_group.course_group_id])
|
|
|
|
members = course.students.where(:course_group_id => exercise_group.course_group_id)
|
|
|
|
|
|
|
|
members.find_each do |member|
|
|
|
|
|
|
|
|
tid_str += "," if tid_str != ""
|
|
|
|
|
|
|
|
tid_str += "(#{member.user_id},#{exercise.user_id}, #{exercise.id}, 'Exercise', #{exercise.id}, 'ExercisePublish', #{course.id}, 'Course', 0, 'Exercise', '#{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
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Rails.logger.info("log--------------------------------exercise_publish end")
|
|
|
|
Rails.logger.info("log--------------------------------exercise_publish end")
|
|
|
|