rename dynamic location code
This commit is contained in:
parent
a3f7590341
commit
476c7da467
@ -87,7 +87,7 @@
|
|||||||
-record(north_data, {
|
-record(north_data, {
|
||||||
id = 0 :: integer(),
|
id = 0 :: integer(),
|
||||||
location_code :: binary(),
|
location_code :: binary(),
|
||||||
real_location_code :: binary(),
|
dynamic_location_code :: binary(),
|
||||||
%% 数据库类型的endpoint, 可以返回list: [{K, V}, {K1, V1}]
|
%% 数据库类型的endpoint, 可以返回list: [{K, V}, {K1, V1}]
|
||||||
fields :: [{K :: binary(), V :: any()}],
|
fields :: [{K :: binary(), V :: any()}],
|
||||||
timestamp = 0 :: integer()
|
timestamp = 0 :: integer()
|
||||||
@ -97,7 +97,7 @@
|
|||||||
-record(event_data, {
|
-record(event_data, {
|
||||||
id = 0 :: integer(),
|
id = 0 :: integer(),
|
||||||
location_code :: binary(),
|
location_code :: binary(),
|
||||||
real_location_code :: binary(),
|
dynamic_location_code :: binary(),
|
||||||
event_type :: integer(),
|
event_type :: integer(),
|
||||||
params :: map()
|
params :: map()
|
||||||
}).
|
}).
|
||||||
|
|||||||
@ -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, RealLocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
handle_event(cast, {forward, LocationCode, DynamicLocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
||||||
EventData = #event_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, event_type = EventType, params = Params},
|
EventData = #event_data{id = Id, location_code = LocationCode, dynamic_location_code = DynamicLocationCode, 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}];
|
||||||
|
|||||||
@ -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, RealLocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
handle_event(cast, {forward, LocationCode, DynamicLocationCode, EventType, Params}, _, State = #state{id = Id, flight_num = FlightNum, pool_size = PoolSize, queue = Q}) ->
|
||||||
EventData = #event_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, event_type = EventType, params = Params},
|
EventData = #event_data{id = Id, location_code = LocationCode, dynamic_location_code = DynamicLocationCode, 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, real_location_code = RealLocationCode, event_type = EventType,
|
do_post(#event_data{id = Id, location_code = LocationCode, dynamic_location_code = DynamicLocationCode, 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,7 +190,7 @@ do_post(#event_data{id = Id, location_code = LocationCode, real_location_code =
|
|||||||
|
|
||||||
DeviceInfo = #{
|
DeviceInfo = #{
|
||||||
<<"location">> => LocationCode,
|
<<"location">> => LocationCode,
|
||||||
<<"real_location">> => RealLocationCode,
|
<<"dynamic_location">> => DynamicLocationCode,
|
||||||
<<"category">> => EventCode,
|
<<"category">> => EventCode,
|
||||||
<<"description">> => Description,
|
<<"description">> => Description,
|
||||||
<<"occurrenceTime">> => Datetime,
|
<<"occurrenceTime">> => Datetime,
|
||||||
|
|||||||
@ -91,8 +91,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, RealLocationCode, Fields, Timestamp}, StateName, State = #state{is_busy = IsBusy}) ->
|
handle_event(cast, {forward, LocationCode, DynamicLocationCode, Fields, Timestamp}, StateName, State = #state{is_busy = IsBusy}) ->
|
||||||
mnesia_queue:insert(#north_data{location_code = LocationCode, real_location_code = RealLocationCode, fields = Fields, timestamp = Timestamp}),
|
mnesia_queue:insert(#north_data{location_code = LocationCode, dynamic_location_code = DynamicLocationCode, fields = Fields, timestamp = Timestamp}),
|
||||||
%% 避免不必要的内部消息
|
%% 避免不必要的内部消息
|
||||||
Actions = case StateName =:= connected andalso not IsBusy of
|
Actions = case StateName =:= connected andalso not IsBusy of
|
||||||
true -> [{next_event, info, fetch_next}];
|
true -> [{next_event, info, fetch_next}];
|
||||||
@ -228,11 +228,11 @@ create_postman(Opts) ->
|
|||||||
mqtt_postman:start_link(PostmanOpts, Topic, Qos).
|
mqtt_postman:start_link(PostmanOpts, Topic, Qos).
|
||||||
|
|
||||||
-spec do_post(PostmanPid :: pid(), NorthData :: #north_data{}) -> no_return().
|
-spec do_post(PostmanPid :: pid(), NorthData :: #north_data{}) -> no_return().
|
||||||
do_post(PostmanPid, #north_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, fields = Fields, timestamp = Timestamp}) when is_pid(PostmanPid) ->
|
do_post(PostmanPid, #north_data{id = Id, location_code = LocationCode, dynamic_location_code = DynamicLocationCode, fields = Fields, timestamp = Timestamp}) when is_pid(PostmanPid) ->
|
||||||
Data = #{
|
Data = #{
|
||||||
<<"version">> => <<"1.0">>,
|
<<"version">> => <<"1.0">>,
|
||||||
<<"location_code">> => LocationCode,
|
<<"location_code">> => LocationCode,
|
||||||
<<"real_location_code">> => RealLocationCode,
|
<<"dynamic_location_code">> => DynamicLocationCode,
|
||||||
<<"ts">> => Timestamp,
|
<<"ts">> => Timestamp,
|
||||||
<<"properties">> => Fields
|
<<"properties">> => Fields
|
||||||
},
|
},
|
||||||
|
|||||||
@ -17,8 +17,8 @@
|
|||||||
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:hgetall(RouterUUID) of
|
case redis_client:hgetall(RouterUUID) of
|
||||||
{ok, #{<<"location_code">> := LocationCode, <<"real_location_code">> := RealLocationCode}} when is_binary(LocationCode), is_binary(RealLocationCode) ->
|
{ok, #{<<"location_code">> := LocationCode, <<"dynamic_location_code">> := DynamicLocationCode}} when is_binary(LocationCode), is_binary(DynamicLocationCode) ->
|
||||||
iot_jinzhi_endpoint:forward(LocationCode, RealLocationCode, EventType, Params);
|
iot_jinzhi_endpoint:forward(LocationCode, DynamicLocationCode, EventType, Params);
|
||||||
{ok, _} ->
|
{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]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
|||||||
@ -17,8 +17,8 @@
|
|||||||
route_uuid(RouterUUID, Fields, Timestamp) when is_binary(RouterUUID), is_list(Fields), is_integer(Timestamp) ->
|
route_uuid(RouterUUID, Fields, Timestamp) when is_binary(RouterUUID), is_list(Fields), is_integer(Timestamp) ->
|
||||||
%% 查找终端设备对应的点位信息
|
%% 查找终端设备对应的点位信息
|
||||||
case redis_client:hgetall(RouterUUID) of
|
case redis_client:hgetall(RouterUUID) of
|
||||||
{ok, #{<<"location_code">> := LocationCode, <<"real_location_code">> := RealLocationCode}} when is_binary(LocationCode) ->
|
{ok, #{<<"location_code">> := LocationCode, <<"dynamic_location_code">> := DynamicLocationCode}} when is_binary(LocationCode), is_binary(DynamicLocationCode) ->
|
||||||
iot_zd_endpoint:forward(LocationCode, RealLocationCode, Fields, Timestamp);
|
iot_zd_endpoint:forward(LocationCode, DynamicLocationCode, Fields, Timestamp);
|
||||||
{ok, _} ->
|
{ok, _} ->
|
||||||
lager:warning("[iot_host] the north_data hget location_code, uuid: ~p, not found, fields: ~p", [RouterUUID, Fields]);
|
lager:warning("[iot_host] the north_data hget location_code, uuid: ~p, not found, fields: ~p", [RouterUUID, Fields]);
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user