123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- package apis
- import (
- "fmt"
- "github.com/gin-gonic/gin"
- "github.com/go-admin-team/go-admin-core/sdk/api"
- "github.com/go-admin-team/go-admin-core/sdk/pkg/jwtauth/user"
- _ "github.com/go-admin-team/go-admin-core/sdk/pkg/response"
- "go-admin/app/admin/models"
- "go-admin/app/admin/service"
- "go-admin/app/admin/service/dto"
- "go-admin/common/actions"
- )
- type OtMonitorRules struct {
- api.Api
- }
- // GetPage 获取OtMonitorRules列表
- // @Summary 获取OtMonitorRules列表
- // @Description 获取OtMonitorRules列表
- // @Tags OtMonitorRules
- // @Param kind query string false "所属分类:trace,metric,log"
- // @Param group query string false "子类型,聚类筛选,可自添加"
- // @Param name query string false "事件项名称,不可重复"
- // @Param monitorAlias query string false "监控项别名"
- // @Param dataSource query string false "数据源"
- // @Param verify query int64 false "是否验证成功"
- // @Param power query int64 false "是否启用"
- // @Param pageSize query int false "页条数"
- // @Param pageIndex query int false "页码"
- // @Success 200 {object} response.Response{data=response.Page{list=[]models.OtMonitorRules}} "{"code": 200, "data": [...]}"
- // @Router /api/v1/ot-monitor-rules [get]
- // @Security Bearer
- func (e OtMonitorRules) GetPage(c *gin.Context) {
- req := dto.OtMonitorRulesGetPageReq{}
- s := service.OtMonitorRules{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- p := actions.GetPermissionFromContext(c)
- list := make([]models.OtMRAndAP, 0)
- var count int64
- err = s.GetPage(&req, p, &list, &count)
- if err != nil {
- e.Error(500, err, fmt.Sprintf("获取OtMonitorRules失败,\r\n失败信息 %s", err.Error()))
- return
- }
- e.PageOK(list, int(count), req.GetPageIndex(), req.GetPageSize(), "查询成功")
- }
- // Get 获取OtMonitorRules
- // @Summary 获取OtMonitorRules
- // @Description 获取OtMonitorRules
- // @Tags OtMonitorRules
- // @Param id path int false "id"
- // @Success 200 {object} response.Response{data=models.OtMonitorRules} "{"code": 200, "data": [...]}"
- // @Router /api/v1/ot-monitor-rules/{id} [get]
- // @Security Bearer
- func (e OtMonitorRules) Get(c *gin.Context) {
- req := dto.OtMonitorRulesGetReq{}
- s := service.OtMonitorRules{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- var object models.OtMonitorRules
- p := actions.GetPermissionFromContext(c)
- err = s.Get(&req, p, &object)
- if err != nil {
- e.Error(500, err, fmt.Sprintf("获取OtMonitorRules失败,\r\n失败信息 %s", err.Error()))
- return
- }
- e.OK(object, "查询成功")
- }
- // Insert 创建OtMonitorRules
- // @Summary 创建OtMonitorRules
- // @Description 创建OtMonitorRules
- // @Tags OtMonitorRules
- // @Accept application/json
- // @Product application/json
- // @Param data body dto.OtMonitorRulesInsertReq true "data"
- // @Success 200 {object} response.Response "{"code": 200, "message": "添加成功"}"
- // @Router /api/v1/ot-monitor-rules [post]
- // @Security Bearer
- func (e OtMonitorRules) Insert(c *gin.Context) {
- req := dto.OtMonitorRulesInsertReq{}
- s := service.OtMonitorRules{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- // 设置创建人
- req.SetCreateBy(user.GetUserId(c))
- err = s.Insert(&req)
- if err != nil {
- e.Error(500, err, fmt.Sprintf("创建OtMonitorRules失败,\r\n失败信息 %s", err.Error()))
- return
- }
- e.OK(req.GetId(), "创建成功")
- }
- // Update 修改OtMonitorRules
- // @Summary 修改OtMonitorRules
- // @Description 修改OtMonitorRules
- // @Tags OtMonitorRules
- // @Accept application/json
- // @Product application/json
- // @Param id path int true "id"
- // @Param data body dto.OtMonitorRulesUpdateReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "message": "修改成功"}"
- // @Router /api/v1/ot-monitor-rules/{id} [put]
- // @Security Bearer
- func (e OtMonitorRules) Update(c *gin.Context) {
- req := dto.OtMonitorRulesUpdateReq{}
- s := service.OtMonitorRules{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- req.SetUpdateBy(user.GetUserId(c))
- p := actions.GetPermissionFromContext(c)
- err = s.Update(&req, p)
- if err != nil {
- e.Error(500, err, fmt.Sprintf("修改OtMonitorRules失败,\r\n失败信息 %s", err.Error()))
- return
- }
- e.OK(req.GetId(), "修改成功")
- }
- // Delete 删除OtMonitorRules
- // @Summary 删除OtMonitorRules
- // @Description 删除OtMonitorRules
- // @Tags OtMonitorRules
- // @Param data body dto.OtMonitorRulesDeleteReq true "body"
- // @Success 200 {object} response.Response "{"code": 200, "message": "删除成功"}"
- // @Router /api/v1/ot-monitor-rules [delete]
- // @Security Bearer
- func (e OtMonitorRules) Delete(c *gin.Context) {
- s := service.OtMonitorRules{}
- req := dto.OtMonitorRulesDeleteReq{}
- err := e.MakeContext(c).
- MakeOrm().
- Bind(&req).
- MakeService(&s.Service).
- Errors
- if err != nil {
- e.Logger.Error(err)
- e.Error(500, err, err.Error())
- return
- }
- // req.SetUpdateBy(user.GetUserId(c))
- p := actions.GetPermissionFromContext(c)
- err = s.Remove(&req, p)
- if err != nil {
- e.Error(500, err, fmt.Sprintf("删除OtMonitorRules失败,\r\n失败信息 %s", err.Error()))
- return
- }
- e.OK(req.GetId(), "删除成功")
- }
|