删除无用字段

Former-commit-id: 92e6cce35c0193a5d8a6d161ee8391156135667c
This commit is contained in:
zhangwei 2023-12-12 16:20:48 +08:00
parent 767c692a36
commit 4a1428fa65
3 changed files with 22 additions and 143 deletions

View File

@ -1,41 +0,0 @@
/*
Copyright (c) [2023] [pcm]
[pcm-coordinator] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPaRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
package models
import (
"github.com/zeromicro/go-zero/core/stores/cache"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
var _ ScQueuePhyInfoModel = (*customScQueuePhyInfoModel)(nil)
type (
// ScQueuePhyInfoModel is an interface to be customized, add more methods here,
// and implement the added methods in customScQueuePhyInfoModel.
ScQueuePhyInfoModel interface {
scQueuePhyInfoModel
}
customScQueuePhyInfoModel struct {
*defaultScQueuePhyInfoModel
}
)
// NewScQueuePhyInfoModel returns a models for the database table.
func NewScQueuePhyInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) ScQueuePhyInfoModel {
return &customScQueuePhyInfoModel{
defaultScQueuePhyInfoModel: newScQueuePhyInfoModel(conn, c, opts...),
}
}

View File

@ -5,14 +5,10 @@ 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"
)
@ -61,80 +57,5 @@ type (
DeletedFlag int64 `db:"deleted_flag"` // 是否删除
QueNcpus string `db:"que_ncpus"`
QueFreeNcpus string `db:"que_free_ncpus"`
CreatedBy sql.NullInt64 `db:"created_by"` // 创建人
CreatedTime time.Time `db:"created_time"` // 创建时间
UpdatedBy sql.NullInt64 `db:"updated_by"` // 更新人
UpdatedTime sql.NullTime `db:"updated_time"` // 更新时间
}
)
func newScQueuePhyInfoModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultScQueuePhyInfoModel {
return &defaultScQueuePhyInfoModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`sc_queue_phy_info`",
}
}
func (m *defaultScQueuePhyInfoModel) withSession(session sqlx.Session) *defaultScQueuePhyInfoModel {
return &defaultScQueuePhyInfoModel{
CachedConn: m.CachedConn.WithSession(session),
table: "`sc_queue_phy_info`",
}
}
func (m *defaultScQueuePhyInfoModel) Delete(ctx context.Context, id int64) error {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, 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)
}, pcmScQueuePhyInfoIdKey)
return err
}
func (m *defaultScQueuePhyInfoModel) FindOne(ctx context.Context, id int64) (*ScQueuePhyInfo, error) {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, id)
var resp ScQueuePhyInfo
err := m.QueryRowCtx(ctx, &resp, pcmScQueuePhyInfoIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scQueuePhyInfoRows, 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 *defaultScQueuePhyInfoModel) Insert(ctx context.Context, data *ScQueuePhyInfo) (sql.Result, error) {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, 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, scQueuePhyInfoRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.Id, data.AclHosts, data.QueueId, data.Text, data.QueueName, data.QueNodes, data.QueMinNodect, data.QueMaxNgpus, data.QueMaxPpn, data.QueChargeRate, data.QueMaxNcpus, data.QueMaxNdcus, data.QueMinNcpus, data.QueFreeNodes, data.QueMaxNodect, data.QueMaxGpuPN, data.QueMaxWalltime, data.QueMaxDcuPN, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime)
}, pcmScQueuePhyInfoIdKey)
return ret, err
}
func (m *defaultScQueuePhyInfoModel) Update(ctx context.Context, data *ScQueuePhyInfo) error {
pcmScQueuePhyInfoIdKey := fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, 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, scQueuePhyInfoRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, data.AclHosts, data.QueueId, data.Text, data.QueueName, data.QueNodes, data.QueMinNodect, data.QueMaxNgpus, data.QueMaxPpn, data.QueChargeRate, data.QueMaxNcpus, data.QueMaxNdcus, data.QueMinNcpus, data.QueFreeNodes, data.QueMaxNodect, data.QueMaxGpuPN, data.QueMaxWalltime, data.QueMaxDcuPN, data.ParticipantId, data.DeletedFlag, data.CreatedBy, data.CreatedTime, data.UpdatedBy, data.UpdatedTime, data.Id)
}, pcmScQueuePhyInfoIdKey)
return err
}
func (m *defaultScQueuePhyInfoModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cachePcmScQueuePhyInfoIdPrefix, primary)
}
func (m *defaultScQueuePhyInfoModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", scQueuePhyInfoRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultScQueuePhyInfoModel) tableName() string {
return m.table
}

View File

@ -88,7 +88,6 @@ func (l *RegisterParticipantLogic) RegisterParticipant(in *pcmCore.ParticipantPh
for _, info := range in.QueueInfo {
queueInfo := &models2.ScQueuePhyInfo{}
utils.Convert(info, queueInfo)
queueInfo.CreatedTime = time.Now()
queueInfo.ParticipantId = participantInfo.Id
//查询队列name与ParticipantId是否存在
queueErr := db.Where(&models2.ScQueuePhyInfo{QueueName: queueInfo.QueueName, ParticipantId: in.ParticipantId}).Take(queueInfo)