From ed3e9e3a0323274decb26fc58caf967531e5b7f3 Mon Sep 17 00:00:00 2001 From: z9hang Date: Mon, 18 Aug 2014 17:14:31 +0800 Subject: [PATCH] =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E6=88=90=E5=91=98=E5=88=97?= =?UTF-8?q?=E8=A1=A8=E7=A7=AF=E5=88=86=E8=AE=A1=E7=AE=97=E7=9A=84=E5=88=9D?= =?UTF-8?q?=E6=AD=A5=E4=BC=98=E5=8C=96=EF=BC=88=E9=99=8D=E4=BD=8E=E8=AE=BF?= =?UTF-8?q?=E9=97=AE=E9=80=9F=E5=BA=A6=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/helpers/user_score_helper.rb | 28 +++++++++++-------- app/models/attachment.rb | 7 +++++ app/models/changeset.rb | 2 ++ app/models/document.rb | 2 ++ app/models/issue.rb | 10 +++++-- app/models/journal.rb | 2 ++ app/models/journal_detail.rb | 13 +++++++++ app/models/journals_for_message.rb | 6 ++++ app/models/memo.rb | 3 +- app/models/message.rb | 16 +++++++++-- app/models/praise_tread.rb | 18 ++++++++++-- app/views/projects/_member_list.html.erb | 2 +- .../projects/_project_score_index.html.erb | 2 +- .../projects/_show_projects_score.html.erb | 2 +- 14 files changed, 92 insertions(+), 21 deletions(-) diff --git a/app/helpers/user_score_helper.rb b/app/helpers/user_score_helper.rb index e981f16a1..1353f9a1c 100644 --- a/app/helpers/user_score_helper.rb +++ b/app/helpers/user_score_helper.rb @@ -441,7 +441,7 @@ FROM `users` where id = #{user.id}") #更新对缺陷留言数 def update_messges_for_issue(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.messages_for_issues = messges_for_issue_num(user,project)#Journal.includes(:user).where("user_id = '#{user.id}' and notes != '' and notes is not null").all.count update_score(option_number) end @@ -464,7 +464,7 @@ FROM `users` where id = #{user.id}") #更新更改缺陷状态状态次数 def update_issues_status(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.issues_status = issues_status_num(user,project)#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 @@ -490,7 +490,7 @@ FROM `users` where id = #{user.id}") #更新对留言的回复数量 def update_replay_for_message(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.replay_for_message = replay_for_message_num(user,project)#JournalsForMessage.includes(:user).where("m_parent_id IS NOT NULL and user_id = #{user.id}").count update_score(option_number) end @@ -514,7 +514,7 @@ FROM `users` where id = #{user.id}") #更新对帖子的回复数量 def update_replay_for_memo(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.replay_for_memo = replay_for_memo_num(user,project)#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 update_score(option_number) end @@ -552,7 +552,7 @@ FROM `users` where id = #{user.id}") #更新帖子踩各项数量 def update_tread(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) tread_nums = tread_num(user,project) option_number.tread = tread_nums[:tread] option_number.tread_by_one = tread_nums[:tead_by_one] @@ -617,7 +617,7 @@ FROM `users` where id = #{user.id}") #更新帖子顶数量 def update_praise(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) praise_nums = praise_num(user,project) option_number.praise_by_one = praise_nums[:praise_by_one] option_number.praise_by_two = praise_nums[:praise_by_two] @@ -682,7 +682,7 @@ FROM `users` where id = #{user.id}") #更新提交代码次数 def update_changeset(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.changeset = changeset_num(user,project)#Changeset.includes(:user).where("user_id = '#{user.id}'").all.count update_score(option_number) end @@ -698,7 +698,7 @@ FROM `users` where id = #{user.id}") #更新文档提交次数 def update_document(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.document = document_num(user,project)#Document.includes(:user).where("user_id = '#{user.id}'").all.count update_score(option_number) end @@ -714,7 +714,7 @@ FROM `users` where id = #{user.id}") #更新附件提交数量 def update_attachment(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.attachment = attachment_num(user,project)#Attachment.includes(:author).where("author_id = '#{user.id}'").all.count update_score(option_number) end @@ -729,7 +729,7 @@ FROM `users` where id = #{user.id}") #更新缺陷完成度次数 def update_issue_done_ratio(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.issue_done_ratio = 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 update_score(option_number) end @@ -745,7 +745,7 @@ FROM `users` where id = #{user.id}") #更新发布缺陷次数 def update_post_issue(user,type,project=nil) - option_number = get_option_number(user,type) + option_number = get_option_number(user,type,project) option_number.post_issue = post_issue_num(user,project) #Issue.includes(:author).where("author_id = '#{user.id}'").all.count update_score(option_number) end @@ -758,6 +758,12 @@ FROM `users` where id = #{user.id}") end end + #读取项目成员得分 + def read_user_project_scores(user,project) + option_num = get_option_number(user,2,project) + option_num.total_score + end + def user_scores(user,type,project=nil) ooption_num = get_option_number(user,type,project) update_memo_number(user,type,project) diff --git a/app/models/attachment.rb b/app/models/attachment.rb index bcd8852f5..8f3d68d02 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -512,11 +512,18 @@ class Attachment < ActiveRecord::Base end end update_attachment(self.author,1) + if self.container_type == 'Project' + update_attachment(self.author,2,self.container) + end + end #删除附件时重新统计用户的附件数量得分 def down_user_score update_attachment(self.author,1) + if self.container_type == 'Project' + update_attachment(self.author,2,self.container) + end end end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 38bdd0cc8..f2228e699 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -308,12 +308,14 @@ class Changeset < ActiveRecord::Base #更新用户等级 UserLevels.update_user_level(self.user) update_changeset(self.user,1) + update_changeset(self.user,2,self.repository.project) end #积分刷新 def down_user_score UserLevels.update_user_level(self.user) update_changeset(self.user,1) + update_changeset(self.user,2,self.repository.project) end end diff --git a/app/models/document.rb b/app/models/document.rb index 42692bc22..7c2fa5a6d 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -69,9 +69,11 @@ class Document < ActiveRecord::Base def be_user_score UserScore.project(:push_document, self.user,self,{ document_id: self.id }) update_document(self.user,1) + update_document(self.user,2,self.project) end def down_user_score update_document(self.user,1) + update_document(self.user,2,self.project) end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 68afe21a2..3ff2a142d 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -1524,6 +1524,7 @@ class Issue < ActiveRecord::Base def be_user_score_new_issue UserScore.project(:post_issue, self.author,self, { issue_id: self.id }) update_post_issue(self.author,1) + update_post_issue(self.author,2,self.project) end def down_user_score @@ -1539,8 +1540,13 @@ class Issue < ActiveRecord::Base # update_issues_status(self.author , 1) #end update_post_issue(self.author,1) - update_issue_done_ratio(User.current,1) - update_issues_status(self.author , 1) + #update_issue_done_ratio(self.author,1) + #update_issues_status(self.author , 1) + + update_post_issue(self.author,2,self.project) + #update_issue_done_ratio(self.author,2,self.project) + #update_issues_status(self.author , 2) + end diff --git a/app/models/journal.rb b/app/models/journal.rb index 0fe2b804b..a386c2b80 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -163,6 +163,7 @@ class Journal < ActiveRecord::Base #协同得分加分 UserScore.joint(:post_issue_message, self.user,self.issue.author,self, { message_id: self.id }) update_messges_for_issue(self.user,1) + update_messges_for_issue(self.user,2,self.issue.project) end end @@ -173,6 +174,7 @@ class Journal < ActiveRecord::Base #协同得分减分 UserScore.joint(:delete_issue_message, self.user,self.issue.author,self, { message_id: self.id }) update_messges_for_issue(self.user,1) + update_messges_for_issue(self.user,2,self.issue.project) end end diff --git a/app/models/journal_detail.rb b/app/models/journal_detail.rb index 82a63b028..57541fe85 100644 --- a/app/models/journal_detail.rb +++ b/app/models/journal_detail.rb @@ -46,9 +46,15 @@ class JournalDetail < ActiveRecord::Base #更新缺陷完成度 if self.prop_key == 'done_ratio' update_issue_done_ratio(self.journal.user,1) + unless self.journal.project.nil? + update_issue_done_ratio(self.journal.user,2,self.journal.project) + end #更新缺陷状态 elsif self.prop_key == 'status_id' update_issues_status(self.journal.user , 1) + unless self.journal.project.nil? + update_issues_status(self.journal.user,2,self.journal.project) + end end end @@ -57,9 +63,16 @@ class JournalDetail < ActiveRecord::Base if self.prop_key == 'done_ratio' update_issue_done_ratio(self.journal.user,1) + unless self.journal.project.nil? + update_issue_done_ratio(self.journal.user,2,self.journal.project) + end + #更新缺陷状态 elsif self.prop_key == 'status_id' update_issues_status(self.journal.user, 1) + unless self.journal.project.nil? + update_issues_status(self.journal.user,2,self.journal.project) + end end end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index dd687f263..20e0c15f4 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -144,6 +144,9 @@ class JournalsForMessage < ActiveRecord::Base #协同得分加分 UserScore.joint(:reply_message, self.user,User.find(self.reply_id),self, { journals_for_messages_id: self.id }) update_replay_for_message(self.user,1) + if self.jour_type == "Project" + update_replay_for_message(self.user,2,self.jour) + end end end # 更新用户分数 -by zjc @@ -153,6 +156,9 @@ class JournalsForMessage < ActiveRecord::Base #协同得分减分 UserScore.joint(:reply_message_delete, self.user,User.find(self.reply_id), { journals_for_messages_id: self.id }) update_replay_for_message(self.user,1) + if self.jour_type == "Project" + update_replay_for_message(self.user,2,self.jour) + end end end end diff --git a/app/models/memo.rb b/app/models/memo.rb index 2c0d3571f..b02564834 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -146,11 +146,12 @@ class Memo < ActiveRecord::Base end #更新用户分数 -by zjc - def be_user_score + def be_user_score #新建memo且无parent的为发帖 if self.parent_id.nil? UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id }) update_memo_number(User.current,1) + #新建memo且有parent的为回帖 elsif !self.parent_id.nil? UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id }) diff --git a/app/models/message.rb b/app/models/message.rb index 647a665dc..62bfb34a5 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -152,11 +152,17 @@ class Message < ActiveRecord::Base #新建message且无parent的为发帖 if self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:post_message, self.author,nil,self, { message_id: self.id }) - update_memo_number(User.current,1) + update_memo_number(self.author,1) + if self.board.project_id != -1 + update_memo_number(self.author,2,self.board.project) + end #新建message且有parent的为回帖 elsif !self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:reply_posting, self.author,self.parent.author,self, { message_id: self.id }) - update_replay_for_memo(User.current,1) + update_replay_for_memo(self.author,1) + if self.board.project_id != -1 + update_replay_for_memo(self.author,2,self.board.project) + end end end @@ -165,9 +171,15 @@ class Message < ActiveRecord::Base if self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:delete_message, self.author,nil,self, { message_id: self.id }) update_memo_number(User.current,1) + if self.board.project_id != -1 + update_memo_number(self.author,2,self.board.project) + end elsif !self.parent_id.nil? && !self.board.project.nil? UserScore.joint(:reply_deleting, self.author,self.parent.author,self, { message_id: self.id }) update_replay_for_memo(User.current,1) + if self.board.project_id != -1 + update_replay_for_memo(self.author,2,self.board.project) + end end end end diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 0a7282d26..3df5c72d9 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -43,14 +43,21 @@ class PraiseTread < ActiveRecord::Base obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(User.current,1) + update_tread(self.user,1) update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end #顶贴吧或讨论区帖子 elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end #更新用户等级 UserLevels.update_user_level(target_user) end @@ -62,14 +69,21 @@ class PraiseTread < ActiveRecord::Base obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author #UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) - update_tread(User.current,1) + update_tread(self.user,1) update_tread(target_user,1) + unless self.project.nil? + update_tread(self.user,2,self.project) + update_tread(target_user,2,self.project) + end #顶贴吧或讨论区帖子 elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Issue' || self.praise_tread_object_type == 'Message') obj = PraiseTread.find_object_by_type_and_id(self.praise_tread_object_type,praise_tread_object_id) target_user = obj.author #UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) update_praise(target_user,1) + unless self.project.nil? + update_praise(target_user,2,self.project) + end #更新用户等级 UserLevels.update_user_level(target_user) end diff --git a/app/views/projects/_member_list.html.erb b/app/views/projects/_member_list.html.erb index 89a88e51c..670519bc0 100644 --- a/app/views/projects/_member_list.html.erb +++ b/app/views/projects/_member_list.html.erb @@ -24,7 +24,7 @@ <%= content_tag "div", content_tag("p", rolesToLanguage(member.roles.sort.collect(&:to_s)).join(', ')), :class => "clear avatar_name" %>

