105 lines
3.8 KiB
Go
105 lines
3.8 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
|
|
Status bool
|
|
Children []*Department
|
|
}
|
|
|
|
type Position struct {
|
|
ID uint
|
|
CreatedAt time.Time
|
|
UpdatedAt time.Time
|
|
Name string
|
|
Code string
|
|
Sort int
|
|
Status bool
|
|
Remark string
|
|
}
|
|
|
|
type OrganizationRepo 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
|
|
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, *Position) ([]*Position, int64, error)
|
|
PositionUserIDs(context.Context, uint) ([]uint, error)
|
|
SetPositionUsers(context.Context, uint, []uint) error
|
|
SetUserPositions(context.Context, uint, []uint) error
|
|
}
|
|
|
|
type OrganizationUsecase struct{ repo OrganizationRepo }
|
|
|
|
func NewOrganizationUsecase(repo OrganizationRepo) *OrganizationUsecase {
|
|
return &OrganizationUsecase{repo: repo}
|
|
}
|
|
|
|
func (uc *OrganizationUsecase) Departments(ctx context.Context, name string) ([]*Department, error) {
|
|
return uc.repo.ListDepartments(ctx, name)
|
|
}
|
|
func (uc *OrganizationUsecase) CreateDepartment(ctx context.Context, value *Department) error {
|
|
return uc.repo.CreateDepartment(ctx, value)
|
|
}
|
|
func (uc *OrganizationUsecase) UpdateDepartment(ctx context.Context, value *Department) error {
|
|
return uc.repo.UpdateDepartment(ctx, value)
|
|
}
|
|
func (uc *OrganizationUsecase) DeleteDepartment(ctx context.Context, id uint) error {
|
|
return uc.repo.DeleteDepartment(ctx, id)
|
|
}
|
|
func (uc *OrganizationUsecase) Department(ctx context.Context, id uint) (*Department, error) {
|
|
return uc.repo.FindDepartment(ctx, id)
|
|
}
|
|
func (uc *OrganizationUsecase) DepartmentUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
|
return uc.repo.DepartmentUserIDs(ctx, id)
|
|
}
|
|
func (uc *OrganizationUsecase) SetDepartmentUsers(ctx context.Context, id uint, ids []uint) error {
|
|
return uc.repo.SetDepartmentUsers(ctx, id, ids)
|
|
}
|
|
func (uc *OrganizationUsecase) SetUserDepartments(ctx context.Context, id uint, ids []uint, primary uint) error {
|
|
return uc.repo.SetUserDepartments(ctx, id, ids, primary)
|
|
}
|
|
func (uc *OrganizationUsecase) Positions(ctx context.Context, page, size int, filter *Position) ([]*Position, int64, error) {
|
|
return uc.repo.ListPositions(ctx, page, size, filter)
|
|
}
|
|
func (uc *OrganizationUsecase) CreatePosition(ctx context.Context, value *Position) error {
|
|
return uc.repo.CreatePosition(ctx, value)
|
|
}
|
|
func (uc *OrganizationUsecase) UpdatePosition(ctx context.Context, value *Position) error {
|
|
return uc.repo.UpdatePosition(ctx, value)
|
|
}
|
|
func (uc *OrganizationUsecase) DeletePosition(ctx context.Context, id uint) error {
|
|
return uc.repo.DeletePosition(ctx, id)
|
|
}
|
|
func (uc *OrganizationUsecase) Position(ctx context.Context, id uint) (*Position, error) {
|
|
return uc.repo.FindPosition(ctx, id)
|
|
}
|
|
func (uc *OrganizationUsecase) PositionUserIDs(ctx context.Context, id uint) ([]uint, error) {
|
|
return uc.repo.PositionUserIDs(ctx, id)
|
|
}
|
|
func (uc *OrganizationUsecase) SetPositionUsers(ctx context.Context, id uint, ids []uint) error {
|
|
return uc.repo.SetPositionUsers(ctx, id, ids)
|
|
}
|
|
func (uc *OrganizationUsecase) SetUserPositions(ctx context.Context, id uint, ids []uint) error {
|
|
return uc.repo.SetUserPositions(ctx, id, ids)
|
|
}
|