2023-06-01 08:19:24 +00:00
|
|
|
package model
|
|
|
|
|
2023-06-06 09:25:49 +00:00
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlc"
|
|
|
|
"github.com/zeromicro/go-zero/core/stores/sqlx"
|
|
|
|
)
|
2023-06-01 08:19:24 +00:00
|
|
|
|
|
|
|
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
|
2023-06-06 09:25:49 +00:00
|
|
|
FindGetType(ctx context.Context) ([]*FsGetTypeCanteenType, error)
|
2023-06-01 08:19:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
customFsCanteenTypeModel struct {
|
|
|
|
*defaultFsCanteenTypeModel
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewFsCanteenTypeModel returns a model for the database table.
|
|
|
|
func NewFsCanteenTypeModel(conn sqlx.SqlConn) FsCanteenTypeModel {
|
|
|
|
return &customFsCanteenTypeModel{
|
|
|
|
defaultFsCanteenTypeModel: newFsCanteenTypeModel(conn),
|
|
|
|
}
|
|
|
|
}
|
2023-06-06 09:25:49 +00:00
|
|
|
|
2023-06-06 09:31:00 +00:00
|
|
|
// FsGetTypeCanteenType GetType返回前端的结构
|
2023-06-06 09:25:49 +00:00
|
|
|
type FsGetTypeCanteenType struct {
|
|
|
|
Id int64 `db:"id" json:"key"` // ID
|
|
|
|
Name string `db:"name" json:"name"` // 餐厅名字
|
|
|
|
}
|
|
|
|
|
2023-06-06 09:31:00 +00:00
|
|
|
// FindGetType 根据status = 1查询出所有,fs_canteen_type 的类型,并排序desc
|
2023-06-06 09:25:49 +00:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|