1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- package data_manage
- import (
- "eta/eta_task/utils"
- "fmt"
- "github.com/beego/beego/v2/client/orm"
- "strings"
- )
- var (
- EdbDataTableNameMap map[int]string
- EdbDataRefreshMethodMap map[int]string
- EdbTableNameSourceMap map[string]*EdbSource
- EdbSourceIdMap map[int]*EdbSource
- EdbSourceExtendIdMap map[string]int
- )
- type EdbSource struct {
- EdbSourceId int `orm:"column(edb_source_id);pk"`
- SourceName string `description:"指标来源名称"`
- TableName string `description:"数据表名"`
- EdbAddMethod string `description:"指标新增接口"`
- EdbRefreshMethod string `description:"指标刷新接口"`
- IsBase int `description:"是否为基础指标: 0-否; 1-是"`
- FromBridge int `description:"是否来源于桥接服务: 0-否; 1-是"`
- BridgeFlag string `description:"桥接服务对象标识"`
- SourceExtend string `description:"扩展字段做查询用"`
- }
- func GetEdbSourceItemsByCondition(condition string, pars []interface{}, fieldArr []string, orderRule string) (items []*EdbSource, err error) {
- o := orm.NewOrmUsingDB("data")
- fields := strings.Join(fieldArr, ",")
- if len(fieldArr) == 0 {
- fields = `*`
- }
- order := `ORDER BY edb_source_id ASC`
- if orderRule != "" {
- order = ` ORDER BY ` + orderRule
- }
- sql := fmt.Sprintf(`SELECT %s FROM edb_source WHERE 1=1 %s %s`, fields, condition, order)
- _, err = o.Raw(sql, pars).QueryRows(&items)
- return
- }
- func GetEdbSourceItemByCondition(condition string, pars []interface{}) (item *EdbSource, err error) {
- o := orm.NewOrmUsingDB("data")
- sql := fmt.Sprintf(`SELECT * FROM edb_source WHERE 1=1 %s`, condition)
- err = o.Raw(sql, pars).QueryRow(&item)
- return
- }
- func InitEdbSourceVar() {
- EdbDataTableNameMap = make(map[int]string)
- EdbDataRefreshMethodMap = make(map[int]string)
- EdbTableNameSourceMap = make(map[string]*EdbSource)
- EdbSourceIdMap = make(map[int]*EdbSource)
- EdbSourceExtendIdMap = make(map[string]int)
- sources, e := GetEdbSourceItemsByCondition(``, make([]interface{}, 0), []string{}, "")
- if e != nil {
- utils.FileLog.Info("init source table err: %s", e.Error())
- return
- }
- for _, v := range sources {
- EdbDataTableNameMap[v.EdbSourceId] = v.TableName
- EdbDataRefreshMethodMap[v.EdbSourceId] = v.EdbRefreshMethod
- EdbTableNameSourceMap[v.TableName] = v
- EdbSourceIdMap[v.EdbSourceId] = v
- if v.SourceExtend != "" {
- arr := strings.Split(v.SourceExtend, ",")
- if len(arr) == 0 {
- continue
- }
- for _, s := range arr {
- EdbSourceExtendIdMap[s] = v.EdbSourceId
- }
- }
- }
- }
|