|
|
package GPSqlOpenapi
|
|
|
|
|
|
import (
|
|
|
"dsDataex/MyReport/GPSql/GPSqlService"
|
|
|
"dsDataex/MyReport/MySwagger"
|
|
|
"dsDataex/MyService/Auth/AuthService"
|
|
|
"dsDataex/MyService/DataEX/DataexService"
|
|
|
"dsDataex/Utils/ConfigUtil"
|
|
|
"dsDataex/Utils/FileCacheUtil"
|
|
|
"dsDataex/Utils/ValidationUtil"
|
|
|
"fmt"
|
|
|
"github.com/gin-gonic/gin"
|
|
|
"net/http"
|
|
|
"strings"
|
|
|
)
|
|
|
|
|
|
// @Summary GP-SQL数据查询
|
|
|
// @Description 【统计分析平台】GP-SQL数据简单查询接口,使用接入系统自定义的查询,返回查询结果数据。
|
|
|
// @Tags report
|
|
|
// @Accept json
|
|
|
// @Produce json
|
|
|
// @Param input body MySwagger.QuerySimpleGP true "简单查询数据"
|
|
|
// @Success 200 {object} MySwagger.DataResult
|
|
|
// @Failure 400 {object} MySwagger.DataResult
|
|
|
// @Router /dataex/report/QuerySimpleGP [post]
|
|
|
func QuerySimpleGP(c *gin.Context) {
|
|
|
|
|
|
var input MySwagger.QuerySimpleGP
|
|
|
|
|
|
if err := c.ShouldBindJSON(&input); err != nil {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataResult{Success: false, Message: "查询数据JSON格式错误"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if input.Query.QueryID == "" {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataResult{Success: false, Message: "查询数据QueryID不能为空"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//TODO:数据查询权限验证 !!!
|
|
|
var temp = strings.Split(input.AccessToken, "##")
|
|
|
|
|
|
if len(temp) != 3 {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataResult{Success: false, Message: "接入系统票据格式不正确"})
|
|
|
return
|
|
|
}
|
|
|
|
|
|
flag, _, systemID := AuthService.CheckAccessToken(temp[0], temp[1], temp[2])
|
|
|
|
|
|
if flag == false {
|
|
|
//c.JSON(http.StatusOK, MySwagger.DataResult{Success: false,Message: "接入系统票据不正确"})
|
|
|
//return
|
|
|
}
|
|
|
|
|
|
flag2, _ := DataexService.CheckDatasourceSql(systemID, input.Query.QueryID)
|
|
|
|
|
|
if flag2 == false {
|
|
|
//c.JSON(http.StatusOK, MySwagger.DataResult{Success: false,Message: "接入系统GP-SQL查询权限验证失败"})
|
|
|
//return
|
|
|
}
|
|
|
|
|
|
// 输入参数 SQL注入检测
|
|
|
if len(input.Query.QueryParam) > 0 {
|
|
|
result, msg, _ := ValidationUtil.ValidGPSql(input.Query.QueryParam)
|
|
|
if result == false {
|
|
|
fmt.Println(msg)
|
|
|
c.JSON(http.StatusOK, MySwagger.DataResult{Success: false, Message: msg})
|
|
|
return
|
|
|
}
|
|
|
}
|
|
|
|
|
|
// 缓存数据
|
|
|
var res bool
|
|
|
var msg string
|
|
|
var data string
|
|
|
|
|
|
if ConfigUtil.FCEnable == 1 && (input.QueryCache == 1 || input.QueryCache == 2) {
|
|
|
if ConfigUtil.FCMode == "calendar" {
|
|
|
// Calendar
|
|
|
res, msg, data = FileCacheUtil.SimpleGPCalendarCache(input)
|
|
|
} else {
|
|
|
// Cycle
|
|
|
res, msg, data = FileCacheUtil.SimpleGPCycleCache(input)
|
|
|
}
|
|
|
} else {
|
|
|
res, msg, data = GPSqlService.QuerySimple(input.Query.QueryID, input.Query.QueryParam, input.QueryGroup, input.QueryCount, input.QueryFormat)
|
|
|
}
|
|
|
|
|
|
if res {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataResult{
|
|
|
Success: true,
|
|
|
Message: msg,
|
|
|
Result: data,
|
|
|
})
|
|
|
} else {
|
|
|
c.JSON(http.StatusOK, MySwagger.DataResult{
|
|
|
Success: false,
|
|
|
Message: msg,
|
|
|
})
|
|
|
}
|
|
|
}
|