init: taotie-api 项目初始化

This commit is contained in:
2026-05-16 00:14:19 +08:00
commit eb15ef4b87
33 changed files with 1746 additions and 0 deletions

45
service/tenantservice.go Normal file
View File

@@ -0,0 +1,45 @@
package service
import (
"context"
"taotie-api/common"
"taotie-api/core"
"taotie-api/model/do/tenantdo"
"taotie-api/model/po"
"taotie-api/repo"
"github.com/gookit/goutil/errorx"
)
type TenantService struct {
cfg *core.Configuration
tenantRepo *repo.TenantRepo[*po.TTenant]
}
func NewTenantService(cfg *core.Configuration, tenantRepo *repo.TenantRepo[*po.TTenant]) *TenantService {
return &TenantService{cfg, tenantRepo}
}
func (rp *TenantService) Create(ctx context.Context, in *tenantdo.CreateIn) (*tenantdo.CreateOut, error) {
// 查重
tenant, err := rp.tenantRepo.FindOneByTenantName(ctx, in.TenantName)
if err != nil {
return nil, err
}
if tenant != nil {
return nil, errorx.With(common.ErrSysDuplicate, "租户名称重复")
}
// 创建租户
tenant = &po.TTenant{
TenantName: in.TenantName,
}
tenantId, err := rp.tenantRepo.Create(ctx, tenant)
if err != nil {
return nil, err
}
return &tenantdo.CreateOut{
Id: tenantId,
}, nil
}