fix
Some checks failed
/ accurics-scan (push) Has been cancelled

This commit is contained in:
stoneliu 2024-11-13 10:09:57 +08:00
parent 5c12dbfe85
commit 05642104d9
11 changed files with 189 additions and 25 deletions

View File

@ -204,9 +204,9 @@ restart_channel(SessionToken) ->
case dgiot_parse:query_object(<<"Channel">>, #{<<"where">> => #{<<"isEnable">> => true}}) of
{ok, #{<<"results">> := Results}} ->
lists:foldl(fun(#{<<"objectId">> := ChannelId}, _Acc) ->
dgiot_bridge:control_channel(ChannelId, <<"disable">>, SessionToken),
dgiot_bridge:control_channel(#{<<"id">> => ChannelId, <<"action">> => <<"disable">>}, SessionToken),
timer:sleep(500),
dgiot_bridge:control_channel(ChannelId, <<"enable">>, SessionToken),
dgiot_bridge:control_channel(#{<<"id">> => ChannelId, <<"action">> => <<"enable">>}, SessionToken),
timer:sleep(500)
end, [], Results);
_ ->

View File

@ -553,7 +553,8 @@ do_request(post_device_debug, #{<<"deviceid">> := DeviceId, <<"messagetype">> :=
{ok, #{<<"devaddr">> := Devaddr, <<"product">> := #{<<"objectId">> := ProductId}}} ->
ProfileTopic = <<"$dg/device/", ProductId/binary, "/", Devaddr/binary, "/debug">>,
NewData = dgiot_edge:get_writeData(Messagetype, Data),
dgiot_mqtt:publish(DeviceId, ProfileTopic, NewData);
dgiot_mqtt:publish(DeviceId, ProfileTopic, NewData),
{200, #{<<"status">> => 0, <<"data">> => #{<<"topic">> => ProfileTopic}}};
_ ->
{200, #{<<"status">> => <<"error">>, <<"msg">> => <<"not find device">>}}
end;

View File

@ -25,6 +25,18 @@
"required": true,
"type": "string"
},
{
"description": "产品ID",
"in": "query",
"name": "productid",
"type": "string"
},
{
"description": "设备地址",
"in": "query",
"name": "devaddr",
"type": "string"
},
{
"description": "动作",
"in": "query",

View File

@ -26,7 +26,7 @@
-export([start/0, start_channel/2, start_channel/3, register_channel/2, get_behaviour/1, do_global_message/1]).
-export([get_product_info/1, get_products/1, get_acl/1, apply_channel/5, apply_product/3, parse_frame/3, to_frame/3]).
-export([get_data/2, send_log/3, send_log/4, send_log/5]).
-export([get_all_channel/0, control_channel/3, list/0, get_proctol_channel/1, control_uniapp/2, uniapp_report/1]).
-export([get_all_channel/0, control_channel/2, list/0, get_proctol_channel/1, control_uniapp/2, uniapp_report/1]).
init_ets() ->
dgiot_data:init(?DGIOT_BRIDGE),
@ -332,7 +332,21 @@ list() ->
end,
lists:sort(dgiot_plugin:check_module(Fun, [])).
control_channel(ChannelId, Action, SessionToken) ->
control_channel(#{<<"id">> := ChannelId, <<"action">> := <<"start_logger">>, <<"productid">> := Productid, <<"devaddr">> := Devaddr}, SessionToken) when Devaddr =/= undefined ->
dgiot_mqtt:subscribe_route_key([<<"$dg/user/channel/", ChannelId/binary, "/", Productid/binary, "/", Devaddr/binary, "/#">>], <<"channel">>, SessionToken),
Topic = <<"channel/", ChannelId/binary>>,
Payload = dgiot_json:encode(#{<<"channelId">> => ChannelId, <<"productId">> => Productid, <<"devaddr">> => Devaddr, <<"action">> => <<"start_logger">>}),
dgiot_mqtt:publish(ChannelId, Topic, Payload),
{ok, #{}};
control_channel(#{<<"id">> := ChannelId, <<"action">> := <<"start_logger">>, <<"productid">> := Productid}, SessionToken) when Productid =/= undefined ->
dgiot_mqtt:subscribe_route_key([<<"$dg/user/channel/", ChannelId/binary, "/", Productid/binary, "/#">>], <<"channel">>, SessionToken),
Topic = <<"channel/", ChannelId/binary>>,
Payload = dgiot_json:encode(#{<<"channelId">> => ChannelId, <<"productId">> => Productid, <<"action">> => <<"start_logger">>}),
dgiot_mqtt:publish(ChannelId, Topic, Payload),
{ok, #{}};
control_channel(#{<<"id">> := ChannelId, <<"action">> := Action}, SessionToken) ->
{IsEnable, Result} =
case Action of
<<"disable">> ->

View File

@ -201,9 +201,9 @@ do_handle(#{<<"channelId">> := ChannelId, <<"action">> := <<"start_logger">>} =
timer:sleep(3000),
case Filter of
#{<<"devaddr">> := Addr, <<"productId">> := ProductId} ->
dgiot_bridge:send_log(ChannelId, ProductId, Addr, "Channel[~s] is Running, ProductId:~s, devaddr:~s, Log is ~s", [ChannelId, ProductId, Addr, true]);
dgiot_bridge:send_log(ChannelId, ProductId, Addr, "Channel[~s] is Running, ProductId: ~s, devaddr: ~s, Log is ~s", [ChannelId, ProductId, Addr, true]);
#{<<"productId">> := ProductId} ->
dgiot_bridge:send_log(ChannelId, ProductId, "Channel[~s] is Running, ProductId:~s, Log is ~s", [ChannelId, ProductId, true]);
dgiot_bridge:send_log(ChannelId, ProductId, "Channel[~s] is Running, ProductId: ~s, Log is ~s", [ChannelId, ProductId, true]);
_ ->
dgiot_bridge:send_log(ChannelId, Fmt, Args)
end;

View File

@ -78,9 +78,9 @@ handle(OperationID, Args, Context, Req) ->
%%%===================================================================
%%% Version:API版本
%%%===================================================================
do_request(post_control_channel, #{<<"id">> := ChannelId, <<"action">> := Action}, #{<<"sessionToken">> := SessionToken} = _Context, _Req)
do_request(post_control_channel, #{<<"action">> := Action} = Args, #{<<"sessionToken">> := SessionToken} = _Context, _Req)
when Action == <<"enable">>; Action == <<"disable">>; Action == <<"update">>; Action == <<"start_logger">>; Action == <<"stop_logger">> ->
dgiot_bridge:control_channel(ChannelId, Action, SessionToken);
dgiot_bridge:control_channel(Args, SessionToken);
%% Decoder : :ID关联的解码器获取指令集
%% OperationId:get_cmd_productid

View File

@ -282,7 +282,7 @@ handle_message({sync_parse, _Pid, 'before', delete, _Token, <<"Channel">>, Objec
%% io:format("~s ~p ~p ~n", [?FILE, ?LINE, ObjectId]),
case dgiot_parsex:get_object(<<"Channel">>, ObjectId) of
{ok, #{<<"isEnable">> := true}} ->
dgiot_bridge:control_channel(ObjectId, <<"disable">>, <<>>);
dgiot_bridge:control_channel(#{<<"id">> => ObjectId, <<"action">> => <<"disable">>}, <<>>);
_ -> pass
end,
{ok, State};

View File

@ -25,7 +25,7 @@
-export([get_prop/1, get_props/1, get_props/2, get_unit/1, update_properties/2, update_properties/0]).
-export([update_topics/0, update_product_filed/1]).
-export([save_devicetype/1, get_devicetype/1, get_device_thing/2, get_productSecret/1]).
-export([save_/1, get_keys/1, get_sub_tab/1, get_control/1, save_control/1, get_interval/1, get_product_identifier/2, hook_topic/1, get_product_statistics/1]).
-export([save_/1, get_keys/1, get_sub_tab/1, get_control/1, save_control/1, get_interval/1, get_product_identifier/2, hook_topic/1, get_product_statistics/2]).
init_ets() ->
dgiot_data:init(?DGIOT_PRODUCT, [public, named_table, set, {write_concurrency, true}, {read_concurrency, true}]),
@ -614,7 +614,7 @@ hook_topic(#{<<"objectId">> := ProductId, <<"topics">> := Topics}) when is_map(T
hook_topic(_) ->
pass.
get_product_statistics(<<"protocol">>) ->
get_product_statistics(<<"protocol">>, _) ->
DevTypes =
case dgiot_parsex:query_object(<<"Product">>, #{}) of
{ok, #{<<"results">> := Products}} ->
@ -654,7 +654,7 @@ get_product_statistics(<<"protocol">>) ->
}
};
get_product_statistics(<<"network">>) ->
get_product_statistics(<<"network">>, _) ->
NetTypes =
case dgiot_parsex:query_object(<<"Product">>, #{}) of
{ok, #{<<"results">> := Products}} ->
@ -706,7 +706,7 @@ get_product_statistics(<<"network">>) ->
]
};
get_product_statistics(<<"thing">>) ->
get_product_statistics(<<"thing">>, _) ->
Props =
case dgiot_parsex:query_object(<<"Product">>, #{}) of
{ok, #{<<"results">> := Products}} ->
@ -757,8 +757,8 @@ get_product_statistics(<<"thing">>) ->
]
};
get_product_statistics(<<"device_statis">>) ->
Now = dgiot_datetime:format(dgiot_datetime:get_today_stamp(), "YYYY-MM-DDT16:00:00.000Z"),
get_product_statistics(<<"device_statis">>, _) ->
Now = dgiot_datetime:format(dgiot_datetime:get_today_stamp() - 86400, "YYYY-MM-DDT16:00:00.000Z"),
{ok, #{<<"count">> := Count}} = dgiot_parsex:query_object(<<"Device">>, #{<<"keys">> => [<<"objectId">>], <<"limit">> => 1, <<"count">> => <<"objectId">>}),
{ok, #{<<"count">> := Online}} = dgiot_parsex:query_object(<<"Device">>, #{<<"keys">> => [<<"objectId">>], <<"limit">> => 1, <<"count">> => <<"objectId">>,
<<"where">> => #{<<"status">> => <<"ONLINE">>}}),
@ -773,7 +773,7 @@ get_product_statistics(<<"device_statis">>) ->
<<"add">> => Add
};
get_product_statistics(<<"alarm_statis">>) ->
get_product_statistics(<<"alarm_statis">>, _) ->
{ok, #{<<"count">> := One}} = dgiot_parsex:query_object(<<"Notification">>, #{<<"keys">> => [<<"objectId">>], <<"limit">> => 1, <<"count">> => <<"objectId">>,
<<"where">> => #{<<"content.level">> => <<"1">>}}),
{ok, #{<<"count">> := Two}} = dgiot_parsex:query_object(<<"Notification">>, #{<<"keys">> => [<<"objectId">>], <<"limit">> => 1, <<"count">> => <<"objectId">>,
@ -783,12 +783,12 @@ get_product_statistics(<<"alarm_statis">>) ->
Now = dgiot_datetime:format(dgiot_datetime:get_today_stamp() - 604800, "YYYY-MM-DDT16:00:00.000Z"),
{Props, Notifications} =
case dgiot_parsex:query_object(<<"Notification">>, #{<<"keys">> => [<<"content">>,<<"device">>], <<"count">> => <<"objectId">>,<<"include">> => <<"device">>,
case dgiot_parsex:query_object(<<"Notification">>, #{<<"keys">> => [<<"content">>, <<"device">>], <<"count">> => <<"objectId">>, <<"include">> => <<"device">>,
<<"where">> => #{<<"createdAt">> => #{<<"$gte">> => #{<<"__type">> => <<"Date">>, <<"iso">> => Now}}}}) of
{ok, #{<<"results">> := Results}} ->
Result =
lists:foldl(fun
(#{<<"content">> := #{<<"starttime">> := Starttime}} = X, Acc) ->
(#{<<"content">> := #{<<"startdatetime">> := Starttime}} = X, Acc) ->
SList = maps:get(Starttime, Acc, []),
Acc#{Starttime => SList ++ [X]};
(_, Acc) ->
@ -868,7 +868,143 @@ get_product_statistics(<<"alarm_statis">>) ->
}
]
}
}.
};
get_product_statistics(<<"information">>, Token) ->
Key = dgiot_device_static:get_count(Token),
Props =
case dgiot_parsex:query_object(<<"Product">>, #{<<"keys">> => [<<"name">>], <<"count">> => <<"objectId">>}) of
{ok, #{<<"results">> := Results}} ->
lists:foldl(fun
(#{<<"objectId">> := ProductId, <<"name">> := Name}, Acc) ->
NewResBody = dgiot_device_static:stats(#{<<"objectId">> => ProductId}, Key),
Acc#{Name => NewResBody};
(_, Acc) ->
Acc
end, #{}, Results);
_ ->
#{}
end,
{XAxis, ONSeries, OFFSeries, PONSeries} =
maps:fold(fun(K, #{<<"online_counts">> := On, <<"offline_counts">> := Off, <<"poweron_counts">> := Pon}, {Xcc, ON, OFF, PON}) ->
{Xcc ++ [K], ON ++ [#{<<"value">> => On, <<"name">> => K}], OFF ++ [#{<<"value">> => Off, <<"name">> => K}], PON ++ [#{<<"value">> => Pon, <<"name">> => K}]}
end, {[], [], [], []}, Props),
#{
<<"tooltip">> => #{
<<"trigger">> => <<"axis">>,
<<"axisLabel">> => #{
<<"textStyle">> => #{
<<"color">> => "#FFFFFF"
},
<<"show">> => true
}
},
<<"xAxis">> => [
#{
<<"data">> => XAxis,
<<"type">> => <<"category">>,
<<"axisLabel">> => #{
<<"show">> => true,
<<"textStyle">> => #{
<<"color">> => <<"#FFFFFF">>
}
},
<<"axisPointer">> => #{
<<"type">> => <<"shadow">>
}
}
],
<<"yAxis">> => [
#{
<<"name">> => <<"在线数"/utf8>>,
<<"type">> => <<"value">>,
<<"interval">> => 1,
<<"axisLabel">> => #{
<<"formatter">> => <<"{value}">>,
<<"textStyle">> => #{
<<"color">> => <<"#FFFFFF">>
}
}
},
#{
<<"name">> => <<"离线数"/utf8>>,
<<"type">> => <<"value">>,
<<"interval">> => 1,
<<"axisLabel">> => #{
<<"formatter">> => <<"{value}">>,
<<"textStyle">> => #{
<<"color">> => <<"#FFFFFF">>
}
}
},
#{
<<"name">> => <<"激活数"/utf8>>,
<<"type">> => <<"value">>,
<<"interval">> => 1,
<<"axisLabel">> => #{
<<"formatter">> => <<"{value}">>,
<<"textStyle">> => #{
<<"color">> => <<"#FFFFFF">>
}
}
}
],
<<"legend">> => #{
<<"data">> => [
<<"在线数"/utf8>>,
<<"离线数"/utf8>>,
<<"激活数"/utf8>>
],
<<"textStyle">> => #{
<<"color">> => <<"#FFFFFF">>,
<<"fontSize">> => 14
}
},
<<"series">> => [
#{
<<"data">> => ONSeries,
<<"name">> => <<"在线数"/utf8>>,
<<"type">> => <<"bar">>,
<<"itemStyle">> => #{
<<"color">> => <<"#13ce66">>
},
<<"axisLabel">> => #{
<<"show">> => true,
<<"textStyle">> => #{
<<"color">> => <<"#ffffff">>
}
}
},
#{
<<"data">> => OFFSeries,
<<"name">> => <<"离线数"/utf8>>,
<<"type">> => <<"bar">>,
<<"itemStyle">> => #{
<<"color">> => <<"#d91b1b">>
},
<<"axisLabel">> => #{
<<"show">> => true,
<<"textStyle">> => #{
<<"color">> => <<"#ffffff">>
}
}
},
#{
<<"data">> => PONSeries,
<<"name">> => <<"激活数"/utf8>>,
<<"type">> => <<"line">>,
<<"axisLabel">> => #{
<<"show">> => true,
<<"textStyle">> => #{
<<"color">> => <<"#ffffff">>
}
}
}
]
};
get_product_statistics(_, _) ->
#{}.

View File

@ -75,7 +75,7 @@ handle(OperationID, Args, Context, Req) ->
do_request(post_dev_transfer, #{<<"objectId">> := ObjectId, <<"rolename">> := RoleName} = _Args, #{<<"sessionToken">> := SessionToken} = _Context, _Req) ->
ACL = #{<<"role:", RoleName/binary>> => #{<<"read">> => true, <<"write">> => true}},
case dgiot_parsex:get_object(<<"Device">>, ObjectId) of
{ok, #{<<"name">> := DevName}} ->
{ok, #{<<"name">> := DevName, <<"devaddr">> := Devaddr}} ->
case dgiot_parsex:update_object(<<"Device">>, ObjectId, #{<<"ACL">> => ACL}) of
{ok, Data} ->
#{<<"nick">> := Nick} = dgiot_auth:get_session(SessionToken),
@ -87,6 +87,7 @@ do_request(post_dev_transfer, #{<<"objectId">> := ObjectId, <<"rolename">> := Ro
, <<"domain">> => [<<"DeviceTransfer">>]
, <<"mfa">> => <<"DeviceTransfer">>
, <<"peername">> => DevName
, <<"devaddr">> => Devaddr
, <<"time">> => dgiot_datetime:nowstamp() * 1000
}),
dgiot_device:put(#{<<"objectId">> => ObjectId, <<"ACL">> => ACL}),
@ -183,9 +184,9 @@ do_request(delete_group, #{<<"name">> := _Name, <<"devType">> := _DevType} = Bod
?LOG(info, "Body ~p ", [Body]),
delete_group(Body, SessionToken);
do_request(get_product_statistics, #{<<"type">> := Type} = _Args, #{<<"sessionToken">> := _SessionToken}, _Body) ->
do_request(get_product_statistics, #{<<"type">> := Type} = _Args, #{<<"sessionToken">> := SessionToken}, _Body) ->
%% Data = get_statistics(SessionToken),
Data = dgiot_product:get_product_statistics(Type),
Data = dgiot_product:get_product_statistics(Type, SessionToken),
{ok, #{<<"status">> => 0, msg => <<"ok">>, <<"data">> => Data}};
%% API接口

View File

@ -351,7 +351,7 @@ save_Product_konva(ProductId) ->
Type = maps:get(<<"type">>, DataType, <<"">>),
Specs = maps:get(<<"specs">>, DataType, #{}),
Unit = maps:get(<<"unit">>, Specs, <<"">>),
Identifier = maps:get(<<"identifier">>, P, <<"">>),
Identifier = dgiot_utils:to_binary(maps:get(<<"identifier">>, P, <<"">>)),
Name = maps:get(<<"name">>, P, <<"">>),
dgiot_data:insert({product, <<ProductId/binary, Identifier/binary>>}, {Name, Type, Unit}),
dgiot_data:insert({thing, <<ProductId/binary, Identifier/binary>>}, P)

View File

@ -257,7 +257,7 @@ save_notification(Ruleid, DeviceId, Payload, NotificationId) ->
_ ->
{<<>>, 1}
end,
Content = Payload#{<<"starttime">> => dgiot_datetime:format("MM.DD"), <<"alarm_createdAt">> => Alarm_createdAt, <<"alarm_message">> => Alarm_message, <<"level">> => Level, <<"_deviceid">> => DeviceId, <<"_productid">> => ProductId},
Content = Payload#{<<"startdatetime">> => dgiot_datetime:format("MM.DD"), <<"alarm_createdAt">> => Alarm_createdAt, <<"alarm_message">> => Alarm_message, <<"level">> => Level, <<"_deviceid">> => DeviceId, <<"_productid">> => ProductId},
dgiot_parse:create_object(<<"Notification">>, #{
<<"objectId">> => NotificationId,
<<"ACL">> => Acl,