54 lines
1.5 KiB
Go
Executable File
54 lines
1.5 KiB
Go
Executable File
package model
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
)
|
|
|
|
var _ FsCanteenTypeModel = (*customFsCanteenTypeModel)(nil)
|
|
|
|
type (
|
|
// FsCanteenTypeModel is an interface to be customized, add more methods here,
|
|
// and implement the added methods in customFsCanteenTypeModel.
|
|
FsCanteenTypeModel interface {
|
|
fsCanteenTypeModel
|
|
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
|
|
}
|
|
|
|
customFsCanteenTypeModel struct {
|
|
*defaultFsCanteenTypeModel
|
|
}
|
|
)
|
|
|
|
// NewFsCanteenTypeModel returns a model for the database table.
|
|
func NewFsCanteenTypeModel(conn sqlx.SqlConn) FsCanteenTypeModel {
|
|
return &customFsCanteenTypeModel{
|
|
defaultFsCanteenTypeModel: newFsCanteenTypeModel(conn),
|
|
}
|
|
}
|
|
|
|
// FsGetTypeCanteenType GetType返回前端的结构
|
|
type FsGetTypeCanteenType struct {
|
|
Id int64 `db:"id" json:"key"` // ID
|
|
Name string `db:"name" json:"name"` // 餐厅名字
|
|
}
|
|
|
|
// FindGetType 根据status = 1查询出所有,fs_canteen_type 的类型,并排序desc
|
|
func (m *defaultFsCanteenTypeModel) FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error) {
|
|
query := fmt.Sprintf("select X.id,X.name from (select %s from %s where status = 1 order by sort desc) X", fsCanteenTypeRows, m.table)
|
|
var resp []*FsGetTypeCanteenType
|
|
err := m.conn.QueryRows(&resp, query)
|
|
switch err {
|
|
case nil:
|
|
return resp, nil
|
|
case sqlc.ErrNotFound:
|
|
return nil, ErrNotFound
|
|
default:
|
|
return nil, err
|
|
}
|
|
|
|
}
|