From a3f759034184e3e68be9adbac63366074dd10ddd Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Fri, 21 Jun 2024 01:35:23 +0800 Subject: [PATCH] fix device query --- apps/iot/src/http_handler/device_handler.erl | 6 +++--- apps/iot/src/iot_device.erl | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/iot/src/http_handler/device_handler.erl b/apps/iot/src/http_handler/device_handler.erl index d5dcf30..2252058 100644 --- a/apps/iot/src/http_handler/device_handler.erl +++ b/apps/iot/src/http_handler/device_handler.erl @@ -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">>)}. \ No newline at end of file + {ok, 200, iot_util:json_error(-1, <<"url: ", Path1/binary, " not found">>)}. diff --git a/apps/iot/src/iot_device.erl b/apps/iot/src/iot_device.erl index 08debcf..f6ed8d6 100644 --- a/apps/iot/src/iot_device.erl +++ b/apps/iot/src/iot_device.erl @@ -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 /= <<>> ->