进出入完善组织机构并加入导入人员和机构功能
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
-module(device_info_esql).
-compile(export_all).
-include("esqltool.hrl").
 
%%not use
create_deviceInfotable(Nodes, TableName) ->
  ok.
 
%%% 增加设备信息
%%%
%%% @DevId 设备uuid
%%% @DevName 设备名称
%%% @DevAdd 设备地址
%%% @NodeId 节点地址名称 name@ip
%%% @FNode 父节点地址
add_deviceInfo(UUid, DevId, NodeId, ClusterID, FatherNodeName) ->
  if
    UUid == " " ->
      ID = syncTool:getUUIDString();
    UUid == "" ->
      ID = syncTool:getUUIDString();
    true ->
      ID = UUid
  end,
  UpdateTime = syncTool:getTimeStr(),
  CreateUser = node(),
  StrUuid = syncTool:change2Str(ID),
  StrNodeId = syncTool:change2Str(NodeId),
  StrDevId = syncTool:change2Str(DevId),
  StrClusterID = syncTool:change2Str(ClusterID),
  StrCreateUser = syncTool:change2Str(CreateUser),
  StrFatherNodeName = syncTool:change2Str(FatherNodeName),
 
  Sql = ["INSERT OR REPLACE INTO device_info (father_node, uuid, node_id, device_id, cluster_id, update_time, create_by)
             VALUES ('" ++ StrFatherNodeName ++ "', '" ++ StrUuid ++ "', '" ++ StrNodeId ++ "', '" ++
              StrDevId ++ "', '" ++ StrClusterID ++ "', '" ++
                UpdateTime ++ "', '" ++ StrCreateUser ++ "');"],
  Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql),
  if
    Ret == {atomic, ok} ->
      Result = {atomic, ok};
    true ->
      Result = {aborted, error}
  end,
  Result.
 
del_deviceInfo(NodeId) ->
  StrNodeId = syncTool:change2Str(NodeId),
  Sql = ["delete from device_info where node_id = '", StrNodeId, "';"],
  Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql),
  if
    Ret == {atomic, ok} ->
      Result = {atomic, ok};
    true ->
      Result = {aborted, error}
  end,
  Result.
 
findDeviceOnlineList([]) -> [];
findDeviceOnlineList([OnlineNode | T]) ->
  StrNodeId = syncTool:change2Str(OnlineNode),
  io:format("StrNodeId size is ~p", [StrNodeId]),
  Sql = ["SELECT a.uuid,a.create_time,a.device_id,a.node_id,b.cluster_id,b.cluster_name
                                  FROM device_info as a, cluster_info as b where a.cluster_id = b.cluster_id
                                    AND a.node_id = '", StrNodeId, "';"],
  Maps = selectSomeInfoWithSql(Sql),
  if
    is_list(Maps) ->
      [Res | Tmp] = Maps;
    is_tuple(Maps) ->
      Res = [];
    true ->
      Res = []
  end,
  [Res | findDeviceOnlineList(T)].
 
findAllDeviceList() ->
  Sql = ["select node_id,uuid from device_info where del_flag = '0';"],
  selectSomeInfoWithSql(Sql).