// Code generated by goctl. DO NOT EDIT!

package model

import (
	"context"
	"database/sql"
	"fmt"
	"strings"

	"reflect"
	"time"

	"bdqr-server/common/globalkey"
	"github.com/Masterminds/squirrel"
	"github.com/google/uuid"
	"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"
)

var (
	userFeatureWhitelistFieldNames          = builder.RawFieldNames(&UserFeatureWhitelist{})
	userFeatureWhitelistRows                = strings.Join(userFeatureWhitelistFieldNames, ",")
	userFeatureWhitelistRowsExpectAutoSet   = strings.Join(stringx.Remove(userFeatureWhitelistFieldNames, "`create_time`", "`update_time`"), ",")
	userFeatureWhitelistRowsWithPlaceHolder = strings.Join(stringx.Remove(userFeatureWhitelistFieldNames, "`id`", "`create_time`", "`update_time`"), "=?,") + "=?"

	cacheBdqrUserFeatureWhitelistIdPrefix                         = "cache:bdqr:userFeatureWhitelist:id:"
	cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix = "cache:bdqr:userFeatureWhitelist:idCard:featureApiId:delState:"
	cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix    = "cache:bdqr:userFeatureWhitelist:idCard:featureId:delState:"
	cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix           = "cache:bdqr:userFeatureWhitelist:whitelistOrderId:"
)

type (
	userFeatureWhitelistModel interface {
		Insert(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) (sql.Result, error)
		FindOne(ctx context.Context, id string) (*UserFeatureWhitelist, error)
		FindOneByIdCardFeatureApiIdDelState(ctx context.Context, idCard string, featureApiId string, delState int64) (*UserFeatureWhitelist, error)
		FindOneByIdCardFeatureIdDelState(ctx context.Context, idCard string, featureId string, delState int64) (*UserFeatureWhitelist, error)
		FindOneByWhitelistOrderId(ctx context.Context, whitelistOrderId sql.NullString) (*UserFeatureWhitelist, error)
		Update(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) (sql.Result, error)
		UpdateWithVersion(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) 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 *UserFeatureWhitelist) 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) ([]*UserFeatureWhitelist, error)
		FindPageListByPage(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, error)
		FindPageListByPageWithTotal(ctx context.Context, rowBuilder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, int64, error)
		FindPageListByIdDESC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*UserFeatureWhitelist, error)
		FindPageListByIdASC(ctx context.Context, rowBuilder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*UserFeatureWhitelist, error)
		Delete(ctx context.Context, session sqlx.Session, id string) error
	}

	defaultUserFeatureWhitelistModel struct {
		sqlc.CachedConn
		table string
	}

	UserFeatureWhitelist struct {
		Id               string         `db:"id"`                 // UUID主键
		CreateTime       time.Time      `db:"create_time"`        // 创建时间
		UpdateTime       time.Time      `db:"update_time"`        // 更新时间
		DeleteTime       sql.NullTime   `db:"delete_time"`        // 删除时间
		DelState         int64          `db:"del_state"`          // 删除状态：0=未删除，1=已删除
		Version          int64          `db:"version"`            // 版本号（乐观锁）
		IdCard           string         `db:"id_card"`            // 身份证号（查询对象标识）
		FeatureId        string         `db:"feature_id"`         // Feature的UUID
		FeatureApiId     string         `db:"feature_api_id"`     // Feature的API标识（冗余字段，方便查询）
		UserId           string         `db:"user_id"`            // 操作用户ID（代理的user_id，以后可扩展为普通用户）
		OrderId          sql.NullString `db:"order_id"`           // 关联的查询订单ID（可选，记录来源）
		WhitelistOrderId sql.NullString `db:"whitelist_order_id"` // 关联的白名单订单ID（用于付费）
		Amount           float64        `db:"amount"`             // 费用（单位：元）
		Status           int64          `db:"status"`             // 状态：1=生效，2=已失效
	}
)

func newUserFeatureWhitelistModel(conn sqlx.SqlConn, c cache.CacheConf) *defaultUserFeatureWhitelistModel {
	return &defaultUserFeatureWhitelistModel{
		CachedConn: sqlc.NewConn(conn, c),
		table:      "`user_feature_whitelist`",
	}
}

