edb_source.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. IsBase int `description:"是否为基础指标: 0-否; 1-是"`
  13. IsPrivate int `description:"是否为自有来源: 0-否; 1-是"`
  14. SourceExtend string `description:"扩展字段做查询用, 如嘉悦的wind对应wind、wind_stop"`
  15. }
  16. // GetEdbSourceItemsByCondition 获取指标来源列表
  17. func GetEdbSourceItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbSource, err error) {
  18. o := orm.NewOrmUsingDB("data")
  19. fields := strings.Join(fieldArr, ",")
  20. if len(fieldArr) == 0 {
  21. fields = `*`
  22. }
  23. order := `ORDER BY edb_source_id ASC`
  24. if orderRule != "" {
  25. order = ` ORDER BY ` + orderRule
  26. }
  27. sql := fmt.Sprintf(`SELECT %s FROM edb_source WHERE 1=1 %s %s`, fields, condition, order)
  28. _, err = o.Raw(sql, pars).QueryRows(&items)
  29. return
  30. }
  31. // EdbSourceChild 指标来源表
  32. type EdbSourceChild struct {
  33. EdbSourceId int `orm:"column(edb_source_id);pk"`
  34. SourceName string `description:"指标来源名称"`
  35. TableName string `description:"数据表名"`
  36. IsBase int `description:"是否为基础指标: 2-否; 1-是"`
  37. Child []EdbSourceChild
  38. }
  39. // GetEdbSourceItemByCondition 获取指标来源
  40. func GetEdbSourceItemByCondition(condition string, pars []interface{}) (item *EdbSource, err error) {
  41. o := orm.NewOrmUsingDB("data")
  42. sql := fmt.Sprintf(`SELECT * FROM edb_source WHERE 1=1 %s`, condition)
  43. err = o.Raw(sql, pars).QueryRow(&item)
  44. return
  45. }