package req import ( "servicebase/pkg/constant" "servicebase/pkg/tools" "errors" "github.com/gin-gonic/gin" ) const ( defaultPage = 1 defaultSize = 10 ) type Page struct { Page int64 `json:"page" form:"page" uri:"page"` Size int64 `json:"size" form:"size" uri:"size"` } func (p *Page) check() { if p.Page < 1 { p.Page = defaultPage } if p.Size == 0 { p.Size = defaultSize } else if p.Size < 0 { p.Size = 9999 } } func (p *Page) Check() error { p.check() return nil } func (p *Page) Offset() int { p.check() return int(p.Page*p.Size - p.Size) } func (p *Page) Limit() int { p.check() return int(p.Size) } func TID(c *gin.Context) string { return c.GetHeader(constant.TenantId) } func SID(c *gin.Context) string { return c.GetHeader(constant.ScopeId) } func UID(c *gin.Context) string { return c.GetHeader(tools.HeaderUserId) } func CLI(c *gin.Context) string { return c.GetHeader(tools.HeaderClient) } type BaseQuery struct { IndustryID string `json:"industry_id" form:"industry_id" uri:"industry_id"` PeriodID string `json:"period_id" form:"period_id" uri:"period_id"` CityID string `json:"city_id" form:"city_id" uri:"city_id"` ProvinceID string `json:"province_id" form:"province_id" uri:"province_id"` RiskLevel string `json:"risk_level" form:"risk_level" uri:"risk_level"` } type KeyBody struct { Key string `json:"key" form:"key" uri:"key"` } type IDBody struct { ID string `json:"id" form:"id" uri:"id"` // put方法时通常为url参数,post方法时通常为json参数 } type ID32Body struct { ID int32 `json:"id" form:"id" uri:"id"` // put方法时通常为url参数,post方法时通常为json参数 } func (d IDBody) Check() error { if len(d.ID) == 0 { return errors.New("ID不能为空") } return nil } type ClanIDBody struct { ClanID string `json:"clan_id" form:"clan_id" uri:"clan_id"` // put方法时通常为url参数,post方法时通常为json参数 } func (d ClanIDBody) Check() error { if len(d.ClanID) == 0 { return errors.New("家ID不能为空") } return nil } type AreaIDBody struct { IDBody KeyBody AreaID string `json:"area_id" form:"area_id" uri:"area_id"` } type TenantUserLoginBody struct { Username string `json:"username"` Password string `json:"password"` } type TenantUserUpdatePwdBody struct { Pre string `json:"pre"` New string `json:"new"` } type PageWithKeyBody struct { Page KeyBody } type PageWithIDBody struct { Page IDBody }