fix period
This commit is contained in:
parent
99bb1aa1d0
commit
60d5ccb13d
@ -48,7 +48,7 @@ ai_event(Id) when is_integer(Id) ->
|
|||||||
get_event_period_settings() ->
|
get_event_period_settings() ->
|
||||||
Token = iot_util:md5(<<?API_TOKEN/binary, ?API_TOKEN/binary>>),
|
Token = iot_util:md5(<<?API_TOKEN/binary, ?API_TOKEN/binary>>),
|
||||||
{ok, Url0} = application:get_env(iot, api_url),
|
{ok, Url0} = application:get_env(iot, api_url),
|
||||||
Url = Url0 ++ "/api/v1/eventPeriodSettings",
|
Url = Url0 ++ "/api/v1/alertPeriod",
|
||||||
|
|
||||||
Headers = [
|
Headers = [
|
||||||
{<<"content-type">>, <<"application/json">>}
|
{<<"content-type">>, <<"application/json">>}
|
||||||
|
|||||||
@ -135,15 +135,15 @@ code_change(_OldVsn, State = #state{}, _Extra) ->
|
|||||||
-spec settings(tuple()) -> no_return().
|
-spec settings(tuple()) -> no_return().
|
||||||
settings({ok, Resp}) when is_binary(Resp) ->
|
settings({ok, Resp}) when is_binary(Resp) ->
|
||||||
case catch jiffy:decode(Resp, [return_maps]) of
|
case catch jiffy:decode(Resp, [return_maps]) of
|
||||||
Settings when is_map(Settings) ->
|
#{<<"code">> := 200, <<"data">> := Settings} when is_list(Settings) ->
|
||||||
lists:foreach(fun({GroupKey, Throttle}) ->
|
lists:foreach(fun(#{<<"event_code">> := GroupKey, <<"time_period">> := Throttle}) ->
|
||||||
case is_integer(Throttle) andalso Throttle > 0 of
|
case is_integer(Throttle) andalso Throttle > 0 of
|
||||||
true ->
|
true ->
|
||||||
ets:insert(?TAB_NAME, #period{group_key = GroupKey, throttle = Throttle});
|
ets:insert(?TAB_NAME, #period{group_key = GroupKey, throttle = Throttle});
|
||||||
false ->
|
false ->
|
||||||
ok
|
ok
|
||||||
end
|
end
|
||||||
end, maps:to_list(Settings));
|
end, Settings);
|
||||||
Error ->
|
Error ->
|
||||||
lager:debug("[iot_event_period_settings] get event_period_settings from api get error: ~p", [Error])
|
lager:debug("[iot_event_period_settings] get event_period_settings from api get error: ~p", [Error])
|
||||||
end;
|
end;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user