fix
This commit is contained in:
@@ -10,8 +10,6 @@ import (
|
||||
|
||||
"time"
|
||||
|
||||
"hm-server/common/globalkey"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
@@ -19,6 +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"
|
||||
"hm-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,17 +26,15 @@ var (
|
||||
orderRefundRowsExpectAutoSet = strings.Join(stringx.Remove(orderRefundFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
orderRefundRowsWithPlaceHolder = strings.Join(stringx.Remove(orderRefundFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheHmOrderRefundIdPrefix = "cache:hm:orderRefund:id:"
|
||||
cacheHmOrderRefundOrderIdPrefix = "cache:hm:orderRefund:orderId:"
|
||||
cacheHmOrderRefundPlatformRefundIdPrefix = "cache:hm:orderRefund:platformRefundId:"
|
||||
cacheHmOrderRefundRefundNoPrefix = "cache:hm:orderRefund:refundNo:"
|
||||
cacheTydataOrderRefundIdPrefix = "cache:tydata:orderRefund:id:"
|
||||
cacheTydataOrderRefundPlatformRefundIdPrefix = "cache:tydata:orderRefund:platformRefundId:"
|
||||
cacheTydataOrderRefundRefundNoPrefix = "cache:tydata:orderRefund:refundNo:"
|
||||
)
|
||||
|
||||
type (
|
||||
orderRefundModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *OrderRefund) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*OrderRefund, error)
|
||||
FindOneByOrderId(ctx context.Context, orderId int64) (*OrderRefund, error)
|
||||
FindOneByPlatformRefundId(ctx context.Context, platformRefundId sql.NullString) (*OrderRefund, error)
|
||||
FindOneByRefundNo(ctx context.Context, refundNo string) (*OrderRefund, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *OrderRefund) (sql.Result, error)
|
||||
@@ -89,23 +86,22 @@ func newOrderRefundModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultOrderRefu
|
||||
|
||||
func (m *defaultOrderRefundModel) Insert(ctx context.Context, session sqlx.Session, data *OrderRefund) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
hmOrderRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundIdPrefix, data.Id)
|
||||
hmOrderRefundOrderIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundOrderIdPrefix, data.OrderId)
|
||||
hmOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
hmOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheHmOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
tydataOrderRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundIdPrefix, data.Id)
|
||||
tydataOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
tydataOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
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, orderRefundRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.RefundNo, data.OrderId, data.UserId, data.ProductId, data.PlatformRefundId, data.RefundAmount, data.RefundReason, data.Status, data.DelState, data.Version, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.RefundNo, data.OrderId, data.UserId, data.ProductId, data.PlatformRefundId, data.RefundAmount, data.RefundReason, data.Status, data.DelState, data.Version, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||
}, hmOrderRefundIdKey, hmOrderRefundOrderIdKey, hmOrderRefundPlatformRefundIdKey, hmOrderRefundRefundNoKey)
|
||||
}, tydataOrderRefundIdKey, tydataOrderRefundPlatformRefundIdKey, tydataOrderRefundRefundNoKey)
|
||||
}
|
||||
|
||||
func (m *defaultOrderRefundModel) FindOne(ctx context.Context, id int64) (*OrderRefund, error) {
|
||||
hmOrderRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundIdPrefix, id)
|
||||
tydataOrderRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundIdPrefix, id)
|
||||
var resp OrderRefund
|
||||
err := m.QueryRowCtx(ctx, &resp, hmOrderRefundIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataOrderRefundIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", orderRefundRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -119,30 +115,10 @@ func (m *defaultOrderRefundModel) FindOne(ctx context.Context, id int64) (*Order
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultOrderRefundModel) FindOneByOrderId(ctx context.Context, orderId int64) (*OrderRefund, error) {
|
||||
hmOrderRefundOrderIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundOrderIdPrefix, orderId)
|
||||
var resp OrderRefund
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, hmOrderRefundOrderIdKey, 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", orderRefundRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultOrderRefundModel) FindOneByPlatformRefundId(ctx context.Context, platformRefundId sql.NullString) (*OrderRefund, error) {
|
||||
hmOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundPlatformRefundIdPrefix, platformRefundId)
|
||||
tydataOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundPlatformRefundIdPrefix, platformRefundId)
|
||||
var resp OrderRefund
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, hmOrderRefundPlatformRefundIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataOrderRefundPlatformRefundIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `platform_refund_id` = ? and del_state = ? limit 1", orderRefundRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, platformRefundId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -160,9 +136,9 @@ func (m *defaultOrderRefundModel) FindOneByPlatformRefundId(ctx context.Context,
|
||||
}
|
||||
|
||||
func (m *defaultOrderRefundModel) FindOneByRefundNo(ctx context.Context, refundNo string) (*OrderRefund, error) {
|
||||
hmOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheHmOrderRefundRefundNoPrefix, refundNo)
|
||||
tydataOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundRefundNoPrefix, refundNo)
|
||||
var resp OrderRefund
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, hmOrderRefundRefundNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataOrderRefundRefundNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `refund_no` = ? and del_state = ? limit 1", orderRefundRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, refundNo, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -184,17 +160,16 @@ func (m *defaultOrderRefundModel) Update(ctx context.Context, session sqlx.Sessi
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
hmOrderRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundIdPrefix, data.Id)
|
||||
hmOrderRefundOrderIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundOrderIdPrefix, data.OrderId)
|
||||
hmOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
hmOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheHmOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
tydataOrderRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundIdPrefix, data.Id)
|
||||
tydataOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
tydataOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
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, orderRefundRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.RefundNo, newData.OrderId, newData.UserId, newData.ProductId, newData.PlatformRefundId, newData.RefundAmount, newData.RefundReason, newData.Status, newData.DelState, newData.Version, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.RefundNo, newData.OrderId, newData.UserId, newData.ProductId, newData.PlatformRefundId, newData.RefundAmount, newData.RefundReason, newData.Status, newData.DelState, newData.Version, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||
}, hmOrderRefundIdKey, hmOrderRefundOrderIdKey, hmOrderRefundPlatformRefundIdKey, hmOrderRefundRefundNoKey)
|
||||
}, tydataOrderRefundIdKey, tydataOrderRefundPlatformRefundIdKey, tydataOrderRefundRefundNoKey)
|
||||
}
|
||||
|
||||
func (m *defaultOrderRefundModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *OrderRefund) error {
|
||||
@@ -209,17 +184,16 @@ func (m *defaultOrderRefundModel) UpdateWithVersion(ctx context.Context, session
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
hmOrderRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundIdPrefix, data.Id)
|
||||
hmOrderRefundOrderIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundOrderIdPrefix, data.OrderId)
|
||||
hmOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
hmOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheHmOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
tydataOrderRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundIdPrefix, data.Id)
|
||||
tydataOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
tydataOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
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, orderRefundRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.RefundNo, newData.OrderId, newData.UserId, newData.ProductId, newData.PlatformRefundId, newData.RefundAmount, newData.RefundReason, newData.Status, newData.DelState, newData.Version, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.RefundNo, newData.OrderId, newData.UserId, newData.ProductId, newData.PlatformRefundId, newData.RefundAmount, newData.RefundReason, newData.Status, newData.DelState, newData.Version, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}, hmOrderRefundIdKey, hmOrderRefundOrderIdKey, hmOrderRefundPlatformRefundIdKey, hmOrderRefundRefundNoKey)
|
||||
}, tydataOrderRefundIdKey, tydataOrderRefundPlatformRefundIdKey, tydataOrderRefundRefundNoKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -442,21 +416,20 @@ func (m *defaultOrderRefundModel) Delete(ctx context.Context, session sqlx.Sessi
|
||||
return err
|
||||
}
|
||||
|
||||
hmOrderRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundIdPrefix, id)
|
||||
hmOrderRefundOrderIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundOrderIdPrefix, data.OrderId)
|
||||
hmOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheHmOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
hmOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheHmOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
tydataOrderRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundIdPrefix, id)
|
||||
tydataOrderRefundPlatformRefundIdKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundPlatformRefundIdPrefix, data.PlatformRefundId)
|
||||
tydataOrderRefundRefundNoKey := fmt.Sprintf("%s%v", cacheTydataOrderRefundRefundNoPrefix, data.RefundNo)
|
||||
_, 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)
|
||||
}, hmOrderRefundIdKey, hmOrderRefundOrderIdKey, hmOrderRefundPlatformRefundIdKey, hmOrderRefundRefundNoKey)
|
||||
}, tydataOrderRefundIdKey, tydataOrderRefundPlatformRefundIdKey, tydataOrderRefundRefundNoKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultOrderRefundModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheHmOrderRefundIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTydataOrderRefundIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultOrderRefundModel) 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", orderRefundRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user