subject.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. package http
  2. import (
  3. "strconv"
  4. "go-common/app/admin/main/dm/model"
  5. "go-common/library/ecode"
  6. bm "go-common/library/net/http/blademaster"
  7. "go-common/library/xstr"
  8. )
  9. func archiveList(c *bm.Context) {
  10. var (
  11. p = c.Request.Form
  12. req = &model.ArchiveListReq{
  13. Pn: 1,
  14. Ps: 20,
  15. IDType: p.Get("type"),
  16. Sort: "desc",
  17. Order: "mtime",
  18. Page: int64(model.CondIntNil),
  19. Attrs: make([]int64, 0),
  20. State: int64(model.CondIntNil),
  21. }
  22. err error
  23. )
  24. if idStr := p.Get("id"); len(idStr) > 0 {
  25. if req.ID, err = strconv.ParseInt(idStr, 10, 64); err != nil {
  26. c.JSON(nil, ecode.RequestErr)
  27. return
  28. }
  29. }
  30. if pageStr := p.Get("page"); len(pageStr) > 0 {
  31. if req.Page, err = strconv.ParseInt(pageStr, 10, 64); err != nil {
  32. c.JSON(nil, ecode.RequestErr)
  33. return
  34. }
  35. }
  36. if attrStr := p.Get("attrs"); len(attrStr) > 0 {
  37. req.Attrs, err = xstr.SplitInts(attrStr)
  38. if err != nil {
  39. c.JSON(nil, ecode.RequestErr)
  40. return
  41. }
  42. }
  43. if stateStr := p.Get("state"); len(stateStr) > 0 {
  44. req.State, err = strconv.ParseInt(stateStr, 10, 64)
  45. if err != nil {
  46. c.JSON(nil, ecode.RequestErr)
  47. return
  48. }
  49. }
  50. if p.Get("sort") != "" {
  51. req.Sort = p.Get("sort")
  52. }
  53. if p.Get("order") != "" {
  54. req.Order = p.Get("order")
  55. }
  56. if pnStr := p.Get("pn"); len(pnStr) > 0 {
  57. req.Pn, err = strconv.ParseInt(pnStr, 10, 64)
  58. if err != nil {
  59. c.JSON(nil, ecode.RequestErr)
  60. return
  61. }
  62. }
  63. if psStr := p.Get("ps"); len(psStr) > 0 {
  64. req.Ps, err = strconv.ParseInt(psStr, 10, 64)
  65. if err != nil {
  66. c.JSON(nil, ecode.RequestErr)
  67. return
  68. }
  69. }
  70. data, err := dmSvc.ArchiveList(c, req)
  71. c.JSON(data, err)
  72. }
  73. func uptSubjectsState(c *bm.Context) {
  74. var (
  75. uid, _ = c.Get("uid")
  76. uname, _ = c.Get("username")
  77. p = c.Request.Form
  78. comment = p.Get("comment")
  79. )
  80. oids, err := xstr.SplitInts(p.Get("oids"))
  81. if err != nil || len(oids) == 0 {
  82. c.JSON(nil, ecode.RequestErr)
  83. return
  84. }
  85. tp, err := strconv.ParseInt(p.Get("type"), 10, 64)
  86. if err != nil {
  87. c.JSON(nil, ecode.RequestErr)
  88. return
  89. }
  90. state, err := strconv.ParseInt(p.Get("state"), 10, 64)
  91. if err != nil || (int32(state) != model.SubStateOpen && int32(state) != model.SubStateClosed) {
  92. c.JSON(nil, ecode.RequestErr)
  93. return
  94. }
  95. err = dmSvc.UptSubjectsState(c, int32(tp), uid.(int64), uname.(string), oids, int32(state), comment)
  96. c.JSON(nil, err)
  97. }
  98. func upSubjectMaxLimit(c *bm.Context) {
  99. var (
  100. tp int64
  101. p = c.Request.Form
  102. cid, maxlimit int64
  103. err error
  104. )
  105. if tp, err = strconv.ParseInt(p.Get("type"), 10, 64); err != nil {
  106. c.JSON(nil, ecode.RequestErr)
  107. return
  108. }
  109. if cid, err = strconv.ParseInt(p.Get("cid"), 10, 64); err != nil {
  110. c.JSON(nil, ecode.RequestErr)
  111. return
  112. }
  113. if maxlimit, err = strconv.ParseInt(p.Get("limit"), 10, 64); err != nil || maxlimit > 20000 || maxlimit < 0 {
  114. c.JSON(nil, ecode.RequestErr)
  115. return
  116. }
  117. err = dmSvc.UpSubjectMaxLimit(c, int32(tp), cid, maxlimit)
  118. c.JSON(nil, err)
  119. }
  120. func subjectLog(c *bm.Context) {
  121. var (
  122. p = c.Request.Form
  123. oid, tp int64
  124. err error
  125. )
  126. if oid, err = strconv.ParseInt(p.Get("oid"), 10, 64); err != nil {
  127. c.JSON(nil, ecode.RequestErr)
  128. return
  129. }
  130. if tp, err = strconv.ParseInt(p.Get("type"), 10, 64); err != nil {
  131. c.JSON(nil, ecode.RequestErr)
  132. return
  133. }
  134. data, err := dmSvc.SubjectLog(c, int32(tp), oid)
  135. c.JSON(data, err)
  136. }