2015-10-30 13:58:54 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
namespace :homework_publishtime do
|
2015-11-12 14:53:12 +08:00
|
|
|
desc "start publish homework and end homework"
|
2015-10-30 13:58:54 +08:00
|
|
|
task :publish => :environment do
|
2016-10-15 12:36:07 +08:00
|
|
|
puts "--------------------------------homework_publish start"
|
2016-10-15 15:13:15 +08:00
|
|
|
Rails.logger.info("log--------------------------------homework_publish start")
|
2017-02-24 11:05:27 +08:00
|
|
|
homework_commons = HomeworkCommon.includes(:homework_detail_manual).where("publish_time < '#{Time.now}' and homework_detail_manuals.comment_status = 0")
|
2015-10-30 13:58:54 +08:00
|
|
|
homework_commons.each do |homework|
|
|
|
|
homework_detail_manual = homework.homework_detail_manual
|
|
|
|
if homework_detail_manual.comment_status == 0
|
|
|
|
homework_detail_manual.update_column('comment_status', 1)
|
2016-08-23 10:17:08 +08:00
|
|
|
if homework.homework_type != 3
|
|
|
|
students = homework.course.student
|
|
|
|
if !homework.course.nil? && !students.empty?
|
|
|
|
name = homework.name
|
|
|
|
name_str = name + "的作品提交"
|
|
|
|
str = ""
|
|
|
|
students.each do |student|
|
|
|
|
if str != ""
|
|
|
|
str += ","
|
|
|
|
end
|
2017-02-24 11:05:27 +08:00
|
|
|
str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}', '#{Time.now.strftime('%Y-%m-%d %H:%M:%S')}')"
|
2016-08-23 10:17:08 +08:00
|
|
|
end
|
|
|
|
sql = "insert into student_works (name, homework_common_id,user_id, created_at, updated_at) values" + str
|
|
|
|
ActiveRecord::Base.connection.execute sql
|
|
|
|
end
|
|
|
|
end
|
2017-02-10 14:35:43 +08:00
|
|
|
|
|
|
|
#更新CourseHomeworkStatistics中每个学生的未交作品数
|
|
|
|
homework.course.student.each do |student|
|
|
|
|
course_statistics = CourseHomeworkStatistics.find_by_course_id_and_user_id(homework.course_id, student.student_id)
|
|
|
|
course_statistics.update_attribute('un_commit_work_num', course_statistics.un_commit_work_num + 1) if course_statistics
|
|
|
|
end
|
|
|
|
|
2015-10-30 13:58:54 +08:00
|
|
|
course = homework.course
|
|
|
|
course.members.each do |m|
|
|
|
|
homework.course_messages << CourseMessage.new(:user_id => m.user_id, :course_id => course.id, :viewed => false, :status => nil)
|
|
|
|
end
|
|
|
|
if homework.course_acts.size == 0
|
|
|
|
homework.course_acts << CourseActivity.new(:user_id => homework.user_id,:course_id => homework.course_id)
|
|
|
|
end
|
|
|
|
# 邮件通知
|
2016-12-23 14:29:48 +08:00
|
|
|
# Mailer.run.homework_added(homework)
|
2015-10-30 13:58:54 +08:00
|
|
|
end
|
|
|
|
end
|
2016-10-15 15:13:15 +08:00
|
|
|
Rails.logger.info("log--------------------------------homework_publish end")
|
2016-10-15 12:36:07 +08:00
|
|
|
puts "--------------------------------homework_publish end"
|
2015-10-30 13:58:54 +08:00
|
|
|
end
|
2015-11-12 14:53:12 +08:00
|
|
|
|
2016-12-12 10:55:19 +08:00
|
|
|
# task :end => :environment do
|
|
|
|
# puts "--------------------------------homework_publish_end start"
|
|
|
|
# Rails.logger.info("log--------------------------------homework_publish_end start")
|
|
|
|
# homework_commons = HomeworkCommon.where("end_time = '#{Date.today}'")
|
|
|
|
# homework_commons.each do |homework|
|
|
|
|
# if homework.anonymous_comment == 1
|
|
|
|
# homework_detail_manual = homework.homework_detail_manual
|
|
|
|
# if homework_detail_manual.comment_status == 1
|
|
|
|
# homework_detail_manual.update_column('comment_status', 3)
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
# Rails.logger.info("log--------------------------------homework_publish_end end")
|
|
|
|
# puts "--------------------------------homework_publish_end end"
|
|
|
|
# end
|
2015-10-30 13:58:54 +08:00
|
|
|
end
|