func (m *defaultUserFeatureWhitelistModel) Insert(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) (sql.Result, error) {
	data.DelState = globalkey.DelStateNo
	m.insertUUID(data)
	bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
	bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
	bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, data.Id)
	bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
	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, userFeatureWhitelistRowsExpectAutoSet)
		if session != nil {
			return session.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.IdCard, data.FeatureId, data.FeatureApiId, data.UserId, data.OrderId, data.WhitelistOrderId, data.Amount, data.Status)
		}
		return conn.ExecCtx(ctx, query, data.Id, data.DeleteTime, data.DelState, data.Version, data.IdCard, data.FeatureId, data.FeatureApiId, data.UserId, data.OrderId, data.WhitelistOrderId, data.Amount, data.Status)
	}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
}
func (m *defaultUserFeatureWhitelistModel) insertUUID(data *UserFeatureWhitelist) {
	t := reflect.TypeOf(data).Elem()
	v := reflect.ValueOf(data).Elem()
	for i := 0; i < t.NumField(); i++ {
		sf := t.Field(i)
		if sf.Tag.Get("db") == "id" {
			f := v.Field(i)
			if f.IsValid() && f.CanSet() && f.Kind() == reflect.String {
				if f.String() == "" {
					f.SetString(uuid.NewString())
				}
			}
			break
		}
	}
}

func (m *defaultUserFeatureWhitelistModel) FindOne(ctx context.Context, id string) (*UserFeatureWhitelist, error) {
	bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, id)
	var resp UserFeatureWhitelist
	err := m.QueryRowCtx(ctx, &resp, bdqrUserFeatureWhitelistIdKey, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) error {
		query := fmt.Sprintf("select %s from %s where `id` = ? and del_state = ? limit 1", userFeatureWhitelistRows, 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 *defaultUserFeatureWhitelistModel) FindOneByIdCardFeatureApiIdDelState(ctx context.Context, idCard string, featureApiId string, delState int64) (*UserFeatureWhitelist, error) {
	bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, idCard, featureApiId, delState)
	var resp UserFeatureWhitelist
	err := m.QueryRowIndexCtx(ctx, &resp, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
		query := fmt.Sprintf("select %s from %s where `id_card` = ? and `feature_api_id` = ? and `del_state` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
		if err := conn.QueryRowCtx(ctx, &resp, query, idCard, featureApiId, delState, 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 *defaultUserFeatureWhitelistModel) FindOneByIdCardFeatureIdDelState(ctx context.Context, idCard string, featureId string, delState int64) (*UserFeatureWhitelist, error) {
	bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, idCard, featureId, delState)
	var resp UserFeatureWhitelist
	err := m.QueryRowIndexCtx(ctx, &resp, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
		query := fmt.Sprintf("select %s from %s where `id_card` = ? and `feature_id` = ? and `del_state` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
		if err := conn.QueryRowCtx(ctx, &resp, query, idCard, featureId, delState, 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 *defaultUserFeatureWhitelistModel) FindOneByWhitelistOrderId(ctx context.Context, whitelistOrderId sql.NullString) (*UserFeatureWhitelist, error) {
	bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, whitelistOrderId)
	var resp UserFeatureWhitelist
	err := m.QueryRowIndexCtx(ctx, &resp, bdqrUserFeatureWhitelistWhitelistOrderIdKey, m.formatPrimary, func(ctx context.Context, conn sqlx.SqlConn, v interface{}) (i interface{}, e error) {
		query := fmt.Sprintf("select %s from %s where `whitelist_order_id` = ? and del_state = ? limit 1", userFeatureWhitelistRows, m.table)
		if err := conn.QueryRowCtx(ctx, &resp, query, whitelistOrderId, 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 *defaultUserFeatureWhitelistModel) Update(ctx context.Context, session sqlx.Session, newData *UserFeatureWhitelist) (sql.Result, error) {
	data, err := m.FindOne(ctx, newData.Id)
	if err != nil {
		return nil, err
	}
	bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
	bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
	bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, data.Id)
	bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
	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, userFeatureWhitelistRowsWithPlaceHolder)
		if session != nil {
			return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id)
		}
		return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id)
	}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
}

func (m *defaultUserFeatureWhitelistModel) UpdateWithVersion(ctx context.Context, session sqlx.Session, newData *UserFeatureWhitelist) 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
	}
	bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
	bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
	bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, data.Id)
	bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
	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, userFeatureWhitelistRowsWithPlaceHolder)
		if session != nil {
			return session.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id, oldVersion)
		}
		return conn.ExecCtx(ctx, query, newData.DeleteTime, newData.DelState, newData.Version, newData.IdCard, newData.FeatureId, newData.FeatureApiId, newData.UserId, newData.OrderId, newData.WhitelistOrderId, newData.Amount, newData.Status, newData.Id, oldVersion)
	}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
	if err != nil {
		return err
	}
	updateCount, err := sqlResult.RowsAffected()
	if err != nil {
		return err
	}
	if updateCount == 0 {
		return ErrNoRowsUpdate
	}

	return nil
}

