fix
This commit is contained in:
parent
692660e899
commit
c79a6edad4
@ -13,9 +13,9 @@
|
||||
-export([insert_hosts/0]).
|
||||
|
||||
insert_hosts() ->
|
||||
lists:foreach(fun(_) ->
|
||||
Id0 = iot_util:rand_bytes(16),
|
||||
Id = list_to_binary(Id0),
|
||||
lists:foreach(fun(Id0) ->
|
||||
%Id0 = iot_util:rand_bytes(16),
|
||||
Id = integer_to_binary(Id0),
|
||||
Name = <<"N1000_0001">>,
|
||||
Model = <<"N1000">>,
|
||||
CellId = <<"公共教学楼"/utf8>>,
|
||||
|
||||
@ -12,7 +12,7 @@
|
||||
-include_lib("stdlib/include/qlc.hrl").
|
||||
|
||||
%% API
|
||||
-export([get_hosts/2, insert/4, change_status/2, delete/1, table_size/0]).
|
||||
-export([get_hosts/2, insert/4, change_status/2, delete/1, table_size/0, filter_hosts/3]).
|
||||
|
||||
%% 获取app信息
|
||||
get_hosts(Start, Limit) when is_integer(Limit), is_integer(Start), Start >= 0, Limit > 0 ->
|
||||
@ -38,6 +38,25 @@ get_hosts(Start, Limit) when is_integer(Limit), is_integer(Start), Start >= 0, L
|
||||
Error
|
||||
end.
|
||||
|
||||
filter_hosts(Pred, Start, Limit) when is_function(Pred, 1), is_integer(Limit), is_integer(Start), Start >= 0, Limit > 0 ->
|
||||
Fun = fun() ->
|
||||
Q = qlc:q([E || E <- mnesia:table(host)]),
|
||||
qlc:fold(fun(Host, Acc) ->
|
||||
case Pred(Host) of
|
||||
true -> [Host|Acc];
|
||||
false -> Acc
|
||||
end
|
||||
end, [], Q)
|
||||
|
||||
end,
|
||||
case mnesia:transaction(Fun) of
|
||||
{atomic, Items} when is_list(Items) ->
|
||||
Items1 = lists:reverse(Items),
|
||||
{ok, lists:sublist(Items1, Start + 1, Limit)};
|
||||
{aborted, Error} ->
|
||||
Error
|
||||
end.
|
||||
|
||||
insert(Id, Name, Model, CellId) ->
|
||||
Host = #host{
|
||||
id = Id,
|
||||
|
||||
@ -14,8 +14,9 @@
|
||||
sasl]},
|
||||
|
||||
% {mode, dev},
|
||||
{mode, prod},
|
||||
|
||||
%% automatically picked up if the files
|
||||
%% automatically picked up if the files
|
||||
%% exist but can be set manually, which
|
||||
%% is required if the names aren't exactly
|
||||
%% sys.config and vm.args
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user