fix host
This commit is contained in:
parent
36b3ec4bf8
commit
d6b82f7ab2
19
apps/iot/src/database/micro_set_bo.erl
Normal file
19
apps/iot/src/database/micro_set_bo.erl
Normal 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]).
|
||||||
@ -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])
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user