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.
224 lines
4.8 KiB
224 lines
4.8 KiB
package MetadataOpenAPI
|
|
|
|
import (
|
|
"dsDataex/GenXorm/models"
|
|
"dsDataex/MyModel/MetaData/MetadataService"
|
|
"dsDataex/MyModel/MySwagger"
|
|
"fmt"
|
|
"github.com/gin-gonic/gin"
|
|
"net/http"
|
|
)
|
|
|
|
// 获取元数据列表 godoc
|
|
// @Summary 获取元数据列表
|
|
// @Description 获取元数据列表
|
|
// @Tags metadata
|
|
// @ID readMetadata
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param input body MySwagger.MetadataSwag true "元数据"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/metadata/ReadMetadata [post]
|
|
func ReadMetadata(c *gin.Context) {
|
|
var raw MySwagger.MetadataSwag
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
fmt.Println("json.page=", raw.Page)
|
|
success, message, count, data, _ := MetadataService.GetMetadataResults(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 metadata
|
|
// @ID createMetadata
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param input body MySwagger.MetadataSwag true "元数据"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/metadata/CreateMetadata [post]
|
|
func CreateMetadata(c *gin.Context) {
|
|
var raw models.TDataexMetadata
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
success, message, _ := MetadataService.CreateMetadata(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 metadata
|
|
// @ID updateMetadata
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "元数据ID"
|
|
// @Param input body MySwagger.MetadataSwag true "元数据"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/metadata/UpdateMetadata/{id} [post]
|
|
func UpdateMetadata(c *gin.Context) {
|
|
var raw models.TDataexMetadata
|
|
|
|
ID := c.Param("id")
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Fail: true, Message: "接入系统数据JSON格式错误"})
|
|
return
|
|
}
|
|
|
|
success, message, _ := MetadataService.UpdateMetadata(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 metadata
|
|
// @ID deleteMetadata
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param id path string true "元数据ID"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/metadata/DeleteMetadata/{id} [post]
|
|
func DeleteMetadata(c *gin.Context) {
|
|
ID := c.Param("id")
|
|
|
|
success, message, _ := MetadataService.RemoveMetadata(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 metadata
|
|
// @ID createMetadataES
|
|
// @Accept json
|
|
// @Produce json
|
|
// @Param input body MySwagger.MetadataESSwag true "ES元数据"
|
|
// @Success 200 {object} MySwagger.Result
|
|
// @Failure 400 {object} MySwagger.Result
|
|
// @Router /v1/openapi/metadata/CreateMetadataES [post]
|
|
func CreateMetadataES(c *gin.Context) {
|
|
var raw MySwagger.MetadataESSwag
|
|
|
|
if err := c.ShouldBindJSON(&raw); err != nil {
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "接入系统数据JSON格式错误"})
|
|
fmt.Println(err)
|
|
return
|
|
}
|
|
|
|
indexName := raw.IndexName
|
|
|
|
success, message, _ := MetadataService.CreateMetadataES(indexName)
|
|
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
|
|
}
|