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 }