120 lines
5.1 KiB
Go
120 lines
5.1 KiB
Go
// Code generated by goctl. DO NOT EDIT.
|
||
// versions:
|
||
// goctl version: 1.7.2
|
||
|
||
package model
|
||
|
||
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 (
|
||
enterpriseAuthFieldNames = builder.RawFieldNames(&EnterpriseAuth{})
|
||
enterpriseAuthRows = strings.Join(enterpriseAuthFieldNames, ",")
|
||
enterpriseAuthRowsExpectAutoSet = strings.Join(stringx.Remove(enterpriseAuthFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
|
||
enterpriseAuthRowsWithPlaceHolder = strings.Join(stringx.Remove(enterpriseAuthFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
|
||
|
||
cacheEnterpriseAuthIdPrefix = "cache:enterpriseAuth:id:"
|
||
)
|
||
|
||
type (
|
||
enterpriseAuthModel interface {
|
||
Insert(ctx context.Context, data *EnterpriseAuth) (sql.Result, error)
|
||
FindOne(ctx context.Context, id int64) (*EnterpriseAuth, error)
|
||
Update(ctx context.Context, data *EnterpriseAuth) error
|
||
Delete(ctx context.Context, id int64) error
|
||
}
|
||
|
||
defaultEnterpriseAuthModel struct {
|
||
sqlc.CachedConn
|
||
table string
|
||
}
|
||
|
||
EnterpriseAuth struct {
|
||
Id int64 `db:"id"` // 认证ID
|
||
UserId int64 `db:"user_id"` // 关联的用户ID
|
||
EnterpriseName string `db:"enterprise_name"` // 企业名称
|
||
CreditCode string `db:"credit_code"` // 企业统一信用代码
|
||
LegalPerson string `db:"legal_person"` // 法人代表
|
||
BusinessLicense string `db:"business_license"` // 营业执照存储路径
|
||
EnterpriseContact string `db:"enterprise_contact"` // 企业联系方式
|
||
AuthStatus string `db:"auth_status"` // 认证状态:unverified=未提交,pending=待审核,approved=审核通过,rejected=审核拒绝
|
||
CreatedAt time.Time `db:"created_at"` // 认证创建时间
|
||
UpdatedAt time.Time `db:"updated_at"` // 认证更新时间
|
||
}
|
||
)
|
||
|
||
func newEnterpriseAuthModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) *defaultEnterpriseAuthModel {
|
||
return &defaultEnterpriseAuthModel{
|
||
CachedConn: sqlc.NewConn(conn, c, opts...),
|
||
table: "`enterprise_auth`",
|
||
}
|
||
}
|
||
|
||
func (m *defaultEnterpriseAuthModel) Delete(ctx context.Context, id int64) error {
|
||
enterpriseAuthIdKey := fmt.Sprintf("%s%v", cacheEnterpriseAuthIdPrefix, 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)
|
||
return conn.ExecCtx(ctx, query, id)
|
||
}, enterpriseAuthIdKey)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultEnterpriseAuthModel) FindOne(ctx context.Context, id int64) (*EnterpriseAuth, error) {
|
||
enterpriseAuthIdKey := fmt.Sprintf("%s%v", cacheEnterpriseAuthIdPrefix, id)
|
||
var resp EnterpriseAuth
|
||
err := m.QueryRowCtx(ctx, &resp, enterpriseAuthIdKey, func(ctx context.Context, conn sqlx.SqlConn, v any) error {
|
||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", enterpriseAuthRows, 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 *defaultEnterpriseAuthModel) Insert(ctx context.Context, data *EnterpriseAuth) (sql.Result, error) {
|
||
enterpriseAuthIdKey := fmt.Sprintf("%s%v", cacheEnterpriseAuthIdPrefix, data.Id)
|
||
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, enterpriseAuthRowsExpectAutoSet)
|
||
return conn.ExecCtx(ctx, query, data.UserId, data.EnterpriseName, data.CreditCode, data.LegalPerson, data.BusinessLicense, data.EnterpriseContact, data.AuthStatus)
|
||
}, enterpriseAuthIdKey)
|
||
return ret, err
|
||
}
|
||
|
||
func (m *defaultEnterpriseAuthModel) Update(ctx context.Context, data *EnterpriseAuth) error {
|
||
enterpriseAuthIdKey := fmt.Sprintf("%s%v", cacheEnterpriseAuthIdPrefix, data.Id)
|
||
_, 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, enterpriseAuthRowsWithPlaceHolder)
|
||
return conn.ExecCtx(ctx, query, data.UserId, data.EnterpriseName, data.CreditCode, data.LegalPerson, data.BusinessLicense, data.EnterpriseContact, data.AuthStatus, data.Id)
|
||
}, enterpriseAuthIdKey)
|
||
return err
|
||
}
|
||
|
||
func (m *defaultEnterpriseAuthModel) formatPrimary(primary any) string {
|
||
return fmt.Sprintf("%s%v", cacheEnterpriseAuthIdPrefix, primary)
|
||
}
|
||
|
||
func (m *defaultEnterpriseAuthModel) queryPrimary(ctx context.Context, conn sqlx.SqlConn, v, primary any) error {
|
||
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", enterpriseAuthRows, m.table)
|
||
return conn.QueryRowCtx(ctx, v, query, primary)
|
||
}
|
||
|
||
func (m *defaultEnterpriseAuthModel) tableName() string {
|
||
return m.table
|
||
}
|