From 4a554a55e9b16b5723d54452d996984990e05efc Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期四, 30 十一月 2023 21:22:22 +0800
Subject: [PATCH] 重构生产进度存储和同步
---
api/v1/device.go | 56 +++++++++++++++++++++++++++++++++++++++++---------------
1 files changed, 41 insertions(+), 15 deletions(-)
diff --git a/api/v1/device.go b/api/v1/device.go
index 02cf81b..5bcb18d 100644
--- a/api/v1/device.go
+++ b/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,37 +48,60 @@
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} "鎴愬姛"
-// @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 {
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