list_contoller.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. package controllers
  2. import (
  3. "eta/eta_mini_ht_api/common/contants"
  4. "eta/eta_mini_ht_api/common/utils/page"
  5. stringUtils "eta/eta_mini_ht_api/common/utils/string"
  6. "strings"
  7. )
  8. type ListController struct {
  9. BaseController
  10. PageInfo page.PageInfo
  11. }
  12. const (
  13. video = "video"
  14. audio = "audio"
  15. )
  16. func (l *ListController) Prepare() {
  17. pageSize, _ := l.GetInt("pageSize")
  18. currentIndex, _ := l.GetInt("currentIndex")
  19. LatestId, _ := l.GetInt64("latestId")
  20. total, _ := l.GetInt64("total")
  21. if pageSize <= 0 {
  22. pageSize = contants.PageSizeDefault
  23. }
  24. if currentIndex <= 0 {
  25. currentIndex = 1
  26. }
  27. if LatestId < 0 {
  28. LatestId = 0
  29. }
  30. l.PageInfo = page.PageInfo{
  31. LatestId: LatestId,
  32. Current: currentIndex,
  33. PageSize: pageSize,
  34. Total: total,
  35. }
  36. }
  37. func (l *ListController) TransPermissionIds(permissionIds string) (permissionIdList []int, err error) {
  38. if strings.HasPrefix(permissionIds, ",") {
  39. permissionIds = permissionIds[1:len(permissionIds)]
  40. }
  41. if strings.HasSuffix(permissionIds, ",") {
  42. permissionIds = permissionIds[0 : len(permissionIds)-1]
  43. }
  44. if permissionIds == "" {
  45. permissionIdList = []int{}
  46. } else {
  47. permissionIdList, err = stringUtils.StringToIntSlice(strings.Split(permissionIds, ","))
  48. }
  49. return
  50. }
  51. func (l *ListController) CheckMediaType(mediaType string) bool {
  52. if mediaType == video || mediaType == audio {
  53. return true
  54. }
  55. return false
  56. }
  57. //func (l *ListController) Finish() {
  58. // l.PageInfo.Reset()
  59. // runMode := web.BConfig.RunMode
  60. // if l.Data["json"] == nil {
  61. // logger.Warn("apiRequest:[异常提醒:%v 接口:URI:%v;无返回值]", runMode, l.Ctx.Input.URI())
  62. // return
  63. // }
  64. // baseRes := l.Data["json"].(BaseResponse)
  65. // if !baseRes.Success {
  66. // logger.Info("apiRequest:[异常提醒:%v接口:URI:%v;ErrMsg:&v;Msg:%v]", l.Ctx.Input.URI(), baseRes.ErrMsg, baseRes.Msg)
  67. // } else {
  68. // if baseRes.Data == nil {
  69. // logger.Warn("apiRequest:[异常提醒:%v 接口:URI:%v;无返回值]", runMode, l.Ctx.Input.URI())
  70. // return
  71. // } else {
  72. // logger.Info("apiRequest:[uri:%s, resData:%s, ip:%s]", l.Ctx.Input.URI(), baseRes.Data)
  73. // }
  74. // }
  75. //}