|
@@ -7,6 +7,7 @@ import com.community.commom.constant.Constant;
|
7
|
7
|
import com.community.commom.mode.ResponseBean;
|
8
|
8
|
import com.community.huiju.common.hk.HKConstant;
|
9
|
9
|
import com.community.huiju.common.hk.HKOpenApi;
|
|
10
|
+import com.community.huiju.common.hk.test.PicUtils;
|
10
|
11
|
import com.community.huiju.controller.ImageController;
|
11
|
12
|
import com.community.huiju.dao.TaFaceMapper;
|
12
|
13
|
import com.community.huiju.dao.TaSysRoleMapper;
|
|
@@ -18,11 +19,16 @@ import com.community.huiju.service.ImageServiceI;
|
18
|
19
|
import com.community.huiju.service.FaceServicel;
|
19
|
20
|
import com.hikvision.cms.api.common.util.Digests;
|
20
|
21
|
import com.hikvision.cms.api.common.util.HttpClientSSLUtils;
|
|
22
|
+import org.apache.commons.io.FileUtils;
|
21
|
23
|
import org.springframework.beans.factory.annotation.Autowired;
|
22
|
24
|
import org.springframework.stereotype.Service;
|
|
25
|
+import org.springframework.transaction.annotation.Transactional;
|
23
|
26
|
import org.springframework.web.multipart.MultipartFile;
|
24
|
27
|
|
|
28
|
+import java.io.File;
|
|
29
|
+import java.io.FileInputStream;
|
25
|
30
|
import java.io.IOException;
|
|
31
|
+import java.io.InputStream;
|
26
|
32
|
import java.util.Date;
|
27
|
33
|
import java.util.HashMap;
|
28
|
34
|
import java.util.Map;
|
|
@@ -44,6 +50,7 @@ public class FaceServicelimpl implements FaceServicel {
|
44
|
50
|
private ImageServiceI imageServiceI;
|
45
|
51
|
|
46
|
52
|
@Override
|
|
53
|
+ @Transactional
|
47
|
54
|
public ResponseBean addFace(Integer userid,MultipartFile uploadFile) {
|
48
|
55
|
String faceImg = null;
|
49
|
56
|
try {
|
|
@@ -87,35 +94,41 @@ public class FaceServicelimpl implements FaceServicel {
|
87
|
94
|
boolean isA=true;
|
88
|
95
|
if (Constant.OWNER.equals(sysRole.getRoleName()) && "1".equals(taUser.getVerifyStatus())) {
|
89
|
96
|
ResponseBean responseBean = new ResponseBean();
|
90
|
|
- boolean resps=checKout(faceImg,taFace,isA,null);
|
91
|
|
- if (resps==true) {
|
92
|
|
- //校验通过后
|
93
|
|
- imgPush(user.getUserName(),faceImg);
|
|
97
|
+ Object resps=checKout(faceImg,taFace,isA,null,user.getUserName(),uploadFile);
|
|
98
|
+ if (null!=resps && "true".equals(resps)) {
|
94
|
99
|
responseBean.addSuccess("图片录入成功");
|
95
|
100
|
}else {
|
96
|
|
- responseBean.addError("7771","请录入正确的图片");
|
|
101
|
+ if ("1".equals(resps)) {
|
|
102
|
+ responseBean.addError("7772", "推送海康服务器失败");
|
|
103
|
+ }else {
|
|
104
|
+ responseBean.addError("7771","请录入正确的图片");
|
|
105
|
+ }
|
97
|
106
|
}
|
98
|
107
|
return responseBean;
|
99
|
108
|
}
|
100
|
|
- //家属或者租客
|
|
109
|
+ //家属或者租客,已认证
|
101
|
110
|
if (Constant.RELATION.equals(sysRole.getRoleName()) || Constant.TENANT.equals(sysRole.getDescription()) && "1".equals(taUser.getVerifyStatus())) {
|
102
|
111
|
ResponseBean responseBeans = new ResponseBean();
|
103
|
|
- boolean resps=checKout(faceImg,taFace,isA,null);
|
104
|
|
- if (resps==true) {
|
105
|
|
- imgPush(user.getUserName(),faceImg);
|
|
112
|
+ Object resps=checKout(faceImg,taFace,isA,null,user.getUserName(),uploadFile);
|
|
113
|
+ if (null!=resps && "true".equals(resps)) {
|
|
114
|
+ imgPush(user.getUserName(), uploadFile);
|
106
|
115
|
responseBeans.addSuccess("图片录入成功");
|
107
|
116
|
}else {
|
108
|
|
- responseBeans.addError("7771","请录入正确的图片");
|
|
117
|
+ if ("1".equals(resps)) {
|
|
118
|
+ responseBeans.addError("7772", "推送海康服务器失败");
|
|
119
|
+ }else {
|
|
120
|
+ responseBeans.addError("7771","请录入正确的图片");
|
|
121
|
+ }
|
109
|
122
|
}
|
110
|
123
|
return responseBeans;
|
111
|
124
|
}
|
112
|
125
|
} else {
|
113
|
|
- //为业主,已认证
|
|
126
|
+ //为业主,未认证情况下
|
114
|
127
|
if (Constant.OWNER.equals(sysRole.getRoleName()) && "1".equals(taUser.getVerifyStatus())) {
|
115
|
128
|
response.addError("8885", "您的信息已存在");
|
116
|
129
|
return response;
|
117
|
130
|
}
|
118
|
|
- //家属或者租客
|
|
131
|
+ //家属或者租客,未认证情况下
|
119
|
132
|
if (Constant.RELATION.equals(sysRole.getRoleName()) || Constant.TENANT.equals(sysRole.getDescription()) && "1".equals(taUser.getVerifyStatus())) {
|
120
|
133
|
response.addError("8885", "您的信息已存在");
|
121
|
134
|
return response;
|
|
@@ -123,11 +136,10 @@ public class FaceServicelimpl implements FaceServicel {
|
123
|
136
|
}
|
124
|
137
|
response.addError("9995", "无法确认您的身份,请联系物业");
|
125
|
138
|
return response;
|
126
|
|
-
|
127
|
|
-
|
128
|
139
|
}
|
129
|
140
|
|
130
|
141
|
@Override
|
|
142
|
+ @Transactional
|
131
|
143
|
public ResponseBean upDateFace(Integer userId,MultipartFile uploadFile) {
|
132
|
144
|
boolean isA=false;
|
133
|
145
|
String faceImg = null;
|
|
@@ -143,8 +155,8 @@ public class FaceServicelimpl implements FaceServicel {
|
143
|
155
|
taFace.setTaUserId(userId);
|
144
|
156
|
taFace.setUpdateUser(userId);
|
145
|
157
|
taFace.setUpdateDate(new Date());
|
146
|
|
- boolean ck=checKout(faceImg,taFace,isA,userId);
|
147
|
|
- if (ck == true) {
|
|
158
|
+ Object resps=checKout(faceImg,taFace,isA,userId,user.getUserName(),uploadFile);
|
|
159
|
+ if (null!=resps && "true".equals(resps)) {
|
148
|
160
|
responseBean.addSuccess("修改成功");
|
149
|
161
|
}else {
|
150
|
162
|
responseBean.addError("7771","请录入正确图片");
|
|
@@ -153,7 +165,8 @@ public class FaceServicelimpl implements FaceServicel {
|
153
|
165
|
}
|
154
|
166
|
|
155
|
167
|
//人脸录入验证
|
156
|
|
- public boolean checKout(String faceImg, TaFace taFace, boolean isA,Integer user) {
|
|
168
|
+ @Transactional
|
|
169
|
+ public Object checKout(String faceImg, TaFace taFace, boolean isA,Integer user,String name,MultipartFile uploadFile) {
|
157
|
170
|
AESDecode aesd = new AESDecode();
|
158
|
171
|
String body = "{\"type\": \"0\", \"image_url\":\"" + faceImg + "\"}";
|
159
|
172
|
try {
|
|
@@ -162,9 +175,18 @@ public class FaceServicelimpl implements FaceServicel {
|
162
|
175
|
Integer type = (Integer) jsonObject.get("errno");
|
163
|
176
|
Integer faceNum= (Integer) jsonObject.get("face_num");
|
164
|
177
|
if (0==type && null!=faceNum && 1==faceNum && isA==true) {
|
165
|
|
- taFace.setFaceImg(faceImg);
|
166
|
|
- taFaceMapper.insertSelective(taFace);
|
167
|
|
- return true;
|
|
178
|
+ //校验通过后
|
|
179
|
+ String errorCode= (String) imgPush(name, uploadFile);
|
|
180
|
+ JSONObject Code = JSONObject.parseObject(errorCode);
|
|
181
|
+ Integer personGroupId = (Integer) Code.get("personGroupId");
|
|
182
|
+ if (null!=personGroupId && personGroupId == 1) {
|
|
183
|
+ taFace.setFaceImg(faceImg);
|
|
184
|
+ taFaceMapper.insertSelective(taFace);
|
|
185
|
+ return true;
|
|
186
|
+ }else{
|
|
187
|
+ String code="1";
|
|
188
|
+ return code;
|
|
189
|
+ }
|
168
|
190
|
}else if (0==type && null!=faceNum && 1==faceNum && isA==false){
|
169
|
191
|
taFace.setFaceImg(faceImg);
|
170
|
192
|
taFaceMapper.updateByPrimaryKeySelective(taFace);
|
|
@@ -177,16 +199,35 @@ public class FaceServicelimpl implements FaceServicel {
|
177
|
199
|
return false;
|
178
|
200
|
}
|
179
|
201
|
//在图片验证通过的情况下,推送到海康
|
180
|
|
- public Object imgPush(String name,String img){
|
|
202
|
+ public Object imgPush(String name,MultipartFile uploadFile){
|
181
|
203
|
HKOpenApi hkOpenApi=new HKOpenApi();
|
182
|
|
- name = hkOpenApi.encodeImgageToBase64(img);
|
|
204
|
+ //把图片压缩成100K以下
|
|
205
|
+ // 压缩后的图片字节数组
|
|
206
|
+ byte [] picByte = null;
|
|
207
|
+ try {
|
|
208
|
+ long l = System.currentTimeMillis();
|
|
209
|
+ byte[] bytes = uploadFile.getBytes();
|
|
210
|
+ // 拿到转换后的图片字节
|
|
211
|
+ picByte= PicUtils.compressPicForScale(bytes,99L,"x");
|
|
212
|
+ } catch (IOException e) {
|
|
213
|
+ e.printStackTrace();
|
|
214
|
+ }
|
|
215
|
+ // String imgs = hkOpenApi.getImgStr(uploadFile);
|
|
216
|
+ String imgs = hkOpenApi.getImgStr(picByte);
|
|
217
|
+ String pgId= (String) HKpersonGroupId();
|
|
218
|
+ JSONObject jsonObject = JSONObject.parseObject(pgId);
|
|
219
|
+ Integer personGroupId = (Integer) jsonObject.get("personGroupId");
|
|
220
|
+ System.out.println(personGroupId);
|
183
|
221
|
String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.OP_IMG;
|
184
|
222
|
Map<String, Object> map = new HashMap<String, Object>();
|
185
|
223
|
map.put("appkey", HKConstant.APPKEY);//设置APPKEY
|
186
|
224
|
map.put("time", System.currentTimeMillis());//设置时间参数
|
187
|
|
- map.put("facePhotos", System.currentTimeMillis());//设置时间参数 //bs64转码
|
|
225
|
+ map.put("token", HKConstant.SECRET);//认证token
|
|
226
|
+ map.put("opUserUuid",HKConstant.OP_USER_UUID);//操作用户UUID
|
|
227
|
+ map.put("facePhotos", imgs); //bs64转码
|
188
|
228
|
map.put("personName",name);//名字
|
189
|
|
- map.put("personName",System.currentTimeMillis());//时间取毫秒
|
|
229
|
+ map.put("personGroupId",personGroupId);//分组用户ID
|
|
230
|
+ map.put("birthday",System.currentTimeMillis());//时间取毫秒
|
190
|
231
|
String params = JSON.toJSONString(map);
|
191
|
232
|
System.out.println(" ====== testGetDefaultUserUUID 请求参数:【" + params + "】");
|
192
|
233
|
String data = null;
|
|
@@ -199,5 +240,27 @@ public class FaceServicelimpl implements FaceServicel {
|
199
|
240
|
return data;
|
200
|
241
|
}
|
201
|
242
|
|
|
243
|
+ //把图片推送海康,需要获得海康人员分组下的
|
|
244
|
+ // **personGroupId**
|
|
245
|
+ @Transactional
|
|
246
|
+ public Object HKpersonGroupId(){
|
|
247
|
+ String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.OP_PERSON_ID;
|
|
248
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
249
|
+ map.put("appkey", HKConstant.APPKEY);//设置APPKEY
|
|
250
|
+ map.put("time", System.currentTimeMillis());//设置时间参数
|
|
251
|
+ map.put("token", HKConstant.SECRET);//认证token
|
|
252
|
+ map.put("opUserUuid",HKConstant.OP_USER_UUID);//操作用户UUID
|
|
253
|
+ map.put("pageNo",1);//当前页码
|
|
254
|
+ map.put("pageSize",100);//每页数据记录数
|
|
255
|
+ map.put("birthday",System.currentTimeMillis());//时间取毫秒
|
|
256
|
+ String params = JSON.toJSONString(map);
|
|
257
|
+ String data = null;
|
|
258
|
+ try {
|
|
259
|
+ data = HttpClientSSLUtils.doPost(url + "?token=" + Digests.buildToken(url + "?" + params, params, HKConstant.SECRET), params);
|
|
260
|
+ } catch (Exception e) {
|
|
261
|
+ e.printStackTrace();
|
|
262
|
+ }
|
|
263
|
+ return data;
|
|
264
|
+ }
|
202
|
265
|
|
203
|
266
|
}
|