temp
This commit is contained in:
@@ -1,27 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ AgentAuditModel = (*customAgentAuditModel)(nil)
|
||||
|
||||
type (
|
||||
// AgentAuditModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customAgentAuditModel.
|
||||
AgentAuditModel interface {
|
||||
agentAuditModel
|
||||
}
|
||||
|
||||
customAgentAuditModel struct {
|
||||
*defaultAgentAuditModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewAgentAuditModel returns a model for the database table.
|
||||
func NewAgentAuditModel(conn sqlx.SqlConn, c cache.CacheConf) AgentAuditModel {
|
||||
return &customAgentAuditModel{
|
||||
defaultAgentAuditModel: newAgentAuditModel(conn, c),
|
||||
}
|
||||
}
|
||||
@@ -1,374 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"qnc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
agentAuditFieldNames = builder.RawFieldNames(&AgentAudit{})
|
||||
agentAuditRows = strings.Join(agentAuditFieldNames, ",")
|
||||
agentAuditRowsExpectAutoSet = strings.Join(stringx.Remove(agentAuditFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentAuditRowsWithPlaceHolder = strings.Join(stringx.Remove(agentAuditFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncAgentAuditIdPrefix = "cache:qnc:agentAudit:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
agentAuditModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*AgentAudit, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentAudit) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentAudit) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*AgentAudit, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentAudit, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentAudit, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
}
|
||||
|
||||
defaultAgentAuditModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
AgentAudit struct {
|
||||
Id int64 `db:"id"`
|
||||
UserId int64 `db:"user_id"`
|
||||
Region string `db:"region"`
|
||||
Mobile string `db:"mobile"`
|
||||
WechatId sql.NullString `db:"wechat_id"`
|
||||
Status int64 `db:"status"`
|
||||
AuditReason sql.NullString `db:"audit_reason"`
|
||||
CreateTime time.Time `db:"create_time"`
|
||||
AuditTime sql.NullTime `db:"audit_time"`
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
}
|
||||
)
|
||||
|
||||
func newAgentAuditModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentAuditModel {
|
||||
return &defaultAgentAuditModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`agent_audit`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) Insert(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, 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, agentAuditRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version)
|
||||
}, qncAgentAuditIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindOne(ctx context.Context, id int64) (*AgentAudit, error) {
|
||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, id)
|
||||
var resp AgentAudit
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentAuditIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", agentAuditRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) Update(ctx context.Context, session sqlx.Session, data *AgentAudit) (sql.Result, error) {
|
||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, 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, agentAuditRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}, qncAgentAuditIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentAudit) error {
|
||||
|
||||
oldVersion := data.Version
|
||||
data.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, 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, agentAuditRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.Status, data.AuditReason, data.AuditTime, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}, qncAgentAuditIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentAudit) error {
|
||||
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 "), "AgentAuditModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentAudit, error) {
|
||||
|
||||
builder = builder.Columns(agentAuditRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentAudit
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, error) {
|
||||
|
||||
builder = builder.Columns(agentAuditRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentAudit
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentAudit, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(agentAuditRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*AgentAudit
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentAudit, error) {
|
||||
|
||||
builder = builder.Columns(agentAuditRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentAudit
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentAudit, error) {
|
||||
|
||||
builder = builder.Columns(agentAuditRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentAudit
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentAuditModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
qncAgentAuditIdKey := fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, 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)
|
||||
}, qncAgentAuditIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentAuditModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentAuditIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentAuditModel) 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", agentAuditRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultAgentAuditModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ AgentClosureModel = (*customAgentClosureModel)(nil)
|
||||
|
||||
type (
|
||||
// AgentClosureModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customAgentClosureModel.
|
||||
AgentClosureModel interface {
|
||||
agentClosureModel
|
||||
}
|
||||
|
||||
customAgentClosureModel struct {
|
||||
*defaultAgentClosureModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewAgentClosureModel returns a model for the database table.
|
||||
func NewAgentClosureModel(conn sqlx.SqlConn, c cache.CacheConf) AgentClosureModel {
|
||||
return &customAgentClosureModel{
|
||||
defaultAgentClosureModel: newAgentClosureModel(conn, c),
|
||||
}
|
||||
}
|
||||
@@ -1,409 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"qnc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
agentClosureFieldNames = builder.RawFieldNames(&AgentClosure{})
|
||||
agentClosureRows = strings.Join(agentClosureFieldNames, ",")
|
||||
agentClosureRowsExpectAutoSet = strings.Join(stringx.Remove(agentClosureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentClosureRowsWithPlaceHolder = strings.Join(stringx.Remove(agentClosureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncAgentClosureIdPrefix = "cache:qnc:agentClosure:id:"
|
||||
cacheQncAgentClosureAncestorIdDescendantIdPrefix = "cache:qnc:agentClosure:ancestorId:descendantId:"
|
||||
)
|
||||
|
||||
type (
|
||||
agentClosureModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *AgentClosure) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*AgentClosure, error)
|
||||
FindOneByAncestorIdDescendantId(ctx context.Context, ancestorId int64, descendantId int64) (*AgentClosure, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *AgentClosure) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentClosure) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentClosure) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*AgentClosure, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentClosure, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentClosure, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
}
|
||||
|
||||
defaultAgentClosureModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
AgentClosure struct {
|
||||
Id int64 `db:"id"`
|
||||
AncestorId int64 `db:"ancestor_id"`
|
||||
DescendantId int64 `db:"descendant_id"`
|
||||
Depth int64 `db:"depth"`
|
||||
CreateTime time.Time `db:"create_time"`
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
}
|
||||
)
|
||||
|
||||
func newAgentClosureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentClosureModel {
|
||||
return &defaultAgentClosureModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`agent_closure`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) Insert(ctx context.Context, session sqlx.Session, data *AgentClosure) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
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)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindOne(ctx context.Context, id int64) (*AgentClosure, error) {
|
||||
qncAgentClosureIdKey := fmt.Sprintf("%s%v", cacheQncAgentClosureIdPrefix, id)
|
||||
var resp AgentClosure
|
||||
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)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindOneByAncestorIdDescendantId(ctx context.Context, ancestorId int64, descendantId int64) (*AgentClosure, error) {
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, ancestorId, descendantId)
|
||||
var resp AgentClosure
|
||||
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
|
||||
}
|
||||
return resp.Id, nil
|
||||
}, m.queryPrimary)
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) Update(ctx context.Context, session sqlx.Session, newData *AgentClosure) (sql.Result, error) {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
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)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *AgentClosure) error {
|
||||
|
||||
oldVersion := newData.Version
|
||||
newData.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
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)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentClosure) error {
|
||||
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 nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentClosure, error) {
|
||||
|
||||
builder = builder.Columns(agentClosureRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentClosure
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, error) {
|
||||
|
||||
builder = builder.Columns(agentClosureRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentClosure
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentClosure, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(agentClosureRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*AgentClosure
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentClosure, error) {
|
||||
|
||||
builder = builder.Columns(agentClosureRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentClosure
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentClosure, error) {
|
||||
|
||||
builder = builder.Columns(agentClosureRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentClosure
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentClosureModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
qncAgentClosureAncestorIdDescendantIdKey := fmt.Sprintf("%s%v:%v", cacheQncAgentClosureAncestorIdDescendantIdPrefix, data.AncestorId, data.DescendantId)
|
||||
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)
|
||||
}, qncAgentClosureAncestorIdDescendantIdKey, qncAgentClosureIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentClosureModel) formatPrimary(primary interface{}) string {
|
||||
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)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultAgentClosureModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ AgentCommissionModel = (*customAgentCommissionModel)(nil)
|
||||
|
||||
type (
|
||||
// AgentCommissionModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customAgentCommissionModel.
|
||||
AgentCommissionModel interface {
|
||||
agentCommissionModel
|
||||
}
|
||||
|
||||
customAgentCommissionModel struct {
|
||||
*defaultAgentCommissionModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewAgentCommissionModel returns a model for the database table.
|
||||
func NewAgentCommissionModel(conn sqlx.SqlConn, c cache.CacheConf) AgentCommissionModel {
|
||||
return &customAgentCommissionModel{
|
||||
defaultAgentCommissionModel: newAgentCommissionModel(conn, c),
|
||||
}
|
||||
}
|
||||
@@ -1,371 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"qnc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
agentCommissionFieldNames = builder.RawFieldNames(&AgentCommission{})
|
||||
agentCommissionRows = strings.Join(agentCommissionFieldNames, ",")
|
||||
agentCommissionRowsExpectAutoSet = strings.Join(stringx.Remove(agentCommissionFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentCommissionRowsWithPlaceHolder = strings.Join(stringx.Remove(agentCommissionFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncAgentCommissionIdPrefix = "cache:qnc:agentCommission:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
agentCommissionModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*AgentCommission, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommission) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentCommission) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*AgentCommission, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentCommission, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentCommission, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
}
|
||||
|
||||
defaultAgentCommissionModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
AgentCommission struct {
|
||||
Id int64 `db:"id"`
|
||||
AgentId int64 `db:"agent_id"`
|
||||
OrderId int64 `db:"order_id"`
|
||||
CommissionAmount float64 `db:"commission_amount"`
|
||||
Status int64 `db:"status"`
|
||||
CreateTime time.Time `db:"create_time"`
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
}
|
||||
)
|
||||
|
||||
func newAgentCommissionModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentCommissionModel {
|
||||
return &defaultAgentCommissionModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`agent_commission`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) Insert(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, 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, agentCommissionRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version)
|
||||
}, qncAgentCommissionIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindOne(ctx context.Context, id int64) (*AgentCommission, error) {
|
||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, id)
|
||||
var resp AgentCommission
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentCommissionIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", agentCommissionRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) Update(ctx context.Context, session sqlx.Session, data *AgentCommission) (sql.Result, error) {
|
||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, 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, agentCommissionRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}, qncAgentCommissionIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentCommission) error {
|
||||
|
||||
oldVersion := data.Version
|
||||
data.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, 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, agentCommissionRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.OrderId, data.CommissionAmount, data.Status, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}, qncAgentCommissionIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentCommission) error {
|
||||
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 "), "AgentCommissionModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentCommission, error) {
|
||||
|
||||
builder = builder.Columns(agentCommissionRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentCommission
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, error) {
|
||||
|
||||
builder = builder.Columns(agentCommissionRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentCommission
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentCommission, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(agentCommissionRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*AgentCommission
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentCommission, error) {
|
||||
|
||||
builder = builder.Columns(agentCommissionRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentCommission
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentCommission, error) {
|
||||
|
||||
builder = builder.Columns(agentCommissionRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentCommission
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentCommissionModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
qncAgentCommissionIdKey := fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, 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)
|
||||
}, qncAgentCommissionIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentCommissionModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentCommissionIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentCommissionModel) 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", agentCommissionRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultAgentCommissionModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ AgentModel = (*customAgentModel)(nil)
|
||||
|
||||
type (
|
||||
// AgentModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customAgentModel.
|
||||
AgentModel interface {
|
||||
agentModel
|
||||
}
|
||||
|
||||
customAgentModel struct {
|
||||
*defaultAgentModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewAgentModel returns a model for the database table.
|
||||
func NewAgentModel(conn sqlx.SqlConn, c cache.CacheConf) AgentModel {
|
||||
return &customAgentModel{
|
||||
defaultAgentModel: newAgentModel(conn, c),
|
||||
}
|
||||
}
|
||||
@@ -1,409 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"qnc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
agentFieldNames = builder.RawFieldNames(&Agent{})
|
||||
agentRows = strings.Join(agentFieldNames, ",")
|
||||
agentRowsExpectAutoSet = strings.Join(stringx.Remove(agentFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentRowsWithPlaceHolder = strings.Join(stringx.Remove(agentFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncAgentIdPrefix = "cache:qnc:agent:id:"
|
||||
cacheQncAgentUserIdPrefix = "cache:qnc:agent:userId:"
|
||||
)
|
||||
|
||||
type (
|
||||
agentModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *Agent) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*Agent, error)
|
||||
FindOneByUserId(ctx context.Context, userId int64) (*Agent, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *Agent) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *Agent) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *Agent) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*Agent, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*Agent, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*Agent, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
}
|
||||
|
||||
defaultAgentModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
Agent struct {
|
||||
Id int64 `db:"id"`
|
||||
UserId int64 `db:"user_id"`
|
||||
Region string `db:"region"`
|
||||
Mobile string `db:"mobile"`
|
||||
WechatId sql.NullString `db:"wechat_id"`
|
||||
CreateTime time.Time `db:"create_time"`
|
||||
UpdateTime time.Time `db:"update_time"`
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
}
|
||||
)
|
||||
|
||||
func newAgentModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentModel {
|
||||
return &defaultAgentModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`agent`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) Insert(ctx context.Context, session sqlx.Session, data *Agent) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, data.Id)
|
||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
||||
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, agentRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.UserId, data.Region, data.Mobile, data.WechatId, data.DeleteTime, data.DelState, data.Version)
|
||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindOne(ctx context.Context, id int64) (*Agent, error) {
|
||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, id)
|
||||
var resp Agent
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", agentRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindOneByUserId(ctx context.Context, userId int64) (*Agent, error) {
|
||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, userId)
|
||||
var resp Agent
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncAgentUserIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `user_id` = ? and del_state = ? limit 1", agentRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, userId, 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 *defaultAgentModel) Update(ctx context.Context, session sqlx.Session, newData *Agent) (sql.Result, error) {
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, data.Id)
|
||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
||||
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, agentRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id)
|
||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Agent) error {
|
||||
|
||||
oldVersion := newData.Version
|
||||
newData.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
data, err := m.FindOne(ctx, newData.Id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, data.Id)
|
||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
||||
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, agentRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.UserId, newData.Region, newData.Mobile, newData.WechatId, newData.DeleteTime, newData.DelState, newData.Version, newData.Id, oldVersion)
|
||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *Agent) error {
|
||||
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 "), "AgentModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*Agent, error) {
|
||||
|
||||
builder = builder.Columns(agentRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*Agent
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, error) {
|
||||
|
||||
builder = builder.Columns(agentRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*Agent
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*Agent, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(agentRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*Agent
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*Agent, error) {
|
||||
|
||||
builder = builder.Columns(agentRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*Agent
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*Agent, error) {
|
||||
|
||||
builder = builder.Columns(agentRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*Agent
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
data, err := m.FindOne(ctx, id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
qncAgentIdKey := fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, id)
|
||||
qncAgentUserIdKey := fmt.Sprintf("%s%v", cacheQncAgentUserIdPrefix, data.UserId)
|
||||
_, 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)
|
||||
}, qncAgentIdKey, qncAgentUserIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentModel) 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", agentRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultAgentModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
)
|
||||
|
||||
var _ AgentWalletModel = (*customAgentWalletModel)(nil)
|
||||
|
||||
type (
|
||||
// AgentWalletModel is an interface to be customized, add more methods here,
|
||||
// and implement the added methods in customAgentWalletModel.
|
||||
AgentWalletModel interface {
|
||||
agentWalletModel
|
||||
}
|
||||
|
||||
customAgentWalletModel struct {
|
||||
*defaultAgentWalletModel
|
||||
}
|
||||
)
|
||||
|
||||
// NewAgentWalletModel returns a model for the database table.
|
||||
func NewAgentWalletModel(conn sqlx.SqlConn, c cache.CacheConf) AgentWalletModel {
|
||||
return &customAgentWalletModel{
|
||||
defaultAgentWalletModel: newAgentWalletModel(conn, c),
|
||||
}
|
||||
}
|
||||
@@ -1,372 +0,0 @@
|
||||
// Code generated by goctl. DO NOT EDIT!
|
||||
|
||||
package model
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
|
||||
"github.com/Masterminds/squirrel"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/zeromicro/go-zero/core/stores/builder"
|
||||
"github.com/zeromicro/go-zero/core/stores/cache"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
||||
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
||||
"github.com/zeromicro/go-zero/core/stringx"
|
||||
"qnc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
agentWalletFieldNames = builder.RawFieldNames(&AgentWallet{})
|
||||
agentWalletRows = strings.Join(agentWalletFieldNames, ",")
|
||||
agentWalletRowsExpectAutoSet = strings.Join(stringx.Remove(agentWalletFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
agentWalletRowsWithPlaceHolder = strings.Join(stringx.Remove(agentWalletFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncAgentWalletIdPrefix = "cache:qnc:agentWallet:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
agentWalletModel interface {
|
||||
Insert(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*AgentWallet, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentWallet) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
SelectBuilder() squirrel.SelectBuilder
|
||||
DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentWallet) error
|
||||
FindSum(ctx context.Context, sumBuilder squirrel.SelectBuilder, field string) (float64, error)
|
||||
FindCount(ctx context.Context, countBuilder squirrel.SelectBuilder, field string) (int64, error)
|
||||
FindAll(ctx context.Context, rowBuilder squirrel.SelectBuilder, orderBy string) ([]*AgentWallet, error)
|
||||
FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, error)
|
||||
FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, int64, error)
|
||||
FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentWallet, error)
|
||||
FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentWallet, error)
|
||||
Delete(ctx context.Context, session sqlx.Session, id int64) error
|
||||
}
|
||||
|
||||
defaultAgentWalletModel struct {
|
||||
sqlc.CachedConn
|
||||
table string
|
||||
}
|
||||
|
||||
AgentWallet struct {
|
||||
Id int64 `db:"id"`
|
||||
AgentId int64 `db:"agent_id"`
|
||||
Balance float64 `db:"balance"`
|
||||
FrozenBalance float64 `db:"frozen_balance"`
|
||||
TotalEarnings float64 `db:"total_earnings"`
|
||||
WithdrawnAmount float64 `db:"withdrawn_amount"`
|
||||
CreateTime time.Time `db:"create_time"`
|
||||
UpdateTime time.Time `db:"update_time"`
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
}
|
||||
)
|
||||
|
||||
func newAgentWalletModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultAgentWalletModel {
|
||||
return &defaultAgentWalletModel{
|
||||
CachedConn: sqlc.NewConn(conn, c),
|
||||
table: "`agent_wallet`",
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) Insert(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, 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, agentWalletRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version)
|
||||
}, qncAgentWalletIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindOne(ctx context.Context, id int64) (*AgentWallet, error) {
|
||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, id)
|
||||
var resp AgentWallet
|
||||
err := m.QueryRowCtx(ctx, &resp, qncAgentWalletIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", agentWalletRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) Update(ctx context.Context, session sqlx.Session, data *AgentWallet) (sql.Result, error) {
|
||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, 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, agentWalletRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id)
|
||||
}, qncAgentWalletIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *AgentWallet) error {
|
||||
|
||||
oldVersion := data.Version
|
||||
data.Version += 1
|
||||
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, 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, agentWalletRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.AgentId, data.Balance, data.FrozenBalance, data.TotalEarnings, data.WithdrawnAmount, data.DeleteTime, data.DelState, data.Version, data.Id, oldVersion)
|
||||
}, qncAgentWalletIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
updateCount, err := sqlResult.RowsAffected()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *AgentWallet) error {
|
||||
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 "), "AgentWalletModel delete err : %+v", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindSum(ctx context.Context, builder squirrel.SelectBuilder, field string) (float64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindSum Least One Field"), "FindSum Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("IFNULL(SUM(" + field + "),0)")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp float64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindCount(ctx context.Context, builder squirrel.SelectBuilder, field string) (int64, error) {
|
||||
|
||||
if len(field) == 0 {
|
||||
return 0, errors.Wrapf(errors.New("FindCount Least One Field"), "FindCount Least One Field")
|
||||
}
|
||||
|
||||
builder = builder.Columns("COUNT(" + field + ")")
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
var resp int64
|
||||
err = m.QueryRowNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*AgentWallet, error) {
|
||||
|
||||
builder = builder.Columns(agentWalletRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentWallet
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, error) {
|
||||
|
||||
builder = builder.Columns(agentWalletRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentWallet
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*AgentWallet, int64, error) {
|
||||
|
||||
total, err := m.FindCount(ctx, builder, "id")
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
||||
builder = builder.Columns(agentWalletRows)
|
||||
|
||||
if orderBy == "" {
|
||||
builder = builder.OrderBy("id DESC")
|
||||
} else {
|
||||
builder = builder.OrderBy(orderBy)
|
||||
}
|
||||
|
||||
if page < 1 {
|
||||
page = 1
|
||||
}
|
||||
offset := (page - 1) * pageSize
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).Offset(uint64(offset)).Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, total, err
|
||||
}
|
||||
|
||||
var resp []*AgentWallet
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, total, nil
|
||||
default:
|
||||
return nil, total, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*AgentWallet, error) {
|
||||
|
||||
builder = builder.Columns(agentWalletRows)
|
||||
|
||||
if preMinId > 0 {
|
||||
builder = builder.Where(" id < ? ", preMinId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id DESC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentWallet
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*AgentWallet, error) {
|
||||
|
||||
builder = builder.Columns(agentWalletRows)
|
||||
|
||||
if preMaxId > 0 {
|
||||
builder = builder.Where(" id > ? ", preMaxId)
|
||||
}
|
||||
|
||||
query, values, err := builder.Where("del_state = ?", globalkey.DelStateNo).OrderBy("id ASC").Limit(uint64(pageSize)).ToSql()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var resp []*AgentWallet
|
||||
err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
|
||||
switch err {
|
||||
case nil:
|
||||
return resp, nil
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) Trans(ctx context.Context, fn func(ctx context.Context, session sqlx.Session) error) error {
|
||||
|
||||
return m.TransactCtx(ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
return fn(ctx, session)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) SelectBuilder() squirrel.SelectBuilder {
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultAgentWalletModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
qncAgentWalletIdKey := fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, 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)
|
||||
}, qncAgentWalletIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultAgentWalletModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncAgentWalletIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultAgentWalletModel) 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", agentWalletRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
func (m *defaultAgentWalletModel) tableName() string {
|
||||
return m.table
|
||||
}
|
||||
@@ -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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,8 +26,8 @@ var (
|
||||
exampleRowsExpectAutoSet = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
exampleRowsWithPlaceHolder = strings.Join(stringx.Remove(exampleFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncExampleIdPrefix = "cache:qnc:example:id:"
|
||||
cacheQncExampleProductIdPrefix = "cache:qnc:example:productId:"
|
||||
cacheTycExampleIdPrefix = "cache:tyc:example:id:"
|
||||
cacheTycExampleProductIdPrefix = "cache:tyc:example:productId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -77,21 +77,21 @@ func newExampleModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultExampleModel
|
||||
|
||||
func (m *defaultExampleModel) Insert(ctx context.Context, session sqlx.Session, data *Example) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||
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, exampleRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.ProductId, data.QueryParams, data.QueryData, data.DelState, data.Version, data.DeleteTime)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultExampleModel) FindOne(ctx context.Context, id int64) (*Example, error) {
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, id)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, id)
|
||||
var resp Example
|
||||
err := m.QueryRowCtx(ctx, &resp, qncExampleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tycExampleIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -106,9 +106,9 @@ func (m *defaultExampleModel) FindOne(ctx context.Context, id int64) (*Example,
|
||||
}
|
||||
|
||||
func (m *defaultExampleModel) FindOneByProductId(ctx context.Context, productId int64) (*Example, error) {
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, productId)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, productId)
|
||||
var resp Example
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncExampleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycExampleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_id` = ? and del_state = ? limit 1", exampleRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -130,15 +130,15 @@ func (m *defaultExampleModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||
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, exampleRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultExampleModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Example) error {
|
||||
@@ -153,15 +153,15 @@ func (m *defaultExampleModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, data.Id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, data.Id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||
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, exampleRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.QueryParams, newData.QueryData, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -384,19 +384,19 @@ func (m *defaultExampleModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncExampleIdKey := fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, id)
|
||||
qncExampleProductIdKey := fmt.Sprintf("%s%v", cacheQncExampleProductIdPrefix, data.ProductId)
|
||||
tycExampleIdKey := fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, id)
|
||||
tycExampleProductIdKey := fmt.Sprintf("%s%v", cacheTycExampleProductIdPrefix, data.ProductId)
|
||||
_, 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)
|
||||
}, qncExampleIdKey, qncExampleProductIdKey)
|
||||
}, tycExampleIdKey, tycExampleProductIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultExampleModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncExampleIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycExampleIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultExampleModel) 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", exampleRows, m.table)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
@@ -18,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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,8 +26,8 @@ var (
|
||||
featureRowsExpectAutoSet = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
featureRowsWithPlaceHolder = strings.Join(stringx.Remove(featureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncFeatureIdPrefix = "cache:qnc:feature:id:"
|
||||
cacheQncFeatureApiIdPrefix = "cache:qnc:feature:apiId:"
|
||||
cacheTycFeatureIdPrefix = "cache:tyc:feature:id:"
|
||||
cacheTycFeatureApiIdPrefix = "cache:tyc:feature:apiId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -77,39 +76,39 @@ func newFeatureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultFeatureModel
|
||||
|
||||
func (m *defaultFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *Feature) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
||||
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, 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, featureRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?)", m.table, featureRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ApiId, data.Name)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultFeatureModel) FindOne(ctx context.Context, id int64) (*Feature, error) {
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id)
|
||||
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, id)
|
||||
var resp Feature
|
||||
err := m.QueryRowCtx(ctx, &resp, qncFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", featureRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tycFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string) (*Feature, error) {
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, apiId)
|
||||
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, apiId)
|
||||
var resp Feature
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `api_id` = ? AND del_state = ? limit 1", featureRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycFeatureApiIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `api_id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, apiId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -119,7 +118,7 @@ func (m *defaultFeatureModel) FindOneByApiId(ctx context.Context, apiId string)
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -130,15 +129,15 @@ func (m *defaultFeatureModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
||||
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, 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, featureRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, featureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Feature) error {
|
||||
@@ -153,15 +152,15 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, data.Id)
|
||||
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, 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, featureRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, featureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ApiId, newData.Name, newData.Id, oldVersion)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -170,7 +169,7 @@ func (m *defaultFeatureModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -384,22 +383,22 @@ func (m *defaultFeatureModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncFeatureApiIdKey := fmt.Sprintf("%s%v", cacheQncFeatureApiIdPrefix, data.ApiId)
|
||||
qncFeatureIdKey := fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, id)
|
||||
tycFeatureApiIdKey := fmt.Sprintf("%s%v", cacheTycFeatureApiIdPrefix, data.ApiId)
|
||||
tycFeatureIdKey := fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, 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)
|
||||
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)
|
||||
}, qncFeatureApiIdKey, qncFeatureIdKey)
|
||||
}, tycFeatureApiIdKey, tycFeatureIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultFeatureModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncFeatureIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycFeatureIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultFeatureModel) 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", featureRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", featureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
model2 "qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
@@ -18,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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,7 +26,7 @@ var (
|
||||
globalNotificationsRowsExpectAutoSet = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
globalNotificationsRowsWithPlaceHolder = strings.Join(stringx.Remove(globalNotificationsFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncGlobalNotificationsIdPrefix = "cache:qnc:globalNotifications:id:"
|
||||
cacheTycGlobalNotificationsIdPrefix = "cache:tyc:globalNotifications:id:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -81,20 +80,20 @@ func newGlobalNotificationsModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultG
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) Insert(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
||||
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, 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, globalNotificationsRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tycGlobalNotificationsIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64) (*GlobalNotifications, error) {
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, id)
|
||||
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, id)
|
||||
var resp GlobalNotifications
|
||||
err := m.QueryRowCtx(ctx, &resp, qncGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tycGlobalNotificationsIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", globalNotificationsRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -102,21 +101,21 @@ func (m *defaultGlobalNotificationsModel) FindOne(ctx context.Context, id int64)
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model2.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) Update(ctx context.Context, session sqlx.Session, data *GlobalNotifications) (sql.Result, error) {
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
||||
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, 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, globalNotificationsRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tycGlobalNotificationsIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, data *GlobalNotifications) error {
|
||||
@@ -127,14 +126,14 @@ func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context,
|
||||
var sqlResult sql.Result
|
||||
var err error
|
||||
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, data.Id)
|
||||
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, 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, globalNotificationsRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.Title, data.Content, data.NotificationPage, data.StartDate, data.EndDate, data.StartTime, data.EndTime, data.Status, data.DelState, data.Version, data.DeleteTime, data.Id, oldVersion)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tycGlobalNotificationsIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -143,7 +142,7 @@ func (m *defaultGlobalNotificationsModel) UpdateWithVersion(ctx context.Context,
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model2.ErrNoRowsUpdate
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -352,18 +351,18 @@ func (m *defaultGlobalNotificationsModel) SelectBuilder() squirrel.SelectBuilder
|
||||
return squirrel.Select().From(m.table)
|
||||
}
|
||||
func (m *defaultGlobalNotificationsModel) Delete(ctx context.Context, session sqlx.Session, id int64) error {
|
||||
qncGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, id)
|
||||
tycGlobalNotificationsIdKey := fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, 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)
|
||||
}, qncGlobalNotificationsIdKey)
|
||||
}, tycGlobalNotificationsIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultGlobalNotificationsModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncGlobalNotificationsIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycGlobalNotificationsIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultGlobalNotificationsModel) 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", globalNotificationsRows, m.table)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
@@ -18,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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,8 +26,8 @@ var (
|
||||
orderRowsExpectAutoSet = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
orderRowsWithPlaceHolder = strings.Join(stringx.Remove(orderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncOrderIdPrefix = "cache:qnc:order:id:"
|
||||
cacheQncOrderOrderNoPrefix = "cache:qnc:order:orderNo:"
|
||||
cacheTycOrderIdPrefix = "cache:tyc:order:id:"
|
||||
cacheTycOrderOrderNoPrefix = "cache:tyc:order:orderNo:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -61,8 +60,8 @@ type (
|
||||
OrderNo string `db:"order_no"` // 自生成的订单号
|
||||
UserId int64 `db:"user_id"` // 用户ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID(软关联到产品表)
|
||||
PaymentPlatform string `db:"payment_platform"` // 支付平台(支付宝、微信、其他)
|
||||
PaymentScene string `db:"payment_scene"` // 支付场景(App、H5、微信小程序、公众号)
|
||||
PaymentPlatform string `db:"payment_platform"` // 支付平台(支付宝、微信、苹果内购、其他)
|
||||
PaymentScene string `db:"payment_scene"` // 支付场景(App、H5、微信小程序、公众号、天远查)
|
||||
PlatformOrderId sql.NullString `db:"platform_order_id"` // 支付平台订单号
|
||||
Amount float64 `db:"amount"` // 支付金额
|
||||
Status string `db:"status"` // 支付状态
|
||||
@@ -86,39 +85,39 @@ func newOrderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultOrderModel {
|
||||
|
||||
func (m *defaultOrderModel) Insert(ctx context.Context, session sqlx.Session, data *Order) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, data.Id)
|
||||
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||
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, orderRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, orderRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.OrderNo, data.UserId, data.ProductId, data.PaymentPlatform, data.PaymentScene, data.PlatformOrderId, data.Amount, data.Status, data.DelState, data.Version, data.PayTime, data.RefundTime, data.CloseTime, data.DeleteTime)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||
}
|
||||
|
||||
func (m *defaultOrderModel) FindOne(ctx context.Context, id int64) (*Order, error) {
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, id)
|
||||
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, id)
|
||||
var resp Order
|
||||
err := m.QueryRowCtx(ctx, &resp, qncOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", orderRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tycOrderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string) (*Order, error) {
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, orderNo)
|
||||
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, orderNo)
|
||||
var resp Order
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncOrderOrderNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `order_no` = ? AND del_state = ? limit 1", orderRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycOrderOrderNoKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `order_no` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderNo, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -128,7 +127,7 @@ func (m *defaultOrderModel) FindOneByOrderNo(ctx context.Context, orderNo string
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -139,15 +138,15 @@ func (m *defaultOrderModel) Update(ctx context.Context, session sqlx.Session, ne
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, data.Id)
|
||||
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||
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, orderRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, orderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||
}
|
||||
|
||||
func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Order) error {
|
||||
@@ -162,15 +161,15 @@ func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, data.Id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, data.Id)
|
||||
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||
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, orderRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, orderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderNo, newData.UserId, newData.ProductId, newData.PaymentPlatform, newData.PaymentScene, newData.PlatformOrderId, newData.Amount, newData.Status, newData.DelState, newData.Version, newData.PayTime, newData.RefundTime, newData.CloseTime, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -179,7 +178,7 @@ func (m *defaultOrderModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -393,22 +392,22 @@ func (m *defaultOrderModel) Delete(ctx context.Context, session sqlx.Session, id
|
||||
return err
|
||||
}
|
||||
|
||||
qncOrderIdKey := fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, id)
|
||||
qncOrderOrderNoKey := fmt.Sprintf("%s%v", cacheQncOrderOrderNoPrefix, data.OrderNo)
|
||||
tycOrderIdKey := fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, id)
|
||||
tycOrderOrderNoKey := fmt.Sprintf("%s%v", cacheTycOrderOrderNoPrefix, data.OrderNo)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncOrderIdKey, qncOrderOrderNoKey)
|
||||
}, tycOrderIdKey, tycOrderOrderNoKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultOrderModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncOrderIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycOrderIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultOrderModel) 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", orderRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", orderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
@@ -18,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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,9 +26,8 @@ var (
|
||||
productFeatureRowsExpectAutoSet = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
productFeatureRowsWithPlaceHolder = strings.Join(stringx.Remove(productFeatureFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncProductFeatureIdPrefix = "cache:qnc:productFeature:id:"
|
||||
cacheQncProductFeatureProductIdFeatureIdPrefix = "cache:qnc:productFeature:productId:featureId:"
|
||||
cacheQncProductFeatureProductIdSortPrefix = "cache:qnc:productFeature:productId:sort:"
|
||||
cacheTycProductFeatureIdPrefix = "cache:tyc:productFeature:id:"
|
||||
cacheTycProductFeatureProductIdFeatureIdPrefix = "cache:tyc:productFeature:productId:featureId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -37,7 +35,6 @@ type (
|
||||
Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
||||
FindOne(ctx context.Context, id int64) (*ProductFeature, error)
|
||||
FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error)
|
||||
FindOneByProductIdSort(ctx context.Context, productId int64, sort int64) (*ProductFeature, error)
|
||||
Update(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error)
|
||||
UpdateWithVersion(ctx context.Context, session sqlx.Session, data *ProductFeature) error
|
||||
Trans(ctx context.Context, fn func(context context.Context, session sqlx.Session) error) error
|
||||
@@ -59,16 +56,17 @@ type (
|
||||
}
|
||||
|
||||
ProductFeature struct {
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID
|
||||
FeatureId int64 `db:"feature_id"` // 功能ID
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
Sort int64 `db:"sort"` // 排序字段
|
||||
IsImportant int64 `db:"is_important"` // 是否重要,1为重要,0为不重要
|
||||
Id int64 `db:"id"` // 主键ID
|
||||
ProductId int64 `db:"product_id"` // 产品ID
|
||||
FeatureId int64 `db:"feature_id"` // 功能ID
|
||||
CreateTime time.Time `db:"create_time"` // 创建时间
|
||||
UpdateTime time.Time `db:"update_time"` // 更新时间
|
||||
DeleteTime sql.NullTime `db:"delete_time"` // 删除时间
|
||||
DelState int64 `db:"del_state"` // 删除状态
|
||||
Version int64 `db:"version"` // 版本号
|
||||
Sort int64 `db:"sort"`
|
||||
Enable int64 `db:"enable"`
|
||||
IsImportant int64 `db:"is_important"`
|
||||
}
|
||||
)
|
||||
|
||||
@@ -81,40 +79,39 @@ func newProductFeatureModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProduc
|
||||
|
||||
func (m *defaultProductFeatureModel) Insert(ctx context.Context, session sqlx.Session, data *ProductFeature) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, data.Id)
|
||||
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
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, productFeatureRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?)", m.table, productFeatureRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant)
|
||||
return session.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.Enable, data.IsImportant)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.IsImportant)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||
return conn.ExecCtx(ctx, query, data.ProductId, data.FeatureId, data.DeleteTime, data.DelState, data.Version, data.Sort, data.Enable, data.IsImportant)
|
||||
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductFeatureModel) FindOne(ctx context.Context, id int64) (*ProductFeature, error) {
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
||||
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, id)
|
||||
var resp ProductFeature
|
||||
err := m.QueryRowCtx(ctx, &resp, qncProductFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tycProductFeatureIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Context, productId int64, featureId int64) (*ProductFeature, error) {
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, productId, featureId)
|
||||
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, productId, featureId)
|
||||
var resp ProductFeature
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductFeatureProductIdFeatureIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_id` = ? AND `feature_id` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycProductFeatureProductIdFeatureIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_id` = ? and `feature_id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, featureId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -124,27 +121,7 @@ func (m *defaultProductFeatureModel) FindOneByProductIdFeatureId(ctx context.Con
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductFeatureModel) FindOneByProductIdSort(ctx context.Context, productId int64, sort int64) (*ProductFeature, error) {
|
||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, productId, sort)
|
||||
var resp ProductFeature
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductFeatureProductIdSortKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_id` = ? AND `sort` = ? AND del_state = ? limit 1", productFeatureRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productId, sort, 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, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -155,16 +132,15 @@ func (m *defaultProductFeatureModel) Update(ctx context.Context, session sqlx.Se
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, data.Id)
|
||||
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
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, productFeatureRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productFeatureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id)
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id)
|
||||
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductFeature) error {
|
||||
@@ -179,16 +155,15 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, data.Id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, data.Id)
|
||||
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
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, productFeatureRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productFeatureRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id, oldVersion)
|
||||
return session.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.IsImportant, newData.Id, oldVersion)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||
return conn.ExecCtx(ctx, query, newData.ProductId, newData.FeatureId, newData.DeleteTime, newData.DelState, newData.Version, newData.Sort, newData.Enable, newData.IsImportant, newData.Id, oldVersion)
|
||||
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -197,7 +172,7 @@ func (m *defaultProductFeatureModel) UpdateWithVersion(ctx context.Context, sess
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -411,23 +386,22 @@ func (m *defaultProductFeatureModel) Delete(ctx context.Context, session sqlx.Se
|
||||
return err
|
||||
}
|
||||
|
||||
qncProductFeatureIdKey := fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, id)
|
||||
qncProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
qncProductFeatureProductIdSortKey := fmt.Sprintf("%s%v:%v", cacheQncProductFeatureProductIdSortPrefix, data.ProductId, data.Sort)
|
||||
tycProductFeatureIdKey := fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, id)
|
||||
tycProductFeatureProductIdFeatureIdKey := fmt.Sprintf("%s%v:%v", cacheTycProductFeatureProductIdFeatureIdPrefix, data.ProductId, data.FeatureId)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncProductFeatureIdKey, qncProductFeatureProductIdFeatureIdKey, qncProductFeatureProductIdSortKey)
|
||||
}, tycProductFeatureIdKey, tycProductFeatureProductIdFeatureIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultProductFeatureModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncProductFeatureIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycProductFeatureIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultProductFeatureModel) 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", productFeatureRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productFeatureRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
@@ -18,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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,8 +26,8 @@ var (
|
||||
productRowsExpectAutoSet = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
productRowsWithPlaceHolder = strings.Join(stringx.Remove(productFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncProductIdPrefix = "cache:qnc:product:id:"
|
||||
cacheQncProductProductEnPrefix = "cache:qnc:product:productEn:"
|
||||
cacheTycProductIdPrefix = "cache:tyc:product:id:"
|
||||
cacheTycProductProductEnPrefix = "cache:tyc:product:productEn:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -81,39 +80,39 @@ func newProductModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProductModel
|
||||
|
||||
func (m *defaultProductModel) Insert(ctx context.Context, session sqlx.Session, data *Product) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, data.Id)
|
||||
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||
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, productRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, productRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.ProductName, data.ProductEn, data.Description, data.Notes, data.CostPrice, data.SellPrice)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tycProductIdKey, tycProductProductEnKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductModel) FindOne(ctx context.Context, id int64) (*Product, error) {
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, id)
|
||||
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, id)
|
||||
var resp Product
|
||||
err := m.QueryRowCtx(ctx, &resp, qncProductIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", productRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tycProductIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultProductModel) FindOneByProductEn(ctx context.Context, productEn string) (*Product, error) {
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, productEn)
|
||||
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, productEn)
|
||||
var resp Product
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductProductEnKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `product_en` = ? AND del_state = ? limit 1", productRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycProductProductEnKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `product_en` = ? and del_state = ? limit 1", productRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, productEn, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,7 +122,7 @@ func (m *defaultProductModel) FindOneByProductEn(ctx context.Context, productEn
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,15 +133,15 @@ func (m *defaultProductModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, data.Id)
|
||||
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||
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, productRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, productRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tycProductIdKey, tycProductProductEnKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Product) error {
|
||||
@@ -157,15 +156,15 @@ func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, data.Id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, data.Id)
|
||||
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||
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, productRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, productRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.ProductName, newData.ProductEn, newData.Description, newData.Notes, newData.CostPrice, newData.SellPrice, newData.Id, oldVersion)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tycProductIdKey, tycProductProductEnKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -174,7 +173,7 @@ func (m *defaultProductModel) UpdateWithVersion(ctx context.Context, session sql
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -388,22 +387,22 @@ func (m *defaultProductModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncProductIdKey := fmt.Sprintf("%s%v", cacheQncProductIdPrefix, id)
|
||||
qncProductProductEnKey := fmt.Sprintf("%s%v", cacheQncProductProductEnPrefix, data.ProductEn)
|
||||
tycProductIdKey := fmt.Sprintf("%s%v", cacheTycProductIdPrefix, id)
|
||||
tycProductProductEnKey := fmt.Sprintf("%s%v", cacheTycProductProductEnPrefix, data.ProductEn)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncProductIdKey, qncProductProductEnKey)
|
||||
}, tycProductIdKey, tycProductProductEnKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultProductModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncProductIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycProductIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultProductModel) 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", productRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,8 +26,8 @@ var (
|
||||
productRenderRowsExpectAutoSet = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
productRenderRowsWithPlaceHolder = strings.Join(stringx.Remove(productRenderFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncProductRenderIdPrefix = "cache:qnc:productRender:id:"
|
||||
cacheQncProductRenderPlatformModuleProductIdPrefix = "cache:qnc:productRender:platform:module:productId:"
|
||||
cacheTycProductRenderIdPrefix = "cache:tyc:productRender:id:"
|
||||
cacheTycProductRenderPlatformModuleProductIdPrefix = "cache:tyc:productRender:platform:module:productId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -78,21 +78,21 @@ func newProductRenderModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultProduct
|
||||
|
||||
func (m *defaultProductRenderModel) Insert(ctx context.Context, session sqlx.Session, data *ProductRender) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
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, productRenderRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Platform, data.Module, data.ProductId, data.IsRendered)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*ProductRender, error) {
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, id)
|
||||
var resp ProductRender
|
||||
err := m.QueryRowCtx(ctx, &resp, qncProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tycProductRenderIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -107,9 +107,9 @@ func (m *defaultProductRenderModel) FindOne(ctx context.Context, id int64) (*Pro
|
||||
}
|
||||
|
||||
func (m *defaultProductRenderModel) FindOneByPlatformModuleProductId(ctx context.Context, platform string, module string, productId int64) (*ProductRender, error) {
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, platform, module, productId)
|
||||
var resp ProductRender
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycProductRenderPlatformModuleProductIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `platform` = ? and `module` = ? and `product_id` = ? and del_state = ? limit 1", productRenderRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, platform, module, productId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -131,15 +131,15 @@ func (m *defaultProductRenderModel) Update(ctx context.Context, session sqlx.Ses
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
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, productRenderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *ProductRender) error {
|
||||
@@ -154,15 +154,15 @@ func (m *defaultProductRenderModel) UpdateWithVersion(ctx context.Context, sessi
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, data.Id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, data.Id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
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, productRenderRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Platform, newData.Module, newData.ProductId, newData.IsRendered, newData.Id, oldVersion)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -385,19 +385,19 @@ func (m *defaultProductRenderModel) Delete(ctx context.Context, session sqlx.Ses
|
||||
return err
|
||||
}
|
||||
|
||||
qncProductRenderIdKey := fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, id)
|
||||
qncProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheQncProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
tycProductRenderIdKey := fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, id)
|
||||
tycProductRenderPlatformModuleProductIdKey := fmt.Sprintf("%s%v:%v:%v", cacheTycProductRenderPlatformModuleProductIdPrefix, data.Platform, data.Module, data.ProductId)
|
||||
_, 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)
|
||||
}, qncProductRenderIdKey, qncProductRenderPlatformModuleProductIdKey)
|
||||
}, tycProductRenderIdKey, tycProductRenderPlatformModuleProductIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultProductRenderModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncProductRenderIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycProductRenderIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultProductRenderModel) 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", productRenderRows, m.table)
|
||||
|
||||
@@ -6,7 +6,6 @@ import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"qnc-server/deploy/script/model"
|
||||
"strings"
|
||||
|
||||
"time"
|
||||
@@ -18,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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -27,8 +26,8 @@ var (
|
||||
queryRowsExpectAutoSet = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
queryRowsWithPlaceHolder = strings.Join(stringx.Remove(queryFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncQueryIdPrefix = "cache:qnc:query:id:"
|
||||
cacheQncQueryOrderIdPrefix = "cache:qnc:query:orderId:"
|
||||
cacheTycQueryIdPrefix = "cache:tyc:query:id:"
|
||||
cacheTycQueryOrderIdPrefix = "cache:tyc:query:orderId:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -81,39 +80,39 @@ func newQueryModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultQueryModel {
|
||||
|
||||
func (m *defaultQueryModel) Insert(ctx context.Context, session sqlx.Session, data *Query) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, data.Id)
|
||||
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||
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, queryRowsExpectAutoSet)
|
||||
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, queryRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.OrderId, data.UserId, data.ProductId, data.QueryParams, data.QueryData, data.QueryState, data.DelState, data.Version, data.DeleteTime)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultQueryModel) FindOne(ctx context.Context, id int64) (*Query, error) {
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, id)
|
||||
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, id)
|
||||
var resp Query
|
||||
err := m.QueryRowCtx(ctx, &resp, qncQueryIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("SELECT %s FROM %s WHERE `id` = ? AND del_state = ? limit 1", queryRows, m.table)
|
||||
err := m.QueryRowCtx(ctx, &resp, tycQueryIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
switch err {
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
func (m *defaultQueryModel) FindOneByOrderId(ctx context.Context, orderId int64) (*Query, error) {
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, orderId)
|
||||
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, orderId)
|
||||
var resp Query
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncQueryOrderIdKey, 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", queryRows, m.table)
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycQueryOrderIdKey, 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", queryRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, orderId, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -123,7 +122,7 @@ func (m *defaultQueryModel) FindOneByOrderId(ctx context.Context, orderId int64)
|
||||
case nil:
|
||||
return &resp, nil
|
||||
case sqlc.ErrNotFound:
|
||||
return nil, model.ErrNotFound
|
||||
return nil, ErrNotFound
|
||||
default:
|
||||
return nil, err
|
||||
}
|
||||
@@ -134,15 +133,15 @@ func (m *defaultQueryModel) Update(ctx context.Context, session sqlx.Session, ne
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, data.Id)
|
||||
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||
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, queryRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, queryRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||
}
|
||||
|
||||
func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *Query) error {
|
||||
@@ -157,15 +156,15 @@ func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, data.Id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, data.Id)
|
||||
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||
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, queryRowsWithPlaceHolder)
|
||||
query := fmt.Sprintf("update %s set %s where `id` = ? and version = ? ", m.table, queryRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.OrderId, newData.UserId, newData.ProductId, newData.QueryParams, newData.QueryData, newData.QueryState, newData.DelState, newData.Version, newData.DeleteTime, newData.Id, oldVersion)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -174,7 +173,7 @@ func (m *defaultQueryModel) UpdateWithVersion(ctx context.Context, session sqlx.
|
||||
return err
|
||||
}
|
||||
if updateCount == 0 {
|
||||
return model.ErrNoRowsUpdate
|
||||
return ErrNoRowsUpdate
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -388,22 +387,22 @@ func (m *defaultQueryModel) Delete(ctx context.Context, session sqlx.Session, id
|
||||
return err
|
||||
}
|
||||
|
||||
qncQueryIdKey := fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, id)
|
||||
qncQueryOrderIdKey := fmt.Sprintf("%s%v", cacheQncQueryOrderIdPrefix, data.OrderId)
|
||||
tycQueryIdKey := fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, id)
|
||||
tycQueryOrderIdKey := fmt.Sprintf("%s%v", cacheTycQueryOrderIdPrefix, data.OrderId)
|
||||
_, 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)
|
||||
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)
|
||||
}, qncQueryIdKey, qncQueryOrderIdKey)
|
||||
}, tycQueryIdKey, tycQueryOrderIdKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultQueryModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncQueryIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycQueryIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultQueryModel) 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", queryRows, m.table)
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", queryRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
|
||||
}
|
||||
|
||||
|
||||
@@ -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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,9 +26,9 @@ var (
|
||||
userAuthRowsExpectAutoSet = strings.Join(stringx.Remove(userAuthFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
userAuthRowsWithPlaceHolder = strings.Join(stringx.Remove(userAuthFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncUserAuthIdPrefix = "cache:qnc:userAuth:id:"
|
||||
cacheQncUserAuthAuthTypeAuthKeyPrefix = "cache:qnc:userAuth:authType:authKey:"
|
||||
cacheQncUserAuthUserIdAuthTypePrefix = "cache:qnc:userAuth:userId:authType:"
|
||||
cacheTycUserAuthIdPrefix = "cache:tyc:userAuth:id:"
|
||||
cacheTycUserAuthAuthTypeAuthKeyPrefix = "cache:tyc:userAuth:authType:authKey:"
|
||||
cacheTycUserAuthUserIdAuthTypePrefix = "cache:tyc:userAuth:userId:authType:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -79,22 +79,22 @@ func newUserAuthModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserAuthMode
|
||||
|
||||
func (m *defaultUserAuthModel) Insert(ctx context.Context, session sqlx.Session, data *UserAuth) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tycUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tycUserAuthIdKey := fmt.Sprintf("%s%v", cacheTycUserAuthIdPrefix, data.Id)
|
||||
tycUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
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, userAuthRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.UserId, data.AuthKey, data.AuthType)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.UserId, data.AuthKey, data.AuthType)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tycUserAuthAuthTypeAuthKeyKey, tycUserAuthIdKey, tycUserAuthUserIdAuthTypeKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) FindOne(ctx context.Context, id int64) (*UserAuth, error) {
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, id)
|
||||
tycUserAuthIdKey := fmt.Sprintf("%s%v", cacheTycUserAuthIdPrefix, id)
|
||||
var resp UserAuth
|
||||
err := m.QueryRowCtx(ctx, &resp, qncUserAuthIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tycUserAuthIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userAuthRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -109,9 +109,9 @@ func (m *defaultUserAuthModel) FindOne(ctx context.Context, id int64) (*UserAuth
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) FindOneByAuthTypeAuthKey(ctx context.Context, authType string, authKey string) (*UserAuth, error) {
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, authType, authKey)
|
||||
tycUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthAuthTypeAuthKeyPrefix, authType, authKey)
|
||||
var resp UserAuth
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncUserAuthAuthTypeAuthKeyKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycUserAuthAuthTypeAuthKeyKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `auth_type` = ? and `auth_key` = ? and del_state = ? limit 1", userAuthRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, authType, authKey, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -129,9 +129,9 @@ func (m *defaultUserAuthModel) FindOneByAuthTypeAuthKey(ctx context.Context, aut
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) FindOneByUserIdAuthType(ctx context.Context, userId int64, authType string) (*UserAuth, error) {
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, userId, authType)
|
||||
tycUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthUserIdAuthTypePrefix, userId, authType)
|
||||
var resp UserAuth
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncUserAuthUserIdAuthTypeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycUserAuthUserIdAuthTypeKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `user_id` = ? and `auth_type` = ? and del_state = ? limit 1", userAuthRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, userId, authType, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -153,16 +153,16 @@ func (m *defaultUserAuthModel) Update(ctx context.Context, session sqlx.Session,
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tycUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tycUserAuthIdKey := fmt.Sprintf("%s%v", cacheTycUserAuthIdPrefix, data.Id)
|
||||
tycUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
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, userAuthRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tycUserAuthAuthTypeAuthKeyKey, tycUserAuthIdKey, tycUserAuthUserIdAuthTypeKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserAuthModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *UserAuth) error {
|
||||
@@ -177,16 +177,16 @@ func (m *defaultUserAuthModel) UpdateWithVersion(ctx context.Context, session sq
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, data.Id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tycUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tycUserAuthIdKey := fmt.Sprintf("%s%v", cacheTycUserAuthIdPrefix, data.Id)
|
||||
tycUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
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, userAuthRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.UserId, newData.AuthKey, newData.AuthType, newData.Id, oldVersion)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tycUserAuthAuthTypeAuthKeyKey, tycUserAuthIdKey, tycUserAuthUserIdAuthTypeKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -409,20 +409,20 @@ func (m *defaultUserAuthModel) Delete(ctx context.Context, session sqlx.Session,
|
||||
return err
|
||||
}
|
||||
|
||||
qncUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
qncUserAuthIdKey := fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, id)
|
||||
qncUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheQncUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
tycUserAuthAuthTypeAuthKeyKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthAuthTypeAuthKeyPrefix, data.AuthType, data.AuthKey)
|
||||
tycUserAuthIdKey := fmt.Sprintf("%s%v", cacheTycUserAuthIdPrefix, id)
|
||||
tycUserAuthUserIdAuthTypeKey := fmt.Sprintf("%s%v:%v", cacheTycUserAuthUserIdAuthTypePrefix, data.UserId, data.AuthType)
|
||||
_, 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)
|
||||
}, qncUserAuthAuthTypeAuthKeyKey, qncUserAuthIdKey, qncUserAuthUserIdAuthTypeKey)
|
||||
}, tycUserAuthAuthTypeAuthKeyKey, tycUserAuthIdKey, tycUserAuthUserIdAuthTypeKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultUserAuthModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncUserAuthIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycUserAuthIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultUserAuthModel) 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", userAuthRows, m.table)
|
||||
|
||||
@@ -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"
|
||||
"qnc-server/common/globalkey"
|
||||
"tyc-server/common/globalkey"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -26,8 +26,8 @@ var (
|
||||
userRowsExpectAutoSet = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), ",")
|
||||
userRowsWithPlaceHolder = strings.Join(stringx.Remove(userFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"
|
||||
|
||||
cacheQncUserIdPrefix = "cache:qnc:user:id:"
|
||||
cacheQncUserMobilePrefix = "cache:qnc:user:mobile:"
|
||||
cacheTycUserIdPrefix = "cache:tyc:user:id:"
|
||||
cacheTycUserMobilePrefix = "cache:tyc:user:mobile:"
|
||||
)
|
||||
|
||||
type (
|
||||
@@ -64,7 +64,7 @@ type (
|
||||
Version int64 `db:"version"` // 版本号
|
||||
Mobile string `db:"mobile"`
|
||||
Password sql.NullString `db:"password"`
|
||||
Nickname string `db:"nickname"`
|
||||
Nickname sql.NullString `db:"nickname"`
|
||||
Info string `db:"info"`
|
||||
Inside int64 `db:"inside"`
|
||||
}
|
||||
@@ -79,21 +79,21 @@ func newUserModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserModel {
|
||||
|
||||
func (m *defaultUserModel) Insert(ctx context.Context, session sqlx.Session, data *User) (sql.Result, error) {
|
||||
data.DelState = globalkey.DelStateNo
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, data.Id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tycUserIdKey := fmt.Sprintf("%s%v", cacheTycUserIdPrefix, data.Id)
|
||||
tycUserMobileKey := fmt.Sprintf("%s%v", cacheTycUserMobilePrefix, data.Mobile)
|
||||
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, userRowsExpectAutoSet)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, data.DeleteTime, data.DelState, data.Version, data.Mobile, data.Password, data.Nickname, data.Info, data.Inside)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tycUserIdKey, tycUserMobileKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error) {
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, id)
|
||||
tycUserIdKey := fmt.Sprintf("%s%v", cacheTycUserIdPrefix, id)
|
||||
var resp User
|
||||
err := m.QueryRowCtx(ctx, &resp, qncUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
err := m.QueryRowCtx(ctx, &resp, tycUserIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
|
||||
query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userRows, m.table)
|
||||
return conn.QueryRowCtx(ctx, v, query, id, globalkey.DelStateNo)
|
||||
})
|
||||
@@ -108,9 +108,9 @@ func (m *defaultUserModel) FindOne(ctx context.Context, id int64) (*User, error)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) FindOneByMobile(ctx context.Context, mobile string) (*User, error) {
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, mobile)
|
||||
tycUserMobileKey := fmt.Sprintf("%s%v", cacheTycUserMobilePrefix, mobile)
|
||||
var resp User
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, qncUserMobileKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
err := m.QueryRowIndexCtx(ctx, &resp, tycUserMobileKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
|
||||
query := fmt.Sprintf("select %s from %s where `mobile` = ? and del_state = ? limit 1", userRows, m.table)
|
||||
if err := conn.QueryRowCtx(ctx, &resp, query, mobile, globalkey.DelStateNo); err != nil {
|
||||
return nil, err
|
||||
@@ -132,15 +132,15 @@ func (m *defaultUserModel) Update(ctx context.Context, session sqlx.Session, new
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, data.Id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tycUserIdKey := fmt.Sprintf("%s%v", cacheTycUserIdPrefix, data.Id)
|
||||
tycUserMobileKey := fmt.Sprintf("%s%v", cacheTycUserMobilePrefix, data.Mobile)
|
||||
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, userRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tycUserIdKey, tycUserMobileKey)
|
||||
}
|
||||
|
||||
func (m *defaultUserModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *User) error {
|
||||
@@ -155,15 +155,15 @@ func (m *defaultUserModel) UpdateWithVersion(ctx context.Context, session sqlx.S
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, data.Id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tycUserIdKey := fmt.Sprintf("%s%v", cacheTycUserIdPrefix, data.Id)
|
||||
tycUserMobileKey := fmt.Sprintf("%s%v", cacheTycUserMobilePrefix, data.Mobile)
|
||||
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, userRowsWithPlaceHolder)
|
||||
if session != nil {
|
||||
return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id, oldVersion)
|
||||
}
|
||||
return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.Mobile, newData.Password, newData.Nickname, newData.Info, newData.Inside, newData.Id, oldVersion)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tycUserIdKey, tycUserMobileKey)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -386,19 +386,19 @@ func (m *defaultUserModel) Delete(ctx context.Context, session sqlx.Session, id
|
||||
return err
|
||||
}
|
||||
|
||||
qncUserIdKey := fmt.Sprintf("%s%v", cacheQncUserIdPrefix, id)
|
||||
qncUserMobileKey := fmt.Sprintf("%s%v", cacheQncUserMobilePrefix, data.Mobile)
|
||||
tycUserIdKey := fmt.Sprintf("%s%v", cacheTycUserIdPrefix, id)
|
||||
tycUserMobileKey := fmt.Sprintf("%s%v", cacheTycUserMobilePrefix, data.Mobile)
|
||||
_, 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)
|
||||
}, qncUserIdKey, qncUserMobileKey)
|
||||
}, tycUserIdKey, tycUserMobileKey)
|
||||
return err
|
||||
}
|
||||
func (m *defaultUserModel) formatPrimary(primary interface{}) string {
|
||||
return fmt.Sprintf("%s%v", cacheQncUserIdPrefix, primary)
|
||||
return fmt.Sprintf("%s%v", cacheTycUserIdPrefix, primary)
|
||||
}
|
||||
func (m *defaultUserModel) 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", userRows, m.table)
|
||||
|
||||
Reference in New Issue
Block a user