fusenapi/model/gmodel/fs_product_render_design_logic.go
laodaming 3a6ab7a666 fix
2023-07-14 15:57:27 +08:00

42 lines
942 B
Go

package gmodel
import "context"
// TODO: 使用model的属性做你想做的
type FindOneRenderDesignByParamsReq struct {
ClientNo *string
Sn *string
UserId *int64
OrderBy string
Fields string
Id *int
}
func (r *FsProductRenderDesignModel) FindOneRenderDesignByParams(ctx context.Context, req FindOneRenderDesignByParamsReq) (resp *FsProductRenderDesign, err error) {
db := r.db.WithContext(ctx).Model(&FsProductRenderDesign{})
if req.Sn != nil {
db = db.Where("`sn` = ?", *req.Sn)
}
if req.ClientNo != nil {
db = db.Where("`client_no` = ?", *req.ClientNo)
}
if req.Id != nil {
db = db.Where("`id` = ?", *req.Id)
}
if req.UserId != nil {
db = db.Where("`user_id` = ?", *req.UserId)
}
if req.Fields != "" {
db = db.Select(req.Fields)
}
switch req.OrderBy {
case "": //id asc
db = db.Order("`id` ASC")
default:
db = db.Order(req.OrderBy)
}
err = db.Take(&resp).Error
return resp, err
}