fix: add get_table

This commit is contained in:
jhonliu 2022-05-04 16:37:24 +08:00
parent f9bb15506f
commit 5d455efd4c
9 changed files with 141 additions and 90 deletions

View File

@ -15,14 +15,10 @@
{dgiot_task, {{enable_plugin_dgiot_task}}}.
{dgiot_http, {{enable_plugin_dgiot_http}}}.
{dgiot_ffmpeg, {{enable_plugin_dgiot_ffmpeg}}}.
{dgiot_license, {{enable_plugin_dgiot_license}}}.
{dgiot_topo, {{enable_plugin_dgiot_topo}}}.
{dgiot_opc, {{enable_plugin_dgiot_opc}}}.
{dgiot_meter, {{enable_plugin_dgiot_meter}}}.
{dgiot_matlab, {{enable_plugin_dgiot_matlab}}}.
{dgiot_niisten, {{enable_plugin_dgiot_niisten}}}.
{dgiot_modbus, {{enable_plugin_dgiot_modbus}}}.
{dgiot_group, {{enable_plugin_dgiot_group}}}.
{dgiot_bamis, {{enable_plugin_dgiot_bamis}}}.
{dgiot_dlink, {{enable_plugin_dgiot_dlink}}}.
{dgiot_hjt212, {{enable_plugin_dgiot_hjt212}}}.

View File

@ -200,28 +200,27 @@ overlay_vars_rel(RelType) ->
, {enable_plugin_emqx_retainer, true}
, {enable_plugin_emqx_web_hook, true}
, {enable_plugin_emqx_telemetry, true}
%% dgiot base plugin
, {enable_plugin_dgiot, true}
, {enable_plugin_dgiot_bridge, true}
, {enable_plugin_dgiot_parse, true}
, {enable_plugin_dgiot_api, true}
, {enable_plugin_dgiot_device, true}
, {enable_plugin_dgiot_license, true}
, {enable_plugin_dgiot_evidence, true}
, {enable_plugin_dgiot_tdengine, true}
, {enable_plugin_dgiot_task, true}
, {enable_plugin_dgiot_device, true}
%% dgiot base plugin
, {enable_plugin_dgiot_http, true}
, {enable_plugin_dgiot_topo, true}
, {enable_plugin_dgiot_opc, true}
, {enable_plugin_dgiot_meter, true}
, {enable_plugin_dgiot_matlab, true}
, {enable_plugin_dgiot_niisten, true}
, {enable_plugin_dgiot_modbus, true}
, {enable_plugin_dgiot_group, true}
, {enable_plugin_dgiot_ffmpeg, true}
, {enable_plugin_dgiot_gb26875, true}
, {enable_plugin_dgiot_dlink, true}
, {enable_plugin_dgiot_bamis, true}
, {enable_plugin_dgiot_iq60, true}
, {enable_plugin_dgiot_evidence, true}
, {enable_plugin_dgiot_opc, true}
, {enable_plugin_dgiot_meter, true}
, {enable_plugin_dgiot_modbus, true}
, {enable_plugin_dgiot_ffmpeg, true}
, {enable_plugin_dgiot_gb26875, true}
, {enable_plugin_dgiot_hjt212, true}
, {enable_plugin_dgiot_bacnet, true}
, {vm_args_file, VmArgs}
].
@ -334,27 +333,24 @@ relx_plugin_apps_per_rel(cloud) ->
, emqx_psk_file
, emqx_auth_mnesia
, dgiot
, dgiot_parse
, dgiot_api
, dgiot_parse
, dgiot_bridge
, dgiot_device
, dgiot_tdengine
, dgiot_evidence
, dgiot_license
, dgiot_task
, dgiot_http
, dgiot_task
, dgiot_dlink
, dgiot_topo
, dgiot_bamis
, dgiot_evidence
, dgiot_opc
, dgiot_meter
, dgiot_matlab
, dgiot_niisten
, dgiot_modbus
, dgiot_group
, dgiot_ffmpeg
, dgiot_gb26875
, dgiot_dlink
, dgiot_bamis
, dgiot_iq60
, dgiot_hjt212
, dgiot_bacnet
];
relx_plugin_apps_per_rel(edge) ->
[].

View File

