This commit is contained in:
nwb 2014-07-01 15:29:44 +08:00
commit 7881a3f20f
4 changed files with 154 additions and 65 deletions

View File

@ -122,7 +122,7 @@ class MembersController < ApplicationController
user_ids = attrs.delete(:user_ids) user_ids = attrs.delete(:user_ids)
user_ids.each do |user_id| user_ids.each do |user_id|
members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id) members << Member.new(:role_ids => params[:membership][:role_ids], :user_id => user_id)
user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id) #user_grades << UserGrade.new(:user_id => user_id, :course_id => @course.id)
if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3") if (params[:membership][:role_ids] && params[:membership][:role_ids][0] == "3")
course_info << CourseInfo.new(:user_id => user_id, :course_id => @course.id) course_info << CourseInfo.new(:user_id => user_id, :course_id => @course.id)
end end

View File

@ -117,6 +117,15 @@ class JournalsForMessage < ActiveRecord::Base
update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id]) update_all("m_reply_count = #{count.to_i}", ["id = ?", journals_for_messages.m_parent_id])
end end
#如果是在项目中留言则返回该项目否则返回nil - zjc
def project
if self.jour_type == 'Project'
Project.find(self.jour_id)
else
nil
end
end
# 更新用户分数 -by zjc # 更新用户分数 -by zjc
def be_user_score def be_user_score
#新建了留言回复 #新建了留言回复

View File

@ -2,4 +2,37 @@ class UserGrade < ActiveRecord::Base
# attr_accessible :title, :body # attr_accessible :title, :body
attr_accessible :user_id, :project_id, :grade attr_accessible :user_id, :project_id, :grade
belongs_to :project belongs_to :project
before_save :correct_score
validates_uniqueness_of :user_id, :scope => [:project_id]
#validate :my_validation
#修正分数
#分数小于0时修正为0
#分数大于等于0时不修正 -by zjc
def correct_score
if !self.grade.nil? && self.grade < 0
self.grade = 0
end
end
#def self.exit_user_and_project(user,project)
# unless user.nil? || project.nil?
# if user.class.to_s == 'User' && project.class.to_s == 'Project'
# user_grade = UserGrade.find_by_user_id_and_project_id(user.id,project.id)
# user_grade
# else
# nil
# end
# else
# nil
# end
#end
#def my_validation
# if user_id.nil? || project_id.nil?
# errors[:Base] << "用户和项目不能为空"
# elsif UserGrade.exit_user_and_project(user_id,project_id)
# errors[:Base] << "当前记录已存在"
# end
#end
end end

View File

