From 7af783b9a25e9ccb8869b3e54936b8f32f6e4a18 Mon Sep 17 00:00:00 2001 From: wangshuai Date: Fri, 4 Sep 2020 10:39:28 +0800 Subject: [PATCH] 'commit' --- .../DataSource/DatasourceDAO/DatasourceDAO.go | 33 ++++++++++++++----- .../DatasourceService/DatasourceService.go | 12 ++++--- 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/dsSupport/MyModel/DataSource/DatasourceDAO/DatasourceDAO.go b/dsSupport/MyModel/DataSource/DatasourceDAO/DatasourceDAO.go index e1915ed4..07fb7c7c 100644 --- a/dsSupport/MyModel/DataSource/DatasourceDAO/DatasourceDAO.go +++ b/dsSupport/MyModel/DataSource/DatasourceDAO/DatasourceDAO.go @@ -2,17 +2,33 @@ package DatasourceDAO import ( "dsSupport/MyModel/MySwagger" - "dsSupport/Utils/CacheUtil" "dsSupport/Utils/DbUtil" "dsSupport/Utils/ErrorConst" "dsSupport/Utils/LogUtil" "dsSupport/models" + "encoding/json" "fmt" ) //数据库 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) { 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) { - sql := "SELECT id FROM t_dataex_datasource WHERE datasource_code='" + code + "'" - fmt.Println("sql = ", sql) - - //通过SQL获取带缓存的数据 - list, count, _ := CacheUtil.Page(sql, 1, 0) + sql := "SELECT id FROM t_dataex_datasource WHERE datasource_code=?" - if count > 0 { - return true, "数据获取成功", list[0]["id"], nil + var id int + has, _ := DbUtil.Engine.SQL(sql, code).Get(&id) + fmt.Println(id) + if has == true { + return true, "数据获取成功", id, nil } else { - return false, "数据获取失败,systemID对应的数据源类型不存在", nil, nil + return false, "数据获取失败,数据源不存在", nil, nil } } diff --git a/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go b/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go index cab853b7..1365e600 100644 --- a/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go +++ b/dsSupport/MyModel/DataSource/DatasourceService/DatasourceService.go @@ -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{}) { 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 esData map[string]interface{} - //esDatas := make(map[string]map[string]interface{}) - //esData := make(map[string]interface{}) + for _, value := range esdata { - //esDatas = append(esDatas, value.DataContent) j, _ := json.Marshal(value) json.Unmarshal(j, &esData) - //fmt.Println(esData) esData = make(map[string]interface{}) + esData["datasource_name"] = datasourceName esDatas = append(esDatas, esData) }