From 094af07a2ff1bfa269fb3cc37e6d112f807c69b4 Mon Sep 17 00:00:00 2001 From: huang Date: Sat, 5 Mar 2016 04:22:01 +0800 Subject: [PATCH] =?UTF-8?q?=E6=95=B0=E6=8D=AE=E8=BF=81=E7=A7=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ourse.rb => 20160304200639_update_contributor.rb} | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) rename db/migrate/{20160304154643_update_contributor_for_course.rb => 20160304200639_update_contributor.rb} (83%) diff --git a/db/migrate/20160304154643_update_contributor_for_course.rb b/db/migrate/20160304200639_update_contributor.rb similarity index 83% rename from db/migrate/20160304154643_update_contributor_for_course.rb rename to db/migrate/20160304200639_update_contributor.rb index 47107dd55..d90699b91 100644 --- a/db/migrate/20160304154643_update_contributor_for_course.rb +++ b/db/migrate/20160304200639_update_contributor.rb @@ -1,4 +1,4 @@ -class UpdateContributorForCourse < ActiveRecord::Migration +class UpdateContributor < ActiveRecord::Migration def up Course.all.each do |course| if course.course_activities.count > 1 @@ -8,16 +8,16 @@ class UpdateContributorForCourse < ActiveRecord::Migration puts s.user_id # board_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?",s.student_id, course.id, "Message").count * 2 # 发帖数 - board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is null;").count * 2 + board_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is null;").count # 回帖数 message_reply_count = Message.find_by_sql("select DISTINCT me.* from messages me, boards b where b.id = me.board_id and b.course_id = #{course.id} and b.project_id = '-1' and me.author_id = #{s.user_id} and me.parent_id is not null").count * 1 # 新闻回复 common_reply_count = Comment.find_by_sql("select cm.* from comments cm, news n where cm.author_id = #{s.user_id} and n.course_id = #{course.id} and cm.commented_id = n.id and cm.commented_type ='News'").count * 1 # 通知 - common_count = New.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").count * 1 + common_count = News.find_by_sql("select n.* from news n where n.author_id = #{s.user_id} and n.course_id = #{course.id} ").count * 1 # attachment_count = CourseActivity.where("user_id =? and course_id =? and course_act_type =?", s.student_id, course.id, "Attachment").count * 5 # 附件数 - attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.user_id} and container_type ='Course'").count * 5 + attachment_count = Attachment.find_by_sql("SELECT * FROM `attachments` where container_id = #{course.id} and author_id = #{s.user_id} and container_type ='Course'").count # 课程留言数 journal_count = JournalsForMessage.where("user_id =? and jour_id =? and jour_type =? ", s.user_id, course.id, "Course").count * 1 # 作业留言 @@ -28,8 +28,8 @@ class UpdateContributorForCourse < ActiveRecord::Migration course_contributor = CourseContributorScore.where("course_id =? and user_id =?", course.id, s.user_id).first if course_contributor.nil? CourseContributorScore.create(:course_id => course.id, :user_id => s.user_id, :message_num => board_count, :message_reply_num => message_reply_count, - :news_reply_num => common_reply_count, :news_num => common_count, :resource_num => attachment_count, :journal_num => journal_count, - :homework_journal_num => journal_homework_count, :journal_reply_num => 0, :total_score => total) + :news_reply_num => common_reply_count, :news_num => common_count, :resource_num => attachment_count, :journal_num => journal_count, + :homework_journal_num => journal_homework_count, :journal_reply_num => 0, :total_score => total) else course_contributor.message_num = board_count course_contributor.message_reply_num = message_reply_count