zhangmeng
2024-01-19 01dfd9dc8de7b19f9dfa4284722e01bbd5837801
deviceCtlApi.go
@@ -1,211 +1,250 @@
package bhomedbapi
import (
   "basic.com/valib/bhshmq.git/proto/source/bhome_msg"
   "encoding/json"
   "basic.com/valib/c_bhomebus.git/proto/source/bhome_msg"
   jsoniter "github.com/json-iterator/go"
)
type DeviceCtlApi struct {
}
func (api DeviceCtlApi) DevAuthApply(paramBody map[string]interface{}) (bool,interface{}) {
func (api DeviceCtlApi) DevAuthApply(targetIp string, fromDevId string, fromIp string, key string) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/devAuth/apply"
   netNode := getNetNode(url2Topic(Topic_System_Service,url))
   dest := &bhome_msg.BHAddress{
      Ip: []byte(targetIp),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil)
   paramBody := map[string]interface{}{
      "key":       key,
      "fromDevId": fromDevId,
      "fromIp":    fromIp,
   }
   body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) DevDetail(paramBody map[string]interface{}) (bool, interface{}) {
func (api DeviceCtlApi) DevDetail(targetIp string, devId string) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/device/detail"
   netNode := getNetNode(url2Topic(Topic_System_Service,url))
   dest := &bhome_msg.BHAddress{
      Ip: []byte(targetIp),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   paramQuery := map[string]string{
      "devId": devId,
   }
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil)
   body, err := client.DoGetRequest(url, paramQuery, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) RemoteCreateCluster(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/cluster/createCluster"
   netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{
   dest := &bhome_msg.BHAddress{
      Ip: []byte(ip),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil)
   body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) RemoteSearchCluster(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/cluster/search"
   netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{
   dest := &bhome_msg.BHAddress{
      Ip: []byte(ip),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil)
   body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) RemoteGetSearchNodes(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/cluster/getSearchNodes"
   netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{
   dest := &bhome_msg.BHAddress{
      Ip: []byte(ip),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil)
   body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) RemoteJoinCluster(devId string, ip string, paramBody map[string]interface{}) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/cluster/joinCluster"
   netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{
   dest := &bhome_msg.BHAddress{
      Ip: []byte(ip),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil)
   body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) RemoteReboot(devId string, ip string) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/sysset/reboot"
   netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{
   dest := &bhome_msg.BHAddress{
      Ip: []byte(ip),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   paramBody := map[string]interface{} {
   }
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, paramBody,nil)
   paramBody := map[string]interface{}{}
   body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, paramBody, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) RemoteUninstall(devId string, ip string, id string) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/sdk/remoteUninstall"
   netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{
   dest := &bhome_msg.BHAddress{
      Ip: []byte(ip),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   paramBody := map[string]interface{} {
   paramBody := map[string]interface{}{
      "id": id,
   }
   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 res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   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 DeviceCtlApi) RemoteSysUpdate(devId string, ip string) (bool, interface{}) {
   url := DATA_URL_PREFIX + "/sysset/remoteSysUpdate"
   netNode := append([]bhome_msg.BHAddress{}, bhome_msg.BHAddress{
   dest := &bhome_msg.BHAddress{
      Ip: []byte(ip),
   }
   netNode := append([]*bhome_msg.MsgQueryTopicReply_BHNodeAddress{}, &bhome_msg.MsgQueryTopicReply_BHNodeAddress{
      Addr: dest,
   })
   client := NewClient(WithNodes(netNode))
   body,err := client.DoPutRequest(url,CONTENT_TYPE_JSON, nil,nil)
   body, err := client.DoPutRequest(url, CONTENT_TYPE_JSON, nil, nil)
   if err != nil {
      return false,nil
      return false, nil
   }
   var res Result
   var json = jsoniter.ConfigCompatibleWithStandardLibrary
   if err = json.Unmarshal(body, &res); err != nil {
      return false,nil
      return false, nil
   }
   return res.Success,res.Data
   return res.Success, res.Data
}