Skip to content

Commit

Permalink
feat:简化sdk调用
Browse files Browse the repository at this point in the history
  • Loading branch information
1340691923 committed Dec 26, 2024
1 parent 7062650 commit cc02fcd
Show file tree
Hide file tree
Showing 107 changed files with 1,889 additions and 578 deletions.
2 changes: 1 addition & 1 deletion backend/api/base_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package api

import (
"bytes"
"ev-tools/backend/response"
"ev-plugin/backend/response"
"github.com/gin-gonic/gin"
"io/ioutil"
)
Expand Down
34 changes: 16 additions & 18 deletions backend/api/es_backup_controller.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
package api

import (
"ev-tools/backend/response"
"ev-tools/backend/services/es_backup"
"ev-plugin/backend/dto"
"ev-plugin/backend/response"
"ev-plugin/backend/services/es_backup_service"
"ev-plugin/backend/vo"
"github.com/1340691923/eve-plugin-sdk-go/ev_api"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/dto"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/vo"
"github.com/1340691923/eve-plugin-sdk-go/util"
"github.com/spf13/cast"

"github.com/gin-gonic/gin"
)

// 备份控制器
type EsBackUpController struct {
*BaseController
esBackUpService *es_backup.EsBackUpService
esBackUpService *es_backup_service.EsBackUpService
}

