update homeworkcommon time
This commit is contained in:
parent
b22882aead
commit
8916cc7730
|
@ -2,7 +2,11 @@
|
|||
|
||||
namespace :update_homework do
|
||||
desc "update homework project time"
|
||||
def update_homework_time homeworks
|
||||
task :update_homework => :environment do
|
||||
year = Time.now.year
|
||||
courses = Course.where("time > ? and is_delete = 0", (year.to_i - 2))
|
||||
course_ids = courses.nil? ? '(-1)' : '(' + courses.map{|c| c.id}.join(',') + ')'
|
||||
homeworks = HomeworkCommon.where("course_id in #{course_ids} and homework_type = 3")
|
||||
unless homeworks.nil?
|
||||
homeworks.each do |h|
|
||||
if h.homework_type == 3
|
||||
|
@ -28,38 +32,34 @@ namespace :update_homework do
|
|||
time = changesets_latest_coimmit.created_at
|
||||
end
|
||||
end
|
||||
rescue
|
||||
rescue Exception => e
|
||||
puts e
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
s_time = time
|
||||
logger.info("latest time is =========================> #{time}")
|
||||
if time.strftime('%Y-%m-%d %H:%M:%S') > h.updated_at.strftime('%Y-%m-%d %H:%M:%S')
|
||||
h.update_column('updated_at', s_time)
|
||||
course_activity = CourseActivity.where("course_act_type=? and course_act_id =?", 'HomeworkCommon', h.id).first
|
||||
if course_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > course_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
course_activity.update_column('updated_at', s_time)
|
||||
logger.info("course_activity time is =========================> #{course_activity}")
|
||||
end
|
||||
user_activity = UserActivity.where("act_type=? and act_id =?", 'HomeworkCommon', h.id).first
|
||||
if user_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > user_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
user_activity.update_column('updated_at', s_time)
|
||||
logger.info("user_activity time is =========================> #{user_activity}")
|
||||
end
|
||||
org_activity = OrgActivity.where("org_act_type=? and org_act_id =?", 'HomeworkCommon', h.id).first
|
||||
if org_activity && (time.strftime('%Y-%m-%d %H:%M:%S') > org_activity.updated_at.strftime('%Y-%m-%d %H:%M:%S'))
|
||||
org_activity.update_column('updated_at', s_time)
|
||||
logger.info("org_activity time is =========================> #{s_time}")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
task :update_homework => :environment do
|
||||
year = Time.now.year
|
||||
courses = Course.where("time > ? and is_delete = 0", (year.to_i - 2))
|
||||
course_ids = courses.nil? ? '(-1)' : '(' + courses.map{|c| c.id}.join(',') + ')'
|
||||
homeworks = HomeworkCommon.where("course_id in #{course_ids} and homework_type = 3")
|
||||
unless homeworks.nil?
|
||||
update_homework_time homeworks
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue