1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677 |
- package app
- import (
- "github.com/gin-gonic/gin"
- "github.com/sirupsen/logrus"
- "lcfns/global"
- "lcfns/model/app/request"
- "lcfns/model/common/response"
- "lcfns/model/system"
- "lcfns/utils"
- "strconv"
- )
- type EventApi struct {
- }
- // List 事件信息,以及图片链接。(事件类型,开始时间,处理时间,图片链接)
- func (ea *EventApi) List(c *gin.Context) {
- var req request.Event
- req.GatewayName = c.Query("gatewayName")
- t := c.Query("eventType")
- atoi, err := strconv.Atoi(t)
- if err == nil {
- req.EventType = uint(atoi)
- }
- req.CreatedAt = c.Query("startTime")
- req.EndAt = c.Query("endTime")
- req.Order = c.Query("order")
- b := c.Query("isHandled")
- parseBool, err := strconv.ParseBool(b)
- if err != nil {
- req.IsHandled = &parseBool
- }
- page := c.Query("Page")
- atoi, err = strconv.Atoi(page)
- if err == nil {
- req.Page = atoi
- }
- pageSize := c.Query("PageSize")
- atoi, err = strconv.Atoi(pageSize)
- if err == nil {
- req.PageSize = atoi
- }
- req.UId = utils.GetUserID(c)
- //err = c.ShouldBindJSON(&req)
- //if err != nil {
- // logrus.Error()
- //}
- list, total, err := eventService.List(req)
- if err != nil {
- logrus.Error(err)
- response.FailWithMessage("查询失败", c)
- return
- }
- response.OkWithData(response.PageResult{
- List: list,
- Total: total,
- Page: req.Page,
- PageSize: req.PageSize,
- }, c)
- }
- // EventType 获取事件类型字典
- func (ea *EventApi) EventType(c *gin.Context) {
- var dic []system.SysDictionaryDetail
- //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';
- err := global.Db.Select("label, value").
- Table("`sys_dictionaries` JOIN `sys_dictionary_details` ON `sys_dictionaries`.id = `sys_dictionary_details`.sys_dictionary_id").
- Where("type = 'eventType'").
- Find(&dic).Error
- if err != nil {
- logrus.Error(err)
- response.Fail(c)
- return
- }
- response.OkWithData(dic, c)
- }
|