个人得相关分方法添加

This commit is contained in:
z9hang 2014-07-29 10:06:48 +08:00
parent 0d0fb7052e
commit 225e3c396a
5 changed files with 118 additions and 20 deletions

View File

@ -408,19 +408,33 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_messges_for_issue(user,type)
option_number = get_option_number(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) update_score(option_number)
end 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) def update_issues_status(user,type)
option_number = get_option_number(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 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) update_score(option_number)
end 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) def update_replay_for_message(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -428,6 +442,10 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_replay_for_memo(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -435,6 +453,10 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_follow(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -442,6 +464,10 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_tread(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -472,6 +498,31 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_praise(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -501,6 +552,30 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_changeset(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -508,6 +583,10 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end end
def changeset_num(user,project=nil)
Changeset.includes(:user).where("user_id = '#{user.id}'").all.count
end
#更新文档提交次数 #更新文档提交次数
def update_document(user,type) def update_document(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -515,6 +594,10 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end end
def document(user,project=nil?)
Document.includes(:user).where("user_id = '#{user.id}'").all.count
end
#更新附件提交数量 #更新附件提交数量
def update_attachment(user,type) def update_attachment(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -522,6 +605,10 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_issue_done_ratio(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
@ -529,10 +616,17 @@ module UserScoreHelper
update_score(option_number) update_score(option_number)
end 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) def update_post_issue(user,type)
option_number = get_option_number(user,type) option_number = get_option_number(user,type)
option_number.post_issue = Issue.includes(:author).where("author_id = '#{user.id}'").all.count option_number.post_issue = Issue.includes(:author).where("author_id = '#{user.id}'").all.count
update_score(option_number) update_score(option_number)
end end
def post_issue_num(user,project=nil)
Issue.includes(:author).where("author_id = '#{user.id}'").all.count
end
end end

View File

@ -48,7 +48,7 @@ class Journal < ActiveRecord::Base
# fq # fq
after_create :act_as_activity,:be_user_score after_create :act_as_activity,:be_user_score
# end # end
after_destroy :down_user_score
#before_save :be_user_score #before_save :be_user_score
#before_destroy :down_user_score #before_destroy :down_user_score
@ -158,19 +158,13 @@ class Journal < ActiveRecord::Base
# 更新用户分数 -by zjc # 更新用户分数 -by zjc
def be_user_score 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 }) UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id })
update_messges_for_issue(User.current,1) update_messges_for_issue(User.current,1)
end end
end
# 减少用户分数 -by zjc # 减少用户分数 -by zjc
def down_user_score def down_user_score
#删除有效缺陷留言 #删除有效缺陷留言
if !self.notes.nil? && self.notes.gsub(' ','') != '' update_messges_for_issue(User.current,1)
#协同得分减分
UserScore.joint(:delete_issue_message, User.current,self.issue.author, { message_id: self.id })
end
end end
end end

View File

@ -20,6 +20,7 @@ class JournalDetail < ActiveRecord::Base
belongs_to :journal belongs_to :journal
before_save :normalize_values before_save :normalize_values
after_create :be_user_score after_create :be_user_score
after_destroy :down_user_score
private private
def normalize_values def normalize_values
@ -42,12 +43,18 @@ class JournalDetail < ActiveRecord::Base
def be_user_score def be_user_score
#更新缺陷完成度 #更新缺陷完成度
if self.prop_key = 'done_ratio' if self.prop_key == 'done_ratio'
update_issue_done_ratio(User.current,1) 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) update_issues_status(User.current , 1)
end end
end end
#更新用户分数
def down_user_score
update_issue_done_ratio(User.current,1)
update_issues_status(User.current , 1)
end
end end

View File

@ -44,7 +44,7 @@ class Memo < ActiveRecord::Base
after_create :add_author_as_watcher, :reset_counters!,:be_user_score after_create :add_author_as_watcher, :reset_counters!,:be_user_score
# after_update :update_memos_forum # after_update :update_memos_forum
after_destroy :reset_counters! after_destroy :reset_counters!,:down_user_score
# after_create :send_notification # after_create :send_notification
# after_save :plusParentAndForum # after_save :plusParentAndForum
# after_destroy :minusParentAndForum # after_destroy :minusParentAndForum
@ -157,4 +157,10 @@ class Memo < ActiveRecord::Base
end end
end end
#被删除时更新用户分数
def down_user_score
update_memo_number(User.current,1)
update_replay_for_memo(User.current,1)
end
end end

View File

@ -59,7 +59,7 @@ class Message < ActiveRecord::Base
after_create :add_author_as_watcher, :reset_counters! after_create :add_author_as_watcher, :reset_counters!
after_update :update_messages_board after_update :update_messages_board
after_destroy :reset_counters! after_destroy :reset_counters!,:down_user_score
# fq # fq
after_create :act_as_activity,:be_user_score after_create :act_as_activity,:be_user_score
@ -158,14 +158,11 @@ class Message < ActiveRecord::Base
update_replay_for_memo(User.current,1) update_replay_for_memo(User.current,1)
end end
end end
#减少用户分数 #减少用户分数
def down_user_score def down_user_score
#删除发帖 #更新发帖和回帖数量
if self.parent_id.nil? update_memo_number(User.current,1)
UserScore.joint(:delete_message, User.current,nil, { message_id: self.id }) update_replay_for_memo(User.current,1)
#删除留言
else
UserScore.joint(:reply_deleting, User.current,self.parent.author, { message_id: self.id })
end
end end
end end