add sort
This commit is contained in:
@@ -7,7 +7,6 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
model2 "tydata-server/deploy/script/model"
|
||||
|
||||
"time"
|
||||
|
||||
@@ -57,14 +56,17 @@ type (
|
||||
}
|
||||
|
||||
ProductFeature struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID
|
||||
FeatureId int64 `db:"feature_id"` // 功能ID
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID
|
||||
FeatureId int64 `db:"feature_id"` // 功能ID
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
Sort int64 `db:"sort"`
|
||||
IsImportant int64 `db:"is_important"`
|
||||
Enable int64 `db:"enable"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -80,11 +82,11 @@ func (m *defaultProductFeatureModel) Insert(ctx context.Context, session sqlx.Se
|
||||
tydataProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataProductFeatureIdPrefix, data.Id)
|
||||
tydataProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTydataProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
return 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, productFeatureRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, productFeatureRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version)
|
||||
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant, data.Enable)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version)
|
||||
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant, data.Enable)
|
||||
}, tydataProductFeatureIdKey, tydataProductFeatureProductIdFeatureIdKey)
|
||||
}
|
||||
|
||||
@@ -99,7 +101,7 @@ func (m *defaultProductFeatureModel) FindOne(ctx context.Context, id int64) (*Pr
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model2.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -119,7 +121,7 @@ func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Con
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model2.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -135,9 +137,9 @@ func (m *defaultProductFeatureModel) Update(ctx context.Context, session sqlx.Se
|
||||
return 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, productFeatureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Enable, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Enable, newData.Id)
|
||||
}, tydataProductFeatureIdKey, tydataProductFeatureProductIdFeatureIdKey)
|
||||
}
|
||||
|
||||
@@ -158,9 +160,9 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
||||
sqlResult, 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` = ? and version = ? ", m.table, productFeatureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Enable, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Enable, newData.Id, oldVersion)
|
||||
}, tydataProductFeatureIdKey, tydataProductFeatureProductIdFeatureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -170,7 +172,7 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model2.ErrNoRowsUpdate
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user