org.go
3.7 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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
package domain
import (
"fmt"
"time"
)
const (
DefaultOrgCodeCompany = "ENTERPRISE01" //默认的低级组织标识
)
const (
IsOrgFlag = 1 // 标记为组织
IsNotOrgFlag = 2 // 标记为非组织
)
const (
OrgStatusEnable = 1
OrgStatusDisable = 2
)
// 组织 organization
type Org struct {
// 组织ID
OrgId int64 `json:"orgId,omitempty"`
// 企业id
CompanyId int64 `json:"companyId,omitempty"`
// 创建时间
CreatedAt time.Time `json:"createdAt,omitempty"`
// 更新时间
UpdatedAt time.Time `json:"updatedAt,omitempty"`
// 删除时间
DeletedAt time.Time `json:"deletedAt,omitempty"`
// 组织编码
OrgCode string `json:"orgCode,omitempty"`
// 组织名称
OrgName string `json:"orgName,omitempty"`
// 扩展数据
Ext *Ext `json:"ext,omitempty"`
// 是否是组织标识 1:是 2:不是
IsOrg int `json:"isOrg,omitempty"`
// 组织状态 1:启用 2:禁用 3.删除
OrgStatus int `json:"orgStatus,omitempty"`
// 父级ID
ParentId int64 `json:"parentId,omitempty"`
// 父级节点路径("0,11,12,")
ParentPath string `json:"parentPath,omitempty"`
}
type OrgRepository interface {
Save(org *Org) (*Org, error)
Remove(org *Org) (*Org, error)
FindOne(queryOptions map[string]interface{}) (*Org, error)
Find(queryOptions map[string]interface{}) (int64, []*Org, error)
}
func (org *Org) Identify() interface{} {
if org.OrgId == 0 {
return nil
}
return org.OrgId
}
func (org *Org) Update(data map[string]interface{}) error {
if createdAt, ok := data["createdAt"]; ok {
org.CreatedAt = createdAt.(time.Time)
}
if updatedAt, ok := data["updatedAt"]; ok {
org.UpdatedAt = updatedAt.(time.Time)
}
if deletedAt, ok := data["deletedAt"]; ok {
org.DeletedAt = deletedAt.(time.Time)
}
if orgCode, ok := data["orgCode"]; ok {
org.OrgCode = orgCode.(string)
}
if orgName, ok := data["orgName"]; ok {
org.OrgName = orgName.(string)
}
if userName, ok := data["userName"]; ok {
org.Ext.UserName = userName.(string)
}
if orgName, ok := data["orgName"]; ok {
org.Ext.OrgName = orgName.(string)
}
if phone, ok := data["phone"]; ok {
org.Ext.Phone = phone.(string)
}
if depName, ok := data["depName"]; ok {
org.Ext.DepName = depName.(string)
}
if parentDepName, ok := data["parentDepName"]; ok {
org.Ext.ParentDepName = parentDepName.(string)
}
if isOrg, ok := data["isOrg"]; ok {
org.IsOrg = isOrg.(int)
}
if parentId, ok := data["parentId"]; ok {
org.ParentId = parentId.(int64)
}
if parentPath, ok := data["parentPath"]; ok {
org.ParentPath = parentPath.(string)
}
return nil
}
// 部门
type Department struct {
// 部门ID
DepartmentId int64 `json:"departmentId"`
// 部门名称
DepartmentName string `json:"departmentName"`
// 部门编号
DepartmentNumber string `json:"departmentNumber"`
}
// 通过组织获取当前部门信息
func (org *Org) ConvDep() *Department {
return &Department{
DepartmentId: org.OrgId,
DepartmentName: org.OrgName,
DepartmentNumber: org.OrgCode,
}
}
func (org *Org) CloneSample() *Org {
return &Org{
OrgId: org.OrgId,
OrgName: org.OrgName,
}
}
/***** 1.实现树 *****/
/*1.1 实现树的方法*/
// GetParentPath 获取菜单路径
func (org *Org) GetParentPath() string {
if org.ParentId == 0 {
return ""
}
if len(org.ParentPath) > 0 {
return fmt.Sprintf("%v%v%v", org.ParentPath, PathSegment, org.OrgId)
}
return fmt.Sprintf("%v", org.OrgId)
}
// GetFullPath 获取菜单全路径
func (org *Org) GetFullPath() string {
if org.ParentId == 0 {
return ""
}
if len(org.ParentPath) > 0 {
return fmt.Sprintf("%v%v%v", org.ParentPath, PathSegment, org.OrgId)
}
return fmt.Sprintf("%v", org.OrgId)
}
func (org *Org) PID() string {
return org.ParentPath
}
func (org *Org) ID() string {
return org.GetFullPath()
}