进出入完善组织机构并加入导入人员和机构功能
554325746@qq.com
2019-08-07 07a66e53d2b4126c2004870d81a379d8ef0071da
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
%%%-------------------------------------------------------------------
%%% @author panse
%%% @copyright (C) 2018, <COMPANY>
%%% @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).