|
@@ -1,5 +1,6 @@
|
1
|
1
|
package com.huiju.welcome.service.impl;
|
2
|
2
|
|
|
3
|
+import com.alibaba.fastjson.JSONArray;
|
3
|
4
|
import com.alibaba.fastjson.JSONObject;
|
4
|
5
|
import com.alibaba.fastjson.serializer.SerializerFeature;
|
5
|
6
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
@@ -8,19 +9,14 @@ import com.huiju.welcome.common.WebSocketServer;
|
8
|
9
|
import com.huiju.welcome.mapper.SysUserMapper;
|
9
|
10
|
import com.huiju.welcome.mapper.TaCustomerMapMapper;
|
10
|
11
|
import com.huiju.welcome.mapper.TaCustomerMapper;
|
11
|
|
-import com.huiju.welcome.model.SysUser;
|
12
|
|
-import com.huiju.welcome.model.TaCustomer;
|
13
|
|
-import com.huiju.welcome.model.TaCustomerMap;
|
14
|
|
-import com.huiju.welcome.model.TaDevice;
|
15
|
|
-import com.huiju.welcome.model.TaFirstUsherRecord;
|
16
|
|
-import com.huiju.welcome.model.TaMainUsherRecord;
|
17
|
|
-import com.huiju.welcome.model.TaPerson;
|
18
|
|
-import com.huiju.welcome.model.TaSnapshotPerson;
|
|
12
|
+import com.huiju.welcome.mapper.TaFaceLibMapper;
|
|
13
|
+import com.huiju.welcome.model.*;
|
19
|
14
|
import com.huiju.welcome.service.*;
|
20
|
15
|
import com.huiju.welcome.utils.*;
|
21
|
16
|
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
|
22
|
17
|
import io.swagger.models.auth.In;
|
23
|
18
|
import lombok.extern.slf4j.Slf4j;
|
|
19
|
+import org.apache.http.HttpStatus;
|
24
|
20
|
import org.springframework.beans.factory.annotation.Autowired;
|
25
|
21
|
import org.springframework.beans.factory.annotation.Value;
|
26
|
22
|
import org.springframework.stereotype.Service;
|
|
@@ -38,6 +34,9 @@ import java.util.Map;
|
38
|
34
|
@Slf4j
|
39
|
35
|
@Service
|
40
|
36
|
public class CameraServiceImpl implements ICameraService {
|
|
37
|
+ final static String HIK_FACE_LIB = "hik-face";
|
|
38
|
+ final static String ALI_FACE_LIB = "ali-face";
|
|
39
|
+
|
41
|
40
|
@Autowired
|
42
|
41
|
private ITaDeviceService taDeviceService;
|
43
|
42
|
|
|
@@ -71,6 +70,9 @@ public class CameraServiceImpl implements ICameraService {
|
71
|
70
|
@Autowired
|
72
|
71
|
private SysUserMapper sysUserMapper;
|
73
|
72
|
|
|
73
|
+ @Autowired
|
|
74
|
+ private TaFaceLibMapper taFaceLibMapper;
|
|
75
|
+
|
74
|
76
|
@Autowired
|
75
|
77
|
private IMessageService iMessageService;
|
76
|
78
|
|
|
@@ -99,6 +101,16 @@ public class CameraServiceImpl implements ICameraService {
|
99
|
101
|
Action act = Action.create(Action.TYPE_DISPATCH_FACE, payload);
|
100
|
102
|
|
101
|
103
|
WebSocketServer.sendInfo(act.toJSON(), "device", device.getDeviceId());
|
|
104
|
+
|
|
105
|
+ // 假设海康设备下发成功
|
|
106
|
+ TaFaceLib taFaceLib = new TaFaceLib();
|
|
107
|
+ taFaceLib.setLocalPerson(taPerson.getPersonId());
|
|
108
|
+ taFaceLib.setLibCode(HIK_FACE_LIB); // 海康设备
|
|
109
|
+ taFaceLib.setLibPerson(taPerson.getPersonId().toString());
|
|
110
|
+ taFaceLib.setLibFace(taPerson.getPersonId().toString());
|
|
111
|
+ taFaceLib.setDeviceId(device.getDeviceId());
|
|
112
|
+ taFaceLibMapper.insert(taFaceLib);
|
|
113
|
+
|
102
|
114
|
} catch (Exception e){
|
103
|
115
|
e.printStackTrace();
|
104
|
116
|
return "连接设备(" + device.getDeviceId() + ")人脸下发服务 失败: "+ e.getMessage();
|
|
@@ -114,7 +126,27 @@ public class CameraServiceImpl implements ICameraService {
|
114
|
126
|
// }
|
115
|
127
|
|
116
|
128
|
try {
|
117
|
|
- aliFaceUtils.createFace(String.valueOf(taPerson.getRealId()), taPerson.getAvatar());
|
|
129
|
+ JSONObject result = aliFaceUtils.createFace(String.valueOf(taPerson.getRealId()), taPerson.getAvatar());
|
|
130
|
+ if (null != result && result.getInteger("code") == HttpStatus.SC_OK) {
|
|
131
|
+ JSONArray faceImageItems = result.getJSONArray("faceImageItems");
|
|
132
|
+ if (null != faceImageItems && faceImageItems.size() > 0) {
|
|
133
|
+ JSONObject faceInfo = faceImageItems.getJSONObject(0);
|
|
134
|
+// Double faceId = faceInfo.getDouble("faceId"); // 阿里返回值是一个 double 类型
|
|
135
|
+ String faceId = faceInfo.getString("faceId");
|
|
136
|
+
|
|
137
|
+ //
|
|
138
|
+ TaFaceLib taFaceLib = new TaFaceLib();
|
|
139
|
+ taFaceLib.setLocalPerson(taPerson.getPersonId());
|
|
140
|
+ taFaceLib.setLibCode(ALI_FACE_LIB); // 海康设备
|
|
141
|
+ taFaceLib.setLibPerson(taPerson.getPersonId().toString());
|
|
142
|
+ taFaceLib.setLibFace(faceId);
|
|
143
|
+// taFaceLib.setDeviceId();
|
|
144
|
+ taFaceLibMapper.insert(taFaceLib);
|
|
145
|
+ }
|
|
146
|
+
|
|
147
|
+ } else {
|
|
148
|
+ log.error("下发人脸到阿里云失败: 原因未知");
|
|
149
|
+ }
|
118
|
150
|
} catch (Exception e) {
|
119
|
151
|
e.printStackTrace();
|
120
|
152
|
log.error("下发人脸到阿里云失败: " + e.getMessage());
|
|
@@ -123,6 +155,45 @@ public class CameraServiceImpl implements ICameraService {
|
123
|
155
|
return "";
|
124
|
156
|
}
|
125
|
157
|
|
|
158
|
+ @Override
|
|
159
|
+ public boolean deleteFace(Integer personId) {
|
|
160
|
+ QueryWrapper<TaFaceLib> wrapper = new QueryWrapper<>();
|
|
161
|
+ wrapper.eq("local_person", personId);
|
|
162
|
+
|
|
163
|
+ List<TaFaceLib> taFaceLibs = taFaceLibMapper.selectList(wrapper);
|
|
164
|
+ if (null == taFaceLibs || taFaceLibs.size() == 0) {
|
|
165
|
+ return true;
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ for (TaFaceLib taFaceLib: taFaceLibs) {
|
|
169
|
+ String libCode = taFaceLib.getLibCode();
|
|
170
|
+
|
|
171
|
+ if (libCode.indexOf(ALI_FACE_LIB) > -1) {
|
|
172
|
+ // 删除阿里人脸
|
|
173
|
+ try {
|
|
174
|
+ aliFaceUtils.deleteFace(taFaceLib.getLibPerson(), taFaceLib.getLibFace());
|
|
175
|
+ } catch (Exception e) {
|
|
176
|
+ e.printStackTrace();
|
|
177
|
+ }
|
|
178
|
+ } else {
|
|
179
|
+ // 删除海康人脸
|
|
180
|
+ try {
|
|
181
|
+ Map<String, Object> payload = new HashMap<>();
|
|
182
|
+ payload.put("personId", personId);
|
|
183
|
+ Action act = Action.create(Action.TYPE_DELETE_FACE, payload);
|
|
184
|
+ WebSocketServer.sendInfo(act.toJSON(), "device", taFaceLib.getDeviceId());
|
|
185
|
+ } catch (Exception e) {
|
|
186
|
+ e.printStackTrace();
|
|
187
|
+ }
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ // 清除数据库
|
|
191
|
+ taFaceLibMapper.deleteById(taFaceLib);
|
|
192
|
+ }
|
|
193
|
+
|
|
194
|
+ return false;
|
|
195
|
+ }
|
|
196
|
+
|
126
|
197
|
@Override
|
127
|
198
|
public boolean newPersonByDevice(TaSnapshotPerson taSnapshotPerson) {
|
128
|
199
|
boolean workingTime = iSysParamService.isInWorkingTime(LocalDateTime.now());
|