sys_department.go
2.3 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
package domain
import (
"context"
"github.com/samber/lo"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/transaction"
"gitlab.fjmaimaimai.com/allied-creation/su-micro/pkg/xcollection"
)
type SysDepartment struct {
Id int64 `json:",omitempty"` // 唯一标识
CompanyId int64 `json:",omitempty"` // 公司表ID
Name string `json:",omitempty"` // 名称
Code string `json:",omitempty"` // 部门编码
ParentId int64 `json:",omitempty"` // 父级部门ID
DepartmentHeads []int64 `json:",omitempty"` // 部门负责人 (职员ID)
IsRoot bool `json:",omitempty"` // 是否是根部门(公司级部门)
Sort int `json:",omitempty"` // 排序
CreatedAt int64 `json:",omitempty"`
UpdatedAt int64 `json:",omitempty"`
DeletedAt int64 `json:",omitempty"`
Version int `json:",omitempty"`
NumberPeople int `json:"-"` // 人数
}
type SysDepartmentRepository interface {
Insert(ctx context.Context, conn transaction.Conn, dm *SysDepartment) (*SysDepartment, error)
Update(ctx context.Context, conn transaction.Conn, dm *SysDepartment) (*SysDepartment, error)
UpdateWithVersion(ctx context.Context, conn transaction.Conn, dm *SysDepartment) (*SysDepartment, error)
Delete(ctx context.Context, conn transaction.Conn, dm *SysDepartment) (*SysDepartment, error)
FindOne(ctx context.Context, conn transaction.Conn, id int64) (*SysDepartment, error)
FindRootDepartmentByCompany(ctx context.Context, conn transaction.Conn, companyId int64) (*SysDepartment, error)
FindChildDepartment(ctx context.Context, conn transaction.Conn, companyId int64, departmentId int64, queryOptions map[string]interface{}) (int64, []*SysDepartment, error)
FindOneUnscoped(ctx context.Context, conn transaction.Conn, id int64) (*SysDepartment, error)
Find(ctx context.Context, conn transaction.Conn, companyId int64, queryOptions map[string]interface{}) (int64, []*SysDepartment, error)
}
func (department *SysDepartment) ID() int64 {
return department.Id
}
func (department *SysDepartment) PID() int64 {
return department.ParentId
}
func NewTreeNodes(departments []*SysDepartment) []xcollection.TreeNode {
nodes := make([]xcollection.TreeNode, 0)
lo.ForEach(departments, func(item *SysDepartment, index int) {
nodes = append(nodes, item)
})
return nodes
}