From b153a486f3f1c34f3e4d8dfc82e397e554239359 Mon Sep 17 00:00:00 2001 From: yystopf Date: Thu, 29 Aug 2024 14:31:58 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=94=B9=EF=BC=9A=E5=AF=BC=E5=85=A5?= =?UTF-8?q?=E7=A6=85=E9=81=93=E6=95=B0=E6=8D=AE=E8=84=9A=E6=9C=AC=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/tasks/import_issues_from_chandao.rake | 35 ++++++++++++++++++++--- 1 file changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/tasks/import_issues_from_chandao.rake b/lib/tasks/import_issues_from_chandao.rake index 245e6df14..96a47b901 100644 --- a/lib/tasks/import_issues_from_chandao.rake +++ b/lib/tasks/import_issues_from_chandao.rake @@ -5,6 +5,14 @@ namespace :import_from_chandao do # 执行示例 bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" # RAILS_ENV=production bundle exec rake "import_from_chandao:bugs[企业内部工时管理系统.csv, 3]" task :bugs, [:name, :pm_project_id] => :environment do |t, args| + def trans_status(str) + h={ + "激活" => 1, + "已解决" => 3, + "已关闭" => 5 + } + h[str] + end name = args.name CSV.foreach("#{Rails.root}/#{args.name}", headers: true) do | row | randd_field_hash = row.to_hash @@ -15,17 +23,27 @@ namespace :import_from_chandao do if assigner.present? issue.assigners << assigner end - issue.status_id = IssueStatus.first.id + issue.project_issues_index = randd_field_hash['编号'].to_i + issue.status_id = trans_status(randd_field_hash['Bug状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['Bug标题'] issue.description = randd_field_hash['重现步骤'] - issue.created_on = randd_field_hash['创建日期'].to_time - issue.due_date = randd_field_hash['截止日期'] + issue.created_on = randd_field_hash['创建日期'].to_time rescue nil + issue.updated_on = randd_field_hash['修改日期'].to_time rescue issue.created_on + issue.due_date = randd_field_hash['截止日期'].to_time rescue nil issue.project_id = 0 issue.pm_project_id = args.pm_project_id issue.pm_issue_type = 3 issue.save! + requirement_issue = Issue.find_by(project_issues_index: randd_field_hash['相关需求'].split('(#')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 1) rescue nil + if requirement_issue.present? + requirement_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end + task_issue = Issue.find_by(project_issues_index: randd_field_hash['相关任务'].split('(')[1].split(')')[0], pm_project_id: pm_project_id, pm_issue_type: 2) rescue nil + if task_issue.present? + task_issue.pm_links.find_or_create_by(be_linkable_type: 'Issue', be_linkable_id: issue.id) + end end end @@ -53,6 +71,7 @@ namespace :import_from_chandao do if assigner.present? issue.assigners << assigner end + issue.project_issues_index = randd_field_hash['编号'].to_i issue.status_id = trans_status(randd_field_hash['任务状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i @@ -77,6 +96,14 @@ namespace :import_from_chandao do # 执行示例 bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" # RAILS_ENV=production bundle exec rake "import_from_chandao:requirements[企业网站第二期.csv, 3]" task :requirements, [:name, :pm_project_id] => :environment do |t, args| + def trans_status(str) + h={ + "草稿" => 1, + "激活" => 1, + "已关闭" => 5 + } + h[str] + end name = args.name pm_project_id = args.pm_project_id CSV.foreach("#{Rails.root}/#{name}", headers: true) do | row | @@ -89,7 +116,7 @@ namespace :import_from_chandao do issue.assigners << assigner end issue.project_issues_index = randd_field_hash['编号'].to_i - issue.status_id = IssueStatus.first.id + issue.status_id = trans_status(randd_field_hash['当前状态']) || IssueStatus.first.id issue.tracker_id = Tracker.first.id issue.priority_id = randd_field_hash['优先级'].to_i issue.subject = randd_field_hash['需求名称']