47 lines
835 B
Go
47 lines
835 B
Go
package dbm
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
json_dataModels "github.com/tecamino/tecamino-json_data/models"
|
|
)
|
|
|
|
func (d *DBMHandler) Set(req *json_dataModels.Request, id string) {
|
|
if req == nil {
|
|
return
|
|
} else if len(req.Set) == 0 {
|
|
return
|
|
}
|
|
d.RLock()
|
|
defer d.RUnlock()
|
|
|
|
resp := json_dataModels.NewResponse()
|
|
resp.Id = req.Id
|
|
|
|
for _, set := range req.Set {
|
|
dps := d.DBM.QueryDatapoints(1, set.Uuid, set.Path)
|
|
|
|
if len(dps) == 0 {
|
|
resp.SetError()
|
|
if resp.Message == "" {
|
|
resp.SetMessage(fmt.Sprintf("datapoint %s not found", set.Path))
|
|
}
|
|
continue
|
|
}
|
|
|
|
for _, dp := range dps {
|
|
dp.UpdateValue(set.Value)
|
|
|
|
resp.AddSet(json_dataModels.Set{
|
|
Uuid: dp.Uuid,
|
|
Path: dp.Path,
|
|
Value: dp.Value,
|
|
})
|
|
}
|
|
}
|
|
|
|
if err := d.Conns.SendResponse(id, resp); err != nil {
|
|
d.Log.Error("get.Set", err.Error())
|
|
}
|
|
}
|