add project statistics and project polyline

This commit is contained in:
呱呱呱 2024-01-25 14:04:36 +08:00
parent 27b81a5479
commit 406da81ccf
2 changed files with 56 additions and 0 deletions

View File

@ -8,6 +8,60 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController
render 'api/v1/issues/index' render 'api/v1/issues/index'
end end
def project_statistics
return tip_exception '参数错误' if params[:pm_project_id].blank?
@issues = Issue.where(pm_project_id: params[:pm_project_id])
type_count_data = @issues.group(:pm_issue_type).count
type_status = @issues.group(:pm_issue_type,:status_id).count
type_status_data = {}
IssueStatus.all.map do |e|
type_count_data.keys.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
else
type_status_data[type][e.id] = type_status[[type,e.id]]
end
}
end
data = {
pie_chart: type_count_data,
bar_chart: type_status_data
}
render_ok(data: data)
end
def project_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_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 = {
create_issues: {},
due_issues: {}
}
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
}
end
render_ok(data: data)
end
def burndown_charts 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]) @issues = Issue.where(pm_sprint_id: params[:pm_sprint_id])

View File

@ -25,6 +25,8 @@ defaults format: :json do
resources :sprint_issues, only: [:index] do resources :sprint_issues, only: [:index] do
collection do collection do
get :statistics get :statistics
get :project_statistics
get :project_polyline
get :burndown_charts get :burndown_charts
post :complete post :complete
end end