department.go
4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package protocol
import (
"time"
)
const (
DepartmentUser = iota //用户所有部门
DepartmentAll //公司所有部门
DepartmentRoot //公司一级部门
)
const (
StatisticApproved = 0 //统计已审核
StatisticApproving = 0 //统计审核中
)
/*Departments */
type DepartmentsRequest struct {
//Type int `json:"type" valid:"Required"` //1:公司所有部门 2:用户所在部门
Type int `json:"type"` //0:用户所在部门 1:公司所有部门
}
type DepartmentsResponse struct {
Departments []*Department `json:"departments,omitempty"`
}
//获取一级部门列表
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{}
}
if this.Departments[0].PId != 0 {
return []*Department{}
}
return this.Departments[0].Departments
}
//获得部门底下子部门的编号列表(包含本身)
func (this DepartmentsResponse) GetChildDepartmentIds(d *Department, isContainSelf bool) []int {
idList := make([]int, 0)
if isContainSelf {
idList = append(idList, d.DepartmentId)
}
idList = append(idList, walkDeparment(d)...)
return idList
}
//遍历部门
func walkDeparment(d *Department) []int {
idList := make([]int, 0)
for i := range d.Departments {
d := d.Departments[i]
idList = append(idList, d.DepartmentId)
if len(d.Departments) > 0 {
idList = append(idList, walkDeparment(d)...)
}
}
return idList
}
type Department struct {
DepartmentId int `orm:"column(department_id)" json:"id"`
Name string `orm:"column(name)" json:"name"`
PId int `orm:"column(parent_id)" json:"-"`
ManagerString string `orm:"column(managers)" json:"-"`
Relation string `orm:"column(relation)" json:"-"`
CreateTime time.Time `orm:"column(create_time)" json:"-"`
Managers []int `json:"-"`
Departments []*Department `json:"departments,omitempty"`
}
/*DepartmentStatistics 部门统计*/
type DepartmentStatisticsRequest struct {
//DId int `json:"did"`//部门编号 //查询所有部门 查询特定部门
Type int `json:"type"` //0:已审核 0:待审核
}
type DepartmentStatisticsResponse struct {
Total int `json:"approvedTotal"`
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].ACTotal == this.List[j].ACTotal && this.List[i].ChanceApprovedTotal < this.List[j].ChanceApprovedTotal {
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 {
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) {
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:"-"` //机会成果总数 (显示)
}
/*DepartmentStatistic 单部门统计*/
type DepartmentStatisticRequest struct {
DepartmentId int64 `json:"departmentId"`
}
type DepartmentStatisticResponse struct {
DepartmentStatistic DepartmentStatistics `json:"departmentStatistic"`
}