diff --git a/app/models/attachment.rb b/app/models/attachment.rb index b2a7cfb0..66d1553e 100644 --- a/app/models/attachment.rb +++ b/app/models/attachment.rb @@ -370,7 +370,7 @@ class Attachment < ActiveRecord::Base type = self.container_type types = %w|Document News Version Project Issue Message WikiPage| if types.include?(type) - UserScore.project(:push_file, User.current, { attachment_id: self.id }) + UserScore.project(:push_file, User.current,self, { attachment_id: self.id }) end end end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 36f78d32..6c22455a 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -19,7 +19,7 @@ class Changeset < ActiveRecord::Base belongs_to :repository belongs_to :user - after_save :be_user_score # user_score + #after_save :be_user_score # user_score has_many :filechanges, :class_name => 'Change', :dependent => :delete_all # fq @@ -63,7 +63,7 @@ class Changeset < ActiveRecord::Base includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args)) } - after_create :scan_for_issues + after_create :scan_for_issues,:be_user_score # user_score before_create :before_create_cs # fq @@ -300,11 +300,9 @@ class Changeset < ActiveRecord::Base # update user score def be_user_score - if self.new_record? - UserScore.project(:push_code, self.user, { changeset_id: self.id }) + UserScore.project(:push_code, self.user,self, { changeset_id: self.id }) #更新用户等级 self.user.update_user_level - end end end diff --git a/app/models/document.rb b/app/models/document.rb index 3710e6eb..7c273068 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -21,7 +21,7 @@ class Document < ActiveRecord::Base belongs_to :user belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" - before_save :be_user_score # user_score + after_create :be_user_score # user_score acts_as_attachable :delete_permission => :delete_documents @@ -62,8 +62,6 @@ class Document < ActiveRecord::Base # update user score def be_user_score - if self.new_record? - UserScore.project(:push_document, self.user, { document_id: self.id }) - end + UserScore.project(:push_document, self.user,self,{ document_id: self.id }) end end diff --git a/app/models/issue.rb b/app/models/issue.rb index 6cfa9b7e..a9b3e357 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -76,8 +76,8 @@ class Issue < ActiveRecord::Base attr_reader :current_journal # fq - after_create :act_as_activity - before_save :be_user_score + after_create :act_as_activity,:be_user_score_new_issue + after_update :be_user_score # after_create :be_user_score # end @@ -1489,14 +1489,18 @@ class Issue < ActiveRecord::Base # update user score def be_user_score - if self.new_record? - UserScore.project(:post_issue, User.current, { issue_id: self.id }) - elsif self.done_ratio_changed? - UserScore.project(:update_issue_ratio, User.current, { issue_id: self.id }) + #缺陷完成度更新 + if self.done_ratio_changed? + UserScore.project(:update_issue_ratio, User.current,self,{ issue_id: self.id }) #缺陷状态更改 elsif self.status_id_changed? #协同得分 - UserScore.joint(:change_issue_status, User.current,nil, {issue_id: self.id}) + UserScore.joint(:change_issue_status, User.current,nil,self, {issue_id: self.id}) end end + + #发布缺陷 + def be_user_score_new_issue + UserScore.project(:post_issue, User.current,self, { issue_id: self.id }) + end end diff --git a/app/models/journal.rb b/app/models/journal.rb index b0e1e9d0..8027f18a 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -45,10 +45,10 @@ class Journal < ActiveRecord::Base before_create :split_private_notes # fq - after_create :act_as_activity + after_create :act_as_activity,:be_user_score # end - before_save :be_user_score + #before_save :be_user_score #before_destroy :down_user_score scope :visible, lambda {|*args| @@ -158,9 +158,9 @@ class Journal < ActiveRecord::Base # 更新用户分数 -by zjc def be_user_score #新建了缺陷留言且留言不为空,不为空白 - if self.new_record? && !self.notes.nil? && self.notes.gsub(' ','') != '' + if !self.notes.nil? && self.notes.gsub(' ','') != '' #协同得分加分 - UserScore.joint(:post_issue_message, User.current,self.issue.author, { message_id: self.id }) + UserScore.joint(:post_issue_message, User.current,self.issue.author,self, { message_id: self.id }) end end # 减少用户分数 -by zjc diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index cba605af..967511be 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -40,9 +40,9 @@ class JournalsForMessage < ActiveRecord::Base validates :notes, presence: true after_create :act_as_activity #huang - after_create :reset_counters! + after_create :reset_counters!,:be_user_score after_destroy :reset_counters! - before_save :be_user_score + #before_save :be_user_score #before_destroy :down_user_score # default_scope { where('m_parent_id IS NULL') } @@ -105,9 +105,9 @@ class JournalsForMessage < ActiveRecord::Base # 更新用户分数 -by zjc def be_user_score #新建了留言回复 - if self.new_record? && self.reply_id != 0 + if self.reply_id != 0 #协同得分加分 - UserScore.joint(:reply_message, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id }) + UserScore.joint(:reply_message, User.current,User.find(self.reply_id),self, { journals_for_messages_id: self.id }) end end # 更新用户分数 -by zjc diff --git a/app/models/memo.rb b/app/models/memo.rb index d706f814..1e857a22 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -12,6 +12,7 @@ class Memo < ActiveRecord::Base acts_as_tree :counter_cache => :replies_count, :order => "#{Memo.table_name}.created_at ASC" acts_as_attachable + has_many :user_score_details, :class_name => 'UserScoreDetails',:as => :score_changeable_obj belongs_to :last_reply, :class_name => 'Memo', :foreign_key => 'last_reply_id' # acts_as_searchable :column => ['subject', 'content'], # #:include => { :forum => :p} @@ -40,13 +41,13 @@ class Memo < ActiveRecord::Base "parent_id", "replies_count" - after_create :add_author_as_watcher, :reset_counters! + after_create :add_author_as_watcher, :reset_counters!,:be_user_score # after_update :update_memos_forum after_destroy :reset_counters! # after_create :send_notification # after_save :plusParentAndForum # after_destroy :minusParentAndForum - before_save :be_user_score + #before_save :be_user_score # scope :visible, lambda { |*args| # includes(:forum => ).where() # } @@ -145,11 +146,11 @@ class Memo < ActiveRecord::Base #更新用户分数 -by zjc def be_user_score #新建memo且无parent的为发帖 - if self.new_record? && self.parent_id.nil? - UserScore.joint(:post_message, User.current,nil, { memo_id: self.id }) + if self.parent_id.nil? + UserScore.joint(:post_message, User.current,nil,self ,{ memo_id: self.id }) #新建memo且有parent的为回帖 - elsif self.new_record? && !self.parent_id.nil? - UserScore.joint(:reply_posting, User.current,self.parent.author, { memo_id: self.id }) + elsif !self.parent_id.nil? + UserScore.joint(:reply_posting, User.current,self.parent.author,self, { memo_id: self.id }) end end diff --git a/app/models/message.rb b/app/models/message.rb index e778977f..4d35d003 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -53,8 +53,8 @@ class Message < ActiveRecord::Base after_destroy :reset_counters! # fq - after_create :act_as_activity - before_save :be_user_score + after_create :act_as_activity,:be_user_score + #before_save :be_user_score #before_destroy :down_user_score # end @@ -127,11 +127,11 @@ class Message < ActiveRecord::Base #更新用户分数 -by zjc def be_user_score #新建message且无parent的为发帖 - if self.new_record? && self.parent_id.nil? - UserScore.joint(:post_message, User.current,nil, { message_id: self.id }) + if self.parent_id.nil? + UserScore.joint(:post_message, User.current,nil,self, { message_id: self.id }) #新建message且有parent的为回帖 - elsif self.new_record? && !self.parent_id.nil? - UserScore.joint(:reply_posting, User.current,self.parent.author, { message_id: self.id }) + elsif !self.parent_id.nil? + UserScore.joint(:reply_posting, User.current,self.parent.author,self, { message_id: self.id }) end end #减少用户分数 diff --git a/app/models/praise_tread.rb b/app/models/praise_tread.rb index 11d68157..b18b569d 100644 --- a/app/models/praise_tread.rb +++ b/app/models/praise_tread.rb @@ -2,7 +2,7 @@ class PraiseTread < ActiveRecord::Base attr_accessible :user_id,:praise_tread_object_id,:praise_tread_object_type,:praise_or_tread belongs_to :user belongs_to :praise_tread_object, polymorphic: true - before_save :be_user_score + after_create :be_user_score def self.find_object_by_type_and_id(type,id) @obj = nil @@ -28,15 +28,15 @@ class PraiseTread < ActiveRecord::Base #更新用户分数 - by zjc def be_user_score #踩贴吧或讨论区帖子 - if self.new_record? && self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') + if self.praise_or_tread == 0 && (self.praise_tread_object_type == 'Memo' || 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(:treaded_by_user, User.current,target_user, { praise_tread_id: self.id }) + UserScore.skill(:treaded_by_user, User.current,target_user,self, { praise_tread_id: self.id }) #顶贴吧或讨论区帖子 - elsif self.new_record? && self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || self.praise_tread_object_type == 'Message') + elsif self.praise_or_tread == 1 && (self.praise_tread_object_type == 'Memo' || 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,{ praise_tread_id: self.id }) + UserScore.skill(:praised_by_user, User.current,target_user,self,{ praise_tread_id: self.id }) #更新用户等级 target_user.update_user_level end diff --git a/app/models/user_score.rb b/app/models/user_score.rb index 6d582919..0e355b79 100644 --- a/app/models/user_score.rb +++ b/app/models/user_score.rb @@ -48,46 +48,51 @@ class UserScore < ActiveRecord::Base # # => true #当前用户发帖计分操作成功 # # Returns boolean. 返回积分保存结果 - def self.joint(operate, current_user, target_user, options={}) + def self.joint(operate, current_user, target_user,obj, options={}) current_user, target_user = get_users(current_user, target_user) user_score = current_user.user_score_attr case operate when :post_message # current_user 发帖了 Add Message user_score.collaboration = user_score.collaboration.to_i + 2 user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:score_type => "collaboration",:score_action => "post_message",:user_id => current_user.id,:old_score => user_score.collaboration - 2,:new_score => user_score.collaboration,:current_user_level => current_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})" - when :delete_message # current_user 发帖了 Delete Message - user_score.collaboration = user_score.collaboration.to_i - 2 - user_score.save - Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a message. options => (#{options.to_s})" + #when :delete_message # current_user 删帖了 Delete Message + # user_score.collaboration = user_score.collaboration.to_i - 2 + # user_score.save + # Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a message. options => (#{options.to_s})" when :post_issue_message # current_user 对 target_user 的缺陷留言了 Add Journal user_score.collaboration = user_score.collaboration.to_i + 1 user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "collaboration",:score_action => "post_issue_message",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})" - when :delete_issue_message # current_user 删除了 对 target_user 的缺陷留言了 Delete Journal - user_score.collaboration = user_score.collaboration.to_i - 1 - user_score.save - Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a issue. options => (#{options.to_s})" + #when :delete_issue_message # current_user 删除了 对 target_user 的缺陷留言了 Delete Journal + # user_score.collaboration = user_score.collaboration.to_i - 1 + # user_score.save + # Rails.logger.info "[UserScore#joint] ===> User: #{current_user} deleting a issue. options => (#{options.to_s})" when :change_issue_status # current_user 更改了缺陷的状态 Changed Issue user_score.collaboration = user_score.collaboration.to_i + 1 user_score.save + create_score_changed_details({:current_user_id => current_user.id , :score_type => "collaboration",:score_action => "change_issue_status",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => current_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})" when :reply_message # current_user 对 target_user 留言的回复 Add Journals_for_messages user_score.collaboration = user_score.collaboration.to_i + 1 user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "collaboration",:score_action => "reply_message",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})" - when :reply_message_delete # current_user 删除了对 target_user 留言的回复 delete Journals_for_messages - user_score.collaboration = user_score.collaboration.to_i - 1 - user_score.save - Rails.logger.info "[UserScore#joint] ===> User: #{current_user} delete reply message. options => (#{options.to_s})" + #when :reply_message_delete # current_user 删除了对 target_user 留言的回复 delete Journals_for_messages + # user_score.collaboration = user_score.collaboration.to_i - 1 + # user_score.save + # Rails.logger.info "[UserScore#joint] ===> User: #{current_user} delete reply message. options => (#{options.to_s})" when :reply_posting # current_user 对 target_user 帖子的回复 Add Message user_score.collaboration = user_score.collaboration.to_i + 1 user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "collaboration",:score_action => "reply_posting",:user_id => current_user.id,:old_score => user_score.collaboration - 1,:new_score => user_score.collaboration,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})" - when :reply_deleting # current_user 删除了 对 target_user 帖子的回复 Delete Message - user_score.collaboration = user_score.collaboration.to_i - 1 - user_score.save - Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply deleting. options => (#{options.to_s})" + #when :reply_deleting # current_user 删除了 对 target_user 帖子的回复 Delete Message + # user_score.collaboration = user_score.collaboration.to_i - 1 + # user_score.save + # Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply deleting. options => (#{options.to_s})" else Rails.logger.error "[UserScore#joint] ===> #{operate} is not define." return false @@ -106,17 +111,19 @@ class UserScore < ActiveRecord::Base # # => true #当前被关注用户记分成功 # # Returns boolean. 返回积分保存结果 - def self.influence(operate, current_user, target_user, options={}) + def self.influence(operate, current_user, target_user,obj, options={}) current_user, target_user = get_users(current_user, target_user) user_score = target_user.user_score_attr case operate when :followed_by # current_user 关注了target_user Add watcher user_score.influence = user_score.influence.to_i + 2 user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "influence",:score_action => "followed_by",:user_id => target_user.id,:old_score => user_score.influence - 2,:new_score => user_score.influence,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})" when :cancel_followed # current_uer 取消了对 target_user的关注 delete watcher user_score.influence = user_score.influence.to_i - 2 user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "influence",:score_action => "cancel_followed",:user_id => target_user.id,:old_score => user_score.influence + 2,:new_score => user_score.influence,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})" else Rails.logger.error "[UserScore#influence] ===> #{operate} is not define." @@ -136,7 +143,7 @@ class UserScore < ActiveRecord::Base # # => true #当前current_user对target_user用户帖子的记分成功 # # Returns boolean. 返回积分保存结果 - def self.skill(operate, current_user, target_user, options={}) + def self.skill(operate, current_user, target_user,obj, options={}) current_user, target_user = get_users(current_user, target_user) current_user_score = current_user.user_score_attr target_user_score = target_user.user_score_attr @@ -146,6 +153,7 @@ class UserScore < ActiveRecord::Base when :treaded_by_user # current_user 踩了 target_user 的帖子 current_user_score.skill = current_user_score.skill.to_i - 2 #踩别人的帖子减2分 add praise_tread current_user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => current_user.id,:old_score => current_user_score.skill + 2,:new_score => current_user_score.skill,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) if current_user.id == target_user.id target_user.reload target_user_score = target_user.user_score_attr @@ -154,12 +162,15 @@ class UserScore < ActiveRecord::Base if level == 1 target_user_score.skill = target_user_score.skill.to_i - 2 #帖子被一级会员踩-2分 add praise_tread target_user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => target_user.id,:old_score => target_user_score.skill + 2,:new_score => target_user_score.skill,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) elsif level == 2 target_user_score.skill = target_user_score.skill.to_i - 4 #帖子被二级会员踩-4分 add praise_tread target_user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => target_user.id,:old_score => target_user_score.skill + 4,:new_score => target_user_score.skill,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) elsif level == 3 target_user_score.skill = target_user_score.skill.to_i - 6 #帖子被三级会员踩-6分 add praise_tread target_user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "treaded_by_user",:user_id => target_user.id,:old_score => target_user_score.skill + 6,:new_score => target_user_score.skill,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) end Rails.logger.info "[UserScore#skill] ===> User: #{current_user} treaded_by #{target_user}. options => (#{options.to_s})" @@ -168,14 +179,16 @@ class UserScore < ActiveRecord::Base if level == 1 target_user_score.skill = target_user_score.skill.to_i + 4 #帖子被一级会员顶+4分 add praise_tread target_user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "praised_by_user",:user_id => target_user.id,:old_score => target_user_score.skill - 4,:new_score => target_user_score.skill,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) elsif level == 2 target_user_score.skill = target_user_score.skill.to_i + 6 #帖子被二级会员顶+6分 add praise_tread target_user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "praised_by_user",:user_id => target_user.id,:old_score => target_user_score.skill - 6,:new_score => target_user_score.skill,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) elsif level == 3 target_user_score.skill = target_user_score.skill.to_i + 8 #帖子被三级会员顶+8分 add praise_tread target_user_score.save + create_score_changed_details({:current_user_id => current_user.id ,:target_user_id =>target_user.id, :score_type => "skill",:score_action => "praised_by_user",:user_id => target_user.id,:old_score => target_user_score.skill - 8,:new_score => target_user_score.skill,:current_user_level => current_user.get_level,:target_user_level => target_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) end - Rails.logger.info "[UserScore#skill] ===> User: #{current_user} praised_by #{target_user}. options => (#{options.to_s})" else Rails.logger.error "[UserScore#skill] ===> #{operate} is not define." @@ -195,7 +208,7 @@ class UserScore < ActiveRecord::Base # # => true #当前current_user对项目贡献积分成功 # # Returns boolean. 返回积分保存结果 - def self.project(operate, current_user, options={}) + def self.project(operate, current_user,obj, options={}) current_user, target_user = get_users(current_user, nil) user_score = current_user.try(:user_score_attr) return false if current_user.nil? @@ -203,22 +216,27 @@ class UserScore < ActiveRecord::Base when :push_code # current_user 提交了代码 changeset user_score = user_score.active.to_i + 4 user_score.save + create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "push_code",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => current_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed code one time. options => (#{options.to_s})" when :push_document # current_user 提交了文档 document user_score.active = user_score.active.to_i + 4 user_score.save + create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "push_document",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => current_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a document. options => (#{options.to_s})" when :push_file # current_user 提交了附件 attachment user_score.active = user_score.active.to_i + 4 user_score.save + create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "push_file",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => current_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] pushed a file. options => (#{options.to_s})" when :update_issue_ratio # current_user 更新了缺陷完成度 issue user_score.active = user_score.active.to_i + 2 user_score.save + create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "update_issue_ratio",:user_id => current_user.id,:old_score => user_score.active - 2,:new_score => user_score.active,:current_user_level => current_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] updated issue ratio. options => (#{options.to_s})" when :post_issue # current_user 发布了缺陷 issue user_score.active = user_score.active.to_i + 4 user_score.save + create_score_changed_details({:current_user_id => current_user.id , :score_type => "active",:score_action => "post_issue",:user_id => current_user.id,:old_score => user_score.active - 4,:new_score => user_score.active,:current_user_level => current_user.get_level,:score_changeable_obj_id=> obj.id,:score_changeable_obj_type => obj.class.to_s}) Rails.logger.debug "[UserScore#project] ===> User: [#{current_user.id},#{current_user.name}] posting issue. options => (#{options.to_s})" else Rails.logger.error "[UserScore#project] ===> #{operate} is not define." @@ -234,6 +252,26 @@ class UserScore < ActiveRecord::Base score end + #创建分数改变记录 -by zjc + def self.create_score_changed_details(attributes) + if attributes.is_a? Hash + usd = UserScoreDetails.new + usd.current_user_id =attributes[:current_user_id] + usd.target_user_id = attributes[:target_user_id] + usd.score_type = attributes[:score_type] + usd.score_action = attributes[:score_action] + usd.user_id = attributes[:user_id] + usd.old_score = attributes[:old_score] + usd.new_score = attributes[:new_score] + usd.current_user_level = attributes[:current_user_level] + usd.target_user_level = attributes[:target_user_level] + #usd.score_changeable_obj = attributes[:score_changeable_obj] + usd.score_changeable_obj_id = attributes[:score_changeable_obj_id] + usd.score_changeable_obj_type = attributes[:score_changeable_obj_type] + usd.save + end + end + private def self.get_users(current_user, target_user) diff --git a/app/models/watcher.rb b/app/models/watcher.rb index 88f23900..e2e255a1 100644 --- a/app/models/watcher.rb +++ b/app/models/watcher.rb @@ -22,7 +22,7 @@ class Watcher < ActiveRecord::Base has_one :project_status has_one :users_status #end - before_save :be_user_score + after_create :be_user_score before_destroy :down_user_score validates_presence_of :user @@ -76,9 +76,9 @@ class Watcher < ActiveRecord::Base # 更新用户分数 -by zjc def be_user_score #添加了关注 - if self.new_record? && self.watchable_type == 'Principal' + if self.watchable_type == 'Principal' #影响力得分 - UserScore.influence(:followed_by, self.user,self.watchable, { watcher_id: self.id }) + UserScore.influence(:followed_by, self.user,self.watchable,self, { watcher_id: self.id }) end end @@ -86,7 +86,7 @@ class Watcher < ActiveRecord::Base def down_user_score #取消关注 if self.watchable_type == 'Principal' - UserScore.influence(:cancel_followed, self.user,self.watchable, { watcher_id: self.id }) + UserScore.influence(:cancel_followed, self.user,self.watchable,self, { watcher_id: self.id }) end end diff --git a/db/schema.rb b/db/schema.rb index b37bc56e..c8cf7128 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20140609061903) do +ActiveRecord::Schema.define(:version => 20140617013146) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -206,6 +206,17 @@ ActiveRecord::Schema.define(:version => 20140609061903) do t.string "reward" end + create_table "contestnotifications", :force => true do |t| + t.integer "contest_id" + t.string "title" + t.string "summary" + t.string "description" + t.integer "author_id" + t.integer "notificationcomments_count" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "contests", :force => true do |t| t.string "name" t.string "budget", :default => "" @@ -567,6 +578,15 @@ ActiveRecord::Schema.define(:version => 20140609061903) do t.datetime "updated_at", :null => false end + create_table "notificationcomments", :force => true do |t| + t.string "notificationcommented_type" + t.integer "notificationcommented_id" + t.integer "author_id" + t.text "notificationcomments" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "open_id_authentication_associations", :force => true do |t| t.integer "issued" t.integer "lifetime" @@ -923,6 +943,22 @@ ActiveRecord::Schema.define(:version => 20140609061903) do add_index "user_preferences", ["user_id"], :name => "index_user_preferences_on_user_id" + create_table "user_score_details", :force => true do |t| + t.integer "current_user_id" + t.integer "target_user_id" + t.string "score_type" + t.string "score_action" + t.integer "user_id" + t.integer "old_score" + t.integer "new_score" + t.integer "current_user_level" + t.integer "target_user_level" + t.integer "score_changeable_obj_id" + t.string "score_changeable_obj_type" + t.datetime "created_at", :null => false + t.datetime "updated_at", :null => false + end + create_table "user_scores", :force => true do |t| t.integer "user_id", :null => false t.integer "collaboration"