|
@@ -1,4 +1,5 @@
|
1
|
1
|
package com.community.huiju.service.impl;
|
|
2
|
+
|
2
|
3
|
import com.alibaba.fastjson.JSONObject;
|
3
|
4
|
import com.community.commom.ailiyun.AESDecode;
|
4
|
5
|
import com.community.commom.constant.Constant;
|
|
@@ -9,10 +10,12 @@ import com.community.huiju.common.welcome.WelcomeProperties;
|
9
|
10
|
import com.community.huiju.dao.TaFaceMapper;
|
10
|
11
|
import com.community.huiju.dao.TaSysRoleMapper;
|
11
|
12
|
import com.community.huiju.dao.TaUserMapper;
|
|
13
|
+import com.community.huiju.dao.TaUserVerifyMapper;
|
12
|
14
|
import com.community.huiju.exception.WisdomException;
|
13
|
15
|
import com.community.huiju.model.TaFace;
|
14
|
16
|
import com.community.huiju.model.TaSysRole;
|
15
|
17
|
import com.community.huiju.model.TaUser;
|
|
18
|
+import com.community.huiju.model.TaUserVerify;
|
16
|
19
|
import com.community.huiju.service.FaceServiceI;
|
17
|
20
|
import com.community.huiju.service.ImageServiceI;
|
18
|
21
|
import lombok.extern.slf4j.Slf4j;
|
|
@@ -25,6 +28,7 @@ import org.springframework.stereotype.Service;
|
25
|
28
|
import org.springframework.transaction.annotation.Transactional;
|
26
|
29
|
import org.springframework.web.client.RestTemplate;
|
27
|
30
|
import org.springframework.web.multipart.MultipartFile;
|
|
31
|
+
|
28
|
32
|
import java.io.IOException;
|
29
|
33
|
import java.util.ArrayList;
|
30
|
34
|
import java.util.Date;
|
|
@@ -51,10 +55,13 @@ public class FaceServicelimpl implements FaceServiceI {
|
51
|
55
|
@Autowired
|
52
|
56
|
private WelcomeProperties welcomeProperties;
|
53
|
57
|
|
|
58
|
+ @Autowired
|
|
59
|
+ private TaUserVerifyMapper taUserVerifyMapper;
|
|
60
|
+
|
54
|
61
|
@Override
|
55
|
62
|
@Transactional(rollbackFor = Exception.class)
|
56
|
|
- public ResponseBean addFace(Integer userid, MultipartFile uploadFile,Integer otherUserId) {
|
57
|
|
- ResponseBean responseBean= new ResponseBean();
|
|
63
|
+ public ResponseBean addFace(UserElement userElement, MultipartFile uploadFile, Integer otherUserId) {
|
|
64
|
+ ResponseBean responseBean = new ResponseBean();
|
58
|
65
|
|
59
|
66
|
// 判断是否是迎宾系统人员
|
60
|
67
|
TaUser welcomeUser = taUserMapper.selectByPrimaryKey(otherUserId);
|
|
@@ -64,65 +71,64 @@ public class FaceServicelimpl implements FaceServiceI {
|
64
|
71
|
return responseBean;
|
65
|
72
|
}
|
66
|
73
|
|
|
74
|
+ // 当前人脸图片url
|
|
75
|
+ String faceImg = img(uploadFile);
|
|
76
|
+ // 房产审核id
|
|
77
|
+ Integer userVerifyId = userElement.getUserVerifyId();
|
67
|
78
|
|
68
|
|
- String faceImg =img(uploadFile);
|
69
|
79
|
/**当otherUserId不为空时判断它是否是业主下的租客或者家属*/
|
70
|
|
- if (null!= otherUserId) {
|
71
|
|
- responseBean = getTaFaceParentId(userid, otherUserId);
|
72
|
|
- if ("1".equals(responseBean.getCode())){
|
73
|
|
- responseBean.getMessage();
|
74
|
|
- return responseBean;
|
75
|
|
- }
|
|
80
|
+ if (null != otherUserId) {
|
|
81
|
+ TaUserVerify otherUserVerify = getTaFaceParentId(userElement, otherUserId);
|
|
82
|
+ userVerifyId = otherUserVerify.getId();
|
76
|
83
|
}
|
77
|
|
- Integer activeUser = otherUserId == null?userid:otherUserId;
|
78
|
|
- TaUser user = taUserMapper.selectByPrimaryKey(activeUser);
|
79
|
|
- TaFace taFace = new TaFace();
|
80
|
|
- taFace.setFaceImg(faceImg);
|
81
|
|
- taFace.setCommunityId(user.getCommunityId());
|
82
|
|
- taFace.setTaUserId(activeUser);
|
83
|
|
- taFace.setCreateUser(userid);
|
84
|
|
- taFace.setUpdateUser(activeUser);
|
85
|
|
- taFace.setCreateDate(new Date());
|
86
|
|
- taFace.setUpdateDate(new Date());
|
|
84
|
+ Integer activeUser = otherUserId == null ? userElement.getId() : otherUserId;
|
|
85
|
+ TaUser user = taUserMapper.selectByPrimaryKey(activeUser);
|
|
86
|
+ TaFace taFace = new TaFace();
|
|
87
|
+ taFace.setFaceImg(faceImg);
|
|
88
|
+ taFace.setCommunityId(user.getCommunityId());
|
|
89
|
+ taFace.setTaUserVerifyId(userVerifyId);
|
|
90
|
+ taFace.setCreateUser(userElement.getId());
|
|
91
|
+ taFace.setUpdateUser(activeUser);
|
|
92
|
+ taFace.setCreateDate(new Date());
|
|
93
|
+ taFace.setUpdateDate(new Date());
|
87
|
94
|
|
88
|
95
|
/*验证身份*/
|
89
|
|
- responseBean=addVerify( activeUser, uploadFile, faceImg, taFace) ;
|
|
96
|
+ responseBean = addVerify(activeUser, userVerifyId, uploadFile, faceImg, taFace);
|
90
|
97
|
return responseBean;
|
91
|
98
|
}
|
92
|
99
|
|
93
|
100
|
/**
|
94
|
101
|
* 修改人脸信息
|
95
|
|
- * @param userId 登入人ID
|
96
|
|
- * @param uploadFile
|
|
102
|
+ *
|
|
103
|
+ * @param userElement 登入人ID
|
|
104
|
+ * @param uploadFile
|
97
|
105
|
* @param otherUserId 关联家属或者租客ID
|
98
|
106
|
* @return
|
99
|
107
|
*/
|
100
|
108
|
@Override
|
101
|
109
|
@Transactional(rollbackFor = Exception.class)
|
102
|
|
- public ResponseBean upDateFace(Integer userId, MultipartFile uploadFile,Integer otherUserId) {
|
103
|
|
- boolean isA = false;
|
104
|
|
- ResponseBean responseBean= new ResponseBean();
|
105
|
|
- String faceImg =img(uploadFile);
|
106
|
|
- if (null!= otherUserId) {
|
107
|
|
- responseBean = getTaFaceParentId(userId, otherUserId);
|
108
|
|
- if ("1".equals(responseBean.getCode())) {
|
109
|
|
- responseBean.getMessage();
|
110
|
|
- return responseBean;
|
111
|
|
- }}
|
112
|
|
- Integer activeUser = otherUserId == null?userId:otherUserId;
|
113
|
|
- //当前修改的id否存在
|
114
|
|
- TaFace face = taFaceMapper.getByUserId(activeUser);
|
115
|
|
- if (null == face){
|
116
|
|
- responseBean.addError("您的信息不存在,请录入人脸");
|
117
|
|
- return responseBean;
|
118
|
|
- }
|
119
|
|
- TaUser user = taUserMapper.selectByPrimaryKey(activeUser);
|
120
|
|
- TaFace taFace = new TaFace();
|
121
|
|
- taFace.setTaUserId(activeUser);
|
122
|
|
- taFace.setFaceImg(faceImg);
|
123
|
|
- taFace.setUpdateUser(userId);
|
124
|
|
- taFace.setUpdateDate(new Date());
|
125
|
|
- ResponseBean resps = checKout(faceImg, taFace, isA, uploadFile, activeUser);
|
|
110
|
+ public ResponseBean upDateFace(UserElement userElement, MultipartFile uploadFile, Integer otherUserId) {
|
|
111
|
+ ResponseBean responseBean = new ResponseBean();
|
|
112
|
+ // 人脸图片地址url
|
|
113
|
+ String faceImg = img(uploadFile);
|
|
114
|
+ // 房产 审核id
|
|
115
|
+ Integer userVerifyId = userElement.getUserVerifyId();
|
|
116
|
+ if (null != otherUserId) {
|
|
117
|
+ TaUserVerify otherUserVerify = getTaFaceParentId(userElement, otherUserId);
|
|
118
|
+ userVerifyId = otherUserVerify.getId();
|
|
119
|
+ }
|
|
120
|
+ Integer activeUser = otherUserId == null ? userElement.getId() : otherUserId;
|
|
121
|
+ //当前修改的id否存在
|
|
122
|
+ TaFace face = taFaceMapper.getByUserVerifyId(userVerifyId);
|
|
123
|
+ if (null == face) {
|
|
124
|
+ responseBean.addError("您的信息不存在,请录入人脸");
|
|
125
|
+ return responseBean;
|
|
126
|
+ }
|
|
127
|
+ face.setTaUserVerifyId(userVerifyId);
|
|
128
|
+ face.setFaceImg(faceImg);
|
|
129
|
+ face.setUpdateUser(userElement.getId());
|
|
130
|
+ face.setUpdateDate(new Date());
|
|
131
|
+ ResponseBean resps = checKout(faceImg, face, false, uploadFile, activeUser);
|
126
|
132
|
if (resps.getCode().equals("0")) {
|
127
|
133
|
resps.addSuccess((Object) faceImg);
|
128
|
134
|
} else {
|
|
@@ -132,7 +138,7 @@ public class FaceServicelimpl implements FaceServiceI {
|
132
|
138
|
}
|
133
|
139
|
|
134
|
140
|
/**
|
135
|
|
- *验证图片是否为人脸,推送海康
|
|
141
|
+ * 验证图片是否为人脸,推送海康
|
136
|
142
|
*/
|
137
|
143
|
public ResponseBean checKout(String faceImg, TaFace taFace, boolean isA, MultipartFile uploadFile, Integer userId) {
|
138
|
144
|
ResponseBean responseBean = new ResponseBean();
|
|
@@ -145,88 +151,88 @@ public class FaceServicelimpl implements FaceServiceI {
|
145
|
151
|
AESDecode aesd = new AESDecode();
|
146
|
152
|
String body = "{\"type\": \"0\", \"image_url\":\"" + faceImg + "\"}";
|
147
|
153
|
try {
|
148
|
|
- responseBean = aesd.send(body);
|
149
|
|
- JSONObject jsonObject = JSONObject.parseObject(responseBean.getMessage());
|
150
|
|
- Integer type = (Integer) jsonObject.get("errno");
|
151
|
|
- Integer faceNum = (Integer) jsonObject.get("face_num");
|
152
|
|
-
|
153
|
|
- /*推送海康*/
|
154
|
|
- String data=HKOpenApi.HKpersonGroupId(uploadFile, user.getHkUserId(), user.getHkPersonNo(), user.getUserName(), user.getHkCardNo());
|
155
|
|
- /*boolean isA为true进行添加,为false进行修改*/
|
|
154
|
+ responseBean = aesd.send(body);
|
|
155
|
+ JSONObject jsonObject = JSONObject.parseObject(responseBean.getMessage());
|
|
156
|
+ Integer type = (Integer) jsonObject.get("errno");
|
|
157
|
+ Integer faceNum = (Integer) jsonObject.get("face_num");
|
|
158
|
+
|
|
159
|
+ /*推送海康*/
|
|
160
|
+ String data = HKOpenApi.HKpersonGroupId(uploadFile, user.getHkUserId(), user.getHkPersonNo(), user.getUserName(), user.getHkCardNo());
|
|
161
|
+ /*boolean isA为true进行添加,为false进行修改*/
|
156
|
162
|
if (0 == type && 1 == faceNum) {
|
157
|
163
|
if (null == data) {
|
158
|
164
|
throw new RuntimeException("海康人脸推送失敗!");
|
159
|
165
|
}
|
160
|
166
|
if (isA) {
|
161
|
167
|
taFaceMapper.insertSelective(taFace);
|
162
|
|
- }else {
|
|
168
|
+ } else {
|
163
|
169
|
taFaceMapper.updateByPrimaryKeySelective(taFace);
|
164
|
170
|
}
|
165
|
171
|
responseBean.addSuccess("操作成功");
|
166
|
172
|
HKOpenApi.downloadFaceAndFingerInfos(String.valueOf(user.getHkUserId()));
|
167
|
173
|
//可视对讲时 指定人员人脸权限下载
|
168
|
|
- List<Integer> userIdList= new ArrayList<>();
|
|
174
|
+ List<Integer> userIdList = new ArrayList<>();
|
169
|
175
|
userIdList.add(user.getHkUserId());
|
170
|
176
|
//临时设备编号
|
171
|
177
|
// TODO 根据期楼栋号,来查询出门口机
|
172
|
|
- List<String> visualList= new ArrayList<>();
|
|
178
|
+ List<String> visualList = new ArrayList<>();
|
173
|
179
|
visualList.add("10010100000");
|
174
|
|
- HKOpenApi.visualIntercom(null,1,userIdList,visualList);
|
175
|
|
- }else {
|
|
180
|
+ HKOpenApi.visualIntercom(null, 1, userIdList, visualList);
|
|
181
|
+ } else {
|
176
|
182
|
responseBean.addError("请录入正确图片");
|
177
|
183
|
}
|
178
|
184
|
} catch (Exception e) {
|
179
|
185
|
e.printStackTrace();
|
180
|
|
- log.error("海康人脸推送失敗! {}",e);
|
|
186
|
+ log.error("海康人脸推送失敗! {}", e);
|
181
|
187
|
throw new RuntimeException("海康人脸推送失敗!");
|
182
|
188
|
}
|
183
|
189
|
return responseBean;
|
184
|
190
|
}
|
185
|
191
|
|
186
|
192
|
/**
|
187
|
|
- *获得用户,租客,家属,其中一种身份的信息
|
|
193
|
+ * 当前登入人是否有人脸信息
|
188
|
194
|
*/
|
189
|
195
|
@Override
|
190
|
|
- public ResponseBean getTaFaceByUserId(Integer userId,Integer otherUserId) {
|
191
|
|
- ResponseBean responseBean= new ResponseBean();
|
|
196
|
+ public ResponseBean getTaFaceByUserId(UserElement userElement, Integer otherUserId) {
|
|
197
|
+ ResponseBean responseBean = new ResponseBean();
|
|
198
|
+ Integer userVerifyId = userElement.getUserVerifyId();
|
|
199
|
+
|
192
|
200
|
/**当otherUserId不为空时判断它是否是业主下的租客或者家属*/
|
193
|
|
- if (null!= otherUserId) {
|
194
|
|
- responseBean = getTaFaceParentId(userId, otherUserId);
|
195
|
|
- if ("1".equals(responseBean.getCode())) {
|
196
|
|
- responseBean.getMessage();
|
197
|
|
- return responseBean;
|
198
|
|
- }
|
|
201
|
+ if (null != otherUserId) {
|
|
202
|
+ TaUserVerify userVerify = getTaFaceParentId(userElement, otherUserId);
|
|
203
|
+ userVerifyId = userVerify.getId();
|
199
|
204
|
}
|
200
|
|
- Integer id = otherUserId == null?userId:otherUserId;
|
201
|
|
- TaFace face = taFaceMapper.getByUserId(id);
|
202
|
|
- if (null!= face){
|
|
205
|
+ TaFace face = taFaceMapper.getByUserVerifyId(userVerifyId);
|
|
206
|
+ if (null != face) {
|
203
|
207
|
responseBean.addSuccess(face);
|
204
|
208
|
return responseBean;
|
205
|
209
|
}
|
206
|
|
- responseBean.addError("当前用户暂无人脸图片");
|
207
|
|
- return responseBean;
|
|
210
|
+ responseBean.addError("当前用户暂无人脸图片");
|
|
211
|
+ return responseBean;
|
208
|
212
|
|
209
|
213
|
}
|
210
|
214
|
|
211
|
215
|
/**
|
212
|
|
- *判断当前用户下的人员关系(家属,租客)
|
|
216
|
+ * 判断当前用户下的人员关系(家属,租客)
|
213
|
217
|
*/
|
214
|
|
- public ResponseBean getTaFaceParentId(Integer userId,Integer otherUserId){
|
215
|
|
- ResponseBean responseBean= new ResponseBean();
|
216
|
|
- TaUser users= taUserMapper.selectByPrimaryKey(otherUserId);
|
217
|
|
- if (null == users || !userId.equals(users.getParentId())){
|
218
|
|
- responseBean.addError("您输入的家属或租户ID有误");
|
219
|
|
-
|
220
|
|
- }else if (userId.equals(otherUserId)){
|
221
|
|
- responseBean.addError("您输入的家属或租户ID有误");
|
|
218
|
+ public TaUserVerify getTaFaceParentId(UserElement userElement, Integer otherUserId) {
|
|
219
|
+ // 根据 家属/租客 的id, 和 当前的房产信息进行查询是否有值,有值就说明是 家属/租客
|
|
220
|
+ TaUserVerify todUserVerify = taUserVerifyMapper.selectCommunityAndAddress(otherUserId, userElement.getCommunityId(), userElement.getPhaseId(), userElement.getBuildingId(), userElement.getUnitId(), userElement.getLevelId(), userElement.getRoomNoId());
|
|
221
|
+ // 判断 家属或者租客 属不属于这个业主的下面
|
|
222
|
+ if (null == todUserVerify) {
|
|
223
|
+ throw new WisdomException("您输入的家属或租户ID有误");
|
222
|
224
|
}
|
223
|
|
- return responseBean;
|
|
225
|
+ if (!Constant.VERIFY_STATUS.equals(todUserVerify.getVerifyStatus())) {
|
|
226
|
+ throw new WisdomException("用户房产审核未通过!");
|
|
227
|
+ }
|
|
228
|
+
|
|
229
|
+ return todUserVerify;
|
224
|
230
|
}
|
225
|
231
|
|
226
|
232
|
/**
|
227
|
233
|
* 得到当前图片
|
228
|
234
|
*/
|
229
|
|
- private String img(MultipartFile uploadFile){
|
|
235
|
+ private String img(MultipartFile uploadFile) {
|
230
|
236
|
String faceImg = null;
|
231
|
237
|
try {
|
232
|
238
|
faceImg = imageServiceI.getImageUrl(uploadFile);
|
|
@@ -237,50 +243,34 @@ public class FaceServicelimpl implements FaceServiceI {
|
237
|
243
|
}
|
238
|
244
|
|
239
|
245
|
/**
|
240
|
|
- *各种身份校验
|
|
246
|
+ * 各种身份校验
|
241
|
247
|
*/
|
242
|
|
- public ResponseBean addVerify(Integer userid, MultipartFile uploadFile,String faceImg,TaFace taFace) {
|
|
248
|
+ public ResponseBean addVerify(Integer userid, Integer userVerifyId, MultipartFile uploadFile, String faceImg, TaFace taFace) {
|
243
|
249
|
ResponseBean response = new ResponseBean();
|
244
|
|
- TaSysRole sysRole = taSysRoleMapper.findRoleByUserId(userid);
|
|
250
|
+
|
|
251
|
+ TaUserVerify userVerify = taUserVerifyMapper.selectByPrimaryKey(userVerifyId);
|
245
|
252
|
TaUser taUser = taUserMapper.selectByPrimaryKey(userid);
|
246
|
|
- if (null!=taUser && null!=sysRole
|
247
|
|
- && Constant.INVALID.equals(taUser.getStatus())&& Constant.OWNER.equals(sysRole.getRoleName())) {
|
|
253
|
+
|
|
254
|
+ //身份为家属租客,状态为已停用
|
|
255
|
+ if (null != taUser && !Constant.EFFECTIVE_STATUS.equals(taUser.getStatus())) {
|
248
|
256
|
response.addError("9996", "您的身份已停用,请联系物业");
|
249
|
257
|
return response;
|
250
|
258
|
}
|
251
|
|
- //身份为家属租客,状态为已停用
|
252
|
|
- if (null!=taUser && null!=sysRole){
|
253
|
|
- if (Constant.INVALID.equals(taUser.getStatus()) && ((Constant.RELATION.equals(sysRole.getRoleName())) || Constant.TENANT.equals(sysRole.getRoleName()))){
|
254
|
|
- response.addError("9996", "您的身份已停用,请联系物业");
|
255
|
|
- return response;
|
256
|
|
- }
|
257
|
|
- }
|
|
259
|
+
|
258
|
260
|
//查询当前用户是否有人脸记录
|
259
|
|
- TaFace User = taFaceMapper.getByUserId(userid);
|
260
|
|
- if (null == User) {
|
|
261
|
+ TaFace face = taFaceMapper.getByUserVerifyId(userVerifyId);
|
|
262
|
+ if (null == face) {
|
261
|
263
|
boolean isA = true;
|
262
|
|
- if (Constant.OWNER.equals(sysRole.getRoleName()) && "1".equals(taUser.getVerifyStatus())) {
|
263
|
|
- ResponseBean resps = checKout(faceImg, taFace, isA, uploadFile, userid);
|
264
|
|
- if (resps.getCode().equals("0")) {
|
265
|
|
- taUser.setFaceStatus("1");
|
266
|
|
- taUserMapper.updateByPrimaryKeySelective(taUser);
|
267
|
|
- resps.addSuccess("图片录入成功");
|
268
|
|
- } else {
|
269
|
|
- resps.addError(resps.getMessage());
|
270
|
|
- }
|
271
|
|
- return resps;
|
272
|
|
- }
|
273
|
|
- //家属或者租客,已认证
|
274
|
|
- if (Constant.RELATION.equals(sysRole.getRoleName()) || Constant.TENANT.equals(sysRole.getRoleName()) && "1".equals(taUser.getVerifyStatus())) {
|
275
|
|
- ResponseBean resps = checKout(faceImg, taFace, isA, uploadFile, userid);
|
276
|
|
- if (resps.getCode().equals("0")) {
|
|
264
|
+ if (Constant.EFFECTIVE_STATUS.equals(taUser.getStatus()) && "1".equals(taUser.getVerifyStatus())) {
|
|
265
|
+ ResponseBean responseBean = checKout(faceImg, taFace, isA, uploadFile, userid);
|
|
266
|
+ if (responseBean.getCode().equals("0")) {
|
277
|
267
|
taUser.setFaceStatus("1");
|
278
|
268
|
taUserMapper.updateByPrimaryKeySelective(taUser);
|
279
|
|
- resps.addSuccess("图片录入成功");
|
|
269
|
+ responseBean.addSuccess("图片录入成功");
|
280
|
270
|
} else {
|
281
|
|
- resps.addError(resps.getMessage());
|
|
271
|
+ responseBean.addError(responseBean.getMessage());
|
282
|
272
|
}
|
283
|
|
- return resps;
|
|
273
|
+ return responseBean;
|
284
|
274
|
}
|
285
|
275
|
}
|
286
|
276
|
response.addError("您的信息已存在");
|
|
@@ -313,9 +303,9 @@ public class FaceServicelimpl implements FaceServiceI {
|
313
|
303
|
}
|
314
|
304
|
|
315
|
305
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
316
|
|
- if (!jsonObject.get("code").equals(200)){
|
|
306
|
+ if (!jsonObject.get("code").equals(200)) {
|
317
|
307
|
String message = jsonObject.get("message").toString();
|
318
|
|
- log.error(" 推送 迎宾系统失败! {}",message);
|
|
308
|
+ log.error(" 推送 迎宾系统失败! {}", message);
|
319
|
309
|
throw new WisdomException(message);
|
320
|
310
|
}
|
321
|
311
|
|
|
@@ -324,7 +314,7 @@ public class FaceServicelimpl implements FaceServiceI {
|
324
|
314
|
taFace.setCommunityId(user.getCommunityId());
|
325
|
315
|
taFace.setCreateDate(new Date());
|
326
|
316
|
taFace.setCreateUser(user.getId());
|
327
|
|
- taFace.setTaUserId(user.getId());
|
|
317
|
+ //taFace.setTaUserId(user.getId());
|
328
|
318
|
taFace.setUpdateDate(new Date());
|
329
|
319
|
taFace.setUpdateUser(user.getId());
|
330
|
320
|
try {
|