作者 yangfu

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

... ... @@ -96,10 +96,10 @@ 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 {
if this.List[i].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal < this.List[j].ChanceApprovedTotal {
return true
}
if this.List[i].AchievementTotal < this.List[j].AchievementTotal {
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 {
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 {
... ...
... ... @@ -82,6 +82,18 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
log.Error(err)
return
}
//公司部门统计
companyDep := departmentsResponse.GetCompanyDepartment()
if companyDep.DepartmentId > 0 {
var companyDepStatistic *protocol.DepartmentStatisticResponse
if companyDepStatistic, err = DepartmentStatistic(header, &protocol.DepartmentStatisticRequest{DepartmentId: companyDep.DepartmentId}); err != nil {
log.Error(err)
return
}
rsp.List = append(rsp.List, &companyDepStatistic.DepartmentStatistic)
rsp.Total += companyDepStatistic.DepartmentStatistic.ChanceApprovedTotal + companyDepStatistic.DepartmentStatistic.AchievementTotal
}
departments := departmentsResponse.GetRootDepartments()
iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) {
for i := range departments {
... ... @@ -124,19 +136,9 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
err = protocol.NewErrWithMessage(2)
return
}
sort.Stable(rsp)
sort.Stable(sort.Reverse(rsp))
companyDep := departmentsResponse.GetCompanyDepartment()
if companyDep.DepartmentId > 0 {
var companyDepStatistic *protocol.DepartmentStatisticResponse
if companyDepStatistic, err = DepartmentStatistic(header, &protocol.DepartmentStatisticRequest{DepartmentId: companyDep.DepartmentId}); err != nil {
log.Error(err)
return
}
rsp.List = append(rsp.List, &companyDepStatistic.DepartmentStatistic)
rsp.Total += companyDepStatistic.DepartmentStatistic.ChanceApprovedTotal + companyDepStatistic.DepartmentStatistic.AchievementTotal
}
return
}
... ...
... ... @@ -35,14 +35,16 @@ func TestGetRootDepartment(t *testing.T) {
func TestSortDepartmentStastics(t *testing.T) {
s := &protocol.DepartmentStatisticsResponse{
List: []*protocol.DepartmentStatistics{
{ChanceApprovedTotal: 12, AchievementTotal: 8, ACTotal: 20},
{ChanceApprovedTotal: 8, AchievementTotal: 12, ACTotal: 20},
{ChanceApprovedTotal: 20, AchievementTotal: 20, ACTotal: 40},
{ChanceApprovedTotal: 5, AchievementTotal: 10, ACTotal: 15},
//{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},
{Dep: protocol.Dep{Id: 2}, ChanceApprovedTotal: 7, AchievementTotal: 9, ACTotal: 16},
{Dep: protocol.Dep{Id: 1}, ChanceApprovedTotal: 7, AchievementTotal: 10, ACTotal: 17},
{Dep: protocol.Dep{Id: 0}, ChanceApprovedTotal: 10, AchievementTotal: 10, ACTotal: 20},
{Dep: protocol.Dep{Id: 4}, ChanceApprovedTotal: 6, AchievementTotal: 10, ACTotal: 16},
//{ChanceApprovedTotal: 20, AchievementTotal: 30, ACTotal: 50},
},
//List: []*protocol.DepartmentStatistics{
// {ChanceApprovingTotal: 10},
... ...