need.go 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. package http
  2. import (
  3. "context"
  4. "go-common/app/admin/main/apm/conf"
  5. "go-common/app/admin/main/apm/model/need"
  6. bm "go-common/library/net/http/blademaster"
  7. )
  8. // @params NListReq
  9. // @router get /x/admin/apm/need/list
  10. // @response NListResp
  11. func needList(c *bm.Context) {
  12. var (
  13. infos []*need.NInfo
  14. total int64
  15. err error
  16. )
  17. username := name(c)
  18. arg := new(need.NListReq)
  19. if err = c.Bind(arg); err != nil {
  20. return
  21. }
  22. if infos, total, err = apmSvc.NeedInfoList(c, arg, username); err != nil {
  23. c.JSON(nil, err)
  24. return
  25. }
  26. res := &need.NListResp{
  27. Data: infos,
  28. Total: total,
  29. }
  30. c.JSON(res, nil)
  31. }
  32. // @params NAddReq
  33. // @router post /x/admin/apm/need/add
  34. // @response EmpResp
  35. func needAdd(c *bm.Context) {
  36. var err error
  37. username := name(c)
  38. req := new(need.NAddReq)
  39. if err = c.Bind(req); err != nil {
  40. return
  41. }
  42. if err = apmSvc.NeedInfoAdd(c, req, username); err != nil {
  43. c.JSON(nil, err)
  44. return
  45. }
  46. go apmSvc.SendWeMessage(context.Background(), req.Title, need.VerifyType[need.NeedApply], "", username, conf.Conf.Superman)
  47. go apmSvc.SendWeMessage(context.Background(), req.Title, need.VerifyType[need.NeedVerify], "", username, []string{username})
  48. c.JSON(nil, err)
  49. }
  50. // @params NEditReq
  51. // @router post /x/admin/apm/need/edit
  52. // @response EmpResp
  53. func needEdit(c *bm.Context) {
  54. var err error
  55. req := new(need.NEditReq)
  56. if err = c.Bind(req); err != nil {
  57. return
  58. }
  59. username := name(c)
  60. if err = apmSvc.NeedInfoEdit(c, req, username); err != nil {
  61. c.JSON(nil, err)
  62. return
  63. }
  64. c.JSON(nil, err)
  65. }
  66. // @params NVerifyReq
  67. // @router post /x/admin/apm/need/verify
  68. // @response EmpResp
  69. func needVerify(c *bm.Context) {
  70. var (
  71. err error
  72. ni *need.NInfo
  73. )
  74. req := new(need.NVerifyReq)
  75. if err = c.Bind(req); err != nil {
  76. return
  77. }
  78. username := name(c)
  79. if ni, err = apmSvc.NeedInfoVerify(c, req); err != nil {
  80. c.JSON(nil, err)
  81. return
  82. }
  83. go apmSvc.SendWeMessage(context.Background(), ni.Title, need.VerifyType[need.NeedReview], need.VerifyType[req.Status], username, []string{username})
  84. c.JSON(nil, err)
  85. }
  86. // @params Likereq
  87. // @router post /x/admin/apm/need/thumbsup
  88. // @response EmpResp
  89. func needThumbsUp(c *bm.Context) {
  90. var err error
  91. req := new(need.Likereq)
  92. if err = c.Bind(req); err != nil {
  93. return
  94. }
  95. username := name(c)
  96. if err = apmSvc.NeedInfoVote(c, req, username); err != nil {
  97. c.JSON(nil, err)
  98. return
  99. }
  100. c.JSON(nil, err)
  101. }
  102. // @params Likereq
  103. // @router get /x/admin/need/vote/list
  104. // @response VoteListResp
  105. func needVoteList(c *bm.Context) {
  106. var (
  107. votes []*need.UserLikes
  108. total int64
  109. err error
  110. )
  111. req := new(need.Likereq)
  112. if err = c.Bind(req); err != nil {
  113. return
  114. }
  115. if votes, total, err = apmSvc.NeedVoteList(c, req); err != nil {
  116. c.JSON(nil, err)
  117. return
  118. }
  119. res := &need.VoteListResp{
  120. Data: votes,
  121. Total: total,
  122. }
  123. c.JSON(res, nil)
  124. }