Skip to content

Commit

Permalink
feat: sqlTpl
Browse files Browse the repository at this point in the history
  • Loading branch information
dgiot-fe committed Mar 28, 2022
1 parent 11b4827 commit d911178
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 25 deletions.
15 changes: 1 addition & 14 deletions .pnpm-debug.log
Original file line number Diff line number Diff line change
@@ -1,14 +1 @@
{
"0 debug pnpm:scope": {
"selected": 1
},
"1 error pnpm": {
"code": "ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND",
"err": {
"name": "pnpm",
"message": "No package.json (or package.yaml, or package.json5) was found in \"D:\\msys64\\home\\h7ml\\dgiot\\dgiot\".",
"code": "ERR_PNPM_NO_IMPORTER_MANIFEST_FOUND",
"stack": "pnpm: No package.json (or package.yaml, or package.json5) was found in \"D:\\msys64\\home\\h7ml\\dgiot\\dgiot\".\n at readProjectManifest (D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:19808:13)\n at async Object.readProjectManifestOnly (D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:19812:28)\n at async readProjectManifestOnly (D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:43711:24)\n at async Object.handler (D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:177889:24)\n at async D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:182165:21\n at async run (D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:182139:34)\n at async runPnpm (D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:182358:5)\n at async D:\\software\\nodejs\\node_global\\node_modules\\pnpm\\dist\\pnpm.cjs:182350:7"
}
}
}
{}
65 changes: 54 additions & 11 deletions apps/dgiot_bridge/src/handler/dgiot_rule_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,11 @@ sql_tpl(Trigger, Condition, Action) ->
%% _ -> Acc
%% end
%% end, <<"">>, Where),
DefaultSql = <<"SELECT", "\r\n",
DefaultSql = <<"SELECT", "\r\n ",
SELECT/binary, "\r\n",
"FROM ", "\r\n",
" \"", FROM/binary, "\"", "\r\n",
"WHERE", "\r\n ",
"WHERE", "\r\n ",
WHERE/binary>>,
{ok, #{<<"template">> => DefaultSql}}.

Expand Down Expand Up @@ -470,12 +470,12 @@ generateFrom(Trigger) ->
end;
<<"trigger/mqtt/event">> ->
case Params of
#{<<"productKey">> := ProductId} ->
#{<<"productKey">> := ProductId, <<"mqtt">> := Mqtt, <<"deviceName">> := Devaddr} ->
case ProductId of
<<"">> ->
<<"$events/", ProductId/binary>>;
<<"$events/", Mqtt/binary, "/", ProductId/binary, "/", Devaddr/binary>>;
_ ->
<<"$events/", "test/#">>
<<"$events/", Mqtt/binary, "/", ProductId/binary, "/", Devaddr/binary, "/#">>
end;
_ ->
<<"$dg/user/", "test/#">>
Expand All @@ -486,13 +486,56 @@ generateFrom(Trigger) ->
<<"$dg/user/", "test/#">>
end.

generateSelect(_Condition, _Trigger, _FROM) ->
<<"SELECT">>.
generateSelect(_Condition, Trigger, _FROM) ->
%% Trigger: [
%% {
%% label: '设备属性触发',
%% value: 'trigger/product/property',
%% },
%% {
%% label: '设备事件触发',
%% value: 'trigger/product/event',
%% },
%% {
%% label: 'mqtt事件触发',
%% value: 'trigger/mqtt/event',
%% },
%% {
%% label: '定时触发',
%% value: 'trigger/timer',
%% },
%% ],
%%
Firstfrom = lists:nth(1, maps:get(<<"items">>, Trigger)),
Uri = maps:get(<<"uri">>, Firstfrom),
Params = maps:get(<<"params">>, Firstfrom, #{}),
case Uri of
<<"trigger/mqtt/event">> ->
case Params of
#{<<"mqtt">> := Mqtt} -> <<"payload.event.", Mqtt/binary, " as ", Mqtt/binary>>;
_ ->
<<"payload.event.", "test">>
end;
<<"trigger/product/property">> ->
case Params of
#{<<"propertyName">> := PropertyName} ->
<<"payload.property.", PropertyName/binary, " as ", PropertyName/binary>>;
_ ->
<<"payload.property.", "test">>
end;
<<"trigger/product/event">> ->
case Params of
#{<<"propertyName">> := PropertyName} ->
<<"payload.productevent.", PropertyName/binary, " as ", PropertyName/binary>>;
_ ->
<<"payload.productevent.", "test">>
end;
<<"trigger/timer">> -> <<"payload.cron">>;
_ ->
<<"$dg/user/", "test/#">>
end.

generateWhere(Condition, _Trigger, _FROM) ->
io:format("Condition ~p", [Condition]),
io:format("_Trigger ~p", [_Trigger]),
io:format("_FROM ~p", [_FROM]),
%% Condition: [
%% {
%% label: '状态持续时长判断',
Expand Down Expand Up @@ -526,7 +569,7 @@ generateWhere(Condition, _Trigger, _FROM) ->
case Item of
#{<<"uri">> := <<"condition/device/stateContinue">>, <<"params">> := #{
<<"state">> := State, <<"times">> := Times}} ->
Continue = <<State/binary, "= ", Times/binary>>,
Continue = <<State/binary, " = ", Times/binary>>,
case Acc of
<<"">> ->
Continue;
Expand Down

0 comments on commit d911178

Please sign in to comment.