diff --git a/apps/iot/src/database/device_bo.erl b/apps/iot/src/database/device_bo.erl index 40875ac..af8ad7e 100644 --- a/apps/iot/src/database/device_bo.erl +++ b/apps/iot/src/database/device_bo.erl @@ -33,13 +33,7 @@ get_device_by_uuid(DeviceUUID) when is_binary(DeviceUUID) -> %% 修改主机的状态 -spec change_status(DeviceUUID :: binary(), Status :: integer()) -> {ok, AffectedRows :: integer()} | {error, Reason :: any()}. change_status(DeviceUUID, NStatus) when is_binary(DeviceUUID), is_integer(NStatus) -> - case change_status0(DeviceUUID, NStatus) of - Result = {ok, _} -> - event_logs_bo:insert(?EVENT_DEVICE, DeviceUUID, NStatus), - Result; - Error -> - Error - end. + change_status0(DeviceUUID, NStatus). change_status0(DeviceUUID, ?DEVICE_ONLINE) when is_binary(DeviceUUID) -> Timestamp = calendar:local_time(), case mysql_pool:get_row(mysql_iot, <<"SELECT status FROM device WHERE device_uuid = ? LIMIT 1">>, [DeviceUUID]) of diff --git a/apps/iot/src/database/host_bo.erl b/apps/iot/src/database/host_bo.erl index f10d127..f2e5087 100644 --- a/apps/iot/src/database/host_bo.erl +++ b/apps/iot/src/database/host_bo.erl @@ -33,13 +33,7 @@ get_host_by_id(HostId) when is_integer(HostId) -> %% 修改主机的状态 -spec change_status(UUID :: binary(), Status :: integer()) -> {ok, AffectedRows :: integer()} | {error, Reason :: any()}. change_status(UUID, NStatus) when is_binary(UUID), is_integer(NStatus) -> - case change_status0(UUID, NStatus) of - Result = {ok, _} -> - event_logs_bo:insert(?EVENT_HOST, UUID, NStatus), - Result; - Error -> - Error - end. + change_status0(UUID, NStatus). change_status0(UUID, ?HOST_ONLINE) when is_binary(UUID) -> Timestamp = calendar:local_time(), case mysql_pool:get_row(mysql_iot, <<"SELECT status FROM host WHERE uuid = ? LIMIT 1">>, [UUID]) of diff --git a/apps/iot/src/database/scene_feedback.erl b/apps/iot/src/database/scene_feedback.erl deleted file mode 100644 index b7620ee..0000000 --- a/apps/iot/src/database/scene_feedback.erl +++ /dev/null @@ -1,17 +0,0 @@ -%%%------------------------------------------------------------------- -%%% @author aresei -%%% @copyright (C) 2023, -%%% @doc -%%% -%%% @end -%%% Created : 16. 5月 2023 12:48 -%%%------------------------------------------------------------------- --module(scene_feedback). --author("aresei"). --include("iot.hrl"). - -%% API --export([insert/1]). - -insert(Fields) when is_map(Fields) -> - mysql_pool:insert(mysql_iot, <<"scene_feedback">>, Fields, true). \ No newline at end of file diff --git a/apps/iot/src/database/scene_feedback_step.erl b/apps/iot/src/database/scene_feedback_step.erl deleted file mode 100644 index c404896..0000000 --- a/apps/iot/src/database/scene_feedback_step.erl +++ /dev/null @@ -1,17 +0,0 @@ -%%%------------------------------------------------------------------- -%%% @author aresei -%%% @copyright (C) 2023, -%%% @doc -%%% -%%% @end -%%% Created : 16. 5月 2023 12:48 -%%%------------------------------------------------------------------- --module(scene_feedback_step). --author("aresei"). --include("iot.hrl"). - -%% API --export([insert/1]). - -insert(Fields) when is_map(Fields) -> - mysql_pool:insert(mysql_iot, <<"scene_feedback_step">>, Fields, true). \ No newline at end of file diff --git a/apps/iot/src/http/service_handler.erl b/apps/iot/src/http/service_handler.erl index 61fefb5..284ee0e 100644 --- a/apps/iot/src/http/service_handler.erl +++ b/apps/iot/src/http/service_handler.erl @@ -31,7 +31,7 @@ handle_request("POST", "/service/set_config", _, #{<<"service_id">> := ServiceId {ok, 200, iot_util:json_error(404, <<"set service config failed">>)} end; -handle_request("POST", "/service/push_config", _, #{<<"host_uuid">> := HostUUID, <<"service_id">> := ServiceId}) +handle_request("POST", "/service/push_config", _, #{<<"host_uuid">> := HostUUID, <<"service_id">> := ServiceId, <<"timeout">> := Timeout}) when is_binary(ServiceId), is_binary(HostUUID) -> lager:debug("[service_handler] push_config host_uuid: ~p, service_id: ~p", [ServiceId, HostUUID, ServiceId]), @@ -43,7 +43,7 @@ handle_request("POST", "/service/push_config", _, #{<<"host_uuid">> := HostUUID, undefined -> {ok, 200, iot_util:json_error(404, <<"host not found">>)}; HostPid when is_pid(HostPid) -> - case iot_host:async_service_config(HostPid, ConfigJson) of + case iot_host:async_service_config(HostPid, ServiceId, ConfigJson, Timeout) of {ok, Ref} -> case iot_host:await_reply(Ref, 15000) of {ok, #async_call_reply{code = 1}} -> diff --git a/apps/iot/src/iot_host.erl b/apps/iot/src/iot_host.erl index 4b3b9d6..64a863b 100644 --- a/apps/iot/src/iot_host.erl +++ b/apps/iot/src/iot_host.erl @@ -25,7 +25,7 @@ -export([get_metric/1, get_status/1]). %% 通讯相关 -export([pub/3, attach_channel/2, command/3]). --export([async_deploy/4, async_invoke/4, async_service_config/2, async_task_log/2, await_reply/2]). +-export([async_deploy/4, async_invoke/4, async_service_config/4, async_task_log/2, await_reply/2]). %% 设备管理 -export([reload_device/2, delete_device/2, activate_device/3]). -export([heartbeat/1]). @@ -89,9 +89,10 @@ get_metric(Pid) when is_pid(Pid) -> attach_channel(Pid, ChannelPid) when is_pid(Pid), is_pid(ChannelPid) -> gen_statem:call(Pid, {attach_channel, ChannelPid}). --spec async_service_config(Pid :: pid(), ConfigJson :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. -async_service_config(Pid, ConfigJson) when is_pid(Pid), is_binary(ConfigJson) -> - gen_statem:call(Pid, {async_call, self(), ?PUSH_SERVICE_CONFIG, ConfigJson}). +-spec async_service_config(Pid :: pid(), ServiceId :: binary(), ConfigJson :: binary(), Timeout :: integer()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. +async_service_config(Pid, ServiceId, ConfigJson, Timeout) when is_pid(Pid), is_binary(ServiceId), is_binary(ConfigJson), is_integer(Timeout) -> + ConfigBin = message_pb:encode_msg(#push_service_config{service_id = ServiceId, config_json = ConfigJson, timeout = Timeout}), + gen_statem:call(Pid, {async_call, self(), ?PUSH_SERVICE_CONFIG, ConfigBin}). -spec async_deploy(Pid :: pid(), TaskId :: integer(), ServiceId :: binary(), TarUrl :: binary()) -> {ok, Ref :: reference()} | {error, Reason :: any()}. async_deploy(Pid, TaskId, ServiceId, TarUrl) when is_pid(Pid), is_integer(TaskId), is_binary(ServiceId), is_binary(TarUrl) ->