From 1a49c4628bc234cf715f7553dabb3a4b1dc44f6e Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Wed, 17 Jan 2024 10:40:09 +0800 Subject: [PATCH] add key --- apps/iot/src/endpoint/iot_zd_endpoint.erl | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/iot/src/endpoint/iot_zd_endpoint.erl b/apps/iot/src/endpoint/iot_zd_endpoint.erl index 5cfc59a..a5a1682 100644 --- a/apps/iot/src/endpoint/iot_zd_endpoint.erl +++ b/apps/iot/src/endpoint/iot_zd_endpoint.erl @@ -15,7 +15,7 @@ %% API -export([start_link/0]). -export([get_pid/0, forward/3, get_stat/0]). --export([parse_json_file/0, export/0]). +-export([parse_json_file/0, export/0, export_n/1]). %% gen_statem callbacks -export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]). @@ -52,6 +52,18 @@ export() -> end end || Line <- Lines]. +export_n(N) when N > 0 -> + Lines0 = parse_json_file(), + Lines = lists:sublist(Lines0, 1, N), + [begin + case catch jiffy:decode(Line, [return_maps]) of + M when is_map(M) -> + export0(M); + Error -> + lager:notice("invalid data: ~p, error: ~p", [Line, Error]) + end + end || Line <- Lines]. + export0(Fields0 = #{<<"device_uuid">> := DeviceUUID, <<"timestamp">> := Timestamp}) -> Fields = lists:foldl(fun(Key, M) -> maps:remove(Key, M) end, Fields0, [<<"device_uuid">>]), %% 查找终端设备对应的点位信息 @@ -237,6 +249,7 @@ do_post(PostmanPid, #north_data{id = Id, location_code = LocationCode, fields = <<"version">> => <<"1.0">>, <<"location_code">> => LocationCode, <<"ts">> => Timestamp, + <<"repair">> => true, <<"properties">> => Fields }, try