This commit is contained in:
tfl
2024-08-21 17:35:50 +08:00
parent 34ea7472b7
commit dd5b38b4e3
24 changed files with 328 additions and 133 deletions

View File

@@ -7,7 +7,6 @@ package api
// ==========================================================================
import (
"fmt"
"pandax/apps/device/util"
"pandax/kit/biz"
"pandax/kit/model"
"pandax/kit/restfulx"
@@ -131,6 +130,18 @@ func (p *DeviceApi) GetDeviceStatus(rc *restfulx.ReqCtx) {
rc.ResData = res
}
func (p *DeviceApi) GetDeviceEvents(rc *restfulx.ReqCtx) {
pageNum := restfulx.QueryInt(rc, "pageNum", 1)
pageSize := restfulx.QueryInt(rc, "pageSize", 10)
deviceId := restfulx.PathParam(rc, "id")
ty := restfulx.QueryParam(rc, "type")
offset := pageSize * (pageNum - 1)
sql := `select * from ? where deviceId = ? and type = ? DESC LIMIT ?,? `
list, err := global.TdDb.GetAllEvents(sql, deviceId, ty, offset, pageSize)
biz.ErrIsNilAppendErr(err, "查询设备事件历史失败")
rc.ResData = list
}
// GetDeviceTelemetryHistory 获取Device属性的遥测历史
func (p *DeviceApi) GetDeviceTelemetryHistory(rc *restfulx.ReqCtx) {
id := restfulx.PathParam(rc, "id")
@@ -146,21 +157,6 @@ func (p *DeviceApi) GetDeviceTelemetryHistory(rc *restfulx.ReqCtx) {
rc.ResData = rs
}
// 下发设备属性
func (p *DeviceApi) DownAttribute(rc *restfulx.ReqCtx) {
id := restfulx.PathParam(rc, "id")
key := restfulx.QueryParam(rc, "key")
value := restfulx.QueryParam(rc, "value")
biz.NotEmpty(value, "请设置属性值")
err := util.BuildRunDeviceRpc(id, "single", map[string]interface{}{
"method": "setAttributes",
"params": map[string]interface{}{
key: value,
},
})
biz.ErrIsNilAppendErr(err, "下发失败:")
}
// InsertDevice 添加Device
func (p *DeviceApi) InsertDevice(rc *restfulx.ReqCtx) {
var data entity.Device