fix device query

This commit is contained in:
anlicheng 2024-06-21 01:35:23 +08:00
parent c8142256e8
commit a3f7590341
2 changed files with 4 additions and 4 deletions

View File

@ -80,8 +80,8 @@ handle_request("POST", "/device/query", _, Params = #{<<"device_uuid">> := Devic
true ->
{ok, DeviceDataList} = iot_device:query(DevicePid, Tags, StartTs, StopTs, Limit),
DataItems = lists:map(fun(#device_data{tags = Tags, val = Val, timestamp = Timestamp}) ->
#{<<"tags">> => Tags, <<"val">> => Val, <<"timestamp">> => Timestamp}
DataItems = lists:map(fun(#device_data{tags = Tags0, val = Val, timestamp = Timestamp}) ->
#{<<"tags">> => Tags0, <<"val">> => Val, <<"timestamp">> => Timestamp}
end, DeviceDataList),
{ok, 200, iot_util:json_data(DataItems)};
false ->
@ -91,4 +91,4 @@ handle_request("POST", "/device/query", _, Params = #{<<"device_uuid">> := Devic
handle_request(_, Path, _, _) ->
Path1 = list_to_binary(Path),
{ok, 200, iot_util:json_error(-1, <<"url: ", Path1/binary, " not found">>)}.
{ok, 200, iot_util:json_error(-1, <<"url: ", Path1/binary, " not found">>)}.

View File

@ -50,7 +50,7 @@
% "timestamp": int
%}
%],
-spec serialize(FieldsList :: [map()]) -> [Val :: binary()].
-spec serialize(FieldsList :: [map()]) -> [Val :: map()].
serialize(FieldsList) when is_list(FieldsList) ->
lists:flatmap(fun serialize0/1, FieldsList).
serialize0(Fields = #{<<"key">> := Key}) when is_binary(Key) andalso Key /= <<>> ->