event.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. )
  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. //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';
  38. err := global.Db.Select("label, value").
  39. Table("`sys_dictionaries` JOIN `sys_dictionary_details` ON `sys_dictionaries`.id = `sys_dictionary_details`.sys_dictionary_id").
  40. Where("type = 'eventType'").
  41. Find(&dic).Error
  42. if err != nil {
  43. logrus.Error(err)
  44. response.Fail(c)
  45. return
  46. }
  47. response.OkWithData(dic, c)
  48. }