feat: group

This commit is contained in:
dawnwinterLiu 2024-10-15 15:18:23 +08:00
parent 801d9bcbfa
commit 6bdf2c1f37
3 changed files with 84 additions and 8 deletions

View File

@ -50,13 +50,17 @@ get_hostname() ->
unicode:characters_to_binary(Hostname).
get_natip() ->
IpList = lists:foldl(fun({_, [{A, B, C, D}]}, Acc) ->
Acc
++ [to_list(A) ++ "."]
++ [to_list(B) ++ "."]
++ [to_list(C) ++ "."]
++ [to_list(D) ++ " "]
end, [], get_ifaddrs()),
IpList = lists:foldl(
fun
({_, [{A, B, C, D}]}, Acc) ->
Acc
++ [to_list(A) ++ "."]
++ [to_list(B) ++ "."]
++ [to_list(C) ++ "."]
++ [to_list(D) ++ " "];
(_, Acc) ->
Acc
end, [], get_ifaddrs()),
to_binary(IpList).
get_wlanip() ->

View File

@ -238,7 +238,7 @@
{
"description": "创建分组,自动创建虚拟组设备,无物模型",
"in": "body",
"name": "group",
"name": "sports",
"required": true,
"schema": {
"properties": {
@ -275,6 +275,51 @@
"Group"
]
}
},
"/dev_transfer": {
"post": {
"description": "设备迁移",
"parameters": [
{
"description": "设备迁移",
"in": "body",
"name": "group",
"required": true,
"schema": {
"properties": {
"objectId": {
"description": "设备Id",
"type": "string",
"example": "3655a61cc1"
},
"rolename": {
"description": "部门名称",
"type": "string",
"example": "test"
}
}
}
}
],
"responses": {
"200": {
"description": "Returns operation status"
},
"400": {
"description": "Bad Request"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"summary": "设备迁移",
"tags": [
"Group"
]
}
}
}
}

View File

@ -71,6 +71,33 @@ handle(OperationID, Args, Context, Req) ->
{Status, maps:merge(Headers, NewHeaders), Res, Req}
end.
%%
do_request(post_dev_transfer, #{<<"objectId">> := ObjectId, <<"rolename">> := RoleName} = _Args, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
ACL = #{<<"role:", RoleName/binary>> => #{<<"read">> => true, <<"write">> => true}},
case dgiot_parsex:get_object(<<"Device">>, ObjectId) of
{ok, #{<<"name">> := DevName}} ->
case dgiot_parsex:update_object(<<"Device">>, ObjectId, #{<<"ACL">> => ACL}) of
{ok, Data} ->
#{<<"nick">> := Nick} = dgiot_auth:get_session(SessionToken),
OldRole = dgiot_device:get_appname(ObjectId),
Msg = <<Nick/binary, " 将设备从部门【"/utf8, OldRole/binary, "】转移到新部门【"/utf8, RoleName/binary, ""/utf8>>,
dgiot_parsex:create_object(<<"Log">>, #{
<<"deviceid">> => ObjectId
, <<"msg">> => Msg
, <<"domain">> => [<<"DeviceTransfer">>]
, <<"mfa">> => <<"DeviceTransfer">>
, <<"peername">> => DevName
, <<"time">> => dgiot_datetime:nowstamp() * 1000
}),
dgiot_device:put(#{<<"objectId">> => ObjectId, <<"ACL">> => ACL}),
{ok, #{<<"data">> => Data, <<"msg">> => Msg, <<"status">> => 0}};
{_, Data} ->
{ok, #{<<"data">> => Data, <<"msg">> => <<"error">>, <<"status">> => 0}}
end;
_ ->
{ok, #{<<"msg">> => <<"not find device">>, <<"status">> => 0}}
end;
do_request(get_sports, _Args, _Context, _Req) ->
Items =