87 lines
2.4 KiB
Go
87 lines
2.4 KiB
Go
package biz
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
type Department struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Name string
|
|
ParentID uint
|
|
Ancestors string
|
|
Sort int
|
|
LeaderID uint
|
|
Leader *User
|
|
Status bool
|
|
Children []*Department
|
|
NamePath string
|
|
}
|
|
|
|
type DepartmentRepo interface {
|
|
CreateDepartment(context.Context, *Department) error
|
|
UpdateDepartment(context.Context, *Department) error
|
|
DeleteDepartment(context.Context, uint) error
|
|
FindDepartment(context.Context, uint) (*Department, error)
|
|
ListDepartments(context.Context, string) ([]*Department, error)
|
|
DepartmentUserIDs(context.Context, uint) ([]uint, error)
|
|
SetDepartmentUsers(context.Context, uint, []uint) error
|
|
SetUserDepartments(context.Context, uint, []uint, uint) error
|
|
}
|
|
|
|
type DepartmentUsecase struct{ DepartmentRepo }
|
|
|
|
func NewDepartmentUsecase(repo DepartmentRepo) *DepartmentUsecase {
|
|
return &DepartmentUsecase{DepartmentRepo: repo}
|
|
}
|
|
|
|
func (uc *DepartmentUsecase) Departments(ctx context.Context, name string) ([]*Department, error) {
|
|
return uc.ListDepartments(ctx, name)
|
|
}
|
|
func (uc *DepartmentUsecase) Department(ctx context.Context, id uint) (*Department, error) {
|
|
return uc.FindDepartment(ctx, id)
|
|
}
|
|
|
|
type Position struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Name string
|
|
Code string
|
|
Sort int
|
|
Status bool
|
|
Remark string
|
|
}
|
|
|
|
type PositionListFilter struct {
|
|
Name string
|
|
Code string
|
|
Status *bool
|
|
}
|
|
|
|
type PositionRepo interface {
|
|
CreatePosition(context.Context, *Position) error
|
|
UpdatePosition(context.Context, *Position) error
|
|
DeletePosition(context.Context, uint) error
|
|
FindPosition(context.Context, uint) (*Position, error)
|
|
ListPositions(context.Context, int, int, *PositionListFilter) ([]*Position, int64, error)
|
|
PositionUserIDs(context.Context, uint) ([]uint, error)
|
|
SetPositionUsers(context.Context, uint, []uint) error
|
|
SetUserPositions(context.Context, uint, []uint) error
|
|
}
|
|
|
|
type PositionUsecase struct{ PositionRepo }
|
|
|
|
func NewPositionUsecase(repo PositionRepo) *PositionUsecase {
|
|
return &PositionUsecase{PositionRepo: repo}
|
|
}
|
|
|
|
func (uc *PositionUsecase) Positions(ctx context.Context, page, size int, filter *PositionListFilter) ([]*Position, int64, error) {
|
|
return uc.ListPositions(ctx, page, size, filter)
|
|
}
|
|
func (uc *PositionUsecase) Position(ctx context.Context, id uint) (*Position, error) {
|
|
return uc.FindPosition(ctx, id)
|
|
}
|