diff --git a/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl b/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl index 0299f11..96bff07 100644 --- a/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl +++ b/apps/iot/src/endpoint/iot_jinzhi_endpoint.erl @@ -93,16 +93,11 @@ handle_call(_Request, _From, State = #state{}) -> {noreply, NewState :: #state{}, timeout() | hibernate} | {stop, Reason :: term(), NewState :: #state{}}). handle_cast({forward, LocationCode, DynamicLocationCode, EventType, Params}, State = #state{id = Id, timer_map = TimerMap, pri_key = PriKey, url = Url}) -> - try - ReqBody = format_event(LocationCode, DynamicLocationCode, EventType, Params, PriKey), - catch do_post(Url, Id, ReqBody), - TimerRef = erlang:start_timer(?RETRY_INTERVAL, self(), {repost_ticker, Id, ReqBody}), + ReqBody = format_event(LocationCode, DynamicLocationCode, EventType, Params, PriKey), + catch do_post(Url, Id, ReqBody), + TimerRef = erlang:start_timer(?RETRY_INTERVAL, self(), {repost_ticker, Id, ReqBody}), - {noreply, State#state{id = Id + 1, timer_map = maps:put(Id, TimerRef, TimerMap)}} - catch _:Err:Stack -> - lager:notice("[iot_jinzhi_endpoint] format_event get error: ~p, stack: ~p", [Err, Stack]), - {noreply, State} - end. + {noreply, State#state{id = Id + 1, timer_map = maps:put(Id, TimerRef, TimerMap)}}. %% @private %% @doc Handling all non call/cast messages @@ -190,20 +185,9 @@ format_event(LocationCode, DynamicLocationCode, EventType, #{<<"event_code">> := end, Attachments0), % <<"occurrenceTime">> => <<"2023-06-10 12:00:00">>, - % TODO delete - FakeLocationCodes = application:get_env(iot, fake_location_codes, []), - LocationCode1 = case length(FakeLocationCodes) > 0 of - true -> - Len = length(FakeLocationCodes), - RandomIndex = rand:uniform(Len), - Code = lists:nth(RandomIndex, FakeLocationCodes), - list_to_binary(Code); - false -> - LocationCode - end, DeviceInfo = #{ % <<"location">> => LocationCode, - <<"location">> => LocationCode1, + <<"location">> => fake_location_code(EventCode, LocationCode), <<"category">> => EventCode, <<"description">> => Description, <<"occurrenceTime">> => Datetime, @@ -277,4 +261,10 @@ serialize0([{K, V}|T], Target) -> <<$[, V0/binary, $]>> end, Item = <<$", K/binary, $", $:, V1/binary>>, - serialize0(T, [Item|Target]). \ No newline at end of file + serialize0(T, [Item|Target]). + + +fake_location_code(EventCode, LocationCode) when is_binary(EventCode), is_binary(LocationCode) -> + % TODO delete + FakeLocationCodes = application:get_env(iot, fake_location_codes, []), + proplists:get_value(EventCode, FakeLocationCodes, LocationCode). \ No newline at end of file diff --git a/config/sys-prod.config b/config/sys-prod.config index 11bf0d8..36b1554 100644 --- a/config/sys-prod.config +++ b/config/sys-prod.config @@ -15,7 +15,11 @@ {device_cache_size, 200}, {fake_location_codes, [ - "0508103010001050300001" + {<<"23103">>, <<"0508103010001050300001">>}, + {<<"20407">>, <<"0512104030001050400003">>}, + {<<"10404">>, <<"0507106030001050600003">>}, + {<<"22503">>, <<"0500000000001022700537">>}, + {<<"23104">>, <<"0500000000001022700538">>} ]}, {watchdog, [ diff --git a/docs/jinzhi.md b/docs/jinzhi.md new file mode 100644 index 0000000..b4e6bd5 --- /dev/null +++ b/docs/jinzhi.md @@ -0,0 +1,15 @@ +# 事件分类 + +```text +23103 鼠类监测 event_code: +20407 异物占道 event_code: +10404 垃圾溢满 event_code: +22503 后厨非标着装 event_code: +23104 动火离人 event_code: +``` + +1、鼠类检测 0508103010001050300001 朴苑餐厅 +2、异物占道 0512104030001050400003 行政楼B楼 +3、垃圾溢满 0507106030001050600003 朴苑3舍 +4、后厨非标着装 0500000000001022700537 监控摄像头532(诚苑餐厅 北侧) +5、动火离人 0500000000001022700538 监控摄像头533(诚苑餐厅 北侧) \ No newline at end of file diff --git a/docs/jinzhi_http.md b/docs/jinzhi_http.md deleted file mode 100644 index f7d52e3..0000000 --- a/docs/jinzhi_http.md +++ /dev/null @@ -1,9 +0,0 @@ -# 事件分类 - -```text -23103 鼠类监测 -20407 异物占道 -10404 垃圾溢满 -22503 后厨非标着装 -23104 动火离人 -```