gitlink-forgeplus/app/controllers/api/pm/sprint_issues_controller.rb

77 lines
2.3 KiB
Ruby

class Api::Pm::SprintIssuesController < Api::Pm::BaseController
before_action :require_login, except: [:index]
def index
@issues = Api::Pm::SprintIssues::ListService.call(query_params, current_user)
@issues = kaminari_paginate(@issues)
render 'api/v1/issues/index'
end
def statistics
pm_sprint_ids = params[:pm_sprint_ids].split(",") rescue []
return tip_exception '参数错误' if pm_sprint_ids.blank?
@issues = Issue.where(pm_sprint_id: pm_sprint_ids)
data = {}
# requirement 1 task 2 bug 3
@issues_count = @issues.group(:pm_sprint_id).count
@issues_type_count = @issues.group(:pm_sprint_id, :status_id).count
@issues_pm_type_count = @issues.group(:pm_sprint_id, :pm_issue_type).count
@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)
pm_sprint_ids.map(&:to_i).map do |sprint_id|
data[sprint_id] = {
count_total: @issues_count[sprint_id] || 0,
count_closed: @issues_type_count[[sprint_id, 5]] || 0,
hour_total: @issues_hour_count[sprint_id] || 0,
hour_closed: @issues_hour_type_count[[sprint_id, 5]] || 0,
requirement: @issues_pm_type_count[[sprint_id, 1]] || 0,
task: @issues_pm_type_count[[sprint_id, 2]] || 0,
bug: @issues_pm_type_count[[sprint_id, 3]] || 0
}
end
render_ok(data: data)
end
before_action :load_uncomplete_issues, only: [:complete]
def complete
begin
case complete_params[:complete_type].to_i
when 1
@issues.update_all(status_id: 5)
when 2
@issues.update_all(pm_sprint_id: 0)
when 3
@issues.update_all(pm_sprint_id: complete_params[:target_pm_project_sprint_id])
end
render_ok
rescue => e
render_error(e.message)
end
end
private
def load_uncomplete_issues
@issues = Issue.where(pm_sprint_id: complete_params[:pm_project_sprint_id]).where.not(status_id: 5)
end
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,
:priority_id,
:status_id,
:keyword,
:sort_by, :sort_direction
)
end
end