From 6f0afffb3bca51b94369f629b37cb27f670f6d3c Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 7 Aug 2024 11:01:24 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=AF=BC?= =?UTF-8?q?=E5=85=A5=E5=AF=BC=E5=87=BA=E5=B7=A5=E4=BD=9C=E9=A1=B9=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 62 +++++++++++++++++++++ config/routes/api.rb | 2 + 2 files changed, 64 insertions(+) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index b74cf29f0..3506dfdea 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -124,6 +124,68 @@ 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.parse(params[:file].to_io) + 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 + row[7].split(',').each do |a| + u = User.find_by(login: a) + next unless u.present? + issue.assigners << u + end + issue.priority_id = row[8] + 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 + 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? diff --git a/config/routes/api.rb b/config/routes/api.rb index 6d5aded88..1aea612b7 100644 --- a/config/routes/api.rb +++ b/config/routes/api.rb @@ -8,6 +8,8 @@ defaults format: :json do get :priorities get :tags get :statues + get :export + get :import end member do get :link_index From 97685bf68cf6441818d79bd3cd4b73ee72f02324 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 7 Aug 2024 11:23:11 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E8=AF=BB?= =?UTF-8?q?=E5=8F=96=E6=96=87=E4=BB=B6=E5=BD=A2=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index 3506dfdea..a85c5b310 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -147,7 +147,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController 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.parse(params[:file].to_io) + 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| From f1a79d926c9457c7bb5d833f494f7b2e4d2c8094 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 7 Aug 2024 11:27:14 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9Anil=E5=88=A4?= =?UTF-8?q?=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 26 ++++++++++++--------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index a85c5b310..e56ef5e53 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -162,19 +162,23 @@ class Api::Pm::IssuesController < Api::Pm::BaseController issue.changer = changer issue.updated_on = row[5] issue.status_id = row[6].to_i - row[7].split(',').each do |a| - u = User.find_by(login: a) - next unless u.present? - issue.assigners << u + 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] - 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 + 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] From b7aa1e51b3c8cc6a12c449f6b9d30fcfada64c04 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 15:56:40 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=A5=E5=BF=97=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/api/pm/issues_controller.rb | 10 +- app/controllers/api/pm/journals_controller.rb | 2 +- app/models/journal.rb | 365 ++++++++++++++++++ .../api/pm/issues/batch_delete_service.rb | 38 ++ .../api/pm/issues/batch_update_service.rb | 33 ++ app/services/api/pm/issues/create_service.rb | 168 ++++++++ app/services/api/pm/issues/delete_service.rb | 42 ++ app/services/api/pm/issues/update_service.rb | 283 ++++++++++++++ .../pm/issues/journals/_detail.json.jbuilder | 25 ++ .../pm/issues/journals/index.json.jbuilder | 8 + 10 files changed, 968 insertions(+), 6 deletions(-) create mode 100644 app/services/api/pm/issues/batch_delete_service.rb create mode 100644 app/services/api/pm/issues/batch_update_service.rb create mode 100644 app/services/api/pm/issues/create_service.rb create mode 100644 app/services/api/pm/issues/delete_service.rb create mode 100644 app/services/api/pm/issues/update_service.rb create mode 100644 app/views/api/pm/issues/journals/_detail.json.jbuilder create mode 100644 app/views/api/pm/issues/journals/index.json.jbuilder diff --git a/app/controllers/api/pm/issues_controller.rb b/app/controllers/api/pm/issues_controller.rb index e56ef5e53..cdf5f1d7d 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -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 diff --git a/app/controllers/api/pm/journals_controller.rb b/app/controllers/api/pm/journals_controller.rb index 14f386860..b10cb4829 100644 --- a/app/controllers/api/pm/journals_controller.rb +++ b/app/controllers/api/pm/journals_controller.rb @@ -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 diff --git a/app/models/journal.rb b/app/models/journal.rb index 0fdca0f9d..ea50646b6 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -82,6 +82,371 @@ class Journal < ApplicationRecord 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 old_value.nil? || old_value.blank? + content += "设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "由#{old_value}更改为#{new_value}" + end + content.gsub!('新增', '待评审') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + return content + when 'root_id' + old_value = Issue.find_by_id(detail.old_value)&.subject + new_value = Issue.find_by_id(detail.value)&.subject + if old_value.nil? || old_value.blank? + content += "关联了父需求<#{new_value}>" + else + if new_value.nil? || new_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| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了子需求#{new_value}" + else + if new_value.nil? || new_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| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了子需求#{new_value}" + else + if new_value.nil? || new_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 old_value.nil? || old_value.blank? + content += "设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "由#{old_value}更改为#{new_value}" + end + content.gsub!('新增', '待处理') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + return content + when 'root_id' + old_value = Issue.find_by_id(detail.old_value)&.subject + new_value = Issue.find_by_id(detail.value)&.subject + if old_value.nil? || old_value.blank? + content += "关联了父任务<#{new_value}>" + else + if new_value.nil? || new_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| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了子任务#{new_value}" + else + if new_value.nil? || new_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| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了子任务#{new_value}" + else + if new_value.nil? || new_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 old_value.nil? || old_value.blank? + content += "设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "由#{old_value}更改为#{new_value}" + end + content.gsub!('新增', '待修复') + content.gsub!('正在解决', '修复中') + content.gsub!('已解决', '已修复') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + return content + when 'root_id' + old_value = Issue.find_by_id(detail.old_value)&.subject + new_value = Issue.find_by_id(detail.value)&.subject + if old_value.nil? || old_value.blank? + content += "关联了父缺陷<#{new_value}>" + else + if new_value.nil? || new_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| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了子缺陷#{new_value}" + else + if new_value.nil? || new_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| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了子缺陷#{new_value}" + else + if new_value.nil? || new_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 "修改了标题" + when 'description' + return "修改了正文" + when 'priority_id' + old_value = IssuePriority.find_by_id(detail.old_value)&.name + new_value = IssuePriority.find_by_id(detail.value)&.name + if old_value.nil? || old_value.blank? + content += "将优先级设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "将优先级由#{old_value}更改为#{new_value}" + end + return content + when 'pm_issue_type' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "将工作项类型设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "将工作项类型由#{old_value}更改为#{new_value}" + 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 old_value.nil? || old_value.blank? + content += "添加了关联迭代" + else + if new_value.nil? || new_value.blank? + content += "将关联迭代更改为未设置" + 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 old_value.nil? || old_value.blank? + content += "添加关联代码库#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将关联代码库更改为未设置" + else + content += "将关联代码库由#{old_value}改为#{new_value}" + end + end + return content + when 'branch_name' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加关联分支#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将关联分支更改为未设置" + else + content += "将关联分支由#{old_value}改为#{new_value}" + end + end + return content + + when 'start_date' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加开始时间#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将开始时间更改为未设置" + else + content += "将开始时间由#{old_value}改为#{new_value}" + end + end + return content + + when 'due_date' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加结束时间#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将结束时间更改为未设置" + else + content += "将结束时间由#{old_value}改为#{new_value}" + end + end + return content + when 'time_scale' + old_value = detail.old_value + new_value = detail.value + if old_value.nil? || old_value.blank? + content += "添加预估工时#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将预估工时更改为未设置" + else + content += "将预估工时由#{old_value}改为#{new_value}" + end + end + return content + end + when 'attachment' + old_value = detail.old_value.to_s + new_value = detail.value.to_s + if old_value.nil? || old_value.blank? + content += "上传了附件" + else + if new_value.nil? || new_value.blank? + content += "删除了附件" + else + content += "上传了附件" + end + end + return content + when 'assigner' + old_value = User.where(id: detail.old_value.split(",")).map{|u| u.real_name}.join("、") + new_value = User.where(id: detail.value.split(",")).map{|u| u.real_name}.join("、") + if old_value.nil? || old_value.blank? + content += "添加负责人#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将负责人更改为未设置" + else + content += "将负责人由#{old_value}更改为#{new_value}" + end + end + return content + when 'issue_tag' + old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name).join("、") + new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name).join("、") + if old_value.nil? || old_value.blank? + content += "添加标记#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "将标记更改为未设置" + 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| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "关联了工作项#{new_value}" + else + if new_value.nil? || new_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| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + if old_value.nil? || old_value.blank? + content += "新建了关联的工作项#{new_value}" + else + if new_value.nil? || new_value.blank? + content += "删除了关联的工作项#{old_value}" + else + content += "新建了关联的工作项#{new_value}" + end + end + return content + end + end + def operate_content content = "" detail = self.journal_details.take diff --git a/app/services/api/pm/issues/batch_delete_service.rb b/app/services/api/pm/issues/batch_delete_service.rb new file mode 100644 index 000000000..9afdfdb81 --- /dev/null +++ b/app/services/api/pm/issues/batch_delete_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/api/pm/issues/batch_update_service.rb b/app/services/api/pm/issues/batch_update_service.rb new file mode 100644 index 000000000..b7eabf2cb --- /dev/null +++ b/app/services/api/pm/issues/batch_update_service.rb @@ -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 \ No newline at end of file diff --git a/app/services/api/pm/issues/create_service.rb b/app/services/api/pm/issues/create_service.rb new file mode 100644 index 000000000..796faf1e5 --- /dev/null +++ b/app/services/api/pm/issues/create_service.rb @@ -0,0 +1,168 @@ +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) + 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.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 + @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! + + PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id) if @linkable_id.present? + 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: 'issue', prop_key: 1, old_value: '', value: ''}) + end +end \ No newline at end of file diff --git a/app/services/api/pm/issues/delete_service.rb b/app/services/api/pm/issues/delete_service.rb new file mode 100644 index 000000000..2d5df500e --- /dev/null +++ b/app/services/api/pm/issues/delete_service.rb @@ -0,0 +1,42 @@ +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}") # 开始写数据,加锁 + + 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 + + unlock("Api::V1::Issues::DeleteService:#{project.id}") + + return true + end + + private + + def delete_issue + raise Error, "删除疑修失败!" unless issue.destroy! + end +end \ No newline at end of file diff --git a/app/services/api/pm/issues/update_service.rb b/app/services/api/pm/issues/update_service.rb new file mode 100644 index 000000000..99896e884 --- /dev/null +++ b/app/services/api/pm/issues/update_service.rb @@ -0,0 +1,283 @@ +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: "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.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.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 + 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 & 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 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 \ No newline at end of file diff --git a/app/views/api/pm/issues/journals/_detail.json.jbuilder b/app/views/api/pm/issues/journals/_detail.json.jbuilder new file mode 100644 index 000000000..58a7ed8fd --- /dev/null +++ b/app/views/api/pm/issues/journals/_detail.json.jbuilder @@ -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 detail.property == "attr" ? detail.prop_key : detail.property + 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 diff --git a/app/views/api/pm/issues/journals/index.json.jbuilder b/app/views/api/pm/issues/journals/index.json.jbuilder new file mode 100644 index 000000000..0ca2a50e6 --- /dev/null +++ b/app/views/api/pm/issues/journals/index.json.jbuilder @@ -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 \ No newline at end of file From 854df00ffb51ad90d7750674f5af9b7c4d927683 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 16:32:19 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E6=93=8D?= =?UTF-8?q?=E4=BD=9C=E6=97=A5=E5=BF=97=E6=97=A7=E6=95=B0=E6=8D=AE=E9=80=82?= =?UTF-8?q?=E9=85=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 48 +++++++++++++++++++ .../pm/issues/journals/_detail.json.jbuilder | 2 +- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index ea50646b6..30924437b 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -82,6 +82,14 @@ class Journal < ApplicationRecord end end + def pm_operate_category + if (detail.property == "requirement" || detail.property == "task" || detail.property == "bug") && detail.prop_key.to_s == "1" + return "issue" + else + return detail.property == "attr" ? detail.prop_key : detail.property + end + end + def pm_operate_content content = "" detail = self.journal_details.take @@ -282,6 +290,36 @@ class Journal < ApplicationRecord content += "将优先级由#{old_value}更改为#{new_value}" 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 old_value.nil? || old_value.blank? + content += "将状态设置为#{new_value}" + else + new_value = "未设置" if new_value.blank? + content += "将状态由#{old_value}更改为#{new_value}" + end + case self.issue.pm_issue_type + when 'requirement' + content.gsub!('新增', '待评审') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + when 'task' + content.gsub!('新增', '待处理') + content.gsub!('正在解决', '进行中') + content.gsub!('已解决', '已完成') + content.gsub!('关闭', '已关闭') + content.gsub!('拒绝', '已拒绝') + when 'bug' + 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 @@ -444,6 +482,16 @@ class Journal < ApplicationRecord end end return content + when 'issue' + issue = self.issue + case issue.pm_issue_type + when 1 + return "创建了需求" + when 2 + return "创建了任务" + when 3 + return "创建了缺陷" + end end end diff --git a/app/views/api/pm/issues/journals/_detail.json.jbuilder b/app/views/api/pm/issues/journals/_detail.json.jbuilder index 58a7ed8fd..fdf4bc716 100644 --- a/app/views/api/pm/issues/journals/_detail.json.jbuilder +++ b/app/views/api/pm/issues/journals/_detail.json.jbuilder @@ -11,7 +11,7 @@ json.user do end if journal.is_journal_detail? detail = journal.journal_details.take - json.operate_category detail.property == "attr" ? detail.prop_key : detail.property + json.operate_category journal.pm_operate_category json.operate_content journal.is_journal_detail? ? journal.pm_operate_content : nil else json.notes journal.notes From a8b0435c94beaf2c02625b0c1de5dbf765188fd4 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 16:34:28 +0800 Subject: [PATCH 06/11] fix --- app/models/journal.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/app/models/journal.rb b/app/models/journal.rb index 30924437b..9a0624cf0 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -83,6 +83,7 @@ class Journal < ApplicationRecord end def pm_operate_category + detail = self.journal_details.take if (detail.property == "requirement" || detail.property == "task" || detail.property == "bug") && detail.prop_key.to_s == "1" return "issue" else From 69b5cae870013bfb38ec6c92dc868f6480469fb9 Mon Sep 17 00:00:00 2001 From: yystopf Date: Tue, 20 Aug 2024 16:43:31 +0800 Subject: [PATCH 07/11] fix --- app/models/journal.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 9a0624cf0..1c37d2f1b 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -300,20 +300,20 @@ class Journal < ApplicationRecord new_value = "未设置" if new_value.blank? content += "将状态由#{old_value}更改为#{new_value}" end - case self.issue.pm_issue_type - when 'requirement' + case self.issue.pm_issue_type.to_i + when 1 content.gsub!('新增', '待评审') content.gsub!('正在解决', '进行中') content.gsub!('已解决', '已完成') content.gsub!('关闭', '已关闭') content.gsub!('拒绝', '已拒绝') - when 'task' + when 2 content.gsub!('新增', '待处理') content.gsub!('正在解决', '进行中') content.gsub!('已解决', '已完成') content.gsub!('关闭', '已关闭') content.gsub!('拒绝', '已拒绝') - when 'bug' + when 3 content.gsub!('新增', '待修复') content.gsub!('正在解决', '修复中') content.gsub!('已解决', '已修复') From 91399808c4498f7e212044ee6dd16c6c85f914d1 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 16:05:45 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=9A=E5=88=9B?= =?UTF-8?q?=E5=BB=BA=E6=93=8D=E4=BD=9C=E8=AE=B0=E5=BD=95=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/issue_links_controller.rb | 36 +++++- app/models/issue.rb | 14 +++ app/models/journal.rb | 111 +++++++++--------- app/services/api/pm/issues/create_service.rb | 39 ++++-- app/services/api/pm/issues/delete_service.rb | 28 +++-- app/services/api/pm/issues/update_service.rb | 45 ++++++- 6 files changed, 188 insertions(+), 85 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index fe2c93c82..370e61d13 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -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) } - render_ok + 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_id.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 - @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')) - @link = @links.last - if @link.try(: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 + @link.destroy! + end render_ok - else + rescue render_error('删除失败!') end end diff --git a/app/models/issue.rb b/app/models/issue.rb index cb8b98cce..955f903e9 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/app/models/journal.rb b/app/models/journal.rb index 1c37d2f1b..d387366aa 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -114,8 +114,8 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = Issue.find_by_id(detail.old_value)&.subject - new_value = Issue.find_by_id(detail.value)&.subject + old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" + new_value = "#{Issue.find_by_id(detail.value)&.subject}" if old_value.nil? || old_value.blank? content += "关联了父需求<#{new_value}>" else @@ -127,28 +127,28 @@ class Journal < ApplicationRecord end return content when 'leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了子需求#{new_value}" + content += "新建了子需求#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的子需求#{old_value}" + content += "删除了关联的子需求#{old_value}" else - content += "新建了子需求#{new_value}" + content += "新建了子需求#{new_value}" end end return content when 'tag_leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了子需求#{new_value}" + content += "关联了子需求#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的子需求#{old_value}" + content += "取消了关联的子需求#{old_value}" else - content += "关联了子需求#{new_value}" + content += "关联了子需求#{new_value}" end end return content @@ -174,8 +174,8 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = Issue.find_by_id(detail.old_value)&.subject - new_value = Issue.find_by_id(detail.value)&.subject + old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" + new_value = "#{Issue.find_by_id(detail.value)&.subject}" if old_value.nil? || old_value.blank? content += "关联了父任务<#{new_value}>" else @@ -187,28 +187,28 @@ class Journal < ApplicationRecord end return content when 'leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了子任务#{new_value}" + content += "新建了子任务#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的子任务#{old_value}" + content += "删除了关联的子任务#{old_value}" else - content += "新建了子任务#{new_value}" + content += "新建了子任务#{new_value}" end end return content when 'tag_leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了子任务#{new_value}" + content += "关联了子任务#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的子任务#{old_value}" + content += "取消了关联的子任务#{old_value}" else - content += "关联了子任务#{new_value}" + content += "关联了子任务#{new_value}" end end return content @@ -234,8 +234,8 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = Issue.find_by_id(detail.old_value)&.subject - new_value = Issue.find_by_id(detail.value)&.subject + old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" + new_value = "#{Issue.find_by_id(detail.value)&.subject}" if old_value.nil? || old_value.blank? content += "关联了父缺陷<#{new_value}>" else @@ -247,28 +247,28 @@ class Journal < ApplicationRecord end return content when 'leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了子缺陷#{new_value}" + content += "新建了子缺陷#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的子缺陷#{old_value}" + content += "删除了关联的子缺陷#{old_value}" else - content += "新建了子缺陷#{new_value}" + content += "新建了子缺陷#{new_value}" end end return content when 'tag_leaf_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了子缺陷#{new_value}" + content += "关联了子缺陷#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的子缺陷#{old_value}" + content += "取消了关联的子缺陷#{old_value}" else - content += "关联了子缺陷#{new_value}" + content += "关联了子缺陷#{new_value}" end end return content @@ -429,41 +429,41 @@ class Journal < ApplicationRecord end return content when 'assigner' - old_value = User.where(id: detail.old_value.split(",")).map{|u| u.real_name}.join("、") - new_value = User.where(id: detail.value.split(",")).map{|u| u.real_name}.join("、") + old_value = User.where(id: detail.old_value.split(",")).map{|u| "#{u.real_name}"}.join("、") + new_value = User.where(id: detail.value.split(",")).map{|u| "#{u.real_name}"}.join("、") if old_value.nil? || old_value.blank? - content += "添加负责人#{new_value}" + content += "添加负责人#{new_value}" else if new_value.nil? || new_value.blank? content += "将负责人更改为未设置" else - content += "将负责人由#{old_value}更改为#{new_value}" + content += "将负责人由#{old_value}更改为#{new_value}" end end return content when 'issue_tag' - old_value = IssueTag.where(id: detail.old_value.split(",")).pluck(:name).join("、") - new_value = IssueTag.where(id: detail.value.split(",")).pluck(:name).join("、") + old_value = IssueTag.where(id: detail.old_value.split(",")).map{|t| "#{t.name}"}.join("、") + new_value = IssueTag.where(id: detail.value.split(",")).map{|t| "#{t.name}"}.join("、") if old_value.nil? || old_value.blank? - content += "添加标记#{new_value}" + content += "添加标记#{new_value}" else if new_value.nil? || new_value.blank? content += "将标记更改为未设置" else - content += "将标记由#{old_value}更改为#{new_value}" + 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| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "关联了工作项#{new_value}" + content += "新建了关联的工作项#{new_value}" else if new_value.nil? || new_value.blank? - content += "取消了关联的工作项#{old_value}" + content += "删除了关联的工作项#{old_value}" else - content += "关联了工作项#{new_value}" + content += "新建了关联的工作项#{new_value}" end end content.gsub!('1', "需求") @@ -471,17 +471,20 @@ class Journal < ApplicationRecord content.gsub!('3', "缺陷") return content when 'tag_link_issue' - old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") + new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") if old_value.nil? || old_value.blank? - content += "新建了关联的工作项#{new_value}" + content += "关联了工作项#{new_value}" else if new_value.nil? || new_value.blank? - content += "删除了关联的工作项#{old_value}" + content += "取消了关联的工作项#{old_value}" else - content += "新建了关联的工作项#{new_value}" + content += "关联了工作项#{new_value}" end end + content.gsub!('1', "需求") + content.gsub!('2', "任务") + content.gsub!('3', "缺陷") return content when 'issue' issue = self.issue diff --git a/app/services/api/pm/issues/create_service.rb b/app/services/api/pm/issues/create_service.rb index 796faf1e5..5412fe17d 100644 --- a/app/services/api/pm/issues/create_service.rb +++ b/app/services/api/pm/issues/create_service.rb @@ -55,16 +55,6 @@ class Api::Pm::Issues::CreateService < ApplicationService load_atme_receivers(receivers_login) unless receivers_login.blank? try_lock("Api::Pm::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.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.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) @@ -75,12 +65,35 @@ class Api::Pm::Issues::CreateService < ApplicationService 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! - - PmLink.create(be_linkable_type: 'Issue', be_linkable_id: @created_issue.id, linkable_type: 'Issue', linkable_id: @linkable_id) if @linkable_id.present? + 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}) @@ -163,6 +176,6 @@ class Api::Pm::Issues::CreateService < ApplicationService def build_issue_journal_details journal = @created_issue.journals.new({user_id: current_user.id}) - journal.journal_details.new({property: 'issue', prop_key: 1, old_value: '', value: ''}) + journal.journal_details.new({property: @created_issue.pm_issue_type_string, prop_key: 1, old_value: '', value: ''}) end end \ No newline at end of file diff --git a/app/services/api/pm/issues/delete_service.rb b/app/services/api/pm/issues/delete_service.rb index 2d5df500e..0a04094c3 100644 --- a/app/services/api/pm/issues/delete_service.rb +++ b/app/services/api/pm/issues/delete_service.rb @@ -14,21 +14,27 @@ class Api::Pm::Issues::DeleteService < ApplicationService 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) + 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 + 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? + 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 - - 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 - unlock("Api::V1::Issues::DeleteService:#{project.id}") return true diff --git a/app/services/api/pm/issues/update_service.rb b/app/services/api/pm/issues/update_service.rb index 99896e884..7196a497e 100644 --- a/app/services/api/pm/issues/update_service.rb +++ b/app/services/api/pm/issues/update_service.rb @@ -196,7 +196,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService # 修改状态 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]}) + 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 # 修改优先级 @@ -205,6 +205,24 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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}) @@ -228,6 +246,31 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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.previous_changes["root_id"][0]}) + 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.previous_changes["root_id"][1]}) + end + end rescue raise Error, "创建操作记录失败!" end From 1a374468eaa1c4fa6c0558fc175bc929bbd625a5 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 17:23:13 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/pm/issue_links_controller.rb | 2 +- app/models/journal.rb | 108 +++++++++--------- app/services/api/pm/issues/update_service.rb | 10 +- 3 files changed, 60 insertions(+), 60 deletions(-) diff --git a/app/controllers/api/pm/issue_links_controller.rb b/app/controllers/api/pm/issue_links_controller.rb index 370e61d13..867dcaf41 100644 --- a/app/controllers/api/pm/issue_links_controller.rb +++ b/app/controllers/api/pm/issue_links_controller.rb @@ -12,7 +12,7 @@ class Api::Pm::IssueLinksController < Api::Pm::BaseController @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_id.id}) + 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}) diff --git a/app/models/journal.rb b/app/models/journal.rb index d387366aa..4a78ed301 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -84,10 +84,10 @@ class Journal < ApplicationRecord def pm_operate_category detail = self.journal_details.take - if (detail.property == "requirement" || detail.property == "task" || detail.property == "bug") && detail.prop_key.to_s == "1" + if %w(requirement task bug).include?(detail.property) && detail.prop_key.to_s == "1" return "issue" else - return detail.property == "attr" ? detail.prop_key : detail.property + return %w(requirement task bug attr).include?(detail.property) ? detail.prop_key : detail.property end end @@ -101,10 +101,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待评审') @@ -116,10 +116,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父需求<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父需求<#{old_value}>" else content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" @@ -129,10 +129,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子需求#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子需求#{old_value}" else content += "新建了子需求#{new_value}" @@ -142,10 +142,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子需求#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子需求#{old_value}" else content += "关联了子需求#{new_value}" @@ -161,10 +161,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待处理') @@ -176,10 +176,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父任务<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父任务<#{old_value}>" else content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" @@ -189,10 +189,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子任务#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子任务#{old_value}" else content += "新建了子任务#{new_value}" @@ -202,10 +202,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子任务#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子任务#{old_value}" else content += "关联了子任务#{new_value}" @@ -221,10 +221,10 @@ class Journal < ApplicationRecord old_value = IssueStatus.find_by_id(detail.old_value)&.name new_value = IssueStatus.find_by_id(detail.value)&.name content += "将状态" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "由#{old_value}更改为#{new_value}" end content.gsub!('新增', '待修复') @@ -236,10 +236,10 @@ class Journal < ApplicationRecord when 'root_id' old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了父缺陷<#{new_value}>" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的父缺陷<#{old_value}>" else content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" @@ -249,10 +249,10 @@ class Journal < ApplicationRecord when 'leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了子缺陷#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的子缺陷#{old_value}" else content += "新建了子缺陷#{new_value}" @@ -262,10 +262,10 @@ class Journal < ApplicationRecord when 'tag_leaf_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了子缺陷#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的子缺陷#{old_value}" else content += "关联了子缺陷#{new_value}" @@ -284,20 +284,20 @@ class Journal < ApplicationRecord when 'priority_id' old_value = IssuePriority.find_by_id(detail.old_value)&.name new_value = IssuePriority.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将优先级设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将优先级由#{old_value}更改为#{new_value}" 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 old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将状态设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将状态由#{old_value}更改为#{new_value}" end case self.issue.pm_issue_type.to_i @@ -324,10 +324,10 @@ class Journal < ApplicationRecord when 'pm_issue_type' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "将工作项类型设置为#{new_value}" else - new_value = "未设置" if new_value.blank? + new_value = "未设置" if detail.value.blank? content += "将工作项类型由#{old_value}更改为#{new_value}" end content.gsub!('1', '需求') @@ -337,10 +337,10 @@ class Journal < ApplicationRecord when 'pm_sprint_id' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加了关联迭代" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联迭代更改为未设置" else content += "变更了关联迭代" @@ -350,10 +350,10 @@ class Journal < ApplicationRecord when 'project_id' old_value = Project.find_by_id(detail.old_value)&.name new_value = Project.find_by_id(detail.value)&.name - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加关联代码库#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联代码库更改为未设置" else content += "将关联代码库由#{old_value}改为#{new_value}" @@ -363,10 +363,10 @@ class Journal < ApplicationRecord when 'branch_name' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加关联分支#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将关联分支更改为未设置" else content += "将关联分支由#{old_value}改为#{new_value}" @@ -377,10 +377,10 @@ class Journal < ApplicationRecord when 'start_date' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加开始时间#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将开始时间更改为未设置" else content += "将开始时间由#{old_value}改为#{new_value}" @@ -391,10 +391,10 @@ class Journal < ApplicationRecord when 'due_date' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加结束时间#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将结束时间更改为未设置" else content += "将结束时间由#{old_value}改为#{new_value}" @@ -404,10 +404,10 @@ class Journal < ApplicationRecord when 'time_scale' old_value = detail.old_value new_value = detail.value - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加预估工时#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将预估工时更改为未设置" else content += "将预估工时由#{old_value}改为#{new_value}" @@ -418,10 +418,10 @@ class Journal < ApplicationRecord when 'attachment' old_value = detail.old_value.to_s new_value = detail.value.to_s - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "上传了附件" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了附件" else content += "上传了附件" @@ -431,10 +431,10 @@ class Journal < ApplicationRecord when 'assigner' old_value = User.where(id: detail.old_value.split(",")).map{|u| "#{u.real_name}"}.join("、") new_value = User.where(id: detail.value.split(",")).map{|u| "#{u.real_name}"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加负责人#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将负责人更改为未设置" else content += "将负责人由#{old_value}更改为#{new_value}" @@ -444,10 +444,10 @@ class Journal < ApplicationRecord when 'issue_tag' old_value = IssueTag.where(id: detail.old_value.split(",")).map{|t| "#{t.name}"}.join("、") new_value = IssueTag.where(id: detail.value.split(",")).map{|t| "#{t.name}"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "添加标记#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "将标记更改为未设置" else content += "将标记由#{old_value}更改为#{new_value}" @@ -457,10 +457,10 @@ class Journal < ApplicationRecord when 'link_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "新建了关联的工作项#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "删除了关联的工作项#{old_value}" else content += "新建了关联的工作项#{new_value}" @@ -473,10 +473,10 @@ class Journal < ApplicationRecord when 'tag_link_issue' old_value = Issue.where(id: detail.old_value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") new_value = Issue.where(id: detail.value.to_s.split(",")).map{|i| "[#{i.pm_issue_type}]-<#{i.subject}>"}.join("、") - if old_value.nil? || old_value.blank? + if detail.old_value.nil? || detail.old_value.blank? content += "关联了工作项#{new_value}" else - if new_value.nil? || new_value.blank? + if detail.value.nil? || detail.value.blank? content += "取消了关联的工作项#{old_value}" else content += "关联了工作项#{new_value}" diff --git a/app/services/api/pm/issues/update_service.rb b/app/services/api/pm/issues/update_service.rb index 7196a497e..78d62fb2b 100644 --- a/app/services/api/pm/issues/update_service.rb +++ b/app/services/api/pm/issues/update_service.rb @@ -262,13 +262,13 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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.previous_changes["root_id"][0]}) + 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.previous_changes["root_id"][1]}) + 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 @@ -282,7 +282,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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?) + 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 @@ -298,7 +298,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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?) + 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 @@ -314,7 +314,7 @@ class Api::Pm::Issues::UpdateService < ApplicationService 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?) + 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 From 0643d24486d3ebfee67f1c7e2fd740c8e96e9cad Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 17:30:14 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index 4a78ed301..d2410a2b7 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -117,12 +117,12 @@ class Journal < ApplicationRecord old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父需求<#{new_value}>" + content += "关联了父需求<#{new_value}>" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父需求<#{old_value}>" + content += "取消了关联的父需求<#{old_value}>" else - content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" end end return content @@ -177,12 +177,12 @@ class Journal < ApplicationRecord old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父任务<#{new_value}>" + content += "关联了父任务<#{new_value}>" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父任务<#{old_value}>" + content += "取消了关联的父任务<#{old_value}>" else - content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" end end return content @@ -237,12 +237,12 @@ class Journal < ApplicationRecord old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" new_value = "#{Issue.find_by_id(detail.value)&.subject}" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父缺陷<#{new_value}>" + content += "关联了父缺陷<#{new_value}>" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父缺陷<#{old_value}>" + content += "取消了关联的父缺陷<#{old_value}>" else - content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" end end return content From 63753c3963f479840f8ce85851dd9f5ac72ad350 Mon Sep 17 00:00:00 2001 From: yystopf Date: Wed, 21 Aug 2024 17:36:03 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=EF=BC=9A=E6=8E=A8?= =?UTF-8?q?=E9=80=81=E4=BB=A3=E7=A0=81=E5=86=B2=E7=AA=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/models/journal.rb | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/app/models/journal.rb b/app/models/journal.rb index d2410a2b7..ab15de9d9 100644 --- a/app/models/journal.rb +++ b/app/models/journal.rb @@ -114,15 +114,15 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" - new_value = "#{Issue.find_by_id(detail.value)&.subject}" + old_value = "<#{Issue.find_by_id(detail.old_value)&.subject}>" + new_value = "<#{Issue.find_by_id(detail.value)&.subject}>" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父需求<#{new_value}>" + content += "关联了父需求#{new_value}" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父需求<#{old_value}>" + content += "取消了关联的父需求#{old_value}" else - content += "将关联的父需求由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父需求由#{old_value}更改为#{new_value}" end end return content @@ -174,15 +174,15 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" - new_value = "#{Issue.find_by_id(detail.value)&.subject}" + old_value = "<#{Issue.find_by_id(detail.old_value)&.subject}>" + new_value = "<#{Issue.find_by_id(detail.value)&.subject}>" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父任务<#{new_value}>" + content += "关联了父任务#{new_value}" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父任务<#{old_value}>" + content += "取消了关联的父任务#{old_value}" else - content += "将关联的父任务由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父任务由#{old_value}>更改为#{new_value}" end end return content @@ -234,15 +234,15 @@ class Journal < ApplicationRecord content.gsub!('拒绝', '已拒绝') return content when 'root_id' - old_value = "#{Issue.find_by_id(detail.old_value)&.subject}" - new_value = "#{Issue.find_by_id(detail.value)&.subject}" + old_value = "<#{Issue.find_by_id(detail.old_value)&.subject}>" + new_value = "<#{Issue.find_by_id(detail.value)&.subject}>" if detail.old_value.nil? || detail.old_value.blank? - content += "关联了父缺陷<#{new_value}>" + content += "关联了父缺陷#{new_value}" else if detail.value.nil? || detail.value.blank? - content += "取消了关联的父缺陷<#{old_value}>" + content += "取消了关联的父缺陷#{old_value}" else - content += "将关联的父缺陷由<#{old_value}>更改为<#{new_value}>" + content += "将关联的父缺陷由#{old_value}更改为#{new_value}" end end return content