fix jinzhi
This commit is contained in:
parent
c01cb4f725
commit
6ee341f2bd
@ -93,12 +93,16 @@ handle_call(_Request, _From, State = #state{}) ->
|
||||
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||
{stop, Reason :: term(), NewState :: #state{}}).
|
||||
handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params}, State = #state{id = Id, timer_map = TimerMap, pri_key = PriKey, url = Url}) ->
|
||||
ReqBody = format_event(LocationCode, DynamicLocationCode, EventType, Params, PriKey),
|
||||
case format_event(LocationCode, DynamicLocationCode, EventType, Params, PriKey) of
|
||||
error ->
|
||||
{noreply, State};
|
||||
{ok, ReqBody} ->
|
||||
Res = catch do_post(Url, Id, ReqBody),
|
||||
lager:debug("[iot_jinzhi_endpoint] format_data: ~p, post result: ~p", [ReqBody, Res]),
|
||||
TimerRef = erlang:start_timer(?RETRY_INTERVAL, self(), {repost_ticker, Id, ReqBody}),
|
||||
|
||||
{noreply, State#state{id = Id + 1, timer_map = maps:put(Id, TimerRef, TimerMap)}}.
|
||||
{noreply, State#state{id = Id + 1, timer_map = maps:put(Id, TimerRef, TimerMap)}}
|
||||
end.
|
||||
|
||||
%% @private
|
||||
%% @doc Handling all non call/cast messages
|
||||
@ -176,10 +180,15 @@ do_post(Url, Id, Body) when is_list(Url), is_integer(Id), is_binary(Body) ->
|
||||
end).
|
||||
|
||||
%% 格式话要发送的数据,避免多次格式化处理
|
||||
-spec format_event(LocationCode :: binary(), DynamicLocationCode :: binary(), EventType :: integer(), Params :: map(), PriKey :: public_key:private_key()) -> binary().
|
||||
-spec format_event(LocationCode :: binary(), DynamicLocationCode :: binary(), EventType :: integer(), Params :: map(), PriKey :: public_key:private_key()) -> error | {ok, binary()}.
|
||||
format_event(LocationCode, DynamicLocationCode, EventType, #{<<"event_code">> := EventCode, <<"description">> := Description, <<"datetime">> := Datetime, <<"attachments">> := Attachments0}, PriKey)
|
||||
when is_binary(LocationCode), is_binary(DynamicLocationCode), is_integer(EventType) ->
|
||||
|
||||
%% 动火离人不推送给金智 2024-12-02
|
||||
case lists:member(EventCode, [<<"23104">>]) of
|
||||
true ->
|
||||
error;
|
||||
false ->
|
||||
Attachments = lists:map(fun(#{<<"filename">> := Filename}) ->
|
||||
{ok, FileUrl} = iot_util:file_uri(Filename),
|
||||
Name = filename:basename(FileUrl),
|
||||
@ -205,7 +214,8 @@ format_event(LocationCode, DynamicLocationCode, EventType, #{<<"event_code">> :=
|
||||
<<"count">> => 1,
|
||||
<<"deviceInfo">> => DeviceInfo
|
||||
},
|
||||
iolist_to_binary(jiffy:encode(ReqData, [force_utf8])).
|
||||
{ok, iolist_to_binary(jiffy:encode(ReqData, [force_utf8]))}
|
||||
end.
|
||||
|
||||
-spec generate_task_id(LocationCode :: binary(), EventCode :: binary()) -> binary().
|
||||
generate_task_id(LocationCode, EventCode) when is_binary(LocationCode), is_binary(EventCode) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user