event.go 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package app
  2. import (
  3. "github.com/gin-gonic/gin"
  4. "github.com/sirupsen/logrus"
  5. "lc-fangdaosha/global"
  6. "lc-fangdaosha/model/app/request"
  7. "lc-fangdaosha/model/common/response"
  8. "lc-fangdaosha/model/system"
  9. "lc-fangdaosha/utils"
  10. )
  11. type EventApi struct {
  12. }
  13. // List 获取事件信息列表
  14. func (ea *EventApi) List(c *gin.Context) {
  15. var req request.Event
  16. req.UId = utils.GetUserID(c)
  17. err := c.ShouldBindJSON(&req)
  18. if err != nil {
  19. logrus.Error()
  20. }
  21. list, err := eventService.List(req)
  22. if err != nil {
  23. logrus.Error(err)
  24. response.FailWithMessage("查询失败", c)
  25. return
  26. }
  27. response.OkWithData(response.PageResult{
  28. List: list,
  29. Total: int64(len(list)),
  30. Page: req.Page,
  31. PageSize: req.PageSize,
  32. }, c)
  33. }
  34. // EventType 获取事件类型字典
  35. func (ea *EventApi) EventType(c *gin.Context) {
  36. var dic []system.SysDictionaryDetail
  37. err := global.Db.Select("label, value").
  38. Table("`sys_dictionaries` JOIN `sys_dictionary_details` ON `sys_dictionaries`.id = `sys_dictionary_details`.sys_dictionary_id").
  39. Where("type = 'eventType'").
  40. Find(&dic).Error
  41. if err != nil {
  42. logrus.Error(err)
  43. response.Fail(c)
  44. return
  45. }
  46. response.OkWithData(dic, c)
  47. }