This commit is contained in:
laodaming
2023-06-06 15:01:13 +08:00
parent 213665eb59
commit cf3a02ae7e
12 changed files with 163 additions and 369 deletions

View File

@@ -0,0 +1,24 @@
package model
import "github.com/zeromicro/go-zero/core/stores/sqlx"
var _ FsProductModel3dLightModel = (*customFsProductModel3dLightModel)(nil)
type (
// FsProductModel3dLightModel is an interface to be customized, add more methods here,
// and implement the added methods in customFsProductModel3dLightModel.
FsProductModel3dLightModel interface {
fsProductModel3dLightModel
}
customFsProductModel3dLightModel struct {
*defaultFsProductModel3dLightModel
}
)
// NewFsProductModel3dLightModel returns a model for the database table.
func NewFsProductModel3dLightModel(conn sqlx.SqlConn) FsProductModel3dLightModel {
return &customFsProductModel3dLightModel{
defaultFsProductModel3dLightModel: newFsProductModel3dLightModel(conn),
}
}

View File

@@ -0,0 +1,88 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"database/sql"
"fmt"
"strings"
"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 (
fsProductModel3dLightFieldNames = builder.RawFieldNames(&FsProductModel3dLight{})
fsProductModel3dLightRows = strings.Join(fsProductModel3dLightFieldNames, ",")
fsProductModel3dLightRowsExpectAutoSet = strings.Join(stringx.Remove(fsProductModel3dLightFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), ",")
fsProductModel3dLightRowsWithPlaceHolder = strings.Join(stringx.Remove(fsProductModel3dLightFieldNames, "`id`", "`create_at`", "`create_time`", "`created_at`", "`update_at`", "`update_time`", "`updated_at`"), "=?,") + "=?"
)
type (
fsProductModel3dLightModel interface {
Insert(ctx context.Context, data *FsProductModel3dLight) (sql.Result, error)
FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error)
Update(ctx context.Context, data *FsProductModel3dLight) error
Delete(ctx context.Context, id int64) error
ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error)
}
defaultFsProductModel3dLightModel struct {
conn sqlx.SqlConn
table string
}
FsProductModel3dLight struct {
Id int64 `db:"id"`
Name string `db:"name"` // 灯光名称
Info string `db:"info"` // 灯光数据json格式
Status int64 `db:"status"` // 状态值1显示0删除
Ctime sql.NullInt64 `db:"ctime"` // 创建时间
}
)
func newFsProductModel3dLightModel(conn sqlx.SqlConn) *defaultFsProductModel3dLightModel {
return &defaultFsProductModel3dLightModel{
conn: conn,
table: "`fs_product_model3d_light`",
}
}
func (m *defaultFsProductModel3dLightModel) 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 *defaultFsProductModel3dLightModel) FindOne(ctx context.Context, id int64) (*FsProductModel3dLight, error) {
query := fmt.Sprintf("select %s from %s where `id` = ? limit 1", fsProductModel3dLightRows, m.table)
var resp FsProductModel3dLight
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 *defaultFsProductModel3dLightModel) Insert(ctx context.Context, data *FsProductModel3dLight) (sql.Result, error) {
query := fmt.Sprintf("insert into %s (%s) values (?, ?, ?, ?)", m.table, fsProductModel3dLightRowsExpectAutoSet)
ret, err := m.conn.ExecCtx(ctx, query, data.Name, data.Info, data.Status, data.Ctime)
return ret, err
}
func (m *defaultFsProductModel3dLightModel) Update(ctx context.Context, data *FsProductModel3dLight) error {
query := fmt.Sprintf("update %s set %s where `id` = ?", m.table, fsProductModel3dLightRowsWithPlaceHolder)
_, err := m.conn.ExecCtx(ctx, query, data.Name, data.Info, data.Status, data.Ctime, data.Id)
return err
}
func (m *defaultFsProductModel3dLightModel) tableName() string {
return m.table
}

View File

@@ -29,6 +29,7 @@ type (
Delete(ctx context.Context, id int64) error
FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error)
FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error)
FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error)
}
defaultFsProductTemplateV2Model struct {

View File

@@ -0,0 +1,18 @@
// Code generated by goctl. DO NOT EDIT.
package model
import (
"context"
"fmt"
"strings"
)
func (m *defaultFsProductModel3dLightModel) ListByIds(ctx context.Context, ids []string) (resp []FsProductModel3dLight, err error) {
query := fmt.Sprintf("select %s from %s where `id` in (?)", fsProductModel3dLightRows, m.table)
err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(ids, ","))
if err != nil {
return nil, err
}
return
}

View File

@@ -31,3 +31,20 @@ func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.C
}
return
}
func (m *defaultFsProductTemplateV2Model) FindAllByModelIds(ctx context.Context, modelIds []string, sort int) (resp []FsProductTemplateV2, err error) {
if len(modelIds) == 0 {
return
}
query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table)
switch sort {
case 1:
query = fmt.Sprintf("%s order by `sort` ASC", query)
case 2:
query = fmt.Sprintf("%s order by `sort` DESC", query)
}
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(modelIds, ","), 0, 1); err != nil {
return nil, err
}
return
}