package gmodel import "context" // TODO: 使用model的属性做你想做的 type FindOneRenderDesignByParamsReq struct { ClientNo *string UserId *int64 SortType int 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.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.SortType { case 1: //id asc db = db.Order("`id` ASC") case 2: //id desc db = db.Order("`id` DESC") } err = db.Take(&resp).Error return resp, err }