zhangqian
2023-11-04 af74e9840efa3379fee18fa8362c6d571a38aad6
api/v1/device.go
@@ -16,20 +16,20 @@
type DeviceApi struct{}
// Set
// SetCurrentDeviceId
// @Tags      设备
// @Summary   设置当前设备id
// @Produce   application/json
// @Param     object  body    request.SetCurrentDevice true  "查询参数"
// @Success   200   {object}  contextx.Response{}  "成功"
// @Router    /v1/device/set [post]
func (slf *DeviceApi) Set(c *gin.Context) {
// @Router    /v1/device/setCurrentDeviceId [post]
func (slf *DeviceApi) SetCurrentDeviceId(c *gin.Context) {
   var params request.SetCurrentDevice
   ctx, ok := contextx.NewContext(c, &params)
   if !ok {
      return
   }
   if params.CurrentDeviceID != "" {
   if params.CurrentDeviceID == "" {
      ctx.Fail(ecode.ParamsErr)
      return
   }
@@ -45,7 +45,7 @@
      return
   }
   service.SetDeviceIDToFile(params.CurrentDeviceID)
   conf.Conf.SerfClusterStatus = params.CurrentDeviceID
   conf.Conf.CurrentDeviceID = params.CurrentDeviceID
   err = crontask.RestartTask(conf.Conf.SerfClusterStatus != constvar.SerfClusterStatusSlave)
   if err != nil {
      logx.Errorf("restart task failed:%v", err)
@@ -57,11 +57,11 @@
}
// DeviceList
// @Tags      Device
// @Tags      设备
// @Summary   获取当前面板绑定的设备列表
// @Produce   application/json
// @Success   200   {object}  contextx.Response{data=response.DeviceListResponse}  "成功"
// @Router    /v1/device/list [post]
// @Router    /v1/device/list [get]
func (slf *DeviceApi) DeviceList(c *gin.Context) {
   ctx, ok := contextx.NewContext(c, nil)
   if !ok {
@@ -73,9 +73,13 @@
      return
   }
   resp := response.DeviceListResponse{
      SystemDeviceID:  conf.Conf.System.DeviceId,
      CurrentDeviceID: conf.Conf.CurrentDeviceID,
      DeviceIDList:    list,
      SystemDeviceID:       conf.Conf.System.DeviceId,
      CurrentDeviceID:      conf.Conf.CurrentDeviceID,
      DeviceIDList:         list,
      SystemDeviceStatus:   response.SystemDeviceStatusNormal,
      ClusterStatus:        conf.Conf.SerfClusterStatus,
      ClusterNodeQuantity:  conf.Conf.ClusterNodeQuantity,
      SystemDeviceRunSince: conf.Conf.SystemDeviceRunSince,
   }
   ctx.OkWithDetailed(resp)
}