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} |
|
{noreply, NewState :: #state{}, timeout() | hibernate} |
|
||||||
{stop, Reason :: term(), NewState :: #state{}}).
|
{stop, Reason :: term(), NewState :: #state{}}).
|
||||||
handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params}, State = #state{id = Id, timer_map = TimerMap, pri_key = PriKey, url = Url}) ->
|
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
|
||||||
Res = catch do_post(Url, Id, ReqBody),
|
error ->
|
||||||
lager:debug("[iot_jinzhi_endpoint] format_data: ~p, post result: ~p", [ReqBody, Res]),
|
{noreply, State};
|
||||||
TimerRef = erlang:start_timer(?RETRY_INTERVAL, self(), {repost_ticker, Id, ReqBody}),
|
{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
|
%% @private
|
||||||
%% @doc Handling all non call/cast messages
|
%% @doc Handling all non call/cast messages
|
||||||
@ -176,36 +180,42 @@ do_post(Url, Id, Body) when is_list(Url), is_integer(Id), is_binary(Body) ->
|
|||||||
end).
|
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)
|
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) ->
|
when is_binary(LocationCode), is_binary(DynamicLocationCode), is_integer(EventType) ->
|
||||||
|
|
||||||
Attachments = lists:map(fun(#{<<"filename">> := Filename}) ->
|
%% 动火离人不推送给金智 2024-12-02
|
||||||
{ok, FileUrl} = iot_util:file_uri(Filename),
|
case lists:member(EventCode, [<<"23104">>]) of
|
||||||
Name = filename:basename(FileUrl),
|
true ->
|
||||||
#{<<"name">> => Name, <<"url">> => FileUrl}
|
error;
|
||||||
end, Attachments0),
|
false ->
|
||||||
|
Attachments = lists:map(fun(#{<<"filename">> := Filename}) ->
|
||||||
|
{ok, FileUrl} = iot_util:file_uri(Filename),
|
||||||
|
Name = filename:basename(FileUrl),
|
||||||
|
#{<<"name">> => Name, <<"url">> => FileUrl}
|
||||||
|
end, Attachments0),
|
||||||
|
|
||||||
% <<"occurrenceTime">> => <<"2023-06-10 12:00:00">>,
|
% <<"occurrenceTime">> => <<"2023-06-10 12:00:00">>,
|
||||||
|
|
||||||
LocationCode1 = fake_location_code(EventCode, LocationCode),
|
LocationCode1 = fake_location_code(EventCode, LocationCode),
|
||||||
DeviceInfo = #{
|
DeviceInfo = #{
|
||||||
% <<"location">> => LocationCode,
|
% <<"location">> => LocationCode,
|
||||||
<<"location">> => LocationCode1,
|
<<"location">> => LocationCode1,
|
||||||
<<"category">> => EventCode,
|
<<"category">> => EventCode,
|
||||||
<<"description">> => Description,
|
<<"description">> => Description,
|
||||||
<<"occurrenceTime">> => Datetime,
|
<<"occurrenceTime">> => Datetime,
|
||||||
<<"attachments">> => Attachments
|
<<"attachments">> => Attachments
|
||||||
},
|
},
|
||||||
|
|
||||||
ReqData = #{
|
ReqData = #{
|
||||||
<<"sign">> => sign(DeviceInfo, PriKey),
|
<<"sign">> => sign(DeviceInfo, PriKey),
|
||||||
<<"sysId">> => ?SYS_ID,
|
<<"sysId">> => ?SYS_ID,
|
||||||
<<"taskId">> => generate_task_id(LocationCode1, EventCode),
|
<<"taskId">> => generate_task_id(LocationCode1, EventCode),
|
||||||
<<"count">> => 1,
|
<<"count">> => 1,
|
||||||
<<"deviceInfo">> => DeviceInfo
|
<<"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().
|
-spec generate_task_id(LocationCode :: binary(), EventCode :: binary()) -> binary().
|
||||||
generate_task_id(LocationCode, EventCode) when is_binary(LocationCode), is_binary(EventCode) ->
|
generate_task_id(LocationCode, EventCode) when is_binary(LocationCode), is_binary(EventCode) ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user