feat: dashboard_work

This commit is contained in:
dawnwinterLiu 2024-09-12 17:16:56 +08:00
parent 2aca3d45f1
commit 801d9bcbfa
3 changed files with 18 additions and 7 deletions

View File

@ -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 ->
{<<DB/binary, "_", ProductId/binary>>, <<"1=1">>, <<"_", ProductId/binary>>};
Subs when length(Subs) > 1 ->
dgiot_device_tdengine:get_tablename(DB, Subs);
_ ->
{<<DB/binary, "_", ProductId/binary>>, <<"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}} ->

View File

@ -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) ->

View File

@ -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.