From 01dfd9dc8de7b19f9dfa4284722e01bbd5837801 Mon Sep 17 00:00:00 2001
From: zhangmeng <775834166@qq.com>
Date: 星期五, 19 一月 2024 09:10:30 +0800
Subject: [PATCH] replace json to json-iterator

---
 syssetApi.go |  329 +++++++++++++++++-------------------------------------
 1 files changed, 107 insertions(+), 222 deletions(-)

diff --git a/syssetApi.go b/syssetApi.go
index 236e5dc..e022bb1 100644
--- a/syssetApi.go
+++ b/syssetApi.go
@@ -1,21 +1,18 @@
-package dbapi
+package bhomedbapi
 
 import (
 	"basic.com/pubsub/protomsg.git"
-	"encoding/json"
+	"basic.com/valib/c_bhomebus.git/proto/source/bhome_msg"
+	jsoniter "github.com/json-iterator/go"
 )
 
 type SysSetApi struct {
-
 }
 
 //鑾峰彇鏈嶅姟鍣ㄦ湰鏈洪厤缃俊鎭�
-func (api SysSetApi) GetServerInfo() (flag bool,sysconf protomsg.LocalConfig){
+func (api SysSetApi) GetServerInfo() (flag bool, sysconf protomsg.LocalConfig) {
 	url := DATA_URL_PREFIX + "/sysset/getServerInfo"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,sysconf
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, nil, nil)
@@ -23,174 +20,46 @@
 		return false, sysconf
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, sysconf
 	}
 
 	b, err := json.Marshal(res.Data)
-	if err !=nil {
-		return false,sysconf
+	if err != nil {
+		return false, sysconf
 	} else {
 		err = json.Unmarshal(b, &sysconf)
-		if err !=nil {
-			return false,sysconf
+		if err != nil {
+			return false, sysconf
 		} else {
-			return true,sysconf
-		}
-	}
-}
-//淇濆瓨杞閰嶇疆
-func (api SysSetApi) SavePollPeriod(period int) (bool,interface{}){
-	url := DATA_URL_PREFIX + "/pollConfig/savePollPeriod"
-	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
-	client := NewClient(WithNodes(netNode))
-	paramBody := make(map[string]interface{},0)
-	paramBody["period"] = period
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_FORM, paramBody,nil,nil)
-	if err != nil {
-		return false,nil
-	}
-
-	var res Result
-	if err = json.Unmarshal(body, &res); err != nil {
-		logPrint(err)
-		return false,nil
-	}
-
-	return res.Success,res.Data
-}
-
-func (api SysSetApi) SavePollDelay(delay int) (bool,interface{}){
-	url := DATA_URL_PREFIX + "/pollConfig/savePollDelay"
-	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
-	client := NewClient(WithNodes(netNode))
-	paramBody := make(map[string]interface{},0)
-	paramBody["delay"] = delay
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_FORM, paramBody,nil,nil)
-	if err != nil {
-		return false,nil
-	}
-
-	var res Result
-	if err = json.Unmarshal(body, &res); err != nil {
-		logPrint(err)
-		return false,nil
-	}
-
-	return res.Success,res.Data
-}
-
-//鑾峰彇杞閰嶇疆
-func (api SysSetApi) GetPollConfig() (flag bool,config protomsg.PollConfig) {
-	url := DATA_URL_PREFIX + "/pollConfig/getPollConfig"
-	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,config
-	}
-	client := NewClient(WithNodes(netNode))
-
-	body, err := client.DoGetRequest(url, nil, nil)
-	if err != nil {
-		return false, config
-	}
-
-	var res Result
-	if err = json.Unmarshal(body, &res); err != nil {
-		return false, config
-	}
-
-	b, err := json.Marshal(res.Data)
-	if err !=nil {
-		return false,config
-	} else {
-		err = json.Unmarshal(b, &config)
-		if err !=nil {
-			return false,config
-		} else {
-			return true,config
+			return true, sysconf
 		}
 	}
 }
 
-//鍒囨崲杞鏄惁寮�鍚拰鍏抽棴
-func (api SysSetApi) UpdatePollEnable(enable bool) bool{
-	url := DATA_URL_PREFIX + "/pollConfig/updateEnable"
-	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false
-	}
-	client := NewClient(WithNodes(netNode))
-	paramBody :=make(map[string]interface{},0)
-	paramBody["enable"] = enable
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
-	if err != nil {
-		return false
-	}
-
-	var res Result
-	if err = json.Unmarshal(body, &res); err != nil {
-		return false
-	}
-
-	return res.Success
-}
-
-func (api SysSetApi) UpdateChannelCount(pollChannelCount int, videoChannelCount int) bool{
-	url := DATA_URL_PREFIX + "/pollConfig/updateChannelCount"
-	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false
-	}
-	client := NewClient(WithNodes(netNode))
-	paramBody :=make(map[string]interface{},0)
-	paramBody["pollChannelCount"] = pollChannelCount
-	paramBody["videoChannelCount"] = videoChannelCount
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
-	if err != nil {
-		return false
-	}
-
-	var res Result
-	if err = json.Unmarshal(body, &res); err != nil {
-		return false
-	}
-
-	return res.Success
-}
-
-func (api SysSetApi) AlarmEdit(paramBody map[string]interface{}) (bool,interface{}){
+func (api SysSetApi) AlarmEdit(paramBody map[string]interface{}) (bool, interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/alarmEdit"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) VideoLenShow() (bool,interface{}){
+func (api SysSetApi) VideoLenShow() (bool, interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/videoLenShow"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, nil, nil)
@@ -198,62 +67,56 @@
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) VideoLenEdit(maxVideoLen string,minVideoLen string) (bool,interface{}){
+func (api SysSetApi) VideoLenEdit(maxVideoLen string, minVideoLen string) (bool, interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/videoLenEdit"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
-	paramBody :=make(map[string]interface{},0)
+	paramBody := make(map[string]interface{}, 0)
 	paramBody["max_video_len"] = maxVideoLen
 	paramBody["min_video_len"] = minVideoLen
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_FORM, paramBody,nil,nil)
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) SaveServerInfo(paramBody map[string]interface{}) (bool,interface{}){
+func (api SysSetApi) SaveServerInfo(paramBody map[string]interface{}) (bool, interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/saveServerInfo"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_FORM, paramBody,nil,nil)
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_FORM, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) Gb28181ConfigShow() (bool,interface{}){
+func (api SysSetApi) Gb28181ConfigShow() (bool, interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/gb28181ConfigShow"
 	netNode := getNetNode(url2Topic(Topic_Gb28181_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, nil, nil)
@@ -261,40 +124,35 @@
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) Gb28181ConfigEdit(paramBody map[string]interface{}) (bool,interface{}){
+func (api SysSetApi) Gb28181ConfigEdit(paramBody map[string]interface{}) (bool, interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/gb28181ConfigEdit"
 	netNode := getNetNode(url2Topic(Topic_Gb28181_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
-	body,err := client.DoPostRequest(url,CONTENT_TYPE_JSON, paramBody,nil,nil)
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil)
 	if err != nil {
-		return false,nil
+		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
-		return false,nil
+		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-
-func (api SysSetApi) GetRemoteFullServerInfo(headers map[string]string) (flag bool,d interface{}){
+func (api SysSetApi) GetRemoteFullServerInfo(headers map[string]string) (flag bool, d interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/getDevInfo"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, nil, headers)
@@ -302,20 +160,18 @@
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) GetClockInfo(headers map[string]string) (flag bool,d interface{}){
+func (api SysSetApi) GetClockInfo(headers map[string]string) (flag bool, d interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/clockInfo"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, nil, headers)
@@ -323,20 +179,18 @@
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) TestNTPServer(query map[string]string,headers map[string]string) (flag bool,d interface{}){
+func (api SysSetApi) TestNTPServer(query map[string]string, headers map[string]string) (flag bool, d interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/ntpTest"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, query, headers)
@@ -344,41 +198,37 @@
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) SetSysClock(paramBody map[string]interface{},headers map[string]string) (flag bool,d interface{}){
+func (api SysSetApi) SetSysClock(paramBody map[string]interface{}, headers map[string]string) (flag bool, d interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/updateClock"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
-	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON,paramBody,nil, headers)
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, headers)
 	if err != nil {
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) GetSysInfo(headers map[string]string) (flag bool,d interface{}){
+func (api SysSetApi) GetSysInfo(headers map[string]string) (flag bool, d interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/sysinfo"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, nil, headers)
@@ -386,20 +236,18 @@
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
 
-	return res.Success,res.Data
+	return res.Success, res.Data
 }
 
-func (api SysSetApi) GetResourceConfig() (flag bool,rc protomsg.ResourceConfig){
+func (api SysSetApi) GetResourceConfig() (flag bool, rc protomsg.ResourceConfig) {
 	url := DATA_URL_PREFIX + "/sysset/getResourceConfig"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false, rc
-	}
 	client := NewClient(WithNodes(netNode))
 
 	body, err := client.DoGetRequest(url, nil, nil)
@@ -407,40 +255,77 @@
 		return false, rc
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, rc
 	}
 	b, err := json.Marshal(res.Data)
-	if err !=nil {
-		return false,rc
+	if err != nil {
+		return false, rc
 	} else {
 		err = json.Unmarshal(b, &rc)
-		if err !=nil {
-			return false,rc
+		if err != nil {
+			return false, rc
 		} else {
-			return true,rc
+			return true, rc
 		}
 	}
 }
 
-func (api SysSetApi) SaveResourceConfig(paramBody map[string]interface{}) (flag bool,d interface{}){
+func (api SysSetApi) SaveResourceConfig(paramBody map[string]interface{}) (flag bool, d interface{}) {
 	url := DATA_URL_PREFIX + "/sysset/saveResourceConfig"
 	netNode := getNetNode(url2Topic(Topic_System_Service, url))
-	if netNode == nil {
-		return false,nil
-	}
 	client := NewClient(WithNodes(netNode))
 
-	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON,paramBody,nil, nil)
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil)
 	if err != nil {
 		return false, nil
 	}
 
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
 	var res Result
 	if err = json.Unmarshal(body, &res); err != nil {
 		return false, nil
 	}
 
-	return res.Success,res.Data
-}
\ No newline at end of file
+	return res.Success, res.Data
+}
+
+//鎺у埗鏈満reboot
+func (api SysSetApi) RebootOS() (bool, interface{}) {
+	url := DATA_URL_PREFIX + "/sysset/reboot"
+	netNode := getNetNode(url2Topic(Topic_System_Service, url))
+	client := NewClient(WithNodes(netNode))
+
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, nil, nil, nil)
+	if err != nil {
+		return false, nil
+	}
+
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
+	var res Result
+	if err = json.Unmarshal(body, &res); err != nil {
+		return false, nil
+	}
+
+	return res.Success, res.Data
+}
+
+func (api SysSetApi) SyncDevToManager(addr []*bhome_msg.MsgQueryTopicReply_BHNodeAddress, paramBody map[string]interface{}) (bool, interface{}) {
+	url := DATA_URL_PREFIX + "/device/syncDevToManager"
+	client := NewClient(WithNodes(addr))
+
+	body, err := client.DoPostRequest(url, CONTENT_TYPE_JSON, paramBody, nil, nil)
+	if err != nil {
+		return false, nil
+	}
+
+	var json = jsoniter.ConfigCompatibleWithStandardLibrary
+	var res Result
+	if err = json.Unmarshal(body, &res); err != nil {
+		return false, nil
+	}
+
+	return res.Success, res.Data
+}

--
Gitblit v1.8.0