forked from JointCloud/pcm-coordinator
45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package adapters
|
|
|
|
import (
|
|
"context"
|
|
"github.com/pkg/errors"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/pkg/utils"
|
|
"gorm.io/gorm"
|
|
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/svc"
|
|
"gitlink.org.cn/JointCloud/pcm-coordinator/internal/types"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type UpdateClusterLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
func NewUpdateClusterLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UpdateClusterLogic {
|
|
return &UpdateClusterLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *UpdateClusterLogic) UpdateCluster(req *types.ClusterCreateReq) (resp *types.ClusterResp, err error) {
|
|
cluster := &types.ClusterInfo{}
|
|
result := l.svcCtx.DbEngin.Table("t_cluster").First(&cluster, req.Id)
|
|
if errors.Is(result.Error, gorm.ErrRecordNotFound) {
|
|
return nil, errors.New("cluster does not exist")
|
|
}
|
|
utils.Convert(req, &cluster)
|
|
// 获取集群经纬度
|
|
location, err := GeoMap(req.RegionName)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
cluster.Location = location
|
|
l.svcCtx.DbEngin.Table("t_cluster").Model(&cluster).Updates(&cluster)
|
|
return
|
|
}
|