简化数据库概念
This commit is contained in:
parent
d52d779f6f
commit
e7d4877d22
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -1,17 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author aresei
|
||||
%%% @copyright (C) 2023, <COMPANY>
|
||||
%%% @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).
|
||||
@ -1,17 +0,0 @@
|
||||
%%%-------------------------------------------------------------------
|
||||
%%% @author aresei
|
||||
%%% @copyright (C) 2023, <COMPANY>
|
||||
%%% @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).
|
||||
@ -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}} ->
|
||||
|
||||
@ -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) ->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user