mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-11-30 11:17:48 +08:00
feat: get_upgrade
This commit is contained in:
parent
90d1035512
commit
3623170264
@ -68,7 +68,7 @@
|
||||
request/5,
|
||||
get_token/1,
|
||||
get_qs/1,
|
||||
update/0
|
||||
update/1
|
||||
]).
|
||||
|
||||
-export([
|
||||
@ -93,7 +93,7 @@ get_schemas_json() ->
|
||||
|
||||
%% dgiot_parse:update_schemas(Fields).
|
||||
update_schemas_json() ->
|
||||
io:format("~s ~p ~p~n", [?FILE, ?LINE, <<"update_schemas_json start">>]),
|
||||
%% io:format("~s ~p ~p~n", [?FILE, ?LINE, <<"update_schemas_json start">>]),
|
||||
%% API更新
|
||||
dgiot_install:generate_rule([{<<"webname">>, #{name => dgiot_apihub}}]),
|
||||
%% 物模型更新
|
||||
@ -110,11 +110,29 @@ update_schemas_json() ->
|
||||
end, #{}, Fields)
|
||||
end, #{}, Schemas).
|
||||
|
||||
update() ->
|
||||
%% 发通知异步调用更新
|
||||
ChannelId = dgiot_parse_id:get_channelid(dgiot_utils:to_binary(?BACKEND_CHL), <<"DEVICE">>, <<"Device缓存通道"/utf8>>),
|
||||
dgiot_channelx:do_message(ChannelId, {update_schemas_json}),
|
||||
ok.
|
||||
update(SessionToken) ->
|
||||
case dgiot_auth:get_session(SessionToken) of
|
||||
#{<<"roles">> := Roles} ->
|
||||
Flag =
|
||||
maps:fold(
|
||||
fun
|
||||
(_RoleId, #{<<"level">> := Level}, _Acc1) when Level < 3 ->
|
||||
%% 发通知异步调用更新
|
||||
ChannelId = dgiot_parse_id:get_channelid(dgiot_utils:to_binary(?BACKEND_CHL), <<"DEVICE">>, <<"Device缓存通道"/utf8>>),
|
||||
dgiot_channelx:do_message(ChannelId, {update_schemas_json}),
|
||||
true;
|
||||
(_, _, _) ->
|
||||
false
|
||||
end, false, Roles),
|
||||
case Flag of
|
||||
true ->
|
||||
{ok, #{<<"msg">> => <<"success">>}};
|
||||
_ ->
|
||||
{ok, #{<<"code">> => 201, <<"msg">> => <<"请使用开发者账号"/utf8>>}}
|
||||
end;
|
||||
_ ->
|
||||
{ok, #{<<"code">> => 201, <<"msg">> => <<"请使用开发者账号"/utf8>>}}
|
||||
end.
|
||||
|
||||
health() ->
|
||||
health(?DEFAULT).
|
||||
|
@ -274,7 +274,7 @@ refresh_session(Token) ->
|
||||
get_roleuser(Filter, SessionToken) ->
|
||||
IncludeChild = maps:get(<<"include">>, Filter, false),
|
||||
%% io:format("~s ~p Filter ~p IncludeChild ~p ~n", [?FILE, ?LINE, Filter, IncludeChild]),
|
||||
case dgiot_parse:query_object(<<"_Role">>, maps:without([<<"include">>],Filter),
|
||||
case dgiot_parse:query_object(<<"_Role">>, maps:without([<<"include">>], Filter),
|
||||
[{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
|
||||
{ok, #{<<"results">> := Roles}} ->
|
||||
Users =
|
||||
@ -428,7 +428,7 @@ get_role(UserId, SessionToken) ->
|
||||
get_role(?DEFAULT, UserId, SessionToken).
|
||||
get_role(Name, UserId, SessionToken) ->
|
||||
Query = #{
|
||||
<<"keys">> => [<<"name">>, <<"alias">>, <<"org_type">>, <<"tag">>],
|
||||
<<"keys">> => [<<"name">>, <<"alias">>, <<"org_type">>, <<"tag">>, <<"level">>],
|
||||
<<"where">> => #{
|
||||
<<"users">> => #{
|
||||
<<"className">> => <<"_User">>,
|
||||
@ -441,8 +441,8 @@ get_role(Name, UserId, SessionToken) ->
|
||||
{ok, #{<<"results">> := RoleResults}} ->
|
||||
Roles =
|
||||
lists:foldr(
|
||||
fun(#{<<"objectId">> := RoleId, <<"name">> := Name1, <<"alias">> := Alias, <<"org_type">> := Org_type} = X, Acc) ->
|
||||
Role = #{<<"objectId">> => RoleId, <<"name">> => Name1, <<"alias">> => Alias, <<"org_type">> => Org_type, <<"tag">> => maps:get(<<"tag">>, X, #{})},
|
||||
fun(#{<<"objectId">> := RoleId, <<"name">> := Name1, <<"alias">> := Alias, <<"org_type">> := Org_type, <<"level">> := Level} = X, Acc) ->
|
||||
Role = #{<<"objectId">> => RoleId, <<"name">> => Name1, <<"alias">> => Alias, <<"org_type">> => Org_type, <<"tag">> => maps:get(<<"tag">>, X, #{}), <<"level">> => Level},
|
||||
Acc#{RoleId => Role}
|
||||
end, #{}, RoleResults),
|
||||
RoleIds =
|
||||
|
@ -111,11 +111,13 @@ do_request(get_health, _Body, _Context, _Req) ->
|
||||
{ok, #{<<"msg">> => <<"success">>}};
|
||||
|
||||
%% 数据库升级
|
||||
do_request(get_upgrade, _Body, _Context, _Req) ->
|
||||
dgiot_parse:update(),
|
||||
{ok, #{<<"msg">> => <<"success">>}};
|
||||
do_request(get_upgrade, _Body, _Context, Req) ->
|
||||
Cookies = cowboy_req:parse_cookies(Req),
|
||||
SessionToken = proplists:get_value(<<"departmentToken">>, Cookies),
|
||||
%% io:format("~s ~p SessionToken = ~p.~n", [?FILE, ?LINE, SessionToken]),
|
||||
dgiot_parse:update(SessionToken);
|
||||
|
||||
|
||||
%% 服务器不支持的API接口
|
||||
do_request(_OperationId, _Args, _Context, _Req) ->
|
||||
?LOG(debug, "_Args ~p", [_Args]),
|
||||
{error, <<"Not Allowed.">>}.
|
||||
|
Loading…
Reference in New Issue
Block a user