Skip to content

Commit

Permalink
â�feat: get_devicedict
Browse files Browse the repository at this point in the history
  • Loading branch information
h7ml committed Jun 29, 2021
1 parent 2a3c26e commit 6159414
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
29 changes: 28 additions & 1 deletion apps/dgiot_topo/priv/swagger/swagger_topo.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,33 @@
"TOPO"
]
}
},
"/devicedict": {
"get": {
"description": "查询设备参数字典",
"parameters": [
{
"in": "query",
"name": "deviceid",
"required": true
}
],
"responses": {
"200": {
"description": "Returns instance data"
},
"404": {
"description": "object not found",
"schema": {
"$ref": "#/definitions/Error"
}
}
},
"summary": "查询设备参数字典",
"tags": [
"TOPO"
]
}
}
},
"tags": [
Expand All @@ -198,4 +225,4 @@
"description": "云组态"
}
]
}
}
19 changes: 14 additions & 5 deletions apps/dgiot_topo/src/dgiot_topo_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -50,23 +50,23 @@ handle(OperationID, Args, Context, Req) ->
Headers = #{},
case catch do_request(OperationID, Args, Context, Req) of
{ErrType, Reason} when ErrType == 'EXIT'; ErrType == error ->
?LOG(info,"do request: ~p, ~p, ~p~n", [OperationID, Args, Reason]),
?LOG(info, "do request: ~p, ~p, ~p~n", [OperationID, Args, Reason]),
Err = case is_binary(Reason) of
true -> Reason;
false -> dgiot_utils:format("~p", [Reason])
end,
{500, Headers, #{<<"error">> => Err}};
ok ->
?LOG(debug,"do request: ~p, ~p ->ok ~n", [OperationID, Args]),
?LOG(debug, "do request: ~p, ~p ->ok ~n", [OperationID, Args]),
{200, Headers, #{}, Req};
{ok, Res} ->
?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
?LOG(info, "do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
{200, Headers, Res, Req};
{Status, Res} ->
?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
?LOG(info, "do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
{Status, Headers, Res, Req};
{Status, NewHeaders, Res} ->
?LOG(info,"do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
?LOG(info, "do request: ~p, ~p ->~p~n", [OperationID, Args, Res]),
{Status, maps:merge(Headers, NewHeaders), Res, Req}
end.

Expand Down Expand Up @@ -124,6 +124,15 @@ do_request(post_dashboard, Arg, Context, _Req) ->
dgiot_dashboard:post_dashboard(Arg, Context),
{200, <<"success">>};

do_request(get_devicedict, #{<<"deviceid">> := Deviceid}, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
%% case dgiot_parse:get_object(<<"Device">>, <<"566cf263dc">>, [{"X-Parse-Session-Token", <<"r:e53794ae4bb367b13f73ddd5891e2755">>}], [{from, rest}]) of
case dgiot_parse:get_object(<<"Device">>, Deviceid, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
{ok, #{<<"basedata">> := #{<<"deviceDict">> := DeviceDict}}} ->
{ok, DeviceDict};
_ ->
{error, []}
end;


%% 服务器不支持的API接口
do_request(_OperationId, _Args, _Context, _Req) ->
Expand Down

0 comments on commit 6159414

Please sign in to comment.