package service import ( "fmt" "github.com/astaxie/beego/orm" "rtzh_elec_temperature/logger" "sync" ) //设备控制点列表缓存 var cpList = sync.Map{} //测点相关服务 type CpinfoService struct { BaseService } // 根据模型ID获取对应的控制点信息 // 返回对应的cpid,cpname,zonename等 func (t *CpinfoService) CpList(modelid int) []orm.Params { key := fmt.Sprintf("%d", modelid) var list = []orm.Params{} if info, ok := cpList.Load(key); ok { return info.([]orm.Params) } else { db := orm.NewOrm() // 多数据源,切换到平台的库上 db.Using("iss") var sqlCommandText = "select * from dev_cpinfo where appid=? and modelid=?" _, err := db.Raw(sqlCommandText, RtelecManageApp().RegAppID, modelid).Values(&list) if err == nil { if len(list) > 0 { cpList.Store(key, list) return list } } else { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("Error SQL:%s 参数:%s,%s", sqlCommandText, RtelecManageApp().RegAppID, modelid)) } } return list } // 根据控制点id获取控制点信息 func (t *CpinfoService) GetCpInfoById(cpid int64) (orm.Params, error) { db := orm.NewOrm() db.Using("iss") cpInfo := []orm.Params{} sqlCommandText := "select * from dev_cpinfo where appid=? and mpid=?" _, err := db.Raw(sqlCommandText, RtelecManageApp().RegAppID, cpid).Values(&cpInfo) if err == nil { if len(cpInfo) > 0 { return cpInfo[0], nil } } else { logger.Logger.Error(err) logger.Logger.Println(fmt.Sprintf("Error SQL:%s 参数:%s,%d", sqlCommandText, RtelecManageApp().RegAppID, cpid)) return orm.Params{}, err } return orm.Params{}, nil }