@ -169,6 +169,18 @@
"description": "更新{{tag}}的ID",
"required": true
},
{
"in": "path",
"name": "mode",
"type": "string",
"default": "REPLACE",
"enum": [
"MERGE",
"REPLACE"
],
"description": "{{tag}}的更新模式,MERGE: 增量替换, REPLACE: 全量替换",
"required": false
},
{
"in": "body",
"name": "body",

View File

@ -7,7 +7,7 @@
],
"definitions": {},
"paths": {
"/group":{
"/profile":{
"post": {
"description": "创建分组",
"parameters": [

View File

@ -257,6 +257,18 @@
"description": "更新{{tag}}的ID",
"required": true
},
{
"in": "path",
"name": "mode",
"type": "string",
"default": "REPLACE",
"enum": [
"MERGE",
"REPLACE"
],
"description": "{{tag}}的更新模式,MERGE: 增量替换, REPLACE: 全量替换",
"required": false
},
{
"in": "body",
"name": "body",

View File

@ -338,6 +338,35 @@
"Basic"
]
}
},
"/table": {
"get": {
"security": [],
"summary": "获取parse表名",
"description": "获取parse表名",
"parameters": [
],
"responses": {
"200": {
"description": "Returns operation status"
},
"400": {
"description": "Bad Request"
},
"401": {
"description": "Unauthorized"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Data"
]
}
}
}
}

View File

@ -106,6 +106,11 @@ do_request(post_batch, Body, #{base_path := BasePath} = _Context, Req) ->
do_request(get_health, _Body, _Context, Req) ->
{200, #{<<"content-type">> => <<"text/plain">>}, <<"ok">>, Req};
%% OperationId:get_table
%% :GET /iotapi/table
do_request(get_table, _Args, _Context, _Req) ->
dgiot_parse:get_schemas();
%% API接口
do_request(_OperationId, _Args, _Context, _Req) ->
?LOG(debug, "_Args ~p", [_Args]),

View File

@ -102,7 +102,7 @@ init(?TYPE, ChannelId, Args) ->
<<"products">> => Products,
<<"args">> => NewArgs}
},
%% dgiot_parse_hook:subscribe(<<"Device/*">>, put, ChannelId),
dgiot_parse_hook:subscribe(<<"Device/*">>, put, [<<"profile">>], ChannelId),
{ok, State, []}.
handle_init(#state{id = _ChannelId, env = #{<<"products">> := _Products, <<"args">> := _Args}} = State) ->
@ -127,13 +127,10 @@ handle_message({check_profile, _Args}, State) ->
%%<<\"248e9007bf\">>
%% }
%%#state{env = #{<<"args">> := #{<<"mode">> := <<"incremental">>}}} =
handle_message({sync_parse, put, _Table, _BeforeData, AfterData, DeviceId}, #state{env = #{<<"args">> := #{<<"mode">> := <<"incremental">>}}} = State) ->
dgiot_task_hook:put('after',AfterData, DeviceId, <<"incremental">>),
handle_message({sync_parse, _Pid, 'after', put, _Header, <<"Device">>, QueryData}, State) ->
dgiot_task_hook:put('after',QueryData),
{ok, State};
handle_message({sync_parse, put, _Table, _Data, AfterData, DeviceId}, State) ->
dgiot_task_hook:put('after', AfterData, DeviceId, <<"">>),
{ok, State};
handle_message(_Message, State) ->
%% ?LOG(info, "_Message ~p", [_Message]),

View File

@ -19,7 +19,7 @@
-include("dgiot_task.hrl").
-include_lib("dgiot_bridge/include/dgiot_bridge.hrl").
-include_lib("dgiot/include/logger.hrl").
-export([post/2, put/4, delete/3]).
-export([post/2, put/2, delete/3]).
post('before', _BeforeData) ->
@ -27,64 +27,68 @@ post('before', _BeforeData) ->
post('after', _AfterData) ->
ok.
put('before', _BeforeData, _ProductId, _Env) ->
ok;
put('after', AfterData, DeviceId, <<"incremental">>) ->
case jsx:decode(AfterData, [{labels, binary}, return_maps]) of
#{<<"profile">> := Profile, <<"devaddr">> := Devaddr, <<"product">> := #{<<"objectId">> := ProductId}} ->
Modifyprofile = get_modifyprofile(DeviceId, Profile),
%%
case dgiot_device:get_online(DeviceId) of
true ->
Topic = <<"profile/", ProductId/binary, "/", Devaddr/binary>>,
dgiot_mqtt:publish(DeviceId, Topic, jsx:encode(Modifyprofile)),
dgiot_data:insert(?PROFILE, DeviceId, Profile);
false ->
dgiot_data:insert(?MODIFYPROFILE, DeviceId, {Profile, ProductId, Devaddr})
end;
_ ->
pass
end,
put('before', _BeforeData) ->
ok;
put('after', #{<<"profile">> := Profile, <<"devaddr">> := Devaddr, <<"product">> := #{<<"objectId">> := ProductId}}, DeviceId, _) ->
%%
case dgiot_device:get_online(DeviceId) of
true ->
case dgiot_parse:get_object(<<"Product">>, ProductId) of
{ok, #{<<"name">> := ProductName, <<"thing">> := #{<<"properties">> := Properties}}} ->
NewPayLoad =
lists:foldl(fun(X, Acc) ->
case X of
#{<<"identifier">> := Identifier, <<"name">> := Name, <<"accessMode">> := <<"rw">>, <<"dataForm">> := DataForm, <<"dataSource">> := #{<<"_dlinkindex">> := Index} = DataSource} ->
case maps:find(Identifier, Profile) of
{ok, V} ->
Acc#{
Index => #{
%% <<"sessiontoken">> => Sessiontoken,
<<"value">> => V,
<<"identifier">> => Identifier,
<<"name">> => Name,
<<"productname">> => ProductName,
<<"dataSource">> => DataSource,
<<"dataForm">> => DataForm
}};
_ ->
Acc
end;
_ -> Acc
end
end, #{}, Properties),
Topic = <<"profile/", ProductId/binary, "/", Devaddr/binary>>,
dgiot_mqtt:publish(DeviceId, Topic, jsx:encode(NewPayLoad)),
%% io:format("~s ~p NewPayLoad = ~p.~n", [?FILE, ?LINE, NewPayLoad]),
dgiot_data:insert(?PROFILE, DeviceId, Profile);
false ->
dgiot_data:insert(?MODIFYPROFILE, DeviceId, {Profile, ProductId, Devaddr})
end;
_ ->
pass
end.
put('after', _AfterData) ->
pass.
%%put('after', AfterData, DeviceId, <<"incremental">>) ->
%% case jsx:decode(AfterData, [{labels, binary}, return_maps]) of
%% #{<<"profile">> := Profile, <<"devaddr">> := Devaddr, <<"product">> := #{<<"objectId">> := ProductId}} ->
%% Modifyprofile = get_modifyprofile(DeviceId, Profile),
%%%%
%% case dgiot_device:get_online(DeviceId) of
%% true ->
%% Topic = <<"profile/", ProductId/binary, "/", Devaddr/binary>>,
%% dgiot_mqtt:publish(DeviceId, Topic, jsx:encode(Modifyprofile)),
%% dgiot_data:insert(?PROFILE, DeviceId, Profile);
%% false ->
%% dgiot_data:insert(?MODIFYPROFILE, DeviceId, {Profile, ProductId, Devaddr})
%% end;
%% _ ->
%% pass
%% end,
%% ok;
%%put('after', #{<<"profile">> := Profile, <<"devaddr">> := Devaddr, <<"product">> := #{<<"objectId">> := ProductId}}, DeviceId, _) ->
%%%%
%% case dgiot_device:get_online(DeviceId) of
%% true ->
%% case dgiot_parse:get_object(<<"Product">>, ProductId) of
%% {ok, #{<<"name">> := ProductName, <<"thing">> := #{<<"properties">> := Properties}}} ->
%% NewPayLoad =
%% lists:foldl(fun(X, Acc) ->
%% case X of
%% #{<<"identifier">> := Identifier, <<"name">> := Name, <<"accessMode">> := <<"rw">>, <<"dataForm">> := DataForm, <<"dataSource">> := #{<<"_dlinkindex">> := Index} = DataSource} ->
%% case maps:find(Identifier, Profile) of
%% {ok, V} ->
%% Acc#{
%% Index => #{
%%%% <<"sessiontoken">> => Sessiontoken,
%% <<"value">> => V,
%% <<"identifier">> => Identifier,
%% <<"name">> => Name,
%% <<"productname">> => ProductName,
%% <<"dataSource">> => DataSource,
%% <<"dataForm">> => DataForm
%% }};
%% _ ->
%% Acc
%% end;
%% _ -> Acc
%% end
%% end, #{}, Properties),
%% Topic = <<"profile/", ProductId/binary, "/", Devaddr/binary>>,
%% dgiot_mqtt:publish(DeviceId, Topic, jsx:encode(NewPayLoad)),
%%%% io:format("~s ~p NewPayLoad = ~p.~n", [?FILE, ?LINE, NewPayLoad]),
%% dgiot_data:insert(?PROFILE, DeviceId, Profile);
%% false ->
%% dgiot_data:insert(?MODIFYPROFILE, DeviceId, {Profile, ProductId, Devaddr})
%% end;
%% _ ->
%% pass
%% end.
delete('before', _BeforeData, _ProductId) ->
ok;