v1.0.0
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"tydata-server/deploy/script/model"
|
||||
model2 "tydata-server/deploy/script/model"
|
||||
|
||||
"time"
|
||||
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
featureRowsExpectAutoSet = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
featureRowsWithPlaceHolder = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncFeatureIdPrefix = "cache:qnc:feature:id:"
|
||||
cacheQncFeatureApiIdPrefix = "cache:qnc:feature:apiId:"
|
||||
cacheTydataFeatureIdPrefix = "cache:tydata:feature:id:"
|
||||
cacheTydataFeatureApiIdPrefix = "cache:tydata:feature:apiId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -77,39 +77,39 @@ func newFeatureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultFeatureModel
|
||||
|
||||
func (m *defaultFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *Feature) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
||||
tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId)
|
||||
tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, data.Id)
|
||||
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, featureRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, featureRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tydataFeatureApiIdKey, tydataFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultFeatureModel) FindOne(ctx context.Context, id int64) (*Feature, error) {
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id)
|
||||
tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, id)
|
||||
var resp Feature
|
||||
err := m.QueryRowCtx(ctx, &resp, qncFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", featureRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string) (*Feature, error) {
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, apiId)
|
||||
tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, apiId)
|
||||
var resp Feature
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `api_id` = ? AND del_state = ? limit 1", featureRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `api_id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, apiId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string)
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -130,15 +130,15 @@ func (m *defaultFeatureModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
||||
tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId)
|
||||
tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, data.Id)
|
||||
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, featureRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, featureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tydataFeatureApiIdKey, tydataFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Feature) error {
|
||||
@@ -153,15 +153,15 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
||||
tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId)
|
||||
tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, data.Id)
|
||||
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, featureRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, featureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tydataFeatureApiIdKey, tydataFeatureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return model2.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -384,22 +384,22 @@ func (m *defaultFeatureModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id)
|
||||
tydataFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureApiIdPrefix, data.ApiId)
|
||||
tydataFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, 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)
|
||||
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)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tydataFeatureApiIdKey, tydataFeatureIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultFeatureModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataFeatureIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultFeatureModel) 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", featureRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ var (
|
||||
globalNotificationsRowsExpectAutoSet = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
globalNotificationsRowsWithPlaceHolder = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncGlobalNotificationsIdPrefix = "cache:qnc:globalNotifications:id:"
|
||||
cacheTydataGlobalNotificationsIdPrefix = "cache:tydata:globalNotifications:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -81,20 +81,20 @@ func newGlobalNotificationsModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultG
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) Insert(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
||||
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, data.Id)
|
||||
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, globalNotificationsRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tydataGlobalNotificationsIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64) (*GlobalNotifications, error) {
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, id)
|
||||
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, id)
|
||||
var resp GlobalNotifications
|
||||
err := m.QueryRowCtx(ctx, &resp, qncGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", globalNotificationsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -109,14 +109,14 @@ func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64)
|
||||
}
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) Update(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
||||
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, data.Id)
|
||||
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, globalNotificationsRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tydataGlobalNotificationsIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *GlobalNotifications) error {
|
||||
@@ -127,14 +127,14 @@ func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context,
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
||||
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, data.Id)
|
||||
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, globalNotificationsRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tydataGlobalNotificationsIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -352,18 +352,18 @@ func (m *defaultGlobalNotificationsModel) SelectBuilder() squirrel.SelectBuilder
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultGlobalNotificationsModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, id)
|
||||
tydataGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, 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)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, id)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tydataGlobalNotificationsIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultGlobalNotificationsModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataGlobalNotificationsIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultGlobalNotificationsModel) 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", globalNotificationsRows, m.table)
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"tydata-server/deploy/script/model"
|
||||
model2 "tydata-server/deploy/script/model"
|
||||
|
||||
"time"
|
||||
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
orderRowsExpectAutoSet = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
orderRowsWithPlaceHolder = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncOrderIdPrefix = "cache:qnc:order:id:"
|
||||
cacheQncOrderOrderNoPrefix = "cache:qnc:order:orderNo:"
|
||||
cacheTydataOrderIdPrefix = "cache:tydata:order:id:"
|
||||
cacheTydataOrderOrderNoPrefix = "cache:tydata:order:orderNo:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -61,7 +61,7 @@ type (
|
||||
OrderNo string `db:"order_no"` // 自生成的订单号
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID(软关联到产品表)
|
||||
PaymentPlatform string `db:"payment_platform"` // 支付平台(支付宝、微信、其他)
|
||||
PaymentPlatform string `db:"payment_platform"` // 支付平台(支付宝、微信、苹果内购、其他)
|
||||
PaymentScene string `db:"payment_scene"` // 支付场景(App、H5、微信小程序、公众号)
|
||||
PlatformOrderId sql.NullString `db:"platform_order_id"` // 支付平台订单号
|
||||
Amount float64 `db:"amount"` // 支付金额
|
||||
@@ -86,39 +86,39 @@ func newOrderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultOrderModel {
|
||||
|
||||
func (m *defaultOrderModel) Insert(ctx context.Context, session sqlx.Session, data *Order) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tydataOrderIdKey := fmt.Sprintf("%s%v", cacheTydataOrderIdPrefix, data.Id)
|
||||
tydataOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTydataOrderOrderNoPrefix, data.OrderNo)
|
||||
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, orderRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, orderRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tydataOrderIdKey, tydataOrderOrderNoKey)
|
||||
}
|
||||
|
||||
func (m *defaultOrderModel) FindOne(ctx context.Context, id int64) (*Order, error) {
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, id)
|
||||
tydataOrderIdKey := fmt.Sprintf("%s%v", cacheTydataOrderIdPrefix, id)
|
||||
var resp Order
|
||||
err := m.QueryRowCtx(ctx, &resp, qncOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", orderRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string) (*Order, error) {
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, orderNo)
|
||||
tydataOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTydataOrderOrderNoPrefix, orderNo)
|
||||
var resp Order
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncOrderOrderNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `order_no` = ? AND del_state = ? limit 1", orderRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataOrderOrderNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `order_no` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderNo, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -128,7 +128,7 @@ func (m *defaultOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -139,15 +139,15 @@ func (m *defaultOrderModel) Update(ctx context.Context, session sqlx.Session, ne
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tydataOrderIdKey := fmt.Sprintf("%s%v", cacheTydataOrderIdPrefix, data.Id)
|
||||
tydataOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTydataOrderOrderNoPrefix, data.OrderNo)
|
||||
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, orderRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, orderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tydataOrderIdKey, tydataOrderOrderNoKey)
|
||||
}
|
||||
|
||||
func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Order) error {
|
||||
@@ -162,15 +162,15 @@ func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tydataOrderIdKey := fmt.Sprintf("%s%v", cacheTydataOrderIdPrefix, data.Id)
|
||||
tydataOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTydataOrderOrderNoPrefix, data.OrderNo)
|
||||
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, orderRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, orderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tydataOrderIdKey, tydataOrderOrderNoKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -179,7 +179,7 @@ func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return model2.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -393,22 +393,22 @@ func (m *defaultOrderModel) Delete(ctx context.Context, session sqlx.Session, id
|
||||
return err
|
||||
}
|
||||
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tydataOrderIdKey := fmt.Sprintf("%s%v", cacheTydataOrderIdPrefix, id)
|
||||
tydataOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTydataOrderOrderNoPrefix, data.OrderNo)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tydataOrderIdKey, tydataOrderOrderNoKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultOrderModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataOrderIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultOrderModel) 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", orderRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"tydata-server/deploy/script/model"
|
||||
model2 "tydata-server/deploy/script/model"
|
||||
|
||||
"time"
|
||||
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
productFeatureRowsExpectAutoSet = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
productFeatureRowsWithPlaceHolder = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncProductFeatureIdPrefix = "cache:qnc:productFeature:id:"
|
||||
cacheQncProductFeatureProductIdFeatureIdPrefix = "cache:qnc:productFeature:productId:featureId:"
|
||||
cacheTydataProductFeatureIdPrefix = "cache:tydata:productFeature:id:"
|
||||
cacheTydataProductFeatureProductIdFeatureIdPrefix = "cache:tydata:productFeature:productId:featureId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -77,39 +77,39 @@ func newProductFeatureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProduc
|
||||
|
||||
func (m *defaultProductFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
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 conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
||||
}, tydataProductFeatureIdKey, tydataProductFeatureProductIdFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductFeatureModel) FindOne(ctx context.Context, id int64) (*ProductFeature, error) {
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
||||
tydataProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataProductFeatureIdPrefix, id)
|
||||
var resp ProductFeature
|
||||
err := m.QueryRowCtx(ctx, &resp, qncProductFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataProductFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error) {
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, productId, featureId)
|
||||
tydataProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTydataProductFeatureProductIdFeatureIdPrefix, productId, featureId)
|
||||
var resp ProductFeature
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductFeatureProductIdFeatureIdKey, 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 `feature_id` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataProductFeatureProductIdFeatureIdKey, 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 `feature_id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, featureId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -119,7 +119,7 @@ func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Con
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -130,15 +130,15 @@ func (m *defaultProductFeatureModel) Update(ctx context.Context, session sqlx.Se
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
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("UPDATE %s SET %s WHERE `id` = ?", m.table, productFeatureRowsWithPlaceHolder)
|
||||
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 conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
||||
}, tydataProductFeatureIdKey, tydataProductFeatureProductIdFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductFeature) error {
|
||||
@@ -153,15 +153,15 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
tydataProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataProductFeatureIdPrefix, data.Id)
|
||||
tydataProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTydataProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
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)
|
||||
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 conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
||||
}, tydataProductFeatureIdKey, tydataProductFeatureProductIdFeatureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -170,7 +170,7 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return model2.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -384,22 +384,22 @@ func (m *defaultProductFeatureModel) Delete(ctx context.Context, session sqlx.Se
|
||||
return err
|
||||
}
|
||||
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
tydataProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTydataProductFeatureIdPrefix, id)
|
||||
tydataProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTydataProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey)
|
||||
}, tydataProductFeatureIdKey, tydataProductFeatureProductIdFeatureIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultProductFeatureModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataProductFeatureIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultProductFeatureModel) 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", productFeatureRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"tydata-server/deploy/script/model"
|
||||
model2 "tydata-server/deploy/script/model"
|
||||
|
||||
"time"
|
||||
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
productRowsExpectAutoSet = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
productRowsWithPlaceHolder = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncProductIdPrefix = "cache:qnc:product:id:"
|
||||
cacheQncProductProductEnPrefix = "cache:qnc:product:productEn:"
|
||||
cacheTydataProductIdPrefix = "cache:tydata:product:id:"
|
||||
cacheTydataProductProductEnPrefix = "cache:tydata:product:productEn:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -81,39 +81,39 @@ func newProductModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProductModel
|
||||
|
||||
func (m *defaultProductModel) Insert(ctx context.Context, session sqlx.Session, data *Product) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tydataProductIdKey := fmt.Sprintf("%s%v", cacheTydataProductIdPrefix, data.Id)
|
||||
tydataProductProductEnKey := fmt.Sprintf("%s%v", cacheTydataProductProductEnPrefix, data.ProductEn)
|
||||
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, productRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, productRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tydataProductIdKey, tydataProductProductEnKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductModel) FindOne(ctx context.Context, id int64) (*Product, error) {
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, id)
|
||||
tydataProductIdKey := fmt.Sprintf("%s%v", cacheTydataProductIdPrefix, id)
|
||||
var resp Product
|
||||
err := m.QueryRowCtx(ctx, &resp, qncProductIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", productRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataProductIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductModel) FindOneByProductEn(ctx context.Context, productEn string) (*Product, error) {
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, productEn)
|
||||
tydataProductProductEnKey := fmt.Sprintf("%s%v", cacheTydataProductProductEnPrefix, productEn)
|
||||
var resp Product
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductProductEnKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_en` = ? AND del_state = ? limit 1", productRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataProductProductEnKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_en` = ? and del_state = ? limit 1", productRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productEn, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (m *defaultProductModel) FindOneByProductEn(ctx context.Context, productEn
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,15 +134,15 @@ func (m *defaultProductModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tydataProductIdKey := fmt.Sprintf("%s%v", cacheTydataProductIdPrefix, data.Id)
|
||||
tydataProductProductEnKey := fmt.Sprintf("%s%v", cacheTydataProductProductEnPrefix, data.ProductEn)
|
||||
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, productRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tydataProductIdKey, tydataProductProductEnKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Product) error {
|
||||
@@ -157,15 +157,15 @@ func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tydataProductIdKey := fmt.Sprintf("%s%v", cacheTydataProductIdPrefix, data.Id)
|
||||
tydataProductProductEnKey := fmt.Sprintf("%s%v", cacheTydataProductProductEnPrefix, data.ProductEn)
|
||||
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, productRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tydataProductIdKey, tydataProductProductEnKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return model2.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -388,22 +388,22 @@ func (m *defaultProductModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tydataProductIdKey := fmt.Sprintf("%s%v", cacheTydataProductIdPrefix, id)
|
||||
tydataProductProductEnKey := fmt.Sprintf("%s%v", cacheTydataProductProductEnPrefix, data.ProductEn)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tydataProductIdKey, tydataProductProductEnKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultProductModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncProductIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataProductIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultProductModel) 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", productRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
"tydata-server/deploy/script/model"
|
||||
model2 "tydata-server/deploy/script/model"
|
||||
|
||||
"time"
|
||||
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
queryRowsExpectAutoSet = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
queryRowsWithPlaceHolder = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncQueryIdPrefix = "cache:qnc:query:id:"
|
||||
cacheQncQueryOrderIdPrefix = "cache:qnc:query:orderId:"
|
||||
cacheTydataQueryIdPrefix = "cache:tydata:query:id:"
|
||||
cacheTydataQueryOrderIdPrefix = "cache:tydata:query:orderId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -81,39 +81,39 @@ func newQueryModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultQueryModel {
|
||||
|
||||
func (m *defaultQueryModel) Insert(ctx context.Context, session sqlx.Session, data *Query) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tydataQueryIdKey := fmt.Sprintf("%s%v", cacheTydataQueryIdPrefix, data.Id)
|
||||
tydataQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTydataQueryOrderIdPrefix, data.OrderId)
|
||||
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, queryRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, queryRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tydataQueryIdKey, tydataQueryOrderIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultQueryModel) FindOne(ctx context.Context, id int64) (*Query, error) {
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, id)
|
||||
tydataQueryIdKey := fmt.Sprintf("%s%v", cacheTydataQueryIdPrefix, id)
|
||||
var resp Query
|
||||
err := m.QueryRowCtx(ctx, &resp, qncQueryIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", queryRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataQueryIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultQueryModel) FindOneByOrderId(ctx context.Context, orderId int64) (*Query, error) {
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, orderId)
|
||||
tydataQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTydataQueryOrderIdPrefix, orderId)
|
||||
var resp Query
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncQueryOrderIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `order_id` = ? AND del_state = ? limit 1", queryRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataQueryOrderIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `order_id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,7 +123,7 @@ func (m *defaultQueryModel) FindOneByOrderId(ctx context.Context, orderId int64)
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,15 +134,15 @@ func (m *defaultQueryModel) Update(ctx context.Context, session sqlx.Session, ne
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tydataQueryIdKey := fmt.Sprintf("%s%v", cacheTydataQueryIdPrefix, data.Id)
|
||||
tydataQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTydataQueryOrderIdPrefix, data.OrderId)
|
||||
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, queryRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, queryRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tydataQueryIdKey, tydataQueryOrderIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Query) error {
|
||||
@@ -157,15 +157,15 @@ func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tydataQueryIdKey := fmt.Sprintf("%s%v", cacheTydataQueryIdPrefix, data.Id)
|
||||
tydataQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTydataQueryOrderIdPrefix, data.OrderId)
|
||||
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, queryRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, queryRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tydataQueryIdKey, tydataQueryOrderIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -174,7 +174,7 @@ func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return model2.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -388,22 +388,22 @@ func (m *defaultQueryModel) Delete(ctx context.Context, session sqlx.Session, id
|
||||
return err
|
||||
}
|
||||
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tydataQueryIdKey := fmt.Sprintf("%s%v", cacheTydataQueryIdPrefix, id)
|
||||
tydataQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTydataQueryOrderIdPrefix, data.OrderId)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tydataQueryIdKey, tydataQueryOrderIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultQueryModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataQueryIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultQueryModel) 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", queryRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ import (
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
model2 "tydata-server/deploy/script/model"
|
||||
|
||||
"time"
|
||||
|
||||
@@ -26,9 +27,9 @@ var (
|
||||
userAuthRowsExpectAutoSet = strings.Join(stringx.Remove(userAuthFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
userAuthRowsWithPlaceHolder = strings.Join(stringx.Remove(userAuthFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncUserAuthIdPrefix = "cache:qnc:userAuth:id:"
|
||||
cacheQncUserAuthAuthTypeAuthKeyPrefix = "cache:qnc:userAuth:authType:authKey:"
|
||||
cacheQncUserAuthUserIdAuthTypePrefix = "cache:qnc:userAuth:userId:authType:"
|
||||
cacheTydataUserAuthIdPrefix = "cache:tydata:userAuth:id:"
|
||||
cacheTydataUserAuthAuthTypeAuthKeyPrefix = "cache:tydata:userAuth:authType:authKey:"
|
||||
cacheTydataUserAuthUserIdAuthTypePrefix = "cache:tydata:userAuth:userId:authType:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -79,22 +80,22 @@ func newUserAuthModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserAuthMode
|
||||
|
||||
func (m *defaultUserAuthModel) Insert(ctx context.Context, session sqlx.Session, data *UserAuth) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, data.Id)
|
||||
tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
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, userAuthRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.UserId, data.AuthKey, data.AuthType)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.UserId, data.AuthKey, data.AuthType)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) FindOne(ctx context.Context, id int64) (*UserAuth, error) {
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, id)
|
||||
tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, id)
|
||||
var resp UserAuth
|
||||
err := m.QueryRowCtx(ctx, &resp, qncUserAuthIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataUserAuthIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userAuthRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -102,16 +103,16 @@ func (m *defaultUserAuthModel) FindOne(ctx context.Context, id int64) (*UserAuth
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) FindOneByAuthTypeAuthKey(ctx context.Context, authType string, authKey string) (*UserAuth, error) {
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, authType, authKey)
|
||||
tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, authType, authKey)
|
||||
var resp UserAuth
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncUserAuthAuthTypeAuthKeyKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataUserAuthAuthTypeAuthKeyKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `auth_type` = ? and `auth_key` = ? and del_state = ? limit 1", userAuthRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, authType, authKey, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -122,16 +123,16 @@ func (m *defaultUserAuthModel) FindOneByAuthTypeAuthKey(ctx context.Context, aut
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) FindOneByUserIdAuthType(ctx context.Context, userId int64, authType string) (*UserAuth, error) {
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, userId, authType)
|
||||
tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, userId, authType)
|
||||
var resp UserAuth
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncUserAuthUserIdAuthTypeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataUserAuthUserIdAuthTypeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `user_id` = ? and `auth_type` = ? and del_state = ? limit 1", userAuthRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, userId, authType, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -142,7 +143,7 @@ func (m *defaultUserAuthModel) FindOneByUserIdAuthType(ctx context.Context, user
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
return nil, model2.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -153,16 +154,16 @@ func (m *defaultUserAuthModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, data.Id)
|
||||
tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
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, userAuthRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *UserAuth) error {
|
||||
@@ -177,16 +178,16 @@ func (m *defaultUserAuthModel) UpdateWithVersion(ctx context.Context, session sq
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, data.Id)
|
||||
tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
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, userAuthRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id, oldVersion)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -195,7 +196,7 @@ func (m *defaultUserAuthModel) UpdateWithVersion(ctx context.Context, session sq
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
return model2.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -409,20 +410,20 @@ func (m *defaultUserAuthModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tydataUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tydataUserAuthIdKey := fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, id)
|
||||
tydataUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTydataUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
_, 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)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tydataUserAuthAuthTypeAuthKeyKey, tydataUserAuthIdKey, tydataUserAuthUserIdAuthTypeKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultUserAuthModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataUserAuthIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultUserAuthModel) 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", userAuthRows, m.table)
|
||||
|
||||
@@ -27,8 +27,8 @@ var (
|
||||
userRowsExpectAutoSet = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
userRowsWithPlaceHolder = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncUserIdPrefix = "cache:qnc:user:id:"
|
||||
cacheQncUserMobilePrefix = "cache:qnc:user:mobile:"
|
||||
cacheTydataUserIdPrefix = "cache:tydata:user:id:"
|
||||
cacheTydataUserMobilePrefix = "cache:tydata:user:mobile:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -80,21 +80,21 @@ func newUserModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserModel {
|
||||
|
||||
func (m *defaultUserModel) Insert(ctx context.Context, session sqlx.Session, data *User) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, data.Id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, data.Id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
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, userRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error) {
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, id)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, id)
|
||||
var resp User
|
||||
err := m.QueryRowCtx(ctx, &resp, qncUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -109,9 +109,9 @@ func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) FindOneByMobile(ctx context.Context, mobile string) (*User, error) {
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, mobile)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, mobile)
|
||||
var resp User
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncUserMobileKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataUserMobileKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `mobile` = ? and del_state = ? limit 1", userRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, mobile, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -133,15 +133,15 @@ func (m *defaultUserModel) Update(ctx context.Context, session sqlx.Session, new
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, data.Id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, data.Id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
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, userRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *User) error {
|
||||
@@ -156,15 +156,15 @@ func (m *defaultUserModel) UpdateWithVersion(ctx context.Context, session sqlx.S
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, data.Id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, data.Id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
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, userRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id, oldVersion)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -387,19 +387,19 @@ func (m *defaultUserModel) Delete(ctx context.Context, session sqlx.Session, id
|
||||
return err
|
||||
}
|
||||
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tydataUserIdKey := fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, id)
|
||||
tydataUserMobileKey := fmt.Sprintf("%s%v", cacheTydataUserMobilePrefix, data.Mobile)
|
||||
_, 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)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tydataUserIdKey, tydataUserMobileKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultUserModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncUserIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataUserIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultUserModel) 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", userRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user