write code for adapter new component struct
This commit is contained in:
parent
5a9fa5cc4d
commit
9385ba695c
|
|
@ -15,43 +15,37 @@ import (
|
|||
)
|
||||
|
||||
// CreateComponentIntoDB define create component info of the circuit diagram into DB
|
||||
func CreateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfos []network.ComponentCreateInfo) error {
|
||||
func CreateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo network.ComponentCreateInfo) (int64, error) {
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
var componentSlice []orm.Component
|
||||
for _, info := range componentInfos {
|
||||
globalUUID, err := uuid.FromString(info.UUID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("format uuid from string type failed:%w", err)
|
||||
}
|
||||
|
||||
componentInfo := orm.Component{
|
||||
GlobalUUID: globalUUID,
|
||||
GridID: info.GridID,
|
||||
ZoneID: info.ZoneID,
|
||||
StationID: info.StationID,
|
||||
ComponentType: info.ComponentType,
|
||||
State: info.State,
|
||||
ConnectedBus: info.ConnectedBus,
|
||||
Name: info.Name,
|
||||
VisibleID: info.Name,
|
||||
Description: info.Description,
|
||||
Context: info.Context,
|
||||
Comment: info.Comment,
|
||||
InService: info.InService,
|
||||
}
|
||||
componentSlice = append(componentSlice, componentInfo)
|
||||
globalUUID, err := uuid.FromString(componentInfo.UUID)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("format uuid from string type failed:%w", err)
|
||||
}
|
||||
|
||||
result := tx.WithContext(cancelCtx).Create(&componentSlice)
|
||||
component := orm.Component{
|
||||
GlobalUUID: globalUUID,
|
||||
GridID: componentInfo.GridID,
|
||||
ZoneID: componentInfo.ZoneID,
|
||||
StationID: componentInfo.StationID,
|
||||
PageID: componentInfo.PageID,
|
||||
Tag: componentInfo.Tag,
|
||||
ComponentType: componentInfo.ComponentType,
|
||||
Name: componentInfo.Name,
|
||||
Context: componentInfo.Context,
|
||||
Op: componentInfo.Op,
|
||||
Ts: time.Now(),
|
||||
}
|
||||
|
||||
if result.Error != nil || result.RowsAffected != int64(len(componentSlice)) {
|
||||
result := tx.WithContext(cancelCtx).Create(&component)
|
||||
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected != int64(len(componentSlice)) {
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check insert component slice", constant.ErrInsertRowUnexpected)
|
||||
}
|
||||
return fmt.Errorf("insert component info failed:%w", err)
|
||||
return -1, fmt.Errorf("insert component info failed:%w", err)
|
||||
}
|
||||
return nil
|
||||
return component.ID, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,37 +8,29 @@ import (
|
|||
|
||||
"modelRT/constant"
|
||||
"modelRT/model"
|
||||
"modelRT/network"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// CreateModelIntoDB define create component model params of the circuit diagram into DB
|
||||
func CreateModelIntoDB(ctx context.Context, tx *gorm.DB, componentInfos []network.ComponentCreateInfo) error {
|
||||
func CreateModelIntoDB(ctx context.Context, tx *gorm.DB, componentID int64, componentType int, modelParas string) error {
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
for _, componentInfo := range componentInfos {
|
||||
modelStruct := model.SelectModelByType(componentInfo.ComponentType)
|
||||
globalUUID, err := uuid.FromString(componentInfo.UUID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("format uuid from string type failed:%w", err)
|
||||
}
|
||||
modelStruct.SetUUID(globalUUID)
|
||||
err = jsoniter.Unmarshal([]byte(componentInfo.Params), modelStruct)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal component model params failed:%w", err)
|
||||
}
|
||||
modelStruct := model.SelectModelByType(componentType)
|
||||
modelStruct.SetComponentID(componentID)
|
||||
err := jsoniter.Unmarshal([]byte(modelParas), modelStruct)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal component model params failed:%w", err)
|
||||
}
|
||||
|
||||
result := tx.Model(modelStruct).WithContext(cancelCtx).Create(modelStruct)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check insert model params", constant.ErrInsertRowUnexpected)
|
||||
}
|
||||
return fmt.Errorf("insert component model params into table %s failed:%w", modelStruct.ReturnTableName(), err)
|
||||
result := tx.Model(modelStruct).WithContext(cancelCtx).Create(modelStruct)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check insert model params", constant.ErrInsertRowUnexpected)
|
||||
}
|
||||
return fmt.Errorf("insert component model params into table %s failed:%w", modelStruct.ReturnTableName(), err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,39 +15,37 @@ import (
|
|||
)
|
||||
|
||||
// UpdateComponentIntoDB define update component info of the circuit diagram into DB
|
||||
func UpdateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfos []network.ComponentUpdateInfo) error {
|
||||
func UpdateComponentIntoDB(ctx context.Context, tx *gorm.DB, componentInfo network.ComponentUpdateInfo) (int64, error) {
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, info := range componentInfos {
|
||||
globalUUID, err := uuid.FromString(info.UUID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("format uuid from string type failed:%w", err)
|
||||
}
|
||||
|
||||
componentInfo := orm.Component{
|
||||
GlobalUUID: globalUUID,
|
||||
GridID: info.GridID,
|
||||
ZoneID: info.ZoneID,
|
||||
StationID: info.StationID,
|
||||
ComponentType: info.ComponentType,
|
||||
State: info.State,
|
||||
ConnectedBus: info.ConnectedBus,
|
||||
Name: info.Name,
|
||||
VisibleID: info.Name,
|
||||
Description: info.Description,
|
||||
Context: info.Context,
|
||||
Comment: info.Comment,
|
||||
InService: info.InService,
|
||||
}
|
||||
result := tx.Model(&orm.Component{}).WithContext(cancelCtx).Updates(&componentInfo)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check update component conditions", constant.ErrUpdateRowZero)
|
||||
}
|
||||
return fmt.Errorf("update component info failed:%w", err)
|
||||
}
|
||||
globalUUID, err := uuid.FromString(componentInfo.UUID)
|
||||
if err != nil {
|
||||
return -1, fmt.Errorf("format uuid from string type failed:%w", err)
|
||||
}
|
||||
return nil
|
||||
|
||||
component := orm.Component{
|
||||
GlobalUUID: globalUUID,
|
||||
GridID: componentInfo.GridID,
|
||||
ZoneID: componentInfo.ZoneID,
|
||||
StationID: componentInfo.StationID,
|
||||
PageID: componentInfo.PageID,
|
||||
Tag: componentInfo.Tag,
|
||||
ComponentType: componentInfo.ComponentType,
|
||||
Name: componentInfo.Name,
|
||||
Context: componentInfo.Context,
|
||||
Op: componentInfo.Op,
|
||||
Ts: time.Now(),
|
||||
}
|
||||
|
||||
result := tx.Model(&orm.Component{}).WithContext(cancelCtx).Updates(&component)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check update component conditions", constant.ErrUpdateRowZero)
|
||||
}
|
||||
return -1, fmt.Errorf("update component info failed:%w", err)
|
||||
}
|
||||
|
||||
return component.ID, nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,43 +8,34 @@ import (
|
|||
|
||||
"modelRT/constant"
|
||||
"modelRT/model"
|
||||
"modelRT/network"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
jsoniter "github.com/json-iterator/go"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
// UpdateModelIntoDB define update component model params of the circuit diagram into DB
|
||||
func UpdateModelIntoDB(ctx context.Context, tx *gorm.DB, componentInfos []network.ComponentUpdateInfo) error {
|
||||
func UpdateModelIntoDB(ctx context.Context, tx *gorm.DB, componentID int64, componentType int, modelParas string) error {
|
||||
cancelCtx, cancel := context.WithTimeout(ctx, 5*time.Second)
|
||||
defer cancel()
|
||||
|
||||
for _, componentInfo := range componentInfos {
|
||||
modelStruct := model.SelectModelByType(componentInfo.ComponentType)
|
||||
if modelStruct == nil {
|
||||
return fmt.Errorf("can not get component model by model type %d", componentInfo.ComponentType)
|
||||
}
|
||||
modelStruct := model.SelectModelByType(componentType)
|
||||
if modelStruct == nil {
|
||||
return fmt.Errorf("can not get component model by model type %d", componentType)
|
||||
}
|
||||
|
||||
err := jsoniter.Unmarshal([]byte(componentInfo.Params), modelStruct)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal component info by component struct %s,failed", model.SelectModelNameByType(componentInfo.ComponentType))
|
||||
}
|
||||
err := jsoniter.Unmarshal([]byte(modelParas), modelStruct)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unmarshal component info by component struct %s,failed", model.SelectModelNameByType(componentType))
|
||||
}
|
||||
modelStruct.SetComponentID(componentID)
|
||||
|
||||
globalUUID, err := uuid.FromString(componentInfo.UUID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("format uuid from string type failed:%w", err)
|
||||
}
|
||||
modelStruct.SetUUID(globalUUID)
|
||||
|
||||
result := tx.Model(modelStruct).WithContext(cancelCtx).Where("uuid = ?", componentInfo.UUID).Updates(modelStruct)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check where conditions", constant.ErrUpdateRowZero)
|
||||
}
|
||||
return err
|
||||
result := tx.Model(modelStruct).WithContext(cancelCtx).Where("component_id = ?", componentID).Updates(modelStruct)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
err := result.Error
|
||||
if result.RowsAffected == 0 {
|
||||
err = fmt.Errorf("%w:please check where conditions", constant.ErrUpdateRowZero)
|
||||
}
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,40 +99,46 @@ func CircuitDiagramCreateHandler(c *gin.Context) {
|
|||
graph.AddEdge(topologicCreateInfo.UUIDFrom, topologicCreateInfo.UUIDTo)
|
||||
}
|
||||
|
||||
err = database.CreateComponentIntoDB(c, tx, request.ComponentInfos)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
for _, componentInfo := range request.ComponentInfos {
|
||||
componentID, err := database.CreateComponentIntoDB(c, tx, componentInfo)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
||||
logger.Error("insert component info into DB failed", zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"component_infos": request.ComponentInfos,
|
||||
},
|
||||
logger.Error("insert component info into DB failed", zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"component_infos": request.ComponentInfos,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
|
||||
err = database.CreateModelIntoDB(c, tx, request.ComponentInfos)
|
||||
if err != nil {
|
||||
logger.Error("create component model into DB failed", zap.Any("component_infos", request.ComponentInfos), zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"uuid": request.PageID,
|
||||
"component_infos": request.ComponentInfos,
|
||||
},
|
||||
err = database.CreateModelIntoDB(c, tx, componentID, componentInfo.ComponentType, componentInfo.Params)
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
||||
logger.Error("create component model into DB failed", zap.Any("component_infos", request.ComponentInfos), zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"uuid": request.PageID,
|
||||
"component_infos": request.ComponentInfos,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
|
||||
for _, componentInfo := range request.ComponentInfos {
|
||||
paramsJSON, err := simplejson.NewJson([]byte(componentInfo.Params))
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
||||
logger.Error("unmarshal component params info failed", zap.String("component_params", componentInfo.Params), zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
|
|
@ -148,6 +154,8 @@ func CircuitDiagramCreateHandler(c *gin.Context) {
|
|||
|
||||
componentMap, err := paramsJSON.Map()
|
||||
if err != nil {
|
||||
tx.Rollback()
|
||||
|
||||
logger.Error("format params json info to map failed", zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
|
|
|
|||
|
|
@ -164,8 +164,9 @@ func CircuitDiagramDeleteHandler(c *gin.Context) {
|
|||
return
|
||||
}
|
||||
|
||||
// TODO 增加 for update 操作后再删除
|
||||
modelStruct := model.SelectModelByType(component.ComponentType)
|
||||
modelStruct.SetUUID(globalUUID)
|
||||
modelStruct.SetComponentID(component.ID)
|
||||
result = tx.WithContext(cancelCtx).Delete(modelStruct)
|
||||
if result.Error != nil || result.RowsAffected == 0 {
|
||||
tx.Rollback()
|
||||
|
|
|
|||
|
|
@ -98,34 +98,36 @@ func CircuitDiagramUpdateHandler(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
err = database.UpdateComponentIntoDB(c, tx, request.ComponentInfos)
|
||||
if err != nil {
|
||||
logger.Error("udpate component info into DB failed", zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"page_id": request.PageID,
|
||||
"component_info": request.ComponentInfos,
|
||||
},
|
||||
for _, componentInfo := range request.ComponentInfos {
|
||||
componentID, err := database.UpdateComponentIntoDB(c, tx, componentInfo)
|
||||
if err != nil {
|
||||
logger.Error("udpate component info into DB failed", zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"page_id": request.PageID,
|
||||
"component_info": request.ComponentInfos,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
|
||||
err = database.UpdateModelIntoDB(c, tx, request.ComponentInfos)
|
||||
if err != nil {
|
||||
logger.Error("udpate component model info into DB failed", zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"page_id": request.PageID,
|
||||
"component_info": request.ComponentInfos,
|
||||
},
|
||||
err = database.UpdateModelIntoDB(c, tx, componentID, componentInfo.ComponentType, componentInfo.Params)
|
||||
if err != nil {
|
||||
logger.Error("udpate component model info into DB failed", zap.Error(err))
|
||||
header := network.FailResponseHeader{Status: http.StatusBadRequest, ErrMsg: err.Error()}
|
||||
resp := network.FailureResponse{
|
||||
FailResponseHeader: header,
|
||||
PayLoad: map[string]interface{}{
|
||||
"page_id": request.PageID,
|
||||
"component_info": request.ComponentInfos,
|
||||
},
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, resp)
|
||||
return
|
||||
}
|
||||
|
||||
for _, componentInfo := range request.ComponentInfos {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,8 @@
|
|||
// Package model define model struct of model runtime service
|
||||
package model
|
||||
|
||||
import "github.com/gofrs/uuid"
|
||||
|
||||
// BasicModelInterface define basic model type interface
|
||||
type BasicModelInterface interface {
|
||||
SetUUID(uuid uuid.UUID)
|
||||
SetComponentID(componentID int64)
|
||||
ReturnTableName() string
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,18 +23,15 @@ type TopologicUUIDCreateInfo struct {
|
|||
type ComponentCreateInfo struct {
|
||||
UUID string `json:"uuid"`
|
||||
Name string `json:"name"`
|
||||
VisibleID string `json:"visible_id"`
|
||||
Description string `json:"description"`
|
||||
Context string `json:"context"`
|
||||
Comment string `json:"comment"`
|
||||
Params string `json:"params"`
|
||||
GridID int64 `json:"grid_id"`
|
||||
ZoneID int64 `json:"zone_id"`
|
||||
StationID int64 `json:"station_id"`
|
||||
PageID int64 `json:"page_id"`
|
||||
Tag string `json:"tag"`
|
||||
ComponentType int `json:"component_type"`
|
||||
State int `json:"state"`
|
||||
ConnectedBus int `json:"connected_bus"`
|
||||
InService bool `json:"in_service"`
|
||||
Params string `json:"params"`
|
||||
Op int `json:"op"`
|
||||
}
|
||||
|
||||
// CircuitDiagramCreateRequest defines request params of circuit diagram create api
|
||||
|
|
|
|||
|
|
@ -35,18 +35,15 @@ type TopologicUUIDChangeInfos struct {
|
|||
type ComponentUpdateInfo struct {
|
||||
UUID string `json:"uuid"`
|
||||
Name string `json:"name"`
|
||||
VisibleID string `json:"visible_id"`
|
||||
Description string `json:"description"`
|
||||
Context string `json:"context"`
|
||||
Comment string `json:"comment"`
|
||||
Params string `json:"params"`
|
||||
GridID int64 `json:"grid_id"`
|
||||
ZoneID int64 `json:"zone_id"`
|
||||
StationID int64 `json:"station_id"`
|
||||
PageID int64 `json:"page_id"`
|
||||
ComponentType int `json:"component_type"`
|
||||
State int `json:"state"`
|
||||
ConnectedBus int `json:"connected_bus"`
|
||||
InService bool `json:"in_service"`
|
||||
Params string `json:"params"`
|
||||
Op int `json:"op"`
|
||||
Tag string `json:"tag"`
|
||||
}
|
||||
|
||||
// CircuitDiagramUpdateRequest defines request params of circuit diagram update api
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import "github.com/gofrs/uuid"
|
|||
// AsyncMotor define asynchronous motor model
|
||||
type AsyncMotor struct {
|
||||
UUID uuid.UUID `gorm:"column:global_uuid;primaryKey"`
|
||||
ComponentID int64 // compoent表ID
|
||||
NoLoadVoltage float64 // 空载电压
|
||||
NoLoadElectricCurrent float64 // 空载电流
|
||||
NoLoadPower float64 // 空载电功率
|
||||
|
|
@ -81,9 +82,9 @@ func (a *AsyncMotor) TableName() string {
|
|||
return "AsyncMotor"
|
||||
}
|
||||
|
||||
// SetUUID func implement BasicModelInterface interface
|
||||
func (a *AsyncMotor) SetUUID(uuid uuid.UUID) {
|
||||
a.UUID = uuid
|
||||
// SetComponentID func implement BasicModelInterface interface
|
||||
func (a *AsyncMotor) SetComponentID(componentID int64) {
|
||||
a.ComponentID = componentID
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import "github.com/gofrs/uuid"
|
|||
// BusbarSection define busbar section model
|
||||
type BusbarSection struct {
|
||||
// 母线基本参数
|
||||
ComponentID int64 // compoent表ID
|
||||
BusbarName string // 母线端名称,默认值BusX
|
||||
BusbarNumber int // 母线编号,默认值1
|
||||
UUID uuid.UUID `gorm:"column:global_uuid;primaryKey"`
|
||||
|
|
@ -68,9 +69,9 @@ func (b *BusbarSection) TableName() string {
|
|||
return "BusbarSection"
|
||||
}
|
||||
|
||||
// SetUUID func implement BasicModelInterface interface
|
||||
func (b *BusbarSection) SetUUID(uuid uuid.UUID) {
|
||||
b.UUID = uuid
|
||||
// SetComponentID func implement BasicModelInterface interface
|
||||
func (b *BusbarSection) SetComponentID(componentID int64) {
|
||||
b.ComponentID = componentID
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2,25 +2,25 @@
|
|||
package orm
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/gofrs/uuid"
|
||||
)
|
||||
|
||||
// Component structure define abstracted info set of electrical component
|
||||
type Component struct {
|
||||
ID int64 `gorm:"column:id"`
|
||||
GlobalUUID uuid.UUID `gorm:"column:global_uuid;primaryKey"`
|
||||
ID int64 `gorm:"column:id;primaryKey"`
|
||||
GlobalUUID uuid.UUID `gorm:"column:global_uuid"`
|
||||
Tag string `gorm:"column:tag"`
|
||||
GridID int64 `gorm:"column:grid"`
|
||||
ZoneID int64 `gorm:"column:zone"`
|
||||
StationID int64 `gorm:"column:station"`
|
||||
PageID int64 `gorm:"column:page_id"`
|
||||
ComponentType int `gorm:"column:type"`
|
||||
State int `gorm:"column:state"`
|
||||
ConnectedBus int `gorm:"column:connected_bus"`
|
||||
Name string `gorm:"column:name"`
|
||||
VisibleID string `gorm:"column:visible_id"`
|
||||
Description string `gorm:"column:description"`
|
||||
Context string `gorm:"column:context"`
|
||||
Comment string `gorm:"column:comment"`
|
||||
InService bool `gorm:"column:in_service"`
|
||||
Op int `gorm:"column:op"`
|
||||
Ts time.Time `gorm:"column:ts"`
|
||||
}
|
||||
|
||||
// TableName func respresent return table name of Component
|
||||
|
|
|
|||
|
|
@ -5,14 +5,15 @@ import "time"
|
|||
|
||||
// Page structure define circuit diagram page info set
|
||||
type Page struct {
|
||||
ID int64 `gorm:"column:id"`
|
||||
StationID int64 `gorm:"column:station_id"`
|
||||
Status int `gorm:"column:status"`
|
||||
Name string `gorm:"column:name"`
|
||||
Owner string `gorm:"column:owner"`
|
||||
Comment string `gorm:"column:comment"`
|
||||
Context string `gorm:"column:context"`
|
||||
TSModified time.Time `gorm:"column:ts_modified"`
|
||||
ID int64 `gorm:"column:id;primaryKey"`
|
||||
Status int `gorm:"column:status"`
|
||||
Op int `gorm:"column:op"`
|
||||
Label string `gorm:"column:label"`
|
||||
Context string `gorm:"column:context"`
|
||||
Description string `gorm:"column:description"`
|
||||
Tag string `gorm:"column:tag"`
|
||||
Name string `gorm:"column:name"`
|
||||
Ts time.Time `gorm:"column:ts"`
|
||||
}
|
||||
|
||||
// TableName func respresent return table name of Page
|
||||
|
|
|
|||
37
orm/demo.go
37
orm/demo.go
|
|
@ -1,37 +1,34 @@
|
|||
// Package orm define database data struct
|
||||
package orm
|
||||
|
||||
import "github.com/gofrs/uuid"
|
||||
import "time"
|
||||
|
||||
type Demo struct {
|
||||
// 母线基本参数
|
||||
DemoName string // 母线端名称,默认值BusX
|
||||
BusbarNumber int // 母线编号,默认值1
|
||||
Resistance float32 // 电阻值
|
||||
Voltage float32 // 电压(测点)
|
||||
AnchorVoltage bool // 是否锚定电压
|
||||
VoltageUpperLimit float32 // 电压上限
|
||||
VoltageLowerLimit float32 // 电压下限
|
||||
Current float32 // 电流(测点)
|
||||
AnchorCurrent bool // 是否锚定电流
|
||||
CurrentUpperLimit float32 // 电流上限
|
||||
CurrentLowerLimit float32 // 电流下限
|
||||
AnchorParaList string // 锚定参量列表
|
||||
UUID uuid.UUID `gorm:"column:global_uuid;primaryKey"`
|
||||
ID int64 `gorm:"column:id"` // 主键 ID
|
||||
ComponentID int64 `gorm:"column:component_id"` // compoent表ID
|
||||
Resistance float32 `gorm:"column:resistance"` // 电阻值
|
||||
AnchorV bool `gorm:"column:anchor_v"` // 是否锚定电压
|
||||
UVAlarm float32 `gorm:"column:uv_alarm"` // 欠压告警值
|
||||
OVAlarm float32 `gorm:"column:ov_alarm"` // 过压告警值
|
||||
AnchorI bool `gorm:"column:anchor_i"` // 是否锚定电流
|
||||
UIAlarm float32 `gorm:"column:ui_alarm"` // 低电流告警值
|
||||
OIAlarm float32 `gorm:"column:oi_alarm"` // 高电流告警值
|
||||
Op int `gorm:"column:op"` // 操作人 ID
|
||||
Ts time.Time `gorm:"column:ts"` // 操作时间
|
||||
}
|
||||
|
||||
// TableName func respresent return table name of busbar section
|
||||
func (d *Demo) TableName() string {
|
||||
return "Demo"
|
||||
return "bus_stability"
|
||||
}
|
||||
|
||||
// SetUUID func implement BasicModelInterface interface
|
||||
func (d *Demo) SetUUID(uuid uuid.UUID) {
|
||||
d.UUID = uuid
|
||||
// SetComponentID func implement BasicModelInterface interface
|
||||
func (d *Demo) SetComponentID(componentID int64) {
|
||||
d.ComponentID = componentID
|
||||
return
|
||||
}
|
||||
|
||||
// ReturnTableName func implement BasicModelInterface interface
|
||||
func (d *Demo) ReturnTableName() string {
|
||||
return "Demo"
|
||||
return "bus_stability"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,10 @@ var AnchorFunc = func(anchorConfig interface{}) {
|
|||
beginUnixTime = milliUnixTime - 1000*60
|
||||
firstTimePolling = false
|
||||
} else {
|
||||
// 判断时间差值是否小于10s,如果小于则重新获取时间
|
||||
// 判断时间差值是否小于10s,如果小于则sleep0.5s后重新获取时间
|
||||
endUnixTime = time.Now().UnixMilli()
|
||||
if endUnixTime-beginUnixTime < 1000*10 {
|
||||
time.Sleep(time.Duration(1 * time.Second))
|
||||
if endUnixTime-beginUnixTime < 1000 {
|
||||
time.Sleep(time.Duration(500 * time.Millisecond))
|
||||
endUnixTime = time.Now().UnixMilli()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -76,18 +76,16 @@ var ParseFunc = func(parseConfig interface{}) {
|
|||
|
||||
unmarshalMap["id"] = modelParseConfig.ComponentInfo.ID
|
||||
unmarshalMap["uuid"] = uuid
|
||||
unmarshalMap["created_time"] = modelParseConfig.ComponentInfo.VisibleID
|
||||
unmarshalMap["parent_id"] = modelParseConfig.ComponentInfo.GridID
|
||||
unmarshalMap["type"] = modelParseConfig.ComponentInfo.ZoneID
|
||||
unmarshalMap["created_time"] = modelParseConfig.ComponentInfo.StationID
|
||||
unmarshalMap["updated_time"] = modelParseConfig.ComponentInfo.ComponentType
|
||||
unmarshalMap["id"] = modelParseConfig.ComponentInfo.State
|
||||
unmarshalMap["parent_id"] = modelParseConfig.ComponentInfo.ConnectedBus
|
||||
unmarshalMap["type"] = modelParseConfig.ComponentInfo.Name
|
||||
unmarshalMap["updated_time"] = modelParseConfig.ComponentInfo.Description
|
||||
unmarshalMap["id"] = modelParseConfig.ComponentInfo.Context
|
||||
unmarshalMap["parent_id"] = modelParseConfig.ComponentInfo.Comment
|
||||
unmarshalMap["type"] = modelParseConfig.ComponentInfo.InService
|
||||
unmarshalMap["uuid"] = modelParseConfig.ComponentInfo.Tag
|
||||
unmarshalMap["grid_id"] = modelParseConfig.ComponentInfo.GridID
|
||||
unmarshalMap["zone_id"] = modelParseConfig.ComponentInfo.ZoneID
|
||||
unmarshalMap["station_id"] = modelParseConfig.ComponentInfo.StationID
|
||||
unmarshalMap["page_id"] = modelParseConfig.ComponentInfo.PageID
|
||||
unmarshalMap["component_type"] = modelParseConfig.ComponentInfo.ComponentType
|
||||
unmarshalMap["name"] = modelParseConfig.ComponentInfo.Name
|
||||
unmarshalMap["context"] = modelParseConfig.ComponentInfo.Context
|
||||
unmarshalMap["op"] = modelParseConfig.ComponentInfo.Op
|
||||
unmarshalMap["ts"] = modelParseConfig.ComponentInfo.Ts
|
||||
|
||||
diagram.StoreComponentMap(uuid, unmarshalMap)
|
||||
return
|
||||
|
|
|
|||
32
sql/demo.sql
32
sql/demo.sql
|
|
@ -1,21 +1,19 @@
|
|||
CREATE TABLE public."Demo" (
|
||||
CREATE TABLE
|
||||
public.bus_stability (
|
||||
id serial NOT NULL,
|
||||
global_uuid uuid NOT NULL,
|
||||
demo_number integer NOT NULL,
|
||||
demo_name character varying(20) default 'Demox' NOT NULL,
|
||||
voltage decimal(5, 2) NOT NULL,
|
||||
voltage_upper_limit decimal(5, 2) NOT NULL,
|
||||
voltage_lower_limit decimal(5, 2) NOT NULL,
|
||||
anchor_voltage boolean NOT NULL,
|
||||
current decimal(5, 2) NOT NULL,
|
||||
current_upper_limit decimal(5, 2) NOT NULL,
|
||||
current_lower_limit decimal(5, 2) NOT NULL,
|
||||
anchor_current boolean NOT NULL,
|
||||
resistance decimal(5, 2) NOT NULL,
|
||||
anchor_para_list text NULL
|
||||
);
|
||||
component_id integer NOT NULL DEFAULT '-1'::integer,
|
||||
resistance double precision NOT NULL DEFAULT 1,
|
||||
anchor_v boolean NOT NULL DEFAULT false,
|
||||
uv_alarm double precision NOT NULL DEFAULT 90,
|
||||
ov_alarm double precision NOT NULL DEFAULT 110,
|
||||
anchor_i boolean NOT NULL DEFAULT false,
|
||||
ui_alarm double precision NOT NULL DEFAULT 90,
|
||||
oi_alarm double precision NOT NULL DEFAULT 110,
|
||||
op integer NOT NULL DEFAULT '-1'::integer,
|
||||
ts timestamp with time zone NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
ALTER TABLE
|
||||
public."Demo"
|
||||
public.bus_stability
|
||||
ADD
|
||||
CONSTRAINT "Demo_pkey" PRIMARY KEY (global_uuid)
|
||||
CONSTRAINT bus_stability_id_primarykey PRIMARY KEY (id)
|
||||
Loading…
Reference in New Issue