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

---
 service/problem/check.go |   48 ++++++++++++++++++++++++++++++++++++++----------
 1 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/service/problem/check.go b/service/problem/check.go
index d472858..17a8e89 100644
--- a/service/problem/check.go
+++ b/service/problem/check.go
@@ -3,9 +3,11 @@
 import (
 	"apsClient/conf"
 	"apsClient/constvar"
+	"apsClient/model"
 	"apsClient/pkg/sqlitex"
 	"apsClient/service"
-	"apsClient/service/plc_address"
+	"fmt"
+	"net"
 	"sync"
 )
 
@@ -14,9 +16,8 @@
 	constvar.ProblemCodeNetwork,
 	constvar.ProblemCodeDB,
 	constvar.ProblemCodeSerf,
-	constvar.ProblemCodeNsq,
+	constvar.ProblemCodeCloud,
 	constvar.ProblemCodeDevice,
-	constvar.ProblemCodeProcessModel,
 	constvar.ProblemCodePlcConfig,
 	constvar.ProblemCodePlcAddressList,
 	constvar.ProblemCodePlcProcessModelAddressList,
@@ -27,9 +28,8 @@
 	constvar.ProblemCodeNetwork:                    "缃戠粶杩炴帴",
 	constvar.ProblemCodeDB:                         "鏁版嵁搴�",
 	constvar.ProblemCodeSerf:                       "serf闆嗙兢",
-	constvar.ProblemCodeNsq:                        "娑堟伅闃熷垪",
+	constvar.ProblemCodeCloud:                      "娑堟伅闃熷垪",
 	constvar.ProblemCodeDevice:                     "鐢熶骇璁惧缁戝畾",
-	constvar.ProblemCodeProcessModel:               "宸ヨ壓鍙傛暟",
 	constvar.ProblemCodePlcConfig:                  "plc閰嶇疆",
 	constvar.ProblemCodePlcAddressList:             "plc鍦板潃琛�",
 	constvar.ProblemCodePlcProcessModelAddressList: "plc宸ヨ壓鍙傛暟鍦板潃琛�",
@@ -58,7 +58,7 @@
 			checkObj = &DB{}
 		case constvar.ProblemCodeSerf:
 			checkObj = &Serf{}
-		case constvar.ProblemCodeNsq:
+		case constvar.ProblemCodeCloud:
 			checkObj = &Nsq{}
 		case constvar.ProblemCodeDevice:
 			checkObj = &Device{}
@@ -70,6 +70,8 @@
 			checkObj = &PlcProcessModelAddressList{}
 		case constvar.ProblemCodePlcConnect:
 			checkObj = &PlcConnect{}
+		default:
+			continue
 		}
 		checkResultListTemp = append(checkResultListTemp, &CheckResult{
 			ItemCode:    item,
@@ -103,7 +105,19 @@
 type Network struct{}
 
 func (slf *Network) Check() bool {
-	return false
+	ifaces, err := net.Interfaces()
+	if err != nil {
+		fmt.Println("Error:", err)
+		return false
+	}
+	var netAllFailed bool
+	for _, iFace := range ifaces {
+		if iFace.Flags == net.FlagUp {
+			netAllFailed = false
+			fmt.Printf("Interface %s is DOWN, indicating a network issue.\n", iFace.Name)
+		}
+	}
+	return !netAllFailed
 }
 
 type DB struct{}
@@ -125,7 +139,11 @@
 type Nsq struct{}
 
 func (slf *Nsq) Check() bool {
-	return false
+	old, err := model.NewSystemStatusSearch().SetKey(constvar.SystemStatusKeyNsq).First()
+	if err != nil {
+		return false
+	}
+	return old.Value == constvar.SystemStatusValueNormal
 }
 
 type Device struct{}
@@ -149,6 +167,9 @@
 
 func (slf *PlcConfig) Check() bool {
 	plcConfig, _ := service.NewDevicePlcService().GetDevicePlc()
+	if plcConfig == nil {
+		return false
+	}
 	if plcConfig.Method == "" {
 		return false
 	}
@@ -169,13 +190,20 @@
 
 func (slf *PlcAddressList) Check() bool {
 	plcConfig, _ := service.NewDevicePlcService().GetDevicePlc()
-	return len(plcConfig.Details) > 0
+	return plcConfig != nil && len(plcConfig.Details) > 0
 }
 
 type PlcProcessModelAddressList struct{}
 
 func (slf *PlcProcessModelAddressList) Check() bool {
-	return plc_address.IsLoad()
+	record, err := model.NewProcessModelPlcAddressSearch().SetDeviceID(conf.Conf.CurrentDeviceID).First()
+	if err != nil {
+		return false
+	}
+	if len(record.AddressList) == 0 {
+		return false
+	}
+	return true
 }
 
 type PlcConnect struct{}

--
Gitblit v1.8.0