mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-02 04:08:54 +08:00
feat: get_Mobile
This commit is contained in:
parent
d070a272b0
commit
b81ec6bc32
@ -122,9 +122,9 @@ do_request(post_configuration, #{<<"data">> := Data}, _Context, _Req) ->
|
||||
Result;
|
||||
|
||||
% 设备短信发送
|
||||
do_request(post_sendsms_deviceid, #{<<"deviceid">> := DeviceId, <<"tplid">> := TplId, <<"params">> := Params} = _Args, _Context, _Req) ->
|
||||
do_request(post_sendsms_deviceid, #{<<"deviceid">> := DeviceId, <<"roleid">> := RoleId, <<"tplid">> := TplId, <<"params">> := Params} = _Args, _Context, _Req) ->
|
||||
%% io:format("~s ~p Args = ~p.~n", [?FILE, ?LINE, _Args]),
|
||||
Mobile = dgiot_notification:get_Mobile(DeviceId),
|
||||
Mobile = dgiot_notification:get_Mobile(DeviceId, RoleId),
|
||||
dgiot_notification:send_sms(Mobile, TplId, Params);
|
||||
|
||||
%数字工厂告警
|
||||
|
@ -29,7 +29,7 @@
|
||||
|
||||
-export([send_verification_code/2, check_verification_code/2]).
|
||||
|
||||
-export([get_newbody/1, get_Mobile/1]).
|
||||
-export([get_newbody/1, get_Mobile/2]).
|
||||
|
||||
init_ets() ->
|
||||
dgiot_data:init(?CONFIGURATION),
|
||||
@ -220,38 +220,54 @@ get_newbody(#{<<"objectId">> := _Notificatid} = Map) ->
|
||||
get_newbody(Body) ->
|
||||
Body.
|
||||
|
||||
get_Mobile(DeviceId) ->
|
||||
case dgiot_device:lookup(DeviceId) of
|
||||
{ok, #{<<"acl">> := Acl}} ->
|
||||
lists:foldl(fun(X, Acc) ->
|
||||
BinX = atom_to_binary(X),
|
||||
case BinX of
|
||||
<<"role:", Name/binary>> ->
|
||||
case dgiot_parse:query_object(<<"_Role">>, #{<<"order">> => <<"updatedAt">>, <<"limit">> => 1,
|
||||
<<"where">> => #{<<"name">> => Name}}) of
|
||||
{ok, #{<<"results">> := [Role]}} ->
|
||||
#{<<"objectId">> := RoleId} = Role,
|
||||
UserIds = dgiot_parse_id:get_userids(RoleId),
|
||||
UsersQuery = #{<<"where">> => #{<<"objectId">> => #{<<"$in">> => UserIds}}},
|
||||
{ok, #{<<"results">> := Users}} = dgiot_parse:query_object(<<"_User">>, UsersQuery),
|
||||
lists:foldl(fun(User, Acc1) ->
|
||||
Phone = maps:get(<<"phone">>, User, ""),
|
||||
case dgiot_utils:is_phone(Phone) of
|
||||
true ->
|
||||
Acc1 ++ [#{<<"mobile">> => Phone, <<"nationcode">> => <<"86">>}];
|
||||
_ ->
|
||||
Acc1
|
||||
end
|
||||
end, Acc, Users);
|
||||
get_Mobile(DeviceId, RoleId) ->
|
||||
case RoleId of
|
||||
<<>> ->
|
||||
case dgiot_device:lookup(DeviceId) of
|
||||
{ok, #{<<"acl">> := Acl}} ->
|
||||
lists:foldl(fun(X, Acc) ->
|
||||
BinX = atom_to_binary(X),
|
||||
case BinX of
|
||||
<<"role:", Name/binary>> ->
|
||||
case dgiot_parse:query_object(<<"_Role">>, #{<<"order">> => <<"updatedAt">>, <<"limit">> => 1,
|
||||
<<"where">> => #{<<"name">> => Name}}) of
|
||||
{ok, #{<<"results">> := [Role]}} ->
|
||||
#{<<"objectId">> := RoleId1} = Role,
|
||||
UserIds = dgiot_parse_id:get_userids(RoleId1),
|
||||
UsersQuery = #{<<"where">> => #{<<"objectId">> => #{<<"$in">> => UserIds}}},
|
||||
{ok, #{<<"results">> := Users}} = dgiot_parse:query_object(<<"_User">>, UsersQuery),
|
||||
lists:foldl(fun(User, Acc1) ->
|
||||
Phone = maps:get(<<"phone">>, User, ""),
|
||||
case dgiot_utils:is_phone(Phone) of
|
||||
true ->
|
||||
Acc1 ++ [#{<<"mobile">> => Phone, <<"nationcode">> => <<"86">>}];
|
||||
_ ->
|
||||
Acc1
|
||||
end
|
||||
end, Acc, Users);
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end
|
||||
end, [], Acl);
|
||||
end
|
||||
end, [], Acl);
|
||||
_ ->
|
||||
[]
|
||||
end;
|
||||
_ ->
|
||||
[]
|
||||
UserIds = dgiot_parse_id:get_userids(RoleId),
|
||||
UsersQuery = #{<<"where">> => #{<<"objectId">> => #{<<"$in">> => UserIds}}},
|
||||
{ok, #{<<"results">> := Users}} = dgiot_parse:query_object(<<"_User">>, UsersQuery),
|
||||
lists:foldl(fun(User, Acc1) ->
|
||||
Phone = maps:get(<<"phone">>, User, ""),
|
||||
case dgiot_utils:is_phone(Phone) of
|
||||
true ->
|
||||
Acc1 ++ [#{<<"mobile">> => Phone, <<"nationcode">> => <<"86">>}];
|
||||
_ ->
|
||||
Acc1
|
||||
end
|
||||
end, [], Users)
|
||||
end.
|
||||
|
||||
save_configuration() ->
|
||||
|
@ -34,7 +34,7 @@
|
||||
"text": "",
|
||||
"type": "paper",
|
||||
"width": 408,
|
||||
"height": 566,
|
||||
"height": 283,
|
||||
"stroke": "black",
|
||||
"opacity": 0.75,
|
||||
"fontSize": 15,
|
||||
|
Loading…
Reference in New Issue
Block a user