add dbm new model and fixed json_data
This commit is contained in:
@@ -87,10 +87,13 @@ func (d *Datapoint) GetValueUint64() uint64 {
|
||||
return utils.Uint64From(d.Value)
|
||||
}
|
||||
|
||||
func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...json_dataModels.Set) (created []json_dataModels.Set, err error) {
|
||||
func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...json_dataModels.Set) (created []json_dataModels.Set, uuids Uuids, err error) {
|
||||
if len(sets) == 0 {
|
||||
return
|
||||
}
|
||||
|
||||
uuids = make(Uuids, 1)
|
||||
|
||||
for _, dp := range sets {
|
||||
parts := strings.Split(dp.Path, ":")
|
||||
|
||||
@@ -105,7 +108,7 @@ func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...js
|
||||
if existing, ok := current.Datapoints[part]; ok {
|
||||
publish, err := existing.Set("", dp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
created = append(created, json_dataModels.Set{
|
||||
Uuid: existing.Uuid,
|
||||
@@ -130,7 +133,7 @@ func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...js
|
||||
current.Datapoints[part] = &ndp
|
||||
publish, err := ndp.Set(strings.Join(parts, ":"), dp)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return nil, nil, err
|
||||
}
|
||||
created = append(created, json_dataModels.Set{
|
||||
Uuid: ndp.Uuid,
|
||||
@@ -143,6 +146,8 @@ func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...js
|
||||
if publish {
|
||||
current.Publish(conns, OnChange)
|
||||
}
|
||||
//add uuid to flat map for faster lookuo
|
||||
uuids[ndp.Uuid] = &ndp
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,15 +178,20 @@ func (d *Datapoint) CreateDatapoints(conns *serverModels.Connections, sets ...js
|
||||
|
||||
current.Datapoints[part] = newDp
|
||||
current = newDp
|
||||
|
||||
//add uuid to flat map for faster lookuo
|
||||
uuids[newDp.Uuid] = newDp
|
||||
}
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func (d *Datapoint) ImportDatapoint(conns *serverModels.Connections, dp Datapoint, path string) error {
|
||||
func (d *Datapoint) ImportDatapoint(conns *serverModels.Connections, dp Datapoint, path string) (uuids Uuids, err error) {
|
||||
parts := strings.Split(dp.Path, ":")
|
||||
|
||||
uuids = make(Uuids, 1)
|
||||
|
||||
current := d
|
||||
for i, part := range parts {
|
||||
if current.Datapoints == nil {
|
||||
@@ -202,9 +212,12 @@ func (d *Datapoint) ImportDatapoint(conns *serverModels.Connections, dp Datapoin
|
||||
dp.UpdateDateTime = time.Now().UnixMilli()
|
||||
dp.Subscriptions = InitSubscribtion()
|
||||
current.Datapoints[part] = &dp
|
||||
//add uuid to flat map for faster lookuo
|
||||
uuids[dp.Uuid] = &dp
|
||||
dp.Publish(conns, OnChange)
|
||||
}
|
||||
return nil
|
||||
|
||||
return uuids, nil
|
||||
}
|
||||
|
||||
// Traverse or create intermediate nodes
|
||||
@@ -220,9 +233,11 @@ func (d *Datapoint) ImportDatapoint(conns *serverModels.Connections, dp Datapoin
|
||||
newDp.ReadWrite = newDp.ReadWrite.GetRights()
|
||||
current.Datapoints[part] = newDp
|
||||
current = newDp
|
||||
//add uuid to flat map for faster lookuo
|
||||
uuids[newDp.Uuid] = newDp
|
||||
}
|
||||
}
|
||||
return nil
|
||||
return uuids, nil
|
||||
}
|
||||
|
||||
func (d *Datapoint) UpdateDatapointValue(conns *serverModels.Connections, value any, path string) error {
|
||||
|
Reference in New Issue
Block a user