fix
zhangqian
2023-12-01 8324f872ef3a4d0c978a9b1d062800c6a1701c12
api/v1/device.go
@@ -2,8 +2,6 @@
import (
   "apsClient/conf"
   "apsClient/constvar"
   "apsClient/crontask"
   "apsClient/model/request"
   "apsClient/model/response"
   _ "apsClient/model/response"
@@ -29,11 +27,16 @@
   if !ok {
      return
   }
   if params.CurrentDeviceID != "" {
   if params.CurrentDeviceID == "" {
      ctx.Fail(ecode.ParamsErr)
      return
   }
   list, err := service.GetDeviceIDList()
   if err != nil {
      logx.Errorf("SetCurrentDeviceId GetDeviceIDList err:%v", err)
      ctx.Fail(ecode.DBErr)
      return
   }
   findFlag := false
   for _, item := range list {
      if item == params.CurrentDeviceID {
@@ -45,19 +48,38 @@
      return
   }
   service.SetDeviceIDToFile(params.CurrentDeviceID)
   conf.Conf.SerfClusterStatus = params.CurrentDeviceID
   err = crontask.RestartTask(conf.Conf.SerfClusterStatus != constvar.SerfClusterStatusSlave)
   if err != nil {
      logx.Errorf("restart task failed:%v", err)
      ctx.Fail(ecode.UnknownErr)
   conf.Conf.CurrentDeviceID = params.CurrentDeviceID
   ctx.Ok()
}
// Config
// @Tags      设备
// @Summary   设置设备一些配置
// @Produce   application/json
// @Param     object  body    request.DeviceConfig true  "查询参数"
// @Success   200   {object}  contextx.Response{}  "成功"
// @Router    /v1/device/config [post]
func (slf *DeviceApi) Config(c *gin.Context) {
   var params request.DeviceConfig
   ctx, ok := contextx.NewContext(c, &params)
   if !ok {
      return
   }
   if conf.Conf.CurrentDeviceID == "" {
      ctx.FailWithMsg(ecode.UnknownErr, "当前设备为空,请检查")
      return
   }
   err := service.UpdateDevice(conf.Conf.CurrentDeviceID, params.NeedSetProcessParams)
   if err != nil {
      logx.Errorf("save device config err:%v", err)
      ctx.Fail(ecode.DBErr)
      return
   }
   ctx.Ok()
}
// DeviceList
// @Tags      Device
// @Tags      设备
// @Summary   获取当前面板绑定的设备列表
// @Produce   application/json
// @Success   200   {object}  contextx.Response{data=response.DeviceListResponse}  "成功"
@@ -67,15 +89,19 @@
   if !ok {
      return
   }
   list, err := service.GetDeviceIDList()
   list, err := service.GetDeviceList()
   if err != nil {
      ctx.Fail(ecode.DBErr)
      return
   }
   resp := response.DeviceListResponse{
      SystemDeviceID:  conf.Conf.System.DeviceId,
      CurrentDeviceID: conf.Conf.CurrentDeviceID,
      DeviceIDList:    list,
      SystemDeviceID:       conf.Conf.System.DeviceId,
      CurrentDeviceID:      conf.Conf.CurrentDeviceID,
      DeviceList:           list,
      SystemDeviceStatus:   response.SystemDeviceStatusNormal,
      ClusterStatus:        conf.Conf.SerfClusterStatus,
      ClusterNodeQuantity:  conf.Conf.ClusterNodeQuantity,
      SystemDeviceRunSince: conf.Conf.SystemDeviceRunSince,
   }
   ctx.OkWithDetailed(resp)
}