func NewEsBackUpController(baseController *BaseController, esBackUpService *es_backup.EsBackUpService) *EsBackUpController {
func NewEsBackUpController(baseController *BaseController, esBackUpService *es_backup_service.EsBackUpService) *EsBackUpController {
return &EsBackUpController{BaseController: baseController, esBackUpService: esBackUpService}
}

Expand All @@ -38,7 +36,7 @@ func (this *EsBackUpController) SnapshotRepositoryListAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(esSnapshotInfo.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esSnapshotInfo.EsConnect, util.GetEvUserID(ctx))

list, res, pathRepo, err := this.esBackUpService.SnapshotRepositoryList(ctx, esI, esSnapshotInfo)
if err != nil {
Expand Down Expand Up @@ -69,7 +67,7 @@ func (this *EsBackUpController) SnapshotCreateRepositoryAction(ctx *gin.Context)
return
}

esI := ev_api.NewEvWrapApi(snapshotCreateRepository.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(snapshotCreateRepository.EsConnect, util.GetEvUserID(ctx))

err = this.esBackUpService.SnapshotCreateRepository(ctx, esI, snapshotCreateRepository)
if err != nil {
Expand Down Expand Up @@ -97,7 +95,7 @@ func (this *EsBackUpController) CleanupeRepositoryAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(cleanupeRepository.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(cleanupeRepository.EsConnect, util.GetEvUserID(ctx))

err = this.esBackUpService.CleanUp(ctx, esI, cleanupeRepository)
if err != nil {
Expand Down Expand Up @@ -125,7 +123,7 @@ func (this *EsBackUpController) SnapshotDeleteRepositoryAction(ctx *gin.Context)
return
}

esI := ev_api.NewEvWrapApi(snapshotDeleteRepository.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(snapshotDeleteRepository.EsConnect, util.GetEvUserID(ctx))

err = this.esBackUpService.SnapshotDeleteRepository(ctx, esI, snapshotDeleteRepository)
if err != nil {
Expand Down Expand Up @@ -153,7 +151,7 @@ func (this *EsBackUpController) CreateSnapshotAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(createSnapshot.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(createSnapshot.EsConnect, util.GetEvUserID(ctx))

err = this.esBackUpService.CreateSnapshot(ctx, esI, createSnapshot)
if err != nil {
Expand Down Expand Up @@ -181,7 +179,7 @@ func (this *EsBackUpController) SnapshotListAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(snapshotList.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(snapshotList.EsConnect, util.GetEvUserID(ctx))

res, err := this.esBackUpService.SnapshotList(ctx, esI, snapshotList)
if err != nil {
Expand All @@ -208,7 +206,7 @@ func (this *EsBackUpController) SnapshotDeleteAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(snapshotDelete.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(snapshotDelete.EsConnect, util.GetEvUserID(ctx))

err = this.esBackUpService.SnapshotDelete(ctx, esI, snapshotDelete)
if err != nil {
Expand Down Expand Up @@ -236,7 +234,7 @@ func (this *EsBackUpController) SnapshotDetailAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(snapshotDetail.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(snapshotDetail.EsConnect, util.GetEvUserID(ctx))

res, err := this.esBackUpService.SnapshotDetail(ctx, esI, snapshotDetail)
if err != nil {
Expand All @@ -263,7 +261,7 @@ func (this *EsBackUpController) SnapshotRestoreAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(snapshotRestore.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(snapshotRestore.EsConnect, util.GetEvUserID(ctx))

err = this.esBackUpService.SnapshotRestore(ctx, esI, snapshotRestore)
if err != nil {
Expand Down Expand Up @@ -291,7 +289,7 @@ func (this *EsBackUpController) SnapshotStatusAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(snapshotStatus.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(snapshotStatus.EsConnect, util.GetEvUserID(ctx))

res, err := this.esBackUpService.SnapshotStatus(ctx, esI, snapshotStatus)
if err != nil {
Expand Down
63 changes: 31 additions & 32 deletions backend/api/es_controller.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
package api

import (
"ev-tools/backend/model"
"ev-tools/backend/response"
"ev-tools/backend/services/cat_service"
"ev-tools/backend/services/es_service"
"ev-plugin/backend/dto"
"ev-plugin/backend/dto/common"
"ev-plugin/backend/model"
"ev-plugin/backend/response"
"ev-plugin/backend/services/cat_service"
"ev-plugin/backend/services/es_service"
"ev-plugin/backend/vo"
"fmt"
"github.com/1340691923/eve-plugin-sdk-go/ev_api"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/dto"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/dto/common"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/vo"
"github.com/1340691923/eve-plugin-sdk-go/util"
"github.com/spf13/cast"
"net/http"
"strconv"

dto2 "github.com/1340691923/eve-plugin-sdk-go/ev_api/dto"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/proto"
"github.com/1340691923/eve-plugin-sdk-go/util"
"github.com/cch123/elasticsql"
"github.com/gin-gonic/gin"
"github.com/pkg/errors"
"net/http"
"strconv"
)

// Es 基本操作
Expand Down Expand Up @@ -50,7 +49,7 @@ func (this *EsController) CatAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(esCat.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esCat.EsConnect, util.GetEvUserID(ctx))

catSvr := this.catService

Expand Down Expand Up @@ -122,7 +121,7 @@ func (this *EsController) SqlToDslAction(ctx *gin.Context) {
// @Accept application/json
// @Produce application/json
// @Param X-Token header string false "用户令牌"
// @Param object body dto.EsConnectID false "查询参数"
// @Param object body common.EsConnectID false "查询参数"
// @Success 0 {object} response.ResponseData
// @Router /api/es/RecoverCanWrite [post]
func (this *EsController) RecoverCanWrite(ctx *gin.Context) {
Expand All @@ -133,7 +132,7 @@ func (this *EsController) RecoverCanWrite(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(esConnectID.EsConnectID, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esConnectID.EsConnectID, util.GetEvUserID(ctx))

err = this.esService.RecoverCanWrite(ctx, esI)

Expand All @@ -154,9 +153,9 @@ func (this *EsController) RunDslPOSTAction(ctx *gin.Context) {
this.Error(ctx, err)
return
}
esI := ev_api.NewEvWrapApi(esRest.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esRest.EsConnect, util.GetEvUserID(ctx))

res, err := esI.EsRunDsl(ctx, &dto.PluginRunDsl2{
res, err := esI.EsRunDsl(ctx, &dto2.PluginRunDsl2{
HttpMethod: http.MethodPost,
Path: esRest.Path,
Dsl: esRest.Body,
Expand All @@ -175,7 +174,7 @@ func (this *EsController) RunDslPOSTAction(ctx *gin.Context) {
return
}
gmDslHistoryModel := model.GmDslHistoryModel{
Uid: cast.ToInt(ctx.GetHeader(util.EvUserID)),
Uid: util.GetEvUserID(ctx),
Method: http.MethodPost,
Path: esRest.Path,
Body: esRest.Body,
Expand All @@ -198,9 +197,9 @@ func (this *EsController) RunDslGETAction(ctx *gin.Context) {
this.Error(ctx, err)
return
}
esI := ev_api.NewEvWrapApi(esRest.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esRest.EsConnect, util.GetEvUserID(ctx))

res, err := esI.EsRunDsl(ctx, &dto.PluginRunDsl2{
res, err := esI.EsRunDsl(ctx, &dto2.PluginRunDsl2{
HttpMethod: http.MethodGet,
Path: esRest.Path,
Dsl: esRest.Body,
Expand All @@ -220,7 +219,7 @@ func (this *EsController) RunDslGETAction(ctx *gin.Context) {
}

gmDslHistoryModel := model.GmDslHistoryModel{
Uid: cast.ToInt(ctx.GetHeader(util.EvUserID)),
Uid: util.GetEvUserID(ctx),
Method: http.MethodGet,
Path: esRest.Path,
Body: esRest.Body,
Expand All @@ -243,9 +242,9 @@ func (this *EsController) RunDslDELETEAction(ctx *gin.Context) {
this.Error(ctx, err)
return
}
esI := ev_api.NewEvWrapApi(esRest.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esRest.EsConnect, util.GetEvUserID(ctx))

res, err := esI.EsRunDsl(ctx, &dto.PluginRunDsl2{
res, err := esI.EsRunDsl(ctx, &dto2.PluginRunDsl2{
HttpMethod: http.MethodDelete,
Path: esRest.Path,
Dsl: esRest.Body,
Expand All @@ -264,7 +263,7 @@ func (this *EsController) RunDslDELETEAction(ctx *gin.Context) {
}

gmDslHistoryModel := model.GmDslHistoryModel{
Uid: cast.ToInt(ctx.GetHeader(util.EvUserID)),
Uid: util.GetEvUserID(ctx),
Method: http.MethodDelete,
Path: esRest.Path,
Body: esRest.Body,
Expand All @@ -287,9 +286,9 @@ func (this *EsController) RunDslPUTAction(ctx *gin.Context) {
this.Error(ctx, err)
return
}
esI := ev_api.NewEvWrapApi(esRest.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esRest.EsConnect, util.GetEvUserID(ctx))

res, err := esI.EsRunDsl(ctx, &dto.PluginRunDsl2{
res, err := esI.EsRunDsl(ctx, &dto2.PluginRunDsl2{
HttpMethod: http.MethodPut,
Path: esRest.Path,
Dsl: esRest.Body,
Expand All @@ -307,7 +306,7 @@ func (this *EsController) RunDslPUTAction(ctx *gin.Context) {
return
}
gmDslHistoryModel := model.GmDslHistoryModel{
Uid: cast.ToInt(ctx.GetHeader(util.EvUserID)),
Uid: util.GetEvUserID(ctx),
Method: http.MethodPut,
Path: esRest.Path,
Body: esRest.Body,
Expand All @@ -331,9 +330,9 @@ func (this *EsController) RunDslHEADAction(ctx *gin.Context) {
this.Error(ctx, err)
return
}
esI := ev_api.NewEvWrapApi(esRest.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esRest.EsConnect, util.GetEvUserID(ctx))

res, err := esI.EsRunDsl(ctx, &dto.PluginRunDsl2{
res, err := esI.EsRunDsl(ctx, &dto2.PluginRunDsl2{
HttpMethod: http.MethodHead,
Path: esRest.Path,
Dsl: esRest.Body,
Expand All @@ -351,7 +350,7 @@ func (this *EsController) RunDslHEADAction(ctx *gin.Context) {
return
}
gmDslHistoryModel := model.GmDslHistoryModel{
Uid: cast.ToInt(ctx.GetHeader(util.EvUserID)),
Uid: util.GetEvUserID(ctx),
Method: http.MethodHead,
Path: esRest.Path,
Body: esRest.Body,
Expand All @@ -374,7 +373,7 @@ func (this *EsController) DslHistoryAction(ctx *gin.Context) {
this.Error(ctx, errors.WithStack(err))
return
}
gmDslHistoryModel.Uid = cast.ToInt(ctx.GetHeader(util.EvUserID))
gmDslHistoryModel.Uid = util.GetEvUserID(ctx)

list, err := gmDslHistoryModel.List()

Expand All @@ -395,7 +394,7 @@ func (this *EsController) DslHistoryAction(ctx *gin.Context) {
func (this *EsController) CleanDslHistoryAction(ctx *gin.Context) {

gmDslHistoryModel := model.GmDslHistoryModel{}
gmDslHistoryModel.Uid = cast.ToInt(ctx.GetHeader(util.EvUserID))
gmDslHistoryModel.Uid = util.GetEvUserID(ctx)
err := gmDslHistoryModel.Clean()
if err != nil {
this.Error(ctx, err)
Expand Down
12 changes: 5 additions & 7 deletions backend/api/es_crud_controller.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package api

import (
"ev-tools/backend/response"
"ev-tools/backend/services/navicat_service"
"ev-plugin/backend/dto"
"ev-plugin/backend/response"
"ev-plugin/backend/services/navicat_service"
"github.com/1340691923/eve-plugin-sdk-go/ev_api"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/dto"
"github.com/1340691923/eve-plugin-sdk-go/util"
"github.com/spf13/cast"

"github.com/gin-gonic/gin"
)

Expand Down Expand Up @@ -38,7 +36,7 @@ func (this *EsCrudController) GetList(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(crudFilter.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(crudFilter.EsConnect, util.GetEvUserID(ctx))
if err != nil {
this.Error(ctx, err)
return
Expand Down Expand Up @@ -99,7 +97,7 @@ func (this *EsCrudController) Download(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(crudFilter.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(crudFilter.EsConnect, util.GetEvUserID(ctx))
if err != nil {
this.Error(ctx, err)
return
Expand Down
13 changes: 6 additions & 7 deletions backend/api/es_doc_controller.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package api

import (
"ev-tools/backend/response"
"ev-tools/backend/services/es_doc_service"
"ev-plugin/backend/dto"
"ev-plugin/backend/response"
"ev-plugin/backend/services/es_doc_service"
"github.com/1340691923/eve-plugin-sdk-go/ev_api"
"github.com/1340691923/eve-plugin-sdk-go/ev_api/dto"
"github.com/1340691923/eve-plugin-sdk-go/util"
"github.com/gin-gonic/gin"
"github.com/spf13/cast"
)

// ES 文档控制器
Expand Down Expand Up @@ -36,7 +35,7 @@ func (this *EsDocController) DeleteRowByIDAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(esDocDeleteRowByID.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esDocDeleteRowByID.EsConnect, util.GetEvUserID(ctx))

err = this.esDocService.DeleteRowByIDAction(ctx, esI, esDocDeleteRowByID)
if err != nil {
Expand All @@ -63,7 +62,7 @@ func (this *EsDocController) UpdateByIDAction(ctx *gin.Context) {
return
}

esI := ev_api.NewEvWrapApi(esDocUpdateByID.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esDocUpdateByID.EsConnect, util.GetEvUserID(ctx))

err = this.esDocService.EsDocUpdateByID(ctx, esI, esDocUpdateByID)
if err != nil {
Expand All @@ -86,7 +85,7 @@ func (this *EsDocController) InsertAction(ctx *gin.Context) {
esDocUpdateByID := new(dto.EsDocUpdateByID)
err := ctx.Bind(esDocUpdateByID)

esI := ev_api.NewEvWrapApi(esDocUpdateByID.EsConnect, cast.ToInt(ctx.GetHeader(util.EvUserID)))
esI := ev_api.NewEvWrapApi(esDocUpdateByID.EsConnect, util.GetEvUserID(ctx))
if err != nil {
this.Error(ctx, err)
return
Expand Down
Loading

0 comments on commit cc02fcd

Please sign in to comment.