Commit d8804c90 authored by AvantLiu's avatar AvantLiu
Browse files

feat: generatereport

parent 855fd6e6
Showing with 365 additions and 63 deletions
+365 -63
...@@ -63,7 +63,7 @@ fileUpload(Url, Path, Producttempid) -> ...@@ -63,7 +63,7 @@ fileUpload(Url, Path, Producttempid) ->
FilenameBody = <<"--", Boundary/binary, "\r\n", "Content-Disposition: form-data; name=\"filename\"", "\r\n", "\r\n", Producttempid/binary, "\r\n">>, FilenameBody = <<"--", Boundary/binary, "\r\n", "Content-Disposition: form-data; name=\"filename\"", "\r\n", "\r\n", Producttempid/binary, "\r\n">>,
PathBody = <<"--", Boundary/binary, "\r\n", "Content-Disposition: form-data; name=\"path\"", "\r\n", "\r\n", "dgiot_file/product/topo", "\r\n">>, PathBody = <<"--", Boundary/binary, "\r\n", "Content-Disposition: form-data; name=\"path\"", "\r\n", "\r\n", "dgiot_file/product/topo/", Producttempid/binary, "\r\n">>,
Tail = <<"--", Boundary/binary, "--">>, Tail = <<"--", Boundary/binary, "--">>,
......
...@@ -107,11 +107,11 @@ put_role(#{<<"objectId">> := RoleId} = Role, SessionToken) -> ...@@ -107,11 +107,11 @@ put_role(#{<<"objectId">> := RoleId} = Role, SessionToken) ->
{error, #{<<"msg">> => <<"role is not exist">>}}; {error, #{<<"msg">> => <<"role is not exist">>}};
{ok, #{<<"objectId">> := RoleId}} -> {ok, #{<<"objectId">> := RoleId}} ->
NewRole = #{ NewRole = #{
<<"users">> => dgiot_role:get_users_role(maps:get(<<"users">>, Role, [])), %% <<"users">> => dgiot_role:get_users_role(maps:get(<<"users">>, Role, [])),
<<"menus">> => dgiot_role:get_menus_role(maps:get(<<"menus">>, Role, [])), <<"menus">> => dgiot_role:get_menus_role(maps:get(<<"menus">>, Role, [])),
<<"rules">> => dgiot_role:get_rules_role(maps:get(<<"rules">>, Role, [])) <<"rules">> => dgiot_role:get_rules_role(maps:get(<<"rules">>, Role, []))
}, },
dgiot_role:remove_users_roles(RoleId), %% dgiot_role:remove_users_roles(RoleId),
dgiot_role:remove_menus_role(RoleId), dgiot_role:remove_menus_role(RoleId),
dgiot_role:remove_rules_role(RoleId), dgiot_role:remove_rules_role(RoleId),
case dgiot_parse:update_object(<<"_Role">>, RoleId, NewRole) of case dgiot_parse:update_object(<<"_Role">>, RoleId, NewRole) of
......
...@@ -98,10 +98,14 @@ do_request(delete_role, #{<<"name">> := _Name, <<"tempname">> := _TempName} = Bo ...@@ -98,10 +98,14 @@ do_request(delete_role, #{<<"name">> := _Name, <<"tempname">> := _TempName} = Bo
%% Role模版 概要: 导库 描述:json文件导库 %% Role模版 概要: 导库 描述:json文件导库
%% OperationId:post_role %% OperationId:post_role
%% 请求:POST /iotapi/role %% 请求:POST /iotapi/role
do_request(put_role, Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) -> do_request(put_role, #{<<"menus">> := Menus, <<"rules">> := Rules} = Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) when length(Menus) > 0 andalso length(Rules) > 0 ->
?LOG(debug, "Body ~p ", [Body]), ?LOG(debug, "Body ~p ", [Body]),
dgiot_role:put_role(Body, SessionToken); dgiot_role:put_role(Body, SessionToken);
do_request(put_role, _Body, #{<<"sessionToken">> := _SessionToken} = _Context, _Req0) ->
?LOG(debug, "Body ~p ", [_Body]),
{ok, #{<<"code">> => 401, <<"msg">> => <<"Menus or Rules is empty">>}};
%% Role 概要: 导库 描述:json文件导库 %% Role 概要: 导库 描述:json文件导库
%% OperationId:get_role %% OperationId:get_role
%% 请求:GET /iotapi/role %% 请求:GET /iotapi/role
...@@ -118,16 +122,30 @@ do_request(get_roleuser, #{<<"where">> := Where} = Filter, #{<<"sessionToken">> ...@@ -118,16 +122,30 @@ do_request(get_roleuser, #{<<"where">> := Where} = Filter, #{<<"sessionToken">>
%% Role模版 概要: 导库 描述:json文件导库 %% Role模版 概要: 导库 描述:json文件导库
%% OperationId:put_roleuser %% OperationId:put_roleuser
%% 请求:POST /iotapi/roleuser %% 请求:POST /iotapi/roleuser
do_request(put_roleuser, Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) -> do_request(put_roleuser, #{<<"userid">> := UserId} = Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) ->
?LOG(debug, "Body ~p ", [Body]), %% ?LOG(debug, "Body ~p ", [Body]),
dgiot_role:put_roleuser(Body, SessionToken); case UserId of
<<"Klht7ERlYn">> ->
{ok, #{<<"code">> => 401, <<"result">> => <<"dgiot_admin Cannot be transferred">>}};
<<"lerYRy2jsh">> ->
{ok, #{<<"code">> => 401, <<"result">> => <<"dgiot_admin Cannot be transferred">>}};
_ ->
dgiot_role:put_roleuser(Body, SessionToken)
end;
%% Role模版 概要: 导库 描述:json文件导库 %% Role模版 概要: 导库 描述:json文件导库
%% OperationId:delete_roleuser %% OperationId:delete_roleuser
%% 请求:POST /iotapi/roleuser %% 请求:POST /iotapi/roleuser
do_request(delete_roleuser, Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) -> do_request(delete_roleuser, #{<<"userid">> := UserId} = Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) ->
%% io:format("Body ~p~n", [Body]), %% io:format("Body ~p~n", [Body]),
dgiot_role:del_roleuser(Body, SessionToken); case UserId of
<<"Klht7ERlYn">> ->
{ok, #{<<"code">> => 401, <<"result">> => <<"dgiot_admin Cannot be Resignation">>}};
<<"lerYRy2jsh">> ->
{ok, #{<<"code">> => 401, <<"result">> => <<"dgiot_admin Cannot be Resignation">>}};
_ ->
dgiot_role:del_roleuser(Body, SessionToken)
end;
%% Role模版 概要: 导库 描述:json文件导库 %% Role模版 概要: 导库 描述:json文件导库
%% OperationId:delete_roleuser %% OperationId:delete_roleuser
......
...@@ -345,9 +345,14 @@ ...@@ -345,9 +345,14 @@
"product": { "product": {
"description": "报告模板id", "description": "报告模板id",
"type": "string", "type": "string",
"example": "6c7347b2d1" "example": "9fa3bba25a"
}, },
"basedata": { "parentId": {
"description": "台体id",
"type": "string",
"example": "3448b83c11"
},
"profile": {
"description": "报告描述信息", "description": "报告描述信息",
"type": "object", "type": "object",
"example": { "example": {
...@@ -969,6 +974,42 @@ ...@@ -969,6 +974,42 @@
"Data" "Data"
] ]
} }
},
"/generatereport": {
"post": {
"summary": "生成报告",
"description": "生成报告",
"parameters": [
{
"description": "任务ID",
"in": "query",
"name": "id",
"default": "7613908c4c",
"required": true,
"type": "string"
}
],
"consumes": [
"*"
],
"responses": {
"200": {
"description": "Returns operation status"
},
"400": {
"description": "Bad Request"
},
"403": {
"description": "Forbidden"
},
"500": {
"description": "Server Internal error"
}
},
"tags": [
"Evidence"
]
}
} }
} }
} }
...@@ -27,7 +27,8 @@ ...@@ -27,7 +27,8 @@
get_ukey/0, get_ukey/0,
signData/1, signData/1,
verifySignData/3, verifySignData/3,
readCert/0 readCert/0,
update_view/5
]). ]).
-export([ -export([
...@@ -613,3 +614,84 @@ get_capture(#{<<"productid">> := ProductId, <<"topoid">> := TopoId, <<"thingid"> ...@@ -613,3 +614,84 @@ get_capture(#{<<"productid">> := ProductId, <<"topoid">> := TopoId, <<"thingid">
Return -> Return ->
Return Return
end. end.
update_view(Index, ImageUrl, Heigh, Width, TaskId) ->
Viewid = dgiot_parse:get_viewid(TaskId, <<"topo">>, <<"Device">>, Index),
case dgiot_parse:get_object(<<"View">>, Viewid) of
{ok, #{<<"data">> := #{<<"konva">> := Konva} = Data}} ->
NewKonva = update_bgimage(Konva, ImageUrl, Heigh, Width),
#{
<<"method">> => <<"PUT">>,
<<"path">> => <<"/classes/View">>,
<<"body">> => #{
<<"objectId">> => Viewid,
<<"data">> => Data#{
<<"icon">> => ImageUrl,
<<"konva">> => NewKonva
}}
};
_ ->
Data = #{
<<"icon">> => ImageUrl,
<<"konva">> => #{
<<"Stage">> => #{
<<"attrs">> => #{
<<"width">> => Width,
<<"height">> => Heigh},
<<"className">> => <<"Stage">>,
<<"children">> => [#{
<<"attrs">> => #{
<<"id">> => <<"Layer_Thing">>},
<<"className">> => <<"Layer">>,
<<"children">> => [#{
<<"attrs">> => #{
<<"id">> => <<"bg">>,
<<"type">> => <<"bg-image">>,
<<"width">> => Width,
<<"height">> => Heigh,
<<"src">> => ImageUrl},
<<"className">> => <<"Image">>}]}]}}},
#{<<"method">> => <<"POST">>,
<<"path">> => <<"/classes/View">>,
<<"body">> => #{
<<"objectId">> => Viewid,
<<"title">> => Index,
<<"key">> => TaskId,
<<"type">> => <<"topo">>,
<<"class">> => <<"Device">>,
<<"data">> => Data}
}
end.
update_bgimage(#{<<"Stage">> := #{<<"children">> := Children} = Stage} = Konva, ImageUrl, Heigh, Width) ->
NewChildren = get_children(Children, ImageUrl, Heigh, Width),
Konva#{<<"Stage">> => Stage#{<<"children">> := NewChildren}}.
get_children(Children, ImageUrl, Heigh, Width) ->
lists:foldl(fun(X, Acc) ->
#{<<"attrs">> := Attrs, <<"className">> := ClassName} = X,
X1 = get_attrs(Attrs, ImageUrl, Heigh, Width, ClassName, X),
X2 =
case maps:find(<<"children">>, X1) of
error ->
X1;
{ok, SubChildren} ->
X1#{<<"children">> => get_children(SubChildren, ImageUrl, Heigh, Width)}
end,
Acc ++ [X2]
end, [], Children).
get_attrs(Attrs, ImageUrl, Heigh, Width, ClassName, X) ->
case ClassName of
<<"Image">> ->
case maps:find(<<"type">>, Attrs) of
error ->
X;
{ok, <<"bg-image">>} ->
X#{<<"attrs">> => Attrs#{<<"src">> => ImageUrl, <<"width">> => Width, <<"height">> => Heigh}};
_ ->
X
end;
_ ->
X
end.
...@@ -136,7 +136,7 @@ do_request(post_testpaper, #{<<"productid">> := Productid, <<"file">> := FileInf ...@@ -136,7 +136,7 @@ do_request(post_testpaper, #{<<"productid">> := Productid, <<"file">> := FileInf
{ok, get_paper(Productid, FileInfo)}; {ok, get_paper(Productid, FileInfo)};
%% evidence 概要: 增加取证报告模版 描述:新增取证报告模版 %% evidence 概要: 增加取证报告模版 描述:新增取证报告模版
%% OperationId:post_reporttemp %% OperationId:put_reporttemp
%% 请求:put /iotapi/reporttemp %% 请求:put /iotapi/reporttemp
do_request(put_reporttemp, #{<<"nodeType">> := _NodeType, <<"devType">> := _DevType} = Body, do_request(put_reporttemp, #{<<"nodeType">> := _NodeType, <<"devType">> := _DevType} = Body,
#{<<"sessionToken">> := SessionToken} = _Context, _Req) -> #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
...@@ -169,6 +169,132 @@ do_request(post_reporttemp, #{<<"name">> := Name, <<"devType">> := DevType, <<"c ...@@ -169,6 +169,132 @@ do_request(post_reporttemp, #{<<"name">> := Name, <<"devType">> := DevType, <<"c
Error -> Error Error -> Error
end; end;
%% DB 概要: 生成报告 描述:生成报告
%% OperationId:generatereport
%% 请求:POST /iotapi/generatereport
do_request(post_generatereport, #{<<"id">> := TaskId}, #{<<"sessionToken">> := _SessionToken} = _Context, #{headers := #{<<"origin">> := Uri}} = _Req) ->
case dgiot_parse:get_object(<<"Device">>, TaskId) of
{ok, #{<<"name">> := TaskName, <<"basedata">> := Basedata, <<"profile">> := #{<<"reporttemp">> := Reporttemp} = Profile,
<<"product">> := #{<<"__type">> := <<"Pointer">>, <<"className">> := <<"Product">>, <<"objectId">> := ProductId},
<<"parentId">> := #{<<"__type">> := <<"Pointer">>, <<"className">> := <<"Device">>, <<"objectId">> := _ParentId}
}} ->
DictId = dgiot_parse:get_dictid(ProductId, <<"word">>, <<"Product">>, <<"worddict">>),
case dgiot_parse:get_object(<<"Dict">>, DictId) of
{ok, #{<<"data">> := #{<<"params">> := Params}}} ->
Worddatas =
lists:foldl(fun(Param, Acc) ->
Sources = maps:get(<<"sources">>, Param, <<"">>),
Type = maps:get(<<"type">>, Param, <<"">>),
Identifier = maps:get(<<"identifier">>, Param, <<"">>),
Row = maps:get(<<"row">>, Param, 1),
Column = maps:get(<<"column">>, Param, 1),
Value = maps:get(Identifier, Basedata, <<"">>),
case Sources of
<<"amis">> ->
case Type of
<<"text">> ->
Acc ++ [#{
<<"type">> => <<"text">>,
<<"source">> => Sources,
<<"name">> => Identifier,
<<"value">> => Value}];
<<"image">> ->
Acc ++ [#{
<<"type">> => <<"image">>,
<<"source">> => Sources,
<<"name">> => Identifier,
<<"url">> => Value,
<<"width">> => 600,
<<"height">> => 330
}];
_ ->
Acc
end;
_ ->
case Type of
<<"text">> ->
Acc ++ [#{
<<"type">> => <<"text">>,
<<"source">> => Sources,
<<"name">> => Identifier,
<<"value">> => Value}];
<<"dynamicTable">> ->
Tabledata = [
<<"10,0,0.784,12.593,2850,0,0.107162,0,12.593,0.784,0">>,
<<"9,2.11,0.882,11.706,2850,0,0.098424,2.11,11.706,0.882,7.64">>,
<<"8,4.15,0.882,11.127,2850,0,0.092627,4.15,11.127,0.882,14.29">>,
<<"7,6.22,0.98,10.607,2850,0,0.087323,6.22,10.607,0.98,18.38">>,
<<"6,8.02,1.078,10.187,2850,0,0.082954,8.02,10.187,1.078,20.69">>,
<<"5,10.04,1.078,9.537,2850,0,0.076222,10.04,9.537,1.078,24.25">>,
<<"4,11.88,1.176,8.813,2850,0,0.068725,11.88,8.813,1.176,24.3">>,
<<"3,13.93,1.176,7.745,2850,0,0.057743,13.93,7.745,1.176,25.05">>,
<<"2,15.92,1.176,6.558,2850,0,0.04552,15.92,6.558,1.176,24.24">>,
<<"1,21.33,1.196,4.021,2850,0,0.01866,21.33,4.021,1.196,19.59">>],
Acc ++ [#{
<<"type">> => <<"dynamicTable">>,
<<"source">> => Sources,
<<"tablerow">> => Row,
<<"tablecolumn">> => Column,
<<"name">> => Identifier,
<<"data">> => Tabledata
}];
<<"image">> ->
PythonBody = #{<<"name">> => <<TaskId/binary, ".png">>, <<"path">> => <<"/data/dgiot/go_fastdfs/files/dgiot_file/pump_pytoh/">>},
Imagepath = base64:decode(os:cmd("python3 /data/dgiot/dgiot/lib/dgiot_evidence-4.3.0/priv/python/drawxnqx.py " ++ dgiot_utils:to_list(base64:encode(jsx:encode(PythonBody))))),
Repath = re:replace(dgiot_utils:to_list(Imagepath), "/data/dgiot/go_fastdfs/files", "", [global, {return, binary}, unicode]),
Acc ++ [#{
<<"type">> => <<"image">>,
<<"source">> => Sources,
<<"name">> => Identifier,
<<"url">> => <<Uri/binary, Repath/binary>>,
<<"width">> => 600,
<<"height">> => 330
}];
_ ->
Acc
end
end
end, [], Params),
Body = #{
<<"datas">> => Worddatas,
<<"templateUrl">> => <<Uri/binary, Reporttemp/binary>>,
<<"wordName">> => TaskName,
<<"path">> => <<"dgiot_file/device/topo/", TaskId/binary>>
},
%% (post, {dgiot_utils:to_list(Url), [{"Content-Length", integer_to_list(Size)}], binary_to_list(ContentType), Body}, [], []),
StrUri = dgiot_utils:to_list(Uri),
Url = StrUri ++ "/WordController/replaceWord",
case httpc:request(post, {Url, [], "application/json", jsx:encode(Body)}, [], []) of
{ok, {{"HTTP/1.1", 200, "OK"}, _, Json}} ->
case jsx:decode(dgiot_utils:to_binary(Json), [{labels, binary}, return_maps]) of
#{<<"code">> := 0, <<"msg">> := <<"SUCCESS">>, <<"path">> := WordPath} = Data ->
Images = maps:get(<<"images">>, Data, []),
ViewRequests =
lists:foldl(fun(Image, Acc) ->
#{<<"heigh">> := Heigh, <<"url">> := ImageUrl, <<"width">> := Width} = Image,
case binary:split(filename:basename(ImageUrl), <<$.>>, [global, trim]) of
[Index, _] ->
Acc ++ [dgiot_evidence:update_view(Index, ImageUrl, Heigh, Width, TaskId)];
_ ->
Acc
end
end, [], Images),
dgiot_parse:batch(ViewRequests),
dgiot_parse:update_object(<<"Device">>, TaskId, #{<<"profile">> => Profile#{<<"generatedreport">> => WordPath, <<"generatedtime">> => dgiot_datetime:now_secs()}}),
{ok, maps:without([<<"images">>], Data)};
Error1 ->
Error1
end;
Error ->
Error
end;
_Oth ->
_Oth
end;
_Oth1 ->
_Oth1
end;
%% evidence 概要: 增加取证报告 描述:新增取证报告 %% evidence 概要: 增加取证报告 描述:新增取证报告
%% OperationId:get_report %% OperationId:get_report
%% 请求:GET /iotapi/report %% 请求:GET /iotapi/report
...@@ -180,7 +306,7 @@ do_request(get_report, #{<<"id">> := Id} = Body, #{<<"sessionToken">> := Session ...@@ -180,7 +306,7 @@ do_request(get_report, #{<<"id">> := Id} = Body, #{<<"sessionToken">> := Session
%% OperationId:post_report %% OperationId:post_report
%% 请求:POST /iotapi/report %% 请求:POST /iotapi/report
do_request(post_report, #{<<"name">> := _Name, <<"product">> := _ProductId, do_request(post_report, #{<<"name">> := _Name, <<"product">> := _ProductId,
<<"basedata">> := _Basedata} = Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req) -> <<"profile">> := _Profile} = Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
%% ?LOG(info, "Body ~p ", [Body]), %% ?LOG(info, "Body ~p ", [Body]),
post_report(Body, SessionToken); post_report(Body, SessionToken);
...@@ -252,34 +378,34 @@ do_request(_OperationId, _Args, _Context, _Req) -> ...@@ -252,34 +378,34 @@ do_request(_OperationId, _Args, _Context, _Req) ->
do_report(Config, DevType, Name, SessionToken, FullPath, Uri) -> do_report(Config, DevType, Name, SessionToken, FullPath, Uri) ->
CategoryId = maps:get(<<"category">>, Config, <<"d6ad425529">>), CategoryId = maps:get(<<"category">>, Config, <<"d6ad425529">>),
Producttempid = maps:get(<<"producttemplet">>, Config, <<"">>), Producttempid = maps:get(<<"producttemplet">>, Config, <<"">>),
ProductParentId =
case dgiot_product:create_product(#{
<<"name">> => Name,
<<"devType">> => DevType,
<<"desc">> => <<"0">>,
<<"nodeType">> => 1,
<<"channel">> => #{<<"type">> => 1, <<"tdchannel">> => <<"24b9b4bc50">>, <<"taskchannel">> => <<"0edaeb918e">>, <<"otherchannel">> => [<<"11ed8ad9f2">>]},
<<"netType">> => <<"Evidence">>,
<<"category">> => #{<<"objectId">> => CategoryId, <<"__type">> => <<"Pointer">>, <<"className">> => <<"Category">>},
<<"producttemplet">> => #{<<"objectId">> => Producttempid, <<"__type">> => <<"Pointer">>, <<"className">> => <<"ProductTemplet">>},
<<"config">> => Config,
<<"thing">> => #{},
<<"productSecret">> => license_loader:random(),
<<"dynamicReg">> => true}, SessionToken) of
{_, #{<<"objectId">> := ProductId}} ->
ProductId;
_ ->
dgiot_parse:get_productid(CategoryId, DevType, Name)
end,
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), Producttempid) of
{ok, #{<<"code">> := 0, <<"msg">> := <<"SUCCESS">>, <<"path">> := WordPath, <<"images">> := Images}} -> {ok, #{<<"code">> := 0, <<"msg">> := <<"SUCCESS">>, <<"path">> := WordPath, <<"images">> := Images}} ->
lists:foldl(fun(Image, Acc) -> case dgiot_product:create_product(#{
#{<<"heigh">> := Heigh, <<"url">> := ImageUrl, <<"width">> := Width} = Image, <<"name">> => Name,
case binary:split(filename:basename(ImageUrl), <<$.>>, [global, trim]) of <<"devType">> => DevType,
[Index, _] -> <<"desc">> => <<"0">>,
Acc ++ [dgiot_evidence:create_report(ProductParentId, Config, Index, ImageUrl, Heigh, Width, WordPath, SessionToken)] <<"nodeType">> => 1,
end <<"channel">> => #{<<"type">> => 1, <<"tdchannel">> => <<"24b9b4bc50">>, <<"taskchannel">> => <<"0edaeb918e">>, <<"otherchannel">> => [<<"11ed8ad9f2">>]},
end, [], Images); <<"netType">> => <<"Evidence">>,
<<"category">> => #{<<"objectId">> => CategoryId, <<"__type">> => <<"Pointer">>, <<"className">> => <<"Category">>},
<<"producttemplet">> => #{<<"objectId">> => Producttempid, <<"__type">> => <<"Pointer">>, <<"className">> => <<"ProductTemplet">>},
<<"config">> => Config#{<<"reporttemp">> => WordPath},
<<"thing">> => #{},
<<"productSecret">> => license_loader:random(),
<<"dynamicReg">> => true}, SessionToken) of
{_, #{<<"objectId">> := ProductId}} ->
lists:foldl(fun(Image, Acc) ->
#{<<"heigh">> := Heigh, <<"url">> := ImageUrl, <<"width">> := Width} = Image,
case binary:split(filename:basename(ImageUrl), <<$.>>, [global, trim]) of
[Index, _] ->
Acc ++ [dgiot_evidence:create_report(ProductId, Config, Index, ImageUrl, Heigh, Width, WordPath, SessionToken)];
_ ->
Acc
end
end, [], Images);
_ ->
[]
end;
_Oth -> _Oth ->
io:format("_Oth ~p~n", [_Oth]), io:format("_Oth ~p~n", [_Oth]),
[] []
...@@ -699,9 +825,10 @@ get_report(Id, SessionToken) -> ...@@ -699,9 +825,10 @@ get_report(Id, SessionToken) ->
Error -> Error Error -> Error
end. end.
post_report(#{<<"name">> := Name, <<"product">> := ProductId, <<"basedata">> := Basedata}, SessionToken) -> post_report(#{<<"name">> := Name, <<"product">> := ProductId, <<"parentId">> := ParentId, <<"profile">> := Profile}, SessionToken) ->
case dgiot_parse:get_object(<<"Product">>, ProductId, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of case dgiot_parse:get_object(<<"Product">>, ProductId, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
{ok, #{<<"ACL">> := Acl, <<"objectId">> := ProductId}} -> {ok, #{<<"ACL">> := Acl, <<"objectId">> := ProductId, <<"config">> := Config}} ->
WordPath = maps:get(<<"reporttemp">>, Config, <<"">>),
case dgiot_parse:query_object(<<"Device">>, #{<<"where">> => #{<<"name">> => Name, <<"product">> => ProductId}}, case dgiot_parse:query_object(<<"Device">>, #{<<"where">> => #{<<"name">> => Name, <<"product">> => ProductId}},
[{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
{ok, #{<<"results">> := Results}} when length(Results) == 0 -> {ok, #{<<"results">> := Results}} when length(Results) == 0 ->
...@@ -710,23 +837,32 @@ post_report(#{<<"name">> := Name, <<"product">> := ProductId, <<"basedata">> := ...@@ -710,23 +837,32 @@ post_report(#{<<"name">> := Name, <<"product">> := ProductId, <<"basedata">> :=
dgiot_device:create_device(#{ dgiot_device:create_device(#{
<<"devaddr">> => DtuAddr, <<"devaddr">> => DtuAddr,
<<"name">> => Name, <<"name">> => Name,
<<"ip">> => <<"">>,
<<"product">> => ProductId, <<"product">> => ProductId,
<<"ACL">> => Acl, <<"ACL">> => Acl,
<<"status">> => <<"ONLINE">>, <<"status">> => <<"ONLINE">>,
<<"brand">> => <<"数蛙桌面采集网关"/utf8>>, <<"brand">> => <<"数蛙桌面采集网关"/utf8>>,
<<"devModel">> => <<"SW_WIN_CAPTURE">>, <<"devModel">> => <<"SW_WIN_CAPTURE">>,
<<"basedata">> => Basedata <<"basedata">> => #{},
<<"profile">> => Profile#{<<"reporttemp">> => WordPath},
<<"parentId">> => #{
<<"__type">> => <<"Pointer">>,
<<"className">> => <<"Device">>,
<<"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">>, #{<<"where">> => #{<<"key">> => ProductId, <<"class">> => <<"Product">>}}, [{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
{ok, #{<<"results">> := Views}} -> {ok, #{<<"results">> := Views}} ->
ViewRequests = ViewRequests =
lists:foldl(fun(View, Acc) -> lists:foldl(fun(View, Acc) ->
NewDict = maps:without([<<"createdAt">>, <<"objectId">>, <<"updatedAt">>], View), NewView = maps:without([<<"createdAt">>, <<"objectId">>, <<"updatedAt">>], View),
Type = maps:get(<<"type">>, View, <<"">>),
Title = maps:get(<<"title">>, View, <<"">>),
Viewid = dgiot_parse:get_viewid(DeviceId, Type, <<"Device">>, Title),
Acc ++ [#{ Acc ++ [#{
<<"method">> => <<"POST">>, <<"method">> => <<"POST">>,
<<"path">> => <<"/classes/View">>, <<"path">> => <<"/classes/View">>,
<<"body">> => NewDict#{ <<"body">> => NewView#{
<<"objectId">> => Viewid,
<<"key">> => DeviceId, <<"key">> => DeviceId,
<<"class">> => <<"Device">>} <<"class">> => <<"Device">>}
}] }]
......
...@@ -6,12 +6,12 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt ...@@ -6,12 +6,12 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
## parse config ## parse config
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
parse.parse_server = http://127.0.0.1:1337 parse.parse_server = http://pump.dgiotcloud.com:1337
parse.parse_path = /parse/ parse.parse_path = /parse/
parse.parse_appid = d4545fe9027a21800a9d9e0ddd8af749 parse.parse_appid = 1272413530fa0981f3339bc2d6c20e89
parse.parse_master_key = bb5c5ec2e59440f4ac0b654c3e4c461e parse.parse_master_key = 648bb761711c773eba9156fc8aaf6902
parse.parse_js_key = 4e76fe7fc0fdd2905a9d847514200dc2 parse.parse_js_key = 9f450c9defb68248a80e142f014aed79
parse.parse_rest_key = 31761d8d379b0067491c026b690b20f8 parse.parse_rest_key = d5d83509563763bc05f26db98cc7aca6
##-------------------------------------------------------------------- ##--------------------------------------------------------------------
## parse cache ## parse cache
......
...@@ -150,9 +150,9 @@ get_dictid(Key, Type, Class, Title) -> ...@@ -150,9 +150,9 @@ get_dictid(Key, Type, Class, Title) ->
dgiot_parse:get_objectid(<<"Dict">>, #{<<"key">> => Key, <<"type">> => Type, <<"class">> => Class, <<"title">> => Title}), dgiot_parse:get_objectid(<<"Dict">>, #{<<"key">> => Key, <<"type">> => Type, <<"class">> => Class, <<"title">> => Title}),
DeviceId. DeviceId.
get_viewid(Key, Type, Class,Title) -> get_viewid(Key, Type, Class, Title) ->
#{<<"objectId">> := DeviceId} = #{<<"objectId">> := DeviceId} =
dgiot_parse:get_objectid(<<"View">>, #{<<"key">> => Key, <<"type">> => Type, <<"class">> => Class,<<"title">> => Title}), dgiot_parse:get_objectid(<<"View">>, #{<<"key">> => Key, <<"type">> => Type, <<"class">> => Class, <<"title">> => Title}),
DeviceId. DeviceId.
get_deviceid(ProductId, DevAddr) -> get_deviceid(ProductId, DevAddr) ->
...@@ -319,7 +319,7 @@ get_objectid(Class, Map) -> ...@@ -319,7 +319,7 @@ get_objectid(Class, Map) ->
Type = maps:get(<<"type">>, Map, <<"">>), Type = maps:get(<<"type">>, Map, <<"">>),
Class1 = maps:get(<<"class">>, Map, <<"">>), Class1 = maps:get(<<"class">>, Map, <<"">>),
Title = maps:get(<<"title">>, Map, <<"">>), Title = maps:get(<<"title">>, Map, <<"">>),
<<DId:10/binary, _/binary>> = dgiot_utils:to_md5(<<"Dict", Class1/binary, Key/binary, Type/binary,Title/binary>>), <<DId:10/binary, _/binary>> = dgiot_utils:to_md5(<<"Dict", Class1/binary, Key/binary, Type/binary, Title/binary>>),
Map#{ Map#{
<<"objectId">> => DId <<"objectId">> => DId
}; };
...@@ -330,7 +330,7 @@ get_objectid(Class, Map) -> ...@@ -330,7 +330,7 @@ get_objectid(Class, Map) ->
Type = maps:get(<<"type">>, Map, <<"">>), Type = maps:get(<<"type">>, Map, <<"">>),
Class2 = maps:get(<<"class">>, Map, <<"">>), Class2 = maps:get(<<"class">>, Map, <<"">>),
Title = maps:get(<<"title">>, Map, <<"">>), Title = maps:get(<<"title">>, Map, <<"">>),
<<VId:10/binary, _/binary>> = dgiot_utils:to_md5(<<"View", Class2/binary, Key/binary, Type/binary,Title/binary>>), <<VId:10/binary, _/binary>> = dgiot_utils:to_md5(<<"View", Class2/binary, Key/binary, Type/binary, Title/binary>>),
Map#{ Map#{
<<"objectId">> => VId <<"objectId">> => VId
}; };
......
...@@ -179,11 +179,16 @@ handle(post_user, #{<<"username">> := _UserName, <<"password">> := _Password} = ...@@ -179,11 +179,16 @@ handle(post_user, #{<<"username">> := _UserName, <<"password">> := _Password} =
handle(delete_user, #{<<"username">> := _UserName} = Body, #{<<"sessionToken">> := SessionToken}, _Req) -> handle(delete_user, #{<<"username">> := _UserName} = Body, #{<<"sessionToken">> := SessionToken}, _Req) ->
?LOG(info, "Body ~p", [Body]), ?LOG(info, "Body ~p", [Body]),
case delete_user(Body, SessionToken) of case _UserName of
{ok, Data} -> <<"dgiot_admin">> ->
dgiot_parse:load_role(), {ok, #{<<"code">> => 401, <<"msg">> => <<"dgiot_admin PROHIBITED DELETE">>}};
{200, Data}; _ ->
{error, Error} -> {error, Error} case delete_user(Body, SessionToken) of
{ok, Data} ->
dgiot_parse:load_role(),
{200, Data};
{error, Error} -> {error, Error}
end
end; end;
handle(put_user, #{<<"username">> := _UserName} = Body, #{<<"sessionToken">> := SessionToken}, _Req) -> handle(put_user, #{<<"username">> := _UserName} = Body, #{<<"sessionToken">> := SessionToken}, _Req) ->
...@@ -596,7 +601,15 @@ create_user(#{<<"username">> := UserName, <<"department">> := RoleId} = Body, Se ...@@ -596,7 +601,15 @@ create_user(#{<<"username">> := UserName, <<"department">> := RoleId} = Body, Se
<<"read">> => true, <<"read">> => true,
<<"write">> => true <<"write">> => true
}}, }},
<<"emailVerified">> => true}), <<"emailVerified">> => true,
<<"roles">> => #{
<<"__op">> => <<"AddRelation">>,
<<"objects">> => [#{
<<"__type">> => <<"Pointer">>,
<<"className">> => <<"_Role">>,
<<"objectId">> => RoleId
}]
}}),
dgiot_parse:update_object(<<"_Role">>, RoleId, #{ dgiot_parse:update_object(<<"_Role">>, RoleId, #{
<<"users">> => #{ <<"users">> => #{
<<"__op">> => <<"AddRelation">>, <<"__op">> => <<"AddRelation">>,
......
...@@ -121,6 +121,7 @@ handle_init(#state{env = #{productids := ProductIds}} = State) -> ...@@ -121,6 +121,7 @@ handle_init(#state{env = #{productids := ProductIds}} = State) ->
handle_event(EventId, Event, _State) -> handle_event(EventId, Event, _State) ->
?LOG(info, "channel ~p, ~p", [EventId, Event]), ?LOG(info, "channel ~p, ~p", [EventId, Event]),
ok. ok.
handle_message({sync_parse, Args}, State) -> handle_message({sync_parse, Args}, State) ->
%% io:format("Args ~p~n", [jsx:decode(Args, [{labels, binary}, return_maps])]), %% io:format("Args ~p~n", [jsx:decode(Args, [{labels, binary}, return_maps])]),
case jsx:decode(Args, [{labels, binary}, return_maps]) of case jsx:decode(Args, [{labels, binary}, return_maps]) of
...@@ -152,8 +153,6 @@ handle_message({sync_parse, Args}, State) -> ...@@ -152,8 +153,6 @@ handle_message({sync_parse, Args}, State) ->
lists:foldl(fun(View, Acc) -> lists:foldl(fun(View, Acc) ->
NewDict = maps:without([<<"createdAt">>, <<"objectId">>, <<"updatedAt">>], View), NewDict = maps:without([<<"createdAt">>, <<"objectId">>, <<"updatedAt">>], View),
Type = maps:get(<<"type">>, View, <<"">>), Type = maps:get(<<"type">>, View, <<"">>),
Title = maps:get(<<"title">>, View, <<"">>), Title = maps:get(<<"title">>, View, <<"">>),
DictId = dgiot_parse:get_viewid(ObjectId, Type, <<"Product">>, Title), DictId = dgiot_parse:get_viewid(ObjectId, Type, <<"Product">>, Title),
Acc ++ [#{ Acc ++ [#{
......
...@@ -18,6 +18,19 @@ ...@@ -18,6 +18,19 @@
<profile version="1.0"> <profile version="1.0">
<option name="myName" value="Project Default" /> <option name="myName" value="Project Default" />
<inspection_tool class="ErlangIncludeDirectories" enabled="false" level="WARNING" enabled_by_default="false" /> <inspection_tool class="ErlangIncludeDirectories" enabled="false" level="WARNING" enabled_by_default="false" />
<inspection_tool class="PyUnresolvedReferencesInspection" enabled="true" level="WARNING" enabled_by_default="true">
<option name="ignoredIdentifiers">
<list>
<option value="apps.dgiot_grpc.priv.example.python3.demo.emqx" />
<option value="apps.dgiot_grpc.priv.example.python3.demo.print" />
<option value="apps.dgiot_grpc.priv.example.python3.demo.bytes" />
<option value="apps.dgiot_grpc.priv.example.python3.demo.any" />
<option value="apps.dgiot_grpc.priv.example.python3.demo.str" />
<option value="apps.dgiot_grpc.priv.example.python3.demo.list" />
<option value="apps.dgiot_grpc.priv.example.python3.demo.driver" />
</list>
</option>
</inspection_tool>
</profile> </profile>
<version value="1.0" /> <version value="1.0" />
</component> </component>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment