From 5d98da77fa019a985725a435b44b0f56583543b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E7=A4=BC=E6=88=90?= Date: Thu, 16 Feb 2023 16:32:34 +0800 Subject: [PATCH] fix --- apps/iot/src/model/host_model.erl | 14 +++++++------- apps/iot/src/model/terminal_model.erl | 6 ++++++ 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/apps/iot/src/model/host_model.erl b/apps/iot/src/model/host_model.erl index 59a8c9f..4cfb559 100644 --- a/apps/iot/src/model/host_model.erl +++ b/apps/iot/src/model/host_model.erl @@ -12,7 +12,7 @@ -include_lib("stdlib/include/qlc.hrl"). %% API --export([get_all_hosts/0, insert/4, change_status/2]). +-export([get_all_hosts/0, insert/4, change_status/2, delete/1, table_size/0]). %% 获取app信息 get_all_hosts() -> @@ -22,6 +22,7 @@ get_all_hosts() -> end, case mnesia:transaction(Fun) of {atomic, Items} when is_list(Items) -> + %% 按照状态分组统计 Stat = lists:foldl(fun(#host{status = Status}, Acc) -> Num = maps:get(Status, Acc, 0), Acc#{Status => Num + 1} @@ -37,7 +38,6 @@ insert(Id, Name, Model, CellId) -> name = Name, model = Model, cell_id = CellId, - terminal_num = 0, update_ts = 0, status = ?HOST_STATUS_INACTIVE }, @@ -49,11 +49,11 @@ insert(Id, Name, Model, CellId) -> {error, Error} end. -change_status(Id, Status) -> +change_status(HostId, Status) when is_binary(HostId), is_integer(Status) -> Fun = fun() -> - case mnesia:read(host, Id) of + case mnesia:read(host, HostId) of [] -> - mnesia:abort(<<"appinfo not found">>); + mnesia:abort(<<"host not found">>); [Host] -> NHost = Host#host{status = Status}, mnesia:write(host, NHost, write) @@ -66,8 +66,8 @@ change_status(Id, Status) -> {error, Reason} end. -delete(Id) -> - case mnesia:transaction(fun() -> mnesia:delete(host, Id, write) end) of +delete(HostId) when is_binary(HostId) -> + case mnesia:transaction(fun() -> mnesia:delete(host, HostId, write) end) of {atomic, ok} -> ok; {aborted, Reason} -> diff --git a/apps/iot/src/model/terminal_model.erl b/apps/iot/src/model/terminal_model.erl index 1db2963..395ba95 100644 --- a/apps/iot/src/model/terminal_model.erl +++ b/apps/iot/src/model/terminal_model.erl @@ -26,6 +26,12 @@ get_all_terminals() -> {error, Reason} end. +get_status_groups() -> + + + ok. + + insert(Id, HostId, Name, ProductId, VendorId, Model, CellId) -> Terminal = #terminal{ id = Id,