- <%= l(:label_user_for_project_grade) %>: <%= format("%.2f" ,user_scores(member.user,2,@project).total_score).to_i %> + <%= l(:label_user_for_project_grade) %>: <%= format("%.2f" ,read_user_project_scores(member.user,@project)).to_i %>

<% end %> diff --git a/app/views/projects/_project_score_index.html.erb b/app/views/projects/_project_score_index.html.erb index 4a94867fc..3cee4413c 100644 --- a/app/views/projects/_project_score_index.html.erb +++ b/app/views/projects/_project_score_index.html.erb @@ -4,7 +4,7 @@
= <%= l(:label_issue_score) %> + <%= l(:label_news_score) %> + <%= l(:label_file_score) %> + <%= l(:label_code_submit_score) %> + <%= l(:label_topic_score) %>
= <%= format("%.2f" , issue_score(@project)).to_i %> + <%= format("%.2f" , news_score(@project)).to_i %> + - <%= format("%.2f" , document_score(@project)).to_i %> + <%= format("%.2f" , changesets_score(@project)).to_i %> + + <%= format("%.2f" , documents_score(@project)).to_i %> + <%= format("%.2f" , changesets_score(@project)).to_i %> + <%= format("%.2f" , board_message_score(@project)).to_i %>
= <%= format("%.2f" , project_scores(@project)).to_i %>
\ No newline at end of file diff --git a/app/views/projects/_show_projects_score.html.erb b/app/views/projects/_show_projects_score.html.erb index 95c93d520..156e63f7b 100644 --- a/app/views/projects/_show_projects_score.html.erb +++ b/app/views/projects/_show_projects_score.html.erb @@ -37,7 +37,7 @@
  • <%= link_to l(:label_file_score), {:controller => 'projects', :action => 'file_score_index', :remote => true}%> : - <%= format("%.2f" , document_score(@project)).to_i %> + <%= format("%.2f" , documents_score(@project)).to_i %>
  • <%= link_to l(:label_code_submit_score), {:controller => 'projects', :action => 'code_submit_score_index', :remote => true}%> :