socialforge/lib/tasks/homework_publishtime.rake

59 lines
2.5 KiB
Ruby
Raw Normal View History

2015-10-30 13:58:54 +08:00
#coding=utf-8
namespace :homework_publishtime do
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")
2015-10-30 13:58:54 +08:00
homework_commons = HomeworkCommon.where("publish_time = '#{Date.today}'")
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)
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
2016-10-14 20:31:42 +08:00
str += "('#{name_str}',#{homework.id},#{student.student_id}, '#{Time.now}', '#{Time.now}')"
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
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
# 邮件通知
Mailer.run.homework_added(homework)
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
task :end => :environment do
2016-10-15 16:09:21 +08:00
puts "--------------------------------homework_publish_end start"
Rails.logger.info("log--------------------------------homework_publish_end start")
2015-12-01 09:22:01 +08:00
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
2016-10-15 16:09:21 +08:00
Rails.logger.info("log--------------------------------homework_publish_end end")
puts "--------------------------------homework_publish_end end"
end
2015-10-30 13:58:54 +08:00
end