new version qnc
This commit is contained in:
@@ -17,16 +17,16 @@ 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 (
|
||||
agentPlatformDeductionFieldNames = builder.RawFieldNames(&AgentPlatformDeduction{})
|
||||
agentPlatformDeductionRows = strings.Join(agentPlatformDeductionFieldNames, ",")
|
||||
agentPlatformDeductionRowsExpectAutoSet = strings.Join(stringx.Remove(agentPlatformDeductionFieldNames, "`create_time`", "`update_time`"), ",")
|
||||
agentPlatformDeductionRowsExpectAutoSet = strings.Join(stringx.Remove(agentPlatformDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentPlatformDeductionRowsWithPlaceHolder = strings.Join(stringx.Remove(agentPlatformDeductionFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheTydataAgentPlatformDeductionIdPrefix = "cache:tydata:agentPlatformDeduction:id:"
|
||||
cacheQncAgentPlatformDeductionIdPrefix = "cache:qnc:agentPlatformDeduction:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -76,20 +76,20 @@ func newAgentPlatformDeductionModel(conn sqlx.SqlConn, c cache.CacheConf) *defau
|
||||
|
||||
func (m *defaultAgentPlatformDeductionModel) Insert(ctx context.Context, session sqlx.Session, data *AgentPlatformDeduction) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
tydataAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentPlatformDeductionIdPrefix, data.Id)
|
||||
qncAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheQncAgentPlatformDeductionIdPrefix, 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, agentPlatformDeductionRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, agentPlatformDeductionRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Id, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Id, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
}, tydataAgentPlatformDeductionIdKey)
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
}, qncAgentPlatformDeductionIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentPlatformDeductionModel) FindOne(ctx context.Context, id int64) (*AgentPlatformDeduction, error) {
|
||||
tydataAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentPlatformDeductionIdPrefix, id)
|
||||
qncAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheQncAgentPlatformDeductionIdPrefix, id)
|
||||
var resp AgentPlatformDeduction
|
||||
err := m.QueryRowCtx(ctx, &resp, tydataAgentPlatformDeductionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentPlatformDeductionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentPlatformDeductionRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -104,14 +104,14 @@ func (m *defaultAgentPlatformDeductionModel) FindOne(ctx context.Context, id int
|
||||
}
|
||||
|
||||
func (m *defaultAgentPlatformDeductionModel) Update(ctx context.Context, session sqlx.Session, data *AgentPlatformDeduction) (sql.Result, error) {
|
||||
tydataAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentPlatformDeductionIdPrefix, data.Id)
|
||||
qncAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheQncAgentPlatformDeductionIdPrefix, 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, agentPlatformDeductionRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}, tydataAgentPlatformDeductionIdKey)
|
||||
}, qncAgentPlatformDeductionIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentPlatformDeductionModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentPlatformDeduction) error {
|
||||
@@ -122,14 +122,14 @@ func (m *defaultAgentPlatformDeductionModel) UpdateWithVersion(ctx context.Conte
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
tydataAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentPlatformDeductionIdPrefix, data.Id)
|
||||
qncAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheQncAgentPlatformDeductionIdPrefix, 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, agentPlatformDeductionRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Amount, data.Type, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}, tydataAgentPlatformDeductionIdKey)
|
||||
}, qncAgentPlatformDeductionIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -148,7 +148,7 @@ func (m *defaultAgentPlatformDeductionModel) DeleteSoft(ctx context.Context, 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 "), "AgentPlatformDeductionModel delete err : %v", err)
|
||||
return errors.Wrapf(errors.New("delete soft failed "), "AgentPlatformDeductionModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@@ -347,18 +347,18 @@ func (m *defaultAgentPlatformDeductionModel) SelectBuilder() squirrel.SelectBuil
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentPlatformDeductionModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
tydataAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheTydataAgentPlatformDeductionIdPrefix, id)
|
||||
qncAgentPlatformDeductionIdKey := fmt.Sprintf("%s%v", cacheQncAgentPlatformDeductionIdPrefix, 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)
|
||||
}, tydataAgentPlatformDeductionIdKey)
|
||||
}, qncAgentPlatformDeductionIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentPlatformDeductionModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheTydataAgentPlatformDeductionIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentPlatformDeductionIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentPlatformDeductionModel) 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", agentPlatformDeductionRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user