%%%-------------------------------------------------------------------
|
%%% @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.
|