作者 yangfu

部门统计修改

@@ -82,20 +82,20 @@ type DepartmentStatisticsResponse struct { @@ -82,20 +82,20 @@ type DepartmentStatisticsResponse struct {
82 func (this *DepartmentStatisticsResponse) Len() int { return len(this.List) } 82 func (this *DepartmentStatisticsResponse) Len() int { return len(this.List) }
83 func (this *DepartmentStatisticsResponse) Less(i, j int) bool { 83 func (this *DepartmentStatisticsResponse) Less(i, j int) bool {
84 //已审核 按照总数从大到小排序;若相同,按照已通过数量从大到小排序;若还相同,按照成果数量从大到小排序;*/ 84 //已审核 按照总数从大到小排序;若相同,按照已通过数量从大到小排序;若还相同,按照成果数量从大到小排序;*/
85 - if this.List[i].ACTotal > this.List[j].ACTotal { 85 + if this.List[i].ACTotal < this.List[j].ACTotal {
86 return true 86 return true
87 } 87 }
88 - if this.List[i].ChanceApprovedTotal > this.List[j].ChanceApprovedTotal { 88 + if this.List[i].ChanceApprovedTotal < this.List[j].ChanceApprovedTotal {
89 return true 89 return true
90 } 90 }
91 - if this.List[i].AchievementTotal > this.List[j].AchievementTotal { 91 + if this.List[i].AchievementTotal < this.List[j].AchievementTotal {
92 return true 92 return true
93 } 93 }
94 -  
95 - //待审核  
96 - //if this.List[i].ChanceApprovingTotal > this.List[j].ChanceApprovingTotal {  
97 - // return true  
98 - //} 94 + 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 {
  95 + if this.List[i].Dep.Id > this.List[j].Dep.Id {
  96 + return true
  97 + }
  98 + }
99 return false 99 return false
100 } 100 }
101 func (this *DepartmentStatisticsResponse) Swap(i, j int) { 101 func (this *DepartmentStatisticsResponse) Swap(i, j int) {
@@ -89,6 +89,7 @@ type Company struct { @@ -89,6 +89,7 @@ type Company struct {
89 type Dep struct { 89 type Dep struct {
90 Id int `json:"id"` 90 Id int `json:"id"`
91 Name string `json:"name"` 91 Name string `json:"name"`
  92 + Time int64 `json:"-"`
92 } 93 }
93 94
94 //岗位 95 //岗位
@@ -57,6 +57,7 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro @@ -57,6 +57,7 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro
57 var newD *protocol.Department = &protocol.Department{ 57 var newD *protocol.Department = &protocol.Department{
58 DepartmentId: dfrom.Id, 58 DepartmentId: dfrom.Id,
59 Name: dfrom.Name, 59 Name: dfrom.Name,
  60 + CreateTime: dfrom.CreateAt,
60 Departments: []*protocol.Department{}, 61 Departments: []*protocol.Department{},
61 } 62 }
62 if len(dfrom.Managers) > 0 { 63 if len(dfrom.Managers) > 0 {
@@ -92,6 +93,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat @@ -92,6 +93,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
92 item.Dep = protocol.Dep{ 93 item.Dep = protocol.Dep{
93 Id: department.DepartmentId, 94 Id: department.DepartmentId,
94 Name: department.Name, 95 Name: department.Name,
  96 + Time: department.CreateTime.Unix(),
95 } 97 }
96 rsp.List = append(rsp.List, item) 98 rsp.List = append(rsp.List, item)
97 rsp.Total += item.ChanceApprovedTotal + item.AchievementTotal 99 rsp.Total += item.ChanceApprovedTotal + item.AchievementTotal
@@ -124,7 +126,8 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat @@ -124,7 +126,8 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
124 err = protocol.NewErrWithMessage(2) 126 err = protocol.NewErrWithMessage(2)
125 return 127 return
126 } 128 }
127 - sort.Sort(rsp) 129 + sort.Stable(rsp)
  130 + sort.Stable(sort.Reverse(rsp))
128 return 131 return
129 } 132 }
130 133
@@ -35,10 +35,14 @@ func TestGetRootDepartment(t *testing.T) { @@ -35,10 +35,14 @@ 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: 8, AchievementTotal: 12, ACTotal: 20},  
39 {ChanceApprovedTotal: 12, AchievementTotal: 8, ACTotal: 20}, 38 {ChanceApprovedTotal: 12, AchievementTotal: 8, ACTotal: 20},
  39 + {ChanceApprovedTotal: 8, AchievementTotal: 12, ACTotal: 20},
40 {ChanceApprovedTotal: 20, AchievementTotal: 20, ACTotal: 40}, 40 {ChanceApprovedTotal: 20, AchievementTotal: 20, ACTotal: 40},
41 {ChanceApprovedTotal: 5, AchievementTotal: 10, ACTotal: 15}, 41 {ChanceApprovedTotal: 5, AchievementTotal: 10, ACTotal: 15},
  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},
42 }, 46 },
43 //List: []*protocol.DepartmentStatistics{ 47 //List: []*protocol.DepartmentStatistics{
44 // {ChanceApprovingTotal: 10}, 48 // {ChanceApprovingTotal: 10},
@@ -49,6 +53,7 @@ func TestSortDepartmentStastics(t *testing.T) { @@ -49,6 +53,7 @@ func TestSortDepartmentStastics(t *testing.T) {
49 // {ChanceApprovingTotal: 50}, 53 // {ChanceApprovingTotal: 50},
50 //}, 54 //},
51 } 55 }
52 - sort.Sort(s) 56 + sort.Stable(s)
  57 + sort.Stable(sort.Reverse(s))
53 t.Log(common.AssertJson(s)) 58 t.Log(common.AssertJson(s))
54 } 59 }