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"
|
|
|
|
|
)
|
|
|
|
|
|
2024-12-18 16:25:49 +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
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
// GetComponentMap define func of get circuit diagram data by component id
|
|
|
|
|
func GetComponentMap(componentID int64) (map[string]interface{}, error) {
|
|
|
|
|
value, ok := diagramsOverview.Load(componentID)
|
2024-11-22 16:41:04 +08:00
|
|
|
if !ok {
|
2025-01-21 16:35:44 +08:00
|
|
|
return nil, fmt.Errorf("can not find graph by global uuid:%d", componentID)
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
2024-12-18 16:25:49 +08:00
|
|
|
paramsMap, ok := value.(map[string]interface{})
|
2024-11-22 16:41:04 +08:00
|
|
|
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
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
// UpdateComponentMap define func of update circuit diagram data by component id and component info
|
|
|
|
|
func UpdateComponentMap(componentID int64, componentInfo map[string]interface{}) bool {
|
|
|
|
|
_, result := diagramsOverview.Swap(componentID, componentInfo)
|
2024-12-02 16:13:16 +08:00
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
// StoreComponentMap define func of store circuit diagram data with component id and component info
|
|
|
|
|
func StoreComponentMap(componentID int64, componentInfo map[string]interface{}) {
|
|
|
|
|
diagramsOverview.Store(componentID, componentInfo)
|
2024-12-02 16:13:16 +08:00
|
|
|
return
|
|
|
|
|
}
|
2024-12-04 15:57:11 +08:00
|
|
|
|
2025-01-21 16:35:44 +08:00
|
|
|
// DeleteComponentMap define func of delete circuit diagram data with component id
|
|
|
|
|
func DeleteComponentMap(componentID int64) {
|
|
|
|
|
diagramsOverview.Delete(componentID)
|
2024-12-04 15:57:11 +08:00
|
|
|
return
|
|
|
|
|
}
|