From cacf363f222e354cad6db18c4a00fb1097d35c2c Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 09 十一月 2023 14:30:58 +0800
Subject: [PATCH] fix

---
 api/v1/device.go |   44 +++++++++++++++++++++++++++++++++++++-------
 1 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/api/v1/device.go b/api/v1/device.go
index bfa4622..e2d0385 100644
--- a/api/v1/device.go
+++ b/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)
@@ -56,8 +56,34 @@
 	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 +93,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)
 }

--
Gitblit v1.8.0