forked from JointCloud/pcm-coordinator
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package cloud
|
|
|
|
import (
|
|
"context"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/models"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/pkg/utils"
|
|
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
|
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateTenantLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUpdateTenantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateTenantLogic {
|
|
return &UpdateTenantLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
// UpdateTenant 更新租户数据
|
|
func (l *UpdateTenantLogic) UpdateTenant(req *types.UpdateTenantReq) (resp *types.CloudResp, err error) {
|
|
//先删除所有租户数据
|
|
l.svcCtx.DbEngin.Where("type = 0").Delete(models.ScTenantInfo{})
|
|
var tenants []*models.ScTenantInfo
|
|
for _, t := range req.Tenants {
|
|
tenants = append(tenants, &models.ScTenantInfo{
|
|
Id: utils.GenSnowflakeID(),
|
|
TenantName: t.TenantName,
|
|
Clusters: t.Clusters,
|
|
Type: 0,
|
|
})
|
|
}
|
|
//再插入新的租户数据
|
|
l.svcCtx.DbEngin.Save(&tenants)
|
|
return
|
|
}
|