Skip to content

Commit

Permalink
fix:product_enum and factory_worker
Browse files Browse the repository at this point in the history
  • Loading branch information
shifttttttt committed Oct 24, 2022
1 parent 509c596 commit 9982a38
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 41 deletions.
41 changes: 23 additions & 18 deletions apps/dgiot_device/src/utils/dgiot_product_enum.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,26 @@ save_product_enum(ProductId) ->
fun
(#{<<"devicetype">> := DeviceType, <<"identifier">> := Identifier,
<<"dataType">> := #{<<"type">> := <<"enum">>, <<"specs">> := Spec}}) ->
case dgiot_data:get(?MODULE, {ProductId, device_thing, DeviceType}) of
dgiot_data:insert(?MODULE, {ProductId, device_thing, Identifier},
#{Identifier => <<"enum">>, <<"specs">> => Spec}),
case dgiot_data:get(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType}) of
not_find ->
dgiot_data:insert(?MODULE, {ProductId, device_thing, Identifier},
#{Identifier => <<"enum">>, <<"specs">> => Spec}),
dgiot_data:insert(?MODULE, {ProductId, device_thing, DeviceType},
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType},
#{Identifier => <<"enum">>});
Map ->
dgiot_data:insert(?MODULE, {ProductId, device_thing, Identifier},
#{Identifier => <<"enum">>, <<"specs">> => Spec}),
dgiot_data:insert(?MODULE, {ProductId, device_thing, DeviceType},
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType},
Map#{Identifier => <<"enum">>})
end;
(#{<<"devicetype">> := DeviceType, <<"identifier">> := Identifier, <<"dataType">> := #{<<"type">> := Type}}) ->
case dgiot_data:get(?MODULE, {ProductId, device_thing, DeviceType}) of
dgiot_data:insert(?MODULE, {ProductId, device_thing, Identifier}, #{Identifier => Type}),
case dgiot_data:get(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType}) of
not_find ->
dgiot_data:insert(?MODULE, {ProductId, device_thing, Identifier}, #{Identifier => Type});
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType},
#{Identifier => <<"enum">>});
Map ->
dgiot_data:insert(?MODULE, {ProductId, device_thing, DeviceType}, Map#{Identifier => Type})
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType},
Map#{Identifier => <<"enum">>})
end


end, Props);

_Error ->
Expand Down Expand Up @@ -97,10 +96,9 @@ post_enum_value(ProductId, Identifier, Name) ->
Acc
end
end, 0, Spec),

upadte_thing(ProductId, Identifier, Name, Max);
_ ->
upadte_thing(ProductId, Identifier, Name, #{<<"0">> => Name})
upadte_thing(ProductId, Identifier, Name, -1)
end.
upadte_thing(ProductId, Identifier, Name, Max) ->
case dgiot_parse:get_object(<<"Product">>, ProductId) of
Expand All @@ -116,7 +114,8 @@ upadte_thing(ProductId, Identifier, Name, Max) ->
end
end, [], Properties),
NewThing = Thing#{<<"properties">> => NewProperties},
dgiot_parse:update_object(<<"Product">>, ProductId, #{<<"thing">> => NewThing});
dgiot_parse:update_object(<<"Product">>, ProductId, #{<<"thing">> => NewThing}),
#{Name => Max + 1};
_ ->
pass
end.
Expand All @@ -139,7 +138,7 @@ turn_name(FlatMap, ProductId) when is_map(FlatMap) ->
case maps:find(K, Acc) of
{ok, Data} ->
case get_enmu_value(ProductId, K, Data) of
#{K := Value} ->
#{Data := Value} ->
Acc#{K => Value};
_ ->
Acc
Expand All @@ -166,13 +165,19 @@ turn_num(FlatMap, ProductId) ->
fun(K, V, Acc) ->
case V of
<<"enum">> ->

case maps:find(K, Acc) of
{ok, Data} ->
case get_enmu_key(ProductId, K, Data) of
#{K := Value} ->
#{Data := Value} ->
Acc#{K => Value};
_ ->
Acc
case post_enum_value(ProductId, K, Data) of
#{K := Value} ->
Acc#{K => Value};
_ ->
Acc
end
end;
_ ->
Acc
Expand Down
13 changes: 7 additions & 6 deletions apps/dgiot_factory/src/dgiot_factory_channel.erl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ handle_message({sync_parse, _Pid, 'before', put, Token, <<"Device">>,
#{<<"person">> := #{<<"type">> := PersonType}} ->
case process_data(Content, PersonType, Token, TaskDeviceId) of
{BatchProductId, BatchDeviceId, BatchAddr, NewData} ->
handle_data(TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAddr, PersonType, NewData,ChannelId),
handle_data(TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAddr, PersonType, NewData, ChannelId),
{ok, State};
_ ->
{ok, State}
Expand Down Expand Up @@ -166,8 +166,8 @@ stop(ChannelType, ChannelId, _State) ->
%% save_data(ProductId, Id, DevAddr, DeviceId, PersonType, Payload).


handle_data(_TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAddr, PersonType, NewData,ChannelId) ->
NewPayLoad = run_factory_hook(_TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, PersonType, NewData,ChannelId),
handle_data(_TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAddr, PersonType, NewData, ChannelId) ->
NewPayLoad = run_factory_hook(_TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, PersonType, NewData, ChannelId),
dgiot_data:insert(?FACTORY_ORDER, {BatchProductId, BatchDeviceId, PersonType}, NewPayLoad),
OldData = get_card_data(BatchProductId, BatchDeviceId),
ALlData = dgiot_map:merge(OldData, NewPayLoad),
Expand Down Expand Up @@ -220,8 +220,8 @@ turn_user(#{<<"person_sessiontoken">> := SessionToken}) ->
SessionToken
end.

run_factory_hook(TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, PersonType, NewData,ChannelId) ->
case dgiot_hook:run_hook({factory, TaskProductId, PersonType}, [BatchProductId, TaskDeviceId, BatchDeviceId, PersonType, NewData,ChannelId]) of
run_factory_hook(TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, PersonType, NewData, ChannelId) ->
case dgiot_hook:run_hook({factory, TaskProductId, PersonType}, [BatchProductId, TaskDeviceId, BatchDeviceId, PersonType, NewData, ChannelId]) of
{ok, [{ok, Res}]} ->
Res;
_ ->
Expand All @@ -247,7 +247,7 @@ process_roll_dev(TaskProductId, TaskDeviceId, OrderName, SessionToken, FlatMap)
{ok, #{<<"acl">> := Acl}} ->
io:format("~s ~p BatchDeviceId = ~p ~n", [?FILE, ?LINE, BatchDeviceId]),
NewAcl = get_new_acl(SessionToken, Acl),
dgiot_parse:update_object(<<"Device">>, BatchDeviceId, #{<<"ACL">> => NewAcl,<<"isEnable">> =>true}),
dgiot_parse:update_object(<<"Device">>, BatchDeviceId, #{<<"ACL">> => NewAcl, <<"isEnable">> => true}),
dgiot_device:save_subdevice(BatchDeviceId, TaskDeviceId, 1),
{ok, {BatchProductId, BatchDeviceId, BatchAddr}};
_ ->
Expand All @@ -257,6 +257,7 @@ process_roll_dev(TaskProductId, TaskDeviceId, OrderName, SessionToken, FlatMap)
<<"devaddr">> => BatchAddr,
<<"name">> => OrderName,
<<"ACL">> => NewAcl,
<<"basedata">> => #{},
<<"product">> => #{
<<"__type">> => <<"Pointer">>,
<<"className">> => <<"Product">>,
Expand Down
7 changes: 4 additions & 3 deletions apps/dgiot_factory/src/dgiot_factory_material.erl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ get_material_record(DeviceId, Depart) ->
case dgiot_parse:get_object(<<"Device">>, DeviceId) of
{ok, #{<<"basedata">> := #{<<"material">> := Material}}} ->
DepartMaterial = get_depart_material(Material, Depart),

{ok, get_usable_material(DepartMaterial)};
_ ->
case dgiot_hook:run_hook({factory, get_material}, [DeviceId]) of
Expand Down Expand Up @@ -95,7 +94,8 @@ hanlde_pickandretrive(DeviceId, #{<<"FPrdOrgId">> := FPrdOrgId, <<"FStockId">> :
#{<<"material_pick">> := Pick, <<"material_retrive">> := Retrive, <<"material_picked">> := Picked} ->
case Type of
<<"picking">> ->
case dgiot_hook:run_hook({kingdee, post_material, <<"picking">>}, [DeviceId, FReplaceGroup, FPrdOrgId, FStockId, Weight, Weight]) of
case dgiot_hook:run_hook({kingdee, post_material, <<"picking">>},
[DeviceId, FReplaceGroup, FPrdOrgId, FStockId, Weight, Weight]) of
{ok, [{ok, _}]} ->
io:format("~s ~p Type = ~p ~n", [?FILE, ?LINE, Type]),
After = dgiot_utils:to_float(Picked) + dgiot_utils:to_float(Weight),
Expand All @@ -109,7 +109,8 @@ hanlde_pickandretrive(DeviceId, #{<<"FPrdOrgId">> := FPrdOrgId, <<"FStockId">> :

end;
<<"retriving">> ->
case dgiot_hook:run_hook({kingdee, post_material, <<"retriving">>}, [DeviceId, FReplaceGroup, FPrdOrgId, FStockId, Weight, Weight]) of
case dgiot_hook:run_hook({kingdee, post_material, <<"retriving">>},
[DeviceId, FReplaceGroup, FPrdOrgId, FStockId, Weight, Weight]) of
{ok, [{ok, _}]} ->
After = dgiot_utils:to_float(Picked) - dgiot_utils:to_float(Weight),
handle_warehouse(Id, Type, Num),
Expand Down
31 changes: 18 additions & 13 deletions apps/dgiot_factory/src/dgiot_factory_worker.erl
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

-export([put_worker_shift/1, get_work_shop_workers/2, get_new_workernum/1]).
-export([duplicate_shift/4]).
-export([record_worker_info/3]).
-export([record_worker_info/4]).

put_worker_shift(#{<<"product">> := ProductId, <<"ids">> := Ids, <<"shift">> := Shift} = Data) ->
WorkShop = maps:get(<<"workshop">>, Data, <<"">>),
Expand Down Expand Up @@ -327,17 +327,21 @@ put_relax(Items, ProductId) ->



record_worker_info(BatchDeviceId, #{<<"quality">> := #{<<"type">> := Type}} = Payload, ChannelId) ->
Quality = maps:get(<<"workshop">>, maps:get(<<"quality">>, Payload, #{}), <<"true">>),
TypeData = dgiot_data:get(?FACTORY_ORDER, Type),
record_worker_info(BatchProductId,BatchDeviceId, #{<<"quality">> := #{<<"type">> := Type}} = Payload, ChannelId) ->
Quality = maps:get(<<"quality">>, maps:get(<<"quality">>, Payload, #{}), <<"合格"/utf8>>),
TypeData = case dgiot_data:get(?FACTORY_ORDER, {BatchProductId, BatchDeviceId, Type}) of
not_find ->
#{};
R ->
R
end,
OrderId = maps:get(<<"ordername">>, maps:get(<<"person">>, TypeData, #{}), <<"null">>),
People = maps:get(<<"people">>, TypeData, <<"null">>),
_WorkShop = maps:get(<<"workshop">>, TypeData, <<"null">>),
Num = maps:get(<<"num">>, TypeData, 0),
Spec = maps:get(<<"spec">>, TypeData, <<"">>),
WorkeTime = maps:get(<<"worketime">>, TypeData, 0),
RollNum = maps:get(<<"rollnum">>, maps:get(<<"person">>, Payload, #{}), <<"null">>),
_Time = dgiot_datetime:nowstamp(),
People = maps:get(<<"people">>, maps:get(Type, TypeData, #{}), <<"null">>),
_WorkShop = maps:get(<<"workshop">>, maps:get(Type, TypeData, #{}), <<"null">>),
Num = maps:get(<<"num">>, maps:get(Type, TypeData, #{}), 0),
Spec = maps:get(<<"spec">>, maps:get(Type, TypeData, #{}), <<"">>),
WorkeTime = maps:get(<<"worketime">>, maps:get(Type, TypeData, #{}), 0),
RollNum = maps:get(<<"rollnum">>, maps:get(<<"person">>, TypeData, #{}), <<"null">>),
WorkerList = re:split(People, <<",">>),
lists:foldl(
fun(Worker, _) ->
Expand All @@ -350,7 +354,6 @@ record_worker_info(BatchDeviceId, #{<<"quality">> := #{<<"type">> := Type}} = Pa
#{};
N ->
lists:nth(1, N)

end,
ManufacData = #{
%% <<"manufac_type">> => dgiot_utils:to_binary(Type),
Expand All @@ -361,12 +364,14 @@ record_worker_info(BatchDeviceId, #{<<"quality">> := #{<<"type">> := Type}} = Pa
<<"manufac_worktime">> => WorkeTime,
<<"manufac_batchid">> => BatchDeviceId,
<<"manufac_rollnum">> => RollNum,
<<"manufac_type">> => dgiot_utils:to_binary(Type),
<<"base_source">> => <<"质检数据"/utf8>>
},
NumData = dgiot_product_enum:turn_num(maps:merge(WorkerData, ManufacData), ProductId),
dgiot_task:save_td(ProductId, Worker, NumData, #{})
end

end, [], WorkerList);
record_worker_info(_, _, _) ->
record_worker_info(_,_, _, _) ->
pass.

2 changes: 1 addition & 1 deletion apps/dgiot_tdengine/src/utils/dgiot_tdengine_field.erl
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ check_field(Data, #{<<"identifier">> := Field, <<"dataType">> := #{<<"type">> :=
Value;
_ when Type1 == <<"FLOAT">>; Type1 == <<"DOUBLE">> ->
Precision = maps:get(<<"precision">>, Specs, 3),
case size(Value) of
case size(dgiot_utils:to_binary(Value)) of
0 ->
0;
_ ->
Expand Down

0 comments on commit 9982a38

Please sign in to comment.