作者 yangfu

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

... ... @@ -25,7 +25,18 @@ type DepartmentsResponse struct {
}
//获取一级部门列表
func (this DepartmentsResponse) GetRootDepartment() []*Department {
func (this DepartmentsResponse) GetCompanyDepartment() *Department {
if len(this.Departments) == 0 {
return &Department{}
}
if this.Departments[0].PId != 0 {
return &Department{}
}
return this.Departments[0]
}
//获取一级部门列表
func (this DepartmentsResponse) GetRootDepartments() []*Department {
if len(this.Departments) == 0 {
return []*Department{}
}
... ... @@ -109,7 +120,7 @@ type DepartmentStatistics struct {
ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会
AchievementTotal int `json:"achievementTotal"` //已创建的成果 (显示)
ACTotal int `json:"total"` //机会成果总数 (显示)
ACTotal int `json:"-"` //机会成果总数 (显示)
}
/*DepartmentStatistic 单部门统计*/
... ...
... ... @@ -42,7 +42,7 @@ func Departments(header *protocol.RequestHeader, request *protocol.DepartmentsRe
walkDepartment(tmpDepartment, item)
}
rsp.Departments = tmpDepartment.Departments
rsp.Departments = rsp.GetRootDepartment()
//rsp.Departments = rsp.GetRootDepartment()
default:
break
}
... ... @@ -82,7 +82,7 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
log.Error(err)
return
}
departments := departmentsResponse.GetRootDepartment()
departments := departmentsResponse.GetRootDepartments()
iterateDepartments := func(call func(d *protocol.Department) *protocol.DepartmentStatistics) {
for i := range departments {
department := departments[i]
... ... @@ -126,6 +126,17 @@ func Statistics(header *protocol.RequestHeader, request *protocol.DepartmentStat
}
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
}
... ...
... ... @@ -24,7 +24,7 @@ func TestGetRootDepartment(t *testing.T) {
{DepartmentId: 0, Name: "0", Departments: Departments},
},
}
depList := deps.GetRootDepartment()
depList := deps.GetRootDepartments()
for i := range depList {
d := depList[i]
t.Log("部门:", d.DepartmentId, deps.GetChildDepartmentIds(d, true))
... ...