diff --git a/apps/dgiot_device/src/utils/dgiot_product_knova.erl b/apps/dgiot_device/src/utils/dgiot_product_knova.erl index 1a551e4a..b7ef4ec5 100644 --- a/apps/dgiot_device/src/utils/dgiot_product_knova.erl +++ b/apps/dgiot_device/src/utils/dgiot_product_knova.erl @@ -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; diff --git a/apps/dgiot_factory/src/dgiot_factory_channel.erl b/apps/dgiot_factory/src/dgiot_factory_channel.erl index 0b2bed7d..0aae1e31 100644 --- a/apps/dgiot_factory/src/dgiot_factory_channel.erl +++ b/apps/dgiot_factory/src/dgiot_factory_channel.erl @@ -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 = <>, + 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; _ -> diff --git a/apps/dgiot_factory/src/dgiot_factory_worker.erl b/apps/dgiot_factory/src/dgiot_factory_worker.erl index 041df3c3..fa619d88 100644 --- a/apps/dgiot_factory/src/dgiot_factory_worker.erl +++ b/apps/dgiot_factory/src/dgiot_factory_worker.erl @@ -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). diff --git a/apps/dgiot_printer/src/dgiot_printer.erl b/apps/dgiot_printer/src/dgiot_printer.erl index 1972cc37..8061c60f 100644 --- a/apps/dgiot_printer/src/dgiot_printer.erl +++ b/apps/dgiot_printer/src/dgiot_printer.erl @@ -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} ->