department.go
2.5 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
package protocol
import (
"time"
)
const (
DepartmentUser = iota //用户所有部门
DepartmentAll //公司所有部门
DepartmentRoot //公司一级部门
)
const (
StatisticApproved = 1 //统计已审核
StatisticApproving = 2 //统计审核中
)
/*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) GetRootDepartment() []*Department {
if len(this.Departments) == 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"` //1:已审核 2:待审核
}
type DepartmentStatisticsResponse struct {
List []*DepartmentStatistics `json:"departmentStatistics"`
}
//部门统计项
type DepartmentStatistics struct {
Dep Dep `json:"dep"` //部门
ChanceApprovedTotal int `json:"chanceApprovedTotal"` //已审核的机会
ChanceApprovingTotal int `json:"chanceApprovingTotal"` //待审核的机会
AchievementTotal int `json:"achievementTotal"` //已创建的成果 (显示)
}