From 476c7da467fcb7d9b6f6c6a63e0e50c51df2db15 Mon Sep 17 00:00:00 2001 From: anlicheng <244108715@qq.com> Date: Sat, 22 Jun 2024 10:33:56 +0800 Subject: [PATCH] rename dynamic location code --- apps/iot/include/iot.hrl | 4 ++-- apps/iot/src/endpoint/iot_http_endpoint.erl | 4 ++-- apps/iot/src/endpoint/iot_jinzhi_endpoint.erl | 8 ++++---- apps/iot/src/endpoint/iot_zd_endpoint.erl | 8 ++++---- apps/iot/src/iot_ai_router.erl | 4 ++-- apps/iot/src/iot_router.erl | 4 ++-- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/apps/iot/include/iot.hrl b/apps/iot/include/iot.hrl index 124f60d..6ff7095 100644 --- a/apps/iot/include/iot.hrl +++ b/apps/iot/include/iot.hrl @@ -87,7 +87,7 @@ -record(north_data, { id = 0 :: integer(), location_code :: binary(), - real_location_code :: binary(), + dynamic_location_code :: binary(), %% 数据库类型的endpoint, 可以返回list: [{K, V}, {K1, V1}] fields :: [{K :: binary(), V :: any()}], timestamp = 0 :: integer() @@ -97,7 +97,7 @@ -record(event_data, { id = 0 :: integer(), location_code :: binary(), - real_location_code :: binary(), + dynamic_location_code :: binary(), event_type :: integer(), params :: map() }). diff --git a/apps/iot/src/endpoint/iot_http_endpoint.erl b/apps/iot/src/endpoint/iot_http_endpoint.erl index d68d38a..1f72f1f 100644 --- a/apps/iot/src/endpoint/iot_http_endpoint.erl +++ b/apps/iot/src/endpoint/iot_http_endpoint.erl @@ -82,8 +82,8 @@ callback_mode() -> %% functions is called when gen_statem receives and event from %% 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}) -> - EventData = #event_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, event_type = EventType, params = Params}, +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, dynamic_location_code = DynamicLocationCode, event_type = EventType, params = Params}, %% 避免不必要的内部消息 Actions = case FlightNum < PoolSize of true -> [{next_event, info, fetch_next}]; diff --git a/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl b/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl index 83a4cff..8ca2bcb 100644 --- a/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl +++ b/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl @@ -92,8 +92,8 @@ callback_mode() -> %% functions is called when gen_statem receives and event from %% 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}) -> - EventData = #event_data{id = Id, location_code = LocationCode, real_location_code = RealLocationCode, event_type = EventType, params = Params}, +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, dynamic_location_code = DynamicLocationCode, event_type = EventType, params = Params}, %% 避免不必要的内部消息 Actions = case FlightNum < PoolSize of 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(). -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}}, #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 = #{ <<"location">> => LocationCode, - <<"real_location">> => RealLocationCode, + <<"dynamic_location">> => DynamicLocationCode, <<"category">> => EventCode, <<"description">> => Description, <<"occurrenceTime">> => Datetime, diff --git a/apps/iot/src/endpoint/iot_zd_endpoint.erl b/apps/iot/src/endpoint/iot_zd_endpoint.erl index 202664a..94eeb6c 100644 --- a/apps/iot/src/endpoint/iot_zd_endpoint.erl +++ b/apps/iot/src/endpoint/iot_zd_endpoint.erl @@ -91,8 +91,8 @@ callback_mode() -> %% functions is called when gen_statem receives and event from %% call/2, cast/2, or as a normal process message. -handle_event(cast, {forward, LocationCode, RealLocationCode, Fields, Timestamp}, StateName, State = #state{is_busy = IsBusy}) -> - mnesia_queue:insert(#north_data{location_code = LocationCode, real_location_code = RealLocationCode, fields = Fields, timestamp = Timestamp}), +handle_event(cast, {forward, LocationCode, DynamicLocationCode, Fields, Timestamp}, StateName, State = #state{is_busy = IsBusy}) -> + mnesia_queue:insert(#north_data{location_code = LocationCode, dynamic_location_code = DynamicLocationCode, fields = Fields, timestamp = Timestamp}), %% 避免不必要的内部消息 Actions = case StateName =:= connected andalso not IsBusy of true -> [{next_event, info, fetch_next}]; @@ -228,11 +228,11 @@ create_postman(Opts) -> mqtt_postman:start_link(PostmanOpts, Topic, Qos). -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 = #{ <<"version">> => <<"1.0">>, <<"location_code">> => LocationCode, - <<"real_location_code">> => RealLocationCode, + <<"dynamic_location_code">> => DynamicLocationCode, <<"ts">> => Timestamp, <<"properties">> => Fields }, diff --git a/apps/iot/src/iot_ai_router.erl b/apps/iot/src/iot_ai_router.erl index b095c23..42075e1 100644 --- a/apps/iot/src/iot_ai_router.erl +++ b/apps/iot/src/iot_ai_router.erl @@ -17,8 +17,8 @@ route_uuid(RouterUUID, EventType, Params) when is_binary(RouterUUID), is_integer(EventType), is_map(Params) -> %% 查找终端设备对应的点位信息 case redis_client:hgetall(RouterUUID) of - {ok, #{<<"location_code">> := LocationCode, <<"real_location_code">> := RealLocationCode}} when is_binary(LocationCode), is_binary(RealLocationCode) -> - iot_jinzhi_endpoint:forward(LocationCode, RealLocationCode, EventType, Params); + {ok, #{<<"location_code">> := LocationCode, <<"dynamic_location_code">> := DynamicLocationCode}} when is_binary(LocationCode), is_binary(DynamicLocationCode) -> + iot_jinzhi_endpoint:forward(LocationCode, DynamicLocationCode, EventType, Params); {ok, _} -> lager:debug("[iot_ai_router] the event_data hget location_code, uuid: ~p, not found", [RouterUUID]); {error, Reason} -> diff --git a/apps/iot/src/iot_router.erl b/apps/iot/src/iot_router.erl index 5e9a1cb..45a4759 100644 --- a/apps/iot/src/iot_router.erl +++ b/apps/iot/src/iot_router.erl @@ -17,8 +17,8 @@ route_uuid(RouterUUID, Fields, Timestamp) when is_binary(RouterUUID), is_list(Fields), is_integer(Timestamp) -> %% 查找终端设备对应的点位信息 case redis_client:hgetall(RouterUUID) of - {ok, #{<<"location_code">> := LocationCode, <<"real_location_code">> := RealLocationCode}} when is_binary(LocationCode) -> - iot_zd_endpoint:forward(LocationCode, RealLocationCode, Fields, Timestamp); + {ok, #{<<"location_code">> := LocationCode, <<"dynamic_location_code">> := DynamicLocationCode}} when is_binary(LocationCode), is_binary(DynamicLocationCode) -> + iot_zd_endpoint:forward(LocationCode, DynamicLocationCode, Fields, Timestamp); {ok, _} -> lager:warning("[iot_host] the north_data hget location_code, uuid: ~p, not found, fields: ~p", [RouterUUID, Fields]); {error, Reason} ->