diff --git a/apps/dgiot_device/src/utils/dgiot_device_static.erl b/apps/dgiot_device/src/utils/dgiot_device_static.erl index 10d4a8f8..a41e6d8a 100644 --- a/apps/dgiot_device/src/utils/dgiot_device_static.erl +++ b/apps/dgiot_device/src/utils/dgiot_device_static.erl @@ -141,9 +141,18 @@ get_realdata({Token, Realdatas}) when is_map(Realdatas) -> {error, Error} -> {error, Error}; {ok, Channel} -> - {_, Newkeys} = dgiot_product_tdengine:get_keys(ProductId, <<"_", ProductId/binary>>, <<"last">>, Keys), DB = dgiot_tdengine:get_database(Channel, ProductId), - Sql1 = <<"select last(devaddr) as devaddr,", Newkeys/binary, " FROM ", DB/binary, "_", ProductId/binary, " group by devaddr;">>, + {TableName, DefWhere, FirstTableName} = + case dgiot_product:get_sub_tab(ProductId) of + not_find -> + {<>, <<"1=1">>, <<"_", ProductId/binary>>}; + Subs when length(Subs) > 1 -> + dgiot_device_tdengine:get_tablename(DB, Subs); + _ -> + {<>, <<"1=1">>, <<"_", ProductId/binary>>} + end, + {_, Newkeys} = dgiot_product_tdengine:get_keys(ProductId, FirstTableName, <<"">>, Keys), + Sql1 = <<"SELECT ", FirstTableName/binary, ".devaddr,", Newkeys/binary, " FROM ", TableName/binary, " where ", DefWhere/binary, " order by ", FirstTableName/binary, ".createdat desc limit 1;">>, %% io:format("Channel = ~p.~n Sql = ~p.~n", [Channel, Sql1]), case dgiot_device_static:query_realdata(Channel, Sql1) of {ok, #{<<"code">> := 0, <<"results">> := Results1}} -> diff --git a/apps/dgiot_tdengine/src/utils/dgiot_device_tdengine.erl b/apps/dgiot_tdengine/src/utils/dgiot_device_tdengine.erl index f9ab80dc..cbe497f3 100644 --- a/apps/dgiot_tdengine/src/utils/dgiot_device_tdengine.erl +++ b/apps/dgiot_tdengine/src/utils/dgiot_device_tdengine.erl @@ -23,7 +23,7 @@ -export([get_device/3, get_device/4, get_device/5]). -export([get_history_data/4, get_realtime_data/4, get_gps_track/4]). --export([get_history_data2/7]). +-export([get_history_data2/7, get_tablename/2]). %% #{<<"keys">> => <<"last_row(*)">>, <<"limit">> => 1} 查询td最新的一条device get_device(ProductId, DevAddr, Query) -> diff --git a/apps/dgiot_topo/src/dashboard_worker.erl b/apps/dgiot_topo/src/dashboard_worker.erl index 84f2d2fd..ba340472 100644 --- a/apps/dgiot_topo/src/dashboard_worker.erl +++ b/apps/dgiot_topo/src/dashboard_worker.erl @@ -34,13 +34,15 @@ start_link(#{<<"dashboardId">> := DashboardId, <<"sessionToken">> := SessionToke {ok, Pid} when is_pid(Pid) -> case is_process_alive(Pid) of true -> - ok; + gen_server:call(Pid, stop, 5000), + erlang:garbage_collect(Pid); false -> - gen_server:start_link(?MODULE, [State], []) + pass end; _Reason -> - gen_server:start_link(?MODULE, [State], []) - end; + pass + end, + gen_server:start_link(?MODULE, [State], []); start_link(_State) -> ok.