进出入完善组织机构并加入导入人员和机构功能
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
141
142
143
144
145
%%%-------------------------------------------------------------------
%%% @author ps
%%% @copyright (C) 2018, <COMPANY>
%%% @doc
%%%
%%% @end
%%% Created : 06. Dec 2018 上午12:34
%%%-------------------------------------------------------------------
-module(person_info_esql).
-author("ps").
 
%% API
-export([create_personInfo/2, add_personInfo/7, del_personInfo/2, upd_personInfo/7]).
-export([findAllpersonInfoNotFea/1]).
%%-export([findAllpersonInfo/1, personInfoFormat2Mat/1, findPersonInfo/2]).
-export([findPersonInfo/2]).
 
-include("esqltool.hrl").
 
 
create_personInfo(Nodes, TabName) ->
  StrTableName = syncTool:change2Str(TabName),
  io:format("TableName is ~p", [StrTableName]),
  Sql = ["CREATE TABLE '", StrTableName, "' (
                           uuid        varchar(255) PRIMARY KEY,
                           personName  varchar(255) DEFAULT NULL,
                           age         varchar(255) DEFAULT NULL,
                           sex         varchar(255) DEFAULT NULL,
                           idCard      varchar(255) DEFAULT NULL,
                           phoneNum    varchar(255) DEFAULT NULL,
                           create_time BLOB         DEFAULT (datetime('now', 'localtime')),
                           update_time DATETIME     DEFAULT NULL,
                           create_by   varchar(255) DEFAULT NULL,
                           del_flag    INTEGER      DEFAULT 0
                           );"],
  executeSqlLocalyAndSaveToCacheAndSendSql(Sql),
  {StrTableName, TabName}.
 
 
add_personInfo(TableName, Uuid, PersonName, Age, Sex, IdCard, PhoneNum) ->
  io:format("TableName ~p, ~n", [TableName]),
  CreateUser = node(),
  if
    Uuid == " " ->
      ID = syncTool:getUUIDString();
    Uuid == "" ->
      ID = syncTool:getUUIDString();
    true ->
      ID = Uuid
  end,
  UpdateTime = syncTool:getTimeStr(),
  CreateUser = node(),
  StrUuid = syncTool:change2Str(ID),
  StrTableName = syncTool:change2Str(TableName),
  StrPersonName = syncTool:change2Str(PersonName),
  StrAge = syncTool:change2Str(Age),
  StrSex = syncTool:change2Str(Sex),
  StrIdCard = syncTool:change2Str(IdCard),
  StrPhoneNum = syncTool:change2Str(PhoneNum),
  StrCreateUser = syncTool:change2Str(CreateUser),
 
  Sql = ["delete from '", StrTableName, "' where uuid ='", StrUuid, "';", "INSERT INTO '", StrTableName, "' (uuid, personName, age, sex, idCard, phoneNum,
       update_time, create_by) VALUES ('", StrUuid, "', '", StrPersonName, "', '", StrAge, "', '",
    StrSex, "', '", StrIdCard, "', '", StrPhoneNum, "', '", UpdateTime, "', '", StrCreateUser,
    "');"],
  Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql),
  io:format("add_personFea ~p~n", [Ret]),
  if
    Ret == {atomic, ok} ->
      Result = ID;
    true ->
      Result = ''
  end,
  Result.
 
del_personInfo(TableName, Uuid) ->
  UpdateTime = syncTool:getTimeStr(),
  StrUuid = syncTool:change2Str(Uuid),
  StrTableName = syncTool:change2Str(TableName),
  Sql = ["UPDATE '", StrTableName, "' SET del_flag = '1',
                          update_time = '", UpdateTime, "' where Uuid = '", StrUuid, "';"],
 
  Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql),
  io:format("del_personFea ~p~n", [Ret]),
  if
    Ret == {atomic, ok} ->
      Result = {atomic, ok};
    true ->
      Result = {}
  end,
  Result.
 
findAllpersonInfoNotFea(TableName) ->
  StrTableName = syncTool:change2Str(TableName),
  Sql = ["Select b.uuid as id,b.faceUrl as img,a.idCard as idcard
                     from '", StrTableName, "' as a,
                     '", StrTableName, "_fea' As b
                     where a.uuid = b.uuid and ( a.del_flag=0 AND b.del_flag=0);"],
  Maps = selectSomeInfoWithSql(Sql),
  if
    is_list(Maps) ->
      Res = Maps;
    is_tuple(Maps) ->
      Res = [];
    true ->
      Res = []
  end,
  Res.
 
findPersonInfo(TableName, PersonId) ->
  StrTableName = syncTool:change2Str(TableName),
  StrPersonId = syncTool:change2Str(PersonId),
  Sql = ["Select * from '", StrTableName, "'
                     where uuid = '", StrPersonId, "' AND del_flag=0;"],
  Maps = selectSomeInfoWithSql(Sql),
  if
    is_list(Maps) ->
      Res = Maps;
    is_tuple(Maps) ->
      Res = [];
    true ->
      Res = []
  end,
  Res.
 
upd_personInfo(TableName, Uuid, PersonName, Age, Sex, IdCard, PhoneNum) ->
  UpdateTime = syncTool:getTimeStr(),
  StrUuid = syncTool:change2Str(Uuid),
  StrTableName = syncTool:change2Str(TableName),
  StrPersonName = syncTool:change2Str(PersonName),
  StrAge = syncTool:change2Str(Age),
  StrSex = syncTool:change2Str(Sex),
  StrIdCard = syncTool:change2Str(IdCard),
  StrPhoneNum = syncTool:change2Str(PhoneNum),
 
  Sql = ["UPDATE '", StrTableName, "' SET idCard = '", StrIdCard, "',update_time = '",
    UpdateTime, "',del_flag = '0'  where Uuid = '", StrUuid, "';"],
  Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql),
  if
    Ret == {atomic, ok} ->
      Result = Uuid;
    true ->
      Result = ''
  end,
  Result.