package business import ( "fmt" "github.com/gin-gonic/gin" "github.com/gin-gonic/gin/binding" //"device-manage/app/admin/models" "device-manage/app/admin/models/busmodels" "device-manage/common/log" mqtthandler "device-manage/common/mqttcli" "device-manage/tools" "device-manage/tools/app" "device-manage/tools/config" ) // @Summary 获取设备列表 // @Description Get JSON // @Tags 设备列表 // @Param name query string false "name" // @Param status query string false "status" // @Param deviceSn query string false "deviceSn" // @Param pageSize query int false "页条数" // @Param pageIndex query int false "页码" // @Success 200 {object} app.Response "{"code": 200, "data": [...]}" // @Router /api/v1/device/list/devicelist [get] // @Security Bearer func GetMonitorList(c *gin.Context) { var data busmodels.BusDevice var err error var params busmodels.QueryParams err = c.MustBindWith(¶ms, binding.JSON) pageSize := params.PageSize pageIndex := params.PageIndex gids := params.Gids data.DeviceName = params.DeviceName data.DeviceSn = params.DeviceSn data.Status = params.Status data.IsRegister = 1 result, count, err := data.GetMonitorPage(pageSize, pageIndex, gids) tools.HasError(err, "", -1) app.PageOK(c, result, count, pageIndex, pageSize, "") } func GetDeviceLog(c *gin.Context) { var err error var dev busmodels.BusDevice var devInfo busmodels.DeviceInfo //"/api/v1/device/usual/log/upload" url := "http://" + tools.GetLocaHonst() + ":" + config.ApplicationConfig.Port + "/" fmt.Println(url) IDS := tools.IdsStrToIdsIntGroup("deviceId", c) userId := tools.GetUserIdStr(c) fmt.Println(IDS) //todo get device log for _, devid := range IDS { fmt.Println(devid) dev.DeviceId = devid if devInfo, err = dev.Get(); err != nil { continue } if devInfo.Status > 0 { log.Info(devInfo.Status) log.Info(len(mqtthandler.MqttClientList)) if _, ok := mqtthandler.MqttClientList[devInfo.ServerIp]; ok { mqtthandler.MqttClientList[devInfo.ServerIp].CollectLog(userId, devInfo.DeviceSn, url) } else { log.Info(ok) } } else { log.Info("cmd collect log device offline [%s]", devInfo.DeviceSn) } } app.OK(c, "", "开始获取日志") } func RebootDevice(c *gin.Context) { var err error var dev busmodels.BusDevice var devInfo busmodels.DeviceInfo IDS := tools.IdsStrToIdsIntGroup("deviceId", c) fmt.Println(IDS) //todo get device log for _, devid := range IDS { fmt.Println(devid) dev.DeviceId = devid if devInfo, err = dev.Get(); err != nil { continue } if devInfo.Status > 0 { if _, ok := mqtthandler.MqttClientList[devInfo.ServerIp]; ok { mqtthandler.MqttClientList[devInfo.ServerIp].Reboot(devInfo.DeviceSn) } } else { log.Info("cmd reboot offline [%s]", devInfo.DeviceSn) } } app.OK(c, "", "重启成功.") }