fix bug of load component info

This commit is contained in:
douxu 2024-12-12 16:17:31 +08:00
parent d9cc5f3738
commit 375655017e
2 changed files with 19 additions and 6 deletions

13
main.go
View File

@ -91,11 +91,24 @@ func main() {
engine := gin.Default() engine := gin.Default()
engine.Use(limiter.Middleware) engine.Use(limiter.Middleware)
// diagram api
engine.GET("/model/diagram_load", handler.CircuitDiagramLoadHandler) engine.GET("/model/diagram_load", handler.CircuitDiagramLoadHandler)
engine.POST("/model/diagram_create", handler.CircuitDiagramCreateHandler) engine.POST("/model/diagram_create", handler.CircuitDiagramCreateHandler)
engine.POST("/model/diagram_update", handler.CircuitDiagramUpdateHandler) engine.POST("/model/diagram_update", handler.CircuitDiagramUpdateHandler)
engine.POST("/model/diagram_delete", handler.CircuitDiagramDeleteHandler) engine.POST("/model/diagram_delete", handler.CircuitDiagramDeleteHandler)
// dashborad api
dashboard := engine.Group("/dashboard", limiter.Middleware)
{
dashboard.GET("/load", nil)
dashboard.GET("/query", nil)
dashboard.POST("/create", nil)
dashboard.POST("/update", nil)
dashboard.POST("/delete", nil)
}
// engine.Group()
// Swagger UI // Swagger UI
engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler)) engine.GET("/swagger/*any", ginSwagger.WrapHandler(swaggerFiles.Handler))

View File

@ -11,6 +11,7 @@ import (
"modelRT/diagram" "modelRT/diagram"
"modelRT/model" "modelRT/model"
cmap "github.com/orcaman/concurrent-map/v2"
"go.uber.org/zap" "go.uber.org/zap"
) )
@ -26,12 +27,8 @@ var ParseFunc = func(parseConfig interface{}) {
cancelCtx, cancel := context.WithTimeout(modelParseConfig.Context, 5*time.Second) cancelCtx, cancel := context.WithTimeout(modelParseConfig.Context, 5*time.Second)
defer cancel() defer cancel()
pgClient := database.GetPostgresDBClient() pgClient := database.GetPostgresDBClient()
componentKey := modelParseConfig.ComponentInfo.GlobalUUID.String() uuid := modelParseConfig.ComponentInfo.GlobalUUID.String()
unmarshalMap, err := diagram.GetComponentMap(componentKey) unmarshalMap := cmap.New[any]()
if err != nil {
logger.Error("get component map from overviewMap failed", zap.String("component_key", componentKey), zap.Error(err))
panic(err)
}
tableName := model.SelectModelNameByType(modelParseConfig.ComponentInfo.ComponentType) tableName := model.SelectModelNameByType(modelParseConfig.ComponentInfo.ComponentType)
result := pgClient.Table(tableName).WithContext(cancelCtx).Find(&unmarshalMap) result := pgClient.Table(tableName).WithContext(cancelCtx).Find(&unmarshalMap)
@ -41,6 +38,7 @@ var ParseFunc = func(parseConfig interface{}) {
logger.Error("query component detail info from table is empty", zap.String("table_name", tableName)) logger.Error("query component detail info from table is empty", zap.String("table_name", tableName))
} }
unmarshalMap.Set("id", modelParseConfig.ComponentInfo.ID) unmarshalMap.Set("id", modelParseConfig.ComponentInfo.ID)
unmarshalMap.Set("uuid", modelParseConfig.ComponentInfo.GlobalUUID.String())
unmarshalMap.Set("created_time", modelParseConfig.ComponentInfo.VisibleID) unmarshalMap.Set("created_time", modelParseConfig.ComponentInfo.VisibleID)
unmarshalMap.Set("parent_id", modelParseConfig.ComponentInfo.GridID) unmarshalMap.Set("parent_id", modelParseConfig.ComponentInfo.GridID)
unmarshalMap.Set("type", modelParseConfig.ComponentInfo.ZoneID) unmarshalMap.Set("type", modelParseConfig.ComponentInfo.ZoneID)
@ -53,5 +51,7 @@ var ParseFunc = func(parseConfig interface{}) {
unmarshalMap.Set("id", modelParseConfig.ComponentInfo.Context) unmarshalMap.Set("id", modelParseConfig.ComponentInfo.Context)
unmarshalMap.Set("parent_id", modelParseConfig.ComponentInfo.Comment) unmarshalMap.Set("parent_id", modelParseConfig.ComponentInfo.Comment)
unmarshalMap.Set("type", modelParseConfig.ComponentInfo.InService) unmarshalMap.Set("type", modelParseConfig.ComponentInfo.InService)
diagram.StoreComponentMap(uuid, &unmarshalMap)
return return
} }