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.
202 lines
4.4 KiB
202 lines
4.4 KiB
package datacenter
|
|
|
|
import (
|
|
"appPlatform/overall/publicmethod"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/url"
|
|
"strings"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-04-18 15:37:05
|
|
@ 功能: 通用地址
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) GaindataCenter(c *gin.Context) {
|
|
var requestData DataInfo
|
|
c.ShouldBindJSON(&requestData)
|
|
if requestData.Url == "" {
|
|
publicmethod.Result(1, requestData, c, "未知访问地址")
|
|
return
|
|
}
|
|
// publicmethod.Result(1, requestData, c, "未知访问地址")
|
|
// return
|
|
if requestData.Where != "" {
|
|
if requestData.Method == "GET" {
|
|
var whereAry []string
|
|
whyOne := strings.Split(requestData.Where, "&")
|
|
if len(whyOne) > 0 {
|
|
for _, v := range whyOne {
|
|
whyTwo := strings.Split(v, "=")
|
|
if len(whyTwo) == 2 {
|
|
whereAry = append(whereAry, fmt.Sprintf("%v=%v", whyTwo[0], url.QueryEscape(whyTwo[1])))
|
|
} else {
|
|
whereAry = append(whereAry, v)
|
|
}
|
|
}
|
|
}
|
|
getUrl := requestData.Url
|
|
if len(whereAry) > 0 {
|
|
getUrl = fmt.Sprintf("%v?%v", requestData.Url, strings.Join(whereAry, "&"))
|
|
}
|
|
|
|
// getUrl = url.QueryEscape(getUrl)
|
|
// fmt.Printf("%T--------->%v\n", getUrl, getUrl)
|
|
getData := publicmethod.CurlGet(getUrl)
|
|
var sendMap map[string]interface{}
|
|
json.Unmarshal(getData, &sendMap)
|
|
// fmt.Printf("%T--------->%v--------->%v\n", sendMap, sendMap, getUrl)
|
|
// publicmethod.Result(0, sendMap, c)
|
|
shenData := publicmethod.MapOut[string]()
|
|
if code, ok := sendMap["code"]; ok {
|
|
|
|
if codeIn, ok := code.(float64); ok {
|
|
if codeIn == 200 {
|
|
shenData["code"] = 0
|
|
} else {
|
|
shenData["code"] = codeIn
|
|
}
|
|
}
|
|
|
|
}
|
|
if msg, ok := sendMap["msg"]; ok {
|
|
shenData["msg"] = msg
|
|
}
|
|
if data, ok := sendMap["data"]; ok {
|
|
shenData["data"] = data
|
|
}
|
|
publicmethod.ResultInterface(sendMap, c)
|
|
return
|
|
} else {
|
|
getData := publicmethod.CurlPostJosn(requestData.Url, []byte(requestData.Where))
|
|
var sendMap map[string]interface{}
|
|
json.Unmarshal(getData, &sendMap)
|
|
publicmethod.ResultInterface(sendMap, c)
|
|
return
|
|
}
|
|
} else {
|
|
if requestData.Method == "GET" {
|
|
getUrl := fmt.Sprintf("%v", requestData.Url)
|
|
getData := publicmethod.CurlGet(getUrl)
|
|
var sendMap map[string]interface{}
|
|
json.Unmarshal(getData, &sendMap)
|
|
// publicmethod.Result(0, sendMap, c)
|
|
shenData := publicmethod.MapOut[string]()
|
|
if code, ok := sendMap["code"]; ok {
|
|
if codeIn, ok := code.(float64); ok {
|
|
if codeIn == 200 {
|
|
shenData["code"] = 0
|
|
} else {
|
|
shenData["code"] = codeIn
|
|
}
|
|
}
|
|
|
|
}
|
|
if msg, ok := sendMap["msg"]; ok {
|
|
shenData["msg"] = msg
|
|
}
|
|
if data, ok := sendMap["data"]; ok {
|
|
shenData["data"] = data
|
|
}
|
|
publicmethod.ResultInterface(sendMap, c)
|
|
return
|
|
} else {
|
|
getData := publicmethod.CurlPostJosn(requestData.Url, []byte(""))
|
|
var sendMap map[string]interface{}
|
|
json.Unmarshal(getData, &sendMap)
|
|
shenData := publicmethod.MapOut[string]()
|
|
if code, ok := sendMap["code"]; ok {
|
|
if codeIn, ok := code.(float64); ok {
|
|
if codeIn == 200 {
|
|
shenData["code"] = 0
|
|
} else {
|
|
shenData["code"] = codeIn
|
|
}
|
|
}
|
|
|
|
}
|
|
if msg, ok := sendMap["msg"]; ok {
|
|
shenData["msg"] = msg
|
|
}
|
|
publicmethod.ResultInterface(sendMap, c)
|
|
return
|
|
}
|
|
}
|
|
}
|
|
|
|
/*
|
|
*
|
|
@ 作者: 秦东
|
|
@ 时间: 2024-04-19 14:05:46
|
|
@ 功能: 数据中台POST提交数据
|
|
@ 参数
|
|
|
|
#
|
|
|
|
@ 返回值
|
|
|
|
#
|
|
|
|
@ 方法原型
|
|
|
|
#
|
|
*/
|
|
func (a *ApiMethod) PostSaveData(c *gin.Context) {
|
|
var requestData DataInfoPost
|
|
c.ShouldBindJSON(&requestData)
|
|
if requestData.Url == "" {
|
|
publicmethod.Result(1, requestData, c, "未知访问地址")
|
|
return
|
|
}
|
|
dataJson, err := json.Marshal(requestData.DataInfo)
|
|
shenData := publicmethod.MapOut[string]()
|
|
if err != nil {
|
|
shenData["code"] = 10001
|
|
shenData["msg"] = err
|
|
publicmethod.ResultInterface(shenData, c)
|
|
return
|
|
}
|
|
callBackBtye := publicmethod.CurlPostJosn(requestData.Url, dataJson)
|
|
var sendMap map[string]interface{}
|
|
err = json.Unmarshal(callBackBtye, &sendMap)
|
|
if err != nil {
|
|
shenData["code"] = 10001
|
|
shenData["msg"] = err
|
|
publicmethod.ResultInterface(shenData, c)
|
|
return
|
|
}
|
|
if code, ok := sendMap["code"]; ok {
|
|
|
|
if codeIn, ok := code.(float64); ok {
|
|
if codeIn == 200 {
|
|
shenData["code"] = 0
|
|
} else {
|
|
shenData["code"] = codeIn
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
if msg, ok := sendMap["msg"]; ok {
|
|
shenData["msg"] = msg
|
|
}
|
|
if data, ok := sendMap["data"]; ok {
|
|
shenData["data"] = data
|
|
}
|
|
publicmethod.ResultInterface(shenData, c)
|
|
}
|
|
|