master
wangshuai 5 years ago
parent b9491e9b31
commit 4f0ac5cb55

@ -50,6 +50,20 @@ func GetDatasourceResults(query MySwagger.DatasourceQuery) (bool, string, int, [
}
}
func GetAllDatasourceResults(query string) (bool, string, int, []map[string]interface{}, error) {
sql := "SELECT * FROM t_dataex_datasource WHERE 1 = 1 " + query + " ORDER BY create_time DESC, change_time DESC"
// 数量
count, _ := DbUtil.Engine.SQL(sql).Query().Count()
// 数据条数
list, err := DbUtil.Engine.SQL(sql).Query().List()
if list != nil {
return true, "数据获取成功", count, list, err
} else {
return false, "数据获取失败,数据源不存在", count, nil, nil
}
}
func CreateDatasource(model *models.TDataexDatasource) (bool, string, error) {
_, err := db.Insert(model)
if err != nil {

@ -219,14 +219,10 @@ func GetESDoc(datasourceCode string, dataId string) (bool, string, map[string]in
func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, conditions map[string]interface{}, sort map[string]interface{}) (bool, string, int, []map[string]interface{}) {
count, _ := ES7Util.GetDocCount(datasourceCode, begin, conditions)
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 datas []map[string]interface{}
// 写法2
//esDatas := make([]interface{}, count)
fmt.Println(esDatas)
@ -236,8 +232,8 @@ func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, c
j, _ := json.Marshal(value)
json.Unmarshal(j, &esData)
esData["datasource_name"] = datasourceName
fmt.Println("esData:", esData)
//esData["datasource_name"] = datasourceName
//fmt.Println("esData:", esData)
esDatas = append(esDatas, esData)
// 写法2
@ -245,7 +241,19 @@ func ReadESDoc(datasourceCode string, orgIDs []string, page int, begin string, c
//esDatas[k] = esData
}
return result, message, count, esDatas
var query = ""
res, _, _, datasources, _ := DatasourceDAO.GetAllDatasourceResults(query)
fmt.Println(datasources)
if res == true {
listJson, _ :=json.Marshal(esDatas)
joinListJson, _ := json.Marshal(datasources)
mergedesDatas := CommonUtil.ListMerge(string(listJson), string(joinListJson), "datasource_id", "datasource_code", "datasource_name", "datasource_name")
json.Unmarshal([]byte(mergedesDatas), &datas)
}
fmt.Println("datas:", datas)
return result, message, count, datas
}
//func IsDatasourceExistsByCode(code string) bool {

Loading…
Cancel
Save