作者 yangfu

部门统计修改

... ... @@ -82,20 +82,20 @@ type DepartmentStatisticsResponse struct {
func (this *DepartmentStatisticsResponse) Len() int { return len(this.List) }
func (this *DepartmentStatisticsResponse) Less(i, j int) bool {
//已审核 按照总数从大到小排序;若相同,按照已通过数量从大到小排序;若还相同,按照成果数量从大到小排序;*/
if this.List[i].ACTotal > this.List[j].ACTotal {
if this.List[i].ACTotal < this.List[j].ACTotal {
return true
}
if this.List[i].ChanceApprovedTotal > this.List[j].ChanceApprovedTotal {
if this.List[i].ChanceApprovedTotal < this.List[j].ChanceApprovedTotal {
return true
}
if this.List[i].AchievementTotal > this.List[j].AchievementTotal {
if this.List[i].AchievementTotal < this.List[j].AchievementTotal {
return true
}
//待审核
//if this.List[i].ChanceApprovingTotal > this.List[j].ChanceApprovingTotal {
// return true
//}
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 {
if this.List[i].Dep.Id > this.List[j].Dep.Id {
return true
}
}
return false
}
func (this *DepartmentStatisticsResponse) Swap(i, j int) {
... ...
... ... @@ -89,6 +89,7 @@ type Company struct {
type Dep struct {
Id int `json:"id"`
Name string `json:"name"`
Time int64 `json:"-"`
}
//岗位
... ...
... ... @@ -57,6 +57,7 @@ func walkDepartment(to *protocol.Department, dfrom *models.Department) (err erro
var newD *protocol.Department = &protocol.Department{
DepartmentId: dfrom.Id,
Name: dfrom.Name,
CreateTime: dfrom.CreateAt,
Departments: []*protocol.Department{},
}
if len(dfrom.Managers) > 0 {
... ... @@ -92,6 +93,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
item.Dep = protocol.Dep{
Id: department.DepartmentId,
Name: department.Name,
Time: department.CreateTime.Unix(),
}
rsp.List = append(rsp.List, item)
rsp.Total += item.ChanceApprovedTotal + item.AchievementTotal
... ... @@ -124,7 +126,8 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
err = protocol.NewErrWithMessage(2)
return
}
sort.Sort(rsp)
sort.Stable(rsp)
sort.Stable(sort.Reverse(rsp))
return
}
... ...
... ... @@ -35,10 +35,14 @@ func TestGetRootDepartment(t *testing.T) {
func TestSortDepartmentStastics(t *testing.T) {
s := &protocol.DepartmentStatisticsResponse{
List: []*protocol.DepartmentStatistics{
{ChanceApprovedTotal: 8, AchievementTotal: 12, ACTotal: 20},
{ChanceApprovedTotal: 12, AchievementTotal: 8, ACTotal: 20},
{ChanceApprovedTotal: 8, AchievementTotal: 12, ACTotal: 20},
{ChanceApprovedTotal: 20, AchievementTotal: 20, ACTotal: 40},
{ChanceApprovedTotal: 5, AchievementTotal: 10, ACTotal: 15},
{Dep: protocol.Dep{Id: 3}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},
{Dep: protocol.Dep{Id: 2}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},
{Dep: protocol.Dep{Id: 1}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},
{ChanceApprovedTotal: 20, AchievementTotal: 30, ACTotal: 50},
},
//List: []*protocol.DepartmentStatistics{
// {ChanceApprovingTotal: 10},
... ... @@ -49,6 +53,7 @@ func TestSortDepartmentStastics(t *testing.T) {
// {ChanceApprovingTotal: 50},
//},
}
sort.Sort(s)
sort.Stable(s)
sort.Stable(sort.Reverse(s))
t.Log(common.AssertJson(s))
}
... ...