2016-05-09 16:16:03 +08:00
|
|
|
#coding=utf-8
|
|
|
|
|
|
|
|
namespace :update_homework do
|
|
|
|
desc "update homework project time"
|
2016-07-08 14:40:21 +08:00
|
|
|
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")
|
2016-05-09 16:16:03 +08:00
|
|
|
unless homeworks.nil?
|
|
|
|
homeworks.each do |h|
|
|
|
|
if h.homework_type == 3
|
|
|
|
student_works = h.student_work_projects.where("is_leader = 1 && project_id != -1")
|
|
|
|
time = h.updated_at
|
|
|
|
unless student_works.nil?
|
|
|
|
student_works.each do |s|
|
|
|
|
project = Project.find s.project_id
|
2016-07-11 15:10:55 +08:00
|
|
|
unless project.nil? && project.gpid.blank?
|
2016-05-09 16:16:03 +08:00
|
|
|
project_time=project.updated_on
|
|
|
|
project_time=ForgeActivity.where("project_id=?",project.id).last.updated_at if ForgeActivity.where("project_id=?",project.id).last
|
2016-07-11 15:10:55 +08:00
|
|
|
puts "the time is =========================> #{time}"
|
|
|
|
puts "the project_time is =========================> #{project_time}"
|
|
|
|
#if time.strftime('%Y-%m-%d %H:%M:%S') < project_time.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
if format_time(time) < format_time(project_time)
|
2016-05-09 16:16:03 +08:00
|
|
|
time = project_time
|
|
|
|
end
|
|
|
|
begin
|
|
|
|
# gitlab端获取默认分支
|
|
|
|
g = Gitlab.client
|
|
|
|
default_branch = g.project(project.gpid).default_branch
|
|
|
|
changesets = g.commits(project.gpid, :ref_name => default_branch)
|
|
|
|
changesets_latest_coimmit = changesets[0]
|
|
|
|
unless changesets[0].blank?
|
2016-07-11 15:10:55 +08:00
|
|
|
puts "the time is =========================> #{time}"
|
|
|
|
puts "the changesets_latest_coimmit is =========================> #{changesets_latest_coimmit.created_at}"
|
|
|
|
#if time.strftime('%Y-%m-%d %H:%M:%S') < changesets_latest_coimmit.created_at.strftime('%Y-%m-%d %H:%M:%S')
|
|
|
|
if format_time(time) < format_time(changesets_latest_coimmit.created_at)
|
2016-05-09 16:16:03 +08:00
|
|
|
time = changesets_latest_coimmit.created_at
|
|
|
|
end
|
|
|
|
end
|
2016-07-08 14:40:21 +08:00
|
|
|
rescue Exception => e
|
|
|
|
puts e
|
2016-05-09 16:16:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
s_time = time
|
2016-07-08 19:45:15 +08:00
|
|
|
puts "latest time is =========================> #{time}"
|
2016-05-09 16:16:03 +08:00
|
|
|
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)
|
2016-07-08 19:45:15 +08:00
|
|
|
puts "user_activity time is =========================> #{course_activity}"
|
2016-05-09 16:16:03 +08:00
|
|
|
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)
|
2016-07-08 19:45:15 +08:00
|
|
|
puts "user_activity time is =========================> #{user_activity}"
|
2016-05-09 16:16:03 +08:00
|
|
|
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)
|
2016-07-08 19:45:15 +08:00
|
|
|
puts "org_activity time is =========================> #{org_activity}"
|
2016-05-09 16:16:03 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|