🐛 Fixing a bug.
Signed-off-by: devad <cossjie@foxmail.com> Former-commit-id: 8fd52e86fd008127940a276ce9d8f875cd7a83fd
This commit is contained in:
parent
f52314ea1f
commit
2e355ff2a6
|
@ -15,7 +15,7 @@ type ModelArtsLink struct {
|
||||||
platform string
|
platform string
|
||||||
pageIndex int32
|
pageIndex int32
|
||||||
pageSize int32
|
pageSize int32
|
||||||
participant *models.ScParticipantPhyInfo
|
participant *models.StorelinkCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
//const (
|
//const (
|
||||||
|
@ -25,7 +25,7 @@ type ModelArtsLink struct {
|
||||||
// RESOURCE_POOL = "common-pool"
|
// RESOURCE_POOL = "common-pool"
|
||||||
//)
|
//)
|
||||||
|
|
||||||
func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *ModelArtsLink {
|
func NewModelArtsLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ModelArtsLink {
|
||||||
return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, participant: participant, platform: participant.Name, pageIndex: 1, pageSize: 100}
|
return &ModelArtsLink{ctx: ctx, svcCtx: svcCtx, participant: participant, platform: participant.Name, pageIndex: 1, pageSize: 100}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@ type OctopusLink struct {
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
pageIndex int32
|
pageIndex int32
|
||||||
pageSize int32
|
pageSize int32
|
||||||
participant *models.ScParticipantPhyInfo
|
participant *models.StorelinkCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,7 +24,7 @@ const (
|
||||||
RESOURCE_POOL = "common-pool"
|
RESOURCE_POOL = "common-pool"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *OctopusLink {
|
func NewOctopusLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *OctopusLink {
|
||||||
return &OctopusLink{ctx: ctx, svcCtx: svcCtx, participant: participant, pageIndex: 1, pageSize: 100}
|
return &OctopusLink{ctx: ctx, svcCtx: svcCtx, participant: participant, pageIndex: 1, pageSize: 100}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,7 @@ import (
|
||||||
type ShuguangAi struct {
|
type ShuguangAi struct {
|
||||||
ctx context.Context
|
ctx context.Context
|
||||||
svcCtx *svc.ServiceContext
|
svcCtx *svc.ServiceContext
|
||||||
participant *models.ScParticipantPhyInfo
|
participant *models.StorelinkCenter
|
||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -29,7 +29,7 @@ const (
|
||||||
SHUGUANGAI_CUSTOM_RESOURCE_NAME = "1*DCU, CPU:5, 内存:10GB"
|
SHUGUANGAI_CUSTOM_RESOURCE_NAME = "1*DCU, CPU:5, 内存:10GB"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewShuguangAi(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *ShuguangAi {
|
func NewShuguangAi(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *ShuguangAi {
|
||||||
return &ShuguangAi{ctx: ctx, svcCtx: svcCtx, participant: participant}
|
return &ShuguangAi{ctx: ctx, svcCtx: svcCtx, participant: participant}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,7 +59,7 @@ type StoreLink struct {
|
||||||
ILinkage Linkage
|
ILinkage Linkage
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.ScParticipantPhyInfo) *StoreLink {
|
func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *models.StorelinkCenter) *StoreLink {
|
||||||
switch participant.Type {
|
switch participant.Type {
|
||||||
case TYPE_OCTOPUS:
|
case TYPE_OCTOPUS:
|
||||||
linkStruct := NewOctopusLink(ctx, svcCtx, participant)
|
linkStruct := NewOctopusLink(ctx, svcCtx, participant)
|
||||||
|
@ -75,19 +75,19 @@ func NewStoreLink(ctx context.Context, svcCtx *svc.ServiceContext, participant *
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetParticipants(dbEngin *gorm.DB) []*models.ScParticipantPhyInfo {
|
func GetParticipants(dbEngin *gorm.DB) []*models.StorelinkCenter {
|
||||||
var participants []*models.ScParticipantPhyInfo
|
var participants []*models.StorelinkCenter
|
||||||
dbEngin.Raw("select * from sc_participant_phy_info where type = 1").Scan(&participants)
|
dbEngin.Raw("select * from storelink_center where type = 1").Scan(&participants)
|
||||||
return participants
|
return participants
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetParticipantById(partId int64, dbEngin *gorm.DB) *models.ScParticipantPhyInfo {
|
func GetParticipantById(partId int64, dbEngin *gorm.DB) *models.StorelinkCenter {
|
||||||
var participant models.ScParticipantPhyInfo
|
var participant models.StorelinkCenter
|
||||||
dbEngin.Raw("select * from sc_participant_phy_info where id = ?", partId).Scan(&participant)
|
dbEngin.Raw("select * from storelink_center where id = ?", partId).Scan(&participant)
|
||||||
return &participant
|
return &participant
|
||||||
}
|
}
|
||||||
|
|
||||||
func ConvertType[T any](in *T, participant *models.ScParticipantPhyInfo) (interface{}, error) {
|
func ConvertType[T any](in *T, participant *models.StorelinkCenter) (interface{}, error) {
|
||||||
|
|
||||||
switch (interface{})(in).(type) {
|
switch (interface{})(in).(type) {
|
||||||
case *octopus.UploadImageResp:
|
case *octopus.UploadImageResp:
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
package models
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||||
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||||
|
)
|
||||||
|
|
||||||
|
var _ StorelinkCenterModel = (*customStorelinkCenterModel)(nil)
|
||||||
|
|
||||||
|
type (
|
||||||
|
// StorelinkCenterModel is an interface to be customized, add more methods here,
|
||||||
|
// and implement the added methods in customStorelinkCenterModel.
|
||||||
|
StorelinkCenterModel interface {
|
||||||
|
storelinkCenterModel
|
||||||
|
}
|
||||||
|
|
||||||
|
customStorelinkCenterModel struct {
|
||||||
|
*defaultStorelinkCenterModel
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
// NewStorelinkCenterModel returns a model for the database table.
|
||||||
|
func NewStorelinkCenterModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) StorelinkCenterModel {
|
||||||
|
return &customStorelinkCenterModel{
|
||||||
|
defaultStorelinkCenterModel: newStorelinkCenterModel(conn, c, opts...),
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,124 @@
|
||||||
|
// Code generated by goctl. DO NOT EDIT.
|
||||||
|
|
||||||
|
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"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
storelinkCenterFieldNames = builder.RawFieldNames(&StorelinkCenter{})
|
||||||
|
storelinkCenterRows = strings.Join(storelinkCenterFieldNames, ",")
|
||||||
|
storelinkCenterRowsExpectAutoSet = strings.Join(stringx.Remove(storelinkCenterFieldNames, "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||||||
|
storelinkCenterRowsWithPlaceHolder = strings.Join(stringx.Remove(storelinkCenterFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||||||
|
|
||||||
|
cachePcmStorelinkCenterIdPrefix = "cache:pcm:storelinkCenter:id:"
|
||||||
|
)
|
||||||
|
|
||||||
|
type (
|
||||||
|
storelinkCenterModel interface {
|
||||||
|
Insert(ctx context.Context, data *StorelinkCenter) (sql.Result, error)
|
||||||
|
FindOne(ctx context.Context, id int64) (*StorelinkCenter, error)
|
||||||
|
Update(ctx context.Context, data *StorelinkCenter) error
|
||||||
|
Delete(ctx context.Context, id int64) error
|
||||||
|
}
|
||||||
|
|
||||||
|
defaultStorelinkCenterModel struct {
|
||||||
|
sqlc.CachedConn
|
||||||
|
table string
|
||||||
|
}
|
||||||
|
|
||||||
|
StorelinkCenter struct {
|
||||||
|
Id int64 `db:"id"` // id
|
||||||
|
Name string `db:"name"` // 名称
|
||||||
|
Address string `db:"address"` // 集群p端地址
|
||||||
|
RpcAddress string `db:"rpc_address"` // rpc服务链接地址
|
||||||
|
Type string `db:"type"` // 类型:1-章鱼;2-modelarts;3-曙光AI
|
||||||
|
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
|
||||||
|
CreatedBy sql.NullInt64 `db:"created_by"` // 创建人
|
||||||
|
CreatedTime time.Time `db:"created_time"` // 创建时间
|
||||||
|
UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人
|
||||||
|
UpdatedTime time.Time `db:"updated_time"` // 更新时间
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func newStorelinkCenterModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultStorelinkCenterModel {
|
||||||
|
return &defaultStorelinkCenterModel{
|
||||||
|
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||||||
|
table: "`storelink_center`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultStorelinkCenterModel) withSession(session sqlx.Session) *defaultStorelinkCenterModel {
|
||||||
|
return &defaultStorelinkCenterModel{
|
||||||
|
CachedConn: m.CachedConn.WithSession(session),
|
||||||
|
table: "`storelink_center`",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultStorelinkCenterModel) Delete(ctx context.Context, id int64) error {
|
||||||
|
pcmStorelinkCenterIdKey := fmt.Sprintf("%s%v", cachePcmStorelinkCenterIdPrefix, 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)
|
||||||
|
}, pcmStorelinkCenterIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultStorelinkCenterModel) FindOne(ctx context.Context, id int64) (*StorelinkCenter, error) {
|
||||||
|
pcmStorelinkCenterIdKey := fmt.Sprintf("%s%v", cachePcmStorelinkCenterIdPrefix, id)
|
||||||
|
var resp StorelinkCenter
|
||||||
|
err := m.QueryRowCtx(ctx, &resp, pcmStorelinkCenterIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", storelinkCenterRows, 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 *defaultStorelinkCenterModel) Insert(ctx context.Context, data *StorelinkCenter) (sql.Result, error) {
|
||||||
|
pcmStorelinkCenterIdKey := fmt.Sprintf("%s%v", cachePcmStorelinkCenterIdPrefix, 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, storelinkCenterRowsExpectAutoSet)
|
||||||
|
return conn.ExecCtx(ctx, query, data.Id, data.Name, data.Address, data.RpcAddress, data.Type, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime)
|
||||||
|
}, pcmStorelinkCenterIdKey)
|
||||||
|
return ret, err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultStorelinkCenterModel) Update(ctx context.Context, data *StorelinkCenter) error {
|
||||||
|
pcmStorelinkCenterIdKey := fmt.Sprintf("%s%v", cachePcmStorelinkCenterIdPrefix, 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, storelinkCenterRowsWithPlaceHolder)
|
||||||
|
return conn.ExecCtx(ctx, query, data.Name, data.Address, data.RpcAddress, data.Type, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id)
|
||||||
|
}, pcmStorelinkCenterIdKey)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultStorelinkCenterModel) formatPrimary(primary any) string {
|
||||||
|
return fmt.Sprintf("%s%v", cachePcmStorelinkCenterIdPrefix, primary)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultStorelinkCenterModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||||||
|
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", storelinkCenterRows, m.table)
|
||||||
|
return conn.QueryRowCtx(ctx, v, query, primary)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *defaultStorelinkCenterModel) tableName() string {
|
||||||
|
return m.table
|
||||||
|
}
|
Loading…
Reference in New Issue