mirror of
https://gitee.com/xiangheng/x_admin.git
synced 2025-10-29 02:32:46 +08:00
完成flow,监控迁移
This commit is contained in:
48
server/controller/admin/monitorController/monitor.go
Normal file
48
server/controller/admin/monitorController/monitor.go
Normal file
@@ -0,0 +1,48 @@
|
||||
package monitorController
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"x_admin/core/response"
|
||||
"x_admin/middleware"
|
||||
"x_admin/util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func RegisterRoute(rg *gin.RouterGroup) {
|
||||
handle := monitorHandler{}
|
||||
|
||||
rg = rg.Group("/monitor", middleware.TokenAuth())
|
||||
rg.GET("/cache", middleware.RecordLog("缓存监控"), handle.cache)
|
||||
rg.GET("/server", middleware.RecordLog("服务监控"), handle.server)
|
||||
}
|
||||
|
||||
type monitorHandler struct{}
|
||||
|
||||
// cache 缓存监控
|
||||
func (mh monitorHandler) cache(c *gin.Context) {
|
||||
cmdStatsMap := util.RedisUtil.Info("commandstats")
|
||||
var stats []map[string]string
|
||||
for k, v := range cmdStatsMap {
|
||||
stats = append(stats, map[string]string{
|
||||
"name": strings.Split(k, "_")[1],
|
||||
"value": v[strings.Index(v, "=")+1 : strings.Index(v, ",")],
|
||||
})
|
||||
}
|
||||
response.OkWithData(c, map[string]interface{}{
|
||||
"info": util.RedisUtil.Info(),
|
||||
"commandStats": stats,
|
||||
"dbSize": util.RedisUtil.DBSize(),
|
||||
})
|
||||
}
|
||||
|
||||
// server 服务监控
|
||||
func (mh monitorHandler) server(c *gin.Context) {
|
||||
response.OkWithData(c, map[string]interface{}{
|
||||
"cpu": util.ServerUtil.GetCpuInfo(),
|
||||
"mem": util.ServerUtil.GetMemInfo(),
|
||||
"sys": util.ServerUtil.GetSysInfo(),
|
||||
"disk": util.ServerUtil.GetDiskInfo(),
|
||||
"go": util.ServerUtil.GetGoInfo(),
|
||||
})
|
||||
}
|
||||
288
server/controller/admin/monitorController/monitor_client_ctl.go
Normal file
288
server/controller/admin/monitorController/monitor_client_ctl.go
Normal file
@@ -0,0 +1,288 @@
|
||||
package monitorController
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"x_admin/core"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
. "x_admin/schema/monitorSchema"
|
||||
"x_admin/service/monitorService"
|
||||
"x_admin/util"
|
||||
"x_admin/util/excel2"
|
||||
"x_admin/util/img_util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/sync/singleflight"
|
||||
)
|
||||
|
||||
type MonitorClientHandler struct {
|
||||
requestGroup singleflight.Group
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息列表
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param PageNo query int true "页码"
|
||||
// @Param PageSize query int true "每页数量"
|
||||
// @Param ProjectKey query string false "项目key"
|
||||
// @Param ClientId query string false "sdk生成的客户端id"
|
||||
// @Param UserId query string false "用户id"
|
||||
// @Param Os query string false "系统"
|
||||
// @Param Browser query string false "浏览器"
|
||||
// @Param Country query string false "国家"
|
||||
// @Param Province query string false "省份"
|
||||
// @Param City query string false "城市"
|
||||
// @Param Operator query string false "电信运营商"
|
||||
// @Param Ip query string false "ip"
|
||||
// @Param Width query number false "屏幕"
|
||||
// @Param Height query number false "屏幕高度"
|
||||
// @Param Ua query string false "ua记录"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
//
|
||||
// @Success 200 {object} response.Response{ data=response.PageResp{ lists=[]MonitorClientResp}} "成功"
|
||||
// @Router /api/admin/monitor_client/list [get]
|
||||
func (hd *MonitorClientHandler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq MonitorClientListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorClientService.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息列表-所有
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
// @Produce json
|
||||
// @Param ProjectKey query string false "项目key"
|
||||
// @Param ClientId query string false "sdk生成的客户端id"
|
||||
// @Param UserId query string false "用户id"
|
||||
// @Param Os query string false "系统"
|
||||
// @Param Browser query string false "浏览器"
|
||||
// @Param Country query string false "国家"
|
||||
// @Param Province query string false "省份"
|
||||
// @Param City query string false "城市"
|
||||
// @Param Operator query string false "电信运营商"
|
||||
// @Param Ip query string false "ip"
|
||||
// @Param Width query number false "屏幕"
|
||||
// @Param Height query number false "屏幕高度"
|
||||
// @Param Ua query string false "ua记录"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
// @Success 200 {object} response.Response{ data=[]MonitorClientResp} "成功"
|
||||
// @Router /api/admin/monitor_client/listAll [get]
|
||||
func (hd *MonitorClientHandler) ListAll(c *gin.Context) {
|
||||
var listReq MonitorClientListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorClientService.ListAll(listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
func (hd *MonitorClientHandler) ErrorUsers(c *gin.Context) {
|
||||
var Req MonitorClientDetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &Req)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorClientService.ErrorUsers(Req.Id)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息详情
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id query number false "uuid"
|
||||
// @Success 200 {object} response.Response{ data=MonitorClientResp} "成功"
|
||||
// @Router /api/admin/monitor_client/detail [get]
|
||||
func (hd *MonitorClientHandler) Detail(c *gin.Context) {
|
||||
var detailReq MonitorClientDetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err, _ := hd.requestGroup.Do("MonitorClient:Detail:"+strconv.Itoa(detailReq.Id), func() (any, error) {
|
||||
v, err := monitorService.MonitorClientService.Detail(detailReq.Id)
|
||||
return v, err
|
||||
})
|
||||
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息新增
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param ProjectKey body string false "项目key"
|
||||
// @Param ClientId body string false "sdk生成的客户端id"
|
||||
// @Param UserId body string false "用户id"
|
||||
// @Param Os body string false "系统"
|
||||
// @Param Browser body string false "浏览器"
|
||||
// @Param Country query string false "国家"
|
||||
// @Param Province query string false "省份"
|
||||
// @Param City query string false "城市"
|
||||
// @Param Operator query string false "电信运营商"
|
||||
// @Param Ip query string false "ip"
|
||||
// @Param Width body number false "屏幕"
|
||||
// @Param Height body number false "屏幕高度"
|
||||
// @Param Ua body string false "ua记录"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_client/add [post]
|
||||
func (hd *MonitorClientHandler) Add(c *gin.Context) {
|
||||
data, err := url.QueryUnescape(c.Query("data"))
|
||||
if err != nil {
|
||||
c.Data(200, "image/gif", img_util.EmptyGif())
|
||||
return
|
||||
}
|
||||
var addReq MonitorClientAddReq
|
||||
json.Unmarshal([]byte(data), &addReq)
|
||||
|
||||
lastClient, err := monitorService.MonitorClientService.DetailByClientId(*addReq.ClientId)
|
||||
|
||||
uaStr := c.GetHeader("user-agent")
|
||||
ip := c.ClientIP()
|
||||
|
||||
if err == nil {
|
||||
last := lastClient.UserId + lastClient.Width.String() + lastClient.Height.String() + lastClient.Ip + lastClient.Ua
|
||||
newStr := *addReq.UserId + addReq.Width.String() + addReq.Height.String() + ip + uaStr
|
||||
if last == newStr {
|
||||
// 前后数据一样,不用创建新的数据
|
||||
fmt.Println("前后数据一样,不用创建新的数据")
|
||||
c.Data(200, "image/gif", img_util.EmptyGif())
|
||||
return
|
||||
} else {
|
||||
// 新建的话,需要清除lastClient对应的缓存
|
||||
monitorService.MonitorClientService.CacheUtil.RemoveCache("ClientId:" + lastClient.ClientId)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
if uaStr != "" {
|
||||
ua := core.UAParser.Parse(uaStr)
|
||||
addReq.Ua = &uaStr
|
||||
addReq.Os = &ua.Os.Family
|
||||
addReq.Browser = &ua.UserAgent.Family
|
||||
}
|
||||
|
||||
addReq.Ip = &ip
|
||||
if ip != "" && ip != "127.0.0.1" {
|
||||
regionInfo := util.IpUtil.Parse(ip)
|
||||
// regionInfo := util.IpUtil.Parse("118.24.157.190")
|
||||
addReq.City = ®ionInfo.City
|
||||
addReq.Country = ®ionInfo.Country
|
||||
addReq.Operator = ®ionInfo.Operator
|
||||
addReq.Province = ®ionInfo.Province
|
||||
}
|
||||
|
||||
monitorService.MonitorClientService.Add(addReq)
|
||||
|
||||
c.Data(200, "image/gif", img_util.EmptyGif())
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息删除
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id body number false "uuid"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_client/del [post]
|
||||
func (hd *MonitorClientHandler) Del(c *gin.Context) {
|
||||
var delReq MonitorClientDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, monitorService.MonitorClientService.Del(delReq.Id))
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息删除-批量
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
//
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Ids body string false "逗号分割的id"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_client/delBatch [post]
|
||||
func (hd *MonitorClientHandler) DelBatch(c *gin.Context) {
|
||||
var delReq MonitorClientDelBatchReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
if delReq.Ids == "" {
|
||||
response.FailWithMsg(c, response.SystemError, "请选择要删除的数据")
|
||||
return
|
||||
}
|
||||
var Ids = strings.Split(delReq.Ids, ",")
|
||||
|
||||
response.CheckAndResp(c, monitorService.MonitorClientService.DelBatch(Ids))
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息导出
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param ProjectKey query string false "项目key"
|
||||
// @Param ClientId query string false "sdk生成的客户端id"
|
||||
// @Param UserId query string false "用户id"
|
||||
// @Param Os query string false "系统"
|
||||
// @Param Browser query string false "浏览器"
|
||||
// @Param Country query string false "国家"
|
||||
// @Param Province query string false "省份"
|
||||
// @Param City query string false "城市"
|
||||
// @Param Operator query string false "电信运营商"
|
||||
// @Param Ip query string false "ip"
|
||||
// @Param Width query number false "屏幕"
|
||||
// @Param Height query number false "屏幕高度"
|
||||
// @Param Ua query string false "ua记录"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
// @Router /api/admin/monitor_client/ExportFile [get]
|
||||
func (hd *MonitorClientHandler) ExportFile(c *gin.Context) {
|
||||
var listReq MonitorClientListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorClientService.ExportFile(listReq)
|
||||
if err != nil {
|
||||
response.FailWithMsg(c, response.SystemError, "查询信息失败")
|
||||
return
|
||||
}
|
||||
f, err := excel2.Export(res, monitorService.MonitorClientService.GetExcelCol(), "Sheet1", "监控-客户端信息")
|
||||
if err != nil {
|
||||
response.FailWithMsg(c, response.SystemError, "导出失败")
|
||||
return
|
||||
}
|
||||
excel2.DownLoadExcel("监控-客户端信息"+time.Now().Format("20060102-150405"), c.Writer, f)
|
||||
}
|
||||
|
||||
// @Summary 监控-客户端信息导入
|
||||
// @Tags monitor_client-监控-客户端信息
|
||||
// @Produce json
|
||||
// @Router /api/admin/monitor_client/ImportFile [post]
|
||||
func (hd *MonitorClientHandler) ImportFile(c *gin.Context) {
|
||||
file, _, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "文件不存在")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
importList := []MonitorClientResp{}
|
||||
err = excel2.GetExcelData(file, &importList, monitorService.MonitorClientService.GetExcelCol())
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = monitorService.MonitorClientService.ImportFile(importList)
|
||||
response.CheckAndResp(c, err)
|
||||
}
|
||||
217
server/controller/admin/monitorController/monitor_error_ctl.go
Normal file
217
server/controller/admin/monitorController/monitor_error_ctl.go
Normal file
@@ -0,0 +1,217 @@
|
||||
package monitorController
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
. "x_admin/schema/monitorSchema"
|
||||
"x_admin/service/monitorService"
|
||||
"x_admin/util"
|
||||
"x_admin/util/excel2"
|
||||
"x_admin/util/img_util"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/sync/singleflight"
|
||||
)
|
||||
|
||||
type MonitorErrorHandler struct {
|
||||
requestGroup singleflight.Group
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列列表
|
||||
// @Tags monitor_error-监控-错误列
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param PageNo query int true "页码"
|
||||
// @Param PageSize query int true "每页数量"
|
||||
// @Param ProjectKey query string false "项目key"
|
||||
// @Param EventType query string false "事件类型"
|
||||
// @Param Path query string false "URL地址"
|
||||
// @Param Message query string false "错误消息"
|
||||
// @Param Stack query string false "错误堆栈"
|
||||
// @Param Md5 query string false "md5"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
//
|
||||
// @Success 200 {object} response.Response{ data=response.PageResp{ lists=[]MonitorErrorResp}} "成功"
|
||||
// @Router /api/admin/monitor_error/list [get]
|
||||
func (hd *MonitorErrorHandler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq MonitorErrorListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorErrorService.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列列表-所有
|
||||
// @Tags monitor_error-监控-错误列
|
||||
// @Produce json
|
||||
// @Param ProjectKey query string false "项目key"
|
||||
// @Param EventType query string false "事件类型"
|
||||
// @Param Path query string false "URL地址"
|
||||
// @Param Message query string false "错误消息"
|
||||
// @Param Stack query string false "错误堆栈"
|
||||
// @Param Md5 query string false "md5"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
// @Success 200 {object} response.Response{ data=[]MonitorErrorResp} "成功"
|
||||
// @Router /api/admin/monitor_error/listAll [get]
|
||||
func (hd *MonitorErrorHandler) ListAll(c *gin.Context) {
|
||||
var listReq MonitorErrorListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorErrorService.ListAll(listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列详情
|
||||
// @Tags monitor_error-监控-错误列
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id query number false "错误id"
|
||||
// @Success 200 {object} response.Response{ data=MonitorErrorResp} "成功"
|
||||
// @Router /api/admin/monitor_error/detail [get]
|
||||
func (hd *MonitorErrorHandler) Detail(c *gin.Context) {
|
||||
var detailReq MonitorErrorDetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err, _ := hd.requestGroup.Do("MonitorError:Detail:"+strconv.Itoa(detailReq.Id), func() (any, error) {
|
||||
v, err := monitorService.MonitorErrorService.Detail(detailReq.Id)
|
||||
return v, err
|
||||
})
|
||||
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列新增
|
||||
// @Tags monitor_error-监控-错误列
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param ProjectKey body string false "项目key"
|
||||
// @Param EventType body string false "事件类型"
|
||||
// @Param Path body string false "URL地址"
|
||||
// @Param Message body string false "错误消息"
|
||||
// @Param Stack body string false "错误堆栈"
|
||||
// @Param Md5 body string false "md5"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_error/add [post]
|
||||
func (hd *MonitorErrorHandler) Add(c *gin.Context) {
|
||||
data, err := url.QueryUnescape(c.Query("data"))
|
||||
if err != nil {
|
||||
c.Data(200, "image/gif", img_util.EmptyGif())
|
||||
return
|
||||
}
|
||||
|
||||
var addReq []MonitorErrorAddReq
|
||||
json.Unmarshal([]byte(data), &addReq)
|
||||
|
||||
// if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &addReq)) {
|
||||
// return
|
||||
// }
|
||||
for i := 0; i < len(addReq); i++ {
|
||||
monitorService.MonitorErrorService.Add(addReq[i])
|
||||
}
|
||||
c.Data(200, "image/gif", img_util.EmptyGif())
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列删除
|
||||
// @Tags monitor_error-监控-错误列
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id body number false "错误id"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_error/del [post]
|
||||
func (hd *MonitorErrorHandler) Del(c *gin.Context) {
|
||||
var delReq MonitorErrorDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, monitorService.MonitorErrorService.Del(delReq.Id))
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列删除-批量
|
||||
// @Tags monitor_error-监控-错误列
|
||||
//
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Ids body string false "逗号分割的id"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_error/delBatch [post]
|
||||
func (hd *MonitorErrorHandler) DelBatch(c *gin.Context) {
|
||||
var delReq MonitorErrorDelBatchReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
if delReq.Ids == "" {
|
||||
response.FailWithMsg(c, response.SystemError, "请选择要删除的数据")
|
||||
return
|
||||
}
|
||||
var Ids = strings.Split(delReq.Ids, ",")
|
||||
|
||||
response.CheckAndResp(c, monitorService.MonitorErrorService.DelBatch(Ids))
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列导出
|
||||
// @Tags monitor_error-监控-错误列
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param ProjectKey query string false "项目key"
|
||||
// @Param EventType query string false "事件类型"
|
||||
// @Param Path query string false "URL地址"
|
||||
// @Param Message query string false "错误消息"
|
||||
// @Param Stack query string false "错误堆栈"
|
||||
// @Param Md5 query string false "md5"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
// @Router /api/admin/monitor_error/ExportFile [get]
|
||||
func (hd *MonitorErrorHandler) ExportFile(c *gin.Context) {
|
||||
var listReq MonitorErrorListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorErrorService.ExportFile(listReq)
|
||||
if err != nil {
|
||||
response.FailWithMsg(c, response.SystemError, "查询信息失败")
|
||||
return
|
||||
}
|
||||
f, err := excel2.Export(res, monitorService.MonitorErrorService.GetExcelCol(), "Sheet1", "监控-错误列")
|
||||
if err != nil {
|
||||
response.FailWithMsg(c, response.SystemError, "导出失败")
|
||||
return
|
||||
}
|
||||
excel2.DownLoadExcel("监控-错误列"+time.Now().Format("20060102-150405"), c.Writer, f)
|
||||
}
|
||||
|
||||
// @Summary 监控-错误列导入
|
||||
// @Tags monitor_error-监控-错误列
|
||||
// @Produce json
|
||||
// @Router /api/admin/monitor_error/ImportFile [post]
|
||||
func (hd *MonitorErrorHandler) ImportFile(c *gin.Context) {
|
||||
file, _, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "文件不存在")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
importList := []MonitorErrorResp{}
|
||||
err = excel2.GetExcelData(file, &importList, monitorService.MonitorErrorService.GetExcelCol())
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = monitorService.MonitorErrorService.ImportFile(importList)
|
||||
response.CheckAndResp(c, err)
|
||||
}
|
||||
221
server/controller/admin/monitorController/monitor_project_ctl.go
Normal file
221
server/controller/admin/monitorController/monitor_project_ctl.go
Normal file
@@ -0,0 +1,221 @@
|
||||
package monitorController
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
"x_admin/core/request"
|
||||
"x_admin/core/response"
|
||||
. "x_admin/schema/monitorSchema"
|
||||
"x_admin/service/monitorService"
|
||||
"x_admin/util"
|
||||
"x_admin/util/excel2"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"golang.org/x/sync/singleflight"
|
||||
)
|
||||
|
||||
type MonitorProjectHandler struct {
|
||||
requestGroup singleflight.Group
|
||||
}
|
||||
|
||||
// @Summary 监控项目列表
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param PageNo query int true "页码"
|
||||
// @Param PageSize query int true "每页数量"
|
||||
// @Param ProjectKey query string false "项目uuid"
|
||||
// @Param ProjectName query string false "项目名称"
|
||||
// @Param ProjectType query string false "项目类型go java web node php 等"
|
||||
// @Param Status query number false "是否启用: 0=否, 1=是"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
// @Param UpdateTimeStart query string false "更新时间"
|
||||
// @Param UpdateTimeEnd query string false "更新时间"
|
||||
//
|
||||
// @Success 200 {object} response.Response{ data=response.PageResp{ lists=[]MonitorProjectResp}} "成功"
|
||||
// @Router /api/admin/monitor_project/list [get]
|
||||
func (hd *MonitorProjectHandler) List(c *gin.Context) {
|
||||
var page request.PageReq
|
||||
var listReq MonitorProjectListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &page)) {
|
||||
return
|
||||
}
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorProjectService.List(page, listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控项目列表-所有
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Param ProjectKey query string false "项目uuid"
|
||||
// @Param ProjectName query string false "项目名称"
|
||||
// @Param ProjectType query string false "项目类型go java web node php 等"
|
||||
// @Param Status query number false "是否启用: 0=否, 1=是"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
// @Param UpdateTimeStart query string false "更新时间"
|
||||
// @Param UpdateTimeEnd query string false "更新时间"
|
||||
// @Success 200 {object} response.Response{ data=[]MonitorProjectResp} "成功"
|
||||
// @Router /api/admin/monitor_project/listAll [get]
|
||||
func (hd *MonitorProjectHandler) ListAll(c *gin.Context) {
|
||||
var listReq MonitorProjectListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorProjectService.ListAll(listReq)
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控项目详情
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id query number false "项目id"
|
||||
// @Success 200 {object} response.Response{ data=MonitorProjectResp} "成功"
|
||||
// @Router /api/admin/monitor_project/detail [get]
|
||||
func (hd *MonitorProjectHandler) Detail(c *gin.Context) {
|
||||
var detailReq MonitorProjectDetailReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &detailReq)) {
|
||||
return
|
||||
}
|
||||
res, err, _ := hd.requestGroup.Do("MonitorProject:Detail:"+strconv.Itoa(detailReq.Id), func() (any, error) {
|
||||
v, err := monitorService.MonitorProjectService.Detail(detailReq.Id)
|
||||
return v, err
|
||||
})
|
||||
|
||||
response.CheckAndRespWithData(c, res, err)
|
||||
}
|
||||
|
||||
// @Summary 监控项目新增
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param ProjectKey body string false "项目uuid"
|
||||
// @Param ProjectName body string false "项目名称"
|
||||
// @Param ProjectType body string false "项目类型go java web node php 等"
|
||||
// @Param Status body number false "是否启用: 0=否, 1=是"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_project/add [post]
|
||||
func (hd *MonitorProjectHandler) Add(c *gin.Context) {
|
||||
var addReq MonitorProjectAddReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &addReq)) {
|
||||
return
|
||||
}
|
||||
createId, e := monitorService.MonitorProjectService.Add(addReq)
|
||||
response.CheckAndRespWithData(c, createId, e)
|
||||
}
|
||||
|
||||
// @Summary 监控项目编辑
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id body number false "项目id"
|
||||
// @Param ProjectKey body string false "项目uuid"
|
||||
// @Param ProjectName body string false "项目名称"
|
||||
// @Param ProjectType body string false "项目类型go java web node php 等"
|
||||
// @Param Status body number false "是否启用: 0=否, 1=是"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_project/edit [post]
|
||||
func (hd *MonitorProjectHandler) Edit(c *gin.Context) {
|
||||
var editReq MonitorProjectEditReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &editReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndRespWithData(c, editReq.Id, monitorService.MonitorProjectService.Edit(editReq))
|
||||
}
|
||||
|
||||
// @Summary 监控项目删除
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Id body number false "项目id"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_project/del [post]
|
||||
func (hd *MonitorProjectHandler) Del(c *gin.Context) {
|
||||
var delReq MonitorProjectDelReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
response.CheckAndResp(c, monitorService.MonitorProjectService.Del(delReq.Id))
|
||||
}
|
||||
|
||||
// @Summary 监控项目删除-批量
|
||||
// @Tags monitor_project-监控项目
|
||||
//
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param Ids body string false "逗号分割的id"
|
||||
// @Success 200 {object} response.Response "成功"
|
||||
// @Router /api/admin/monitor_project/delBatch [post]
|
||||
func (hd *MonitorProjectHandler) DelBatch(c *gin.Context) {
|
||||
var delReq MonitorProjectDelBatchReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyJSON(c, &delReq)) {
|
||||
return
|
||||
}
|
||||
if delReq.Ids == "" {
|
||||
response.FailWithMsg(c, response.SystemError, "请选择要删除的数据")
|
||||
return
|
||||
}
|
||||
var Ids = strings.Split(delReq.Ids, ",")
|
||||
|
||||
response.CheckAndResp(c, monitorService.MonitorProjectService.DelBatch(Ids))
|
||||
}
|
||||
|
||||
// @Summary 监控项目导出
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Param Token header string true "token"
|
||||
// @Param ProjectKey query string false "项目uuid"
|
||||
// @Param ProjectName query string false "项目名称"
|
||||
// @Param ProjectType query string false "项目类型go java web node php 等"
|
||||
// @Param Status query number false "是否启用: 0=否, 1=是"
|
||||
// @Param CreateTimeStart query string false "创建时间"
|
||||
// @Param CreateTimeEnd query string false "创建时间"
|
||||
// @Param UpdateTimeStart query string false "更新时间"
|
||||
// @Param UpdateTimeEnd query string false "更新时间"
|
||||
// @Router /api/admin/monitor_project/ExportFile [get]
|
||||
func (hd *MonitorProjectHandler) ExportFile(c *gin.Context) {
|
||||
var listReq MonitorProjectListReq
|
||||
if response.IsFailWithResp(c, util.VerifyUtil.VerifyQuery(c, &listReq)) {
|
||||
return
|
||||
}
|
||||
res, err := monitorService.MonitorProjectService.ExportFile(listReq)
|
||||
if err != nil {
|
||||
response.FailWithMsg(c, response.SystemError, "查询信息失败")
|
||||
return
|
||||
}
|
||||
f, err := excel2.Export(res, monitorService.MonitorProjectService.GetExcelCol(), "Sheet1", "监控项目")
|
||||
if err != nil {
|
||||
response.FailWithMsg(c, response.SystemError, "导出失败")
|
||||
return
|
||||
}
|
||||
excel2.DownLoadExcel("监控项目"+time.Now().Format("20060102-150405"), c.Writer, f)
|
||||
}
|
||||
|
||||
// @Summary 监控项目导入
|
||||
// @Tags monitor_project-监控项目
|
||||
// @Produce json
|
||||
// @Router /api/admin/monitor_project/ImportFile [post]
|
||||
func (hd *MonitorProjectHandler) ImportFile(c *gin.Context) {
|
||||
file, _, err := c.Request.FormFile("file")
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, "文件不存在")
|
||||
return
|
||||
}
|
||||
defer file.Close()
|
||||
importList := []MonitorProjectResp{}
|
||||
err = excel2.GetExcelData(file, &importList, monitorService.MonitorProjectService.GetExcelCol())
|
||||
if err != nil {
|
||||
c.String(http.StatusInternalServerError, err.Error())
|
||||
return
|
||||
}
|
||||
|
||||
err = monitorService.MonitorProjectService.ImportFile(importList)
|
||||
response.CheckAndResp(c, err)
|
||||
}
|
||||
Reference in New Issue
Block a user