| @@ -28,6 +28,60 @@ class Api::Pm::ProjectsController < Api::Pm::BaseController | |||||
| render_ok(data: data) | render_ok(data: data) | ||||
| end | end | ||||
| def 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 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 bind_project | def bind_project | ||||
| return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? | return render_forbidden('您没有操作权限!') unless @project.member?(current_user) || current_user.admin? | ||||
| Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id]) | Issue.where(pm_project_id: params[:pm_project_id], user_id: current_user).update_all(project_id: params[:project_id]) | ||||
| @@ -9,58 +9,6 @@ class Api::Pm::SprintIssuesController < Api::Pm::BaseController | |||||
| 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? | ||||
| @@ -25,8 +25,7 @@ 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 | ||||
| @@ -35,6 +34,8 @@ defaults format: :json do | |||||
| collection do | collection do | ||||
| get :convert | get :convert | ||||
| get :issues_count | get :issues_count | ||||
| get :statistics | |||||
| get :polyline | |||||
| end | end | ||||
| end | end | ||||
| end | end | ||||