Skip to content

Commit

Permalink
fix:factory
Browse files Browse the repository at this point in the history
  • Loading branch information
shifttttttt committed Oct 13, 2022
1 parent a96c907 commit 8c2e399
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 13 deletions.
5 changes: 2 additions & 3 deletions apps/dgiot_bamis/src/dgiot_bamis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -238,13 +238,12 @@ format_multilayer(Object) ->
end
end,
#{}, MapWhere).


format_value(#{<<"gt">> := V}) ->
#{<<"$gt">> => V};

format_value(#{<<"lt">> := V}) ->
#{<<"$lt">> => V};
format_value(#{<<"regex">> := V}) ->
#{<<"$regex">> => V};
format_value(V) ->
V.
%%dgiot_parse:query_object(<<"Device">>,#{<<"where">> => #{<<"content.quality.status">> => #{<<"$gt">> => 3}}, <<"product">> => <<"b0ec1970c7">>
11 changes: 7 additions & 4 deletions apps/dgiot_factory/src/dgiot_factory_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ handle_data(_TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAd
dgiot_task:save_td(BatchProductId, BatchAddr, maps:merge(OldNumData, NumData), #{}),
Content.
get_card_data(BatchProductId, BatchDeviceId) ->
DevcieTypeList = dgiot_product:get_devicetype(BatchProductId),
DevcieTypeList = dgiot_product:get_devicetype(BatchProductId) -- [<<"quality">>],
lists:foldl(
fun(DeviceType, {Num, Name}) ->
case dgiot_data:get(?FACTORY_ORDER, {BatchProductId, BatchDeviceId, DeviceType}) of
Expand Down Expand Up @@ -202,10 +202,14 @@ get_sub_product(ProductId) ->
end.

process_roll_dev(TaskProductId, TaskDeviceId, OrderName, SessionToken, FlatMap) ->
{BatchProductId, BatchDeviceId, BatchAddr} = get_roll_dev_id(TaskProductId, FlatMap),
{BatchProductId, BatchDeviceId, BatchAddr} = case get_roll_dev_id(TaskProductId, FlatMap) of
{A, B, C} ->
{A, B, C};
_ -> {<<"1">>, <<"1">>, <<"1">>}
end,
case dgiot_device_cache:lookup(BatchDeviceId) of
{ok, #{<<"acl">> := Acl}} ->
io:format("~s ~p RollDeviceId = ~p ~n", [?FILE, ?LINE, BatchDeviceId]),
io:format("~s ~p BatchDeviceId = ~p ~n", [?FILE, ?LINE, BatchDeviceId]),
NewAcl = get_new_acl(SessionToken, Acl),
%% dgiot_device_cache:put(#{<<"objectId">> => TaskDeviceId, <<"ACL">> => NewAcl}),
dgiot_parse:update_object(<<"Device">>, BatchDeviceId, #{<<"ACL">> => NewAcl}),
Expand Down Expand Up @@ -245,7 +249,6 @@ get_roll_dev_id(ProductId, FlatMap) ->
error
end;
_ ->

BatchAddr = dgiot_utils:to_binary(dgiot_datetime:nowstamp()),
BatchDeviceId = list_to_binary(string:to_upper(binary_to_list(dgiot_parse_id:get_deviceid(BatchProductId, BatchAddr)))),
{BatchProductId, BatchDeviceId, BatchAddr}
Expand Down
8 changes: 5 additions & 3 deletions apps/dgiot_factory/src/dgiot_factory_data.erl
Original file line number Diff line number Diff line change
Expand Up @@ -581,13 +581,14 @@ filter_data(Data) when is_map(Data) ->
%%get_td_sheet(ProductId, Type, Start, End, Channel, DeviceId, Where, Limit, Skip, New)

get_history_data(ProductId, DeviceId, Type, Function, FunctionMap, Group,Having, Where, Order, Channel, Limit, Skip) ->
io:format("~s ~p ProductId = ~p ~n", [?FILE, ?LINE, ProductId]),
DB = dgiot_tdengine_select:format_db(?Database(ProductId)),
TableName = case DeviceId of
undefined ->
?Table(ProductId);
Lower = list_to_binary(string:to_lower(dgiot_utils:to_list(ProductId))),
?Table(Lower);
_ ->
?Table(DeviceId)
Low = list_to_binary(string:to_lower(dgiot_utils:to_list(DeviceId))),
?Table(Low)
end,
Select = select(ProductId, Type, Function, FunctionMap),
From = <<DB/binary, TableName/binary>>,
Expand All @@ -600,6 +601,7 @@ get_history_data(ProductId, DeviceId, Type, Function, FunctionMap, Group,Having,
fun(Context) ->
Sql = <<"SELECT ", Select/binary, " FROM ", From/binary, WHERE/binary,GROPU/binary,Have/binary, ORDER/binary, ";">>,
io:format("~s ~p Sql = ~p ~n", [?FILE, ?LINE, Sql]),

dgiot_tdengine_pool:run_sql(Context#{<<"channel">> => Channel}, execute_query, Sql)
end)
of
Expand Down
6 changes: 3 additions & 3 deletions apps/dgiot_factory/src/dgiot_factory_handler.erl
Original file line number Diff line number Diff line change
Expand Up @@ -136,17 +136,17 @@ do_request(get_data, #{<<"productId">> := ProductId, <<"objectId">> := DeviceId,
<<"function">> := Function, <<"functionmap">> := FunctionMap, <<"group">> := Group, <<"having">> := Having,
<<"order">> := Order, <<"where">> := Where, <<"limit">> := Limit, <<"skip">> := Skip} = _Args,
#{<<"sessionToken">> := SessionToken} = _Context, _Body) ->
io:format("~s ~p _Args = ~p ~n", [?FILE, ?LINE, _Args]),
%% io:format("~s ~p _Args = ~p ~n", [?FILE, ?LINE, _Args]),
case dgiot_product_tdengine:get_channel(SessionToken) of
{error, Error} ->
io:format("~s ~p ProductId = ~p ~n", [?FILE, ?LINE, ProductId]),
%% io:format("~s ~p ProductId = ~p ~n", [?FILE, ?LINE, ProductId]),
{error, Error};
{ok, Channel} ->
case dgiot_factory_data:get_history_data(ProductId, DeviceId, Type, Function, FunctionMap, Group, Having, Where, Order, Channel, Limit, Skip) of
{ok, {Total, Res}} ->
{ok, #{<<"status">> => 0, msg => <<"数据请求成功"/utf8>>, <<"data">> => #{<<"total">> => Total, <<"items">> => Res}}};
_ ->
io:format("~s ~p ProductId = ~p ~n", [?FILE, ?LINE, ProductId]),
io:format("~s ~p here ~n", [?FILE, ?LINE]),
{error, <<"get_data_failed">>}
end;
_ ->
Expand Down

0 comments on commit 8c2e399

Please sign in to comment.