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