fix jinzhi
This commit is contained in:
parent
89214c6918
commit
bab0089190
@ -97,6 +97,7 @@
|
|||||||
-record(event_data, {
|
-record(event_data, {
|
||||||
id = 0 :: integer(),
|
id = 0 :: integer(),
|
||||||
location_code :: binary(),
|
location_code :: binary(),
|
||||||
|
real_location_code :: binary(),
|
||||||
event_type :: integer(),
|
event_type :: integer(),
|
||||||
params :: map()
|
params :: map()
|
||||||
}).
|
}).
|
||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/2]).
|
-export([start_link/2]).
|
||||||
-export([get_pid/1, forward/4, get_stat/0]).
|
-export([get_pid/1, forward/5, get_stat/0]).
|
||||||
|
|
||||||
%% gen_statem callbacks
|
%% gen_statem callbacks
|
||||||
-export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]).
|
-export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]).
|
||||||
@ -42,9 +42,9 @@
|
|||||||
get_pid(Name) when is_atom(Name) ->
|
get_pid(Name) when is_atom(Name) ->
|
||||||
whereis(Name).
|
whereis(Name).
|
||||||
|
|
||||||
-spec forward(Pid :: pid(), LocationCode :: binary(), EventType :: integer(), Params :: map()) -> no_return().
|
-spec forward(Pid :: pid(), LocationCode :: binary(), RealLocationCode :: binary(), EventType :: integer(), Params :: map()) -> no_return().
|
||||||
forward(Pid, LocationCode, EventType, Params) when is_pid(Pid), is_binary(LocationCode), is_integer(EventType), is_map(Params) ->
|
forward(Pid, LocationCode, RealLocationCode, EventType, Params) when is_pid(Pid), is_binary(LocationCode), is_binary(RealLocationCode), is_integer(EventType), is_map(Params) ->
|
||||||
gen_statem:cast(Pid, {forward, LocationCode, EventType, Params}).
|
gen_statem:cast(Pid, {forward, LocationCode, RealLocationCode, EventType, Params}).
|
||||||
|
|
||||||
-spec get_stat() -> {ok, Stat :: #{}}.
|
-spec get_stat() -> {ok, Stat :: #{}}.
|
||||||
get_stat() ->
|
get_stat() ->
|
||||||
@ -82,8 +82,8 @@ callback_mode() ->
|
|||||||
%% functions is called when gen_statem receives and event from
|
%% functions is called when gen_statem receives and event from
|
||||||
%% call/2, cast/2, or as a normal process message.
|
%% call/2, cast/2, or as a normal process message.
|
||||||
|
|
||||||
handle_event(cast, {forward, LocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
handle_event(cast, {forward, LocationCode, RealLocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
||||||
EventData = #event_data{id = Id, location_code = LocationCode, event_type = EventType, params = Params},
|
EventData = #event_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, event_type = EventType, params = Params},
|
||||||
%% 避免不必要的内部消息
|
%% 避免不必要的内部消息
|
||||||
Actions = case FlightNum < PoolSize of
|
Actions = case FlightNum < PoolSize of
|
||||||
true -> [{next_event, info, fetch_next}];
|
true -> [{next_event, info, fetch_next}];
|
||||||
|
|||||||
@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
%% API
|
%% API
|
||||||
-export([start_link/0]).
|
-export([start_link/0]).
|
||||||
-export([get_pid/0, forward/3, get_stat/0]).
|
-export([get_pid/0, forward/4, get_stat/0]).
|
||||||
|
|
||||||
%% gen_statem callbacks
|
%% gen_statem callbacks
|
||||||
-export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]).
|
-export([init/1, handle_event/4, terminate/3, code_change/4, callback_mode/0]).
|
||||||
@ -46,9 +46,9 @@
|
|||||||
get_pid() ->
|
get_pid() ->
|
||||||
whereis(?MODULE).
|
whereis(?MODULE).
|
||||||
|
|
||||||
-spec forward(LocationCode :: binary(), EventType :: integer(), Params :: map()) -> no_return().
|
-spec forward(LocationCode :: binary(), RealLocationCode :: binary(), EventType :: integer(), Params :: map()) -> no_return().
|
||||||
forward(LocationCode, EventType, Params) when is_binary(LocationCode), is_integer(EventType), is_map(Params) ->
|
forward(LocationCode, RealLocationCode, EventType, Params) when is_binary(LocationCode), is_binary(RealLocationCode), is_integer(EventType), is_map(Params) ->
|
||||||
gen_statem:cast(?MODULE, {forward, LocationCode, EventType, Params}).
|
gen_statem:cast(?MODULE, {forward, LocationCode, RealLocationCode, EventType, Params}).
|
||||||
|
|
||||||
-spec get_stat() -> {ok, Stat :: #{}}.
|
-spec get_stat() -> {ok, Stat :: #{}}.
|
||||||
get_stat() ->
|
get_stat() ->
|
||||||
@ -92,8 +92,8 @@ callback_mode() ->
|
|||||||
%% functions is called when gen_statem receives and event from
|
%% functions is called when gen_statem receives and event from
|
||||||
%% call/2, cast/2, or as a normal process message.
|
%% call/2, cast/2, or as a normal process message.
|
||||||
|
|
||||||
handle_event(cast, {forward, LocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
handle_event(cast, {forward, LocationCode, RealLocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
||||||
EventData = #event_data{id = Id, location_code = LocationCode, event_type = EventType, params = Params},
|
EventData = #event_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, event_type = EventType, params = Params},
|
||||||
%% 避免不必要的内部消息
|
%% 避免不必要的内部消息
|
||||||
Actions = case FlightNum < PoolSize of
|
Actions = case FlightNum < PoolSize of
|
||||||
true -> [{next_event, info, fetch_next}];
|
true -> [{next_event, info, fetch_next}];
|
||||||
@ -176,7 +176,7 @@ code_change(_OldVsn, StateName, State = #state{}, _Extra) ->
|
|||||||
%%%===================================================================
|
%%%===================================================================
|
||||||
|
|
||||||
-spec do_post(EventData :: #event_data{}, State :: #state{}) -> no_return().
|
-spec do_post(EventData :: #event_data{}, State :: #state{}) -> no_return().
|
||||||
do_post(#event_data{id = Id, location_code = LocationCode, event_type = EventType,
|
do_post(#event_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, event_type = EventType,
|
||||||
params = Params = #{<<"event_code">> := EventCode, <<"description">> := Description, <<"datetime">> := Datetime, <<"attachments">> := Attachments0}},
|
params = Params = #{<<"event_code">> := EventCode, <<"description">> := Description, <<"datetime">> := Datetime, <<"attachments">> := Attachments0}},
|
||||||
#state{pri_key = PriKey, url = Url, logger_pid = LoggerPid}) ->
|
#state{pri_key = PriKey, url = Url, logger_pid = LoggerPid}) ->
|
||||||
|
|
||||||
@ -190,6 +190,7 @@ do_post(#event_data{id = Id, location_code = LocationCode, event_type = EventTyp
|
|||||||
|
|
||||||
DeviceInfo = #{
|
DeviceInfo = #{
|
||||||
<<"location">> => LocationCode,
|
<<"location">> => LocationCode,
|
||||||
|
<<"real_location">> => RealLocationCode,
|
||||||
<<"category">> => EventCode,
|
<<"category">> => EventCode,
|
||||||
<<"description">> => Description,
|
<<"description">> => Description,
|
||||||
<<"occurrenceTime">> => Datetime,
|
<<"occurrenceTime">> => Datetime,
|
||||||
|
|||||||
@ -16,11 +16,11 @@
|
|||||||
-spec route_uuid(RouterUUID :: binary(), EventType :: integer(), Params :: map()) -> no_return().
|
-spec route_uuid(RouterUUID :: binary(), EventType :: integer(), Params :: map()) -> no_return().
|
||||||
route_uuid(RouterUUID, EventType, Params) when is_binary(RouterUUID), is_integer(EventType), is_map(Params) ->
|
route_uuid(RouterUUID, EventType, Params) when is_binary(RouterUUID), is_integer(EventType), is_map(Params) ->
|
||||||
%% 查找终端设备对应的点位信息
|
%% 查找终端设备对应的点位信息
|
||||||
case redis_client:hget(RouterUUID, <<"location_code">>) of
|
case redis_client:hgetall(RouterUUID) of
|
||||||
{ok, undefined} ->
|
{ok, #{<<"location_code">> := LocationCode, <<"real_location_code">> := RealLocationCode}} when is_binary(LocationCode), is_binary(RealLocationCode) ->
|
||||||
|
iot_jinzhi_endpoint:forward(LocationCode, RealLocationCode, EventType, Params);
|
||||||
|
{ok, _} ->
|
||||||
lager:debug("[iot_ai_router] the event_data hget location_code, uuid: ~p, not found", [RouterUUID]);
|
lager:debug("[iot_ai_router] the event_data hget location_code, uuid: ~p, not found", [RouterUUID]);
|
||||||
{ok, LocationCode} when is_binary(LocationCode) ->
|
|
||||||
iot_jinzhi_endpoint:forward(LocationCode, EventType, Params);
|
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
lager:debug("[iot_ai_router] the event_data hget location_code uuid: ~p, get error: ~p", [RouterUUID, Reason])
|
lager:debug("[iot_ai_router] the event_data hget location_code uuid: ~p, get error: ~p", [RouterUUID, Reason])
|
||||||
end.
|
end.
|
||||||
Loading…
x
Reference in New Issue
Block a user