PageParam.go 793 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package Models
  2. import (
  3. "forward-core/Utils"
  4. )
  5. type PageParam struct {
  6. PIndex int64
  7. PSize int64
  8. // 要排序的字段名
  9. Sort string
  10. // ASC 或 DESC
  11. Direction string
  12. }
  13. func (this *PageParam) PageSize() int {
  14. return int(this.PSize)
  15. }
  16. // 分页, 排序处理
  17. func (this *PageParam) SkipRows() int {
  18. this.PIndex = Utils.If(this.PIndex < 1, 1, this.PIndex).(int64)
  19. this.PSize = Utils.If(this.PSize < 1, 5, this.PSize).(int64)
  20. skipRows := (this.PIndex - 1) * this.PSize
  21. return int(skipRows)
  22. }
  23. func (this *PageParam) SortField() string {
  24. var sortField string
  25. if !Utils.IsEmpty(this.Sort) {
  26. if !Utils.IsEmpty(this.Direction) && this.Direction == "DESC" {
  27. //降序
  28. sortField = "-" + this.Sort
  29. } else {
  30. //升序
  31. sortField = this.Sort
  32. }
  33. }
  34. return sortField
  35. }
粤ICP备19079148号