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 (
|
||||
exampleRowsExpectAutoSet = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
exampleRowsWithPlaceHolder = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncExampleIdPrefix = "cache:qnc:example:id:"
|
||||
cacheQncExampleProductIdPrefix = "cache:qnc:example:productId:"
|
||||
cacheTycExampleIdPrefix = "cache:tyc:example:id:"
|
||||
cacheTycExampleProductIdPrefix = "cache:tyc:example:productId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -77,21 +77,21 @@ func newExampleModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultExampleModel
|
||||
|
||||
func (m *defaultExampleModel) Insert(ctx context.Context, session sqlx.Session, data *Example) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, 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, exampleRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultExampleModel) FindOne(ctx context.Context, id int64) (*Example, error) {
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, id)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, id)
|
||||
var resp Example
|
||||
err := m.QueryRowCtx(ctx, &resp, qncExampleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tycExampleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -106,9 +106,9 @@ func (m *defaultExampleModel) FindOne(ctx context.Context, id int64) (*Example,
|
||||
}
|
||||
|
||||
func (m *defaultExampleModel) FindOneByProductId(ctx context.Context, productId int64) (*Example, error) {
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, productId)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, productId)
|
||||
var resp Example
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncExampleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycExampleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -130,15 +130,15 @@ func (m *defaultExampleModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, 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, exampleRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultExampleModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Example) error {
|
||||
@@ -153,15 +153,15 @@ func (m *defaultExampleModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, 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, exampleRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -384,19 +384,19 @@ func (m *defaultExampleModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, 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)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultExampleModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultExampleModel) 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", exampleRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user