You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
234 lines
5.2 KiB
234 lines
5.2 KiB
package DatasourceOpenAPI
|
|
|
|
import (
|
|
"dsDataex/GenXorm/models"
|
|
"dsDataex/MyModel/DataSource/DatasourceService"
|
|
"dsDataex/MyModel/MySwagger"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
// 获取数据源列表 godoc
|
|
// @Summary 获取数据源列表
|
|
// @Description 获取数据源列表
|
|
// @Tags datasource
|
|
// @ID readDatasource
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param input body MySwagger.DatasourceSwag true "数据源"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/datasource/ReadDatasource [post]
|
|
func ReadDatasource(c *gin.Context) {
|
|
var raw MySwagger.DatasourceSwag
|
|
|
|
//input.AuthToken = c.Request.Header["Authorization"][0]
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
success, message, count, data, _ := DatasourceService.GetDatasourceResults(raw)
|
|
|
|
if success {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: true,
|
|
Fail: false,
|
|
Message: message,
|
|
Total: count,
|
|
Data: data,
|
|
})
|
|
|
|
return
|
|
} else {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: false,
|
|
Fail: true,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 创建数据源 godoc
|
|
// @Summary 创建数据源
|
|
// @Description 创建数据源
|
|
// @Tags datasource
|
|
// @ID createDatasource
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param input body MySwagger.DatasourceSwag true "数据源"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/datasource/CreateDatasource [post]
|
|
func CreateDatasource(c *gin.Context) {
|
|
var raw models.TDataexDatasource
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
success, message, _ := DatasourceService.CreateDatasource(raw)
|
|
if success {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: true,
|
|
Fail: false,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
} else {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: false,
|
|
Fail: true,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 修改数据源 godoc
|
|
// @Summary 修改数据源
|
|
// @Description 修改数据源
|
|
// @Tags datasource
|
|
// @ID updateDatasource
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "数据源ID"
|
|
// @Param input body MySwagger.DatasourceSwag true "数据源"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/datasource/UpdateDatasource/{id} [post]
|
|
func UpdateDatasource(c *gin.Context) {
|
|
var raw models.TDataexDatasource
|
|
|
|
ID := c.Param("id")
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
fmt.Println("err=", err)
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Fail: true, Message: "接入系统数据JSON格式错误"})
|
|
return
|
|
}
|
|
|
|
success, message, _ := DatasourceService.UpdateDatasource(ID, raw)
|
|
|
|
if success {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: true,
|
|
Fail: false,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
} else {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: false,
|
|
Fail: true,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 删除数据源 godoc
|
|
// @Summary 删除数据源
|
|
// @Description 删除数据源
|
|
// @Tags datasource
|
|
// @ID deleteDatasource
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "数据源ID"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/datasource/DeleteDatasource/{id} [post]
|
|
func DeleteDatasource(c *gin.Context) {
|
|
ID := c.Param("id")
|
|
|
|
success, message, _ := DatasourceService.RemoveDatasource(ID)
|
|
|
|
if success {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: true,
|
|
Fail: false,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
} else {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: false,
|
|
Fail: true,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|
|
|
|
// 获取es数据列表 godoc
|
|
// @Summary 获取es数据列表
|
|
// @Description 获取es数据列表
|
|
// @Tags datasource
|
|
// @ID readESDoc
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param input body MySwagger.DatasourceESSwag true "es数据"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/datasource/ReadESDoc [post]
|
|
func ReadESDoc(c *gin.Context) {
|
|
var raw MySwagger.DatasourceESSwag
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
datasourceCode := raw.DatasourceCode
|
|
orgIDs := raw.OrgIDs
|
|
page := raw.Page
|
|
begin := raw.BeginTime
|
|
conditions := raw.Conditions
|
|
sort := raw.Sort
|
|
|
|
success, message, esdata := DatasourceService.ReadESDoc(datasourceCode, orgIDs, page, begin, conditions, sort)
|
|
//fmt.Println("esdata=", esdata)
|
|
if success {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: true,
|
|
Fail: false,
|
|
Message: message,
|
|
Data: esdata,
|
|
})
|
|
|
|
return
|
|
} else {
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
Success: false,
|
|
Fail: true,
|
|
Message: message,
|
|
})
|
|
|
|
return
|
|
}
|
|
|
|
return
|
|
}
|