88 lines
2.1 KiB
Go
88 lines
2.1 KiB
Go
package uniss
|
|
|
|
import (
|
|
"dashboard/dao/dadis/unisd"
|
|
"dashboard/models"
|
|
"fmt"
|
|
"net/http"
|
|
"reflect"
|
|
)
|
|
|
|
type commonService struct {
|
|
comm *communicateService
|
|
dataCenter *dataCenterService
|
|
}
|
|
|
|
type communicateWithDataCenter interface {
|
|
getCommunicate() *communicateService
|
|
getDataCenter() *dataCenterService
|
|
}
|
|
|
|
func newcommonService(comm communicateWithDataCenter) *commonService {
|
|
res := new(commonService)
|
|
|
|
res.comm = comm.getCommunicate()
|
|
res.dataCenter = comm.getDataCenter()
|
|
|
|
res.comm.httpServerHandler.Put(string(models.UNIS_HTTP_ID_CONFIG_ADD), res.stationConfig)
|
|
|
|
return res
|
|
}
|
|
|
|
func (c *commonService) stationConfig(reqest *models.UnisHttpRequest, respons *models.UnisHttpResponse) error {
|
|
config := reqest.Msg.(*models.StationConfigParams)
|
|
fmt.Println(config)
|
|
|
|
if !config.StationConfig.ConfigType {
|
|
res, ok := c.dataCenter.dataMap.Get(unisd.DadisKey_UnisStationInfo.KeyWithChannel(0))
|
|
if ok {
|
|
oldCfg := res.(*models.StationConfigParams)
|
|
|
|
oldCfg.StationConfig.ConfigType = config.StationConfig.ConfigType
|
|
if reflect.DeepEqual(config, oldCfg) {
|
|
log.Sugar().Warnf("stationConfig is same")
|
|
|
|
respons.SetResParam(int(models.CodeNotChange), models.CodeNotChange.String(), nil)
|
|
|
|
return nil
|
|
}
|
|
}
|
|
}
|
|
|
|
var addres []*rpcIdAddres
|
|
for _, sc := range config.StationConfig.Screens {
|
|
add := new(rpcIdAddres)
|
|
|
|
add.host = sc.NodeIP
|
|
add.id = sc.NodeID
|
|
|
|
addres = append(addres, add)
|
|
}
|
|
|
|
c.comm.rpcClientStub.flushRpcClients(addres)
|
|
|
|
fmt.Println(c.comm.rpcClientStub.getConfig(addres[0].id, models.UnisRpcRequest{Id: "zhangshuo"}))
|
|
|
|
// res := &models.UnisHttpResponse{
|
|
// Code: int(models.CodeSuccess),
|
|
// Msg: "config ok",
|
|
// }
|
|
respons.SetResParam(int(models.CodeSuccess), "config ok", nil)
|
|
|
|
c.dataCenter.dataMap.Set(unisd.DadisKey_UnisStationInfo.KeyWithChannel(0), config, 0)
|
|
|
|
c.comm.httpClientHandler.curl(http.MethodGet,
|
|
models.UNIS_HTTP_CLIENT_URL_SOURCE_LIST.URI("192.168.177.7", 8080),
|
|
nil,
|
|
func(msg *models.UnisHttpClientRequest) error {
|
|
fmt.Println(msg.Url)
|
|
|
|
if err, ok := msg.Msg.(error); ok {
|
|
fmt.Println(err)
|
|
}
|
|
return nil
|
|
})
|
|
|
|
return nil
|
|
}
|