mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-01 19:58:46 +08:00
feat: generatereport
This commit is contained in:
parent
855fd6e642
commit
d8804c9065
@ -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">>,
|
||||
|
||||
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, "--">>,
|
||||
|
||||
|
@ -107,11 +107,11 @@ put_role(#{<<"objectId">> := RoleId} = Role, SessionToken) ->
|
||||
{error, #{<<"msg">> => <<"role is not exist">>}};
|
||||
{ok, #{<<"objectId">> := RoleId}} ->
|
||||
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, [])),
|
||||
<<"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_rules_role(RoleId),
|
||||
case dgiot_parse:update_object(<<"_Role">>, RoleId, NewRole) of
|
||||
|
@ -98,10 +98,14 @@ do_request(delete_role, #{<<"name">> := _Name, <<"tempname">> := _TempName} = Bo
|
||||
%% Role模版 概要: 导库 描述:json文件导库
|
||||
%% OperationId:post_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]),
|
||||
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文件导库
|
||||
%% OperationId:get_role
|
||||
%% 请求:GET /iotapi/role
|
||||
@ -118,16 +122,30 @@ do_request(get_roleuser, #{<<"where">> := Where} = Filter, #{<<"sessionToken">>
|
||||
%% Role模版 概要: 导库 描述:json文件导库
|
||||
%% OperationId:put_roleuser
|
||||
%% 请求:POST /iotapi/roleuser
|
||||
do_request(put_roleuser, Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) ->
|
||||
?LOG(debug, "Body ~p ", [Body]),
|
||||
dgiot_role:put_roleuser(Body, SessionToken);
|
||||
do_request(put_roleuser, #{<<"userid">> := UserId} = Body, #{<<"sessionToken">> := SessionToken} = _Context, _Req0) ->
|
||||
%% ?LOG(debug, "Body ~p ", [Body]),
|
||||
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文件导库
|
||||
%% OperationId:delete_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]),
|
||||
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文件导库
|
||||
%% OperationId:delete_roleuser
|
||||
|
@ -345,9 +345,14 @@
|
||||
"product": {
|
||||
"description": "报告模板id",
|
||||
"type": "string",
|
||||
"example": "6c7347b2d1"
|
||||
"example": "9fa3bba25a"
|
||||
},
|
||||
"basedata": {
|
||||
"parentId": {
|
||||
"description": "台体id",
|
||||
"type": "string",
|
||||
"example": "3448b83c11"
|
||||
},
|
||||
"profile": {
|
||||
"description": "报告描述信息",
|
||||
"type": "object",
|
||||
"example": {
|
||||
@ -969,6 +974,42 @@
|
||||
"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 @@
|
||||
get_ukey/0,
|
||||
signData/1,
|
||||
verifySignData/3,
|
||||
readCert/0
|
||||
readCert/0,
|
||||
update_view/5
|
||||
]).
|
||||
|
||||
-export([
|
||||
@ -613,3 +614,84 @@ get_capture(#{<<"productid">> := ProductId, <<"topoid">> := TopoId, <<"thingid">
|
||||
Return ->
|
||||
Return
|
||||
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
|
||||
{ok, get_paper(Productid, FileInfo)};
|
||||
|
||||
%% evidence 概要: 增加取证报告模版 描述:新增取证报告模版
|
||||
%% OperationId:post_reporttemp
|
||||
%% OperationId:put_reporttemp
|
||||
%% 请求:put /iotapi/reporttemp
|
||||
do_request(put_reporttemp, #{<<"nodeType">> := _NodeType, <<"devType">> := _DevType} = Body,
|
||||
#{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
|
||||
@ -169,6 +169,132 @@ do_request(post_reporttemp, #{<<"name">> := Name, <<"devType">> := DevType, <<"c
|
||||
Error -> Error
|
||||
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 概要: 增加取证报告 描述:新增取证报告
|
||||
%% OperationId:get_report
|
||||
%% 请求:GET /iotapi/report
|
||||
@ -180,7 +306,7 @@ do_request(get_report, #{<<"id">> := Id} = Body, #{<<"sessionToken">> := Session
|
||||
%% OperationId:post_report
|
||||
%% 请求:POST /iotapi/report
|
||||
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]),
|
||||
post_report(Body, SessionToken);
|
||||
|
||||
@ -252,34 +378,34 @@ do_request(_OperationId, _Args, _Context, _Req) ->
|
||||
do_report(Config, DevType, Name, SessionToken, FullPath, Uri) ->
|
||||
CategoryId = maps:get(<<"category">>, Config, <<"d6ad425529">>),
|
||||
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
|
||||
{ok, #{<<"code">> := 0, <<"msg">> := <<"SUCCESS">>, <<"path">> := WordPath, <<"images">> := Images}} ->
|
||||
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(ProductParentId, Config, Index, ImageUrl, Heigh, Width, WordPath, SessionToken)]
|
||||
end
|
||||
end, [], Images);
|
||||
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#{<<"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 ->
|
||||
io:format("_Oth ~p~n", [_Oth]),
|
||||
[]
|
||||
@ -699,9 +825,10 @@ get_report(Id, SessionToken) ->
|
||||
Error -> Error
|
||||
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
|
||||
{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}},
|
||||
[{"X-Parse-Session-Token", SessionToken}], [{from, rest}]) of
|
||||
{ok, #{<<"results">> := Results}} when length(Results) == 0 ->
|
||||
@ -710,23 +837,32 @@ post_report(#{<<"name">> := Name, <<"product">> := ProductId, <<"basedata">> :=
|
||||
dgiot_device:create_device(#{
|
||||
<<"devaddr">> => DtuAddr,
|
||||
<<"name">> => Name,
|
||||
<<"ip">> => <<"">>,
|
||||
<<"product">> => ProductId,
|
||||
<<"ACL">> => Acl,
|
||||
<<"status">> => <<"ONLINE">>,
|
||||
<<"brand">> => <<"数蛙桌面采集网关"/utf8>>,
|
||||
<<"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
|
||||
{ok, #{<<"results">> := Views}} ->
|
||||
ViewRequests =
|
||||
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 ++ [#{
|
||||
<<"method">> => <<"POST">>,
|
||||
<<"path">> => <<"/classes/View">>,
|
||||
<<"body">> => NewDict#{
|
||||
<<"body">> => NewView#{
|
||||
<<"objectId">> => Viewid,
|
||||
<<"key">> => DeviceId,
|
||||
<<"class">> => <<"Device">>}
|
||||
}]
|
||||
|
@ -6,12 +6,12 @@ parse.delete_field = ACL,objectId,updatedAt,createdAt
|
||||
##--------------------------------------------------------------------
|
||||
## 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_appid = d4545fe9027a21800a9d9e0ddd8af749
|
||||
parse.parse_master_key = bb5c5ec2e59440f4ac0b654c3e4c461e
|
||||
parse.parse_js_key = 4e76fe7fc0fdd2905a9d847514200dc2
|
||||
parse.parse_rest_key = 31761d8d379b0067491c026b690b20f8
|
||||
parse.parse_appid = 1272413530fa0981f3339bc2d6c20e89
|
||||
parse.parse_master_key = 648bb761711c773eba9156fc8aaf6902
|
||||
parse.parse_js_key = 9f450c9defb68248a80e142f014aed79
|
||||
parse.parse_rest_key = d5d83509563763bc05f26db98cc7aca6
|
||||
|
||||
##--------------------------------------------------------------------
|
||||
## parse cache
|
||||
|
@ -150,9 +150,9 @@ get_dictid(Key, Type, Class, Title) ->
|
||||
dgiot_parse:get_objectid(<<"Dict">>, #{<<"key">> => Key, <<"type">> => Type, <<"class">> => Class, <<"title">> => Title}),
|
||||
DeviceId.
|
||||
|
||||
get_viewid(Key, Type, Class,Title) ->
|
||||
get_viewid(Key, Type, Class, Title) ->
|
||||
#{<<"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.
|
||||
|
||||
get_deviceid(ProductId, DevAddr) ->
|
||||
@ -319,7 +319,7 @@ get_objectid(Class, Map) ->
|
||||
Type = maps:get(<<"type">>, Map, <<"">>),
|
||||
Class1 = maps:get(<<"class">>, 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#{
|
||||
<<"objectId">> => DId
|
||||
};
|
||||
@ -330,7 +330,7 @@ get_objectid(Class, Map) ->
|
||||
Type = maps:get(<<"type">>, Map, <<"">>),
|
||||
Class2 = maps:get(<<"class">>, 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#{
|
||||
<<"objectId">> => VId
|
||||
};
|
||||
|
@ -179,11 +179,16 @@ handle(post_user, #{<<"username">> := _UserName, <<"password">> := _Password} =
|
||||
|
||||
handle(delete_user, #{<<"username">> := _UserName} = Body, #{<<"sessionToken">> := SessionToken}, _Req) ->
|
||||
?LOG(info, "Body ~p", [Body]),
|
||||
case delete_user(Body, SessionToken) of
|
||||
{ok, Data} ->
|
||||
dgiot_parse:load_role(),
|
||||
{200, Data};
|
||||
{error, Error} -> {error, Error}
|
||||
case _UserName of
|
||||
<<"dgiot_admin">> ->
|
||||
{ok, #{<<"code">> => 401, <<"msg">> => <<"dgiot_admin PROHIBITED DELETE">>}};
|
||||
_ ->
|
||||
case delete_user(Body, SessionToken) of
|
||||
{ok, Data} ->
|
||||
dgiot_parse:load_role(),
|
||||
{200, Data};
|
||||
{error, Error} -> {error, Error}
|
||||
end
|
||||
end;
|
||||
|
||||
handle(put_user, #{<<"username">> := _UserName} = Body, #{<<"sessionToken">> := SessionToken}, _Req) ->
|
||||
@ -596,7 +601,15 @@ create_user(#{<<"username">> := UserName, <<"department">> := RoleId} = Body, Se
|
||||
<<"read">> => true,
|
||||
<<"write">> => true
|
||||
}},
|
||||
<<"emailVerified">> => true}),
|
||||
<<"emailVerified">> => true,
|
||||
<<"roles">> => #{
|
||||
<<"__op">> => <<"AddRelation">>,
|
||||
<<"objects">> => [#{
|
||||
<<"__type">> => <<"Pointer">>,
|
||||
<<"className">> => <<"_Role">>,
|
||||
<<"objectId">> => RoleId
|
||||
}]
|
||||
}}),
|
||||
dgiot_parse:update_object(<<"_Role">>, RoleId, #{
|
||||
<<"users">> => #{
|
||||
<<"__op">> => <<"AddRelation">>,
|
||||
|
@ -121,6 +121,7 @@ handle_init(#state{env = #{productids := ProductIds}} = State) ->
|
||||
handle_event(EventId, Event, _State) ->
|
||||
?LOG(info, "channel ~p, ~p", [EventId, Event]),
|
||||
ok.
|
||||
|
||||
handle_message({sync_parse, Args}, State) ->
|
||||
%% io:format("Args ~p~n", [jsx:decode(Args, [{labels, binary}, return_maps])]),
|
||||
case jsx:decode(Args, [{labels, binary}, return_maps]) of
|
||||
@ -152,8 +153,6 @@ handle_message({sync_parse, Args}, State) ->
|
||||
lists:foldl(fun(View, Acc) ->
|
||||
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),
|
||||
Acc ++ [#{
|
||||
|
13
dgiot.ipr
13
dgiot.ipr
@ -18,6 +18,19 @@
|
||||
<profile version="1.0">
|
||||
<option name="myName" value="Project Default" />
|
||||
<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>
|
||||
<version value="1.0" />
|
||||
</component>
|
||||
|
Loading…
Reference in New Issue
Block a user