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
|
|
|
|
2025-01-07 16:45:52 +08:00
|
|
|
// PrintGrapMap define func of print circuit diagram topologic info data
|
|
|
|
|
func PrintGrapMap() {
|
|
|
|
|
graphOverview.Range(func(key, value interface{}) bool {
|
|
|
|
|
fmt.Println(key, value)
|
|
|
|
|
return true
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
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 {
|
2025-01-08 16:37:18 +08:00
|
|
|
_, result := graphOverview.Swap(pageID, graphInfo)
|
2024-12-02 16:13:16 +08:00
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// StoreGraphMap define func of store circuit diagram topologic data with pageID and topologic info
|
|
|
|
|
func StoreGraphMap(pageID int64, graphInfo *Graph) {
|
2025-01-08 16:37:18 +08:00
|
|
|
graphOverview.Store(pageID, graphInfo)
|
2024-12-02 16:13:16 +08:00
|
|
|
return
|
|
|
|
|
}
|
2024-12-04 15:57:11 +08:00
|
|
|
|
|
|
|
|
// DeleteGraphMap define func of delete circuit diagram topologic data with pageID
|
|
|
|
|
func DeleteGraphMap(pageID int64) {
|
2025-01-08 16:37:18 +08:00
|
|
|
graphOverview.Delete(pageID)
|
2024-12-04 15:57:11 +08:00
|
|
|
return
|
|
|
|
|
}
|