F1 告警静默规则 [done]: - 后端 alert_silence.go: CRUD + Toggle (onetime/daily/weekly 三模式) - 告警引擎 isSilenced 集成 (alert_engine.go) - 前端 SilenceRuleTab + SilenceDialog - 路由 /alerts/silences 已注册 F2 审计日志导出 [done]: - 重写 ExportAuditLogs: 真正的 CSV 导出 (encoding/csv + UTF-8 BOM) - 支持 module/action/username/startTime/endTime 筛选 - 导出限制 10000 条防溢出,自动记录审计日志 - JSON 格式向后兼容 (format=json) - 前端 exportLogs 传递查询参数 同时包含累积的前期工作: - 目录重构 internal/ -> controller/model/router (v0.55-v0.57) - 后端分层架构 dto/repository/service/utils - 审计模块全功能 (终端审计/操作审计/登录日志) - asciicast v2 录制格式 - SFTP 文件浏览器 - StatStrip 紧凑统计条 - 在线会话自动刷新 - LiveMonitor WebSocket 诊断修复 验证: go build ✅ | npm run build ✅ | Docker 部署 ✅ | 10 回归端点 ✅ | CSV 导出 ✅ | 静默 CRUD ✅
187 lines
4.5 KiB
Go
187 lines
4.5 KiB
Go
package controller
|
|
|
|
import (
|
|
"net/http"
|
|
"strconv"
|
|
|
|
"ezops/model"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gorm.io/gorm"
|
|
)
|
|
|
|
// NavigationHandler 导航处理器
|
|
type NavigationHandler struct {
|
|
db *gorm.DB
|
|
}
|
|
|
|
// NewNavigationHandler 创建导航处理器
|
|
func NewNavigationHandler(db *gorm.DB) *NavigationHandler {
|
|
return &NavigationHandler{db: db}
|
|
}
|
|
|
|
// ListGroups 获取导航分组列表
|
|
// @Summary 获取导航分组列表
|
|
// @Description 获取所有导航分组列表
|
|
// @Tags 站内导航
|
|
// @Produce json
|
|
// @Security Bearer
|
|
// @Success 200 {object} model.Response{data=[]model.NavigationGroup}
|
|
// @Router /navigations/groups [get]
|
|
func (h *NavigationHandler) ListGroups(c *gin.Context) {
|
|
var groups []model.NavigationGroup
|
|
h.db.Order("sort ASC, created_at ASC").Find(&groups)
|
|
|
|
c.JSON(http.StatusOK, model.Response{
|
|
Code: 200,
|
|
Message: "success",
|
|
Data: groups,
|
|
})
|
|
}
|
|
|
|
// CreateGroup 创建导航分组
|
|
// @Summary 创建导航分组
|
|
// @Description 创建新导航分组
|
|
// @Tags 站内导航
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security Bearer
|
|
// @Param request body model.CreateNavigationGroupRequest true "创建请求"
|
|
// @Success 200 {object} model.Response{data=model.NavigationGroup}
|
|
// @Router /navigations/groups [post]
|
|
func (h *NavigationHandler) CreateGroup(c *gin.Context) {
|
|
var req model.CreateNavigationGroupRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, model.Response{
|
|
Code: 400,
|
|
Message: "请求参数错误: " + err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
group := model.NavigationGroup{
|
|
Name: req.Name,
|
|
Code: req.Code,
|
|
Description: req.Description,
|
|
Icon: req.Icon,
|
|
Sort: req.Sort,
|
|
Enabled: true,
|
|
}
|
|
|
|
if err := h.db.Create(&group).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.Response{
|
|
Code: 500,
|
|
Message: "创建失败",
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, model.Response{
|
|
Code: 200,
|
|
Message: "创建成功",
|
|
Data: group,
|
|
})
|
|
}
|
|
|
|
// UpdateGroup 更新导航分组
|
|
// @Summary 更新导航分组
|
|
// @Description 更新指定导航分组
|
|
// @Tags 站内导航
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Security Bearer
|
|
// @Param id path int true "分组ID"
|
|
// @Param request body model.UpdateNavigationGroupRequest true "更新请求"
|
|
// @Success 200 {object} model.Response{data=model.NavigationGroup}
|
|
// @Router /navigations/groups/{id} [put]
|
|
func (h *NavigationHandler) UpdateGroup(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
|
|
var req model.UpdateNavigationGroupRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, model.Response{
|
|
Code: 400,
|
|
Message: "请求参数错误: " + err.Error(),
|
|
})
|
|
return
|
|
}
|
|
|
|
var group model.NavigationGroup
|
|
if err := h.db.First(&group, id).Error; err != nil {
|
|
c.JSON(http.StatusNotFound, model.Response{
|
|
Code: 404,
|
|
Message: "分组不存在",
|
|
})
|
|
return
|
|
}
|
|
|
|
updates := map[string]interface{}{}
|
|
if req.Name != "" {
|
|
updates["name"] = req.Name
|
|
}
|
|
if req.Description != "" {
|
|
updates["description"] = req.Description
|
|
}
|
|
if req.Icon != "" {
|
|
updates["icon"] = req.Icon
|
|
}
|
|
updates["sort"] = req.Sort
|
|
if req.Enabled != nil {
|
|
updates["enabled"] = *req.Enabled
|
|
}
|
|
|
|
if err := h.db.Model(&group).Updates(updates).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.Response{
|
|
Code: 500,
|
|
Message: "更新失败",
|
|
})
|
|
return
|
|
}
|
|
|
|
h.db.First(&group, id)
|
|
|
|
c.JSON(http.StatusOK, model.Response{
|
|
Code: 200,
|
|
Message: "更新成功",
|
|
Data: group,
|
|
})
|
|
}
|
|
|
|
// DeleteGroup 删除导航分组
|
|
// @Summary 删除导航分组
|
|
// @Description 删除指定导航分组
|
|
// @Tags 站内导航
|
|
// @Produce json
|
|
// @Security Bearer
|
|
// @Param id path int true "分组ID"
|
|
// @Success 200 {object} model.Response
|
|
// @Router /navigations/groups/{id} [delete]
|
|
func (h *NavigationHandler) DeleteGroup(c *gin.Context) {
|
|
id, _ := strconv.Atoi(c.Param("id"))
|
|
|
|
// 删除分组下的所有链接
|
|
if err := h.db.Where("group_id = ?", id).Delete(&model.NavigationLink{}).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.Response{
|
|
Code: 500,
|
|
Message: "删除链接失败",
|
|
})
|
|
return
|
|
}
|
|
|
|
if err := h.db.Delete(&model.NavigationGroup{}, id).Error; err != nil {
|
|
c.JSON(http.StatusInternalServerError, model.Response{
|
|
Code: 500,
|
|
Message: "删除失败",
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, model.Response{
|
|
Code: 200,
|
|
Message: "删除成功",
|
|
})
|
|
}
|
|
|
|
// 导航链接(Link)相关的 CRUD 及收藏功能处理器方法已拆分到 navigation_link.go
|
|
// 涉及方法: ListLinks, CreateLink, UpdateLink, DeleteLink, ToggleFavorite
|