作者 yangfu

部门统计增加对公司部门的统计

@@ -25,7 +25,18 @@ type DepartmentsResponse struct { @@ -25,7 +25,18 @@ type DepartmentsResponse struct {
25 } 25 }
26 26
27 //获取一级部门列表 27 //获取一级部门列表
28 -func (this DepartmentsResponse) GetRootDepartment() []*Department { 28 +func (this DepartmentsResponse) GetCompanyDepartment() *Department {
  29 + if len(this.Departments) == 0 {
  30 + return &Department{}
  31 + }
  32 + if this.Departments[0].PId != 0 {
  33 + return &Department{}
  34 + }
  35 + return this.Departments[0]
  36 +}
  37 +
  38 +//获取一级部门列表
  39 +func (this DepartmentsResponse) GetRootDepartments() []*Department {
29 if len(this.Departments) == 0 { 40 if len(this.Departments) == 0 {
30 return []*Department{} 41 return []*Department{}
31 } 42 }
@@ -109,7 +120,7 @@ type DepartmentStatistics struct { @@ -109,7 +120,7 @@ type DepartmentStatistics struct {
109 ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会 120 ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会
110 AchievementTotal int `json:"achievementTotal"` //已创建的成果 (显示) 121 AchievementTotal int `json:"achievementTotal"` //已创建的成果 (显示)
111 122
112 - ACTotal int `json:"total"` //机会成果总数 (显示) 123 + ACTotal int `json:"-"` //机会成果总数 (显示)
113 } 124 }
114 125
115 /*DepartmentStatistic 单部门统计*/ 126 /*DepartmentStatistic 单部门统计*/
@@ -42,7 +42,7 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe @@ -42,7 +42,7 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
42 walkDepartment(tmpDepartment, item) 42 walkDepartment(tmpDepartment, item)
43 } 43 }
44 rsp.Departments = tmpDepartment.Departments 44 rsp.Departments = tmpDepartment.Departments
45 - rsp.Departments = rsp.GetRootDepartment() 45 + //rsp.Departments = rsp.GetRootDepartment()
46 default: 46 default:
47 break 47 break
48 } 48 }
@@ -82,7 +82,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat @@ -82,7 +82,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
82 log.Error(err) 82 log.Error(err)
83 return 83 return
84 } 84 }
85 - departments := departmentsResponse.GetRootDepartment() 85 + departments := departmentsResponse.GetRootDepartments()
86 iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) { 86 iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) {
87 for i := range departments { 87 for i := range departments {
88 department := departments[i] 88 department := departments[i]
@@ -126,6 +126,17 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat @@ -126,6 +126,17 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
126 } 126 }
127 sort.Stable(rsp) 127 sort.Stable(rsp)
128 sort.Stable(sort.Reverse(rsp)) 128 sort.Stable(sort.Reverse(rsp))
  129 +
  130 + companyDep := departmentsResponse.GetCompanyDepartment()
  131 + if companyDep.DepartmentId > 0 {
  132 + var companyDepStatistic *protocol.DepartmentStatisticResponse
  133 + if companyDepStatistic, err = DepartmentStatistic(header, &protocol.DepartmentStatisticRequest{DepartmentId: companyDep.DepartmentId}); err != nil {
  134 + log.Error(err)
  135 + return
  136 + }
  137 + rsp.List = append(rsp.List, &companyDepStatistic.DepartmentStatistic)
  138 + rsp.Total += companyDepStatistic.DepartmentStatistic.ChanceApprovedTotal + companyDepStatistic.DepartmentStatistic.AchievementTotal
  139 + }
129 return 140 return
130 } 141 }
131 142
@@ -24,7 +24,7 @@ func TestGetRootDepartment(t *testing.T) { @@ -24,7 +24,7 @@ func TestGetRootDepartment(t *testing.T) {
24 {DepartmentId: 0, Name: "0", Departments: Departments}, 24 {DepartmentId: 0, Name: "0", Departments: Departments},
25 }, 25 },
26 } 26 }
27 - depList := deps.GetRootDepartment() 27 + depList := deps.GetRootDepartments()
28 for i := range depList { 28 for i := range depList {
29 d := depList[i] 29 d := depList[i]
30 t.Log("部门:", d.DepartmentId, deps.GetChildDepartmentIds(d, true)) 30 t.Log("部门:", d.DepartmentId, deps.GetChildDepartmentIds(d, true))