From 225e3c396a3f9c2becb431e3554be0816de28dde Mon Sep 17 00:00:00 2001 From: z9hang Date: Tue, 29 Jul 2014 10:06:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=AA=E4=BA=BA=E5=BE=97=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E5=88=86=E6=96=B9=E6=B3=95=E6=B7=BB=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/user_score_helper.rb | 96 +++++++++++++++++++++++++++++++- app/models/journal.rb | 10 +--- app/models/journal_detail.rb | 11 +++- app/models/memo.rb | 8 ++- app/models/message.rb | 13 ++--- 5 files changed, 118 insertions(+), 20 deletions(-) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index 720919369..700a162ef 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -408,19 +408,33 @@ module UserScoreHelper update_score(option_number) end + #发帖数 + def memo_num(user,project=nil) + Message.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + Memo.includes(:author).where("parent_id IS NULL and author_id = '#{user.id}'").all.count + end + #更新对缺陷留言数 def update_messges_for_issue(user,type) option_number = get_option_number(user,type) - option_number.messages_for_issues = Journal.includes(:user).where("user_id = '#{user.id}'").all.count + option_number.messages_for_issues = Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count update_score(option_number) end + def messges_for_issue_num(user,project=nil) + Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count + end + #更新更改缺陷状态状态次数 def update_issues_status(user,type) option_number = get_option_number(user,type) option_number.issues_status = Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count update_score(option_number) end + + def issues_status_num(user,project=nil) + Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'status_id' and #{User.table_name}.id = '#{user.id}'").count + end + #更新对留言的回复数量 def update_replay_for_message(user,type) option_number = get_option_number(user,type) @@ -428,6 +442,10 @@ module UserScoreHelper update_score(option_number) end + def replay_for_message_num(user,project=nil) + JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id}").count + end + #更新对帖子的回复数量 def update_replay_for_memo(user,type) option_number = get_option_number(user,type) @@ -435,6 +453,10 @@ module UserScoreHelper update_score(option_number) end + def replay_for_memo_num(user,project=nil) + Message.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count + Memo.includes(:author).where("parent_id IS NOT NULL and author_id = #{user.id}").all.count + end + #更新被关注的人数 def update_follow(user,type) option_number = get_option_number(user,type) @@ -442,6 +464,10 @@ module UserScoreHelper update_score(option_number) end + def follow_num(user,project=nil) + Watcher.includes(:watchable).where("watchable_type = 'Principal' and watchable_id = '#{user.id}'").count + end + #更新帖子踩各项数量 def update_tread(user,type) option_number = get_option_number(user,type) @@ -472,6 +498,31 @@ module UserScoreHelper update_score(option_number) end + def tread_num(user,project=nil) + result0 = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0 and user_id = '#{user.id}'").all.count + pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 0").all + result = [] + result1 = [] + result2 = [] + pts.each do |pt| + obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id) + if obj.nil? + next + end + target_user = obj.author + level = UserLevels.get_level(pt.user)#pt.user.get_level + project = pt.project + if level == 1 && target_user.id = user.id + result << pt + elsif level == 2 && target_user.id = user.id + result1 << pt + elsif level == 3 && target_user.id = user.id + result2 << pt + end + end + [:tread=>result0,:tead_by_one => result.count,:tread_by_two => result1.count,:tread_by_three =>result2.count] + end + #更新帖子顶数量 def update_praise(user,type) option_number = get_option_number(user,type) @@ -501,6 +552,30 @@ module UserScoreHelper update_score(option_number) end + def praise_num(user,project=nil) + pts = PraiseTread.where("praise_tread_object_type = 'Memo' || praise_tread_object_type = 'Message' and praise_or_tread = 1").all + result = [] + result1 = [] + result2 = [] + pts.each do |pt| + obj = PraiseTread.find_object_by_type_and_id(pt.praise_tread_object_type, pt.praise_tread_object_id) + if obj.nil? + next + end + target_user = obj.author + level = UserLevels.get_level(pt.user)#pt.user.get_level + project = pt.project + if level == 1 && target_user.id = user.id + result << pt + elsif level == 2 && target_user.id = user.id + result1 << pt + elsif level == 3 && target_user.id = user.id + result2 << pt + end + end + [:praise_by_one => result.count,:praise_by_two => result1.count,:praise_by_three => result2.count] + end + #更新提交代码次数 def update_changeset(user,type) option_number = get_option_number(user,type) @@ -508,6 +583,10 @@ module UserScoreHelper update_score(option_number) end + def changeset_num(user,project=nil) + Changeset.includes(:user).where("user_id = '#{user.id}'").all.count + end + #更新文档提交次数 def update_document(user,type) option_number = get_option_number(user,type) @@ -515,6 +594,10 @@ module UserScoreHelper update_score(option_number) end + def document(user,project=nil?) + Document.includes(:user).where("user_id = '#{user.id}'").all.count + end + #更新附件提交数量 def update_attachment(user,type) option_number = get_option_number(user,type) @@ -522,6 +605,10 @@ module UserScoreHelper update_score(option_number) end + def attachment_num(user,project=nil) + Attachment.includes(:author).where("author_id = '#{user.id}'").all.count + end + #更新缺陷完成度次数 def update_issue_done_ratio(user,type) option_number = get_option_number(user,type) @@ -529,10 +616,17 @@ module UserScoreHelper update_score(option_number) end + def issue_done_ratio_num(user,project) + Journal.joins(:details, :user).where("#{JournalDetail.table_name}.prop_key = 'done_ratio' and #{User.table_name}.id = '#{user.id}'").count + end + #更新发布缺陷次数 def update_post_issue(user,type) option_number = get_option_number(user,type) option_number.post_issue = Issue.includes(:author).where("author_id = '#{user.id}'").all.count update_score(option_number) end + def post_issue_num(user,project=nil) + Issue.includes(:author).where("author_id = '#{user.id}'").all.count + end end diff --git a/app/models/journal.rb b/app/models/journal.rb index 8d03f2325..4e5780997 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -48,7 +48,7 @@ class Journal < ActiveRecord::Base # fq after_create :act_as_activity,:be_user_score # end - + after_destroy :down_user_score #before_save :be_user_score #before_destroy :down_user_score @@ -158,19 +158,13 @@ class Journal < ActiveRecord::Base # 更新用户分数 -by zjc def be_user_score - #新建了缺陷留言且留言不为空,不为空白 - if !self.notes.nil? && self.notes.gsub(' ','') != '' #协同得分加分 UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id }) update_messges_for_issue(User.current,1) - end end # 减少用户分数 -by zjc def down_user_score #删除有效缺陷留言 - if !self.notes.nil? && self.notes.gsub(' ','') != '' - #协同得分减分 - UserScore.joint(:delete_issue_message, User.current,self.issue.author, { message_id: self.id }) - end + update_messges_for_issue(User.current,1) end end diff --git a/app/models/journal_detail.rb b/app/models/journal_detail.rb index 4100a5b1c..2839077fe 100644 --- a/app/models/journal_detail.rb +++ b/app/models/journal_detail.rb @@ -20,6 +20,7 @@ class JournalDetail < ActiveRecord::Base belongs_to :journal before_save :normalize_values after_create :be_user_score + after_destroy :down_user_score private def normalize_values @@ -42,12 +43,18 @@ class JournalDetail < ActiveRecord::Base def be_user_score #更新缺陷完成度 - if self.prop_key = 'done_ratio' + if self.prop_key == 'done_ratio' update_issue_done_ratio(User.current,1) #更新缺陷状态 - elsif self.prop_key = 'status_id' + elsif self.prop_key == 'status_id' update_issues_status(User.current , 1) end end + #更新用户分数 + def down_user_score + update_issue_done_ratio(User.current,1) + update_issues_status(User.current , 1) + end + end diff --git a/app/models/memo.rb b/app/models/memo.rb index 6370065ba..3629db8a2 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -44,7 +44,7 @@ class Memo < ActiveRecord::Base after_create :add_author_as_watcher, :reset_counters!,:be_user_score # after_update :update_memos_forum - after_destroy :reset_counters! + after_destroy :reset_counters!,:down_user_score # after_create :send_notification # after_save :plusParentAndForum # after_destroy :minusParentAndForum @@ -157,4 +157,10 @@ class Memo < ActiveRecord::Base end end + #被删除时更新用户分数 + def down_user_score + update_memo_number(User.current,1) + update_replay_for_memo(User.current,1) + end + end diff --git a/app/models/message.rb b/app/models/message.rb index 2c183dc59..78071466d 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -59,7 +59,7 @@ class Message < ActiveRecord::Base after_create :add_author_as_watcher, :reset_counters! after_update :update_messages_board - after_destroy :reset_counters! + after_destroy :reset_counters!,:down_user_score # fq after_create :act_as_activity,:be_user_score @@ -158,14 +158,11 @@ class Message < ActiveRecord::Base update_replay_for_memo(User.current,1) end end + #减少用户分数 def down_user_score - #删除发帖 - if self.parent_id.nil? - UserScore.joint(:delete_message, User.current,nil, { message_id: self.id }) - #删除留言 - else - UserScore.joint(:reply_deleting, User.current,self.parent.author, { message_id: self.id }) - end + #更新发帖和回帖数量 + update_memo_number(User.current,1) + update_replay_for_memo(User.current,1) end end