Skip to content

Commit

Permalink
feat: bamis path add or and
Browse files Browse the repository at this point in the history
  • Loading branch information
dawnwinterLiu committed Sep 18, 2023
1 parent d6ba37e commit 1cb9e6f
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
9 changes: 9 additions & 0 deletions apps/dgiot/src/utils/dgiot_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
, binary_bits_zip/1
, zip_bin/1
, is_in_binary/2
, binary_start_with/2
, is_number/1
, modbus_crc16/1
, xor_sum/1
Expand Down Expand Up @@ -465,6 +466,14 @@ is_in_binary(Partten, Binary) ->
_ -> true
end.

binary_start_with(_Binary, <<>>) ->
true;
binary_start_with(Binary, Partten) ->
case binary:match(Binary, Partten) of
{0, _} -> true;
_ -> false
end.


reverse(Bin) -> reverse(Bin, <<>>).
reverse(<<>>, Acc) -> Acc;
Expand Down
44 changes: 38 additions & 6 deletions apps/dgiot_bamis/src/dgiot_bamis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,11 @@ delete({'after', Data}) ->
%%excludeKeys Exclude specific fields from the returned query
%%include Use on Pointer columns to return the full object
%%*/
format(#{<<"orderBy">> := OrderBy} = Data) when byte_size(OrderBy) >0->
format(#{<<"orderBy">> := OrderBy} = Data) when byte_size(OrderBy) > 0 ->
NewData = maps:without([<<"orderBy">>], Data),
format(NewData#{<<"order">> => [OrderBy]});

format(#{<<"order">> := [Order | _], <<"orderDir">> := OrderDir} = Data) when byte_size(Order) >0 ->
format(#{<<"order">> := [Order | _], <<"orderDir">> := OrderDir} = Data) when byte_size(Order) > 0 ->
NewData = maps:without([<<"orderDir">>], Data),
NewOrder =
case OrderDir of
Expand Down Expand Up @@ -188,7 +188,7 @@ format(OldData) ->
{ok, Object} ->
NewWhere = format_multilayer(Object),
%% io:format("~s ~p NewWhere= ~p ~n", [?FILE, ?LINE, NewWhere]),
maps:merge(OldData, #{<<"where">> =>NewWhere });
maps:merge(OldData, #{<<"where">> => NewWhere});
_ ->
OldData
end,
Expand Down Expand Up @@ -227,14 +227,42 @@ format_multilayer(Object) ->
Acc;
_ ->
NewV = format_value(V),
Acc#{K => NewV}
NewK = format_value(K),
Acc#{NewK => NewV}
end;
(K, V, Acc) ->
(K, V, Acc) when is_list(V) ->
NewK = format_value(K),
NewV =
lists:foldl(fun
(V1, Acc1) when is_map(V1) ->
Fv = format_multilayer(V1),
case length(maps:values(Fv)) > 0 of
true ->
Acc1 ++ [Fv];
_ ->
Acc1
end;
(V2, Acc1) ->
case size(dgiot_utils:to_binary(V2)) of
0 ->
Acc1;
_ ->
Acc1 ++ [V2]
end
end, [], V),
case length(NewV) > 0 of
true ->
Acc#{NewK => NewV};
_ ->
Acc
end;
(K, V, Acc) ->
case size(dgiot_utils:to_binary(V)) of
0 ->
Acc;
_ ->
Acc#{K => V}
NewK = format_value(K),
Acc#{NewK => V}
end
end,
#{}, MapWhere).
Expand All @@ -252,5 +280,9 @@ format_value(#{<<"regex">> := V}) ->
#{<<"$regex">> => V};
format_value(#{<<"in">> := V}) ->
#{<<"$in">> => V};
format_value(<<"or">>) ->
<<"$or">>;
format_value(<<"and">>) ->
<<"$and">>;
format_value(V) ->
V.
5 changes: 5 additions & 0 deletions apps/dgiot_http/src/wechat/dgiot_wechat.erl
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,11 @@ sendSubscribe(UserId, Template_id, Data, Page) ->
%% io:format("~s ~p Subscribe = ~p.~n", [?FILE, ?LINE, Subscribe]),
_R = httpc:request(post, {SubscribeUrl, [], "application/x-www-form-urlencoded", Data1}, [{timeout, 5000}, {connect_timeout, 10000}], [{body_format, binary}]),
%% io:format("~s ~p R = ~p.~n", [?FILE, ?LINE, R]),
dgiot_parse:create_object(<<"Log">>, #{
<<"clientid">> => UserId,
<<"mfa">> => SubscribeUrl,
<<"msg">> => jiffy:encode(Subscribe)
}),
{ok, UserId};
_Result ->
{error, <<"not find access_token">>}
Expand Down
8 changes: 7 additions & 1 deletion apps/dgiot_modbus/src/dgiot_modbus_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,13 @@ get_app(Products) ->
_ -> false
end
end,
[<<"role:", App/binary>> | _] = lists:filter(Predicate, maps:keys(Acl)),
App =
case lists:filter(Predicate, maps:keys(Acl)) of
[<<"role:", Name/binary>> | _] ->
Name;
_ ->
<<"dgiot">>
end,
{ProdcutId, App}
end, Products).

Expand Down
2 changes: 1 addition & 1 deletion apps/dgiot_task/src/dgiot_task_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ send_msg(#dclient{channel = ChannelId, userdata = #device_task{ref = Ref, produc
case X of
{InstructOrder, _, Identifier1, DataSource} ->
Topic = <<"$dg/device/", Product/binary, "/", DevAddr/binary, "/properties">>,
Payload = jsx:encode(DataSource),
Payload = jsx:encode(DataSource#{<<"identifier">> => Identifier1}),
%% io:format("~s ~p DataSource = ~p.~n", [?FILE, ?LINE, DataSource]),
dgiot_mqtt:publish(dgiot_utils:to_binary(ChannelId), Topic, Payload),
dgiot_bridge:send_log(dgiot_utils:to_binary(ChannelId), Product, DevAddr, "~s ~p to dev => ~ts: ~ts", [?FILE, ?LINE, unicode:characters_to_list(Topic), unicode:characters_to_list(jsx:encode(DataSource))]),
Expand Down
2 changes: 1 addition & 1 deletion dgiot_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1610,7 +1610,7 @@ deploy_dgiot
echo -e "$(date +%F_%T) $LINENO: ${BLUE} database login info${NC}"
echo -e "$(date +%F_%T) $LINENO: ${BLUE} pg_info: postgres://postgres:${pg_auth}@${pg_eip}:7432/parse${NC}"
echo -e "$(date +%F_%T) $LINENO: ${BLUE} pg_info: pg_eip=${pg_eip} pg_auth=${pg_auth}${NC}"
echo -e "$(date +%F_%T) $LINENO: ${BLUE} parse_info: http://${wlanip}:1337/dashboard/ ${NC}"
echo -e "$(date +%F_%T) $LINENO: ${BLUE} parse_info: http://${wlanip}:1337/dashboard/# ${NC}"
echo -e "$(date +%F_%T) $LINENO: ${BLUE} parse_info: username=${parse_user} password=${parse_pwd} ${NC}"
echo -e "$(date +%F_%T) $LINENO: ${BLUE} dashboard: http://${wlanip}/# ${NC}"
echo -e "$(date +%F_%T) $LINENO: ${BLUE} dashboard: username=dgiot_dev password=dgiot_dev ${NC}"
Expand Down

0 comments on commit 1cb9e6f

Please sign in to comment.