From 8324f872ef3a4d0c978a9b1d062800c6a1701c12 Mon Sep 17 00:00:00 2001
From: zhangqian <zhangqian@123.com>
Date: 星期五, 01 十二月 2023 09:58:17 +0800
Subject: [PATCH] fix

---
 conf/config.go |  108 ++++++++++++++++++++++++++++++++++--------------------
 1 files changed, 68 insertions(+), 40 deletions(-)

diff --git a/conf/config.go b/conf/config.go
index 5af1d43..53632ae 100644
--- a/conf/config.go
+++ b/conf/config.go
@@ -3,12 +3,12 @@
 import (
 	"apsClient/pkg/convertx"
 	"apsClient/pkg/logx"
-	"apsClient/pkg/mysqlx"
-	"apsClient/pkg/redisx"
 	"apsClient/pkg/sqlitex"
-	"flag"
+	"apsClient/pkg/timex"
+	"apsClient/utils"
 	"github.com/spf13/viper"
 	"log"
+	"time"
 )
 
 var (
@@ -25,16 +25,12 @@
 
 type (
 	System struct {
-		Env           string // 鐜鍊� develop test public
-		Port          int    // 绔彛
-		DbType        string // 鏁版嵁搴撶被鍨�
-		UseMultipoint bool   // 澶氱偣鐧诲綍鎷︽埅
-		UseRedis      bool   // 浣跨敤redis
-		LimitCountIP  int
-		LimitTimeIP   int
-		RouterPrefix  string // 璺敱鍓嶇紑
-		SudoPassword  string // sudo瀵嗙爜
-		DeviceId      string //璁惧id
+		Env              string // 鐜鍊� develop test public
+		Port             int    // 绔彛
+		DeviceId         string //璁惧id
+		NetSetShellPath  string //缃戠粶璁剧疆鑴氭湰璺緞
+		NetUpShellName   string //缃戠粶鍋滅敤鑴氭湰
+		NetDownShellName string //缃戠粶寮�鍚剼鏈�
 	}
 
 	Etcd struct {
@@ -65,12 +61,27 @@
 
 	Services struct {
 		ApsServer string
+		Serial    string
 	}
 
 	nsqConf struct {
 		NodeId         string
 		NsqdAddr       string
 		NsqlookupdAddr string
+	}
+
+	plc struct {
+		FinishNumberTimeInterval int
+		TotalNumberTimeInterval  int
+		ModbusIntType            string
+		SlaveId                  int
+		Package                  string
+		StandbyTime              int64
+	}
+
+	Prompt struct {
+		SafeProduce     string `json:"safeProduce,omitempty"`
+		PlcNotConnected string `json:"plcNotConnected,omitempty"`
 	}
 
 	config struct {
@@ -81,27 +92,26 @@
 		Log logx.Conf
 
 		// mysql閰嶇疆
-		Mysql mysqlx.Conf
-
-		// mysql閰嶇疆
 		Sqlite sqlitex.Conf
-
-		// redis閰嶇疆
-		Redis redisx.Conf
-
-		// etcd閰嶇疆
-		Etcd Etcd
-
-		// rancher閰嶇疆
-		Rancher Rancher
-
-		// k8s閰嶇疆
-		K8s K8s
 
 		//Services Address
 		Services Services
 
+		//NsqConf
 		NsqConf nsqConf
+
+		//PLC
+		PLC plc
+
+		Prompt Prompt
+
+		CurrentDeviceID string //璁剧疆褰撳墠闈㈡澘鎺у埗鐨勮澶�
+
+		SerfClusterStatus string //闆嗙兢鐘舵��
+
+		ClusterNodeQuantity int //闆嗙兢鑺傜偣鏁伴噺
+
+		SystemDeviceRunSince int64 //绯荤粺寮�濮嬭繍琛屾椂闂存埑
 	}
 )
 
@@ -111,14 +121,6 @@
 )
 
 func init() {
-	var configFile string
-	flag.StringVar(&configFile, "config", "", "config file in json")
-	flag.Parse()
-
-	if len(configFile) > 0 {
-		configName = configFile
-	}
-
 	Viper = viper.New()
 	Viper.SetConfigName(configName)
 	for _, path := range configPaths {
@@ -132,6 +134,22 @@
 	if err := Viper.Unmarshal(&Conf); err != nil {
 		log.Fatalf("Unmarshal err:%v", err)
 	}
+	if Conf.PLC.StandbyTime == 0 {
+		Conf.PLC.StandbyTime = 300 //5鍒嗛挓
+	}
+
+	uptimeStr, err := utils.Exec("uptime -s")
+	if err == nil {
+		t, err := timex.StringToTime(uptimeStr)
+		if err == nil {
+			Conf.SystemDeviceRunSince = t.Unix()
+		}
+	} else {
+		Conf.SystemDeviceRunSince = time.Now().Unix()
+	}
+
+	SetUpTime()
+
 	ShowConfig()
 }
 
@@ -148,9 +166,19 @@
 	log.Println("......................................................")
 	log.Printf("   System:                %+v", Conf.System)
 	log.Printf("   Log:                   %+v", Conf.Log)
-	log.Printf("   Mysql:                 %+v", Conf.Mysql)
-	log.Printf("   etcd:                  %+v", Conf.Etcd)
-	log.Printf("   rancher:               %+v", Conf.Rancher)
-	log.Printf("   k8s:                   %+v", Conf.K8s)
+	log.Printf("   plc :                  %+v", Conf.PLC)
+	log.Printf("   services :                  %+v", Conf.Services)
 	log.Println("......................................................")
 }
+
+func SetUpTime() {
+	uptimeStr, err := utils.Exec("uptime -s")
+	if err == nil {
+		t, err := timex.StringToTime(uptimeStr)
+		if err == nil {
+			Conf.SystemDeviceRunSince = t.Unix()
+		}
+	} else {
+		Conf.SystemDeviceRunSince = time.Now().Unix()
+	}
+}

--
Gitblit v1.8.0