monitor.go 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. package http
  2. import (
  3. "strconv"
  4. "time"
  5. "go-common/app/admin/main/reply/conf"
  6. "go-common/app/admin/main/reply/model"
  7. "go-common/library/ecode"
  8. "go-common/library/log"
  9. bm "go-common/library/net/http/blademaster"
  10. "go-common/library/xstr"
  11. )
  12. func monitorStats(c *bm.Context) {
  13. var (
  14. err error
  15. mode int64
  16. startTime int64
  17. endTime int64
  18. page = int64(conf.Conf.Reply.PageNum)
  19. pageSize = int64(conf.Conf.Reply.PageSize)
  20. )
  21. params := c.Request.Form
  22. modeStr := params.Get("mode")
  23. sortStr := params.Get("sort")
  24. pageStr := params.Get("page")
  25. pageSizeStr := params.Get("pagesize")
  26. adminIDsStr := params.Get("adminids")
  27. startTimeStr := params.Get("start_time")
  28. endTimeStr := params.Get("end_time")
  29. orderStr := params.Get("order_time")
  30. if mode, err = strconv.ParseInt(modeStr, 10, 64); err != nil {
  31. log.Warn("strconv.ParseInt(mode:%s) error(%v)", modeStr, err)
  32. c.JSON(nil, ecode.RequestErr)
  33. return
  34. }
  35. if pageStr != "" {
  36. if page, err = strconv.ParseInt(pageStr, 10, 64); err != nil {
  37. log.Warn("strconv.ParseInt(page:%s) error(%v)", pageStr, err)
  38. c.JSON(nil, ecode.RequestErr)
  39. return
  40. }
  41. }
  42. if pageSizeStr != "" {
  43. if pageSize, err = strconv.ParseInt(pageSizeStr, 10, 64); err != nil {
  44. log.Warn("strconv.ParseInt(pageSize:%s) error(%v)", pageSizeStr, err)
  45. c.JSON(nil, ecode.RequestErr)
  46. return
  47. }
  48. }
  49. if startTimeStr != "" {
  50. if startTime, err = strconv.ParseInt(startTimeStr, 10, 64); err == nil {
  51. startTimeStr = time.Unix(startTime, 0).Format(model.DateSimpleFormat)
  52. }
  53. }
  54. if endTimeStr != "" {
  55. if endTime, err = strconv.ParseInt(endTimeStr, 10, 64); err == nil {
  56. endTimeStr = time.Unix(endTime, 0).Format(model.DateSimpleFormat)
  57. }
  58. } else {
  59. t := time.Now()
  60. endTimeStr = t.Format(model.DateSimpleFormat)
  61. }
  62. stats, err := rpSvc.MonitorStats(c, mode, page, pageSize, adminIDsStr, sortStr, orderStr, startTimeStr, endTimeStr)
  63. if err != nil {
  64. log.Error("svc.MonitorStats(%d,%d,%d,%s,%s,%s,%s,%s) error(%v)", mode, page, pageSize, adminIDsStr, sortStr, orderStr, startTimeStr, endTimeStr, err)
  65. c.JSON(nil, err)
  66. return
  67. }
  68. c.JSON(stats, nil)
  69. }
  70. func monitorSearch(c *bm.Context) {
  71. var (
  72. err error
  73. mode, typ int64
  74. page = int64(conf.Conf.Reply.PageNum)
  75. pageSize = int64(conf.Conf.Reply.PageSize)
  76. sp = &model.SearchMonitorParams{}
  77. )
  78. params := c.Request.Form
  79. modeStr := params.Get("mode")
  80. typeStr := params.Get("type")
  81. oidStr := params.Get("oid")
  82. uidStr := params.Get("uid")
  83. pageStr := params.Get("page")
  84. pageSizeStr := params.Get("pagesize")
  85. if typ, err = strconv.ParseInt(typeStr, 10, 64); err != nil {
  86. log.Warn("strconv.ParseInt(type:%s) error(%v)", typeStr, err)
  87. c.JSON(nil, ecode.RequestErr)
  88. return
  89. }
  90. if modeStr != "" {
  91. if mode, err = strconv.ParseInt(modeStr, 10, 64); err != nil {
  92. log.Warn("strconv.ParseInt(mode:%s) error(%v)", typeStr, err)
  93. c.JSON(nil, ecode.RequestErr)
  94. return
  95. }
  96. }
  97. if oidStr != "" {
  98. if sp.Oid, err = strconv.ParseInt(oidStr, 10, 64); err != nil {
  99. log.Warn("strconv.ParseInt(oid:%s) error(%v)", oidStr, err)
  100. c.JSON(nil, ecode.RequestErr)
  101. return
  102. }
  103. }
  104. if uidStr != "" {
  105. if sp.UID, err = strconv.ParseInt(uidStr, 10, 64); err != nil {
  106. log.Warn("strconv.ParseInt(uid:%s) error(%v)", uidStr, err)
  107. c.JSON(nil, ecode.RequestErr)
  108. return
  109. }
  110. }
  111. sp.Mode = int8(mode)
  112. sp.Type = int8(typ)
  113. sp.Keyword = params.Get("keyword")
  114. sp.NickName = params.Get("nickname")
  115. sp.Sort = params.Get("sort")
  116. sp.Order = params.Get("order")
  117. if pageStr != "" {
  118. if page, err = strconv.ParseInt(pageStr, 10, 64); err != nil || page < 1 {
  119. log.Warn("strconv.ParseInt(page:%s) error(%v)", pageStr, err)
  120. c.JSON(nil, ecode.RequestErr)
  121. return
  122. }
  123. }
  124. if pageSizeStr != "" {
  125. if pageSize, err = strconv.ParseInt(pageSizeStr, 10, 64); err != nil || pageSize < 1 || pageSize > int64(conf.Conf.Reply.PageSize) {
  126. log.Warn("strconv.ParseInt(pagesize:%s) error(%v)", pageSizeStr, err)
  127. c.JSON(nil, ecode.RequestErr)
  128. return
  129. }
  130. }
  131. rpts, err := rpSvc.MonitorSearch(c, sp, page, pageSize)
  132. if err != nil {
  133. log.Error("svc.ReportSearch(%d,%d,%v) error(%v)", page, pageSize, sp, err)
  134. c.JSON(nil, err)
  135. return
  136. }
  137. c.JSON(rpts, nil)
  138. }
  139. func monitorState(c *bm.Context) {
  140. var (
  141. err error
  142. typ int64
  143. state int64
  144. adminID int64
  145. oids []int64
  146. )
  147. params := c.Request.Form
  148. typeStr := params.Get("type")
  149. oidStr := params.Get("oid")
  150. stateStr := params.Get("state")
  151. adminIDStr := params.Get("adid")
  152. remark := params.Get("remark")
  153. if oids, err = xstr.SplitInts(oidStr); err != nil {
  154. log.Warn("strconv.ParseInt(oid:%s) error(%v)", oidStr, err)
  155. c.JSON(nil, ecode.RequestErr)
  156. return
  157. }
  158. if typ, err = strconv.ParseInt(typeStr, 10, 64); err != nil {
  159. log.Warn("strconv.ParseInt(type:%s) error(%v)", typeStr, err)
  160. c.JSON(nil, ecode.RequestErr)
  161. return
  162. }
  163. if state, err = strconv.ParseInt(stateStr, 10, 64); err != nil {
  164. log.Warn("strconv.ParseInt(state:%s) error(%v)", stateStr, err)
  165. c.JSON(nil, ecode.RequestErr)
  166. return
  167. }
  168. if adminIDStr != "" {
  169. if adminID, err = strconv.ParseInt(adminIDStr, 10, 64); err != nil {
  170. log.Warn("strconv.ParseInt(admin:%s) error(%v)", adminIDStr, err)
  171. c.JSON(nil, ecode.RequestErr)
  172. return
  173. }
  174. }
  175. if uid, ok := c.Get("uid"); ok {
  176. adminID = uid.(int64)
  177. }
  178. var adName string
  179. if uname, ok := c.Get("username"); ok {
  180. adName = uname.(string)
  181. }
  182. for _, oid := range oids {
  183. if err = rpSvc.UpMonitorState(c, adminID, adName, oid, int32(typ), int32(state), remark); err != nil {
  184. log.Error("svc.MonitorState(%d,%d,%d,%d,%s) error(%v)", oid, typ, state, adminID, remark, err)
  185. c.JSON(nil, err)
  186. return
  187. }
  188. }
  189. c.JSON(nil, nil)
  190. }
  191. // monitorLog get monitor log.
  192. func monitorLog(c *bm.Context) {
  193. v := new(struct {
  194. Oid int64 `form:"oid" `
  195. Type int32 `form:"type" `
  196. StartTime string `form:"start_time"`
  197. EndTime string `form:"end_time"`
  198. Page int64 `form:"pn"`
  199. PageSize int64 `form:"ps"`
  200. Mid int64 `form:"mid"`
  201. Order string `form:"order"`
  202. Sort string `form:"sort"`
  203. })
  204. var err error
  205. err = c.Bind(v)
  206. if err != nil {
  207. return
  208. }
  209. sp := model.LogSearchParam{
  210. Oid: v.Oid,
  211. Type: v.Type,
  212. Mid: v.Mid,
  213. CtimeFrom: v.StartTime,
  214. CtimeTo: v.EndTime,
  215. Pn: v.Page,
  216. Ps: v.PageSize,
  217. Order: v.Order,
  218. Sort: v.Sort,
  219. }
  220. data, err := rpSvc.MointorLog(c, sp)
  221. res := map[string]interface{}{}
  222. res["data"] = data
  223. c.JSONMap(res, err)
  224. return
  225. }