models更新
Signed-off-by: devad <cossjie@foxmail.com> Former-commit-id: b9775efde3cedc0d09b8d734ecd04cfec567e889
This commit is contained in:
parent
48ff9d1d4f
commit
3120d5c081
|
@ -161,6 +161,10 @@ service pcm {
|
|||
@doc "触发租户更新"
|
||||
@handler noticeTenantHandler
|
||||
get /cloud/noticeTenant returns (CloudResp)
|
||||
|
||||
@doc "触发租户更新"
|
||||
@handler updateTenantHandler
|
||||
post /cloud/updateTenant (UpdateTenantReq) returns (CloudResp)
|
||||
}
|
||||
|
||||
//智算二级接口
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package cloud
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/cloud"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/utils/result"
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
package cloud
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/rest/httpx"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/logic/cloud"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/svc"
|
||||
"gitlink.org.cn/jcce-pcm/pcm-coordinator/api/internal/types"
|
||||
"gitlink.org.cn/jcce-pcm/utils/result"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func UpdateTenantHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
var req types.UpdateTenantReq
|
||||
if err := httpx.Parse(r, &req); err != nil {
|
||||
result.ParamErrorResult(r, w, err)
|
||||
return
|
||||
}
|
||||
|
||||
l := cloud.NewUpdateTenantLogic(r.Context(), svcCtx)
|
||||
resp, err := l.UpdateTenant(&req)
|
||||
result.HttpResult(r, w, resp, err)
|
||||
}
|
||||
}
|
|
@ -187,6 +187,11 @@ func RegisterHandlers(server *rest.Server, serverCtx *svc.ServiceContext) {
|
|||
Path: "/cloud/noticeTenant",
|
||||
Handler: cloud.NoticeTenantHandler(serverCtx),
|
||||
},
|
||||
{
|
||||
Method: http.MethodPost,
|
||||
Path: "/cloud/updateTenant",
|
||||
Handler: cloud.UpdateTenantHandler(serverCtx),
|
||||
},
|
||||
},
|
||||
rest.WithPrefix("/pcm/v1"),
|
||||
)
|
||||
|
|
|
@ -23,6 +23,7 @@ func NewNoticeTenantLogic(ctx context.Context, svcCtx *svc.ServiceContext) *Noti
|
|||
}
|
||||
}
|
||||
|
||||
// NoticeTenant 通知租户更新数据
|
||||
func (l *NoticeTenantLogic) NoticeTenant() (resp *types.CloudResp, err error) {
|
||||
// todo: add your logic here and delete this line
|
||||
|
||||
|
|
|
@ -5,10 +5,14 @@ package models
|
|||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
)
|
||||
|
||||
|
@ -37,9 +41,10 @@ type (
|
|||
ScParticipantPhyInfo struct {
|
||||
Id int64 `db:"id"` // id
|
||||
Name string `db:"name"` // 名称
|
||||
Address string `db:"address"` // 集群地址
|
||||
RpcAddress string `db:"rpc_address"` // rpc服务链接地址
|
||||
Address string `db:"address"` // 集群p端地址
|
||||
Token string `db:"token"` // 数算集群token
|
||||
MetricsUrl string `db:"metrics_url"` // 监控url
|
||||
RpcAddress string `db:"rpc_address"` // rpc服务链接地址
|
||||
NetworkType string `db:"network_type"` // 集群网络类型
|
||||
NetworkBandwidth string `db:"network_bandwidth"` // 集群网络带宽
|
||||
StorageType string `db:"storage_type"` // 集群存储类型
|
||||
|
@ -47,6 +52,82 @@ type (
|
|||
StorageAvailSpace string `db:"storage_avail_space"` // 集群存储可用空间
|
||||
StorageBandwidth string `db:"storage_bandwidth"` // 集群存储带宽
|
||||
TenantId int64 `db:"tenant_id"` // 租户信息id
|
||||
Type string `db:"type"` // 类型
|
||||
Type string `db:"type"` // 类型:0-数算集群;1-智算集群;2-超算集群
|
||||
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
|
||||
CreatedBy int64 `db:"created_by"` // 创建人
|
||||
CreatedTime time.Time `db:"created_time"` // 创建时间
|
||||
UpdatedBy int64 `db:"updated_by"` // 更新人
|
||||
UpdatedTime time.Time `db:"updated_time"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
func newScParticipantPhyInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultScParticipantPhyInfoModel {
|
||||
return &defaultScParticipantPhyInfoModel{
|
||||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||
table: "`sc_participant_phy_info`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) withSession(session sqlx.Session) *defaultScParticipantPhyInfoModel {
|
||||
return &defaultScParticipantPhyInfoModel{
|
||||
CachedConn: m.CachedConn.WithSession(session),
|
||||
table: "`sc_participant_phy_info`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) Delete(ctx context.Context, id int64) error {
|
||||
pcmScParticipantPhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantPhyInfoIdPrefix, id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, pcmScParticipantPhyInfoIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) FindOne(ctx context.Context, id int64) (*ScParticipantPhyInfo, error) {
|
||||
pcmScParticipantPhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantPhyInfoIdPrefix, id)
|
||||
var resp ScParticipantPhyInfo
|
||||
err := m.QueryRowCtx(ctx, &resp, pcmScParticipantPhyInfoIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scParticipantPhyInfoRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) Insert(ctx context.Context, data *ScParticipantPhyInfo) (sql.Result, error) {
|
||||
pcmScParticipantPhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantPhyInfoIdPrefix, data.Id)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scParticipantPhyInfoRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.Name, data.Address, data.Token, data.MetricsUrl, data.RpcAddress, data.NetworkType, data.NetworkBandwidth, data.StorageType, data.StorageSpace, data.StorageAvailSpace, data.StorageBandwidth, data.TenantId, data.Type, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime)
|
||||
}, pcmScParticipantPhyInfoIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) Update(ctx context.Context, data *ScParticipantPhyInfo) error {
|
||||
pcmScParticipantPhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScParticipantPhyInfoIdPrefix, data.Id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, scParticipantPhyInfoRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, data.Name, data.Address, data.Token, data.MetricsUrl, data.RpcAddress, data.NetworkType, data.NetworkBandwidth, data.StorageType, data.StorageSpace, data.StorageAvailSpace, data.StorageBandwidth, data.TenantId, data.Type, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id)
|
||||
}, pcmScParticipantPhyInfoIdKey)
|
||||
return err
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) formatPrimary(primary any) string {
|
||||
return fmt.Sprintf("%s%v", cachePcmScParticipantPhyInfoIdPrefix, primary)
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scParticipantPhyInfoRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||
}
|
||||
|
||||
func (m *defaultScParticipantPhyInfoModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
|
|
|
@ -42,11 +42,12 @@ type (
|
|||
Id int64 `db:"id"` // id
|
||||
TenantName string `db:"tenant_name"` // 租户名称
|
||||
TenantDesc string `db:"tenant_desc"` // 描述信息
|
||||
Clusters string `db:"clusters"` // 集群名称,用","分割
|
||||
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
|
||||
CreatedBy sql.NullInt64 `db:"created_by"` // 创建人
|
||||
CreatedBy int64 `db:"created_by"` // 创建人
|
||||
CreatedTime time.Time `db:"created_time"` // 创建时间
|
||||
UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人
|
||||
UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
|
||||
UpdatedBy int64 `db:"updated_by"` // 更新人
|
||||
UpdatedTime time.Time `db:"updated_time"` // 更新时间
|
||||
}
|
||||
)
|
||||
|
||||
|
@ -93,8 +94,8 @@ func (m *defaultScTenantInfoModel) FindOne(ctx context.Context, id int64) (*ScTe
|
|||
func (m *defaultScTenantInfoModel) Insert(ctx context.Context, data *ScTenantInfo) (sql.Result, error) {
|
||||
pcmScTenantInfoIdKey := fmt.Sprintf("%s%v", cachePcmScTenantInfoIdPrefix, data.Id)
|
||||
ret, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, scTenantInfoRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.TenantName, data.TenantDesc, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, scTenantInfoRowsExpectAutoSet)
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.TenantName, data.TenantDesc, data.Clusters, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime)
|
||||
}, pcmScTenantInfoIdKey)
|
||||
return ret, err
|
||||
}
|
||||
|
@ -103,7 +104,7 @@ func (m *defaultScTenantInfoModel) Update(ctx context.Context, data *ScTenantInf
|
|||
pcmScTenantInfoIdKey := fmt.Sprintf("%s%v", cachePcmScTenantInfoIdPrefix, data.Id)
|
||||
_, err := m.ExecCtx(ctx, func(ctx context.Context, conn sqlx.SqlConn) (result sql.Result, err error) {
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, scTenantInfoRowsWithPlaceHolder)
|
||||
return conn.ExecCtx(ctx, query, data.TenantName, data.TenantDesc, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id)
|
||||
return conn.ExecCtx(ctx, query, data.TenantName, data.TenantDesc, data.Clusters, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id)
|
||||
}, pcmScTenantInfoIdKey)
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue