mirror of
https://gitee.com/dgiiot/dgiot.git
synced 2024-12-03 12:48:30 +08:00
add:product_enum
This commit is contained in:
parent
e373db46fc
commit
509c59611a
@ -26,7 +26,7 @@
|
||||
-export([get_prop/1, get_props/1, get_props/2, get_unit/1, do_td_message/1, update_properties/2, update_properties/0]).
|
||||
-export([update_topics/0, update_product_filed/1]).
|
||||
-export([get_initdata/2, init_inspection/1, get_inspection/1]).
|
||||
-export([save_devicetype/1, get_devicetype/1,get_device_thing/2]).
|
||||
-export([save_devicetype/1, get_devicetype/1, get_device_thing/2]).
|
||||
-export([save_keys/1, get_keys/1, get_control/1, save_control/1, save_channel/1, save_tdchannel/1,
|
||||
save_taskchannel/1, get_channel/1, get_tdchannel/1,
|
||||
get_taskchannel/1, get_interval/1]).
|
||||
@ -83,6 +83,7 @@ save(Product) ->
|
||||
save_tdchannel(ProductId),
|
||||
save_taskchannel(ProductId),
|
||||
save_device_thingtype(ProductId),
|
||||
dgiot_product_enum:save_product_enum(ProductId),
|
||||
{ok, Product1}.
|
||||
|
||||
put(Product) ->
|
||||
@ -209,16 +210,15 @@ get_devicetype(ProductId) ->
|
||||
save_device_thingtype(ProductId) ->
|
||||
case dgiot_product:lookup_prod(ProductId) of
|
||||
{ok, #{<<"thing">> := #{<<"properties">> := Props}}} ->
|
||||
lists:map(fun(#{<<"devicetype">> := DeviceType, <<"identifier">> := Identifier, <<"dataType">> := #{<<"type">> := Type}}) ->
|
||||
|
||||
case dgiot_data:get(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType}) of
|
||||
not_find ->
|
||||
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType}, #{Identifier => Type});
|
||||
Map ->
|
||||
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType}, Map#{Identifier => Type})
|
||||
end
|
||||
|
||||
end, Props);
|
||||
lists:map(
|
||||
fun(#{<<"devicetype">> := DeviceType, <<"identifier">> := Identifier, <<"dataType">> := #{<<"type">> := Type}}) ->
|
||||
case dgiot_data:get(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType}) of
|
||||
not_find ->
|
||||
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, Identifier}, #{Identifier => Type});
|
||||
Map ->
|
||||
dgiot_data:insert(?DGIOT_PRODUCT, {ProductId, device_thing, DeviceType}, Map#{Identifier => Type})
|
||||
end
|
||||
end, Props);
|
||||
|
||||
_Error ->
|
||||
[]
|
||||
|
203
apps/dgiot_device/src/utils/dgiot_product_enum.erl
Normal file
203
apps/dgiot_device/src/utils/dgiot_product_enum.erl
Normal file
@ -0,0 +1,203 @@
|
||||
%%--------------------------------------------------------------------
|
||||
%% Copyright (c) 2020-2021 DGIOT Technologies Co., Ltd. All Rights Reserved.
|
||||
%%
|
||||
%% Licensed under the Apache License, Version 2.0 (the "License");
|
||||
%% you may not use this file except in compliance with the License.
|
||||
%% You may obtain a copy of the License at
|
||||
%%
|
||||
%% http://www.apache.org/licenses/LICENSE-2.0
|
||||
%%
|
||||
%% Unless required by applicable law or agreed to in writing, software
|
||||
%% distributed under the License is distributed on an "AS IS" BASIS,
|
||||
%% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
%% See the License for the specific language governing permissions and
|
||||
%% limitations under the License.
|
||||
%%--------------------------------------------------------------------
|
||||
|
||||
-module(dgiot_product_enum).
|
||||
-author("jonliu").
|
||||
-include("dgiot_device.hrl").
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
-include_lib("dgiot_bridge/include/dgiot_bridge.hrl").
|
||||
-dgiot_data("ets").
|
||||
-export([init_ets/0, save_product_enum/1, get_enmu_key/3, get_enmu_value/3, post_enum_value/3]).
|
||||
-export([turn_name/2, turn_num/2, get_ThingMap/1]).
|
||||
|
||||
|
||||
init_ets() ->
|
||||
dgiot_data:init(?MODULE).
|
||||
|
||||
|
||||
%% 设备类型
|
||||
save_product_enum(ProductId) ->
|
||||
case dgiot_product:lookup_prod(ProductId) of
|
||||
{ok, #{<<"thing">> := #{<<"properties">> := Props}}} ->
|
||||
lists:map(
|
||||
fun
|
||||
(#{<<"devicetype">> := DeviceType, <<"identifier">> := Identifier,
|
||||
<<"dataType">> := #{<<"type">> := <<"enum">>, <<"specs">> := Spec}}) ->
|
||||
case dgiot_data:get(?MODULE, {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},
|
||||
#{Identifier => <<"enum">>});
|
||||
Map ->
|
||||
dgiot_data:insert(?MODULE, {ProductId, device_thing, Identifier},
|
||||
#{Identifier => <<"enum">>, <<"specs">> => Spec}),
|
||||
dgiot_data:insert(?MODULE, {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
|
||||
not_find ->
|
||||
dgiot_data:insert(?MODULE, {ProductId, device_thing, Identifier}, #{Identifier => Type});
|
||||
Map ->
|
||||
dgiot_data:insert(?MODULE, {ProductId, device_thing, DeviceType}, Map#{Identifier => Type})
|
||||
end
|
||||
|
||||
|
||||
end, Props);
|
||||
|
||||
_Error ->
|
||||
[]
|
||||
end.
|
||||
%%#{<<"1">> => <<"name">>}
|
||||
get_enmu_key(ProductId, Identifier, Value) ->
|
||||
case dgiot_data:get(?MODULE, {ProductId, device_thing, Identifier}) of
|
||||
#{Identifier := <<"enum">>, <<"specs">> := Spec} ->
|
||||
maps:fold(fun(K, V, Acc) ->
|
||||
case V of
|
||||
Value ->
|
||||
Acc#{Value => K};
|
||||
_ ->
|
||||
Acc
|
||||
end
|
||||
end, #{}, Spec);
|
||||
_ ->
|
||||
#{}
|
||||
end.
|
||||
get_enmu_value(ProductId, Identifier, Key) ->
|
||||
case dgiot_data:get(?MODULE, {ProductId, device_thing, Identifier}) of
|
||||
#{Identifier := <<"enum">>, <<"specs">> := #{Key := V}} ->
|
||||
#{Key => V};
|
||||
_ ->
|
||||
#{}
|
||||
end.
|
||||
|
||||
post_enum_value(ProductId, Identifier, Name) ->
|
||||
case dgiot_data:get(?MODULE, {ProductId, device_thing, Identifier}) of
|
||||
#{Identifier := <<"enum">>, <<"specs">> := Spec} ->
|
||||
Max = maps:fold(
|
||||
fun(K, _, Acc) ->
|
||||
case dgiot_utils:to_int(K) > Acc of
|
||||
true ->
|
||||
dgiot_utils:to_int(K);
|
||||
_ ->
|
||||
Acc
|
||||
end
|
||||
end, 0, Spec),
|
||||
|
||||
upadte_thing(ProductId, Identifier, Name, Max);
|
||||
_ ->
|
||||
upadte_thing(ProductId, Identifier, Name, #{<<"0">> => Name})
|
||||
end.
|
||||
upadte_thing(ProductId, Identifier, Name, Max) ->
|
||||
case dgiot_parse:get_object(<<"Product">>, ProductId) of
|
||||
{ok, #{<<"thing">> := #{<<"properties">> := Properties} = Thing}} ->
|
||||
NewProperties = lists:foldl(
|
||||
fun(X, Acc) ->
|
||||
case X of
|
||||
#{<<"identifier">> := Identifier, <<"dataType">> := #{<<"type">> := <<"enum">>, <<"specs">> := Spec} = DataType} ->
|
||||
NewSpec = maps:merge(Spec, #{dgiot_utils:to_binary(Max + 1) => Name}),
|
||||
Acc ++ [X#{<<"dataType">> => DataType#{<<"specs">> => NewSpec}}];
|
||||
_ ->
|
||||
Acc ++ [X]
|
||||
end
|
||||
end, [], Properties),
|
||||
NewThing = Thing#{<<"properties">> => NewProperties},
|
||||
dgiot_parse:update_object(<<"Product">>, ProductId, #{<<"thing">> => NewThing});
|
||||
_ ->
|
||||
pass
|
||||
end.
|
||||
|
||||
|
||||
|
||||
turn_name(List, ProductId) when is_list(List) ->
|
||||
lists:foldl(
|
||||
fun(X, Acc) ->
|
||||
Acc ++ [turn_name(X, ProductId)]
|
||||
end, [], List);
|
||||
|
||||
turn_name(FlatMap, ProductId) when is_map(FlatMap) ->
|
||||
case get_ThingMap(ProductId) of
|
||||
{ok, ThingMap} ->
|
||||
maps:fold(
|
||||
fun(K, V, Acc) ->
|
||||
case V of
|
||||
<<"enum">> ->
|
||||
case maps:find(K, Acc) of
|
||||
{ok, Data} ->
|
||||
case get_enmu_value(ProductId, K, Data) of
|
||||
#{K := Value} ->
|
||||
Acc#{K => Value};
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end
|
||||
|
||||
end, FlatMap, ThingMap);
|
||||
_ ->
|
||||
FlatMap
|
||||
end;
|
||||
|
||||
turn_name(Data, _) ->
|
||||
Data.
|
||||
|
||||
turn_num(FlatMap, ProductId) ->
|
||||
case get_ThingMap(ProductId) of
|
||||
{ok, ThingMap} ->
|
||||
maps:fold(
|
||||
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} ->
|
||||
Acc#{K => Value};
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end
|
||||
|
||||
end, FlatMap, ThingMap);
|
||||
_ ->
|
||||
FlatMap
|
||||
end.
|
||||
get_ThingMap(ProductId) ->
|
||||
case dgiot_product:get_devicetype(ProductId) of
|
||||
not_find ->
|
||||
error;
|
||||
List ->
|
||||
Res = lists:foldl(
|
||||
fun(DeviceType, Acc) ->
|
||||
case dgiot_product:get_device_thing(ProductId, DeviceType) of
|
||||
not_find ->
|
||||
Acc;
|
||||
Res ->
|
||||
maps:merge(Acc, Res)
|
||||
end
|
||||
end, #{}, List),
|
||||
{ok, Res}
|
||||
end.
|
@ -31,7 +31,7 @@
|
||||
|
||||
%% Channel callback
|
||||
-export([init/3, handle_init/1, handle_event/3, handle_message/2, stop/3]).
|
||||
-export([get_id/2, after_handle/4, handle_data/7, get_card_data/2]).
|
||||
-export([get_id/2, after_handle/4, handle_data/8, get_card_data/2]).
|
||||
-export([get_sub_product/1, get_new_acl/2, init_worker_device/3]).
|
||||
|
||||
%% 注册通道类型
|
||||
@ -120,7 +120,9 @@ handle_message({sync_parse, _Pid, 'after', put, _Token, <<"_User">>, #{<<"object
|
||||
end
|
||||
end,
|
||||
{ok, State};
|
||||
handle_message({sync_parse, _Pid, 'before', put, Token, <<"Device">>, #{<<"content">> := Content, <<"id">> := TaskDeviceId} = _QueryData}, State) ->
|
||||
handle_message({sync_parse, _Pid, 'before', put, Token, <<"Device">>,
|
||||
#{<<"content">> := Content, <<"id">> := TaskDeviceId} = _QueryData},
|
||||
#state{id = ChannelId} = State) ->
|
||||
io:format("~s ~p TaskDeviceId =~p ~n", [?FILE, ?LINE, TaskDeviceId]),
|
||||
case dgiot_device_cache:lookup(TaskDeviceId) of
|
||||
{ok, #{<<"productid">> := TaskProductId}} ->
|
||||
@ -128,7 +130,7 @@ handle_message({sync_parse, _Pid, 'before', put, Token, <<"Device">>, #{<<"conte
|
||||
#{<<"person">> := #{<<"type">> := PersonType}} ->
|
||||
case process_data(Content, PersonType, Token, TaskDeviceId) of
|
||||
{BatchProductId, BatchDeviceId, BatchAddr, NewData} ->
|
||||
handle_data(TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAddr, PersonType, NewData),
|
||||
handle_data(TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAddr, PersonType, NewData,ChannelId),
|
||||
{ok, State};
|
||||
_ ->
|
||||
{ok, State}
|
||||
@ -164,8 +166,8 @@ stop(ChannelType, ChannelId, _State) ->
|
||||
%% save_data(ProductId, Id, DevAddr, DeviceId, PersonType, Payload).
|
||||
|
||||
|
||||
handle_data(_TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, BatchAddr, PersonType, NewData) ->
|
||||
NewPayLoad = run_factory_hook(_TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, PersonType, NewData),
|
||||
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),
|
||||
@ -218,8 +220,8 @@ turn_user(#{<<"person_sessiontoken">> := SessionToken}) ->
|
||||
SessionToken
|
||||
end.
|
||||
|
||||
run_factory_hook(TaskProductId, TaskDeviceId, BatchProductId, BatchDeviceId, PersonType, NewData) ->
|
||||
case dgiot_hook:run_hook({factory, TaskProductId, PersonType}, [BatchProductId, TaskDeviceId, BatchDeviceId, PersonType, NewData]) 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;
|
||||
_ ->
|
||||
@ -318,7 +320,7 @@ save2parse(BatchProductId, BatchDeviceId, ALlData) ->
|
||||
|
||||
save2td(BatchProductId, BatchAddr, Data) ->
|
||||
FlatternData = dgiot_map:flatten(Data),
|
||||
NumData = dgiot_factory_utils:turn_num(FlatternData, BatchProductId),
|
||||
NumData = dgiot_product_enum:turn_num(FlatternData, BatchProductId),
|
||||
dgiot_task:save_td(BatchProductId, BatchAddr, NumData, #{}).
|
||||
|
||||
|
||||
@ -346,7 +348,7 @@ init_worker_device(ProductId, WorkerNum, WorkerName) ->
|
||||
<<"worker_date">> => 0,
|
||||
<<"worker_name">> => WorkerName,
|
||||
<<"product">> => ProductId},
|
||||
NumData = dgiot_factory_utils:turn_num(AllData, ProductId),
|
||||
NumData = dgiot_product_enum:turn_num(AllData, ProductId),
|
||||
dgiot_task:save_td_no_match(ProductId, WorkerNum, NumData, #{});
|
||||
_ ->
|
||||
pass
|
||||
|
@ -54,7 +54,7 @@
|
||||
%% ThingMap ->
|
||||
%% case get_history(Channel, ProductId, DeviceId, ThingMap, Type) of
|
||||
%% {ok, #{<<"results">> := HistoryData}} ->
|
||||
%% NamedData = dgiot_factory_utils:turn_name(HistoryData, ThingMap),
|
||||
%% NamedData = dgiot_product_enum:turn_name(HistoryData, ThingMap),
|
||||
%%%% {Total, Res} = filter_data(Limit, Skip, NamedData),
|
||||
%% {ok, {Total, filter_data(Res)}};
|
||||
%%
|
||||
@ -72,7 +72,7 @@
|
||||
%% ThingMap ->
|
||||
%% case get_history(Channel, ProductId, DeviceId, ThingMap, Where, Start, End, Type, New) of
|
||||
%% {ok, #{<<"results">> := HistoryData}} ->
|
||||
%% NamedData = dgiot_factory_utils:turn_name(HistoryData, ThingMap),
|
||||
%% NamedData = dgiot_product_enum:turn_name(HistoryData, ThingMap),
|
||||
%% {Total, Res} = filter_data(Limit, Skip, NamedData),
|
||||
%% {ok, {Total, filter_data(Res)}};
|
||||
%%
|
||||
@ -88,7 +88,7 @@
|
||||
%% ThingMap ->
|
||||
%% case get_history(Channel, ProductId, DeviceId, ThingMap, Where, Start, End, Type, New) of
|
||||
%% {ok, #{<<"results">> := HistoryData}} ->
|
||||
%% NamedData = dgiot_factory_utils:turn_name(HistoryData, ThingMap),
|
||||
%% NamedData = dgiot_product_enum:turn_name(HistoryData, ThingMap),
|
||||
%% {Total, Res} = filter_data(Limit, Skip, NamedData),
|
||||
%% {ok, {Total, filter_data(Res)}};
|
||||
%%
|
||||
@ -551,9 +551,9 @@ filter_data(Data) when is_map(Data) ->
|
||||
%%filter_where(Where, ProductId, Type) ->
|
||||
%% MapWhere = case is_map(Where) of
|
||||
%% true ->
|
||||
%% dgiot_factory_utils:turn_num(Where, ProductId, Type);
|
||||
%% dgiot_product_enum:turn_num(Where, ProductId, Type);
|
||||
%% _ ->
|
||||
%% dgiot_factory_utils:turn_num(jsx:decode(Where), ProductId, Type)
|
||||
%% dgiot_product_enum:turn_num(jsx:decode(Where), ProductId, Type)
|
||||
%% end,
|
||||
%% case get_ThingMap(Type, ProductId) of
|
||||
%% {ok, ThingMap} ->
|
||||
@ -606,7 +606,7 @@ get_history_data(ProductId, DeviceId, Type, Function, FunctionMap, Group, Having
|
||||
end)
|
||||
of
|
||||
{ok, #{<<"results">> := HistoryData}} ->
|
||||
NamedData = dgiot_factory_utils:turn_name(HistoryData, ProductId),
|
||||
NamedData = dgiot_product_enum:turn_name(HistoryData, ProductId),
|
||||
{Total, FileredRes} = filter_data(Limit, Skip, NamedData),
|
||||
Data = case dgiot_hook:run_hook({factory, ProductId, afterTd}, [FileredRes]) of
|
||||
{ok, [{ok, AfteRes}]} ->
|
||||
|
@ -18,8 +18,7 @@
|
||||
-author("jonhl").
|
||||
-include_lib("dgiot/include/logger.hrl").
|
||||
-include("dgiot_factory.hrl").
|
||||
-export([get_num/2, get_name/2, turn_name/2, turn_num/2]).
|
||||
-export([get_usertree/2, getalluser/1, get_ThingMap/1,clear_cache/2]).
|
||||
-export([get_usertree/2, getalluser/1, clear_cache/2]).
|
||||
-export([get_zero_list/1, get_zero_binary/1]).
|
||||
-export([fix_model/1, get_worker/1, get_children/1, check_workteam/1]).
|
||||
|
||||
@ -42,116 +41,6 @@ fix_model(ID) ->
|
||||
|
||||
|
||||
|
||||
get_num(K, V) ->
|
||||
Id = dgiot_parse_id:get_dictid(K, K, K, K),
|
||||
case dgiot_parse:get_object(<<"Dict">>, Id) of
|
||||
{ok, #{<<"data">> := #{<<"end">> := End} = Dict}} ->
|
||||
case maps:find(V, Dict) of
|
||||
{ok, Num} ->
|
||||
#{K => Num};
|
||||
_ ->
|
||||
case dgiot_parse:update_object(<<"Dict">>, Id, #{<<"data">> => Dict#{<<"end">> => End + 1, V => End}}) of
|
||||
{ok, _} ->
|
||||
#{K => End};
|
||||
_ ->
|
||||
error
|
||||
end
|
||||
end;
|
||||
_ ->
|
||||
Map = #{<<"class">> => K,
|
||||
<<"title">> => K,
|
||||
<<"type">> => K,
|
||||
<<"key">> => K,
|
||||
<<"objectId">> => Id,
|
||||
<<"data">> => #{<<"end">> => 1, V => 0}
|
||||
},
|
||||
case dgiot_parse:create_object(<<"Dict">>, Map) of
|
||||
{ok, _} ->
|
||||
#{K => 0};
|
||||
_ ->
|
||||
error
|
||||
end
|
||||
end.
|
||||
|
||||
get_name(K, Num) ->
|
||||
Id = dgiot_parse_id:get_dictid(K, K, K, K),
|
||||
case dgiot_parse:get_object(<<"Dict">>, Id) of
|
||||
{ok, #{<<"data">> := Dict}} ->
|
||||
TupleList = maps:to_list(Dict),
|
||||
case lists:keytake(Num, 2, TupleList) of
|
||||
{value, {Name, _}, _} ->
|
||||
#{K => Name};
|
||||
_ ->
|
||||
error
|
||||
end;
|
||||
_ ->
|
||||
error
|
||||
end.
|
||||
|
||||
turn_name(List, ProductId) when is_list(List) ->
|
||||
lists:foldl(
|
||||
fun(X, Acc) ->
|
||||
Acc ++ [turn_name(X, ProductId)]
|
||||
end, [], List);
|
||||
|
||||
turn_name(FlatMap, ProductId) when is_map(FlatMap) ->
|
||||
case get_ThingMap( ProductId) of
|
||||
{ok, ThingMap} ->
|
||||
maps:fold(
|
||||
fun(K, V, Acc) ->
|
||||
case V of
|
||||
<<"enum">> ->
|
||||
case maps:find(K, Acc) of
|
||||
{ok, Data} ->
|
||||
case dgiot_factory_utils:get_name(K, Data) of
|
||||
error ->
|
||||
Acc;
|
||||
Map ->
|
||||
maps:merge(Acc, Map)
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end
|
||||
|
||||
end, FlatMap, ThingMap);
|
||||
_ ->
|
||||
FlatMap
|
||||
end;
|
||||
|
||||
turn_name(Data, _) ->
|
||||
Data.
|
||||
|
||||
turn_num(FlatMap, ProductId) ->
|
||||
case get_ThingMap( ProductId) of
|
||||
{ok, ThingMap} ->
|
||||
maps:fold(
|
||||
fun(K, V, Acc) ->
|
||||
case V of
|
||||
<<"enum">> ->
|
||||
case maps:find(K, Acc) of
|
||||
{ok, Data} ->
|
||||
case dgiot_factory_utils:get_num(K, Data) of
|
||||
error ->
|
||||
Acc;
|
||||
Map ->
|
||||
maps:merge(Acc, Map)
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end;
|
||||
_ ->
|
||||
Acc
|
||||
end
|
||||
|
||||
end, FlatMap, ThingMap);
|
||||
_ ->
|
||||
FlatMap
|
||||
end.
|
||||
|
||||
|
||||
get_usertree(#{<<"id">> := undefined}, SessionToken) ->
|
||||
case get_same_level_role(SessionToken) of
|
||||
RoleTree when length(RoleTree) > 0 ->
|
||||
@ -267,22 +156,7 @@ get_zero_binary(Acc, Num) ->
|
||||
|
||||
|
||||
|
||||
get_ThingMap( ProductId) ->
|
||||
case dgiot_product:get_devicetype(ProductId) of
|
||||
not_find ->
|
||||
error;
|
||||
List ->
|
||||
Res = lists:foldl(
|
||||
fun(DeviceType, Acc) ->
|
||||
case dgiot_product:get_device_thing(ProductId, DeviceType) of
|
||||
not_find ->
|
||||
Acc;
|
||||
Res ->
|
||||
maps:merge(Acc, Res)
|
||||
end
|
||||
end, #{}, List),
|
||||
{ok, Res}
|
||||
end.
|
||||
|
||||
|
||||
%%dgiot_data:insert(?WORKER, Id, {UserName, Nick,1}),
|
||||
update_worker_ets(Id, UserName, Nick, Depname) ->
|
||||
@ -297,24 +171,24 @@ record_workteam(List) ->
|
||||
WorkTeamMember = lists:foldl(
|
||||
fun(X, Acc) ->
|
||||
Team = lists:nth(1, maps:keys(X)),
|
||||
OldList = maps:get(Team,Acc,[]),
|
||||
OldList = maps:get(Team, Acc, []),
|
||||
WorkerList = lists:flatten(maps:get(Team, X, [])),
|
||||
lists:foldl(
|
||||
fun(Worker, Acc1) ->
|
||||
case dgiot_data:get(?WORKER, Worker) of
|
||||
not_find ->
|
||||
Acc1 ++[Worker];
|
||||
Acc1 ++ [Worker];
|
||||
{Id, _, Name, State} ->
|
||||
dgiot_data:insert(?WORKER, Worker, {Id, Team, Name, State}),
|
||||
Acc1 ++[Worker];
|
||||
Acc1 ++ [Worker];
|
||||
_ ->
|
||||
Acc1 ++[Worker]
|
||||
Acc1 ++ [Worker]
|
||||
|
||||
end
|
||||
end, [], WorkerList),
|
||||
maps:merge(Acc,#{Team => OldList ++ WorkerList})
|
||||
maps:merge(Acc, #{Team => OldList ++ WorkerList})
|
||||
end, #{}, List),
|
||||
dgiot_data:insert(?WORKER, workteam,WorkTeamMember).
|
||||
dgiot_data:insert(?WORKER, workteam, WorkTeamMember).
|
||||
|
||||
check_workteam(Worker) ->
|
||||
WorkerList = lists:delete(<<>>, re:split(Worker, <<" ">>)),
|
||||
@ -358,7 +232,7 @@ format_tree(Tree) ->
|
||||
case Team of
|
||||
#{<<"name">> := Value, <<"children">> := Child} ->
|
||||
{AllChild, ChildList} = get_all_worker(Child),
|
||||
{NewTree ++ [#{<<"label">> => Value,<<"value">> => Value,<<"children">> => AllChild}], List ++ [#{Value => ChildList}]};
|
||||
{NewTree ++ [#{<<"label">> => Value, <<"value">> => Value, <<"children">> => AllChild}], List ++ [#{Value => ChildList}]};
|
||||
#{<<"name">> := Lable, <<"value">> := Value} ->
|
||||
{NewTree ++ [#{<<"label">> => Lable, <<"value">> => Value}], List ++ [Value]};
|
||||
_ ->
|
||||
|
@ -26,10 +26,11 @@
|
||||
|
||||
-export([put_worker_shift/1, get_work_shop_workers/2, get_new_workernum/1]).
|
||||
-export([duplicate_shift/4]).
|
||||
-export([record_worker_info/3]).
|
||||
|
||||
put_worker_shift(#{<<"product">> := ProductId, <<"ids">> := Ids, <<"shift">> := Shift } = Data) ->
|
||||
WorkShop = maps:get(<<"workshop">> ,Data,<<"">>),
|
||||
WorkTeam = maps:get(<<"workteam">>,Data,<<"">>),
|
||||
put_worker_shift(#{<<"product">> := ProductId, <<"ids">> := Ids, <<"shift">> := Shift} = Data) ->
|
||||
WorkShop = maps:get(<<"workshop">>, Data, <<"">>),
|
||||
WorkTeam = maps:get(<<"workteam">>, Data, <<"">>),
|
||||
Validate = maps:get(<<"worker_validate">>, Data, true),
|
||||
_Leader = maps:get(<<"leader">>, Data, <<"">>),
|
||||
WorkerList = re:split(Ids, <<",">>),
|
||||
@ -76,7 +77,7 @@ put_worker_shift(_) ->
|
||||
|
||||
put_one_shift(AllData, ProductId, Worker) ->
|
||||
BinWorker = dgiot_utils:to_binary(Worker),
|
||||
NumTd = dgiot_factory_utils:turn_num(AllData, ProductId),
|
||||
NumTd = dgiot_product_enum:turn_num(AllData, ProductId),
|
||||
dgiot_task:save_td_no_match(ProductId, BinWorker, NumTd, #{}),
|
||||
case dgiot_data:get(?WORKER, BinWorker) of
|
||||
not_find ->
|
||||
@ -219,7 +220,7 @@ get_new_shift(Now, ShiftList) ->
|
||||
%% NewData = duplicate_shift(First),
|
||||
%% Worker = maps:get(<<"worker_name">>, First, <<"null">>),
|
||||
%% ProductId = maps:get(<<"product">>, First, <<"null">>),
|
||||
%% NumTd = dgiot_factory_utils:turn_num(NewData, ProductId),
|
||||
%% NumTd = dgiot_product_enum:turn_num(NewData, ProductId),
|
||||
%% dgiot_task:save_td(ProductId, Worker, NumTd, #{}),
|
||||
%% dgiot_data:insert(?WORKER, Worker, [NewData]);
|
||||
%% _ ->
|
||||
@ -266,11 +267,14 @@ check_shift(Data, List) ->
|
||||
Day = maps:get(<<"worker_date">>, Data, 0),
|
||||
Res = lists:foldl(
|
||||
fun(#{<<"worker_date">> := OldDay} = X, Acc) ->
|
||||
io:format("~s ~p OldDay: ~p~n", [?FILE, ?LINE, OldDay]),
|
||||
io:format("~s ~p Day: ~p~n", [?FILE, ?LINE, Day]),
|
||||
case Day == OldDay of
|
||||
true ->
|
||||
io:format("~s ~p here~n", [?FILE, ?LINE]),
|
||||
Acc;
|
||||
_ ->
|
||||
io:format("~s ~p here~n", [?FILE, ?LINE]),
|
||||
Acc ++ [X]
|
||||
end;
|
||||
(_, Acc) ->
|
||||
@ -318,3 +322,51 @@ put_relax(Items, ProductId) ->
|
||||
(_, _) ->
|
||||
pass
|
||||
end, [], Items).
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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),
|
||||
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(),
|
||||
WorkerList = re:split(People, <<",">>),
|
||||
lists:foldl(
|
||||
fun(Worker, _) ->
|
||||
case dgiot_data:get({ChannelId, worker}) of
|
||||
not_find ->
|
||||
pass;
|
||||
ProductId ->
|
||||
WorkerData = case dgiot_data:get(?WORKER, Worker) of
|
||||
not_find ->
|
||||
#{};
|
||||
N ->
|
||||
lists:nth(1, N)
|
||||
|
||||
end,
|
||||
ManufacData = #{
|
||||
%% <<"manufac_type">> => dgiot_utils:to_binary(Type),
|
||||
<<"manufac_quality">> => Quality,
|
||||
<<"manufac_orderid">> => OrderId,
|
||||
<<"manufac_spec">> => Spec,
|
||||
<<"manufac_num">> => Num,
|
||||
<<"manufac_worktime">> => WorkeTime,
|
||||
<<"manufac_batchid">> => BatchDeviceId,
|
||||
<<"manufac_rollnum">> => RollNum,
|
||||
<<"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(_, _, _) ->
|
||||
pass.
|
||||
|
Loading…
Reference in New Issue
Block a user