new version qnc
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"
|
||||
"tydata-server/common/globalkey"
|
||||
"qnc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,8 +26,8 @@ var (
|
||||
agentLinkRowsExpectAutoSet = strings.Join(stringx.Remove(agentLinkFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentLinkRowsWithPlaceHolder = strings.Join(stringx.Remove(agentLinkFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheTydataAgentLinkIdPrefix = "cache:tydata:agentLink:id:"
|
||||
cacheTydataAgentLinkLinkIdentifierPrefix = "cache:tydata:agentLink:linkIdentifier:"
|
||||
cacheQncAgentLinkIdPrefix = "cache:qnc:agentLink:id:"
|
||||
cacheQncAgentLinkLinkIdentifierPrefix = "cache:qnc:agentLink:linkIdentifier:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -79,21 +79,21 @@ func newAgentLinkModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentLinkMo
|
||||
|
||||
func (m *defaultAgentLinkModel) Insert(ctx context.Context, session sqlx.Session, data *AgentLink) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
tydataAgentLinkIdKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkIdPrefix, data.Id)
|
||||
tydataAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
qncAgentLinkIdKey := fmt.Sprintf("%s%v", cacheQncAgentLinkIdPrefix, data.Id)
|
||||
qncAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheQncAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
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, agentLinkRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.ProductId, data.Price, data.UserId, data.AgentId, data.LinkIdentifier, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.ProductId, data.Price, data.UserId, data.AgentId, data.LinkIdentifier, data.DeleteTime, data.DelState, data.Version)
|
||||
}, tydataAgentLinkIdKey, tydataAgentLinkLinkIdentifierKey)
|
||||
}, qncAgentLinkIdKey, qncAgentLinkLinkIdentifierKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentLinkModel) FindOne(ctx context.Context, id int64) (*AgentLink, error) {
|
||||
tydataAgentLinkIdKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkIdPrefix, id)
|
||||
qncAgentLinkIdKey := fmt.Sprintf("%s%v", cacheQncAgentLinkIdPrefix, id)
|
||||
var resp AgentLink
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataAgentLinkIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentLinkIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentLinkRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -108,9 +108,9 @@ func (m *defaultAgentLinkModel) FindOne(ctx context.Context, id int64) (*AgentLi
|
||||
}
|
||||
|
||||
func (m *defaultAgentLinkModel) FindOneByLinkIdentifier(ctx context.Context, linkIdentifier string) (*AgentLink, error) {
|
||||
tydataAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkLinkIdentifierPrefix, linkIdentifier)
|
||||
qncAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheQncAgentLinkLinkIdentifierPrefix, linkIdentifier)
|
||||
var resp AgentLink
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataAgentLinkLinkIdentifierKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncAgentLinkLinkIdentifierKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `link_identifier` = ? and del_state = ? limit 1", agentLinkRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, linkIdentifier, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -132,15 +132,15 @@ func (m *defaultAgentLinkModel) Update(ctx context.Context, session sqlx.Session
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tydataAgentLinkIdKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkIdPrefix, data.Id)
|
||||
tydataAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
qncAgentLinkIdKey := fmt.Sprintf("%s%v", cacheQncAgentLinkIdPrefix, data.Id)
|
||||
qncAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheQncAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
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, agentLinkRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.Price, newData.UserId, newData.AgentId, newData.LinkIdentifier, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.Price, newData.UserId, newData.AgentId, newData.LinkIdentifier, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}, tydataAgentLinkIdKey, tydataAgentLinkLinkIdentifierKey)
|
||||
}, qncAgentLinkIdKey, qncAgentLinkLinkIdentifierKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentLinkModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *AgentLink) error {
|
||||
@@ -155,15 +155,15 @@ func (m *defaultAgentLinkModel) UpdateWithVersion(ctx context.Context, session s
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tydataAgentLinkIdKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkIdPrefix, data.Id)
|
||||
tydataAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
qncAgentLinkIdKey := fmt.Sprintf("%s%v", cacheQncAgentLinkIdPrefix, data.Id)
|
||||
qncAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheQncAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
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, agentLinkRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.Price, newData.UserId, newData.AgentId, newData.LinkIdentifier, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.Price, newData.UserId, newData.AgentId, newData.LinkIdentifier, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}, tydataAgentLinkIdKey, tydataAgentLinkLinkIdentifierKey)
|
||||
}, qncAgentLinkIdKey, qncAgentLinkLinkIdentifierKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -182,7 +182,7 @@ func (m *defaultAgentLinkModel) DeleteSoft(ctx context.Context, session sqlx.Ses
|
||||
data.DelState = globalkey.DelStateYes
|
||||
data.DeleteTime = sql.NullTime{Time: time.Now(), Valid: true}
|
||||
if err := m.UpdateWithVersion(ctx, session, data); err != nil {
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "AgentLinkModel delete err : %v", err)
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "AgentLinkModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -386,19 +386,19 @@ func (m *defaultAgentLinkModel) Delete(ctx context.Context, session sqlx.Session
|
||||
return err
|
||||
}
|
||||
|
||||
tydataAgentLinkIdKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkIdPrefix, id)
|
||||
tydataAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheTydataAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
qncAgentLinkIdKey := fmt.Sprintf("%s%v", cacheQncAgentLinkIdPrefix, id)
|
||||
qncAgentLinkLinkIdentifierKey := fmt.Sprintf("%s%v", cacheQncAgentLinkLinkIdentifierPrefix, data.LinkIdentifier)
|
||||
_, 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)
|
||||
}, tydataAgentLinkIdKey, tydataAgentLinkLinkIdentifierKey)
|
||||
}, qncAgentLinkIdKey, qncAgentLinkLinkIdentifierKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentLinkModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheTydataAgentLinkIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentLinkIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentLinkModel) 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", agentLinkRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user