fusenapi/model/gorm/fsproducttemplatev2model.go

73 lines
2.7 KiB
Go
Raw Normal View History

2023-06-12 06:05:35 +00:00
package model
import (
"context"
"fmt"
"github.com/zeromicro/go-zero/core/stores/sqlx"
"strings"
)
var _ FsProductTemplateV2Model = (*customFsProductTemplateV2Model)(nil)
type (
// FsProductTemplateV2Model is an interface to be customized, add more methods here,
// and implement the added methods in customFsProductTemplateV2Model.
FsProductTemplateV2Model interface {
fsProductTemplateV2Model
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)
}
customFsProductTemplateV2Model struct {
*defaultFsProductTemplateV2Model
}
)
// NewFsProductTemplateV2Model returns a model for the database table.
func NewFsProductTemplateV2Model(conn sqlx.SqlConn) FsProductTemplateV2Model {
return &customFsProductTemplateV2Model{
defaultFsProductTemplateV2Model: newFsProductTemplateV2Model(conn),
}
}
func (m *defaultFsProductTemplateV2Model) FindAllByCondition(ctx context.Context, productIds []string) (resp []FsProductTemplateV2, err error) {
query := fmt.Sprintf("select %s from %s where `id` in (?) and `is_del` = ? and `status` = ?", fsProductTemplateV2Rows, m.table)
if err = m.conn.QueryRowsCtx(ctx, &resp, query, strings.Join(productIds, ","), 0, 1); err != nil {
return nil, err
}
return
}
func (m *defaultFsProductTemplateV2Model) FindAllByModelIdsProduct(ctx context.Context, modelIds []string, productId int64, sort int) (resp []FsProductTemplateV2, err error) {
if len(modelIds) == 0 {
return
}
query := fmt.Sprintf("select %s from %s where `model_id` in (?) and `product_id` = ? 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, ","), productId, 0, 1); err != nil {
return nil, err
}
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
}