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.

263 lines
10 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package MetadataOpenAPI
import (
"dsSupport/MyModel/MetaData/MetadataService"
"dsSupport/MyModel/MySwagger"
"dsSupport/models"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
// 获取元数据列表 godoc
// @Summary 获取元数据列表
// @Description json:"`datasource_id`" xorm:"default ''NULL'' comment('数据源编码') index VARCHAR(36)" example:"0383FF67-CCBA-4256-891E-BAFD487547FA"
// @Description json:"item_name" xorm:"not null comment('数据项名称【英文】') VARCHAR(50)" example:"org_name"
// @Description json:"dic_id" xorm:"default ''NULL'' comment('数据字典ID') index VARCHAR(36)" example:"F38BD0DB-0142-4356-8F2B-623813FC2578"
// @Description json:"item_type" xorm:"default ''NULL'' comment('数据项类型【1整数、2浮点、3字符、4布尔、5日期、6时间、7日期+时间】') VARCHAR(50)" example:"string"
// @Description json:"item_length" xorm:"default NULL comment('数据最大长度【UTF-8 字符长度】') INT(11)" example:"36"
// @Description json:"item_pattern" xorm:"default 'NULL' comment('数据项模式') VARCHAR(255)" example:""
// @Description json:"item_info" xorm:"not null comment('数据项说明') VARCHAR(50)" example:"我是数据项说明"
// @Description json:"check_name" xorm:"not null default -1 comment('是否检测名称【1-1否】') INT(11)" example:"1"
// @Description json:"check_dic" xorm:"not null default -1 comment('是否检测字典') INT(11)" example:"1"
// @Description json:"check_type" xorm:"not null default -1 comment('是否检测类型') INT(11)" example:"1"
// @Description json:"check_pattern" xorm:"not null default -1 comment('是否检测模式') INT(11)" example:"1"
// @Description json:"check_exist" xorm:"not null default -1 comment('是否检测必填') INT(11)" example:"1"
// @Description json:"delete_flag" xorm:"not null default -1 comment('删除标志【默认-11删除-1正常】') INT(11)" example:"1"
// @Description json:"enable_flag" xorm:"not null default 1 comment('启用标志【默认11启用-1禁用】') INT(11)" example:"1"
// @Description json:"page" example:"1"
// @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 /support/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
}
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 `*`json:"`datasource_id`" xorm:"default ''NULL'' comment('数据源编码') index VARCHAR(36)" example:"0383FF67-CCBA-4256-891E-BAFD487547FA"
// @Description `*`json:"item_name" xorm:"not null comment('数据项名称【英文】') VARCHAR(50)" example:"org_name"
// @Description json:"dic_id" xorm:"default ''NULL'' comment('数据字典ID') index VARCHAR(36)" example:"F38BD0DB-0142-4356-8F2B-623813FC2578"
// @Description `*`json:"item_type" xorm:"default ''NULL'' comment('数据项类型【1整数、2浮点、3字符、4布尔、5日期、6时间、7日期+时间】') VARCHAR(50)" example:"string"
// @Description `*`json:"item_length" xorm:"default NULL comment('数据最大长度【UTF-8 字符长度】') INT(11)" example:"36"
// @Description `*`json:"item_pattern" xorm:"default 'NULL' comment('数据项模式') VARCHAR(255)" example:""
// @Description `*`json:"item_info" xorm:"not null comment('数据项说明') VARCHAR(50)" example:"我是数据项说明"
// @Description `*`json:"check_name" xorm:"not null default -1 comment('是否检测名称【1-1否】') INT(11)" example:"1"
// @Description `*`json:"check_dic" xorm:"not null default -1 comment('是否检测字典') INT(11)" example:"1"
// @Description `*`json:"check_type" xorm:"not null default -1 comment('是否检测类型') INT(11)" example:"1"
// @Description `*`json:"check_pattern" xorm:"not null default -1 comment('是否检测模式') INT(11)" example:"1"
// @Description `*`json:"check_exist" xorm:"not null default -1 comment('是否检测必填') INT(11)" example:"1"
// @Description json:"delete_flag" xorm:"not null default -1 comment('删除标志【默认-11删除-1正常】') INT(11)" example:"1"
// @Description json:"enable_flag" xorm:"not null default 1 comment('启用标志【默认11启用-1禁用】') INT(11)" example:"1"
// @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 /support/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.ResultOne{
Success: true,
Fail: false,
Message: message,
})
return
} else {
c.JSON(http.StatusOK, MySwagger.ResultOne{
Success: false,
Fail: true,
Message: message,
})
return
}
return
}
// 修改元数据 godoc
// @Summary 修改元数据
// @Description json:"`datasource_id`" xorm:"default ''NULL'' comment('数据源编码') index VARCHAR(36)" example:"0383FF67-CCBA-4256-891E-BAFD487547FA"
// @Description json:"item_name" xorm:"not null comment('数据项名称【英文】') VARCHAR(50)" example:"org_name"
// @Description json:"dic_id" xorm:"default ''NULL'' comment('数据字典ID') index VARCHAR(36)" example:"F38BD0DB-0142-4356-8F2B-623813FC2578"
// @Description json:"item_type" xorm:"default ''NULL'' comment('数据项类型【1整数、2浮点、3字符、4布尔、5日期、6时间、7日期+时间】') VARCHAR(50)" example:"string"
// @Description json:"item_length" xorm:"default NULL comment('数据最大长度【UTF-8 字符长度】') INT(11)" example:"36"
// @Description json:"item_pattern" xorm:"default 'NULL' comment('数据项模式') VARCHAR(255)" example:""
// @Description json:"item_info" xorm:"not null comment('数据项说明') VARCHAR(50)" example:"我是数据项说明"
// @Description json:"check_name" xorm:"not null default -1 comment('是否检测名称【1-1否】') INT(11)" example:"1"
// @Description json:"check_dic" xorm:"not null default -1 comment('是否检测字典') INT(11)" example:"1"
// @Description json:"check_type" xorm:"not null default -1 comment('是否检测类型') INT(11)" example:"1"
// @Description json:"check_pattern" xorm:"not null default -1 comment('是否检测模式') INT(11)" example:"1"
// @Description json:"check_exist" xorm:"not null default -1 comment('是否检测必填') INT(11)" example:"1"
// @Description json:"delete_flag" xorm:"not null default -1 comment('删除标志【默认-11删除-1正常】') INT(11)" example:"1"
// @Description json:"enable_flag" xorm:"not null default 1 comment('启用标志【默认11启用-1禁用】') INT(11)" example:"1"
// @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 /support/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.ResultOne{
Success: true,
Fail: false,
Message: message,
})
return
} else {
c.JSON(http.StatusOK, MySwagger.ResultOne{
Success: false,
Fail: true,
Message: message,
})
return
}
return
}
// 删除元数据 godoc
// @Summary 删除元数据
// @Description `*`json:"id" xorm:"not null pk comment('ID') VARCHAR(36)"
// @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 /support/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.ResultOne{
Success: true,
Fail: false,
Message: message,
})
return
} else {
c.JSON(http.StatusOK, MySwagger.ResultOne{
Success: false,
Fail: true,
Message: message,
})
return
}
return
}
// 创建ES元数据 godoc
// @Summary 创建ES元数据
// @Description `*`json:"index_name" xorm:"not null comment('ES Index Name') VARCHAR(50)" example:"org_tree"
// @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 /support/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格式错误"})
return
}
indexName := raw.IndexName
success, message, _ := MetadataService.CreateMetadataES(indexName)
if success {
c.JSON(http.StatusOK, MySwagger.ResultOne{
Success: true,
Fail: false,
Message: message,
})
return
} else {
c.JSON(http.StatusOK, MySwagger.ResultOne{
Success: false,
Fail: true,
Message: message,
})
return
}
return
}