fix
zhangqian
2023-12-01 8324f872ef3a4d0c978a9b1d062800c6a1701c12
conf/config.go
@@ -4,8 +4,11 @@
   "apsClient/pkg/convertx"
   "apsClient/pkg/logx"
   "apsClient/pkg/sqlitex"
   "apsClient/pkg/timex"
   "apsClient/utils"
   "github.com/spf13/viper"
   "log"
   "time"
)
var (
@@ -58,6 +61,7 @@
   Services struct {
      ApsServer string
      Serial    string
   }
   nsqConf struct {
@@ -66,9 +70,18 @@
      NsqlookupdAddr string
   }
   PLCAddressItem struct {
      FieldName string
      Address   int
   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 {
@@ -87,8 +100,18 @@
      //NsqConf
      NsqConf nsqConf
      //PLC write address
      PLCAddresses []PLCAddressItem
      //PLC
      PLC plc
      Prompt Prompt
      CurrentDeviceID string //设置当前面板控制的设备
      SerfClusterStatus string //集群状态
      ClusterNodeQuantity int //集群节点数量
      SystemDeviceRunSince int64 //系统开始运行时间戳
   }
)
@@ -111,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()
}
@@ -127,6 +166,19 @@
   log.Println("......................................................")
   log.Printf("   System:                %+v", Conf.System)
   log.Printf("   Log:                   %+v", Conf.Log)
   log.Printf("   plc address:                  %+v", Conf.PLCAddresses)
   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()
   }
}