作者 yangfu

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

@@ -96,10 +96,10 @@ func (this *DepartmentStatisticsResponse) Less(i, j int) bool { @@ -96,10 +96,10 @@ func (this *DepartmentStatisticsResponse) Less(i, j int) bool {
96 if this.List[i].ACTotal < this.List[j].ACTotal { 96 if this.List[i].ACTotal < this.List[j].ACTotal {
97 return true 97 return true
98 } 98 }
99 - if this.List[i].ChanceApprovedTotal < this.List[j].ChanceApprovedTotal { 99 + if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal < this.List[j].ChanceApprovedTotal {
100 return true 100 return true
101 } 101 }
102 - if this.List[i].AchievementTotal < this.List[j].AchievementTotal { 102 + if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal == this.List[j].ChanceApprovedTotal && this.List[i].AchievementTotal < this.List[j].AchievementTotal {
103 return true 103 return true
104 } 104 }
105 if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal == this.List[j].ChanceApprovedTotal && this.List[i].AchievementTotal == this.List[j].AchievementTotal { 105 if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal == this.List[j].ChanceApprovedTotal && this.List[i].AchievementTotal == this.List[j].AchievementTotal {
@@ -82,6 +82,18 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat @@ -82,6 +82,18 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
82 log.Error(err) 82 log.Error(err)
83 return 83 return
84 } 84 }
  85 + //公司部门统计
  86 + companyDep := departmentsResponse.GetCompanyDepartment()
  87 + if companyDep.DepartmentId > 0 {
  88 + var companyDepStatistic *protocol.DepartmentStatisticResponse
  89 + if companyDepStatistic, err = DepartmentStatistic(header, &protocol.DepartmentStatisticRequest{DepartmentId: companyDep.DepartmentId}); err != nil {
  90 + log.Error(err)
  91 + return
  92 + }
  93 + rsp.List = append(rsp.List, &companyDepStatistic.DepartmentStatistic)
  94 + rsp.Total += companyDepStatistic.DepartmentStatistic.ChanceApprovedTotal + companyDepStatistic.DepartmentStatistic.AchievementTotal
  95 + }
  96 +
85 departments := departmentsResponse.GetRootDepartments() 97 departments := departmentsResponse.GetRootDepartments()
86 iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) { 98 iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) {
87 for i := range departments { 99 for i := range departments {
@@ -124,19 +136,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat @@ -124,19 +136,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
124 err = protocol.NewErrWithMessage(2) 136 err = protocol.NewErrWithMessage(2)
125 return 137 return
126 } 138 }
  139 +
127 sort.Stable(rsp) 140 sort.Stable(rsp)
128 sort.Stable(sort.Reverse(rsp)) 141 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 - }  
140 return 142 return
141 } 143 }
142 144
@@ -35,14 +35,16 @@ func TestGetRootDepartment(t *testing.T) { @@ -35,14 +35,16 @@ func TestGetRootDepartment(t *testing.T) {
35 func TestSortDepartmentStastics(t *testing.T) { 35 func TestSortDepartmentStastics(t *testing.T) {
36 s := &protocol.DepartmentStatisticsResponse{ 36 s := &protocol.DepartmentStatisticsResponse{
37 List: []*protocol.DepartmentStatistics{ 37 List: []*protocol.DepartmentStatistics{
38 - {ChanceApprovedTotal: 12, AchievementTotal: 8, ACTotal: 20},  
39 - {ChanceApprovedTotal: 8, AchievementTotal: 12, ACTotal: 20},  
40 - {ChanceApprovedTotal: 20, AchievementTotal: 20, ACTotal: 40},  
41 - {ChanceApprovedTotal: 5, AchievementTotal: 10, ACTotal: 15}, 38 + //{ChanceApprovedTotal: 12, AchievementTotal: 8, ACTotal: 20},
  39 + //{ChanceApprovedTotal: 8, AchievementTotal: 12, ACTotal: 20},
  40 + //{ChanceApprovedTotal: 20, AchievementTotal: 20, ACTotal: 40},
  41 + //{ChanceApprovedTotal: 5, AchievementTotal: 10, ACTotal: 15},
42 {Dep: protocol.Dep{Id: 3}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16}, 42 {Dep: protocol.Dep{Id: 3}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},
43 - {Dep: protocol.Dep{Id: 2}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},  
44 - {Dep: protocol.Dep{Id: 1}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},  
45 - {ChanceApprovedTotal: 20, AchievementTotal: 30, ACTotal: 50}, 43 + {Dep: protocol.Dep{Id: 2}, ChanceApprovedTotal: 7, AchievementTotal: 9, ACTotal: 16},
  44 + {Dep: protocol.Dep{Id: 1}, ChanceApprovedTotal: 7, AchievementTotal: 10, ACTotal: 17},
  45 + {Dep: protocol.Dep{Id: 0}, ChanceApprovedTotal: 10, AchievementTotal: 10, ACTotal: 20},
  46 + {Dep: protocol.Dep{Id: 4}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},
  47 + //{ChanceApprovedTotal: 20, AchievementTotal: 30, ACTotal: 50},
46 }, 48 },
47 //List: []*protocol.DepartmentStatistics{ 49 //List: []*protocol.DepartmentStatistics{
48 // {ChanceApprovingTotal: 10}, 50 // {ChanceApprovingTotal: 10},