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.

91 lines
2.7 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package DatasourceDAO
import (
"dsDataex/GenXorm/models"
"dsDataex/MyModel/MySwagger"
"dsDataex/Utils/CacheUtil"
"dsDataex/Utils/DbUtil"
"dsDataex/Utils/ErrorConst"
"dsDataex/Utils/LogUtil"
"fmt"
)
//数据库
var db = DbUtil.Engine
func GetDatasourceResults (query MySwagger.DatasourceQuery) (bool, string, int32, []map[string]interface{}, error){
sql := "SELECT id FROM t_dataex_datasource WHERE 1 = 1" + query.Conditions
fmt.Println("sql = ", sql)
//通过SQL获取带缓存的数据
list, count, _ := CacheUtil.Page(sql, 100, query.Page)
if count >0 {
return true, "数据获取成功", count, list, nil
}else {
return false, "数据获取失败systemID对应的数据源类型不存在", count, nil, nil
}
}
func CreateDatasource (model *models.TDataexDatasource) (bool, string, error) {
_, err := db.Insert(model)
if err != nil {
fmt.Println("err=", err)
LogUtil.Error(ErrorConst.SqlUpdateError, "接入系统authToken Update数据库操作发生严重错误"+err.Error())
return false, "数据库操作失败", err
}
return true, "创建成功!", nil
}
func UpdateDatasource (id string, model *models.TDataexDatasource) (bool, string, error){
_, err := db.Where(" id = ?", id ).Update(model)
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "接入系统authToken Update数据库操作发生严重错误"+err.Error())
return false, "数据库操作失败", err
}
return true, "修改成功!", nil
}
func RemoveDatasource (id string, model *models.TDataexDatasource) (bool, string, error){
_, err := db.Where(" id = ?", id ).Update(model)
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "接入系统authToken Update数据库操作发生严重错误"+err.Error())
return false, "数据库操作失败", err
}
return true, "删除成功!", nil
}
func GetDatasourceCountById(id string) int64 {
business := new(models.TDataexLinksystem)
total, err := db.Where("id =?", id).Count(business)
if err != nil {
LogUtil.Error(ErrorConst.SqlUpdateError, "接入系统authToken Update数据库操作发生严重错误"+err.Error())
}
return total
}
func IsDatasourceExistsById(id string) bool {
if GetDatasourceCountById(id) > 0 {
return true
}
return false
}
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)
if count >0 {
return true, "数据获取成功", list[0]["id"],nil
}else {
return false, "数据获取失败systemID对应的数据源类型不存在", nil,nil
}
}