2024-11-22 16:41:04 +08:00
|
|
|
package diagram
|
|
|
|
|
|
|
|
|
|
import (
|
2024-11-25 16:19:58 +08:00
|
|
|
"errors"
|
2024-11-22 16:41:04 +08:00
|
|
|
"fmt"
|
2024-11-25 16:19:58 +08:00
|
|
|
"sync"
|
2024-11-22 16:41:04 +08:00
|
|
|
)
|
|
|
|
|
|
2024-12-18 16:25:49 +08:00
|
|
|
// graphOverview define struct of storage all circuit diagram topologic data
|
2024-12-02 16:13:16 +08:00
|
|
|
var graphOverview sync.Map
|
2024-11-25 16:19:58 +08:00
|
|
|
|
2024-11-27 15:41:22 +08:00
|
|
|
// GetGraphMap define func of get circuit diagram topologic data by pageID
|
|
|
|
|
func GetGraphMap(pageID int64) (*Graph, error) {
|
2024-12-02 16:13:16 +08:00
|
|
|
value, ok := graphOverview.Load(pageID)
|
2024-11-27 09:11:48 +08:00
|
|
|
if !ok {
|
2024-11-27 15:41:22 +08:00
|
|
|
return nil, fmt.Errorf("can not find graph by pageID:%d", pageID)
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
2024-11-27 09:11:48 +08:00
|
|
|
graph, ok := value.(*Graph)
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil, errors.New("convert to graph struct failed")
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
2024-11-27 09:11:48 +08:00
|
|
|
return graph, nil
|
2024-11-22 16:41:04 +08:00
|
|
|
}
|
2024-12-02 16:13:16 +08:00
|
|
|
|
|
|
|
|
// UpdateGrapMap define func of update circuit diagram data by pageID and topologic info
|
|
|
|
|
func UpdateGrapMap(pageID int64, graphInfo *Graph) bool {
|
|
|
|
|
_, result := diagramsOverview.Swap(pageID, graphInfo)
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StoreGraphMap define func of store circuit diagram topologic data with pageID and topologic info
|
|
|
|
|
func StoreGraphMap(pageID int64, graphInfo *Graph) {
|
|
|
|
|
diagramsOverview.Store(pageID, graphInfo)
|
|
|
|
|
return
|
|
|
|
|
}
|
2024-12-04 15:57:11 +08:00
|
|
|
|
|
|
|
|
// DeleteGraphMap define func of delete circuit diagram topologic data with pageID
|
|
|
|
|
func DeleteGraphMap(pageID int64) {
|
|
|
|
|
diagramsOverview.Delete(pageID)
|
|
|
|
|
return
|
|
|
|
|
}
|