%%%------------------------------------------------------------------- %%% @author bsk %%% @copyright (C) 2018, %%% @doc %%% %%% @end %%% Created : 05. 十二月 2018 下午3:34 %%%------------------------------------------------------------------- -module(person_info_feature_esql). -author("bsk"). %% API -export([create_personFeature/2, add_personFea/5, upd_personFea/4, del_personFea/2, findPersonFea/2]). -export([loadFaceFeaData/1]). %%-export([findAllPersonFea/1, personFeaFormat2Mat/1, personNoFeaFormat2Mat/1, findPersonFea/2]). -include("esqltool.hrl"). create_personFeature(Nodes, TableName) -> %% 实际的表名 ID = syncTool:getUUIDString(), StrUuid = syncTool:change2Str(ID), Sql = ["CREATE TABLE 'main'.'", StrUuid, "_fea'( uuid varchar(255) PRIMARY KEY, feature BLOB NOT NULL, faceUrl BLOB NOT NULL, create_time BLOB default (datetime('now', 'localtime')), update_time varchar(255) DEFAULT NULL, create_by varchar(255) DEFAULT NULL, del_flag INTEGER DEFAULT 0 );"], executeSqlLocalyAndSaveToCacheAndSendSql(Sql), {ID, TableName}. add_personFea(Uuid, TableName, Feature, Img, Idcard) -> io:format("TableName ~p, Feature ~p ~n", [TableName, Feature]), CreateUser = node(), if Uuid == " " -> ID = syncTool:getUUIDString(); Uuid == "" -> ID = syncTool:getUUIDString(); true -> ID = Uuid end, UpdateTime = syncTool:getTimeStr(), CreateUser = node(), StrUuid = syncTool:change2Str(ID), StrFeature = syncTool:change2Str(Feature), StrTableName = syncTool:change2Str(TableName), StrImg = syncTool:change2Str(Img), StrCreateUser = syncTool:change2Str(CreateUser), Sql = ["delete from '", StrTableName, "_fea' where uuid ='", StrUuid, "';", "INSERT INTO '", StrTableName, "_fea' (uuid, feature, faceUrl, update_time, create_by) VALUES ('", StrUuid, "', '", StrFeature, "', '", StrImg, "', '", UpdateTime, "', '", StrCreateUser, "' );"], Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql), if Ret == {atomic, ok} -> Result = ID; true -> Result = '' end, Result. findPersonFea(TableName, Uuid) -> StrTableName = syncTool:change2Str(TableName), StrUuid = syncTool:change2Str(Uuid), io:format("StrTableName and size is ~p,~p", [StrTableName, StrUuid]), Sql = ["Select uuid,faceUrl,del_flag from '", StrTableName, "_fea' where uuid = '", StrUuid, "';"], Maps = selectSomeInfoWithSql(Sql), if is_list(Maps) -> Res = Maps; is_tuple(Maps) -> Res = []; true -> Res = [] end, Res. del_personFea(TableName, Uuid) -> UpdateTime = syncTool:getTimeStr(), StrUuid = syncTool:change2Str(Uuid), StrTableName = syncTool:change2Str(TableName), Sql = ["UPDATE '", StrTableName, "_fea' SET del_flag = '1', update_time = '", UpdateTime, "' where Uuid = '", StrUuid, "';"], Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql), io:format("add_personFea ~p~n", [Ret]), if Ret == {atomic, ok} -> Result = {atomic, ok}; true -> Result = [] end, Result. loadFaceFeaData(TableName) -> StrTableName = syncTool:change2Str(TableName), Sql = ["Select a.uuid as id ,a.faceUrl as img,a.feature,a.del_flag,b.idCard as idcard from '", StrTableName, "_fea' as a ,'", StrTableName, "' 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. upd_personFea(Uuid, TableName, Feature, Img) -> UpdateTime = syncTool:getTimeStr(), StrUuid = syncTool:change2Str(Uuid), StrFeature = syncTool:change2Str(Feature), StrTableName = syncTool:change2Str(TableName), StrImg = syncTool:change2Str(Img), Sql = ["UPDATE '", StrTableName, "_fea' SET faceUrl = '", StrImg, "',feature = '", StrFeature, "', update_time = '", UpdateTime, "',del_flag = '0' where Uuid = '", StrUuid, "';"], Ret = executeSqlLocalyAndSaveToCacheAndSendSql(Sql), if Ret == {atomic, ok} -> Result = Uuid; true -> Result = '' end, Result.