terry před 1 měsícem
rodič
revize
459d081ae6
4 změnil soubory, kde provedl 1247 přidání a 441 odebrání
  1. 15 11
      initialize/myData.go
  2. 598 420
      static/data.json
  3. 604 0
      static/data1.json
  4. 30 10
      utils/myTool.go

+ 15 - 11
initialize/myData.go

@@ -61,19 +61,22 @@ func StartInductanceTCP() {
 		logger.Get().Printf("lis Accept conn = %s\n", remoteAddr)
 
 		model.Mutex.Lock()
-		if _, exists := model.ConnectionMap[remoteAddr]; exists {
-			log.Printf("Connection from %s already exists, closing new connection\n", remoteAddr)
+
+		deviceId, err := GetDeviceId(conn)
+		if err != nil {
+			log.Println("Error getting device ID:", err)
 			conn.Close()
 			model.Mutex.Unlock()
 			continue
 		}
-		deviceId, err := GetDeviceId(conn)
-		if err != nil {
-			log.Println("Error getting device ID:", err)
+
+		if _, exists := model.ConnectionMap[deviceId]; exists {
+			log.Printf("Connection from %s already exists, closing new connection\n", remoteAddr)
 			conn.Close()
 			model.Mutex.Unlock()
 			continue
 		}
+
 		model.ConnectionMap[deviceId] = conn
 		model.Mutex.Unlock()
 		//用新的协程处理新的连接
@@ -176,6 +179,7 @@ func parseData(data *model.QueueData) {
 		return
 	}
 	toString := hex.EncodeToString(data.Value)
+	logger.Get().Println(data.Id + "--------" + toString)
 	switch toString[0:2] {
 	case "fe":
 		switch toString[4:8] { // 开关灯
@@ -198,12 +202,12 @@ func parseData(data *model.QueueData) {
 				if device.Sn == data.Id {
 					reg.Devices[i].State = 1
 					reg.Devices[i].OnlineTime = time.Now()
-				}
-				for i2, _ := range device.DeviceLoops {
-					if toString[6:8] == "ff" || toString[6:8] == "0f" {
-						device.DeviceLoops[i2].State = 1
-					} else if toString[6:8] == "00" {
-						device.DeviceLoops[i2].State = 0
+					for i2, _ := range device.DeviceLoops {
+						if toString[6:8] == "ff" || toString[6:8] == "0f" {
+							device.DeviceLoops[i2].State = 1
+						} else if toString[6:8] == "00" {
+							device.DeviceLoops[i2].State = 0
+						}
 					}
 				}
 			}

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 598 - 420
static/data.json


+ 604 - 0
static/data1.json

@@ -0,0 +1,604 @@
+[
+  {
+    "id": 1,
+    "name": "生活区",
+    "subRegion": null,
+    "devices": [
+      {
+        "id": 1,
+        "sn": "JM36xWRZq6PiwmKV",
+        "regionId": 1,
+        "name": "维修车间",
+        "genre": "八回路控制",
+        "state": 0,
+        "isSun": true,
+        "loopNumber": 8,
+        "onlineTime": "2025-01-19T09:43:59.91502361+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路12",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 5,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路5",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 6,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路6",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 7,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路7",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 8,
+            "deviceId": "JM36xWRZq6PiwmKV",
+            "name": "回路8",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "JM36xWRZq6PiwmKV",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      },
+      {
+        "id": 3,
+        "sn": "JM453Sa4a8pdYdgV",
+        "regionId": 1,
+        "name": "洗车房",
+        "genre": "四回路控制",
+        "state": 0,
+        "isSun": false,
+        "loopNumber": 4,
+        "onlineTime": "2025-01-19T09:46:00.028035846+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM453Sa4a8pdYdgV",
+            "name": "回路1",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM453Sa4a8pdYdgV",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM453Sa4a8pdYdgV",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM453Sa4a8pdYdgV",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      },
+      {
+        "id": 2,
+        "sn": "JM45U0zGDCMhgrxc",
+        "regionId": 1,
+        "name": "污泥厂大配电房",
+        "genre": "四回路控制",
+        "state": 0,
+        "isSun": false,
+        "loopNumber": 4,
+        "onlineTime": "2025-01-19T09:46:00.027293637+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM45U0zGDCMhgrxc",
+            "name": "回路1",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM45U0zGDCMhgrxc",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM45U0zGDCMhgrxc",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM45U0zGDCMhgrxc",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      },
+      {
+        "id": 4,
+        "sn": "JM45S67eqnSKueAK",
+        "regionId": 1,
+        "name": "生活区",
+        "genre": "四回路控制",
+        "state": 0,
+        "isSun": false,
+        "loopNumber": 4,
+        "onlineTime": "2025-01-19T09:44:00.051568026+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM45S67eqnSKueAK",
+            "name": "回路1",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM45S67eqnSKueAK",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM45S67eqnSKueAK",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM45S67eqnSKueAK",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      },
+      {
+        "id": 5,
+        "sn": "JM36g0RM0ivegAGK",
+        "regionId": 1,
+        "name": "入厂道路",
+        "genre": "八回路控制",
+        "state": 0,
+        "isSun": false,
+        "loopNumber": 8,
+        "onlineTime": "2025-01-22T15:44:16.9767512+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路1",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 5,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路5",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 6,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路6",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 7,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路7",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 8,
+            "deviceId": "JM36g0RM0ivegAGK",
+            "name": "回路8",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      }
+    ]
+  },
+  {
+    "id": 2,
+    "name": "股份公司进场上坡",
+    "subRegion": null,
+    "devices": [
+      {
+        "id": 1,
+        "sn": "JM45L1V0q2TrA8tn",
+        "regionId": 1,
+        "name": "维修车间",
+        "genre": "八回路控制",
+        "state": 1,
+        "isSun": true,
+        "loopNumber": 8,
+        "onlineTime": "2025-02-10T10:53:59.1019652+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM45L1V0q2TrA8tn",
+            "name": "回路12",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM45L1V0q2TrA8tn",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM45L1V0q2TrA8tn",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM45L1V0q2TrA8tn",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "JM45L1V0q2TrA8tn",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      },
+      {
+        "id": 2,
+        "sn": "JM45uSabL2URuQaD",
+        "regionId": 1,
+        "name": "维修车间",
+        "genre": "八回路控制",
+        "state": 1,
+        "isSun": true,
+        "loopNumber": 4,
+        "onlineTime": "2025-02-10T10:54:00.0122945+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM45uSabL2URuQaD",
+            "name": "回路12",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM45uSabL2URuQaD",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM45uSabL2URuQaD",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM45uSabL2URuQaD",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "JM45uSabL2URuQaD",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      },
+      {
+        "id": 3,
+        "sn": "JM45Xy7KQGyxDhS3",
+        "regionId": 1,
+        "name": "维修车间",
+        "genre": "八回路控制",
+        "state": 1,
+        "isSun": true,
+        "loopNumber": 4,
+        "onlineTime": "2025-02-10T10:54:00.0122945+08:00",
+        "deviceLoops": [
+          {
+            "id": 1,
+            "deviceId": "JM45Xy7KQGyxDhS3",
+            "name": "回路12",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 2,
+            "deviceId": "JM45Xy7KQGyxDhS3",
+            "name": "回路2",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 3,
+            "deviceId": "JM45Xy7KQGyxDhS3",
+            "name": "回路3",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          },
+          {
+            "id": 4,
+            "deviceId": "JM45Xy7KQGyxDhS3",
+            "name": "回路4",
+            "state": 0,
+            "timeCondition1OnTime": "关闭",
+            "timeCondition1OffTime": "关闭",
+            "timeCondition2OnTime": "关闭",
+            "timeCondition2OffTime": "关闭"
+          }
+        ],
+        "sun": {
+          "deviceId": "JM45Xy7KQGyxDhS3",
+          "batteryVoltage": 0,
+          "batteryCurrent": 0,
+          "batteryPlateVoltage": 0
+        }
+      }
+    ]
+  },
+  {
+    "id": 3,
+    "name": "地磅房至污泥厂门口",
+    "subRegion": null,
+    "devices": []
+  },
+  {
+    "id": 4,
+    "name": "三角花园至油库",
+    "subRegion": null,
+    "devices": []
+  },
+  {
+    "id": 5,
+    "name": "地磅房至搅拌站",
+    "subRegion": null,
+    "devices": []
+  },
+  {
+    "id": 6,
+    "name": "搅拌站至三岔路口",
+    "subRegion": null,
+    "devices": []
+  },
+  {
+    "id": 7,
+    "name": "垃圾堆体道路",
+    "subRegion": null,
+    "devices": []
+  },
+  {
+    "id": 8,
+    "name": "污水进场道路",
+    "subRegion": null,
+    "devices": []
+  }
+]

+ 30 - 10
utils/myTool.go

@@ -1,9 +1,10 @@
 package utils
 
 import (
+	"bytes"
 	"encoding/json"
 	"fmt"
-	"io/ioutil"
+	"io"
 	"net"
 	"os"
 	"path/filepath"
@@ -113,44 +114,63 @@ func SaveRegionOnData(data dao.Region) ([]dao.Region, error) {
 
 // SaveData 保存数据到文件
 func SaveData(path string, parameter interface{}) error {
-	// 如果 parameter 是 nil 或者是空的结构体/切片,可以选择不写入文件或返回错误。
+	// 参数验证
 	if parameter == nil {
 		return fmt.Errorf("无法保存 nil 数据")
 	}
 
 	// 序列化数据
-	data, err := json.MarshalIndent(parameter, "", "  ")
+	data, err := json.MarshalIndent(parameter, "", " ")
 	if err != nil {
 		return fmt.Errorf("JSON 序列化失败: %v", err)
 	}
 
 	// 创建临时文件用于原子写入
-	tempFile, err := ioutil.TempFile(filepath.Dir(path), "tmp-")
+	tempFile, err := os.CreateTemp(filepath.Dir(path), "tmp-*.json")
 	if err != nil {
 		return fmt.Errorf("创建临时文件失败: %v", err)
 	}
 	defer os.Remove(tempFile.Name()) // 确保即使出错也能清理临时文件
 
 	// 写入临时文件
-	if _, err := tempFile.Write(data); err != nil {
-		tempFile.Close()
+	if _, err := io.Copy(tempFile, bytes.NewReader(data)); err != nil {
 		return fmt.Errorf("写入临时文件失败: %v", err)
 	}
 
 	// 确保所有数据都写入磁盘
 	if err := tempFile.Sync(); err != nil {
-		tempFile.Close()
 		return fmt.Errorf("同步临时文件失败: %v", err)
 	}
 
-	// 关闭临时文件
+	// 关闭临时文件(这里其实可以省略错误处理,因为defer会确保文件被关闭)
 	if err := tempFile.Close(); err != nil {
-		return fmt.Errorf("关闭临时文件失败: %v", err)
+		// 通常不需要处理这个错误,因为defer已经确保了关闭操作
+		// 但如果你想记录这个错误,可以在这里做
 	}
 
 	// 使用原子操作替换原始文件
 	if err := os.Rename(tempFile.Name(), path); err != nil {
-		return fmt.Errorf("替换文件失败: %v", err)
+		// 将结构体转换为JSON字节切片
+		jsonBytes, err := json.Marshal(parameter)
+		if err != nil {
+			return fmt.Errorf("Error marshalling to JSON: %v\n", err)
+		}
+
+		// 将字节切片转换为字符串
+		jsonString := string(jsonBytes)
+		// 打开或创建文件,并设置标志以覆盖原有内容
+		file, err := os.OpenFile("output.txt", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
+		if err != nil {
+			fmt.Printf("无法打开或创建文件: %v\n", err)
+		}
+		defer file.Close() // 确保在main函数结束时关闭文件
+
+		// 写入数据到文件
+		_, err = file.WriteString(string(jsonString))
+		if err != nil {
+			fmt.Printf("写入文件失败: %v\n", err)
+		}
+		//return fmt.Errorf("替换文件失败,直接写入: %v", err)
 	}
 
 	return nil