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.

331 lines
12 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 DatasourceOpenAPI
import (
"dsSupport/MyModel/DataSource/DatasourceService"
"dsSupport/MyModel/MySwagger"
"dsSupport/models"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
)
// 获取数据源列表 godoc
// @Summary 获取数据源列表
// @Description json:"`system_id`" xorm:"not null comment('数据提供系统编码') index VARCHAR(36)" example:"1C0F6832-65C6-4888-BDDE-A3373B11499D"
// @Description json:"datasource_name" xorm:"not null comment('数据源名称') VARCHAR(100)" example:"组织机构信息"
// @Description json:"datasource_code" xorm:"not null comment('数据源编码') VARCHAR(8)" example:"org_tree"
// @Description json:"datasource_detail" xorm:"default 'NULL' comment('数据源说明') VARCHAR(500)" example:"教育主管单位、教辅单位、各级各类学校机构信息"
// @Description json:"set_flag" xorm:"not null default 1 comment('可修改【1-1否】') INT(11)" example:"1"
// @Description json:"collect_flag" xorm:"not null default 1 comment('可汇集【1-1否】') INT(11)" example:"1"
// @Description json:"provide_type" xorm:"not null comment('提供数据范围【1本机构2本机构以及下属机构-1不限制】') INT(11)" example:"2"
// @Description json:"provide_orgid" xorm:"not null comment('提供数据机构ID【-1不限制】') index VARCHAR(36)" example:"-1"
// @Description json:"datastore_type" xorm:"not null comment('数据存储类型【1DB2ES3Kafka】') INT(11)" example:"2"
// @Description json:"dic_id, omitempty" xorm:"default 'NULL' comment('数据字典ID') index VARCHAR(36)" example:"1C0F6832-65C6-4888-BDDE-A3373B11499D"
// @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 datasource
// @ID readDatasource
// @Accept json
// @Produce json
// @Param input body MySwagger.DatasourceSwag true "数据源"
// @Success 200 {object} MySwagger.Result
// @Failure 400 {object} MySwagger.Result
// @Router /support/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
}
fmt.Println("raw = ", raw)
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 `*`json:"`system_id`" xorm:"not null comment('数据提供系统编码') index VARCHAR(36)" example:"1C0F6832-65C6-4888-BDDE-A3373B11499D"
// @Description `*`json:"datasource_name" xorm:"not null comment('数据源名称') VARCHAR(100)" example:"组织机构信息"
// @Description `*`json:"datasource_code" xorm:"not null comment('数据源编码') VARCHAR(8)" example:"org_tree"
// @Description json:"datasource_detail" xorm:"default 'NULL' comment('数据源说明') VARCHAR(500)" example:"教育主管单位、教辅单位、各级各类学校机构信息"
// @Description json:"set_flag" xorm:"not null default 1 comment('可修改【1-1否】') INT(11)" example:"1"
// @Description json:"collect_flag" xorm:"not null default 1 comment('可汇集【1-1否】') INT(11)" example:"1"
// @Description `*`json:"provide_type" xorm:"not null comment('提供数据范围【1本机构2本机构以及下属机构-1不限制】') INT(11)" example:"2"
// @Description `*`json:"provide_orgid" xorm:"not null comment('提供数据机构ID【-1不限制】') index VARCHAR(36)" example:"-1"
// @Description `*`json:"datastore_type" xorm:"not null comment('数据存储类型【1DB2ES3Kafka】') INT(11)" example:"2"
// @Description json:"dic_id, omitempty" xorm:"default 'NULL' comment('数据字典ID') index VARCHAR(36)" example:"1C0F6832-65C6-4888-BDDE-A3373B11499D"
// @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 datasource
// @ID createDatasource
// @Accept json
// @Produce json
// @Param input body MySwagger.DatasourceSwag true "数据源"
// @Success 200 {object} MySwagger.Result
// @Failure 400 {object} MySwagger.Result
// @Router /support/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
}
if raw.DatasourceCode == "" {
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false, Message: "数据源编码必填"})
return
}
success, message, _ := DatasourceService.CreateDatasource(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:"`system_id`" xorm:"not null comment('数据提供系统编码') index VARCHAR(36)" example:"1C0F6832-65C6-4888-BDDE-A3373B11499D"
// @Description json:"datasource_name" xorm:"not null comment('数据源名称') VARCHAR(100)" example:"组织机构信息"
// @Description json:"datasource_code" xorm:"not null comment('数据源编码') VARCHAR(8)" example:"org_tree"
// @Description json:"datasource_detail" xorm:"default 'NULL' comment('数据源说明') VARCHAR(500)" example:"教育主管单位、教辅单位、各级各类学校机构信息"
// @Description json:"set_flag" xorm:"not null default 1 comment('可修改【1-1否】') INT(11)" example:"1"`
// @Description json:"collect_flag" xorm:"not null default 1 comment('可汇集【1-1否】') INT(11)" example:"1"
// @Description json:"provide_type" xorm:"not null comment('提供数据范围【1本机构2本机构以及下属机构-1不限制】') INT(11)" example:"2"
// @Description json:"provide_orgid" xorm:"not null comment('提供数据机构ID【-1不限制】') index VARCHAR(36)" example:"-1"
// @Description json:"datastore_type" xorm:"not null comment('数据存储类型【1DB2ES3Kafka】') INT(11)" example:"2"
// @Description json:"dic_id, omitempty" xorm:"default 'NULL' comment('数据字典ID') index VARCHAR(36)" example:"1C0F6832-65C6-4888-BDDE-A3373B11499D"
// @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 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 /support/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.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 datasource
// @ID deleteDatasource
// @Accept json
// @Produce json
// @Param id path string true "数据源ID"
// @Success 200 {object} MySwagger.Result
// @Failure 400 {object} MySwagger.Result
// @Router /support/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.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:"datasource_code" xorm:"not null comment('数据源编码') VARCHAR(8)" example:"org_tree"
// @Description json:"`orgids`" xorm:"not null comment('提供数据范围【1本机构2本机构以及下属机构-1不限制】') VARCHAR(36)" example:"[F38BD0DB-0142-4356-8F2B-623813FC2578,F38BD0DB-0142-4356-8F2B-623813FC2578]"
// @Description json:"begin_time" example:"2020-06-22 17:26:53"`
// @Description json:"conditions" example:""
// @Description json:"sort" example:""
// @Description json:"data_id" example:"CfBQnRJPyXMEI5nqLT0"
// @Description json:"page" example:"1"
// @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 /support/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, count, esdata := DatasourceService.ReadESDoc(datasourceCode, orgIDs, page, begin, conditions, sort)
if success {
c.JSON(http.StatusOK, MySwagger.Result2{
Success: true,
Fail: false,
Message: message,
Data: esdata,
Total: count,
})
return
} else {
c.JSON(http.StatusOK, MySwagger.Result2{
Success: false,
Fail: true,
Message: message,
})
return
}
return
}
// 获取es数据 godoc
// @Summary 获取es数据
// @Description `*`json:"datasource_code" xorm:"not null comment('数据源编码') VARCHAR(8)" example:"org_tree"
// @Description json:"`orgids`" xorm:"not null comment('提供数据范围【1本机构2本机构以及下属机构-1不限制】') VARCHAR(36)" example:"[F38BD0DB-0142-4356-8F2B-623813FC2578,F38BD0DB-0142-4356-8F2B-623813FC2578]"
// @Description json:"begin_time" example:"2020-06-22 17:26:53"`
// @Description json:"conditions" example:""
// @Description json:"sort" example:""
// @Description `*`json:"data_id" example:"CfBQnRJPyXMEI5nqLT0"
// @Tags datasource
// @ID getESDoc
// @Accept json
// @Produce json
// @Param input body MySwagger.DatasourceESSwag true "es数据"
// @Success 200 {object} MySwagger.Result
// @Failure 400 {object} MySwagger.Result
// @Router /support/datasource/GetESDoc [post]
func GetESDoc(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
dataID := raw.DataId
success, message, esdata := DatasourceService.GetESDoc(datasourceCode, dataID)
if success {
c.JSON(http.StatusOK, MySwagger.ResultOne{
Success: true,
Fail: false,
Message: message,
Data: esdata,
})
return
} else {
c.JSON(http.StatusOK, MySwagger.ResultOne{
Success: false,
Fail: true,
Message: message,
})
return
}
return
}