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 (
|
||||
agentActiveStatRowsExpectAutoSet = strings.Join(stringx.Remove(agentActiveStatFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentActiveStatRowsWithPlaceHolder = strings.Join(stringx.Remove(agentActiveStatFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheTydataAgentActiveStatIdPrefix = "cache:tydata:agentActiveStat:id:"
|
||||
cacheTydataAgentActiveStatAgentIdStatDatePrefix = "cache:tydata:agentActiveStat:agentId:statDate:"
|
||||
cacheQncAgentActiveStatIdPrefix = "cache:qnc:agentActiveStat:id:"
|
||||
cacheQncAgentActiveStatAgentIdStatDatePrefix = "cache:qnc:agentActiveStat:agentId:statDate:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -77,21 +77,21 @@ func newAgentActiveStatModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgent
|
||||
|
||||
func (m *defaultAgentActiveStatModel) Insert(ctx context.Context, session sqlx.Session, data *AgentActiveStat) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
tydataAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
tydataAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheTydataAgentActiveStatIdPrefix, data.Id)
|
||||
qncAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheQncAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
qncAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheQncAgentActiveStatIdPrefix, 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, agentActiveStatRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.StatDate, data.ActiveNumber, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.StatDate, data.ActiveNumber, data.DeleteTime, data.DelState, data.Version)
|
||||
}, tydataAgentActiveStatAgentIdStatDateKey, tydataAgentActiveStatIdKey)
|
||||
}, qncAgentActiveStatAgentIdStatDateKey, qncAgentActiveStatIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentActiveStatModel) FindOne(ctx context.Context, id int64) (*AgentActiveStat, error) {
|
||||
tydataAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheTydataAgentActiveStatIdPrefix, id)
|
||||
qncAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheQncAgentActiveStatIdPrefix, id)
|
||||
var resp AgentActiveStat
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataAgentActiveStatIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentActiveStatIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentActiveStatRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -106,9 +106,9 @@ func (m *defaultAgentActiveStatModel) FindOne(ctx context.Context, id int64) (*A
|
||||
}
|
||||
|
||||
func (m *defaultAgentActiveStatModel) FindOneByAgentIdStatDate(ctx context.Context, agentId int64, statDate time.Time) (*AgentActiveStat, error) {
|
||||
tydataAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentActiveStatAgentIdStatDatePrefix, agentId, statDate)
|
||||
qncAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheQncAgentActiveStatAgentIdStatDatePrefix, agentId, statDate)
|
||||
var resp AgentActiveStat
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tydataAgentActiveStatAgentIdStatDateKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncAgentActiveStatAgentIdStatDateKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `agent_id` = ? and `stat_date` = ? and del_state = ? limit 1", agentActiveStatRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, agentId, statDate, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -130,15 +130,15 @@ func (m *defaultAgentActiveStatModel) Update(ctx context.Context, session sqlx.S
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
tydataAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
tydataAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheTydataAgentActiveStatIdPrefix, data.Id)
|
||||
qncAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheQncAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
qncAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheQncAgentActiveStatIdPrefix, 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, agentActiveStatRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.AgentId, newData.StatDate, newData.ActiveNumber, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.AgentId, newData.StatDate, newData.ActiveNumber, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}, tydataAgentActiveStatAgentIdStatDateKey, tydataAgentActiveStatIdKey)
|
||||
}, qncAgentActiveStatAgentIdStatDateKey, qncAgentActiveStatIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentActiveStatModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *AgentActiveStat) error {
|
||||
@@ -153,15 +153,15 @@ func (m *defaultAgentActiveStatModel) UpdateWithVersion(ctx context.Context, ses
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
tydataAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
tydataAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheTydataAgentActiveStatIdPrefix, data.Id)
|
||||
qncAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheQncAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
qncAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheQncAgentActiveStatIdPrefix, 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, agentActiveStatRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.AgentId, newData.StatDate, newData.ActiveNumber, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.AgentId, newData.StatDate, newData.ActiveNumber, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}, tydataAgentActiveStatAgentIdStatDateKey, tydataAgentActiveStatIdKey)
|
||||
}, qncAgentActiveStatAgentIdStatDateKey, qncAgentActiveStatIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -180,7 +180,7 @@ func (m *defaultAgentActiveStatModel) DeleteSoft(ctx context.Context, session sq
|
||||
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 "), "AgentActiveStatModel delete err : %v", err)
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "AgentActiveStatModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -384,19 +384,19 @@ func (m *defaultAgentActiveStatModel) Delete(ctx context.Context, session sqlx.S
|
||||
return err
|
||||
}
|
||||
|
||||
tydataAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheTydataAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
tydataAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheTydataAgentActiveStatIdPrefix, id)
|
||||
qncAgentActiveStatAgentIdStatDateKey := fmt.Sprintf("%s%v:%v", cacheQncAgentActiveStatAgentIdStatDatePrefix, data.AgentId, data.StatDate)
|
||||
qncAgentActiveStatIdKey := fmt.Sprintf("%s%v", cacheQncAgentActiveStatIdPrefix, 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)
|
||||
}, tydataAgentActiveStatAgentIdStatDateKey, tydataAgentActiveStatIdKey)
|
||||
}, qncAgentActiveStatAgentIdStatDateKey, qncAgentActiveStatIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentActiveStatModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheTydataAgentActiveStatIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentActiveStatIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentActiveStatModel) 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", agentActiveStatRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user