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,9 +26,9 @@ var (
|
||||
agentClosureRowsExpectAutoSet = strings.Join(stringx.Remove(agentClosureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentClosureRowsWithPlaceHolder = strings.Join(stringx.Remove(agentClosureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheTydataAgentClosureIdPrefix = "cache:tydata:agentClosure:id:"
|
||||
cacheTydataAgentClosureAncestorIdDescendantIdPrefix = "cache:tydata:agentClosure:ancestorId:descendantId:"
|
||||
cacheTydataAgentClosureDescendantIdDepthPrefix = "cache:tydata:agentClosure:descendantId:depth:"
|
||||
cacheQncAgentClosureIdPrefix = "cache:qnc:agentClosure:id:"
|
||||
cacheQncAgentClosureAncestorIdDescendantIdPrefix = "cache:qnc:agentClosure:ancestorId:descendantId:"
|
||||
cacheQncAgentClosureDescendantIdDepthPrefix = "cache:qnc:agentClosure:descendantId:depth:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -79,22 +79,22 @@ func newAgentClosureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentClo
|
||||
|
||||
func (m *defaultAgentClosureModel) Insert(ctx context.Context, session sqlx.Session, data *AgentClosure) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
tydataAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
tydataAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
tydataAgentClosureIdKey := fmt.Sprintf("%s%v", cacheTydataAgentClosureIdPrefix, data.Id)
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
qncAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, 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, agentClosureRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AncestorId, data.DescendantId, data.Depth, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AncestorId, data.DescendantId, data.Depth, data.DeleteTime, data.DelState, data.Version)
|
||||
}, tydataAgentClosureAncestorIdDescendantIdKey, tydataAgentClosureDescendantIdDepthKey, tydataAgentClosureIdKey)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureDescendantIdDepthKey, qncAgentClosureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindOne(ctx context.Context, id int64) (*AgentClosure, error) {
|
||||
tydataAgentClosureIdKey := fmt.Sprintf("%s%v", cacheTydataAgentClosureIdPrefix, id)
|
||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, id)
|
||||
var resp AgentClosure
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataAgentClosureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentClosureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentClosureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -109,9 +109,9 @@ func (m *defaultAgentClosureModel) FindOne(ctx context.Context, id int64) (*Agen
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindOneByAncestorIdDescendantId(ctx context.Context, ancestorId int64, descendantId int64) (*AgentClosure, error) {
|
||||
tydataAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureAncestorIdDescendantIdPrefix, ancestorId, descendantId)
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, ancestorId, descendantId)
|
||||
var resp AgentClosure
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataAgentClosureAncestorIdDescendantIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncAgentClosureAncestorIdDescendantIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `ancestor_id` = ? and `descendant_id` = ? and del_state = ? limit 1", agentClosureRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, ancestorId, descendantId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -129,9 +129,9 @@ func (m *defaultAgentClosureModel) FindOneByAncestorIdDescendantId(ctx context.C
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindOneByDescendantIdDepth(ctx context.Context, descendantId int64, depth int64) (*AgentClosure, error) {
|
||||
tydataAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureDescendantIdDepthPrefix, descendantId, depth)
|
||||
qncAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureDescendantIdDepthPrefix, descendantId, depth)
|
||||
var resp AgentClosure
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataAgentClosureDescendantIdDepthKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncAgentClosureDescendantIdDepthKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `descendant_id` = ? and `depth` = ? and del_state = ? limit 1", agentClosureRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, descendantId, depth, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -153,16 +153,16 @@ func (m *defaultAgentClosureModel) Update(ctx context.Context, session sqlx.Sess
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tydataAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
tydataAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
tydataAgentClosureIdKey := fmt.Sprintf("%s%v", cacheTydataAgentClosureIdPrefix, data.Id)
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
qncAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, 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, agentClosureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}, tydataAgentClosureAncestorIdDescendantIdKey, tydataAgentClosureDescendantIdDepthKey, tydataAgentClosureIdKey)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureDescendantIdDepthKey, qncAgentClosureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *AgentClosure) error {
|
||||
@@ -177,16 +177,16 @@ func (m *defaultAgentClosureModel) UpdateWithVersion(ctx context.Context, sessio
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tydataAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
tydataAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
tydataAgentClosureIdKey := fmt.Sprintf("%s%v", cacheTydataAgentClosureIdPrefix, data.Id)
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
qncAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, 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, agentClosureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.AncestorId, newData.DescendantId, newData.Depth, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}, tydataAgentClosureAncestorIdDescendantIdKey, tydataAgentClosureDescendantIdDepthKey, tydataAgentClosureIdKey)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureDescendantIdDepthKey, qncAgentClosureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -205,7 +205,7 @@ func (m *defaultAgentClosureModel) DeleteSoft(ctx context.Context, session sqlx.
|
||||
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 "), "AgentClosureModel delete err : %v", err)
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "AgentClosureModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -409,20 +409,20 @@ func (m *defaultAgentClosureModel) Delete(ctx context.Context, session sqlx.Sess
|
||||
return err
|
||||
}
|
||||
|
||||
tydataAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
tydataAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
tydataAgentClosureIdKey := fmt.Sprintf("%s%v", cacheTydataAgentClosureIdPrefix, id)
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
qncAgentClosureDescendantIdDepthKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureDescendantIdDepthPrefix, data.DescendantId, data.Depth)
|
||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, 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)
|
||||
}, tydataAgentClosureAncestorIdDescendantIdKey, tydataAgentClosureDescendantIdDepthKey, tydataAgentClosureIdKey)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureDescendantIdDepthKey, qncAgentClosureIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentClosureModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheTydataAgentClosureIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentClosureModel) 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", agentClosureRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user