102 lines
3.0 KiB
Go
102 lines
3.0 KiB
Go
package unis
|
|
|
|
import (
|
|
"bytes"
|
|
"dashboard/dao/sqldb"
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
"net/http"
|
|
"reflect"
|
|
"strconv"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type StationConfigParams struct {
|
|
StationConfig UnisConfig `json:"stationConfig,omitempty"`
|
|
}
|
|
type Screens struct {
|
|
ScreenIndex int `json:"screenIndex,omitempty"`
|
|
Mode int `json:"mode,omitempty"`
|
|
PhysicalX int `json:"physicalX,omitempty"`
|
|
PhysicalY int `json:"physicalY,omitempty"`
|
|
PhysicalWidth int `json:"physicalWidth,omitempty"`
|
|
PhysicalHeight int `json:"physicalHeight,omitempty"`
|
|
LogicX int `json:"logicX,omitempty"`
|
|
LogicY int `json:"logicY,omitempty"`
|
|
LogicWidth int `json:"logicWidth,omitempty"`
|
|
LogicHeight int `json:"logicHeight,omitempty"`
|
|
LogicFrameRate int `json:"logicFrameRate,omitempty"`
|
|
Channel int `json:"channel,omitempty"`
|
|
McType int `json:"mcType,omitempty"`
|
|
SupportChannel int `json:"supportChannel,omitempty"`
|
|
Primary bool `json:"primary,omitempty"`
|
|
NodeID string `json:"nodeId,omitempty"`
|
|
NodeIP string `json:"nodeIp,omitempty"`
|
|
FpgaID string `json:"fpgaId,omitempty"`
|
|
SupportHighestTiming string `json:"supportHighestTiming,omitempty"`
|
|
UnisCapability string `json:"unisCapability,omitempty"`
|
|
}
|
|
type UnisConfig struct {
|
|
ID string `json:"id,omitempty"`
|
|
Name string `json:"name,omitempty"`
|
|
RowCount int `json:"rowCount,omitempty"`
|
|
ColCount int `json:"colCount,omitempty"`
|
|
ScreenNum int `json:"screenNum,omitempty"`
|
|
WallWidth int `json:"wallWidth,omitempty"`
|
|
WallHeight int `json:"wallHeight,omitempty"`
|
|
ReceiveIndex int `json:"receiveIndex,omitempty"`
|
|
PrimaryIndex int `json:"primaryIndex,omitempty"`
|
|
ConfigType bool `json:"configType,omitempty"`
|
|
Screens []Screens `json:"screens,omitempty"`
|
|
}
|
|
|
|
func StationConfig(c *gin.Context) error {
|
|
var config StationConfigParams
|
|
|
|
bodyBytes, err := io.ReadAll(c.Request.Body)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
c.Request.Body = io.NopCloser(bytes.NewBuffer(bodyBytes))
|
|
|
|
if err := c.ShouldBindJSON(&config); err != nil {
|
|
return err
|
|
}
|
|
|
|
// serverId := c.GetHeader("serverId")
|
|
channelStr := c.GetHeader("channel")
|
|
channel, err := strconv.Atoi(channelStr)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
oldConf, err := sqldb.ResDataGet("stationconfig", channel)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
|
|
var oldconfig StationConfigParams
|
|
if oldConf != "" {
|
|
if err := json.Unmarshal([]byte(oldConf), &oldconfig); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
config.StationConfig.ConfigType = false
|
|
oldconfig.StationConfig.ConfigType = false
|
|
|
|
if !reflect.DeepEqual(config, oldconfig) {
|
|
fmt.Println("config is not equal")
|
|
if err := sqldb.ResDataStore("stationconfig", string(bodyBytes), channel); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
c.String(http.StatusOK, "ok")
|
|
|
|
return nil
|
|
}
|