fix:printer

This commit is contained in:
guo 2022-12-14 21:26:25 +08:00
parent 777c878acd
commit 5e8b21211a
4 changed files with 36 additions and 9 deletions

View File

@ -377,7 +377,7 @@ get_stage(ProductId) ->
end.
get_stage(ProductId, Tiltle) ->
ViewId = dgiot_parse_id:get_viewid(ProductId, <<"topo">>, <<"Product">>, Tiltle),
ViewId = dgiot_parse_id:get_viewid(ProductId, <<"Topo">>, <<"Product">>, Tiltle),
case dgiot_parse:get_object(<<"View">>, ViewId) of
{ok, #{<<"data">> := #{<<"konva">> := #{<<"Stage">> := Stage}}}} ->
Stage;

View File

@ -351,7 +351,9 @@ get_wokrer_id(Name, DevType) ->
dgiot_parse_id:get_productid(?WORKERCATEGORY, DevType, Name).
init_worker_device(ProductId, WorkerNum, WorkerName) ->
DeviceId = dgiot_parse_id:get_deviceid(ProductId,WorkerNum),
BinNum = dgiot_utils:to_binary(WorkerNum),
Devaddr = <<WorkerName/binary,"_",BinNum/binary>>,
DeviceId = dgiot_parse_id:get_deviceid(ProductId,Devaddr),
case dgiot_device_cache:lookup(DeviceId) of
{ok,_} ->
io:format("~s ~p DeviceId = ~p ~n",[?FILE,?LINE,DeviceId]),
@ -361,18 +363,20 @@ init_worker_device(ProductId, WorkerNum, WorkerName) ->
{ok, Product} ->
case Product of
#{<<"ACL">> := Acl, <<"name">> := Name, <<"devType">> := DevType, <<"dynamicReg">> := true} ->
%% +"_"+
Device = #{
<<"profile">>=>#{<<"worker_flag">> => 1},
<<"status">> => <<"ONLINE">>,
<<"brand">> => Name,
<<"devModel">> => DevType,
<<"name">> => WorkerName,
<<"devaddr">> => WorkerNum,
<<"name">> => Devaddr,
<<"devaddr">> => Devaddr,
<<"product">> => ProductId,
<<"ACL">> => Acl
},
io:format("~s ~p DeviceId = ~p ~n",[?FILE,?LINE,DeviceId]),
dgiot_device:create_device(Device),
io:format("~s ~p DeviceId = ~p ~n", [?FILE, ?LINE, DeviceId]),
dgiot_parse:update_object(<<"Device">>,DeviceId , #{<<"ACL">>=> Acl#{<<"*">> =>#{<<"read">> => true}}}),
AllData = #{<<"worker_validate">> => true,
<<"worker_num">> => WorkerNum,
@ -381,8 +385,9 @@ init_worker_device(ProductId, WorkerNum, WorkerName) ->
<<"product">> => ProductId},
NumData = dgiot_product_enum:turn_num(AllData, ProductId),
dgiot_data:insert(?WORKER, {ProductId, WorkerNum}, WorkerName),
dgiot_task:save_td_no_match(ProductId, WorkerNum, NumData, #{});
dgiot_task:save_td_no_match(ProductId, Devaddr, NumData, #{});
_ ->
io:format("~s ~p not_find_product ~n",[?FILE,?LINE]),
pass
end;
_ ->

View File

@ -154,8 +154,8 @@ get_new_workernum(WorkerProduct) ->
Max = lists:foldl(
fun(X, Acc) ->
case maps:find(<<"devaddr">>, X) of
{ok, WorkerNum} ->
Num = dgiot_utils:to_int(WorkerNum),
{ok, Devaddr} ->
Num = get_worker_num(Devaddr),
case Acc > Num of
true ->
Acc;
@ -444,3 +444,8 @@ format_worker(_, Worker) ->
%% end
%%
%% end, [], WorkerList);
get_worker_num(Devaddr)->
[_,Num] =re:split(Devaddr,<<"_">>),
dgiot_utils:to_int(Num).

View File

@ -27,7 +27,24 @@
handle_profile({QueryData, ProductId, _State}) ->
get_topo(QueryData, ProductId).
get_topo(#{<<"profile">> := #{<<"Topo">> := Topo} = Profile} = QueryData, ProductId) ->
case dgiot_product_knova:get_stage(ProductId, Topo) of
{ok, Stage} ->
StageMap = dgiot_product_knova:get_nodes(Stage, [<<"Text">>, <<"Rect">>]),
NewProfile =
maps:fold(fun(K, V, Acc) ->
case maps:find(K, Profile) of
error ->
Acc ++ [V];
{ok, Text} ->
Acc ++ [V#{<<"text">> => Text}]
end
end, [], StageMap),
Cmd = maps:get(<<"cmd">>, Profile, <<"printer_barcode">>),
QueryData#{<<"profile">> => #{<<"cmd">> => Cmd, <<"data">> => NewProfile}};
_ ->
QueryData
end;
get_topo(#{<<"profile">> := Profile} = QueryData, ProductId) ->
case dgiot_product_knova:get_stage(ProductId) of
{ok, Stage} ->