Merge remote-tracking branch 'origin/pm_project_develop' into pm_project_develop
This commit is contained in:
commit
1d9387e1ab
|
@ -6,16 +6,40 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController
|
|||
end
|
||||
|
||||
def create
|
||||
params[:link_ids].map { |e| @issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: e) }
|
||||
begin
|
||||
ActiveRecord::Base.transaction do
|
||||
params[:link_ids].each do |e|
|
||||
@issue.pm_links.find_or_create_by!(be_linkable_type: 'Issue', be_linkable_id: e)
|
||||
tag_issue = Issue.find_by_id(e)
|
||||
next unless tag_issue.present?
|
||||
journal = tag_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", value: @issue.id.to_s})
|
||||
end
|
||||
journal = @issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "tag_link_issue", prop_key: "#{params[:link_ids].size}", value: params[:link_ids].join(",")})
|
||||
end
|
||||
render_ok
|
||||
rescue
|
||||
render_error('创建失败!')
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
begin
|
||||
ActiveRecord::Base.transaction do
|
||||
@links = PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue', linkable_id: params[:id], linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue', be_linkable_id: params[:id], be_linkable_type: 'Issue'))
|
||||
journal = @issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: params[:id].to_s})
|
||||
another_issue = Issue.find_by_id(params[:id])
|
||||
if another_issue.present?
|
||||
journal = another_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "tag_link_issue", prop_key: "1", old_value: @issue.id.to_s})
|
||||
end
|
||||
@link = @links.last
|
||||
if @link.try(:destroy)
|
||||
@link.destroy!
|
||||
end
|
||||
render_ok
|
||||
else
|
||||
rescue
|
||||
render_error('删除失败!')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -62,17 +62,17 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
|
|||
end
|
||||
|
||||
def create
|
||||
@object_result = Api::V1::Issues::CreateService.call(@project, issue_params, current_user)
|
||||
@object_result = Api::Pm::Issues::CreateService.call(@project, issue_params, current_user)
|
||||
render 'api/v1/issues/create'
|
||||
end
|
||||
|
||||
def update
|
||||
@object_result = Api::V1::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
|
||||
@object_result = Api::Pm::Issues::UpdateService.call(@project, @issue, issue_params, current_user)
|
||||
render 'api/v1/issues/update'
|
||||
end
|
||||
|
||||
def batch_update
|
||||
@object_result = Api::V1::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
|
||||
@object_result = Api::Pm::Issues::BatchUpdateService.call(@project, @issues, batch_issue_params, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
|
@ -82,7 +82,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
|
|||
|
||||
def batch_destroy
|
||||
return render_ok if params[:ids].is_a?(Array) && params[:ids].blank?
|
||||
@object_result = Api::V1::Issues::BatchDeleteService.call(@project, @issues, current_user)
|
||||
@object_result = Api::Pm::Issues::BatchDeleteService.call(@project, @issues, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
|
@ -116,7 +116,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
|
|||
|
||||
|
||||
def destroy
|
||||
@object_result = Api::V1::Issues::DeleteService.call(@project, @issue, current_user)
|
||||
@object_result = Api::Pm::Issues::DeleteService.call(@project, @issue, current_user)
|
||||
if @object_result
|
||||
render_ok
|
||||
else
|
||||
|
@ -124,6 +124,72 @@ class Api::Pm::IssuesController < Api::Pm::BaseController
|
|||
end
|
||||
end
|
||||
|
||||
def export
|
||||
return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank?
|
||||
Axlsx::Package.new do |p|
|
||||
[['requirement', 1], ['task', 2], ['bug', 3]].each do |type|
|
||||
p.workbook.add_worksheet(:name => type[0]) do |sheet|
|
||||
@issues = Issue.where(pm_project_id: params[:pm_project_id], pm_issue_type: type[1])
|
||||
sheet.add_row ["标题", "正文", "创建者", "创建时间", "修改者", "更新时间", "状态", "负责人", "优先级", "标记", "开始时间","结束时间", "预估工时"]
|
||||
@issues.each do |issue|
|
||||
sheet.add_row [issue.subject, issue.description, issue.user.try(:login), issue.created_on.strftime("%Y-%m-%d %H:%M:%S"), issue.changer.try(:login), issue.updated_on.strftime("%Y-%m-%d %H:%M:%S"), issue.status_id, issue.assigners.pluck(:login).join(","), issue.priority_id, issue.issue_tags.pluck(:name, :color).join(","), issue.start_date.present? ? issue.start_date.strftime("%Y-%m-%d") : "", issue.due_date.present? ? issue.due_date.strftime("%Y-%m-%d") : "", issue.time_scale]
|
||||
end
|
||||
end
|
||||
end
|
||||
p.serialize('public/导出工作项.xlsx')
|
||||
end
|
||||
|
||||
send_file('public/导出工作项.xlsx')
|
||||
end
|
||||
|
||||
def import
|
||||
return render_error('请上传正确的文件') if params[:file].blank? || !params[:file].is_a?(ActionDispatch::Http::UploadedFile)
|
||||
return render_error('请输入正确的项目ID.') if params[:pm_project_id].blank?
|
||||
return render_error('请输入正确的组织ID.') if params[:organization_id].blank?
|
||||
types = {requirement: 1, task: 2, bug: 3}
|
||||
doc = SimpleXlsxReader.open(params[:file].tempfile)
|
||||
doc.sheets.each do |sheet|
|
||||
type = types["#{sheet.name}".to_sym]
|
||||
sheet.rows.each.with_index do |row, index|
|
||||
next if index == 0
|
||||
issue = Issue.new(issue_classify: "issue", project_id: 0, pm_project_id: params[:pm_project_id], pm_issue_type: type, tracker_id: Tracker.first.id)
|
||||
issue.subject = row[0]
|
||||
issue.description = row[1]
|
||||
author = User.find_by(login: row[2]) || User.first
|
||||
issue.user = author
|
||||
issue.created_on = row[3]
|
||||
changer = User.find_by(login: row[4]) || User.first
|
||||
issue.changer = changer
|
||||
issue.updated_on = row[5]
|
||||
issue.status_id = row[6].to_i
|
||||
if row[7].present?
|
||||
row[7].split(',').each do |a|
|
||||
u = User.find_by(login: a)
|
||||
next unless u.present?
|
||||
issue.assigners << u
|
||||
end
|
||||
end
|
||||
issue.priority_id = row[8]
|
||||
if row[9].present?
|
||||
row[9].split(',').each_slice(2).to_a.each do |t|
|
||||
tag = IssueTag.find_by(project_id: 0, organization_id: params[:organization_id], name: t[0])
|
||||
if tag.present?
|
||||
issue.issue_tags << tag
|
||||
else
|
||||
tag = IssueTag.create(project_id: 0,organization_id: params[:organization_id], name: t[0], color: t[1])
|
||||
issue.issue_tags << tag
|
||||
end
|
||||
end
|
||||
end
|
||||
issue.start_date = row[10]
|
||||
issue.due_date = row[11]
|
||||
issue.time_scale = row[12]
|
||||
issue.save
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def check_issue_operate_permission
|
||||
return if params[:project_id].to_i.zero?
|
||||
|
|
|
@ -10,7 +10,7 @@ class Api::Pm::JournalsController < Api::Pm::BaseController
|
|||
@total_operate_journals_count = @object_result[:total_operate_journals_count]
|
||||
@total_comment_journals_count = @object_result[:total_comment_journals_count]
|
||||
@journals = kaminary_select_paginate(@object_result[:data])
|
||||
render 'api/v1/issues/journals/index'
|
||||
render 'api/pm/issues/journals/index'
|
||||
end
|
||||
|
||||
def create
|
||||
|
|
|
@ -109,6 +109,20 @@ class Issue < ApplicationRecord
|
|||
after_save :incre_or_decre_closed_issues_count, :change_versions_count, :send_update_message_to_notice_system, :associate_attachment_container, :generate_uuid
|
||||
after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic, :destroy_be_pm_links
|
||||
|
||||
|
||||
def pm_issue_type_string
|
||||
case pm_issue_type
|
||||
when 1
|
||||
"requirement"
|
||||
when 2
|
||||
"task"
|
||||
when 3
|
||||
"bug"
|
||||
else
|
||||
"issue"
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_be_pm_links
|
||||
PmLink.where(be_linkable_type:"Issue",be_linkable_id:self.id).map(&:destroy)
|
||||
end
|
||||
|
|
|
@ -82,6 +82,423 @@ class Journal < ApplicationRecord
|
|||
end
|
||||
end
|
||||
|
||||
def pm_operate_category
|
||||
detail = self.journal_details.take
|
||||
if %w(requirement task bug).include?(detail.property) && detail.prop_key.to_s == "1"
|
||||
return "issue"
|
||||
else
|
||||
return %w(requirement task bug attr).include?(detail.property) ? detail.prop_key : detail.property
|
||||
end
|
||||
end
|
||||
|
||||
def pm_operate_content
|
||||
content = ""
|
||||
detail = self.journal_details.take
|
||||
case detail.property
|
||||
when 'requirement'
|
||||
case detail.prop_key
|
||||
when 'status_id'
|
||||
old_value = IssueStatus.find_by_id(detail.old_value)&.name
|
||||
new_value = IssueStatus.find_by_id(detail.value)&.name
|
||||
content += "将状态"
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "设置为<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "未设置" if detail.value.blank?
|
||||
content += "由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
content.gsub!('新增', '待评审')
|
||||
content.gsub!('正在解决', '进行中')
|
||||
content.gsub!('已解决', '已完成')
|
||||
content.gsub!('关闭', '已关闭')
|
||||
content.gsub!('拒绝', '已拒绝')
|
||||
return content
|
||||
when 'root_id'
|
||||
old_value = "<b><#{Issue.find_by_id(detail.old_value)&.subject}></b>"
|
||||
new_value = "<b><#{Issue.find_by_id(detail.value)&.subject}></b>"
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "关联了父需求#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "取消了关联的父需求#{old_value}"
|
||||
else
|
||||
content += "将关联的父需求由#{old_value}更改为#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'leaf_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "新建了子需求#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "删除了关联的子需求#{old_value}"
|
||||
else
|
||||
content += "新建了子需求#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'tag_leaf_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "关联了子需求#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "取消了关联的子需求#{old_value}"
|
||||
else
|
||||
content += "关联了子需求#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
else
|
||||
return "创建了需求"
|
||||
end
|
||||
when 'task'
|
||||
case detail.prop_key
|
||||
when 'status_id'
|
||||
old_value = IssueStatus.find_by_id(detail.old_value)&.name
|
||||
new_value = IssueStatus.find_by_id(detail.value)&.name
|
||||
content += "将状态"
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "设置为<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "未设置" if detail.value.blank?
|
||||
content += "由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
content.gsub!('新增', '待处理')
|
||||
content.gsub!('正在解决', '进行中')
|
||||
content.gsub!('已解决', '已完成')
|
||||
content.gsub!('关闭', '已关闭')
|
||||
content.gsub!('拒绝', '已拒绝')
|
||||
return content
|
||||
when 'root_id'
|
||||
old_value = "<b><#{Issue.find_by_id(detail.old_value)&.subject}></b>"
|
||||
new_value = "<b><#{Issue.find_by_id(detail.value)&.subject}></b>"
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "关联了父任务#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "取消了关联的父任务#{old_value}"
|
||||
else
|
||||
content += "将关联的父任务由#{old_value}>更改为#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'leaf_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "新建了子任务#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "删除了关联的子任务#{old_value}"
|
||||
else
|
||||
content += "新建了子任务#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'tag_leaf_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "关联了子任务#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "取消了关联的子任务#{old_value}"
|
||||
else
|
||||
content += "关联了子任务#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
else
|
||||
return "创建了任务"
|
||||
end
|
||||
when 'bug'
|
||||
case detail.prop_key
|
||||
when 'status_id'
|
||||
old_value = IssueStatus.find_by_id(detail.old_value)&.name
|
||||
new_value = IssueStatus.find_by_id(detail.value)&.name
|
||||
content += "将状态"
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "设置为<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "未设置" if detail.value.blank?
|
||||
content += "由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
content.gsub!('新增', '待修复')
|
||||
content.gsub!('正在解决', '修复中')
|
||||
content.gsub!('已解决', '已修复')
|
||||
content.gsub!('关闭', '已关闭')
|
||||
content.gsub!('拒绝', '已拒绝')
|
||||
return content
|
||||
when 'root_id'
|
||||
old_value = "<b><#{Issue.find_by_id(detail.old_value)&.subject}></b>"
|
||||
new_value = "<b><#{Issue.find_by_id(detail.value)&.subject}></b>"
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "关联了父缺陷#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "取消了关联的父缺陷#{old_value}"
|
||||
else
|
||||
content += "将关联的父缺陷由#{old_value}更改为#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'leaf_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "新建了子缺陷#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "删除了关联的子缺陷#{old_value}"
|
||||
else
|
||||
content += "新建了子缺陷#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'tag_leaf_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b><#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "关联了子缺陷#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "取消了关联的子缺陷#{old_value}"
|
||||
else
|
||||
content += "关联了子缺陷#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
else
|
||||
return "创建了缺陷"
|
||||
end
|
||||
when 'attr'
|
||||
case detail.prop_key
|
||||
when 'subject'
|
||||
return "修改了<b>标题</b>"
|
||||
when 'description'
|
||||
return "修改了<b>正文</b>"
|
||||
when 'priority_id'
|
||||
old_value = IssuePriority.find_by_id(detail.old_value)&.name
|
||||
new_value = IssuePriority.find_by_id(detail.value)&.name
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "将优先级设置为<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "未设置" if detail.value.blank?
|
||||
content += "将优先级由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
return content
|
||||
when 'status_id'
|
||||
old_value = IssueStatus.find_by_id(detail.old_value)&.name
|
||||
new_value = IssueStatus.find_by_id(detail.value)&.name
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "将状态设置为<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "未设置" if detail.value.blank?
|
||||
content += "将状态由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
case self.issue.pm_issue_type.to_i
|
||||
when 1
|
||||
content.gsub!('新增', '待评审')
|
||||
content.gsub!('正在解决', '进行中')
|
||||
content.gsub!('已解决', '已完成')
|
||||
content.gsub!('关闭', '已关闭')
|
||||
content.gsub!('拒绝', '已拒绝')
|
||||
when 2
|
||||
content.gsub!('新增', '待处理')
|
||||
content.gsub!('正在解决', '进行中')
|
||||
content.gsub!('已解决', '已完成')
|
||||
content.gsub!('关闭', '已关闭')
|
||||
content.gsub!('拒绝', '已拒绝')
|
||||
when 3
|
||||
content.gsub!('新增', '待修复')
|
||||
content.gsub!('正在解决', '修复中')
|
||||
content.gsub!('已解决', '已修复')
|
||||
content.gsub!('关闭', '已关闭')
|
||||
content.gsub!('拒绝', '已拒绝')
|
||||
end
|
||||
return content
|
||||
when 'pm_issue_type'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "将工作项类型设置为<b>#{new_value}</b>"
|
||||
else
|
||||
new_value = "未设置" if detail.value.blank?
|
||||
content += "将工作项类型由<b>#{old_value}</b>更改为<b>#{new_value}</b>"
|
||||
end
|
||||
content.gsub!('1', '需求')
|
||||
content.gsub!('2', '任务')
|
||||
content.gsub!('3', '缺陷')
|
||||
return content
|
||||
when 'pm_sprint_id'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加了关联迭代"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将关联迭代更改为<b>未设置</b>"
|
||||
else
|
||||
content += "变更了关联迭代"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'project_id'
|
||||
old_value = Project.find_by_id(detail.old_value)&.name
|
||||
new_value = Project.find_by_id(detail.value)&.name
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加关联代码库<b>#{new_value}</b>"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将关联代码库更改为<b>未设置</b>"
|
||||
else
|
||||
content += "将关联代码库由<b>#{old_value}</b>改为<b>#{new_value}</b>"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'branch_name'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加关联分支<b>#{new_value}</b>"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将关联分支更改为<b>未设置</b>"
|
||||
else
|
||||
content += "将关联分支由<b>#{old_value}</b>改为<b>#{new_value}</b>"
|
||||
end
|
||||
end
|
||||
return content
|
||||
|
||||
when 'start_date'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加开始时间<b>#{new_value}</b>"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将开始时间更改为<b>未设置</b>"
|
||||
else
|
||||
content += "将开始时间由<b>#{old_value}</b>改为<b>#{new_value}</b>"
|
||||
end
|
||||
end
|
||||
return content
|
||||
|
||||
when 'due_date'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加结束时间<b>#{new_value}</b>"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将结束时间更改为<b>未设置</b>"
|
||||
else
|
||||
content += "将结束时间由<b>#{old_value}</b>改为<b>#{new_value}</b>"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'time_scale'
|
||||
old_value = detail.old_value
|
||||
new_value = detail.value
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加预估工时<b>#{new_value}</b>"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将预估工时更改为<b>未设置</b>"
|
||||
else
|
||||
content += "将预估工时由<b>#{old_value}</b>改为<b>#{new_value}</b>"
|
||||
end
|
||||
end
|
||||
return content
|
||||
end
|
||||
when 'attachment'
|
||||
old_value = detail.old_value.to_s
|
||||
new_value = detail.value.to_s
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "上传了附件"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "删除了附件"
|
||||
else
|
||||
content += "上传了附件"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'assigner'
|
||||
old_value = User.where(id: detail.old_value.split(",")).map{|u| "<b>#{u.real_name}</b>"}.join("、")
|
||||
new_value = User.where(id: detail.value.split(",")).map{|u| "<b>#{u.real_name}</b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加负责人#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将负责人更改为<b>未设置</b>"
|
||||
else
|
||||
content += "将负责人由#{old_value}更改为#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'issue_tag'
|
||||
old_value = IssueTag.where(id: detail.old_value.split(",")).map{|t| "<b>#{t.name}</b>"}.join("、")
|
||||
new_value = IssueTag.where(id: detail.value.split(",")).map{|t| "<b>#{t.name}</b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "添加标记#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "将标记更改为<b>未设置</b>"
|
||||
else
|
||||
content += "将标记由#{old_value}更改为#{new_value}"
|
||||
end
|
||||
end
|
||||
return content
|
||||
when 'link_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b>[#{i.pm_issue_type}]-<#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b>[#{i.pm_issue_type}]-<#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "新建了关联的工作项#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "删除了关联的工作项#{old_value}"
|
||||
else
|
||||
content += "新建了关联的工作项#{new_value}"
|
||||
end
|
||||
end
|
||||
content.gsub!('1', "需求")
|
||||
content.gsub!('2', "任务")
|
||||
content.gsub!('3', "缺陷")
|
||||
return content
|
||||
when 'tag_link_issue'
|
||||
old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<b>[#{i.pm_issue_type}]-<#{i.subject}></b>"}.join("、")
|
||||
new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<b>[#{i.pm_issue_type}]-<#{i.subject}></b>"}.join("、")
|
||||
if detail.old_value.nil? || detail.old_value.blank?
|
||||
content += "关联了工作项#{new_value}"
|
||||
else
|
||||
if detail.value.nil? || detail.value.blank?
|
||||
content += "取消了关联的工作项#{old_value}"
|
||||
else
|
||||
content += "关联了工作项#{new_value}"
|
||||
end
|
||||
end
|
||||
content.gsub!('1', "需求")
|
||||
content.gsub!('2', "任务")
|
||||
content.gsub!('3', "缺陷")
|
||||
return content
|
||||
when 'issue'
|
||||
issue = self.issue
|
||||
case issue.pm_issue_type
|
||||
when 1
|
||||
return "创建了需求"
|
||||
when 2
|
||||
return "创建了任务"
|
||||
when 3
|
||||
return "创建了缺陷"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def operate_content
|
||||
content = ""
|
||||
detail = self.journal_details.take
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
class Api::Pm::Issues::BatchDeleteService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_reader :project, :issues, :current_user
|
||||
|
||||
validates :project, :issues, :current_user, presence: true
|
||||
|
||||
def initialize(project, issues, current_user = nil)
|
||||
@project = project
|
||||
@issues = issues.includes(:assigners)
|
||||
@current_user = current_user
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁
|
||||
|
||||
delete_issues
|
||||
|
||||
project.incre_project_issue_cache_delete_count(@issues.size)
|
||||
|
||||
if Site.has_notice_menu? && !project.id.zero?
|
||||
@issues.each do |issue|
|
||||
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
|
||||
end
|
||||
end
|
||||
|
||||
unlock("Api::V1::Issues::DeleteService:#{project.id}")
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delete_issues
|
||||
raise Error, "批量删除疑修失败!" unless @issues.destroy_all
|
||||
end
|
||||
end
|
|
@ -0,0 +1,33 @@
|
|||
class Api::Pm::Issues::BatchUpdateService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
include Api::V1::Issues::Concerns::Checkable
|
||||
include Api::V1::Issues::Concerns::Loadable
|
||||
|
||||
attr_reader :project, :issues, :params, :current_user
|
||||
attr_reader :status_id, :priority_id, :milestone_id, :project_id
|
||||
attr_reader :issue_tag_ids, :assigner_ids
|
||||
|
||||
validates :project, :issues, :current_user, presence: true
|
||||
|
||||
def initialize(project, issues, params, current_user = nil)
|
||||
@project = project
|
||||
@issues = issues
|
||||
@params = params
|
||||
@current_user = current_user
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
ActiveRecord::Base.transaction do
|
||||
@issues.each do |issue|
|
||||
if issue.issue_classify == "issue"
|
||||
Api::Pm::Issues::UpdateService.call(project, issue, params, current_user)
|
||||
end
|
||||
end
|
||||
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
end
|
|
@ -0,0 +1,181 @@
|
|||
class Api::Pm::Issues::CreateService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
include Api::V1::Issues::Concerns::Checkable
|
||||
include Api::V1::Issues::Concerns::Loadable
|
||||
|
||||
attr_reader :project, :current_user
|
||||
attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num, :root_subject
|
||||
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login
|
||||
attr_accessor :created_issue
|
||||
|
||||
validates :subject, presence: true
|
||||
validates :status_id, :priority_id, presence: true
|
||||
validates :project, :current_user, presence: true
|
||||
validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true
|
||||
|
||||
def initialize(project, params, current_user = nil)
|
||||
@project = project
|
||||
@current_user = current_user
|
||||
@status_id = params[:status_id]
|
||||
@priority_id = params[:priority_id]
|
||||
@milestone_id = params[:milestone_id]
|
||||
@branch_name = params[:branch_name]
|
||||
@start_date = params[:start_date]
|
||||
@due_date = params[:due_date]
|
||||
@subject = params[:subject]
|
||||
@description = params[:description]
|
||||
@blockchain_token_num = params[:blockchain_token_num]
|
||||
@issue_tag_ids = params[:issue_tag_ids]
|
||||
@assigner_ids = params[:assigner_ids]
|
||||
@attachment_ids = params[:attachment_ids]
|
||||
@receivers_login = params[:receivers_login]
|
||||
@pm_project_id = params[:pm_project_id]
|
||||
@pm_sprint_id = params[:pm_sprint_id]
|
||||
@pm_issue_type = params[:pm_issue_type]
|
||||
@root_id = params[:root_id]
|
||||
@time_scale = params[:time_scale]
|
||||
@linkable_id = params[:link_able_id]
|
||||
@root_subject = params[:root_subject]
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(', ') unless valid?
|
||||
ActiveRecord::Base.transaction do
|
||||
check_issue_status(status_id)
|
||||
check_issue_priority(priority_id)
|
||||
check_milestone(milestone_id) if milestone_id.present?
|
||||
check_issue_tags(issue_tag_ids) unless issue_tag_ids.blank?
|
||||
check_assigners(assigner_ids) unless assigner_ids.blank?
|
||||
check_attachments(attachment_ids) unless attachment_ids.blank?
|
||||
check_atme_receivers(receivers_login) unless receivers_login.blank?
|
||||
check_blockchain_token_num(current_user.id, project.id, blockchain_token_num) if blockchain_token_num.present?
|
||||
load_assigners(assigner_ids) unless assigner_ids.blank?
|
||||
load_attachments(attachment_ids) unless attachment_ids.blank?
|
||||
load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank?
|
||||
load_atme_receivers(receivers_login) unless receivers_login.blank?
|
||||
try_lock("Api::Pm::Issues::CreateService:#{project.id}") # 开始写数据,加锁
|
||||
@created_issue = Issue.new(issue_attributes)
|
||||
@created_issue.pm_issue_type = @pm_issue_type
|
||||
if @root_subject.present? && @pm_issue_type.to_i == 4
|
||||
@root_issue = Issue.find_by(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id)
|
||||
unless @root_issue.present?
|
||||
@root_issue = Issue.create(subject: @root_subject, pm_issue_type: 4, pm_project_id: @pm_project_id, status_id: 1, priority_id: 1, tracker_id: Tracker.first.id, project_id: @project.id, author_id: current_user.id)
|
||||
end
|
||||
@created_issue.root_id = @root_issue.id
|
||||
else
|
||||
@created_issue.root_id = @root_id
|
||||
end
|
||||
build_author_participants
|
||||
build_assigner_participants unless assigner_ids.blank?
|
||||
build_atme_participants if @atme_receivers.present?
|
||||
build_issue_journal_details
|
||||
build_issue_project_trends
|
||||
@created_issue.assigners = @assigners unless assigner_ids.blank?
|
||||
@created_issue.attachments = @attachments unless attachment_ids.blank?
|
||||
@created_issue.issue_tags = @issue_tags unless issue_tag_ids.blank?
|
||||
@created_issue.pm_project_id = @pm_project_id
|
||||
@created_issue.pm_sprint_id = @pm_sprint_id
|
||||
@created_issue.time_scale = @time_scale
|
||||
@created_issue.issue_tags_value = @issue_tags.order('id asc').pluck(:id).join(',') unless issue_tag_ids.blank?
|
||||
@created_issue.changer_id = @current_user.id
|
||||
@created_issue.save!
|
||||
if @created_issue.parent_issue.present?
|
||||
parent_issue = @created_issue.parent_issue
|
||||
if @created_issue.root_id.present? && parent_issue.present?
|
||||
journal = parent_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: @created_issue.pm_issue_type_string, prop_key: 'leaf_issue', value: @created_issue.id.to_s})
|
||||
end
|
||||
end
|
||||
if @linkable_id.present?
|
||||
PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id)
|
||||
another_issue = Issue.find_by_id(@linkable_id)
|
||||
if another_issue.present?
|
||||
journal = another_issue.journals.create!({user_id: @current_user.id})
|
||||
journal.journal_details.create!({property: 'link_issue', prop_key: "1", value: @created_issue.id.to_s})
|
||||
end
|
||||
end
|
||||
if Site.has_blockchain? && @project.use_blockchain
|
||||
if @created_issue.blockchain_token_num.present? && @created_issue.blockchain_token_num > 0
|
||||
Blockchain::CreateIssue.call({user_id: current_user.id, project_id: @created_issue.project_id, token_num: @created_issue.blockchain_token_num})
|
||||
end
|
||||
|
||||
push_activity_2_blockchain('issue_create', @created_issue)
|
||||
end
|
||||
|
||||
project.del_project_issue_cache_delete_count # 把缓存里存储项目删除issue的个数清除掉
|
||||
unless @project.id.zero?
|
||||
# 新增时向grimoirelab推送事件
|
||||
IssueWebhookJob.set(wait: 5.seconds).perform_later(@created_issue.id)
|
||||
|
||||
# @信息发送
|
||||
AtmeService.call(current_user, @atme_receivers, @created_issue) unless receivers_login.blank?
|
||||
|
||||
# 发消息
|
||||
if Site.has_notice_menu?
|
||||
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @created_issue&.id, assigner_ids) unless assigner_ids.blank?
|
||||
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @created_issue&.id)
|
||||
end
|
||||
|
||||
# 触发webhook
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueCreate', @created_issue&.id, current_user.id)
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @created_issue&.id, current_user.id, {issue_tag_ids: [[], issue_tag_ids]}) unless issue_tag_ids.blank?
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @created_issue&.id, current_user.id, {assigner_ids: [[], assigner_ids]}) unless assigner_ids.blank?
|
||||
end
|
||||
unlock("Api::Pm::Issues::CreateService:#{project.id}") # 结束写数据,解锁
|
||||
end
|
||||
|
||||
return @created_issue
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def issue_attributes
|
||||
issue_attributes = {
|
||||
subject: subject,
|
||||
project_id: project.id,
|
||||
author_id: current_user.id,
|
||||
tracker_id: Tracker.first.id,
|
||||
status_id: status_id,
|
||||
priority_id: priority_id,
|
||||
project_issues_index: (project.get_last_project_issues_index + 1),
|
||||
issue_type: '1',
|
||||
issue_classify: 'issue'
|
||||
}
|
||||
|
||||
issue_attributes.merge!({description: description}) if description.present?
|
||||
issue_attributes.merge!({fixed_version_id: milestone_id}) if milestone_id.present?
|
||||
issue_attributes.merge!({start_date: start_date}) if start_date.present?
|
||||
issue_attributes.merge!({due_date: due_date}) if due_date.present?
|
||||
issue_attributes.merge!({branch_name: branch_name}) if branch_name.present?
|
||||
issue_attributes.merge!({blockchain_token_num: blockchain_token_num}) if blockchain_token_num.present?
|
||||
|
||||
issue_attributes
|
||||
end
|
||||
|
||||
def build_author_participants
|
||||
@created_issue.issue_participants.new({participant_type: 'authored', participant_id: current_user.id})
|
||||
end
|
||||
|
||||
def build_assigner_participants
|
||||
assigner_ids.each do |aid|
|
||||
@created_issue.issue_participants.new({participant_type: 'assigned', participant_id: aid})
|
||||
end
|
||||
end
|
||||
|
||||
def build_atme_participants
|
||||
@atme_receivers.each do |receiver|
|
||||
@created_issue.issue_participants.new({participant_type: 'atme', participant_id: receiver.id})
|
||||
end
|
||||
end
|
||||
|
||||
def build_issue_project_trends
|
||||
return if @project.id == 0
|
||||
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: 'create'})
|
||||
@created_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE}) if status_id.to_i == 5
|
||||
end
|
||||
|
||||
def build_issue_journal_details
|
||||
journal = @created_issue.journals.new({user_id: current_user.id})
|
||||
journal.journal_details.new({property: @created_issue.pm_issue_type_string, prop_key: 1, old_value: '', value: ''})
|
||||
end
|
||||
end
|
|
@ -0,0 +1,48 @@
|
|||
class Api::Pm::Issues::DeleteService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_reader :project, :issue, :current_user
|
||||
|
||||
validates :project, :issue, :current_user, presence: true
|
||||
|
||||
def initialize(project, issue, current_user = nil)
|
||||
@project = project
|
||||
@issue = issue
|
||||
@current_user = current_user
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁
|
||||
ActiveRecord::Base.transaction do
|
||||
parent_issue = @issue.parent_issue
|
||||
if @issue.root_id.present? && parent_issue.present?
|
||||
journal = parent_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: @issue.pm_issue_type_string, prop_key: 'leaf_issue', old_value: @issue.id.to_s})
|
||||
end
|
||||
|
||||
delete_issue
|
||||
#删除双向关联
|
||||
PmLink.where(be_linkable_id: @issue.id, be_linkable_type: 'Issue').or(PmLink.where(linkable_id: @issue.id, linkable_type: 'Issue')).map(&:destroy)
|
||||
|
||||
project.incre_project_issue_cache_delete_count
|
||||
|
||||
if Site.has_blockchain? && @project.use_blockchain && !project.id.zero?
|
||||
unlock_balance_on_blockchain(@issue.author_id.to_s, @project.id.to_s, @issue.blockchain_token_num.to_i) if @issue.blockchain_token_num.present?
|
||||
end
|
||||
|
||||
if Site.has_notice_menu? && !project.id.zero?
|
||||
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
|
||||
end
|
||||
end
|
||||
unlock("Api::V1::Issues::DeleteService:#{project.id}")
|
||||
|
||||
return true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def delete_issue
|
||||
raise Error, "删除疑修失败!" unless issue.destroy!
|
||||
end
|
||||
end
|
|
@ -0,0 +1,326 @@
|
|||
class Api::Pm::Issues::UpdateService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
include Api::V1::Issues::Concerns::Checkable
|
||||
include Api::V1::Issues::Concerns::Loadable
|
||||
|
||||
attr_reader :project, :issue, :current_user
|
||||
attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description, :blockchain_token_num
|
||||
attr_reader :target_pm_project_id, :pm_sprint_id, :pm_issue_type, :root_id, :time_scale
|
||||
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login, :before_issue_tag_ids, :before_assigner_ids, :project_id
|
||||
attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers
|
||||
|
||||
validates :project, :issue, :current_user, presence: true
|
||||
validates :blockchain_token_num, numericality: {greater_than: 0}, allow_blank: true
|
||||
|
||||
def initialize(project, issue, params, current_user = nil)
|
||||
@project = project
|
||||
@issue = issue
|
||||
@current_user = current_user
|
||||
@status_id = params[:status_id]
|
||||
@priority_id = params[:priority_id]
|
||||
@milestone_id = params[:milestone_id]
|
||||
@branch_name = params[:branch_name]
|
||||
@start_date = params[:start_date]
|
||||
@due_date = params[:due_date]
|
||||
@subject = params[:subject]
|
||||
@description = params[:description]
|
||||
@blockchain_token_num = params[:blockchain_token_num]
|
||||
@issue_tag_ids = params[:issue_tag_ids]
|
||||
@assigner_ids = params[:assigner_ids]
|
||||
@before_issue_tag_ids = issue.issue_tags.pluck(:id)
|
||||
@before_assigner_ids = issue.assigners.pluck(:id)
|
||||
@attachment_ids = params[:attachment_ids]
|
||||
@receivers_login = params[:receivers_login]
|
||||
@target_pm_project_id = params[:target_pm_project_id]
|
||||
@pm_sprint_id = params[:pm_sprint_id]
|
||||
@pm_issue_type = params[:pm_issue_type]
|
||||
@root_id = params[:root_id]
|
||||
@time_scale = params[:time_scale]
|
||||
@project_id = params[:project_id]
|
||||
@add_assigner_ids = []
|
||||
@previous_issue_changes = {}
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
ActiveRecord::Base.transaction do
|
||||
check_issue_status(status_id) if status_id.present?
|
||||
check_issue_priority(priority_id) if priority_id.present?
|
||||
check_milestone(milestone_id) if milestone_id.present?
|
||||
check_root_issue(issue, root_id) if root_id.present?
|
||||
check_issue_tags(issue_tag_ids) unless issue_tag_ids.nil?
|
||||
check_assigners(assigner_ids) unless assigner_ids.nil?
|
||||
check_attachments(attachment_ids) unless attachment_ids.nil?
|
||||
check_atme_receivers(receivers_login) unless receivers_login.nil?
|
||||
check_blockchain_token_num(issue.author_id, project.id, blockchain_token_num, (@issue.blockchain_token_num || 0)) if blockchain_token_num.present? && current_user.id == @issue.author_id && !PullAttachedIssue.exists?(issue_id: @issue, fixed: true)
|
||||
load_assigners(assigner_ids)
|
||||
load_attachments(attachment_ids)
|
||||
load_issue_tags(issue_tag_ids)
|
||||
load_atme_receivers(receivers_login) unless receivers_login.nil?
|
||||
|
||||
try_lock("Api::Pm::Issues::UpdateService:#{project.id}:#{issue.id}")
|
||||
@updated_issue = @issue
|
||||
issue_load_attributes
|
||||
build_assigner_issue_journal_details unless assigner_ids.nil?# 操作记录
|
||||
build_attachment_issue_journal_details unless attachment_ids.nil?
|
||||
build_issue_tag_issue_journal_details unless issue_tag_ids.nil?
|
||||
build_issue_project_trends if status_id.present? # 开关时间记录
|
||||
build_assigner_participants unless assigner_ids.nil? # 负责人
|
||||
build_edit_participants
|
||||
build_atme_participants if @atme_receivers.present?
|
||||
unless assigner_ids.nil?
|
||||
@previous_issue_changes.merge!(assigned_to_id: [@updated_issue.assigners.pluck(:id), @assigners.pluck(:id)])
|
||||
@updated_issue.assigners = @assigners || User.none
|
||||
end
|
||||
@updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil?
|
||||
@updated_issue.issue_tags_relates.destroy_all & @updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil?
|
||||
@updated_issue.issue_tags_value = @issue_tags.order("id asc").pluck(:id).join(",") unless issue_tag_ids.nil?
|
||||
|
||||
#Pm相关
|
||||
@updated_issue.pm_project_id = @target_pm_project_id unless @target_pm_project_id.nil?
|
||||
@updated_issue.pm_sprint_id = @pm_sprint_id unless @pm_sprint_id.nil?
|
||||
if @updated_issue.children_issues.count == 0 && @updated_issue.parent_id.nil?
|
||||
@updated_issue.pm_issue_type = @pm_issue_type unless @pm_issue_type.nil?
|
||||
end
|
||||
@updated_issue.root_id = @root_id unless @root_id.nil? #不为 nil的时候更新
|
||||
@updated_issue.root_id = nil if @root_id.try(:zero?) #为 0 的时候设置为 nil
|
||||
@updated_issue.time_scale = @time_scale unless @time_scale.nil?
|
||||
@updated_issue.project_id = @project_id unless @project_id.nil?
|
||||
@updated_issue.updated_on = Time.now
|
||||
@updated_issue.changer_id = @current_user.id
|
||||
@updated_issue.save!
|
||||
|
||||
build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
|
||||
build_previous_issue_changes
|
||||
build_cirle_blockchain_token if blockchain_token_num.present?
|
||||
unless @project.id.zero?
|
||||
# @信息发送
|
||||
AtmeService.call(current_user, @atme_receivers, @issue) unless receivers_login.blank?
|
||||
# 消息发送
|
||||
if Site.has_notice_menu?
|
||||
SendTemplateMessageJob.perform_later('IssueChanged', current_user.id, @issue&.id, previous_issue_changes) unless previous_issue_changes.blank?
|
||||
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank?
|
||||
end
|
||||
# 触发webhook
|
||||
Rails.logger.info "################### 触发webhook"
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueUpdate', @updated_issue&.id, current_user.id, previous_issue_changes.except(:issue_tags_value, :assigned_to_id))
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueLabel', @issue&.id, current_user.id, {issue_tag_ids: [before_issue_tag_ids, issue_tag_ids]}) unless issue_tag_ids.nil?
|
||||
TouchWebhookJob.set(wait: 5.seconds).perform_later('IssueAssign', @issue&.id, current_user.id, {assigner_ids: [before_assigner_ids, assigner_ids]}) unless assigner_ids.nil?
|
||||
end
|
||||
|
||||
unlock("Api::Pm::Issues::UpdateService:#{project.id}:#{issue.id}")
|
||||
return @updated_issue
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def issue_load_attributes
|
||||
if current_user.id == @updated_issue.author_id && !PullAttachedIssue.exists?(issue_id: @updated_issue, fixed: true)
|
||||
@updated_issue.blockchain_token_num = blockchain_token_num unless blockchain_token_num.nil?
|
||||
end
|
||||
@updated_issue.status_id = status_id if status_id.present?
|
||||
@updated_issue.priority_id = priority_id if priority_id.present?
|
||||
@updated_issue.fixed_version_id = milestone_id unless milestone_id.nil?
|
||||
@updated_issue.branch_name = branch_name unless branch_name.nil?
|
||||
@updated_issue.start_date = start_date unless start_date.nil?
|
||||
@updated_issue.due_date = due_date unless due_date.nil?
|
||||
@updated_issue.subject = subject if subject.present?
|
||||
@updated_issue.description = description unless description.nil?
|
||||
end
|
||||
|
||||
def build_assigner_participants
|
||||
if assigner_ids.blank?
|
||||
@updated_issue.issue_participants.where(participant_type: "assigned").each(&:destroy!)
|
||||
else
|
||||
@updated_issue.issue_participants.where(participant_type: "assigned").where.not(participant_id: assigner_ids).each(&:destroy!)
|
||||
assigner_ids.each do |aid|
|
||||
next if @updated_issue.issue_participants.exists?(participant_type: "assigned", participant_id: aid)
|
||||
@updated_issue.issue_participants.new({participant_type: "assigned", participant_id: aid})
|
||||
@add_assigner_ids << aid
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def build_edit_participants
|
||||
@updated_issue.issue_participants.new({participant_type: "edited", participant_id: current_user.id}) unless @updated_issue.issue_participants.exists?(participant_type: "edited", participant_id: current_user.id)
|
||||
end
|
||||
|
||||
def build_atme_participants
|
||||
@atme_receivers.each do |receiver|
|
||||
next if @updated_issue.issue_participants.exists?(participant_type: "atme", participant_id: receiver.id)
|
||||
@updated_issue.issue_participants.new({participant_type: "atme", participant_id: receiver.id})
|
||||
end
|
||||
end
|
||||
|
||||
def build_previous_issue_changes
|
||||
@previous_issue_changes.merge!(@updated_issue.previous_changes.slice("status_id", "priority_id", "fixed_version_id", "issue_tags_value", "branch_name", "subject").symbolize_keys)
|
||||
if @updated_issue.previous_changes[:start_date].present?
|
||||
@previous_issue_changes.merge!(start_date: [@updated_issue.previous_changes[:start_date][0].to_s, @updated_issue.previous_changes[:start_date][1].to_s])
|
||||
end
|
||||
if @updated_issue.previous_changes[:due_date].present?
|
||||
@previous_issue_changes.merge!(due_date: [@updated_issue.previous_changes[:due_date][0].to_s, @updated_issue.previous_changes[:due_date][1].to_s])
|
||||
end
|
||||
end
|
||||
|
||||
def build_cirle_blockchain_token
|
||||
if @updated_issue.previous_changes["blockchain_token_num"].present?
|
||||
unlock_balance_on_blockchain(@updated_issue&.author_id.to_s, @updated_issue.project_id.to_s, @updated_issue.previous_changes["blockchain_token_num"][0].to_i) if @updated_issue.previous_changes["blockchain_token_num"][0].present?
|
||||
lock_balance_on_blockchain(@updated_issue&.author_id.to_s, @updated_issue.project_id.to_s, @updated_issue.previous_changes["blockchain_token_num"][1].to_i) if @updated_issue.previous_changes["blockchain_token_num"][1].present?
|
||||
end
|
||||
end
|
||||
|
||||
def build_issue_project_trends
|
||||
if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][1] == 5
|
||||
@updated_issue.project_trends.new({user_id: current_user.id, project_id: @project.id, action_type: ProjectTrend::CLOSE})
|
||||
end
|
||||
if @updated_issue.previous_changes["status_id"].present? && @updated_issue.previous_changes["status_id"][0] == 5
|
||||
@updated_issue.project_trends.where(action_type: ProjectTrend::CLOSE).each(&:destroy!)
|
||||
end
|
||||
end
|
||||
|
||||
def build_after_issue_journal_details
|
||||
begin
|
||||
# 更改标题
|
||||
if @updated_issue.previous_changes["subject"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes["subject"][0], value: @updated_issue.previous_changes["subject"][1]})
|
||||
end
|
||||
|
||||
# 更改描述
|
||||
if @updated_issue.previous_changes["description"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "description", old_value: @updated_issue.previous_changes["description"][0], value: @updated_issue.previous_changes["description"][1]})
|
||||
end
|
||||
|
||||
# 修改状态
|
||||
if @updated_issue.previous_changes["status_id"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "status_id", old_value: @updated_issue.previous_changes["status_id"][0], value: @updated_issue.previous_changes["status_id"][1]})
|
||||
end
|
||||
|
||||
# 修改优先级
|
||||
if @updated_issue.previous_changes["priority_id"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "priority_id", old_value: @updated_issue.previous_changes["priority_id"][0], value: @updated_issue.previous_changes["priority_id"][1]})
|
||||
end
|
||||
|
||||
# 修改工作项类型
|
||||
if @updated_issue.previous_changes["pm_issue_type"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "pm_issue_type", old_value: @updated_issue.previous_changes["pm_issue_type"][0], value: @updated_issue.previous_changes["pm_issue_type"][1]})
|
||||
end
|
||||
|
||||
# 修改迭代
|
||||
if @updated_issue.previous_changes["pm_sprint_id"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "pm_sprint_id", old_value: @updated_issue.previous_changes["pm_sprint_id"][0], value: @updated_issue.previous_changes["pm_sprint_id"][1]})
|
||||
end
|
||||
|
||||
# 修改代码库
|
||||
if @updated_issue.previous_changes["project_id"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "project_id", old_value: @updated_issue.previous_changes["project_id"][0], value: @updated_issue.previous_changes["project_id"][1]})
|
||||
end
|
||||
|
||||
# 修改里程碑
|
||||
if @updated_issue.previous_changes["fixed_version_id"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "fixed_version_id", old_value: @updated_issue.previous_changes["fixed_version_id"][0], value: @updated_issue.previous_changes["fixed_version_id"][1]})
|
||||
end
|
||||
|
||||
# 更改分支
|
||||
if @updated_issue.previous_changes["branch_name"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "branch_name", old_value: @updated_issue.previous_changes["branch_name"][0], value: @updated_issue.previous_changes["branch_name"][1]})
|
||||
end
|
||||
|
||||
# 更改开始时间
|
||||
if @updated_issue.previous_changes["start_date"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "start_date", old_value: @updated_issue.previous_changes["start_date"][0], value: @updated_issue.previous_changes["start_date"][1]})
|
||||
end
|
||||
|
||||
# 更改结束时间
|
||||
if @updated_issue.previous_changes["due_date"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "due_date", old_value: @updated_issue.previous_changes["due_date"][0], value: @updated_issue.previous_changes["due_date"][1]})
|
||||
end
|
||||
|
||||
# 更改预估工时
|
||||
if @updated_issue.previous_changes["time_scale"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", prop_key: "time_scale", old_value: @updated_issue.previous_changes["time_scale"][0], value: @updated_issue.previous_changes["time_scale"][1]})
|
||||
end
|
||||
|
||||
# 更改父工作项
|
||||
if @updated_issue.previous_changes["root_id"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "root_id", old_value: @updated_issue.previous_changes["root_id"][0], value: @updated_issue.previous_changes["root_id"][1]})
|
||||
|
||||
# 更改子工作项
|
||||
before_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][0])
|
||||
if before_parent_issue.present?
|
||||
journal = before_parent_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", old_value: @updated_issue.id.to_s})
|
||||
end
|
||||
|
||||
after_parent_issue = Issue.find_by_id(@updated_issue.previous_changes["root_id"][1])
|
||||
if after_parent_issue.present?
|
||||
journal = after_parent_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: @updated_issue.pm_issue_type_string, prop_key: "tag_leaf_issue", value: @updated_issue.id.to_s})
|
||||
end
|
||||
end
|
||||
rescue
|
||||
raise Error, "创建操作记录失败!"
|
||||
end
|
||||
end
|
||||
|
||||
def build_assigner_issue_journal_details
|
||||
begin
|
||||
# 更改负责人
|
||||
new_assigner_ids = @assigner_ids
|
||||
new_assigner_ids = [] if @assigner_ids.nil?
|
||||
now_assigner_ids = @updated_issue.assigners.pluck(:id)
|
||||
if !(now_assigner_ids.sort == new_assigner_ids.sort)
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "assigner", prop_key: "#{new_assigner_ids.size}", old_value: now_assigner_ids.join(","), value: new_assigner_ids.join(",")})
|
||||
end
|
||||
|
||||
rescue
|
||||
raise Error, "创建操作记录失败!"
|
||||
end
|
||||
end
|
||||
|
||||
def build_issue_tag_issue_journal_details
|
||||
begin
|
||||
# 更改标记
|
||||
new_issue_tag_ids = @issue_tag_ids
|
||||
new_issue_tag_ids = [] if @issue_tag_ids.nil?
|
||||
now_issue_tag_ids = @updated_issue.issue_tags.pluck(:id)
|
||||
if !(now_issue_tag_ids.sort == new_issue_tag_ids.sort)
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "issue_tag", prop_key: "#{new_issue_tag_ids.size}", old_value: now_issue_tag_ids.join(","), value: new_issue_tag_ids.join(",")})
|
||||
end
|
||||
rescue
|
||||
raise Error, "创建操作记录失败!"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def build_attachment_issue_journal_details
|
||||
begin
|
||||
# 更改附件
|
||||
new_attachment_ids = @attachment_ids
|
||||
new_attachment_ids = [] if @attachment_ids.nil?
|
||||
now_attachment_ids = @updated_issue.attachments.pluck(:id)
|
||||
if !(now_attachment_ids.sort == new_attachment_ids.sort)
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attachment", prop_key: "#{new_attachment_ids.size}", old_value: now_attachment_ids.join(","), value: new_attachment_ids.join(",")})
|
||||
end
|
||||
rescue
|
||||
raise Error, "创建操作记录失败!"
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,25 @@
|
|||
json.id journal.id
|
||||
json.is_journal_detail journal.is_journal_detail?
|
||||
json.created_at journal.created_on.strftime("%Y-%m-%d %H:%M")
|
||||
json.updated_at journal.updated_on.strftime("%Y-%m-%d %H:%M")
|
||||
json.user do
|
||||
if journal.user.present?
|
||||
json.partial! "api/v1/users/simple_user", user: journal.user
|
||||
else
|
||||
json.nil!
|
||||
end
|
||||
end
|
||||
if journal.is_journal_detail?
|
||||
detail = journal.journal_details.take
|
||||
json.operate_category journal.pm_operate_category
|
||||
json.operate_content journal.is_journal_detail? ? journal.pm_operate_content : nil
|
||||
else
|
||||
json.notes journal.notes
|
||||
json.comments_count journal.comments_count
|
||||
json.children_journals journal.first_ten_children_journals.each do |journal|
|
||||
json.partial! "api/v1/issues/journals/children_detail", journal: journal
|
||||
end
|
||||
json.attachments journal.attachments do |attachment|
|
||||
json.partial! "api/v1/attachments/simple_detail", locals: {attachment: attachment}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
json.total_journals_count @total_journals_count
|
||||
json.total_operate_journals_count @total_operate_journals_count
|
||||
json.total_comment_journals_count @total_comment_journals_count
|
||||
json.total_count @journals.total_count
|
||||
json.journals @journals do |journal|
|
||||
journal.associate_attachment_container
|
||||
json.partial! "api/pm/issues/journals/detail", journal: journal
|
||||
end
|
|
@ -8,6 +8,8 @@ defaults format: :json do
|
|||
get :priorities
|
||||
get :tags
|
||||
get :statues
|
||||
get :export
|
||||
get :import
|
||||
end
|
||||
member do
|
||||
get :link_index
|
||||
|
|
Loading…
Reference in New Issue