44 lines
1.3 KiB
Go
44 lines
1.3 KiB
Go
package diagram
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"sync"
|
|
|
|
"modelRT/orm"
|
|
)
|
|
|
|
// diagramsOverview define struct of storage all circuit diagram data
|
|
var diagramsOverview sync.Map
|
|
|
|
// GetComponentMap define func of get circuit diagram data by component uuid
|
|
func GetComponentMap(componentUUID string) (*orm.Component, error) {
|
|
value, ok := diagramsOverview.Load(componentUUID)
|
|
if !ok {
|
|
return nil, fmt.Errorf("can not find graph by global uuid:%s", componentUUID)
|
|
}
|
|
componentInfo, ok := value.(*orm.Component)
|
|
if !ok {
|
|
return nil, errors.New("convert to component map struct failed")
|
|
}
|
|
return componentInfo, nil
|
|
}
|
|
|
|
// UpdateComponentMap define func of update circuit diagram data by component uuid and component info
|
|
func UpdateComponentMap(componentID int64, componentInfo *orm.Component) bool {
|
|
_, result := diagramsOverview.Swap(componentID, componentInfo)
|
|
return result
|
|
}
|
|
|
|
// StoreComponentMap define func of store circuit diagram data with component uuid and component info
|
|
func StoreComponentMap(componentUUID string, componentInfo *orm.Component) {
|
|
diagramsOverview.Store(componentUUID, componentInfo)
|
|
return
|
|
}
|
|
|
|
// DeleteComponentMap define func of delete circuit diagram data with component uuid
|
|
func DeleteComponentMap(componentUUID string) {
|
|
diagramsOverview.Delete(componentUUID)
|
|
return
|
|
}
|