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
| %%%-------------------------------------------------------------------
| %%% @author bsk
| %%% @copyright (C) 2018, <COMPANY>
| %%% @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.
|
|