187 lines
6.1 KiB
Go
187 lines
6.1 KiB
Go
|
package api
|
|||
|
|
|||
|
import (
|
|||
|
|
|||
|
"github.com/flipped-aurora/gin-vue-admin/server/global"
|
|||
|
"github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
|
|||
|
"github.com/flipped-aurora/gin-vue-admin/server/plugin/monitor/model"
|
|||
|
"github.com/flipped-aurora/gin-vue-admin/server/plugin/monitor/model/request"
|
|||
|
"github.com/gin-gonic/gin"
|
|||
|
"go.uber.org/zap"
|
|||
|
)
|
|||
|
|
|||
|
var MonitorConfig = new(MC)
|
|||
|
|
|||
|
type MC struct {}
|
|||
|
|
|||
|
// CreateMonitorConfig 创建监控配置
|
|||
|
// @Tags MonitorConfig
|
|||
|
// @Summary 创建监控配置
|
|||
|
// @Security ApiKeyAuth
|
|||
|
// @Accept application/json
|
|||
|
// @Produce application/json
|
|||
|
// @Param data body model.MonitorConfig true "创建监控配置"
|
|||
|
// @Success 200 {object} response.Response{msg=string} "创建成功"
|
|||
|
// @Router /MC/createMonitorConfig [post]
|
|||
|
func (a *MC) CreateMonitorConfig(c *gin.Context) {
|
|||
|
// 创建业务用Context
|
|||
|
ctx := c.Request.Context()
|
|||
|
|
|||
|
var info model.MonitorConfig
|
|||
|
err := c.ShouldBindJSON(&info)
|
|||
|
if err != nil {
|
|||
|
response.FailWithMessage(err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
err = serviceMonitorConfig.CreateMonitorConfig(ctx,&info)
|
|||
|
if err != nil {
|
|||
|
global.GVA_LOG.Error("创建失败!", zap.Error(err))
|
|||
|
response.FailWithMessage("创建失败:" + err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
response.OkWithMessage("创建成功", c)
|
|||
|
}
|
|||
|
|
|||
|
// DeleteMonitorConfig 删除监控配置
|
|||
|
// @Tags MonitorConfig
|
|||
|
// @Summary 删除监控配置
|
|||
|
// @Security ApiKeyAuth
|
|||
|
// @Accept application/json
|
|||
|
// @Produce application/json
|
|||
|
// @Param data body model.MonitorConfig true "删除监控配置"
|
|||
|
// @Success 200 {object} response.Response{msg=string} "删除成功"
|
|||
|
// @Router /MC/deleteMonitorConfig [delete]
|
|||
|
func (a *MC) DeleteMonitorConfig(c *gin.Context) {
|
|||
|
// 创建业务用Context
|
|||
|
ctx := c.Request.Context()
|
|||
|
|
|||
|
ID := c.Query("ID")
|
|||
|
err := serviceMonitorConfig.DeleteMonitorConfig(ctx,ID)
|
|||
|
if err != nil {
|
|||
|
global.GVA_LOG.Error("删除失败!", zap.Error(err))
|
|||
|
response.FailWithMessage("删除失败:" + err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
response.OkWithMessage("删除成功", c)
|
|||
|
}
|
|||
|
|
|||
|
// DeleteMonitorConfigByIds 批量删除监控配置
|
|||
|
// @Tags MonitorConfig
|
|||
|
// @Summary 批量删除监控配置
|
|||
|
// @Security ApiKeyAuth
|
|||
|
// @Accept application/json
|
|||
|
// @Produce application/json
|
|||
|
// @Success 200 {object} response.Response{msg=string} "批量删除成功"
|
|||
|
// @Router /MC/deleteMonitorConfigByIds [delete]
|
|||
|
func (a *MC) DeleteMonitorConfigByIds(c *gin.Context) {
|
|||
|
// 创建业务用Context
|
|||
|
ctx := c.Request.Context()
|
|||
|
|
|||
|
IDs := c.QueryArray("IDs[]")
|
|||
|
err := serviceMonitorConfig.DeleteMonitorConfigByIds(ctx,IDs)
|
|||
|
if err != nil {
|
|||
|
global.GVA_LOG.Error("批量删除失败!", zap.Error(err))
|
|||
|
response.FailWithMessage("批量删除失败:" + err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
response.OkWithMessage("批量删除成功", c)
|
|||
|
}
|
|||
|
|
|||
|
// UpdateMonitorConfig 更新监控配置
|
|||
|
// @Tags MonitorConfig
|
|||
|
// @Summary 更新监控配置
|
|||
|
// @Security ApiKeyAuth
|
|||
|
// @Accept application/json
|
|||
|
// @Produce application/json
|
|||
|
// @Param data body model.MonitorConfig true "更新监控配置"
|
|||
|
// @Success 200 {object} response.Response{msg=string} "更新成功"
|
|||
|
// @Router /MC/updateMonitorConfig [put]
|
|||
|
func (a *MC) UpdateMonitorConfig(c *gin.Context) {
|
|||
|
// 创建业务用Context
|
|||
|
ctx := c.Request.Context()
|
|||
|
|
|||
|
var info model.MonitorConfig
|
|||
|
err := c.ShouldBindJSON(&info)
|
|||
|
if err != nil {
|
|||
|
response.FailWithMessage(err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
err = serviceMonitorConfig.UpdateMonitorConfig(ctx,info)
|
|||
|
if err != nil {
|
|||
|
global.GVA_LOG.Error("更新失败!", zap.Error(err))
|
|||
|
response.FailWithMessage("更新失败:" + err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
response.OkWithMessage("更新成功", c)
|
|||
|
}
|
|||
|
|
|||
|
// FindMonitorConfig 用id查询监控配置
|
|||
|
// @Tags MonitorConfig
|
|||
|
// @Summary 用id查询监控配置
|
|||
|
// @Security ApiKeyAuth
|
|||
|
// @Accept application/json
|
|||
|
// @Produce application/json
|
|||
|
// @Param ID query uint true "用id查询监控配置"
|
|||
|
// @Success 200 {object} response.Response{data=model.MonitorConfig,msg=string} "查询成功"
|
|||
|
// @Router /MC/findMonitorConfig [get]
|
|||
|
func (a *MC) FindMonitorConfig(c *gin.Context) {
|
|||
|
// 创建业务用Context
|
|||
|
ctx := c.Request.Context()
|
|||
|
|
|||
|
ID := c.Query("ID")
|
|||
|
reMC, err := serviceMonitorConfig.GetMonitorConfig(ctx,ID)
|
|||
|
if err != nil {
|
|||
|
global.GVA_LOG.Error("查询失败!", zap.Error(err))
|
|||
|
response.FailWithMessage("查询失败:" + err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
response.OkWithData(reMC, c)
|
|||
|
}
|
|||
|
// GetMonitorConfigList 分页获取监控配置列表
|
|||
|
// @Tags MonitorConfig
|
|||
|
// @Summary 分页获取监控配置列表
|
|||
|
// @Security ApiKeyAuth
|
|||
|
// @Accept application/json
|
|||
|
// @Produce application/json
|
|||
|
// @Param data query request.MonitorConfigSearch true "分页获取监控配置列表"
|
|||
|
// @Success 200 {object} response.Response{data=response.PageResult,msg=string} "获取成功"
|
|||
|
// @Router /MC/getMonitorConfigList [get]
|
|||
|
func (a *MC) GetMonitorConfigList(c *gin.Context) {
|
|||
|
// 创建业务用Context
|
|||
|
ctx := c.Request.Context()
|
|||
|
|
|||
|
var pageInfo request.MonitorConfigSearch
|
|||
|
err := c.ShouldBindQuery(&pageInfo)
|
|||
|
if err != nil {
|
|||
|
response.FailWithMessage(err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
list, total, err := serviceMonitorConfig.GetMonitorConfigInfoList(ctx,pageInfo)
|
|||
|
if err != nil {
|
|||
|
global.GVA_LOG.Error("获取失败!", zap.Error(err))
|
|||
|
response.FailWithMessage("获取失败:" + err.Error(), c)
|
|||
|
return
|
|||
|
}
|
|||
|
response.OkWithDetailed(response.PageResult{
|
|||
|
List: list,
|
|||
|
Total: total,
|
|||
|
Page: pageInfo.Page,
|
|||
|
PageSize: pageInfo.PageSize,
|
|||
|
}, "获取成功", c)
|
|||
|
}
|
|||
|
// GetMonitorConfigPublic 不需要鉴权的监控配置接口
|
|||
|
// @Tags MonitorConfig
|
|||
|
// @Summary 不需要鉴权的监控配置接口
|
|||
|
// @Accept application/json
|
|||
|
// @Produce application/json
|
|||
|
// @Success 200 {object} response.Response{data=object,msg=string} "获取成功"
|
|||
|
// @Router /MC/getMonitorConfigPublic [get]
|
|||
|
func (a *MC) GetMonitorConfigPublic(c *gin.Context) {
|
|||
|
// 创建业务用Context
|
|||
|
ctx := c.Request.Context()
|
|||
|
|
|||
|
// 此接口不需要鉴权 示例为返回了一个固定的消息接口,一般本接口用于C端服务,需要自己实现业务逻辑
|
|||
|
serviceMonitorConfig.GetMonitorConfigPublic(ctx)
|
|||
|
response.OkWithDetailed(gin.H{"info": "不需要鉴权的监控配置接口信息"}, "获取成功", c)
|
|||
|
}
|