dynamic.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/service/main/archive/api"
  5. "go-common/app/service/main/dynamic/conf"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. bm "go-common/library/net/http/blademaster"
  9. "go-common/library/xstr"
  10. )
  11. func regionTotal(c *bm.Context) {
  12. c.JSON(dySvc.RegionTotal(c), nil)
  13. }
  14. // regionTagArcs get new arcs of region and hot tag
  15. func regionTagArcs(c *bm.Context) {
  16. var (
  17. count int
  18. rid, tagID int64
  19. pn, ps int64
  20. arcs []*api.Arc
  21. err error
  22. )
  23. query := c.Request.Form
  24. ridStr := query.Get("rid")
  25. tagIDStr := query.Get("tag_id")
  26. pnStr := query.Get("pn")
  27. psStr := query.Get("ps")
  28. if rid, err = strconv.ParseInt(ridStr, 10, 64); err != nil {
  29. c.JSON(nil, ecode.RequestErr)
  30. return
  31. }
  32. if tagID, err = strconv.ParseInt(tagIDStr, 10, 64); err != nil {
  33. c.JSON(nil, ecode.RequestErr)
  34. return
  35. }
  36. if pn, err = strconv.ParseInt(pnStr, 10, 64); err != nil || pn < 1 {
  37. pn = 1
  38. }
  39. if ps, err = strconv.ParseInt(psStr, 10, 64); err != nil || ps < 1 {
  40. ps = int64(conf.Conf.Rule.NumArcs)
  41. }
  42. if arcs, count, err = dySvc.RegionTagArcs3(c, int32(rid), tagID, int(pn), int(ps)); err != nil {
  43. c.JSON(nil, err)
  44. log.Error("dySvc.RegionTagArcs(%d,%d) error(%v)", rid, tagID, err)
  45. return
  46. }
  47. data := make(map[string]interface{}, 2)
  48. page := map[string]int{
  49. "num": int(pn),
  50. "size": int(ps),
  51. "count": count,
  52. }
  53. data["page"] = page
  54. data["archives"] = arcs
  55. c.JSON(data, nil)
  56. }
  57. // regionArcs get new arcs of region.
  58. func regionArcs(c *bm.Context) {
  59. var (
  60. count int
  61. rid int64
  62. pn, ps int64
  63. arcs []*api.Arc
  64. err error
  65. )
  66. query := c.Request.Form
  67. ridStr := query.Get("rid")
  68. pnStr := query.Get("pn")
  69. psStr := query.Get("ps")
  70. if rid, err = strconv.ParseInt(ridStr, 10, 64); err != nil {
  71. c.JSON(nil, ecode.RequestErr)
  72. return
  73. }
  74. if pn, err = strconv.ParseInt(pnStr, 10, 64); err != nil || pn < 1 {
  75. pn = 1
  76. }
  77. if ps, err = strconv.ParseInt(psStr, 10, 64); err != nil || ps < 1 {
  78. ps = int64(conf.Conf.Rule.NumArcs)
  79. }
  80. if arcs, count, err = dySvc.RegionArcs3(c, int32(rid), int(pn), int(ps)); err != nil {
  81. c.JSON(nil, err)
  82. log.Error("dySvc.RegionArcs(%d) error(%v)", rid, err)
  83. return
  84. }
  85. data := make(map[string]interface{}, 2)
  86. page := map[string]int{
  87. "num": int(pn),
  88. "size": int(ps),
  89. "count": count,
  90. }
  91. data["page"] = page
  92. data["archives"] = arcs
  93. c.JSON(data, nil)
  94. }
  95. // regionsArcs get batch new arcs of region.
  96. func regionsArcs(c *bm.Context) {
  97. var (
  98. ridStr string
  99. count int
  100. rids []int32
  101. ridsTmp []int64
  102. err error
  103. )
  104. query := c.Request.Form
  105. if count, err = strconv.Atoi(query.Get("count")); err != nil || count < 1 {
  106. count = conf.Conf.Rule.NumIndexArcs
  107. }
  108. if ridStr = query.Get("rids"); ridStr == "" {
  109. c.JSON(nil, ecode.RequestErr)
  110. return
  111. }
  112. if ridsTmp, err = xstr.SplitInts(ridStr); err != nil {
  113. c.JSON(nil, ecode.RequestErr)
  114. return
  115. }
  116. for _, rid := range ridsTmp {
  117. rids = append(rids, int32(rid))
  118. }
  119. c.JSON(dySvc.RegionsArcs3(c, rids, count))
  120. }