@ -17,6 +17,7 @@ namespace :user_score do
users[m.author.id] = users[m.author.id].to_i + 2 users[m.author.id] = users[m.author.id].to_i + 2
project = m.project project = m.project
unless project.nil? unless project.nil?
if m.author.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id => m.author.id, :project_id => project.id) user_grade = UserGrade.create(:user_id => m.author.id, :project_id => project.id)
@ -25,6 +26,8 @@ namespace :user_score do
end end
end end
end
puts ":post_message calculate Completed. collaboration users count: #{users.count}" puts ":post_message calculate Completed. collaboration users count: #{users.count}"
# 对缺陷的留言 # 对缺陷的留言
@ -32,12 +35,15 @@ namespace :user_score do
users[j.user.id] = users[j.user.id].to_i + 1 users[j.user.id] = users[j.user.id].to_i + 1
project = j.project project = j.project
unless project.nil? unless project.nil?
if j.user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 1 grades[user_grade.id] = grades[user_grade.id].to_i + 1
end end
end
end end
puts ":post_issue_message calculate Completed. collaboration users count: #{users.count}" puts ":post_issue_message calculate Completed. collaboration users count: #{users.count}"
@ -46,6 +52,7 @@ namespace :user_score do
users[j.user.id] = users[j.user.id].to_i + 1 users[j.user.id] = users[j.user.id].to_i + 1
project = j.project project = j.project
unless project.nil? unless project.nil?
if j.user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id => j.user.id, :project_id => project.id)
@ -54,6 +61,8 @@ namespace :user_score do
end end
end end
end
puts ":change_issue_status calculate Completed. collaboration users count: #{users.count}" puts ":change_issue_status calculate Completed. collaboration users count: #{users.count}"
# 对留言的回复 # 对留言的回复
@ -67,12 +76,15 @@ namespace :user_score do
users[m.author.id] = users[m.author.id].to_i + 1 users[m.author.id] = users[m.author.id].to_i + 1
project = m.project project = m.project
unless project.nil? unless project.nil?
if m.author.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(m.author.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>m.author.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>m.author.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 1 grades[user_grade.id] = grades[user_grade.id].to_i + 1
end end
end
end end
puts ":reply_posting calculate Completed. collaboration users count: #{users.count}" puts ":reply_posting calculate Completed. collaboration users count: #{users.count}"
@ -116,69 +128,90 @@ namespace :user_score do
#踩帖 #踩帖
users_skill[pt.user.id] = users_skill[pt.user.id].to_i - 2 #踩别人帖-2分 users_skill[pt.user.id] = users_skill[pt.user.id].to_i - 2 #踩别人帖-2分
unless project.nil? unless project.nil?
if pt.user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(pt.user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(pt.user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>pt.user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>pt.user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i - 2 grades[user_grade.id] = grades[user_grade.id].to_i - 2
end end
end
if level == 1 if level == 1
users_skill[target_user.id] = users_skill[target_user.id].to_i - 2 #帖子被一级会员踩-2分 add praise_tread users_skill[target_user.id] = users_skill[target_user.id].to_i - 2 #帖子被一级会员踩-2分 add praise_tread
unless project.nil? unless project.nil?
if target_user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i - 2 grades[user_grade.id] = grades[user_grade.id].to_i - 2
end end
end
elsif level == 2 elsif level == 2
users_skill[target_user.id] = users_skill[target_user.id].to_i - 4 #帖子被二级会员踩-4分 add praise_tread users_skill[target_user.id] = users_skill[target_user.id].to_i - 4 #帖子被二级会员踩-4分 add praise_tread
unless project.nil? unless project.nil?
if target_user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i - 4 grades[user_grade.id] = grades[user_grade.id].to_i - 4
end end
end
elsif level == 3 elsif level == 3
users_skill[target_user.id] = users_skill[target_user.id].to_i - 6 #帖子被三级会员踩-6分 add praise_tread users_skill[target_user.id] = users_skill[target_user.id].to_i - 6 #帖子被三级会员踩-6分 add praise_tread
unless project.nil? unless project.nil?
if target_user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i - 6 grades[user_grade.id] = grades[user_grade.id].to_i - 6
end end
end
end end
elsif pt.praise_or_tread == 1 elsif pt.praise_or_tread == 1
#顶贴 #顶贴
if level == 1 if level == 1
users_skill[target_user.id] = users_skill[target_user.id].to_i + 4 #帖子被一级会员顶+4分 add praise_tread users_skill[target_user.id] = users_skill[target_user.id].to_i + 4 #帖子被一级会员顶+4分 add praise_tread
unless project.nil? unless project.nil?
if target_user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 4 grades[user_grade.id] = grades[user_grade.id].to_i + 4
end end
end
elsif level == 2 elsif level == 2
users_skill[target_user.id] = users_skill[target_user.id].to_i + 6 #帖子被二级会员顶+6分 add praise_tread users_skill[target_user.id] = users_skill[target_user.id].to_i + 6 #帖子被二级会员顶+6分 add praise_tread
unless project.nil? unless project.nil?
if target_user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 6 grades[user_grade.id] = grades[user_grade.id].to_i + 6
end end
end
elsif level == 3 elsif level == 3
users_skill[target_user.id] = users_skill[target_user.id].to_i + 8 #帖子被三级会员顶+8分 add praise_tread users_skill[target_user.id] = users_skill[target_user.id].to_i + 8 #帖子被三级会员顶+8分 add praise_tread
unless project.nil? unless project.nil?
if target_user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(target_user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>target_user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 8 grades[user_grade.id] = grades[user_grade.id].to_i + 8
end end
end
end end
end end
end end
@ -201,12 +234,15 @@ namespace :user_score do
users_active[changeset.user.id] = users_active[changeset.user.id].to_i + 4 users_active[changeset.user.id] = users_active[changeset.user.id].to_i + 4
project = changeset.project project = changeset.project
unless project.nil? unless project.nil?
if changeset.user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(changeset.user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(changeset.user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>changeset.user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>changeset.user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 4 grades[user_grade.id] = grades[user_grade.id].to_i + 4
end end
end
end end
puts ":push_code calculate Completed. active users count: #{users_active.count}" puts ":push_code calculate Completed. active users count: #{users_active.count}"
#提交文档 #提交文档
@ -217,12 +253,15 @@ namespace :user_score do
users_active[document.user.id] = users_active[document.user.id].to_i + 4 users_active[document.user.id] = users_active[document.user.id].to_i + 4
project = document.project project = document.project
unless project.nil? unless project.nil?
if document.user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(document.user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(document.user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>document.user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>document.user.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 4 grades[user_grade.id] = grades[user_grade.id].to_i + 4
end end
end
end end
puts ":push_document calculate Completed. active users count: #{users_active.count}" puts ":push_document calculate Completed. active users count: #{users_active.count}"
#提交附件 #提交附件
@ -238,12 +277,15 @@ namespace :user_score do
if attachment.container.class.to_s == "Project" if attachment.container.class.to_s == "Project"
project = attachment.project project = attachment.project
unless project.nil? unless project.nil?
if attachment.author.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(attachment.author.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(attachment.author.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>attachment.author.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>attachment.author.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 4 grades[user_grade.id] = grades[user_grade.id].to_i + 4
end end
end
end end
# end # end
@ -255,6 +297,7 @@ namespace :user_score do
users_active[j.user.id] = users_active[j.user.id].to_i + 2 users_active[j.user.id] = users_active[j.user.id].to_i + 2
project = j.project project = j.project
unless project.nil? unless project.nil?
if j.user.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(j.user.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>j.user.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>j.user.id, :project_id => project.id)
@ -262,18 +305,22 @@ namespace :user_score do
grades[user_grade.id] = grades[user_grade.id].to_i + 4 grades[user_grade.id] = grades[user_grade.id].to_i + 4
end end
end end
end
puts ":update_issue_ratio calculate Completed. active users count: #{users_active.count}" puts ":update_issue_ratio calculate Completed. active users count: #{users_active.count}"
#发布缺陷 #发布缺陷
Issue.includes(:author).all.each do |issue| Issue.includes(:author).all.each do |issue|
users_active[issue.author.id] = users_active[issue.author.id].to_i + 4 users_active[issue.author.id] = users_active[issue.author.id].to_i + 4
project = issue.project project = issue.project
unless project.nil? unless project.nil?
if issue.author.member_of?(project)
user_grade = UserGrade.find_by_user_id_and_project_id(issue.author.id, project.id) user_grade = UserGrade.find_by_user_id_and_project_id(issue.author.id, project.id)
if user_grade.nil? if user_grade.nil?
user_grade = UserGrade.create(:user_id =>issue.author.id, :project_id => project.id) user_grade = UserGrade.create(:user_id =>issue.author.id, :project_id => project.id)
end end
grades[user_grade.id] = grades[user_grade.id].to_i + 4 grades[user_grade.id] = grades[user_grade.id].to_i + 4
end end
end
end end
puts ":post_issue calculate Completed. active users count: #{users_active.count}" puts ":post_issue calculate Completed. active users count: #{users_active.count}"