temp
This commit is contained in:
@@ -17,7 +17,7 @@ import (
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,8 +26,8 @@ var (
|
||||
productRenderRowsExpectAutoSet = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
productRenderRowsWithPlaceHolder = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncProductRenderIdPrefix = "cache:qnc:productRender:id:"
|
||||
cacheQncProductRenderPlatformModuleProductIdPrefix = "cache:qnc:productRender:platform:module:productId:"
|
||||
cacheTycProductRenderIdPrefix = "cache:tyc:productRender:id:"
|
||||
cacheTycProductRenderPlatformModuleProductIdPrefix = "cache:tyc:productRender:platform:module:productId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -78,21 +78,21 @@ func newProductRenderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProduct
|
||||
|
||||
func (m *defaultProductRenderModel) Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
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, productRenderRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*ProductRender, error) {
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, id)
|
||||
var resp ProductRender
|
||||
err := m.QueryRowCtx(ctx, &resp, qncProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tycProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -107,9 +107,9 @@ func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*Pro
|
||||
}
|
||||
|
||||
func (m *defaultProductRenderModel) FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error) {
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
||||
var resp ProductRender
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `platform` = ? and `module` = ? and `product_id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, platform, module, productId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -131,15 +131,15 @@ func (m *defaultProductRenderModel) Update(ctx context.Context, session sqlx.Ses
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
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, productRenderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductRender) error {
|
||||
@@ -154,15 +154,15 @@ func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, sessi
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
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, productRenderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -385,19 +385,19 @@ func (m *defaultProductRenderModel) Delete(ctx context.Context, session sqlx.Ses
|
||||
return err
|
||||
}
|
||||
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
_, 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)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultProductRenderModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultProductRenderModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user