mirror of
https://gitlink.org.cn/Gitlink/forgeplus.git
synced 2026-05-21 20:25:45 +08:00
新增:疑修操作记录、评论列表接口以及更新疑修无法产生操作记录修复
This commit is contained in:
@@ -13,7 +13,7 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
try_lock # 开始写数据,加锁
|
||||
try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁
|
||||
|
||||
delete_issues
|
||||
|
||||
@@ -25,7 +25,7 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService
|
||||
end
|
||||
end
|
||||
|
||||
unlock
|
||||
unlock("Api::V1::Issues::DeleteService:#{project.id}")
|
||||
|
||||
return true
|
||||
end
|
||||
@@ -35,13 +35,4 @@ class Api::V1::Issues::BatchDeleteService < ApplicationService
|
||||
def delete_issues
|
||||
raise Error, "批量删除疑修失败!" unless @issues.destroy_all
|
||||
end
|
||||
|
||||
def try_lock
|
||||
raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::BatchDeleteService:#{project.id}", 1, nx: true, ex: 60.seconds)
|
||||
end
|
||||
|
||||
def unlock
|
||||
$redis_cache.del("Api::V1::Issues::BatchDeleteService:#{project.id}")
|
||||
end
|
||||
|
||||
end
|
||||
@@ -43,10 +43,11 @@ class Api::V1::Issues::CreateService < ApplicationService
|
||||
load_issue_tags(issue_tag_ids) unless issue_tag_ids.blank?
|
||||
load_atme_receivers(receivers_login) unless receivers_login.blank?
|
||||
|
||||
try_lock # 开始写数据,加锁
|
||||
try_lock("Api::V1::Issues::CreateService:#{project.id}") # 开始写数据,加锁
|
||||
@created_issue = Issue.new(issue_attributes)
|
||||
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.attachments = @attachments unless attachment_ids.blank?
|
||||
@@ -64,7 +65,7 @@ class Api::V1::Issues::CreateService < ApplicationService
|
||||
SendTemplateMessageJob.perform_later('ProjectIssue', current_user.id, @issue&.id)
|
||||
end
|
||||
|
||||
unlock # 结束写数据,解锁
|
||||
unlock("Api::V1::Issues::CreateService:#{project.id}") # 结束写数据,解锁
|
||||
end
|
||||
|
||||
return @created_issue
|
||||
@@ -104,6 +105,12 @@ class Api::V1::Issues::CreateService < ApplicationService
|
||||
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
|
||||
@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
|
||||
@@ -113,12 +120,4 @@ class Api::V1::Issues::CreateService < ApplicationService
|
||||
journal = @created_issue.journals.new({user_id: current_user.id})
|
||||
journal.journal_details.new({property: "issue", prop_key: 1, old_value: '', value: ''})
|
||||
end
|
||||
|
||||
def try_lock
|
||||
raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::CreateService:#{project.id}", 1, nx: true, ex: 60.seconds)
|
||||
end
|
||||
|
||||
def unlock
|
||||
$redis_cache.del("Api::V1::Issues::CreateService:#{project.id}")
|
||||
end
|
||||
end
|
||||
@@ -13,7 +13,7 @@ class Api::V1::Issues::DeleteService < ApplicationService
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
try_lock # 开始写数据,加锁
|
||||
try_lock("Api::V1::Issues::DeleteService:#{project.id}") # 开始写数据,加锁
|
||||
|
||||
delete_issue
|
||||
|
||||
@@ -23,7 +23,7 @@ class Api::V1::Issues::DeleteService < ApplicationService
|
||||
SendTemplateMessageJob.perform_later('IssueDeleted', current_user.id, @issue&.subject, @issue.assigners.pluck(:id), @issue.author_id)
|
||||
end
|
||||
|
||||
unlock
|
||||
unlock("Api::V1::Issues::DeleteService:#{project.id}")
|
||||
|
||||
return true
|
||||
end
|
||||
@@ -34,12 +34,4 @@ class Api::V1::Issues::DeleteService < ApplicationService
|
||||
raise Error, "删除疑修失败!" unless issue.destroy!
|
||||
end
|
||||
|
||||
def try_lock
|
||||
raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::DeleteService:#{project.id}", 1, nx: true, ex: 60.seconds)
|
||||
end
|
||||
|
||||
def unlock
|
||||
$redis_cache.del("Api::V1::Issues::DeleteService:#{project.id}")
|
||||
end
|
||||
|
||||
end
|
||||
48
app/services/api/v1/issues/journals/create_service.rb
Normal file
48
app/services/api/v1/issues/journals/create_service.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
class Api::V1::Issues::Journals::CreateService < ApplicationService
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_reader :issue, :current_user, :notes, :parent_id, :attachment_ids
|
||||
|
||||
validates :issue, :current_user, presence: true
|
||||
|
||||
def initialize(issue, params, current_user=nil)
|
||||
@issue = issue
|
||||
@notes = params[:notes]
|
||||
@parent_id = params[:parent_id]
|
||||
@attachment_ids = params[:attachment_ids]
|
||||
@current_user = current_user
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
ActiveRecord::Base.transaction do
|
||||
check_attachments(attachment_ids) unless attachment_ids.blank?
|
||||
load_attachments(attachment_ids) unless attachment_ids.blank?
|
||||
|
||||
try_lock("Api::V1::Issues::Journals::CreateService:#{@issue.id}")
|
||||
@created_journal = Journal.new(journal_attributes)
|
||||
|
||||
build_comment_participants
|
||||
@created_journal.attachments = @attachments
|
||||
|
||||
@created_journal.save!
|
||||
unlock("Api::V1::Issues::Journals::CreateService:#{@issue.id}")
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def journal_attributes
|
||||
journal_attributes = {
|
||||
notes: notes
|
||||
}
|
||||
|
||||
journal_attributes.merge!({parent_id: parent_id}) if parent_id.present?
|
||||
|
||||
journal_attributes
|
||||
end
|
||||
|
||||
def build_comment_participants
|
||||
@issue.issue_participants.new({participant_type: "commented", participant_id: current_user.id}) unless @issue.issue_participants.exists?(participant_type: "commented", participant_id: current_user.id)
|
||||
end
|
||||
end
|
||||
52
app/services/api/v1/issues/journals/list_service.rb
Normal file
52
app/services/api/v1/issues/journals/list_service.rb
Normal file
@@ -0,0 +1,52 @@
|
||||
class Api::V1::Issues::Journals::ListService < ApplicationService
|
||||
|
||||
include ActiveModel::Model
|
||||
|
||||
attr_reader :issue, :category, :keyword, :sort_by, :sort_direction
|
||||
attr_accessor :queried_journals
|
||||
|
||||
validates :category, inclusion: {in: %w(all comment operate), message: "请输入正确的Category"}
|
||||
validates :sort_by, inclusion: {in: Journal.column_names, message: '请输入正确的SortBy'}, allow_blank: true
|
||||
validates :sort_direction, inclusion: {in: %w(asc desc), message: '请输入正确的SortDirection'}, allow_blank: true
|
||||
|
||||
def initialize(issue, params, current_user=nil)
|
||||
@issue = issue
|
||||
@keyword = params[:keyword]
|
||||
@category = params[:category] || 'all'
|
||||
@sort_by = params[:sort_by].present? ? params[:sort_by] : 'created_on'
|
||||
@sort_direction = (params[:sort_direction].present? ? params[:sort_direction] : 'asc').downcase
|
||||
end
|
||||
|
||||
def call
|
||||
raise Error, errors.full_messages.join(", ") unless valid?
|
||||
begin
|
||||
journal_query_data
|
||||
|
||||
@queried_journals
|
||||
rescue
|
||||
raise Error, "服务器错误,请联系系统管理员!"
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
def journal_query_data
|
||||
|
||||
@queried_journals = issue.journals
|
||||
|
||||
case category
|
||||
when 'comment'
|
||||
@queried_journals = issue.comment_journals
|
||||
when 'operate'
|
||||
@queried_journals = issue.operate_journals
|
||||
end
|
||||
|
||||
@queried_journals = @queried_journals.parent_journals
|
||||
|
||||
@queried_journals = @queried_journals.ransack(notes_cont: keyword).result if keyword.present?
|
||||
|
||||
@queried_journals = @queried_journals.includes(:journal_details, :user, :attachments, first_ten_children_journals: [:parent_journal, :reply_journal])
|
||||
@queried_journals = @queried_journals.reorder("journals.#{sort_by} #{sort_direction}").distinct
|
||||
|
||||
@queried_journals
|
||||
end
|
||||
end
|
||||
@@ -79,7 +79,6 @@ class Api::V1::Issues::ListService < ApplicationService
|
||||
|
||||
scope = q.result.includes(:priority, :issue_status, :user, :assigners, :version, :issue_tags, :comment_journals)
|
||||
|
||||
|
||||
scope = scope.reorder("issues.#{sort_by} #{sort_direction}").distinct
|
||||
|
||||
@queried_issues = scope
|
||||
|
||||
@@ -6,7 +6,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
||||
attr_reader :project, :issue, :current_user
|
||||
attr_reader :status_id, :priority_id, :milestone_id, :branch_name, :start_date, :due_date, :subject, :description
|
||||
attr_reader :issue_tag_ids, :assigner_ids, :attachment_ids, :receivers_login
|
||||
attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue
|
||||
attr_accessor :add_assigner_ids, :previous_issue_changes, :updated_issue, :atme_receivers
|
||||
|
||||
validates :project, :issue, :current_user, presence: true
|
||||
|
||||
@@ -40,23 +40,29 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
||||
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?
|
||||
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_assigners(assigner_ids)
|
||||
load_attachments(attachment_ids)
|
||||
load_issue_tags(issue_tag_ids)
|
||||
load_atme_receivers(receivers_login) unless receivers_login.blank?
|
||||
|
||||
try_lock
|
||||
try_lock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}")
|
||||
@updated_issue = @issue
|
||||
issue_load_attributes
|
||||
build_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
|
||||
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.blank? # 负责人
|
||||
@updated_issue.assigners = @assigners unless assigner_ids.blank?
|
||||
@updated_issue.attachments = @attachments unless attachment_ids.blank?
|
||||
@updated_issue.issue_tags = @issue_tags unless issue_tag_ids.blank?
|
||||
build_assigner_participants unless assigner_ids.nil? # 负责人
|
||||
build_edit_participants
|
||||
build_atme_participants if @atme_receivers.present?
|
||||
@updated_issue.assigners = @assigners || User.none unless assigner_ids.nil?
|
||||
@updated_issue.attachments = @attachments || Attachment.none unless attachment_ids.nil?
|
||||
@updated_issue.issue_tags = @issue_tags || IssueTag.none unless issue_tag_ids.nil?
|
||||
|
||||
@updated_issue.updated_on = Time.now
|
||||
@updated_issue.save!
|
||||
|
||||
build_after_issue_journal_details if @updated_issue.previous_changes.present? # 操作记录
|
||||
build_previous_issue_changes
|
||||
|
||||
# @信息发送
|
||||
@@ -67,7 +73,7 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
||||
SendTemplateMessageJob.perform_later('IssueAssigned', current_user.id, @issue&.id, add_assigner_ids) unless add_assigner_ids.blank?
|
||||
end
|
||||
|
||||
unlock
|
||||
unlock("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}")
|
||||
|
||||
return @updated_issue
|
||||
end
|
||||
@@ -87,108 +93,147 @@ class Api::V1::Issues::UpdateService < ApplicationService
|
||||
end
|
||||
|
||||
def build_assigner_participants
|
||||
@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
|
||||
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 = @updated_issue.previous_changes.except("updated_on", "created_on")
|
||||
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])
|
||||
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])
|
||||
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_issue_project_trends
|
||||
if @updated_issue.previous_changes[:status_id].present? && @updated_issue.previous_changes[:status_id][1] == 5
|
||||
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
|
||||
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_issue_journal_details
|
||||
# 更改标题
|
||||
if @updated_issue.previous_changes[:subject].present?
|
||||
journal = @updated_issue.journals.new({user_id: current_user.id})
|
||||
journal.journal_details.new({property: "attr", prop_key: "subject", old_value: @updated_issue.previous_changes[:subject][0], value: @updated_issue.previous_changes[:subject][1]})
|
||||
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.new({user_id: current_user.id})
|
||||
journal.journal_details.new({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["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.new({user_id: current_user.id})
|
||||
journal.journal_details.new({property: "attr", 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["status_id"].present?
|
||||
journal = @updated_issue.journals.create!({user_id: current_user.id})
|
||||
journal.journal_details.create!({property: "attr", 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.new({user_id: current_user.id})
|
||||
journal.journal_details.new({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["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[:fixed_version_id].present?
|
||||
journal = @updated_issue.journals.new({user_id: current_user.id})
|
||||
journal.journal_details.new({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["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.new({user_id: current_user.id})
|
||||
journal.journal_details.new({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["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.new({user_id: current_user.id})
|
||||
journal.journal_details.new({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["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.new({user_id: current_user.id})
|
||||
journal.journal_details.new({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.assigners.pluck(:id).sort! == assigner_ids.sort!
|
||||
journal = @updated_issue.journals.new({user_id: current_user.id})
|
||||
journal.journal_details.new({property: "assigner", prop_key: "#{assigner_ids.size}", old_value: @updated_issue.assigners.pluck(:nickname).join(","), value: @assigners.pluck(:nickname).join(",")})
|
||||
end
|
||||
|
||||
# 更改标记
|
||||
if !@updated_issue.issue_tags.pluck(:id).sort! == issue_tag_ids.sort!
|
||||
journal = @updated_issue.journals.new({user_id: current_user.id})
|
||||
journal.journal_details.new({property: "issue_tag", prop_key: "#{issue_tag_ids.size}", old_value: @updated_issue.issue_tags.pluck(:name).join(","), value: @issue_tags.pluck(:name).join(",")})
|
||||
end
|
||||
|
||||
# 更改附件
|
||||
if !@updated_issue.attachments.pluck(:id).sort! == attachment_ids.sort!
|
||||
journal = @updated_issue.journals.new({user_id: current_user.id})
|
||||
journal.journal_details.new({property: "attachment", prop_key: "#{attachment_ids.size}", old_value: @updated_issue.attachments.pluck(:filename).join(","), value: @attachments.pluck(:filename).join(",")})
|
||||
# 更改结束时间
|
||||
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
|
||||
rescue
|
||||
raise Error, "创建操作记录失败!"
|
||||
end
|
||||
end
|
||||
|
||||
def try_lock
|
||||
raise Error, "请稍后再试!" unless $redis_cache.set("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}", 1, nx: true, ex: 60.seconds)
|
||||
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 & assigner_ids).empty? || !(now_assigner_ids.empty? && new_assigner_ids.empty?)
|
||||
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 unlock
|
||||
$redis_cache.del("Api::V1::Issues::UpdateService:#{project.id}:#{issue.id}")
|
||||
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 & new_issue_tag_ids).empty? || !(now_issue_tag_ids.empty? && new_issue_tag_ids.empty?)
|
||||
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 & new_attachment_ids).empty? || !(now_attachment_ids.empty? && new_attachment_ids.empty?)
|
||||
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
|
||||
Reference in New Issue
Block a user