fix period

This commit is contained in:
anlicheng 2024-07-12 17:02:38 +08:00
parent 99bb1aa1d0
commit 60d5ccb13d
2 changed files with 4 additions and 4 deletions

View File

@ -48,7 +48,7 @@ ai_event(Id) when is_integer(Id) ->
get_event_period_settings() ->
Token = iot_util:md5(<<?API_TOKEN/binary, ?API_TOKEN/binary>>),
{ok, Url0} = application:get_env(iot, api_url),
Url = Url0 ++ "/api/v1/eventPeriodSettings",
Url = Url0 ++ "/api/v1/alertPeriod",
Headers = [
{<<"content-type">>, <<"application/json">>}

View File

@ -135,15 +135,15 @@ code_change(_OldVsn, State = #state{}, _Extra) ->
-spec settings(tuple()) -> no_return().
settings({ok, Resp}) when is_binary(Resp) ->
case catch jiffy:decode(Resp, [return_maps]) of
Settings when is_map(Settings) ->
lists:foreach(fun({GroupKey, Throttle}) ->
#{<<"code">> := 200, <<"data">> := Settings} when is_list(Settings) ->
lists:foreach(fun(#{<<"event_code">> := GroupKey, <<"time_period">> := Throttle}) ->
case is_integer(Throttle) andalso Throttle > 0 of
true ->
ets:insert(?TAB_NAME, #period{group_key = GroupKey, throttle = Throttle});
false ->
ok
end
end, maps:to_list(Settings));
end, Settings);
Error ->
lager:debug("[iot_event_period_settings] get event_period_settings from api get error: ~p", [Error])
end;