2024-11-22 16:41:04 +08:00
|
|
|
package diagram
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"errors"
|
2024-11-27 09:11:48 +08:00
|
|
|
"fmt"
|
2024-11-22 16:41:04 +08:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
|
|
cmap "github.com/orcaman/concurrent-map/v2"
|
|
|
|
|
)
|
|
|
|
|
|
2024-11-27 15:41:22 +08:00
|
|
|
// DiagramsOverview define struct of storage all circuit diagram data
|
2024-12-02 16:13:16 +08:00
|
|
|
var diagramsOverview sync.Map
|
2024-11-22 16:41:04 +08:00
|
|
|
|
2024-11-27 15:41:22 +08:00
|
|
|
// GetComponentMap define func of get circuit diagram data by global uuid
|
|
|
|
|
func GetComponentMap(uuid string) (*cmap.ConcurrentMap[string, any], error) {
|
2024-12-02 16:13:16 +08:00
|
|
|
value, ok := diagramsOverview.Load(uuid)
|
2024-11-22 16:41:04 +08:00
|
|
|
if !ok {
|
2024-11-27 15:41:22 +08:00
|
|
|
return nil, fmt.Errorf("can not find graph by global uuid:%s", uuid)
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
|
|
|
|
paramsMap, ok := value.(*cmap.ConcurrentMap[string, any])
|
|
|
|
|
if !ok {
|
2024-11-27 09:11:48 +08:00
|
|
|
return nil, errors.New("convert to component map struct failed")
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
|
|
|
|
return paramsMap, nil
|
|
|
|
|
}
|
2024-12-02 16:13:16 +08:00
|
|
|
|
|
|
|
|
// UpdateComponentMap define func of update circuit diagram data by global uuid and component info
|
|
|
|
|
func UpdateComponentMap(uuid string, componentInfo *cmap.ConcurrentMap[string, any]) bool {
|
|
|
|
|
_, result := diagramsOverview.Swap(uuid, componentInfo)
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StoreComponentMap define func of store circuit diagram data with global uuid and component info
|
|
|
|
|
func StoreComponentMap(uuid string, componentInfo *cmap.ConcurrentMap[string, any]) {
|
|
|
|
|
diagramsOverview.Store(uuid, componentInfo)
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-12-04 15:57:11 +08:00
|
|
|
|
|
|
|
|
// DeleteComponentMap define func of delete circuit diagram data with global uuid
|
|
|
|
|
func DeleteComponentMap(uuid string) {
|
|
|
|
|
diagramsOverview.Delete(uuid)
|
|
|
|
|
return
|
|
|
|
|
}
|