event.go 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package app
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "lcfns/global"
  6. "lcfns/model/app/request"
  7. "lcfns/model/common/response"
  8. "lcfns/model/system"
  9. "lcfns/utils"
  10. "strconv"
  11. )
  12. type EventApi struct {
  13. }
  14. // List 事件信息,以及图片链接。(事件类型,开始时间,处理时间,图片链接)
  15. func (ea *EventApi) List(c *gin.Context) {
  16. var req request.Event
  17. req.GatewayName = c.Query("gatewayName")
  18. t := c.Query("eventType")
  19. atoi, err := strconv.Atoi(t)
  20. if err == nil {
  21. req.EventType = uint(atoi)
  22. }
  23. req.CreatedAt = c.Query("startTime")
  24. req.EndAt = c.Query("endTime")
  25. req.Order = c.Query("order")
  26. b := c.Query("isHandled")
  27. parseBool, err := strconv.ParseBool(b)
  28. if err != nil {
  29. req.IsHandled = &parseBool
  30. }
  31. page := c.Query("Page")
  32. atoi, err = strconv.Atoi(page)
  33. if err == nil {
  34. req.Page = atoi
  35. }
  36. pageSize := c.Query("PageSize")
  37. atoi, err = strconv.Atoi(pageSize)
  38. if err == nil {
  39. req.PageSize = atoi
  40. }
  41. req.UId = utils.GetUserID(c)
  42. //err = c.ShouldBindJSON(&req)
  43. //if err != nil {
  44. // logrus.Error()
  45. //}
  46. list, total, err := eventService.List(req)
  47. if err != nil {
  48. logrus.Error(err)
  49. response.FailWithMessage("查询失败", c)
  50. return
  51. }
  52. response.OkWithData(response.PageResult{
  53. List: list,
  54. Total: total,
  55. Page: req.Page,
  56. PageSize: req.PageSize,
  57. }, c)
  58. }
  59. // EventType 获取事件类型字典
  60. func (ea *EventApi) EventType(c *gin.Context) {
  61. var dic []system.SysDictionaryDetail
  62. //SELECT label AS type_name,value AS type_id FROM sys_dictionaries s1 JOIN sys_dictionary_details s2 ON s1.id = s2.sys_dictionary_id WHERE s1.type = 'eventType';
  63. err := global.Db.Select("label, value").
  64. Table("`sys_dictionaries` JOIN `sys_dictionary_details` ON `sys_dictionaries`.id = `sys_dictionary_details`.sys_dictionary_id").
  65. Where("type = 'eventType'").
  66. Find(&dic).Error
  67. if err != nil {
  68. logrus.Error(err)
  69. response.Fail(c)
  70. return
  71. }
  72. response.OkWithData(dic, c)
  73. }