zhangqian
2023-11-09 02a84fb6fb2a39bfe7fc5cf6c0137bbf231b17fe
api/v1/device.go
@@ -29,7 +29,7 @@
   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)
@@ -53,6 +53,32 @@
      return
   }
   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()
}
@@ -67,7 +93,7 @@
   if !ok {
      return
   }
   list, err := service.GetDeviceIDList()
   list, err := service.GetDeviceList()
   if err != nil {
      ctx.Fail(ecode.DBErr)
      return
@@ -75,7 +101,7 @@
   resp := response.DeviceListResponse{
      SystemDeviceID:       conf.Conf.System.DeviceId,
      CurrentDeviceID:      conf.Conf.CurrentDeviceID,
      DeviceIDList:         list,
      DeviceList:           list,
      SystemDeviceStatus:   response.SystemDeviceStatusNormal,
      ClusterStatus:        conf.Conf.SerfClusterStatus,
      ClusterNodeQuantity:  conf.Conf.ClusterNodeQuantity,