fusenapi/model/gmodel/fs_product_render_design_logic.go

42 lines
942 B
Go
Raw Permalink Normal View History

2023-06-19 10:27:31 +00:00
package gmodel
2023-07-06 09:43:07 +00:00
import "context"
// TODO: 使用model的属性做你想做的
type FindOneRenderDesignByParamsReq struct {
ClientNo *string
2023-07-14 07:57:27 +00:00
Sn *string
2023-07-06 09:43:07 +00:00
UserId *int64
2023-07-14 07:57:27 +00:00
OrderBy string
2023-07-06 09:43:07 +00:00
Fields string
Id *int
}
func (r *FsProductRenderDesignModel) FindOneRenderDesignByParams(ctx context.Context, req FindOneRenderDesignByParamsReq) (resp *FsProductRenderDesign, err error) {
db := r.db.WithContext(ctx).Model(&FsProductRenderDesign{})
2023-07-14 07:57:27 +00:00
if req.Sn != nil {
db = db.Where("`sn` = ?", *req.Sn)
}
2023-07-06 09:43:07 +00:00
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)
}
2023-07-14 07:57:27 +00:00
switch req.OrderBy {
case "": //id asc
2023-07-06 09:43:07 +00:00
db = db.Order("`id` ASC")
2023-07-14 07:57:27 +00:00
default:
db = db.Order(req.OrderBy)
2023-07-06 09:43:07 +00:00
}
err = db.Take(&resp).Error
return resp, err
}