%%%------------------------------------------------------------------- %%% @author panse %%% @copyright (C) 2018, %%% @doc %%% %%% @end %%% Created : 06. 八月 2018 9:57 %%%------------------------------------------------------------------- -module(syncTool). -author("panse"). -compile(export_all). %%% 类型转换 change2Str(Element) -> if is_list(Element) == true -> case Element of "" -> Res = " "; _ -> Res = Element end; true -> ResTmp = lists:flatten(io_lib:format("~w", [Element])), if is_atom(Element) == true -> Pos = string:str(ResTmp, "'"), if Pos == 1 -> Res = string:strip(ResTmp, both, $'); true -> Res = ResTmp end; true -> Res = ResTmp end end, Res. %%% 获取时间戳 getTimeStr() -> TS = {_, _, Micro} = os:timestamp(), {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_local_time(TS), lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w", [Year, Month, Day, Hour, Minute, Second])). getTimestamp() -> TS = {_, _, Micro} = os:timestamp(), {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_local_time(TS), lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w~2..0w~2..0w.~6..0w", [Year, Month, Day, Hour, Minute, Second, Micro])). getTimestamp1() -> TS = {_, _, Micro} = os:timestamp(), {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_local_time(TS), lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0wT~2..0w~2..0w~2..0w.~6..0w", [Year, Month, Day, Hour, Minute, Second, Micro])). getTimestampStr() -> TS = {_, _, Micro} = os:timestamp(), {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_local_time(TS), lists:flatten(io_lib:format("~4..0w-~2..0w-~2..0w ~2..0w:~2..0w:~2..0w.~6..0w", [Year, Month, Day, Hour, Minute, Second, Micro])). %%% 获取uuid,字符型 getUUIDStr() -> NodeName = lists:flatten(io_lib:format("~w", [node()])), list_to_atom(uuid:to_string(uuid:uuid5(uuid:uuid4(), NodeName))). getUUIDString() -> NodeName = lists:flatten(io_lib:format("~w", [node()])), uuid:to_string(uuid:uuid5(uuid:uuid4(), NodeName)). getPersonIdStr() -> Batch = change2Str(persconfg:lookup(batch)), SerialNumber = change2Str(persconfg:lookup(serialNumber)), TS = {_, _, Micro} = os:timestamp(), {{Year, Month, Day}, {Hour, Minute, Second}} = calendar:now_to_local_time(TS), lists:flatten(io_lib:format("PSVAD~2..0w~2..0w~4..0w~2..0w~2..0w ~2..0w:~2..0w:~2..0w.~3..0w", [Batch, SerialNumber, Year, Month, Day, Hour, Minute, Second, Micro])). %%% 无限循环 forLoop(N) -> %code% io:format("forLoop ~n"), timer:sleep(N), forLoop(N). %%% ping %%% 即可做连接使用,又可做判断设备是否在线使用 pingOnce(Node) -> Rtn = net_adm:ping(Node), case Rtn of pong -> Ping = true; pang -> Ping = false end, Ping. %%% 创建表后制动修改同步 changeTableConfig([], _Table) -> null; changeTableConfig(_RunningNodeList = [Node | T], Table) -> io:format("change_table_copy_type Node = ~p, connection=~p~n", [Node, net_adm:ping(Node)]), Rtn = mnesia:change_table_copy_type(Table, Node, disc_copies), io:format("Node = ~p, change_table_copy_type = ~p~n", [Node, Rtn]), changeTableConfig(T, Table). sendMessToCNode(Message) -> io:format("sendMessToCNode ~p ", [Message]), CallID = mochiglobal:get('cNodeName'), {call, FuncName, Args} = Message, case CallID of undefined -> io:format("connect server fail!"); _ -> case net_kernel:connect(CallID) of true -> {any, CallID} ! {call, self(), {FuncName, Args}}, io:format("send ok call log ~p,~p,~p", [CallID, FuncName, Args]); _ -> io:format("connect server fail!") end end. rpcSendMessToCNode([], Message) -> null; rpcSendMessToCNode(_RunningNodeList = [Node | T], Message) -> Res = rpc:cast(Node, syncTool, sendMessToCNode, [Message]), io:format("rpcSendMessToCNode ~p ", [Res]), rpcSendMessToCNode(T, Message).