list_contoller.go 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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. productVideo = "video"
  16. productAudio = "audio"
  17. productReport = "report"
  18. productPackage = "package"
  19. )
  20. func (l *ListController) Prepare() {
  21. pageSize, _ := l.GetInt("pageSize")
  22. currentIndex, _ := l.GetInt("currentIndex")
  23. LatestId, _ := l.GetInt64("latestId")
  24. total, _ := l.GetInt64("total")
  25. if pageSize <= 0 {
  26. pageSize = contants.PageSizeDefault
  27. }
  28. if currentIndex <= 0 {
  29. currentIndex = 1
  30. }
  31. if LatestId < 0 {
  32. LatestId = 0
  33. }
  34. l.PageInfo = page.PageInfo{
  35. LatestId: LatestId,
  36. Current: currentIndex,
  37. PageSize: pageSize,
  38. Total: total,
  39. }
  40. }
  41. func (l *ListController) TransPermissionIds(permissionIds string) (permissionIdList []int, err error) {
  42. if strings.HasPrefix(permissionIds, ",") {
  43. permissionIds = permissionIds[1:len(permissionIds)]
  44. }
  45. if strings.HasSuffix(permissionIds, ",") {
  46. permissionIds = permissionIds[0 : len(permissionIds)-1]
  47. }
  48. if permissionIds == "" {
  49. permissionIdList = []int{}
  50. } else {
  51. permissionIdList, err = stringUtils.StringToIntSlice(strings.Split(permissionIds, ","))
  52. }
  53. return
  54. }
  55. func (l *ListController) CheckMediaType(mediaType string) bool {
  56. if mediaType == video || mediaType == audio {
  57. return true
  58. }
  59. return false
  60. }
  61. func (l *ListController) CheckProductType(productType string) bool {
  62. if productType == productReport || productType == productPackage || productType == productVideo || productType == productAudio {
  63. return true
  64. }
  65. return false
  66. }
  67. //func (l *ListController) Finish() {
  68. // l.PageInfo.Reset()
  69. // runMode := web.BConfig.RunMode
  70. // if l.Data["json"] == nil {
  71. // logger.Warn("apiRequest:[异常提醒:%v 接口:URI:%v;无返回值]", runMode, l.Ctx.Input.URI())
  72. // return
  73. // }
  74. // baseRes := l.Data["json"].(BaseResponse)
  75. // if !baseRes.Success {
  76. // logger.Info("apiRequest:[异常提醒:%v接口:URI:%v;ErrMsg:&v;Msg:%v]", l.Ctx.Input.URI(), baseRes.ErrMsg, baseRes.Msg)
  77. // } else {
  78. // if baseRes.Data == nil {
  79. // logger.Warn("apiRequest:[异常提醒:%v 接口:URI:%v;无返回值]", runMode, l.Ctx.Input.URI())
  80. // return
  81. // } else {
  82. // logger.Info("apiRequest:[uri:%s, resData:%s, ip:%s]", l.Ctx.Input.URI(), baseRes.Data)
  83. // }
  84. // }
  85. //}