This commit is contained in:
anlicheng 2023-06-19 10:02:35 +08:00
parent 36b3ec4bf8
commit d6b82f7ab2
2 changed files with 23 additions and 5 deletions

View File

@ -0,0 +1,19 @@
%%%-------------------------------------------------------------------
%%% @author aresei
%%% @copyright (C) 2023, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 16. 5 2023 12:48
%%%-------------------------------------------------------------------
-module(micro_set_bo).
-author("aresei").
-include("iot.hrl").
%% API
-export([change_status/4]).
%%
-spec change_status(HostId :: integer(), SceneId :: integer(), MircoId :: integer(), Status :: integer()) -> {ok, AffectedRows :: integer()} | {error, Reason :: any()}.
change_status(HostId, SceneId, MircoId, Status) when is_integer(HostId), is_integer(SceneId), is_integer(MircoId), is_integer(Status) ->
mysql_client:update_by(<<"UPDATE micro_set SET status = ? WHERE host_id = ? AND scene_id = ? AND micro_id = ? LIMIT 1">>, [Status, HostId, SceneId, MircoId]).

View File

@ -359,8 +359,9 @@ handle_message(#{<<"method">> := <<"inform">>, <<"params">> := Info0}, State = #
Info = iot_cipher_aes:decrypt(AES, base64:decode(Info0)), Info = iot_cipher_aes:decrypt(AES, base64:decode(Info0)),
case catch jiffy:decode(Info, [return_maps]) of case catch jiffy:decode(Info, [return_maps]) of
#{<<"at">> := At, <<"services">> := ServiceInforms} -> #{<<"at">> := At, <<"services">> := ServiceInforms} ->
lists:foreach(fun(Item = #{<<"name">> := Name, <<"version">> := Version, <<"version_copy">> := VersionCopy, <<"status">> := Status}) -> lists:foreach(fun(#{<<"props">> := Props, <<"name">> := Name, <<"version">> := Version, <<"version_copy">> := VersionCopy, <<"status">> := Status}) ->
SceneId = maps:get(<<"scene_id">>, Item, 0), %% props id:id:id
[_, SceneId, MicroId] = binary:split(Props, <<":">>, [global]),
micro_inform_log:insert(#{ micro_inform_log:insert(#{
<<"host_id">> => HostId, <<"host_id">> => HostId,
<<"scene_id">> => SceneId, <<"scene_id">> => SceneId,
@ -370,9 +371,7 @@ handle_message(#{<<"method">> := <<"inform">>, <<"params">> := Info0}, State = #
<<"status">> => Status, <<"status">> => Status,
<<"created_at">> => At <<"created_at">> => At
}), }),
micro_set_bo:change_status(HostId, SceneId, MicroId, Status)
%% TODO
ok
end, ServiceInforms); end, ServiceInforms);
Error -> Error ->
lager:warning("[iot_host] inform get error: ~p", [Error]) lager:warning("[iot_host] inform get error: ~p", [Error])