edb_source.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. package data_manage
  2. import (
  3. "fmt"
  4. "github.com/beego/beego/v2/client/orm"
  5. "strings"
  6. )
  7. // EdbSource 指标来源表
  8. type EdbSource struct {
  9. EdbSourceId int `orm:"column(edb_source_id);pk"`
  10. SourceName string `description:"指标来源名称"`
  11. TableName string `description:"数据表名"`
  12. EdbAddMethod string `description:"指标新增接口"`
  13. EdbRefreshMethod string `description:"指标刷新接口"`
  14. IsBase int `description:"是否为基础指标: 0-否; 1-是"`
  15. FromBridge int `description:"是否来源于桥接服务: 0-否; 1-是"`
  16. BridgeFlag string `description:"桥接服务对象标识"`
  17. SourceExtend string `description:"扩展字段做查询用"`
  18. }
  19. // GetEdbSourceItemsByCondition 获取指标来源列表
  20. func GetEdbSourceItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbSource, err error) {
  21. o := orm.NewOrmUsingDB("data")
  22. fields := strings.Join(fieldArr, ",")
  23. if len(fieldArr) == 0 {
  24. fields = `*`
  25. }
  26. order := `ORDER BY edb_source_id ASC`
  27. if orderRule != "" {
  28. order = ` ORDER BY ` + orderRule
  29. }
  30. sql := fmt.Sprintf(`SELECT %s FROM edb_source WHERE 1=1 %s %s`, fields, condition, order)
  31. _, err = o.Raw(sql, pars).QueryRows(&items)
  32. return
  33. }
  34. // GetEdbSourceItemByCondition 获取指标来源
  35. func GetEdbSourceItemByCondition(condition string, pars []interface{}) (item *EdbSource, err error) {
  36. o := orm.NewOrmUsingDB("data")
  37. sql := fmt.Sprintf(`SELECT * FROM edb_source WHERE 1=1 %s`, condition)
  38. err = o.Raw(sql, pars).QueryRow(&item)
  39. return
  40. }