kra/internal/biz/system/params.go

74 lines
2.0 KiB
Go

package system
import (
"context"
"time"
)
// Params 系统参数实体
type Params struct {
ID uint
CreatedAt time.Time
UpdatedAt time.Time
Name string // 参数名
Key string // 参数键
Value string // 参数值
Desc string // 参数描述
}
// ParamsRepo 系统参数仓储接口
type ParamsRepo interface {
Create(ctx context.Context, params *Params) error
Delete(ctx context.Context, id uint) error
DeleteByIds(ctx context.Context, ids []uint) error
Update(ctx context.Context, params *Params) error
FindByID(ctx context.Context, id uint) (*Params, error)
FindByKey(ctx context.Context, key string) (*Params, error)
FindList(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*Params, int64, error)
}
// ParamsUsecase 系统参数用例
type ParamsUsecase struct {
repo ParamsRepo
}
// NewParamsUsecase 创建系统参数用例
func NewParamsUsecase(repo ParamsRepo) *ParamsUsecase {
return &ParamsUsecase{repo: repo}
}
// Create 创建参数
func (uc *ParamsUsecase) Create(ctx context.Context, params *Params) error {
return uc.repo.Create(ctx, params)
}
// Delete 删除参数
func (uc *ParamsUsecase) Delete(ctx context.Context, id uint) error {
return uc.repo.Delete(ctx, id)
}
// DeleteByIds 批量删除参数
func (uc *ParamsUsecase) DeleteByIds(ctx context.Context, ids []uint) error {
return uc.repo.DeleteByIds(ctx, ids)
}
// Update 更新参数
func (uc *ParamsUsecase) Update(ctx context.Context, params *Params) error {
return uc.repo.Update(ctx, params)
}
// GetByID 根据ID获取参数
func (uc *ParamsUsecase) GetByID(ctx context.Context, id uint) (*Params, error) {
return uc.repo.FindByID(ctx, id)
}
// GetByKey 根据Key获取参数
func (uc *ParamsUsecase) GetByKey(ctx context.Context, key string) (*Params, error) {
return uc.repo.FindByKey(ctx, key)
}
// GetList 获取参数列表
func (uc *ParamsUsecase) GetList(ctx context.Context, page, pageSize int, filters map[string]interface{}) ([]*Params, int64, error) {
return uc.repo.FindList(ctx, page, pageSize, filters)
}