Files
jx-callback/business/model/dao/thing_map.go
2019-12-09 17:37:56 +08:00

35 lines
1.0 KiB
Go

package dao
import "git.rosy.net.cn/jx-callback/business/model"
import "git.rosy.net.cn/baseapi/utils"
func GetThingMapList(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (cats []*model.ThingMap, err error) {
sql := `
SELECT t1.*
FROM thing_map t1
WHERE t1.deleted_at = ? AND t1.thing_type = ?
`
sqlParams := []interface{}{
utils.DefaultTimeValue,
thingType,
}
if len(thingIDs) > 0 { // 必须要指定ID
sql += " AND t1.thing_id IN (" + GenQuestionMarks(len(thingIDs)) + ")"
sqlParams = append(sqlParams, thingIDs)
err = GetRows(db, &cats, sql, sqlParams...)
}
return cats, err
}
func GetThingMapMap(db *DaoDB, thingType int, vendorIDs, thingIDs []int) (thingMapMap map[int64][]*model.ThingMap, err error) {
thingMapList, err := GetThingMapList(db, thingType, vendorIDs, thingIDs)
if err == nil {
thingMapMap = make(map[int64][]*model.ThingMap)
for _, thingMap := range thingMapList {
thingMapMap[thingMap.ThingID] = append(thingMapMap[thingMap.ThingID], thingMap)
}
}
return thingMapMap, err
}