transfer_middleware/genModel/marketReseller/resellerMerchantModel_gen.go

209 lines
10 KiB
Go
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Code generated by goctl. DO NOT EDIT.
package marketReseller
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"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"
)
var (
resellerMerchantFieldNames = builder.RawFieldNames(&ResellerMerchant{})
resellerMerchantRows = strings.Join(resellerMerchantFieldNames, ",")
resellerMerchantRowsExpectAutoSet = strings.Join(stringx.Remove(resellerMerchantFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
resellerMerchantRowsWithPlaceHolder = strings.Join(stringx.Remove(resellerMerchantFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
cacheResellerResellerMerchantIdPrefix = "cache:reseller:resellerMerchant:id:"
cacheResellerResellerMerchantAppIdPrefix = "cache:reseller:resellerMerchant:appId:"
cacheResellerResellerMerchantMerchantIdPrefix = "cache:reseller:resellerMerchant:merchantId:"
cacheResellerResellerMerchantPosIdPrefix = "cache:reseller:resellerMerchant:posId:"
)
type (
resellerMerchantModel interface {
Insert(ctx context.Context, data *ResellerMerchant) (sql.Result, error)
FindOne(ctx context.Context, id uint64) (*ResellerMerchant, error)
FindOneByAppId(ctx context.Context, appId string) (*ResellerMerchant, error)
FindOneByMerchantId(ctx context.Context, merchantId string) (*ResellerMerchant, error)
FindOneByPosId(ctx context.Context, posId string) (*ResellerMerchant, error)
Update(ctx context.Context, data *ResellerMerchant) error
Delete(ctx context.Context, id uint64) error
}
defaultResellerMerchantModel struct {
sqlc.CachedConn
table string
}
ResellerMerchant struct {
Id uint64 `db:"id"`
MerchantId string `db:"merchant_id"` // 商户号
ResellerId uint64 `db:"reseller_id"` // 分销商id
PosId string `db:"pos_id"` // 平台id 目前都是单平台
AppId string `db:"app_id"` // appid。目前都是单应用 通知地址 事件地址都针对于这一个应用配置
StoreId string `db:"store_id"` // 没有门店,兴业银行需求。 当作后期的扩展字段
ApiMode int64 `db:"api_mode"` // 对接类型 1-RSA+标准接口返回【默认】2-兴业银行模式
PublicKey sql.NullString `db:"public_key"` // 公钥
PrivateKey sql.NullString `db:"private_key"` // 私钥
MerchantPublicKey sql.NullString `db:"merchant_public_key"` // 客户侧公钥
SecretKey string `db:"secret_key"` // body加解密密钥
NotifyUrl sql.NullString `db:"notify_url"` // 通知地址配置
SubscribeEvent sql.NullString `db:"subscribe_event"` // 订阅事件
Status uint64 `db:"status"` // 状态 1正常 2禁用
UpdateTime sql.NullTime `db:"update_time"` // 编辑时间
CreateTime time.Time `db:"create_time"` // 创建时间
}
)
func newResellerMerchantModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultResellerMerchantModel {
return &defaultResellerMerchantModel{
CachedConn: sqlc.NewConn(conn, c, opts...),
table: "`reseller_merchant`",
}
}
func (m *defaultResellerMerchantModel) Delete(ctx context.Context, id uint64) error {
data, err := m.FindOne(ctx, id)
if err != nil {
return err
}
resellerResellerMerchantAppIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantAppIdPrefix, data.AppId)
resellerResellerMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantIdPrefix, id)
resellerResellerMerchantMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantMerchantIdPrefix, data.MerchantId)
resellerResellerMerchantPosIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantPosIdPrefix, data.PosId)
_, 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)
return conn.ExecCtx(ctx, query, id)
}, resellerResellerMerchantAppIdKey, resellerResellerMerchantIdKey, resellerResellerMerchantMerchantIdKey, resellerResellerMerchantPosIdKey)
return err
}
func (m *defaultResellerMerchantModel) FindOne(ctx context.Context, id uint64) (*ResellerMerchant, error) {
resellerResellerMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantIdPrefix, id)
var resp ResellerMerchant
err := m.QueryRowCtx(ctx, &resp, resellerResellerMerchantIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resellerMerchantRows, m.table)
return conn.QueryRowCtx(ctx, v, query, id)
})
switch err {
case nil:
return &resp, nil
case sqlc.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultResellerMerchantModel) FindOneByAppId(ctx context.Context, appId string) (*ResellerMerchant, error) {
resellerResellerMerchantAppIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantAppIdPrefix, appId)
var resp ResellerMerchant
err := m.QueryRowIndexCtx(ctx, &resp, resellerResellerMerchantAppIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `app_id` = ? limit 1", resellerMerchantRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, appId); 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 *defaultResellerMerchantModel) FindOneByMerchantId(ctx context.Context, merchantId string) (*ResellerMerchant, error) {
resellerResellerMerchantMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantMerchantIdPrefix, merchantId)
var resp ResellerMerchant
err := m.QueryRowIndexCtx(ctx, &resp, resellerResellerMerchantMerchantIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `merchant_id` = ? limit 1", resellerMerchantRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, merchantId); 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 *defaultResellerMerchantModel) FindOneByPosId(ctx context.Context, posId string) (*ResellerMerchant, error) {
resellerResellerMerchantPosIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantPosIdPrefix, posId)
var resp ResellerMerchant
err := m.QueryRowIndexCtx(ctx, &resp, resellerResellerMerchantPosIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v any) (i any, e error) {
query := fmt.Sprintf("select %s from %s where `pos_id` = ? limit 1", resellerMerchantRows, m.table)
if err := conn.QueryRowCtx(ctx, &resp, query, posId); 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 *defaultResellerMerchantModel) Insert(ctx context.Context, data *ResellerMerchant) (sql.Result, error) {
resellerResellerMerchantAppIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantAppIdPrefix, data.AppId)
resellerResellerMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantIdPrefix, data.Id)
resellerResellerMerchantMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantMerchantIdPrefix, data.MerchantId)
resellerResellerMerchantPosIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantPosIdPrefix, data.PosId)
ret, err := 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, resellerMerchantRowsExpectAutoSet)
return conn.ExecCtx(ctx, query, data.MerchantId, data.ResellerId, data.PosId, data.AppId, data.StoreId, data.ApiMode, data.PublicKey, data.PrivateKey, data.MerchantPublicKey, data.SecretKey, data.NotifyUrl, data.SubscribeEvent, data.Status)
}, resellerResellerMerchantAppIdKey, resellerResellerMerchantIdKey, resellerResellerMerchantMerchantIdKey, resellerResellerMerchantPosIdKey)
return ret, err
}
func (m *defaultResellerMerchantModel) Update(ctx context.Context, newData *ResellerMerchant) error {
data, err := m.FindOne(ctx, newData.Id)
if err != nil {
return err
}
resellerResellerMerchantAppIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantAppIdPrefix, data.AppId)
resellerResellerMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantIdPrefix, data.Id)
resellerResellerMerchantMerchantIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantMerchantIdPrefix, data.MerchantId)
resellerResellerMerchantPosIdKey := fmt.Sprintf("%s%v", cacheResellerResellerMerchantPosIdPrefix, data.PosId)
_, 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` = ?", m.table, resellerMerchantRowsWithPlaceHolder)
return conn.ExecCtx(ctx, query, newData.MerchantId, newData.ResellerId, newData.PosId, newData.AppId, newData.StoreId, newData.ApiMode, newData.PublicKey, newData.PrivateKey, newData.MerchantPublicKey, newData.SecretKey, newData.NotifyUrl, newData.SubscribeEvent, newData.Status, newData.Id)
}, resellerResellerMerchantAppIdKey, resellerResellerMerchantIdKey, resellerResellerMerchantMerchantIdKey, resellerResellerMerchantPosIdKey)
return err
}
func (m *defaultResellerMerchantModel) formatPrimary(primary any) string {
return fmt.Sprintf("%s%v", cacheResellerResellerMerchantIdPrefix, primary)
}
func (m *defaultResellerMerchantModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", resellerMerchantRows, m.table)
return conn.QueryRowCtx(ctx, v, query, primary)
}
func (m *defaultResellerMerchantModel) tableName() string {
return m.table
}