|
@@ -5,9 +5,11 @@ import com.community.commom.constant.Constant;
|
5
|
5
|
import com.community.commom.mode.ResponseBean;
|
6
|
6
|
import com.community.commom.session.UserElement;
|
7
|
7
|
import com.community.huiju.common.hk.HKOpenApi;
|
|
8
|
+import com.community.huiju.common.welcome.WelcomeProperties;
|
8
|
9
|
import com.community.huiju.dao.TaFaceMapper;
|
9
|
10
|
import com.community.huiju.dao.TaSysRoleMapper;
|
10
|
11
|
import com.community.huiju.dao.TaUserMapper;
|
|
12
|
+import com.community.huiju.exception.WisdomException;
|
11
|
13
|
import com.community.huiju.model.TaFace;
|
12
|
14
|
import com.community.huiju.model.TaSysRole;
|
13
|
15
|
import com.community.huiju.model.TaUser;
|
|
@@ -15,8 +17,13 @@ import com.community.huiju.service.FaceServiceI;
|
15
|
17
|
import com.community.huiju.service.ImageServiceI;
|
16
|
18
|
import lombok.extern.slf4j.Slf4j;
|
17
|
19
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
20
|
+import org.springframework.http.HttpEntity;
|
|
21
|
+import org.springframework.http.HttpHeaders;
|
|
22
|
+import org.springframework.http.HttpMethod;
|
|
23
|
+import org.springframework.http.MediaType;
|
18
|
24
|
import org.springframework.stereotype.Service;
|
19
|
25
|
import org.springframework.transaction.annotation.Transactional;
|
|
26
|
+import org.springframework.web.client.RestTemplate;
|
20
|
27
|
import org.springframework.web.multipart.MultipartFile;
|
21
|
28
|
import java.io.IOException;
|
22
|
29
|
import java.util.ArrayList;
|
|
@@ -41,11 +48,23 @@ public class FaceServicelimpl implements FaceServiceI {
|
41
|
48
|
@Autowired
|
42
|
49
|
private ImageServiceI imageServiceI;
|
43
|
50
|
|
|
51
|
+ @Autowired
|
|
52
|
+ private WelcomeProperties welcomeProperties;
|
|
53
|
+
|
44
|
54
|
@Override
|
45
|
55
|
@Transactional(rollbackFor = Exception.class)
|
46
|
56
|
public ResponseBean addFace(Integer userid, MultipartFile uploadFile,Integer otherUserId) {
|
47
|
57
|
ResponseBean responseBean= new ResponseBean();
|
48
|
58
|
|
|
59
|
+ // 判断是否是迎宾系统人员
|
|
60
|
+ TaUser welcomeUser = taUserMapper.selectByPrimaryKey(otherUserId);
|
|
61
|
+ if (null != welcomeUser && null != welcomeProperties.getCommunityId() && welcomeUser.getCommunityId().intValue() == welcomeProperties.getCommunityId()) {
|
|
62
|
+ // 开始推送迎宾
|
|
63
|
+ responseBean = addWelcomeFace(uploadFile, welcomeUser);
|
|
64
|
+ return responseBean;
|
|
65
|
+ }
|
|
66
|
+
|
|
67
|
+
|
49
|
68
|
String faceImg =img(uploadFile);
|
50
|
69
|
/**当otherUserId不为空时判断它是否是业主下的租客或者家属*/
|
51
|
70
|
if (null!= otherUserId) {
|
|
@@ -267,6 +286,59 @@ public class FaceServicelimpl implements FaceServiceI {
|
267
|
286
|
response.addError("您的信息已存在");
|
268
|
287
|
return response;
|
269
|
288
|
}
|
|
289
|
+
|
|
290
|
+ @Override
|
|
291
|
+ @Transactional(rollbackFor = Exception.class)
|
|
292
|
+ public ResponseBean addWelcomeFace(MultipartFile uploadFile, TaUser user) {
|
|
293
|
+ ResponseBean responseBean = new ResponseBean();
|
|
294
|
+
|
|
295
|
+ // 开始推送 迎宾系统
|
|
296
|
+ String result = "";
|
|
297
|
+ try {
|
|
298
|
+// Map<String, Object> parameterMap = Maps.newHashMap();
|
|
299
|
+// parameterMap.put("userName", user.getUserName());
|
|
300
|
+// String welcomeUrl = welcomeProperties.getUrl() + "/" + user.getId();
|
|
301
|
+// OkHttpRequestUtils.doPost(welcomeUrl, Maps.newHashMap(), parameterMap, uploadFile.getOriginalFilename(), uploadFile.getBytes());
|
|
302
|
+
|
|
303
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
304
|
+ String faceUrl = welcomeProperties.getUrl() + "/" + user.getId() + "?userName=" + user.getUserName();
|
|
305
|
+ HttpHeaders headers = new HttpHeaders();
|
|
306
|
+ headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
|
|
307
|
+ HttpEntity httpEntity = new HttpEntity(uploadFile.getBytes());
|
|
308
|
+ result = restTemplate.exchange(faceUrl, HttpMethod.POST, httpEntity, String.class).getBody();
|
|
309
|
+ } catch (Exception e) {
|
|
310
|
+ e.printStackTrace();
|
|
311
|
+ log.error("推送 迎宾系统失败!", e);
|
|
312
|
+ throw new WisdomException("推送 迎宾系统失败!");
|
|
313
|
+ }
|
|
314
|
+
|
|
315
|
+ JSONObject jsonObject = JSONObject.parseObject(result);
|
|
316
|
+ if (!jsonObject.get("code").equals(200)){
|
|
317
|
+ String message = jsonObject.get("message").toString();
|
|
318
|
+ log.error(" 推送 迎宾系统失败! {}",message);
|
|
319
|
+ throw new WisdomException(message);
|
|
320
|
+ }
|
|
321
|
+
|
|
322
|
+ // 开始存储人脸的图片到本地库
|
|
323
|
+ TaFace taFace = new TaFace();
|
|
324
|
+ taFace.setCommunityId(user.getCommunityId());
|
|
325
|
+ taFace.setCreateDate(new Date());
|
|
326
|
+ taFace.setCreateUser(user.getId());
|
|
327
|
+ taFace.setTaUserId(user.getId());
|
|
328
|
+ taFace.setUpdateDate(new Date());
|
|
329
|
+ taFace.setUpdateUser(user.getId());
|
|
330
|
+ try {
|
|
331
|
+ taFace.setFaceImg(imageServiceI.getImageUrl(uploadFile));
|
|
332
|
+ } catch (IOException e) {
|
|
333
|
+ e.printStackTrace();
|
|
334
|
+ log.error("迎宾系统 人脸图片上传阿里云失败!", e);
|
|
335
|
+ }
|
|
336
|
+
|
|
337
|
+ taFaceMapper.insertSelective(taFace);
|
|
338
|
+
|
|
339
|
+ responseBean.addSuccess("操作成功!");
|
|
340
|
+ return responseBean;
|
|
341
|
+ }
|
270
|
342
|
}
|
271
|
343
|
|
272
|
344
|
|