作者 yangfu

部门统计排序

... ... @@ -72,13 +72,39 @@ type DepartmentStatisticsRequest struct {
Type int `json:"type"` //1:已审核 2:待审核
}
type DepartmentStatisticsResponse struct {
Total int `json:"total"`
List []*DepartmentStatistics `json:"departmentStatistics"`
}
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 {
return true
}
if this.List[i].ChanceApprovedTotal > this.List[j].ChanceApprovedTotal {
return true
}
if this.List[i].AchievementTotal > this.List[j].AchievementTotal {
return true
}
//待审核
if this.List[i].ChanceApprovingTotal > this.List[j].ChanceApprovingTotal {
return true
}
return false
}
func (this *DepartmentStatisticsResponse) Swap(i, j int) {
this.List[i], this.List[j] = this.List[j], this.List[i]
}
//部门统计项
type DepartmentStatistics struct {
Dep Dep `json:"dep"` //部门
ChanceApprovedTotal int `json:"chanceApprovedTotal"` //已审核的机会
ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会
AchievementTotal int `json:"achievementTotal"` //已创建的成果 (显示)
ACTotal int `json:"-"` //机会成果总数 (显示)
}
... ...
... ... @@ -7,6 +7,7 @@ import (
"opp/models"
"opp/protocol"
"opp/services/agg"
"sort"
)
func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRequest) (rsp *protocol.DepartmentsResponse, err error) {
... ... @@ -93,6 +94,11 @@ func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.Depa
Name: department.Name,
}
rsp.List = append(rsp.List, item)
if request.Type == protocol.StatisticApproved {
rsp.Total += item.ChanceApprovedTotal + item.AchievementTotal
} else {
rsp.Total += item.ChanceApprovingTotal
}
}
}
switch request.Type {
... ... @@ -102,6 +108,7 @@ func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.Depa
dIds := departmentsResponse.GetChildDepartmentIds(d, true)
rsp.AchievementTotal, _ = agg.AchievementDepartmentStatic(header, 0, dIds)
rsp.ChanceApprovedTotal, _ = agg.GetChancePool(header.UserId, header.CompanyId, 0, d.DepartmentId, 0, 0, nil)
rsp.ACTotal = rsp.AchievementTotal + rsp.ChanceApprovedTotal
return rsp
})
break
... ... @@ -116,5 +123,6 @@ func DepartmentStatistics(header *protocol.RequestHeader, request *protocol.Depa
err = protocol.NewErrWithMessage(2)
return
}
sort.Sort(rsp)
return
}
... ...
... ... @@ -2,6 +2,7 @@ package department
import (
"opp/protocol"
"sort"
"testing"
)
... ... @@ -28,3 +29,25 @@ func TestGetRootDepartment(t *testing.T) {
t.Log("部门:", d.DepartmentId, deps.GetChildDepartmentIds(d, true))
}
}
//排序
func TestSortDepartmentStastics(t *testing.T) {
s := &protocol.DepartmentStatisticsResponse{
//List:[]*protocol.DepartmentStatistics{
// {ChanceApprovedTotal:10,AchievementTotal:10,ACTotal:20},
// {ChanceApprovedTotal:10,AchievementTotal:10,ACTotal:20},
// {ChanceApprovedTotal:20,AchievementTotal:10,ACTotal:30},
// {ChanceApprovedTotal:5,AchievementTotal:10,ACTotal:15},
//},
List: []*protocol.DepartmentStatistics{
{ChanceApprovingTotal: 10},
{ChanceApprovingTotal: 10},
{ChanceApprovingTotal: 30},
{ChanceApprovingTotal: 40},
{ChanceApprovingTotal: 60},
{ChanceApprovingTotal: 50},
},
}
sort.Sort(s)
//t.Log(common.AssertJson(s))
}
... ...