|
|
package DataexOpenapi
|
|
|
|
|
|
import (
|
|
|
"dsDataex/MyService/Auth/AuthService"
|
|
|
"dsDataex/MyService/DataEX/DataexService"
|
|
|
"dsDataex/MyService/MySwagger"
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
// @Summary 修改数据
|
|
|
// @Description 【数据交换平台】修改数据服务接口,支持批量修改,一个批次少于100条数据。
|
|
|
// @Tags dataex
|
|
|
// @Accept json
|
|
|
// @Produce json
|
|
|
// @Param input body MySwagger.DataIn true "修改数据"
|
|
|
// @Success 200 {object} MySwagger.DataInResult
|
|
|
// @Failure 400 {object} MySwagger.Result
|
|
|
// @Router /v1/dataex/DataexSet [post]
|
|
|
func DataexSet(c *gin.Context) {
|
|
|
var input MySwagger.DataIn
|
|
|
|
|
|
if err := c.ShouldBindJSON(&input); err != nil {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统JSON数据格式不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.SystemID == "" || input.AuthToken == "" {
|
|
|
fmt.Println("接入系统票据不能为空")
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统票据不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if len(input.Datas)==0 {
|
|
|
fmt.Println("接入系统JSON数据Datas不能为空")
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统JSON数据Datas不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag,_,systemID:=AuthService.CheckToken(input.SystemID,input.AuthToken)
|
|
|
|
|
|
if flag==false {
|
|
|
fmt.Println("接入系统票据不正确")
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统票据不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag2,_,dataSource := DataexService.CheckDatasourceSet(systemID,input.DataSource)
|
|
|
|
|
|
if flag2==false {
|
|
|
fmt.Println("接入系统访问的数据源类型不正确")
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统访问的数据源类型不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//success,result,successIDs,failResults:=DataexService.DataexSet(input.SystemID,input.Datas,dataSource)
|
|
|
success,result,successIDs,failResults:=DataexService.DataexSetBatch(input.SystemID,input.Datas,dataSource)
|
|
|
|
|
|
if success{
|
|
|
fmt.Println("DataexSet服务调用成功")
|
|
|
c.JSON(http.StatusOK, MySwagger.DataInResult{
|
|
|
Success: true,
|
|
|
Message: "DataexSet服务调用成功",
|
|
|
SuccessIDs: successIDs,
|
|
|
FailResults: failResults,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}else {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataInResult{
|
|
|
Success: false,
|
|
|
Message: result,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// @Summary 汇集数据
|
|
|
// @Description 【数据交换平台】用户行为数据汇集服务接口,支持用户事件批量入库,一个批次少于100个事件数据。
|
|
|
// @Tags dataex
|
|
|
// @Accept json
|
|
|
// @Produce json
|
|
|
// @Param input body MySwagger.DataCollect true "汇集数据"
|
|
|
// @Success 200 {object} MySwagger.Result
|
|
|
// @Failure 400 {object} MySwagger.Result
|
|
|
// @Router /v1/dataex/DataexCollect [post]
|
|
|
func DataexCollect(c *gin.Context) {
|
|
|
|
|
|
var input MySwagger.DataCollect
|
|
|
|
|
|
if err := c.ShouldBindJSON(&input); err != nil {
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{Success: false,Message: "接入系统数据JSON格式错误"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.AccessToken == "" {
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{Success: false,Message: "接入系统票据验证失败"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if len(input.EventDatas)==0 {
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{Success: false,Message: "接入系统JSON数据EventDatas不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var temp=strings.Split(input.AccessToken,"##")
|
|
|
|
|
|
if len(temp)!=3{
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{Success: false,Message: "接入系统票据格式不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag,_,systemID:=AuthService.CheckAccessToken(temp[0],temp[1],temp[2])
|
|
|
|
|
|
if flag==false {
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{Success: false,Message: "接入系统票据不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag2,_,dataSource := DataexService.CheckDatasourceSet(systemID,input.DataSource)
|
|
|
|
|
|
if flag2==false {
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{Success: false,Message: "接入系统访问的数据源类型不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var ip = c.ClientIP()
|
|
|
|
|
|
success,message:=DataexService.DataexCollect(temp[0],input.UserDatas,input.EventDatas,dataSource,ip)
|
|
|
|
|
|
if success{
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
|
Success: true,
|
|
|
Message: "DataexCollect服务调用成功",
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}else {
|
|
|
c.JSON(http.StatusOK, MySwagger.Result{
|
|
|
Success: false,
|
|
|
Message: message,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
return
|
|
|
}
|
|
|
|
|
|
// @Summary 获取数据
|
|
|
// @Description 【数据交换平台】获取数据服务接口。
|
|
|
// @Tags dataex
|
|
|
// @Accept json
|
|
|
// @Produce json
|
|
|
// @Param input body MySwagger.DataGet true "获取数据"
|
|
|
// @Success 200 {object} MySwagger.DataGetResult
|
|
|
// @Failure 400 {object} MySwagger.Result
|
|
|
// @Router /v1/dataex/DataexGet [post]
|
|
|
func DataexGet(c *gin.Context) {
|
|
|
|
|
|
var input MySwagger.DataGet
|
|
|
|
|
|
if err := c.ShouldBindJSON(&input); err != nil {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统数据JSON格式错误"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.SystemID == "" || input.AuthToken == "" {
|
|
|
c.JSON(http.StatusUnauthorized, MySwagger.Result{Success: false,Message: "接入系统票据不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.DataID=="" ||input.OrgID=="" || input.DataSource=="" {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统JSON数据字段不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag,_,systemID:=AuthService.CheckToken(input.SystemID,input.AuthToken)
|
|
|
|
|
|
if flag==false {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统票据不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag2,_,dataSource2 := DataexService.CheckDatasourceSet(systemID,input.DataSource)
|
|
|
flag3,_,dataSource3 := DataexService.CheckDatasourceGet(systemID,input.DataSource)
|
|
|
|
|
|
if flag2==false && flag3==false {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统访问的数据源类型不正确"})
|
|
|
return
|
|
|
}
|
|
|
var getType int
|
|
|
var getOrgID string
|
|
|
|
|
|
if flag2{
|
|
|
getType =dataSource2.ProvideType
|
|
|
getOrgID =dataSource2.ProvideOrgid
|
|
|
}
|
|
|
if flag3{
|
|
|
getType=dataSource3.ConsumeType
|
|
|
getOrgID=dataSource3.ConsumeOrgid
|
|
|
|
|
|
}
|
|
|
|
|
|
flag4,result,data:=DataexService.DataexGet(input.DataSource,getType,getOrgID,input.OrgID,input.DataID)
|
|
|
|
|
|
if flag4{
|
|
|
c.JSON(http.StatusOK, MySwagger.DataGetResult{
|
|
|
Success: true,
|
|
|
Message: "DataexGet服务调用成功",
|
|
|
Datas: data,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}else {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataGetResult{
|
|
|
Success: flag,
|
|
|
Message: result,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// @Summary 分页查询数据
|
|
|
// @Description 【数据交换平台】分页查询数据服务接口,支持分页查询,支持数据变更时间查询,一个批次返回100条数据【query_page从0开始计数,query_time可以为空】。
|
|
|
// @Tags dataex
|
|
|
// @Accept json
|
|
|
// @Produce json
|
|
|
// @Param input body MySwagger.DataPage true "分页查询数据"
|
|
|
// @Success 200 {object} MySwagger.DataGetResult
|
|
|
// @Failure 400 {object} MySwagger.Result
|
|
|
// @Router /v1/dataex/DataexPage [post]
|
|
|
func DataexPage(c *gin.Context) {
|
|
|
|
|
|
var input MySwagger.DataPage
|
|
|
|
|
|
if err := c.ShouldBindJSON(&input); err != nil {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统数据JSON格式错误"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.SystemID == "" || input.AuthToken == "" {
|
|
|
c.JSON(http.StatusUnauthorized, MySwagger.Result{Success: false,Message: "接入系统票据验证失败"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.QueryPage <0 ||input.OrgID=="" || input.DataSource=="" {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统JSON数据字段不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag,_,systemID:=AuthService.CheckToken(input.SystemID,input.AuthToken)
|
|
|
|
|
|
if flag==false {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统票据不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag2,_,dataSource2 := DataexService.CheckDatasourceSet(systemID,input.DataSource)
|
|
|
flag3,_,dataSource3 := DataexService.CheckDatasourceGet(systemID,input.DataSource)
|
|
|
|
|
|
if flag2==false && flag3==false {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统访问的数据源类型不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var getType int
|
|
|
var getOrgID string
|
|
|
|
|
|
if flag2{
|
|
|
getType =dataSource2.ProvideType
|
|
|
getOrgID =dataSource2.ProvideOrgid
|
|
|
}
|
|
|
if flag3{
|
|
|
getType=dataSource3.ConsumeType
|
|
|
getOrgID=dataSource3.ConsumeOrgid
|
|
|
}
|
|
|
|
|
|
flag4,result,data:=DataexService.DataexPage(input.DataSource,getType,getOrgID,input.OrgID,input.QueryPage,input.QueryTime)
|
|
|
|
|
|
if flag4{
|
|
|
c.JSON(http.StatusOK, MySwagger.DataGetResult{
|
|
|
Success: true,
|
|
|
Message: "DataexPage服务调用成功",
|
|
|
Datas: data,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}else {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataGetResult{
|
|
|
Success: flag,
|
|
|
Message: result,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// @Summary 条件查询数据
|
|
|
// @Description 【数据交换平台】条件查询数据服务接口,支持组合条件查询,支持分页查询,一个批次返回100条数据。
|
|
|
// @Tags dataex
|
|
|
// @Accept json
|
|
|
// @Produce json
|
|
|
// @Param input body MySwagger.DataQuery true "条件查询数据"
|
|
|
// @Success 200 {object} MySwagger.DataGetResult
|
|
|
// @Failure 400 {object} MySwagger.Result
|
|
|
// @Router /v1/dataex/DataexQuery [post]
|
|
|
func DataexQuery(c *gin.Context) {
|
|
|
|
|
|
var input MySwagger.DataQuery
|
|
|
|
|
|
if err := c.ShouldBindJSON(&input); err != nil {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统数据JSON格式错误"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.SystemID == "" || input.AuthToken == "" {
|
|
|
c.JSON(http.StatusUnauthorized, MySwagger.Result{Success: false,Message: "接入系统票据不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.QueryPage <0 ||input.OrgID=="" || input.DataSource=="" {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统JSON数据字段不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag,_,systemID:=AuthService.CheckToken(input.SystemID,input.AuthToken)
|
|
|
|
|
|
if flag==false {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统票据不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag2,_,dataSource2 := DataexService.CheckDatasourceSet(systemID,input.DataSource)
|
|
|
flag3,_,dataSource3 := DataexService.CheckDatasourceGet(systemID,input.DataSource)
|
|
|
|
|
|
if flag2==false && flag3==false {
|
|
|
c.JSON(http.StatusBadRequest, MySwagger.Result{Success: false,Message: "接入系统访问的数据源类型不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var getType int
|
|
|
var getOrgID string
|
|
|
|
|
|
if flag2{
|
|
|
getType =dataSource2.ProvideType
|
|
|
getOrgID =dataSource2.ProvideOrgid
|
|
|
}
|
|
|
if flag3{
|
|
|
getType=dataSource3.ConsumeType
|
|
|
getOrgID=dataSource3.ConsumeOrgid
|
|
|
}
|
|
|
|
|
|
flag4,result,data:=DataexService.DataexQuery(input.DataSource,getType,getOrgID,input.OrgID,input.QueryPage,input.QueryConditions)
|
|
|
|
|
|
if flag4{
|
|
|
c.JSON(http.StatusOK, MySwagger.DataGetResult{
|
|
|
Success: true,
|
|
|
Message: "DataexQuery服务调用成功",
|
|
|
Datas: data,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}else {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataGetResult{
|
|
|
Success: flag,
|
|
|
Message: result,
|
|
|
})
|
|
|
|
|
|
return
|
|
|
}
|
|
|
} |