缺陷留言+1分、
更改缺陷状态+1分、 对留言回复+1分、 对帖子的回复+1分、 添加分数修正方法,分数为负时修正为0
This commit is contained in:
parent
541b22b84d
commit
7eb3c9f874
|
@ -122,7 +122,9 @@ class WatchersController < ApplicationController
|
|||
end
|
||||
|
||||
def find_watchables
|
||||
#根据参数获取关注对象的类型(user、project)
|
||||
klass = Object.const_get(params[:object_type].camelcase) rescue nil
|
||||
#判断获取的对象能否响应‘watched_by’方法
|
||||
if klass && klass.respond_to?('watched_by')
|
||||
@watchables = klass.find_all_by_id(Array.wrap(params[:object_id]))
|
||||
raise Unauthorized if @watchables.any? {|w| w.respond_to?(:visible?) && !w.visible?}
|
||||
|
|
|
@ -1493,7 +1493,10 @@ class Issue < ActiveRecord::Base
|
|||
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 })
|
||||
#缺陷状态更改
|
||||
elsif self.status_id_changed?
|
||||
#协同得分
|
||||
UserScore.joint(:change_issue_status, User.current,nil, {issue_id: self.id})
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -46,6 +46,7 @@ class Journal < ActiveRecord::Base
|
|||
|
||||
# fq
|
||||
after_create :act_as_activity
|
||||
before_save :be_user_score
|
||||
# end
|
||||
|
||||
scope :visible, lambda {|*args|
|
||||
|
@ -151,4 +152,13 @@ class Journal < ActiveRecord::Base
|
|||
self.acts << Activity.new(:user_id => self.user_id)
|
||||
end
|
||||
# end
|
||||
|
||||
# 更新用户分数 -by zjc
|
||||
def be_user_score
|
||||
#新建了留言且留言不为空,不为空白
|
||||
if self.new_record? && !self.notes.nil? && self.notes.gsub(' ','') != ''
|
||||
#协同得分加分
|
||||
UserScore.joint(:post_issue, User.current,self.issue.author, { message_id: self.id })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -42,6 +42,7 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
after_create :act_as_activity #huang
|
||||
after_create :reset_counters!
|
||||
after_destroy :reset_counters!
|
||||
before_save :be_user_score
|
||||
|
||||
# default_scope { where('m_parent_id IS NULL') }
|
||||
|
||||
|
@ -99,4 +100,13 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
count = find_all_by_m_parent_id(journals_for_messages.m_parent_id).count #(SELECT COUNT(*) FROM #{JournalsForMessage.table_name} WHERE m_parent_id = #{jfm_id} )
|
||||
update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id])
|
||||
end
|
||||
|
||||
# 更新用户分数 -by zjc
|
||||
def be_user_score
|
||||
#新建了留言且留言不为空,不为空白
|
||||
if self.new_record?
|
||||
#协同得分加分
|
||||
UserScore.joint(:reply_message, User.current,User.find(self.reply_id), { journals_for_messages_id: self.id })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -123,10 +123,14 @@ class Message < ActiveRecord::Base
|
|||
end
|
||||
# end
|
||||
|
||||
# update user score
|
||||
#更新用户分数 -by zjc
|
||||
def be_user_score
|
||||
if self.new_record?
|
||||
#新建message且无parent的为发帖
|
||||
if self.new_record? && self.parent_id.nil?
|
||||
UserScore.joint(:post_message, User.current,nil, { 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 })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
class UserScore < ActiveRecord::Base
|
||||
belongs_to :user
|
||||
|
||||
before_save :correct_score
|
||||
|
||||
def self.find_max_file
|
||||
self.maximum(:file)
|
||||
end
|
||||
|
@ -50,23 +52,23 @@ class UserScore < ActiveRecord::Base
|
|||
current_user, target_user = get_users(current_user, target_user)
|
||||
user_score = current_user.user_score_attr
|
||||
case operate
|
||||
when :post_message # current_user 发帖了
|
||||
when :post_message # current_user 发帖了 Add Message
|
||||
user_score.collaboration = user_score.collaboration.to_i + 2
|
||||
user_score.save
|
||||
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a message. options => (#{options.to_s})"
|
||||
when :post_issue # current_user 对 target_user 的缺陷留言了
|
||||
when :post_issue # current_user 对 target_user 的缺陷留言了 Add Journal
|
||||
user_score.collaboration = user_score.collaboration.to_i + 1
|
||||
user_score.save
|
||||
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} posting a issue. options => (#{options.to_s})"
|
||||
when :change_issue_status # current_user 更改了缺陷的状态
|
||||
when :change_issue_status # current_user 更改了缺陷的状态 Changed Issue
|
||||
user_score.collaboration = user_score.collaboration.to_i + 1
|
||||
user_score.save
|
||||
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} change issue status. options => (#{options.to_s})"
|
||||
when :reply_message # current_user 对 target_user 留言的回复
|
||||
when :reply_message # current_user 对 target_user 留言的回复 Add Journals_for_messages
|
||||
user_score.collaboration = user_score.collaboration.to_i + 1
|
||||
user_score.save
|
||||
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply message. options => (#{options.to_s})"
|
||||
when :reply_posting # current_user 对 target_user 帖子的回复
|
||||
when :reply_posting # current_user 对 target_user 帖子的回复 Add Message
|
||||
user_score.collaboration = user_score.collaboration.to_i + 1
|
||||
user_score.save
|
||||
Rails.logger.info "[UserScore#joint] ===> User: #{current_user} reply posting. options => (#{options.to_s})"
|
||||
|
@ -90,12 +92,16 @@ class UserScore < ActiveRecord::Base
|
|||
# Returns boolean. 返回积分保存结果
|
||||
def self.influence(operate, current_user, target_user, options={})
|
||||
current_user, target_user = get_users(current_user, target_user)
|
||||
user_score = current_user.user_score_attr
|
||||
user_score = target_user.user_score_attr
|
||||
case operate
|
||||
when :followed_by # current_user 关注了target_user
|
||||
user_score.active = user_score.influence.to_i + 2
|
||||
user_score.save
|
||||
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} be followed. options => (#{options.to_s})"
|
||||
when :cancel_followed # current_uer 取消了对 target_user的关注
|
||||
user_score.active = user_score.influence.to_i - 2
|
||||
user_score.save
|
||||
Rails.logger.info "[UserScore#influence] ===> User: #{current_user} canceled followed. options => (#{options.to_s})"
|
||||
else
|
||||
Rails.logger.error "[UserScore#influence] ===> #{operate} is not define."
|
||||
return false
|
||||
|
@ -183,4 +189,22 @@ class UserScore < ActiveRecord::Base
|
|||
|
||||
[cUser, tUser]
|
||||
end
|
||||
|
||||
#修正分数
|
||||
#分数小于0时修正为0
|
||||
#分数大于等于0时不修正 -by zjc
|
||||
def correct_score
|
||||
if self.collaboration < 0
|
||||
self.collaboration = 0
|
||||
end
|
||||
if self.active < 0
|
||||
self.active = 0
|
||||
end
|
||||
if self.influence < 0
|
||||
self.influence = 0
|
||||
end
|
||||
if self.skill < 0
|
||||
self.skill = 0
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue