package controller import ( "github.com/gin-gonic/gin" "iot_manager_service/app/middleware" "iot_manager_service/app/warn/model" "iot_manager_service/app/warn/service" "iot_manager_service/util/common" "math" "net/http" "strconv" ) var PlatformAlarm = new(platformAlarmCrl) type platformAlarmCrl struct { } func (c platformAlarmCrl) List(ctx *gin.Context) { value, _ := ctx.Get(middleware.Authorization) claims := value.(*middleware.Claims) filter := model.RequestPlatFormAlartFilter{} current, _ := strconv.Atoi(ctx.Query("current")) size, _ := strconv.Atoi(ctx.Query("size")) if current == 0 { current = 1 } if size <= 0 || size > 100 { size = 10 } err := ctx.ShouldBind(&filter) if err != nil { ctx.JSON(http.StatusBadRequest, err) return } list, total, err := service.PlatformAlarmService.GetList(claims.TenantId, filter) if err != nil { ctx.JSON(http.StatusBadRequest, err) return } pages := math.Ceil(float64((total)) / float64(size)) rsp := model.ResposePlatFormAlart{ Current: current, Size: size, Total: total, Pages: int(pages), Records: list, } ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, rsp)) } func (c platformAlarmCrl) Refresh(ctx *gin.Context) { value, _ := ctx.Get(middleware.Authorization) claims := value.(*middleware.Claims) tenantId := claims.TenantId alarmService := service.PlatformAlarmService go func() { alarmService.Refresh(tenantId) }() ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil)) } func (c platformAlarmCrl) HannleAlart(ctx *gin.Context) { value, _ := ctx.Get(middleware.Authorization) claims := value.(*middleware.Claims) id, _ := strconv.Atoi(ctx.Query("id")) armHandle, _ := strconv.Atoi(ctx.Query("armHandle")) remark := ctx.Query("remark") err := service.PlatformAlarmService.HannleAlart(claims.TenantId, id, armHandle, remark) if err != nil { ctx.JSON(http.StatusBadRequest, err) return } ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil)) } func (c platformAlarmCrl) Detail(ctx *gin.Context) { ctx.JSON(http.StatusOK, common.SuccessResponse(common.Succeeded, nil)) }