func (m *defaultUserFeatureWhitelistModel) DeleteSoft(ctx context.Context, session sqlx.Session, data *UserFeatureWhitelist) 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 "), "UserFeatureWhitelistModel delete err : %+v", err)
	}
	return nil
}

func (m *defaultUserFeatureWhitelistModel) 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 *defaultUserFeatureWhitelistModel) 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 *defaultUserFeatureWhitelistModel) FindAll(ctx context.Context, builder squirrel.SelectBuilder, orderBy string) ([]*UserFeatureWhitelist, error) {

	builder = builder.Columns(userFeatureWhitelistRows)

	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 []*UserFeatureWhitelist
	err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
	switch err {
	case nil:
		return resp, nil
	default:
		return nil, err
	}
}

func (m *defaultUserFeatureWhitelistModel) FindPageListByPage(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, error) {

	builder = builder.Columns(userFeatureWhitelistRows)

	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 []*UserFeatureWhitelist
	err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
	switch err {
	case nil:
		return resp, nil
	default:
		return nil, err
	}
}

func (m *defaultUserFeatureWhitelistModel) FindPageListByPageWithTotal(ctx context.Context, builder squirrel.SelectBuilder, page, pageSize int64, orderBy string) ([]*UserFeatureWhitelist, int64, error) {

	total, err := m.FindCount(ctx, builder, "id")
	if err != nil {
		return nil, 0, err
	}

	builder = builder.Columns(userFeatureWhitelistRows)

	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 []*UserFeatureWhitelist
	err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
	switch err {
	case nil:
		return resp, total, nil
	default:
		return nil, total, err
	}
}

func (m *defaultUserFeatureWhitelistModel) FindPageListByIdDESC(ctx context.Context, builder squirrel.SelectBuilder, preMinId, pageSize int64) ([]*UserFeatureWhitelist, error) {

	builder = builder.Columns(userFeatureWhitelistRows)

	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 []*UserFeatureWhitelist
	err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
	switch err {
	case nil:
		return resp, nil
	default:
		return nil, err
	}
}

func (m *defaultUserFeatureWhitelistModel) FindPageListByIdASC(ctx context.Context, builder squirrel.SelectBuilder, preMaxId, pageSize int64) ([]*UserFeatureWhitelist, error) {

	builder = builder.Columns(userFeatureWhitelistRows)

	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 []*UserFeatureWhitelist
	err = m.QueryRowsNoCacheCtx(ctx, &resp, query, values...)
	switch err {
	case nil:
		return resp, nil
	default:
		return nil, err
	}
}

func (m *defaultUserFeatureWhitelistModel) 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 *defaultUserFeatureWhitelistModel) SelectBuilder() squirrel.SelectBuilder {
	return squirrel.Select().From(m.table)
}
func (m *defaultUserFeatureWhitelistModel) Delete(ctx context.Context, session sqlx.Session, id string) error {
	data, err := m.FindOne(ctx, id)
	if err != nil {
		return err
	}

	bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureApiIdDelStatePrefix, data.IdCard, data.FeatureApiId, data.DelState)
	bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey := fmt.Sprintf("%s%v:%v:%v", cacheBdqrUserFeatureWhitelistIdCardFeatureIdDelStatePrefix, data.IdCard, data.FeatureId, data.DelState)
	bdqrUserFeatureWhitelistIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, id)
	bdqrUserFeatureWhitelistWhitelistOrderIdKey := fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistWhitelistOrderIdPrefix, data.WhitelistOrderId)
	_, 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)
	}, bdqrUserFeatureWhitelistIdCardFeatureApiIdDelStateKey, bdqrUserFeatureWhitelistIdCardFeatureIdDelStateKey, bdqrUserFeatureWhitelistIdKey, bdqrUserFeatureWhitelistWhitelistOrderIdKey)
	return err
}
func (m *defaultUserFeatureWhitelistModel) formatPrimary(primary interface{}) string {
	return fmt.Sprintf("%s%v", cacheBdqrUserFeatureWhitelistIdPrefix, primary)
}
func (m *defaultUserFeatureWhitelistModel) 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", userFeatureWhitelistRows, m.table)
	return conn.QueryRowCtx(ctx, v, query, primary, globalkey.DelStateNo)
}

func (m *defaultUserFeatureWhitelistModel) tableName() string {
	return m.table
}
