diff --git a/constant/attrs_key.go b/constant/attrs_key.go new file mode 100644 index 0000000..26206fe --- /dev/null +++ b/constant/attrs_key.go @@ -0,0 +1,9 @@ +// Package constants define constant variable +package constants + +const ( + // ShortAttrKeyLenth define short attribute key length + ShortAttrKeyLenth int = 4 + // LongAttrKeyLenth define long attribute key length + LongAttrKeyLenth int = 7 +) diff --git a/model/attribute_model.go b/model/attribute_model.go new file mode 100644 index 0000000..853d718 --- /dev/null +++ b/model/attribute_model.go @@ -0,0 +1,23 @@ +// Package model define model struct of model runtime service +package model + +import "modelRT/orm" + +// AttrModelInterface define basic attr model type interface +type AttrModelInterface interface { + GetGridInfo() *orm.Grid + GetZoneInfo() *orm.Zone + GetStationInfo() *orm.Station + GetComponentInfo() *orm.Component + IsLocal() bool +} + +// LongAttrInfo structure define long attribute key info of component +type LongAttrInfo struct { + AttrKey string `json:"attr_key"` +} + +// ShortAttrInfo structure define short attribute key info of component +type ShortAttrInfo struct { + AttrKey string `json:"attr_key"` +} diff --git a/orm/circuit_diagram_component.go b/orm/circuit_diagram_component.go index e2062b1..bccc7e5 100644 --- a/orm/circuit_diagram_component.go +++ b/orm/circuit_diagram_component.go @@ -9,21 +9,32 @@ import ( // Component structure define abstracted info set of electrical component type Component struct { - ID int64 `gorm:"column:id;primaryKey"` - GlobalUUID uuid.UUID `gorm:"column:global_uuid"` - Tag string `gorm:"column:tag"` - GridID string `gorm:"column:grid"` - ZoneID string `gorm:"column:zone"` - StationID string `gorm:"column:station"` - PageID int64 `gorm:"column:page_id"` - ComponentType int `gorm:"column:type"` - Name string `gorm:"column:name"` - Context string `gorm:"column:context"` - Op int `gorm:"column:op"` - Ts time.Time `gorm:"column:ts"` + GlobalUUID uuid.UUID `gorm:"column:GLOBAL_UUID;primaryKey"` + NsPath string `gorm:"column:NSPATH"` + Tag string `gorm:"column:TAG"` + Name string `gorm:"column:NAME"` + ModelName string `gorm:"column:MODEL_NAME"` + Description string `gorm:"column:DESCRIPTION"` + GridID string `gorm:"column:GRID"` + ZoneID string `gorm:"column:ZONE"` + StationID string `gorm:"column:STATION"` + Type int `gorm:"column:TYPE"` + InService bool `gorm:"column:IN_SERVICE"` + State int `gorm:"column:STATE"` + Status int `gorm:"column:STATUS"` + Connection map[string]interface{} `gorm:"column:CONNECTION;type:jsonb;default:'{}'"` + Label map[string]interface{} `gorm:"column:LABEL;type:jsonb;default:'{}'"` + Context string `gorm:"column:CONTEXT"` + Op int `gorm:"column:OP"` + Ts time.Time `gorm:"column:TS"` + + // TODO 解决删除ID、ComponentType、PageID后的报错 + ID int64 `gorm:"column:id;primaryKey"` + PageID int64 `gorm:"column:page_id"` + ComponentType int `gorm:"column:TYPE"` } // TableName func respresent return table name of Component func (c *Component) TableName() string { - return "component" + return "COMPONENT" } diff --git a/orm/circuit_diagram_grid.go b/orm/circuit_diagram_grid.go new file mode 100644 index 0000000..311815e --- /dev/null +++ b/orm/circuit_diagram_grid.go @@ -0,0 +1,20 @@ +// Package orm define database data struct +package orm + +import ( + "time" +) + +// Grid structure define abstracted info set of electrical grid +type Grid struct { + ID int64 `gorm:"column:ID;primaryKey"` + Name string `gorm:"column:NAME"` + Description string `gorm:"column:DESCRIPTION"` + Op int `gorm:"column:OP"` + Ts time.Time `gorm:"column:TS"` +} + +// TableName func respresent return table name of Grid +func (g *Grid) TableName() string { + return "GRID" +} diff --git a/orm/circuit_diagram_station.go b/orm/circuit_diagram_station.go new file mode 100644 index 0000000..575ef23 --- /dev/null +++ b/orm/circuit_diagram_station.go @@ -0,0 +1,22 @@ +// Package orm define database data struct +package orm + +import ( + "time" +) + +// Station structure define abstracted info set of electrical Station +type Station struct { + ID int64 `gorm:"column:ID;primaryKey"` + ZoneID int64 `gorm:"column:ZONE_ID"` + Name string `gorm:"column:NAME"` + Description string `gorm:"column:DESCRIPTION"` + IsLocal bool `gorm:"column:IS_LOCAL"` + Op int `gorm:"column:OP"` + Ts time.Time `gorm:"column:TS"` +} + +// TableName func respresent return table name of Station +func (s *Station) TableName() string { + return "STATION" +} diff --git a/orm/circuit_diagram_zone.go b/orm/circuit_diagram_zone.go new file mode 100644 index 0000000..30a3f81 --- /dev/null +++ b/orm/circuit_diagram_zone.go @@ -0,0 +1,21 @@ +// Package orm define database data struct +package orm + +import ( + "time" +) + +// Zone structure define abstracted info set of electrical zone +type Zone struct { + ID int64 `gorm:"column:ID;primaryKey"` + GridID int64 `gorm:"column:GRID_ID"` + Name string `gorm:"column:NAME"` + Description string `gorm:"column:DESCRIPTION"` + Op int `gorm:"column:OP"` + Ts time.Time `gorm:"column:TS"` +} + +// TableName func respresent return table name of Zone +func (z *Zone) TableName() string { + return "ZONE" +}