hk-service/model/goods_info/goodsinfomodel_gen.go
2025-02-20 17:32:53 +08:00

106 lines
4.6 KiB
Go
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.
// versions:
// goctl version: 1.7.6
package goods_info
import (
"context"
"database/sql"
"fmt"
"strings"
"time"
"github.com/zeromicro/go-zero/core/stores/builder"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"github.com/zeromicro/go-zero/core/stringx"
)
var (
goodsInfoFieldNames = builder.RawFieldNames(&GoodsInfo{})
goodsInfoRows = strings.Join(goodsInfoFieldNames, ",")
goodsInfoRowsExpectAutoSet = strings.Join(stringx.Remove(goodsInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
goodsInfoRowsWithPlaceHolder = strings.Join(stringx.Remove(goodsInfoFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
goodsInfoModel interface {
Insert(ctx context.Context, data *GoodsInfo) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*GoodsInfo, error)
Update(ctx context.Context, data *GoodsInfo) error
Delete(ctx context.Context, id int64) error
}
defaultGoodsInfoModel struct {
conn sqlx.SqlConn
table string
}
GoodsInfo struct {
Id int64 `db:"id"` // 主键ID
Type string `db:"type"` // 运营商 0未标注 1电信 2联通 3移动 4光电
Name string `db:"name"` // 商品名
MainPic string `db:"main_pic"` // 主图
LittlePicture string `db:"little_picture"` // 详情图
NetAddr string `db:"netAddr"` // 商品套餐资料介绍地址
Area string `db:"area"` // 归属地
UniFlow string `db:"uni_flow"` // 通用流量
DirFlow string `db:"dir_flow"` // 定向流量
TalkTime string `db:"talk_time"` // 通话时间
DisableArea string `db:"disable_area"` // 禁发地区
DisableAge string `db:"disable_age"` // 年龄限制
DisableContract string `db:"disable_contract"` // 合约期
Notes sql.NullString `db:"notes"` // 商品说明
ApiId sql.NullInt64 `db:"api_id"` // 三方接口
ApiProductId sql.NullInt64 `db:"api_product_id"` // 三方商品id
NumberSel string `db:"number_sel"` // 是否选号 0不支持 1收货地不是归属地 2收货地是归属地
Status string `db:"status"` // 状态 0上架 1下架
CreateTime time.Time `db:"create_time"` // 创建时间
UpdateTime time.Time `db:"update_time"` // 更新时间
Remarks sql.NullString `db:"remarks"` // 备注
}
)
func newGoodsInfoModel(conn sqlx.SqlConn) *defaultGoodsInfoModel {
return &defaultGoodsInfoModel{
conn: conn,
table: "`goods_info`",
}
}
func (m *defaultGoodsInfoModel) 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 *defaultGoodsInfoModel) FindOne(ctx context.Context, id int64) (*GoodsInfo, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", goodsInfoRows, m.table)
var resp GoodsInfo
err := m.conn.QueryRowCtx(ctx, &resp, query, id)
switch err {
case nil:
return &resp, nil
case sqlx.ErrNotFound:
return nil, ErrNotFound
default:
return nil, err
}
}
func (m *defaultGoodsInfoModel) Insert(ctx context.Context, data *GoodsInfo) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", m.table, goodsInfoRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Type, data.Name, data.MainPic, data.LittlePicture, data.NetAddr, data.Area, data.UniFlow, data.DirFlow, data.TalkTime, data.DisableArea, data.DisableAge, data.DisableContract, data.Notes, data.ApiId, data.ApiProductId, data.NumberSel, data.Status, data.Remarks)
return ret, err
}
func (m *defaultGoodsInfoModel) Update(ctx context.Context, data *GoodsInfo) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, goodsInfoRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Type, data.Name, data.MainPic, data.LittlePicture, data.NetAddr, data.Area, data.UniFlow, data.DirFlow, data.TalkTime, data.DisableArea, data.DisableAge, data.DisableContract, data.Notes, data.ApiId, data.ApiProductId, data.NumberSel, data.Status, data.Remarks, data.Id)
return err
}
func (m *defaultGoodsInfoModel) tableName() string {
return m.table
}