master
wangshuai 5 years ago
parent 37caba0dec
commit 7af783b9a2

@ -2,17 +2,33 @@ package DatasourceDAO
import ( import (
"dsSupport/MyModel/MySwagger" "dsSupport/MyModel/MySwagger"
"dsSupport/Utils/CacheUtil"
"dsSupport/Utils/DbUtil" "dsSupport/Utils/DbUtil"
"dsSupport/Utils/ErrorConst" "dsSupport/Utils/ErrorConst"
"dsSupport/Utils/LogUtil" "dsSupport/Utils/LogUtil"
"dsSupport/models" "dsSupport/models"
"encoding/json"
"fmt" "fmt"
) )
//数据库 //数据库
var db = DbUtil.Engine var db = DbUtil.Engine
func GetDatasourceRow(query string) (bool, string, map[string]interface{}, error) {
sql := "SELECT * FROM t_dataex_datasource WHERE 1 = 1 " + query
var datasource models.TDataexDatasource
has, _ := DbUtil.Engine.SQL(sql).Get(&datasource)
if has == true {
m := make(map[string]interface{})
j, _ := json.Marshal(datasource)
json.Unmarshal(j, &m)
return true, "数据获取成功", m, nil
} else {
return false, "数据获取失败,数据源不存在", nil, nil
}
}
func GetDatasourceResults(query MySwagger.DatasourceQuery) (bool, string, int, []map[string]interface{}, error) { func GetDatasourceResults(query MySwagger.DatasourceQuery) (bool, string, int, []map[string]interface{}, error) {
sql := "SELECT * FROM t_dataex_datasource WHERE 1 = 1" + query.Conditions + " ORDER BY create_time DESC, change_time DESC" sql := "SELECT * FROM t_dataex_datasource WHERE 1 = 1" + query.Conditions + " ORDER BY create_time DESC, change_time DESC"
//接收传入参数 //接收传入参数
@ -80,15 +96,14 @@ func IsDatasourceExistsById(id string) bool {
} }
func GetDatasourceIdByCode(code string) (bool, string, interface{}, error) { func GetDatasourceIdByCode(code string) (bool, string, interface{}, error) {
sql := "SELECT id FROM t_dataex_datasource WHERE datasource_code='" + code + "'" sql := "SELECT id FROM t_dataex_datasource WHERE datasource_code=?"
fmt.Println("sql = ", sql)
//通过SQL获取带缓存的数据
list, count, _ := CacheUtil.Page(sql, 1, 0)
if count > 0 { var id int
return true, "数据获取成功", list[0]["id"], nil has, _ := DbUtil.Engine.SQL(sql, code).Get(&id)
fmt.Println(id)
if has == true {
return true, "数据获取成功", id, nil
} else { } else {
return false, "数据获取失败systemID对应的数据源类型不存在", nil, nil return false, "数据获取失败,数据源不存在", nil, nil
} }
} }

@ -166,17 +166,21 @@ func RemoveDatasource(id string) (bool, string, error) {
func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, conditions map[string]interface{}, sort map[string]interface{}) (bool, string, []map[string]interface{}) { func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, conditions map[string]interface{}, sort map[string]interface{}) (bool, string, []map[string]interface{}) {
result, message, esdata := ES7Util.SearchDocPage(datasourceCode, orgIDs, page, begin, conditions, sort) result, message, esdata := ES7Util.SearchDocPage(datasourceCode, orgIDs, page, begin, conditions, sort)
var query = "AND datasource_code='" + datasourceCode + "'"
res, _, data, _ := DatasourceDAO.GetDatasourceRow(query)
var datasourceName interface{}
if res == true {
datasourceName = data["datasource_name"]
}
var esDatas []map[string]interface{} var esDatas []map[string]interface{}
var esData map[string]interface{} var esData map[string]interface{}
//esDatas := make(map[string]map[string]interface{})
//esData := make(map[string]interface{})
for _, value := range esdata { for _, value := range esdata {
//esDatas = append(esDatas, value.DataContent)
j, _ := json.Marshal(value) j, _ := json.Marshal(value)
json.Unmarshal(j, &esData) json.Unmarshal(j, &esData)
//fmt.Println(esData)
esData = make(map[string]interface{}) esData = make(map[string]interface{})
esData["datasource_name"] = datasourceName
esDatas = append(esDatas, esData) esDatas = append(esDatas, esData)
} }

Loading…
Cancel
Save