From b331c9990a0396301e934daffe095f99d62d1c89 Mon Sep 17 00:00:00 2001 From: zhangqian <zhangqian@123.com> Date: 星期三, 27 九月 2023 15:58:49 +0800 Subject: [PATCH] 任务获取修改,状态2只返回已开始和已结束的 --- api/v1/config.go | 40 +++++++++++++++++++++++++++++++++++++--- 1 files changed, 37 insertions(+), 3 deletions(-) diff --git a/api/v1/config.go b/api/v1/config.go index 43065ad..2e94285 100644 --- a/api/v1/config.go +++ b/api/v1/config.go @@ -1,6 +1,8 @@ package v1 import ( + "apsClient/conf" + "apsClient/constvar" "apsClient/model" "apsClient/model/request" _ "apsClient/model/response" @@ -8,6 +10,8 @@ "apsClient/pkg/ecode" "apsClient/pkg/logx" "apsClient/service" + "apsClient/utils" + "fmt" "github.com/gin-gonic/gin" ) @@ -28,7 +32,7 @@ ConfigData, err := service.NewConfigService().GetNetConfigList() if err != nil { logx.Errorf("get net config error: %v", err.Error()) - ctx.FailWithMsg(ecode.UnknownErr, "鑾峰彇缃戠粶閰嶇疆澶辫触") + ctx.FailWithMsg(ecode.DBErr, "鑾峰彇缃戠粶閰嶇疆澶辫触") return } @@ -53,14 +57,30 @@ if err != nil { logx.Errorf("get net config error: %v", err.Error()) - ctx.FailWithMsg(ecode.UnknownErr, "鑾峰彇缃戠粶閰嶇疆澶辫触") + ctx.FailWithMsg(ecode.DBErr, "鑾峰彇缃戠粶閰嶇疆澶辫触") return } - err = service.NewConfigService().SetNetConfig(params.Id, ¶ms) if err != nil { logx.Errorf("SetNetConfig error: %v", err.Error()) ctx.FailWithMsg(ecode.DBErr, "璁剧疆澶辫触") + return + } + if conf.Conf.System.NetSetShellPath == "" || conf.Conf.System.NetUpShellName == "" || conf.Conf.System.NetDownShellName == "" { + ctx.FailWithMsg(ecode.DBErr, "璇峰厛閰嶇疆缃戠粶璁剧疆璺緞鍜岃剼鏈悕") + return + } + var shName string + if params.Status == model.NetConfigStatusEnabled { + shName = conf.Conf.System.NetUpShellName + } else { + shName = conf.Conf.System.NetDownShellName + } + sh := fmt.Sprintf("%s %v %v %v %v", shName, params.NetworkCard, params.IP, params.MASK, params.Gateway) + err = utils.Cmd(conf.Conf.System.NetSetShellPath + sh) + if err != nil { + logx.Errorf("network update failed: %v", err.Error()) + ctx.FailWithMsg(ecode.UnknownErr, "缃戠粶璁剧疆澶辫触") return } ctx.Ok() @@ -100,6 +120,20 @@ return } + if !params.Method.Valid() { + ctx.FailWithMsg(ecode.ParamsErr, "鎺ュ彛鏂瑰紡涓嶆纭�") + return + } + + if params.Method == constvar.PlcMethodModbusTCP && (params.Address == "" || params.Port == 0) { + ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负modbusTCP鏃讹紝address鍜宲ort涓嶈兘涓虹┖") + return + } + if params.Method == constvar.PlcMethodSerial && (params.BaudRate == 0 || params.SerialName == "") { + ctx.FailWithMsg(ecode.ParamsErr, "褰撴帴鍙f柟寮忎负serial鏃讹紝baudRate鍜宻erialName涓嶈兘涓虹┖") + return + } + errCode := service.NewDevicePlcService().UpdateDevicePlc(¶ms) if errCode != ecode.OK { ctx.Fail(errCode) -- Gitblit v1.8.0