From 3505d29410f54b6423cb68c51030f956cd9ea0fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 10:56:46 +0800 Subject: [PATCH 01/12] fix --- app/controllers/api/pm/projects_controller.rb | 31 ++++++++-------- .../api/pm/sprint_issues_controller.rb | 37 ++++++++++--------- 2 files changed, 35 insertions(+), 33 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 83e2ecdb4..e80d3a692 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -55,10 +55,8 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController def polyline return tip_exception '参数错误' if params[:pm_project_id].blank? time_line = (Time.current.beginning_of_day - 6.day) .. Time.current - # @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) - # @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) - @create_issues = Issue.where(pm_project_id: 135,created_on: time_line) - @due_issues = Issue.where(pm_project_id: 135,due_date: time_line) + @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) + @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count data = { @@ -67,17 +65,20 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController } 7.times do |time| current_time = Date.current - time.day - data[:create_issues][current_time] = { - "1": @create_issues_count[[1,current_time]] || 0, - "2": @create_issues_count[[2,current_time]] || 0, - "3": @create_issues_count[[3,current_time]] || 0 - } - - data[:due_issues][current_time] = { - "1": @due_issues_count[[1,current_time]] || 0, - "2": @due_issues_count[[2,current_time]] || 0, - "3": @due_issues_count[[3,current_time]] || 0 - } + if @create_issues_count.present? + data[:create_issues][current_time] = { + "1": @create_issues_count[[1,current_time]] || 0, + "2": @create_issues_count[[2,current_time]] || 0, + "3": @create_issues_count[[3,current_time]] || 0 + } + end + if @due_issues_count.present? + data[:due_issues][current_time] = { + "1": @due_issues_count[[1,current_time]] || 0, + "2": @due_issues_count[[2,current_time]] || 0, + "3": @due_issues_count[[3,current_time]] || 0 + } + end end render_ok(data: data) end diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index e0d4c50e6..fa66d53de 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -2,29 +2,27 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController before_action :require_login, except: [:index] - def index + def index @issues = Api::Pm::SprintIssues::ListService.call(query_params, current_user) @issues = kaminari_paginate(@issues) render 'api/v1/issues/index' end - - def burndown_charts - return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank? + return tip_exception '参数错误' if params[:pm_sprint_id].blank? || params[:start_time].blank? || params[:end_time].blank? @issues = Issue.where(pm_sprint_id: params[:pm_sprint_id]) start_time = Date.parse params[:start_time] end_time = Date.parse params[:end_time] - time_count = (end_time - start_time).to_i + 1 #计算间隔时间 加上最后一天 + time_count = (end_time - start_time).to_i + 1 # 计算间隔时间 加上最后一天 data = [] - curren_issues = @issues.group(:status_id,:due_date).count + curren_issues = @issues.group(:status_id, :due_date).count total_count = @issues.count cardinality = BigDecimal.new(total_count) / BigDecimal.new(time_count) time_count.times do |x| e_time = start_time + x - completed = curren_issues[[5,e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size + completed = curren_issues[[5, e_time]].to_i + curren_issues[[3, e_time]].to_i - @issues.where(pm_issue_type: 3, status_id: 3).size total_count = total_count - completed - data << {time: e_time, undone: total_count, completed:completed, base_number: (cardinality * (time_count - x - 1)).to_f.round(2)} + data << { time: e_time, undone: total_count, completed: completed, base_number: (cardinality * (time_count - x - 1)).to_f.round(2) } end render_ok(data: data) end @@ -41,11 +39,12 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) @issues_hour_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).sum(:time_scale) + @issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).sum(:time_scale) pm_sprint_ids.map(&:to_i).map do |sprint_id| # count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量 count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size # hour_closed 已完成/已关闭 预估工时之和,需排除已修复的缺陷预估工时 - hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f + hour_closed = @issues_hour_type_count[[sprint_id, 5]].to_f + @issues_hour_type_count[[sprint_id, 3]].to_f - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).sum(:time_scale).to_f data[sprint_id] = { count_total: @issues_count[sprint_id] || 0, count_closed: count_closed || 0, @@ -56,8 +55,10 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController bug: @issues_pm_type_count[[sprint_id, 3]] || 0, requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]] || 0, task_hour: @issues_hour_pm_type_count[[sprint_id, 2]] || 0, - bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0 - + bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0, + requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]] + @issues_status_pm_type_count[[sprint_id, 1, 2]]) || 0, + task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]] + @issues_status_pm_type_count[[sprint_id, 2, 2]] || 0, + bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]] + @issues_status_pm_type_count[[sprint_id, 3, 2]] || 0 } end render_ok(data: data) @@ -65,10 +66,10 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController before_action :load_uncomplete_issues, only: [:complete] - def complete + def complete begin - case complete_params[:complete_type].to_i - when 1 + case complete_params[:complete_type].to_i + when 1 @issues.update_all(status_id: 5) when 2 @issues.update_all(pm_sprint_id: 0) @@ -87,16 +88,16 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues = Issue.where(pm_sprint_id: complete_params[:pm_project_sprint_id]).where.not(status_id: 5) end - def complete_params + def complete_params params.permit(:pm_project_sprint_id, :complete_type, :target_pm_project_sprint_id) end - + def query_params params.permit( :category, :pm_project_id, - :pm_issue_type, #需求1 任务2 缺陷3 - :assigner_id, + :pm_issue_type, # 需求1 任务2 缺陷3 + :assigner_id, :priority_id, :status_id, :keyword, :status_ids, :pm_issue_types, From 3094c81d2cec0ea13618d5a56cf2a60848dcc793 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 11:07:01 +0800 Subject: [PATCH 02/12] fix bug --- app/controllers/api/pm/sprint_issues_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index fa66d53de..436327c80 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -56,9 +56,9 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController requirement_hour: @issues_hour_pm_type_count[[sprint_id, 1]] || 0, task_hour: @issues_hour_pm_type_count[[sprint_id, 2]] || 0, bug_hour: @issues_hour_pm_type_count[[sprint_id, 3]] || 0, - requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]] + @issues_status_pm_type_count[[sprint_id, 1, 2]]) || 0, - task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]] + @issues_status_pm_type_count[[sprint_id, 2, 2]] || 0, - bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]] + @issues_status_pm_type_count[[sprint_id, 3, 2]] || 0 + requirement_open: (@issues_status_pm_type_count[[sprint_id, 1, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 1, 2]].to_i) || 0, + task_open: @issues_status_pm_type_count[[sprint_id, 2, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 2, 2]].to_i || 0, + bug_open: @issues_status_pm_type_count[[sprint_id, 3, 1]].to_i + @issues_status_pm_type_count[[sprint_id, 3, 2]].to_i || 0 } end render_ok(data: data) From f39b83692bfb6ec20cc8b0b65f1b4c30d490a781 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 11:16:06 +0800 Subject: [PATCH 03/12] update --- app/controllers/api/pm/sprint_issues_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/sprint_issues_controller.rb b/app/controllers/api/pm/sprint_issues_controller.rb index 436327c80..0d3c7f31b 100644 --- a/app/controllers/api/pm/sprint_issues_controller.rb +++ b/app/controllers/api/pm/sprint_issues_controller.rb @@ -39,7 +39,7 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController @issues_hour_count = @issues.group(:pm_sprint_id).sum(:time_scale) @issues_hour_type_count = @issues.group(:pm_sprint_id, :status_id).sum(:time_scale) @issues_hour_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).sum(:time_scale) - @issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).sum(:time_scale) + @issues_status_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type, :status_id).count pm_sprint_ids.map(&:to_i).map do |sprint_id| # count_closed 工作项已完成/已关闭数量,需排除已修复的缺陷数量 count_closed = @issues_type_count[[sprint_id, 5]].to_i + @issues_type_count[[sprint_id, 3]].to_i - @issues.where(pm_sprint_id: sprint_id, pm_issue_type: 3, status_id: 3).size From 53083d30305f92dd1d737024832f0f7a8e1eb836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 11:40:56 +0800 Subject: [PATCH 04/12] add open data for pm project statistics --- app/controllers/api/pm/projects_controller.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index e80d3a692..d71a945ea 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -45,9 +45,15 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController end } end + open_data = { + "1": type_status_data[1][1] + type_status_data[1][2], + "2": type_status_data[2][1] + type_status_data[2][2], + "3": type_status_data[3][1] + type_status_data[3][2], + } data = { pie_chart: type_count_data, - bar_chart: type_status_data + bar_chart: type_status_data, + open_data: open_data } render_ok(data: data) end From 7d8e0d018e05e417debbde973f6dfd9f2970fd86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 14:03:34 +0800 Subject: [PATCH 05/12] add default for project polyline --- app/controllers/api/pm/projects_controller.rb | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index d71a945ea..89732e79e 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -77,6 +77,12 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController "2": @create_issues_count[[2,current_time]] || 0, "3": @create_issues_count[[3,current_time]] || 0 } + else + data[:create_issues][current_time] = { + "1": 0, + "2": 0, + "3": 0 + } end if @due_issues_count.present? data[:due_issues][current_time] = { @@ -84,6 +90,12 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController "2": @due_issues_count[[2,current_time]] || 0, "3": @due_issues_count[[3,current_time]] || 0 } + else + data[:due_issues][current_time] = { + "1": 0, + "2": 0, + "3": 0 + } end end render_ok(data: data) From 95387671678cebc94fd82c13350eac0eb6427215 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 14:20:16 +0800 Subject: [PATCH 06/12] update pm project statistics --- app/controllers/api/pm/projects_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index 89732e79e..f2e31bbbe 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -46,9 +46,9 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController } end open_data = { - "1": type_status_data[1][1] + type_status_data[1][2], - "2": type_status_data[2][1] + type_status_data[2][2], - "3": type_status_data[3][1] + type_status_data[3][2], + "1": type_status_data[1][1].to_i + type_status_data[1][2].to_i, + "2": type_status_data[2][1].to_i + type_status_data[2][2].to_i, + "3": type_status_data[3][1].to_i + type_status_data[3][2].to_i, } data = { pie_chart: type_count_data, From a5a22f6889b04f4c3680a39ea45525775e04b178 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 14:29:37 +0800 Subject: [PATCH 07/12] add default pm project statistics --- app/controllers/api/pm/projects_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index f2e31bbbe..d1dd3ac8f 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -36,7 +36,7 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController type_status = @issues.group(:pm_issue_type,:status_id).count type_status_data = {} IssueStatus.all.map do |e| - type_count_data.keys.map{ |type| + [1,2,3].map{ |type| type_status_data[type] = {} if type_status_data[type].nil? if type_status[[type,e.id]].nil? type_status_data[type][e.id] = 0 From b456bf99ca1c6e3032f8bba5835f5b751e1d06fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Tue, 30 Jan 2024 17:10:32 +0800 Subject: [PATCH 08/12] update plyline --- app/controllers/api/pm/projects_controller.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/controllers/api/pm/projects_controller.rb b/app/controllers/api/pm/projects_controller.rb index d1dd3ac8f..3dfd2e9c0 100644 --- a/app/controllers/api/pm/projects_controller.rb +++ b/app/controllers/api/pm/projects_controller.rb @@ -62,7 +62,8 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController return tip_exception '参数错误' if params[:pm_project_id].blank? time_line = (Time.current.beginning_of_day - 6.day) .. Time.current @create_issues = Issue.where(pm_project_id: params[:pm_project_id],created_on: time_line) - @due_issues = Issue.where(pm_project_id: params[:pm_project_id],due_date: time_line) + @create_issues = Issue.where(pm_project_id: 179,created_on: time_line) + @due_issues = Issue.where(pm_project_id: params[:pm_project_id],status_id:[3,5],due_date: time_line) @create_issues_count = @create_issues.group(:pm_issue_type,"DATE(created_on)").count @due_issues_count = @due_issues.group(:pm_issue_type,"DATE(due_date)").count data = { From 9b9374c99bb1ba1cc0ac8dce83a975e7ccb4fbb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 08:43:10 +0800 Subject: [PATCH 09/12] add due_date to pm issue batch params --- 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 6cd37ce18..06ada1e9a 100644 --- a/app/controllers/api/pm/issues_controller.rb +++ b/app/controllers/api/pm/issues_controller.rb @@ -182,7 +182,7 @@ class Api::Pm::IssuesController < Api::Pm::BaseController def batch_issue_params params.permit( - :status_id, :priority_id, :milestone_id, :pm_sprint_id, :pm_issue_type, :root_id, :target_pm_project_id, :project_id, + :status_id, :priority_id, :milestone_id, :pm_sprint_id, :due_date, :pm_issue_type, :root_id, :target_pm_project_id, :project_id, :issue_tag_ids => [], :assigner_ids => [] ) end From 65d23879313dc9311c9826d34258d1b204cd33e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 09:08:38 +0800 Subject: [PATCH 10/12] update --- app/models/issue.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/models/issue.rb b/app/models/issue.rb index b40efefa1..2c1a22d92 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -104,9 +104,16 @@ class Issue < ApplicationRecord scope :closed, ->{where(status_id: 5)} scope :opened, ->{where.not(status_id: 5)} after_create :incre_project_common, :incre_user_statistic, :incre_platform_statistic + before_save :check_pm_and_update_due_date after_save :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 + def check_pm_and_update_due_date + if pm_project_id.present? && status_id.changed? && status_id == 5 + self.due_date = self.due_date || Time.current + end + end + def incre_project_common CacheAsyncSetJob.perform_later('project_common_service', {issues: 1}, self.project_id) end From 9e90b2cef381827c86eb8e30602051e6b1b42910 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 09:19:20 +0800 Subject: [PATCH 11/12] update check_pm_and_update_due_date for issue --- app/models/issue.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index 2c1a22d92..ad1090d8e 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -109,8 +109,20 @@ class Issue < ApplicationRecord after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def check_pm_and_update_due_date - if pm_project_id.present? && status_id.changed? && status_id == 5 - self.due_date = self.due_date || Time.current + if pm_project_id.present? && pm_issue_type.present? && status_id_chenged? + status_ids = case pm_issue_type + when 1 + [3,5] + when 2 + [3,5] + when 3 + [5] + else + [] + end + if status_ids.include? self.status_id + self.due_date = self.due_date || Time.current + end end end From f3dd40515aaf6eb3d155060b50e838f8cdceb91c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=91=B1=E5=91=B1=E5=91=B1?= Date: Wed, 31 Jan 2024 10:21:31 +0800 Subject: [PATCH 12/12] fix bug check_pm_and_update_due_date --- app/models/issue.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/issue.rb b/app/models/issue.rb index ad1090d8e..028ceb930 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -109,7 +109,7 @@ class Issue < ApplicationRecord after_destroy :update_closed_issues_count_in_project!, :decre_project_common, :decre_user_statistic, :decre_platform_statistic def check_pm_and_update_due_date - if pm_project_id.present? && pm_issue_type.present? && status_id_chenged? + if pm_project_id.present? && pm_issue_type.present? && status_id_changed? status_ids = case pm_issue_type when 1 [3,5]