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.
62 lines
1.6 KiB
62 lines
1.6 KiB
package DatahyperDAO
|
|
|
|
import (
|
|
"dsDataex/GenXorm/models"
|
|
"dsDataex/Utils/DbUtil"
|
|
"dsDataex/Utils/MariaDbUtil"
|
|
"encoding/json"
|
|
"fmt"
|
|
)
|
|
|
|
// 基础数据库
|
|
var baseDb = DbUtil.Engine
|
|
// Maria数据库
|
|
var mariaDb = MariaDbUtil.Engine
|
|
|
|
func GetQuerySQL(queryID string) (bool, string, string, error) {
|
|
sql := "SELECT * FROM t_report_sqlquery WHERE query_code='" + queryID + "'"
|
|
|
|
var sqlQuery models.TReportSqlquery
|
|
has, _ := baseDb.SQL(sql).Get(&sqlQuery)
|
|
|
|
if has {
|
|
m := make(map[string]interface{})
|
|
j, _ := json.Marshal(sqlQuery)
|
|
json.Unmarshal(j, &m)
|
|
|
|
return true, "ok", m["query_sql"].(string), nil
|
|
} else {
|
|
return false, "fail", "", nil
|
|
}
|
|
}
|
|
|
|
func GetRow(sql string, dataID string) (bool, string, map[string]interface{}, error) {
|
|
result, err := mariaDb.SQL(sql, dataID).Query().List()
|
|
//result = result[4 : len(result) - 2]
|
|
if err == nil {
|
|
return true, "数据查询成功", result[0], nil
|
|
} else {
|
|
return false, "数据查询失败", nil, err
|
|
}
|
|
}
|
|
|
|
func GetResults(sql string, limit int, offset int) (bool, string, int, []map[string]interface{}, error) {
|
|
//条件查询语句
|
|
conditionSql := fmt.Sprintf("%s", " limit ? offset ? ")
|
|
//分页的语句
|
|
pageSql := fmt.Sprintf("%s %s", sql, conditionSql)
|
|
//数据条数
|
|
count, _ := mariaDb.SQL(sql).Query().Count()
|
|
if count > 0 {
|
|
//分页数据
|
|
list, err := mariaDb.SQL(pageSql, limit, offset).Query().List()
|
|
if err == nil {
|
|
return true, "数据获取成功", count, list, nil
|
|
} else {
|
|
return false, "数据获取失败,数据不存在", count, nil, nil
|
|
}
|
|
} else {
|
|
return false, "数据获取失败,数据不存在", count, nil, nil
|
|
}
|
|
}
|