| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- // Code generated by goctl. DO NOT EDIT.
- package model
- import (
- "context"
- "database/sql"
- "fmt"
- "strings"
- "time"
- "github.com/zeromicro/go-zero/core/stores/builder"
- "github.com/zeromicro/go-zero/core/stores/sqlc"
- "github.com/zeromicro/go-zero/core/stores/sqlx"
- "github.com/zeromicro/go-zero/core/stringx"
- )
- var (
- cbCustomerFieldNames = builder.RawFieldNames(&CbCustomer{})
- cbCustomerRows = strings.Join(cbCustomerFieldNames, ",")
- cbCustomerRowsExpectAutoSet = strings.Join(stringx.Remove(cbCustomerFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
- cbCustomerRowsWithPlaceHolder = strings.Join(stringx.Remove(cbCustomerFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
- )
- type (
- cbCustomerModel interface {
- Insert(ctx context.Context, data *CbCustomer) (sql.Result, error)
- FindOne(ctx context.Context, id int64) (*CbCustomer, error)
- FindOneByOpenKfidExternalUserid(ctx context.Context, openKfid string, externalUserid string) (*CbCustomer, error)
- Update(ctx context.Context, data *CbCustomer) error
- Delete(ctx context.Context, id int64) error
- }
- defaultCbCustomerModel struct {
- conn sqlx.SqlConn
- table string
- }
- CbCustomer struct {
- Id int64 `db:"id"`
- OpenKfid string `db:"open_kfid"` // 客服ID
- ExternalUserid string `db:"external_userid"` // 微信客户的external_userid
- Nickname string `db:"nickname"` // 昵称
- Avatar string `db:"avatar"` // 图片
- Gender int64 `db:"gender"` // 性别
- ServiceState int64 `db:"service_state"` // 会话状态:0未处理,1由智能助手接待,2待接入池排队中,3由人工接待,4已结束/未开始
- CreatedAt time.Time `db:"created_at"`
- UpdatedAt time.Time `db:"updated_at"`
- LastMsgTime int64 `db:"last_msg_time"` // 最后消息时间
- }
- )
- func newCbCustomerModel(conn sqlx.SqlConn) *defaultCbCustomerModel {
- return &defaultCbCustomerModel{
- conn: conn,
- table: "`cb_customer`",
- }
- }
- func (m *defaultCbCustomerModel) withSession(session sqlx.Session) *defaultCbCustomerModel {
- return &defaultCbCustomerModel{
- conn: sqlx.NewSqlConnFromSession(session),
- table: "`cb_customer`",
- }
- }
- func (m *defaultCbCustomerModel) Delete(ctx context.Context, id int64) error {
- query := fmt.Sprintf("delete from %s where `id` = ?", m.table)
- _, err := m.conn.ExecCtx(ctx, query, id)
- return err
- }
- func (m *defaultCbCustomerModel) FindOne(ctx context.Context, id int64) (*CbCustomer, error) {
- query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", cbCustomerRows, m.table)
- var resp CbCustomer
- err := m.conn.QueryRowCtx(ctx, &resp, query, id)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultCbCustomerModel) FindOneByOpenKfidExternalUserid(ctx context.Context, openKfid string, externalUserid string) (*CbCustomer, error) {
- var resp CbCustomer
- query := fmt.Sprintf("select %s from %s where `open_kfid` = ? and `external_userid` = ? limit 1", cbCustomerRows, m.table)
- err := m.conn.QueryRowCtx(ctx, &resp, query, openKfid, externalUserid)
- switch err {
- case nil:
- return &resp, nil
- case sqlc.ErrNotFound:
- return nil, ErrNotFound
- default:
- return nil, err
- }
- }
- func (m *defaultCbCustomerModel) Insert(ctx context.Context, data *CbCustomer) (sql.Result, error) {
- query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?)", m.table, cbCustomerRowsExpectAutoSet)
- ret, err := m.conn.ExecCtx(ctx, query, data.OpenKfid, data.ExternalUserid, data.Nickname, data.Avatar, data.Gender, data.ServiceState, data.LastMsgTime)
- return ret, err
- }
- func (m *defaultCbCustomerModel) Update(ctx context.Context, newData *CbCustomer) error {
- query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, cbCustomerRowsWithPlaceHolder)
- _, err := m.conn.ExecCtx(ctx, query, newData.OpenKfid, newData.ExternalUserid, newData.Nickname, newData.Avatar, newData.Gender, newData.ServiceState, newData.LastMsgTime, newData.Id)
- return err
- }
- func (m *defaultCbCustomerModel) tableName() string {
- return m.table
- }
|