mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-11-30 11:17:48 +08:00
do_hook_delete_product;delete_device
This commit is contained in:
parent
17de269f25
commit
dea36c5af9
@ -377,8 +377,9 @@ do_request(_OperationId, _Args, _Context, _Req) ->
|
||||
|
||||
do_report(Config, DevType, Name, SessionToken, FullPath, Uri) ->
|
||||
CategoryId = maps:get(<<"category">>, Config, <<"d6ad425529">>),
|
||||
ProductId = dgiot_parse:get_productid(CategoryId, DevType, Name),
|
||||
Producttempid = maps:get(<<"producttemplet">>, Config, <<"">>),
|
||||
case dgiot_httpc:fileUpload(Uri ++ "/WordController/fileUpload", dgiot_utils:to_list(FullPath), Producttempid) of
|
||||
case dgiot_httpc:fileUpload(Uri ++ "/WordController/fileUpload", dgiot_utils:to_list(FullPath), ProductId) of
|
||||
{ok, #{<<"code">> := 0, <<"msg">> := <<"SUCCESS">>, <<"path">> := WordPath, <<"images">> := Images}} ->
|
||||
case dgiot_product:create_product(#{
|
||||
<<"name">> => Name,
|
||||
@ -403,12 +404,13 @@ do_report(Config, DevType, Name, SessionToken, FullPath, Uri) ->
|
||||
Acc
|
||||
end
|
||||
end, [], Images);
|
||||
_ ->
|
||||
[]
|
||||
_Oth1 ->
|
||||
io:format("_Oth1 ~p~n", [_Oth1]),
|
||||
_Oth1
|
||||
end;
|
||||
_Oth ->
|
||||
io:format("_Oth ~p~n", [_Oth]),
|
||||
[]
|
||||
_Oth
|
||||
end.
|
||||
|
||||
get_paper(_ProductId, FileInfo) ->
|
||||
@ -850,7 +852,7 @@ post_report(#{<<"name">> := Name, <<"product">> := ProductId, <<"parentId">> :=
|
||||
<<"objectId">> => ParentId
|
||||
}
|
||||
}),
|
||||
case dgiot_parse:query_object(<<"View">>, #{<<"where">> => #{<<"key">> => ProductId, <<"class">> => <<"Product">>}}, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
|
||||
case dgiot_parse:query_object(<<"View">>, #{<<"order">> => <<"createdAt">>, <<"where">> => #{<<"key">> => ProductId, <<"class">> => <<"Product">>}}, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
|
||||
{ok, #{<<"results">> := Views}} ->
|
||||
ViewRequests =
|
||||
lists:foldl(fun(View, Acc) ->
|
||||
|
@ -181,8 +181,8 @@ get_notificationid(Type) ->
|
||||
<<DId:10/binary, _/binary>> = dgiot_utils:to_md5(<<"Notification", Type/binary, UUID/binary>>),
|
||||
DId.
|
||||
|
||||
get_productid(Category, DevType, Name) ->
|
||||
<<Pid:10/binary, _/binary>> = dgiot_utils:to_md5(<<"Product", Category/binary, DevType/binary, Name/binary>>),
|
||||
get_productid(Categoryid, DevType, Name) ->
|
||||
<<Pid:10/binary, _/binary>> = dgiot_utils:to_md5(<<"Product", Categoryid/binary, DevType/binary, Name/binary>>),
|
||||
Pid.
|
||||
|
||||
get_maintenanceid(Deviceid, Number) ->
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
|
||||
%% API
|
||||
-export([request/5, method/1, method/2]).
|
||||
-export([request/5, method/1, method/2, do_hook/2]).
|
||||
|
||||
%%%===================================================================
|
||||
%%% API
|
||||
|
@ -473,6 +473,12 @@ do_request_after(<<"get_login">>, 200, ResHeaders, ResBody, Context, Req) ->
|
||||
{error, ErrMsg} ->
|
||||
{500, ErrMsg}
|
||||
end;
|
||||
%% delete_classes_product_id
|
||||
%% delete_classes_device_id
|
||||
do_request_after(<<"delete_classes_", _OperationID/binary>>, 200, ResHeaders, ResBody, _Context, #{bindings := #{id := ObjectId}} = Req) ->
|
||||
dgiot_parse_rest:do_hook({_OperationID, delete}, ['after', <<"{\"objectId\" : \"", ObjectId/binary, "\"}">>, <<"">>]),
|
||||
{200, ResHeaders, ResBody, Req};
|
||||
|
||||
|
||||
do_request_after(_OperationID, StatusCode, ResHeaders, ResBody, _Context, Req) ->
|
||||
{StatusCode, ResHeaders, ResBody, Req}.
|
||||
@ -608,8 +614,8 @@ create_user(#{<<"username">> := UserName, <<"department">> := RoleId} = Body, Se
|
||||
<<"__type">> => <<"Pointer">>,
|
||||
<<"className">> => <<"_Role">>,
|
||||
<<"objectId">> => RoleId
|
||||
}]
|
||||
}}),
|
||||
}]}
|
||||
}),
|
||||
dgiot_parse:update_object(<<"_Role">>, RoleId, #{
|
||||
<<"users">> => #{
|
||||
<<"__op">> => <<"AddRelation">>,
|
||||
|
@ -206,7 +206,7 @@ handle_init(#state{id = ChannelId, env = #{<<"products">> := Products, <<"args">
|
||||
dgiot_task:load(NewArgs)
|
||||
end, Products),
|
||||
dgiot_task:timing_start(Args#{<<"channel">> => ChannelId}),
|
||||
dgiot_parse:subscribe(<<"Device">>, delete),
|
||||
dgiot_parse:subscribe(<<"device_id">>, delete),
|
||||
{ok, State}.
|
||||
|
||||
%% 通道消息处理,注意:进程池调用
|
||||
@ -215,10 +215,39 @@ handle_event(_EventId, Event, State) ->
|
||||
{ok, State}.
|
||||
|
||||
handle_message({sync_parse, Args}, State) ->
|
||||
%% io:format("DeviceArgs ~p~n", [jsx:decode(Args, [{labels, binary}, return_maps])]),
|
||||
case jsx:decode(Args, [return_maps]) of
|
||||
#{<<"objectId">> := DtuId} ->
|
||||
%% 从队列删除该设备
|
||||
dgiot_task:del_pnque(DtuId);
|
||||
dgiot_task:del_pnque(DtuId),
|
||||
case dgiot_parse:query_object(<<"Dict">>, #{<<"where">> => #{<<"key">> => DtuId, <<"class">> => <<"Device">>}}) of
|
||||
{ok, #{<<"results">> := Dicts}} ->
|
||||
DictRequests =
|
||||
lists:foldl(fun(#{<<"objectId">> := DictId}, Acc) ->
|
||||
Acc ++ [#{
|
||||
<<"method">> => <<"DELETE">>,
|
||||
<<"path">> => <<"/classes/Dict/", DictId/binary>>,
|
||||
<<"body">> => #{}
|
||||
}]
|
||||
end, [], Dicts),
|
||||
dgiot_parse:batch(DictRequests);
|
||||
_ ->
|
||||
pass
|
||||
end,
|
||||
case dgiot_parse:query_object(<<"View">>, #{<<"where">> => #{<<"key">> => DtuId, <<"class">> => <<"Device">>}}) of
|
||||
{ok, #{<<"results">> := Views}} ->
|
||||
ViewRequests =
|
||||
lists:foldl(fun(#{<<"objectId">> := ViewId}, Acc) ->
|
||||
Acc ++ [#{
|
||||
<<"method">> => <<"DELETE">>,
|
||||
<<"path">> => <<"/classes/View/", ViewId/binary>>,
|
||||
<<"body">> => #{}
|
||||
}]
|
||||
end, [], Views),
|
||||
dgiot_parse:batch(ViewRequests);
|
||||
_ ->
|
||||
pass
|
||||
end;
|
||||
_ ->
|
||||
pass
|
||||
end,
|
||||
|
@ -187,12 +187,13 @@ init(?TYPE, ChannelId, Config) ->
|
||||
Specs = [
|
||||
{dgiot_dcache, {dgiot_dcache, start_link, Opts}, permanent, 5000, worker, [dgiot_dcache]}
|
||||
],
|
||||
dgiot_metrics:dec(dgiot_tdengine,<<"tdengine">>,1000),
|
||||
dgiot_metrics:dec(dgiot_tdengine, <<"tdengine">>, 1000),
|
||||
{ok, State, Specs}.
|
||||
|
||||
handle_init(State) ->
|
||||
dgiot_metrics:inc(dgiot_tdengine,<<"tdengine">>,1),
|
||||
dgiot_metrics:inc(dgiot_tdengine, <<"tdengine">>, 1),
|
||||
erlang:send_after(5000, self(), init),
|
||||
dgiot_parse:subscribe(<<"product_id">>, delete),
|
||||
{ok, State}.
|
||||
|
||||
%% 通道消息处理,注意:进程池调用
|
||||
@ -204,6 +205,44 @@ handle_event(EventType, Event, _State) ->
|
||||
?LOG(info, "channel ~p, ~p", [EventType, Event]),
|
||||
ok.
|
||||
|
||||
handle_message({sync_parse, Args}, State) ->
|
||||
%% io:format("ProductArgs ~p~n", [jsx:decode(Args, [{labels, binary}, return_maps])]),
|
||||
case jsx:decode(Args, [return_maps]) of
|
||||
#{<<"objectId">> := ProductId} ->
|
||||
case dgiot_parse:query_object(<<"Dict">>, #{<<"where">> => #{<<"key">> => ProductId, <<"class">> => <<"Product">>}}) of
|
||||
{ok, #{<<"results">> := Dicts}} ->
|
||||
DictRequests =
|
||||
lists:foldl(fun(#{<<"objectId">> := DictId}, Acc) ->
|
||||
Acc ++ [#{
|
||||
<<"method">> => <<"DELETE">>,
|
||||
<<"path">> => <<"/classes/Dict/", DictId/binary>>,
|
||||
<<"body">> => #{}
|
||||
}]
|
||||
end, [], Dicts),
|
||||
dgiot_parse:batch(DictRequests);
|
||||
_ ->
|
||||
pass
|
||||
end,
|
||||
case dgiot_parse:query_object(<<"View">>, #{<<"where">> => #{<<"key">> => ProductId, <<"class">> => <<"Product">>}}) of
|
||||
{ok, #{<<"results">> := Views}} ->
|
||||
ViewRequests =
|
||||
lists:foldl(fun(#{<<"objectId">> := ViewId}, Acc) ->
|
||||
Acc ++ [#{
|
||||
<<"method">> => <<"DELETE">>,
|
||||
<<"path">> => <<"/classes/View/", ViewId/binary>>,
|
||||
<<"body">> => #{}
|
||||
}]
|
||||
end, [], Views),
|
||||
io:format("ViewRequests ~p~n", [ViewRequests]),
|
||||
dgiot_parse:batch(ViewRequests);
|
||||
_ ->
|
||||
pass
|
||||
end;
|
||||
_ ->
|
||||
pass
|
||||
end,
|
||||
{ok, State};
|
||||
|
||||
%% 规则引擎导入
|
||||
handle_message({rule, Msg, Context}, State) ->
|
||||
?LOG(info, "Msg ~p", [Msg]),
|
||||
@ -225,7 +264,7 @@ handle_message(init, #state{id = ChannelId, env = Config} = State) ->
|
||||
|
||||
%% 数据与产品,设备地址分离
|
||||
handle_message({data, Product, DevAddr, Data, Context}, State) ->
|
||||
dgiot_metrics:inc(dgiot_tdengine,<<"tdengine_recv">>,1),
|
||||
dgiot_metrics:inc(dgiot_tdengine, <<"tdengine_recv">>, 1),
|
||||
case catch do_save([Product, DevAddr, Data, Context], State) of
|
||||
{Err, Reason} when Err == error; Err == 'EXIT' ->
|
||||
?LOG(error, "Save to Tdengine error, ~p, ~p", [Data, Reason]),
|
||||
|
@ -154,12 +154,12 @@ handle_message({sync_parse, Args}, State) ->
|
||||
NewDict = maps:without([<<"createdAt">>, <<"objectId">>, <<"updatedAt">>], View),
|
||||
Type = maps:get(<<"type">>, View, <<"">>),
|
||||
Title = maps:get(<<"title">>, View, <<"">>),
|
||||
DictId = dgiot_parse:get_viewid(ObjectId, Type, <<"Product">>, Title),
|
||||
ViewId = dgiot_parse:get_viewid(ObjectId, Type, <<"Product">>, Title),
|
||||
Acc ++ [#{
|
||||
<<"method">> => <<"POST">>,
|
||||
<<"path">> => <<"/classes/View">>,
|
||||
<<"body">> => NewDict#{
|
||||
<<"objectId">> => DictId,
|
||||
<<"objectId">> => ViewId,
|
||||
<<"key">> => ObjectId,
|
||||
<<"class">> => <<"Product">>}
|
||||
}]
|
||||
|
Loading…
Reference in New Issue
Block a user