| | |
| | | |
| | | import ( |
| | | "apsClient/conf" |
| | | "apsClient/constvar" |
| | | "apsClient/crontask" |
| | | "apsClient/model/request" |
| | | "apsClient/model/response" |
| | | _ "apsClient/model/response" |
| | |
| | | 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 { |
| | |
| | | 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, ¶ms) |
| | | 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} "成功" |
| | |
| | | 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) |
| | | } |