100 lines
2.4 KiB
Go
100 lines
2.4 KiB
Go
package handler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/go-kratos/kratos/v3/errors"
|
|
"kra/internal/service/business"
|
|
"kra/internal/service/dto"
|
|
"net/http"
|
|
"strconv"
|
|
)
|
|
|
|
type AlertGovernance struct {
|
|
service *business.AlertGovernanceService
|
|
}
|
|
|
|
func (h *AlertGovernance) Candidates(c *gin.Context) {
|
|
values, err := h.service.Candidates(c.Request.Context(), c.Query("keyword"))
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, values)
|
|
}
|
|
|
|
func NewAlertGovernance(service *business.AlertGovernanceService) *AlertGovernance {
|
|
return &AlertGovernance{service}
|
|
}
|
|
func (h *AlertGovernance) Gap(c *gin.Context) {
|
|
v, err := h.service.Gap(c.Request.Context())
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *AlertGovernance) SaveGap(c *gin.Context) {
|
|
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 4096)
|
|
var req dto.AlertGapRequest
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
Fail(c, "预警间隔参数不正确")
|
|
return
|
|
}
|
|
if err := h.service.SaveGap(c.Request.Context(), &req); err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OK(c)
|
|
}
|
|
func (h *AlertGovernance) List(c *gin.Context) {
|
|
var req dto.AlertExemptionQuery
|
|
if c.ShouldBindQuery(&req) != nil {
|
|
Fail(c, "查询参数不正确")
|
|
return
|
|
}
|
|
v, err := h.service.List(c.Request.Context(), &req)
|
|
if err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OKWithData(c, v)
|
|
}
|
|
func (h *AlertGovernance) Add(c *gin.Context) {
|
|
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 8192)
|
|
var req dto.AlertExemptionRequest
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
Fail(c, "免预警参数不正确")
|
|
return
|
|
}
|
|
if err := h.service.Add(c.Request.Context(), &req); err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OK(c)
|
|
}
|
|
func (h *AlertGovernance) Remove(c *gin.Context) {
|
|
id, err := strconv.ParseUint(c.Param("id"), 10, 64)
|
|
if err != nil {
|
|
Fail(c, "记录 ID 不正确")
|
|
return
|
|
}
|
|
if err = h.service.Remove(c.Request.Context(), id); err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OK(c)
|
|
}
|
|
func (h *AlertRecord) Ignore(c *gin.Context) {
|
|
c.Request.Body = http.MaxBytesReader(c.Writer, c.Request.Body, 32768)
|
|
var req dto.AlertIgnoreRequest
|
|
if c.ShouldBindJSON(&req) != nil {
|
|
Fail(c, "预警记录参数不正确")
|
|
return
|
|
}
|
|
if err := h.service.Ignore(c.Request.Context(), &req); err != nil {
|
|
Fail(c, errors.FromError(err).Message)
|
|
return
|
|
}
|
|
OK(c)
|
|
}
|