傅行帆 6 years ago
parent
commit
bab62d988e

+ 10
- 9
CODE/smart-community/app-api/src/main/java/com/community/huiju/common/PicUtils.java View File

@@ -18,14 +18,6 @@ public class PicUtils {
18 18
 
19 19
     private static Logger logger = LoggerFactory.getLogger(PicUtils.class);
20 20
 
21
-   /*public static void main(String[] args) throws IOException {
22
-        byte[] bytes = FileUtils.readFileToByteArray(new File("C:\\Users\\DELL\\Pictures\\timg.jpg"));
23
-      long l = System.currentTimeMillis();
24
-       bytes = PicUtils.compressPicForScale(bytes, 20, "x");// 图片小于300kb
25
-        System.out.println(System.currentTimeMillis() - l);
26
-        FileUtils.writeByteArrayToFile(new File("C:\\Users\\DELL\\Pictures\\timg.jpg"), bytes);
27
-   }*/
28
-
29 21
     /**
30 22
      * 根据指定大小压缩图片
31 23
      *
@@ -77,5 +69,14 @@ public class PicUtils {
77 69
         }
78 70
         return accuracy;
79 71
     }
80
-
72
+    
73
+    /**
74
+     * 将本地图片进行Base64位编码
75
+     * @param fileBytes
76
+     * @return
77
+     */
78
+    public static String getImgStr(byte [] fileBytes) {
79
+        return new String(org.apache.commons.codec.binary.Base64.encodeBase64(fileBytes));
80
+    }
81
+    
81 82
 }

+ 1
- 104
CODE/smart-community/app-api/src/main/java/com/community/huiju/common/hk/HKOpenApi.java View File

@@ -43,48 +43,6 @@ public class HKOpenApi {
43 43
         return data;
44 44
     }
45 45
 
46
-    /**
47
-     *
48
-     * @param img_path 获取图片的扩展名
49
-     * @return
50
-     */
51
-    public static String getPicSuffix(String img_path){
52
-        if (img_path == null || img_path.indexOf(".") == -1){
53
-            //如果图片地址为null或者地址中没有"."就返回""
54
-            return "";
55
-        }
56
-        return img_path.substring(img_path.lastIndexOf(".") + 1).
57
-                trim().toLowerCase();
58
-    }
59
-    
60
-    /**
61
-     * 将本地图片进行Base64位编码
62
-     */
63
-    public static String getImgStr(MultipartFile imgFile){
64
-        //将图片文件转化为字节数组字符串,并对其进行Base64编码处理
65
-        byte[] data = null;
66
-        //读取图片字节数组
67
-        try
68
-        {
69
-            data = imgFile.getBytes();
70
-        }
71
-        catch (IOException e)
72
-        {
73
-            e.printStackTrace();
74
-        }
75
-        return new String(org.apache.commons.codec.binary.Base64.encodeBase64(data));
76
-    }
77
-    
78
-    /**
79
-     * 将本地图片进行Base64位编码
80
-     * @param fileBytes
81
-     * @return
82
-     */
83
-    public static String getImgStr(byte [] fileBytes) {
84
-        return new String(org.apache.commons.codec.binary.Base64.encodeBase64(fileBytes));
85
-    }
86
-
87
-
88 46
     /**
89 47
      * 根据部门名称分页获取部门
90 48
      *      第几页, 一页多少行, 操作用户uuid
@@ -115,60 +73,7 @@ public class HKOpenApi {
115 73
 
116 74
         return data;
117 75
     }
118
-
119
-
120
-    /**
121
-     * 根据指定大小压缩图片
122
-     *
123
-     * @param imageBytes  源图片字节数组
124
-     * @param desFileSize 指定图片大小,单位kb
125
-     * @param imageId     影像编号
126
-     * @return 压缩质量后的图片字节数组
127
-     */
128
-    public static byte[] compressPicForScale(byte[] imageBytes, long desFileSize, String imageId) {
129
-        if (imageBytes == null || imageBytes.length <= 0 || imageBytes.length < desFileSize * 1024) {
130
-            return imageBytes;
131
-        }
132
-        long srcSize = imageBytes.length;
133
-        double accuracy = getAccuracy(srcSize / 1024);
134
-        try {
135
-            while (imageBytes.length > desFileSize * 1024) {
136
-                ByteArrayInputStream inputStream = new ByteArrayInputStream(imageBytes);
137
-                ByteArrayOutputStream outputStream = new ByteArrayOutputStream(imageBytes.length);
138
-                Thumbnails.of(inputStream)
139
-                        .scale(accuracy)
140
-                        .outputQuality(accuracy)
141
-                        .toOutputStream(outputStream);
142
-                imageBytes = outputStream.toByteArray();
143
-            }
144
-            log.info("【图片压缩】imageId={} | 图片原大小={}kb | 压缩后大小={}kb",
145
-                    imageId, srcSize / 1024, imageBytes.length / 1024);
146
-        } catch (Exception e) {
147
-            log.error("【图片压缩】msg=图片压缩失败!", e);
148
-        }
149
-        return imageBytes;
150
-    }
151
-
152
-    /**
153
-     * 自动调节精度(经验数值)
154
-     *
155
-     * @param size 源图片大小
156
-     * @return 图片压缩质量比
157
-     */
158
-    private static double getAccuracy(long size) {
159
-        double accuracy;
160
-        if (size < 900) {
161
-            accuracy = 0.85;
162
-        } else if (size < 2047) {
163
-            accuracy = 0.6;
164
-        } else if (size < 3275) {
165
-            accuracy = 0.44;
166
-        } else {
167
-            accuracy = 0.4;
168
-        }
169
-        return accuracy;
170
-    }
171
-
76
+    
172 77
     /**
173 78
      *
174 79
      * 添加人员
@@ -433,14 +338,6 @@ public class HKOpenApi {
433 338
         return data;
434 339
     }
435 340
 
436
-
437 341
     public static void main(String[] args) {
438
-        Map<String,Object> parMap = Maps.newHashMap();
439
-        parMap.put("pageNo",1);
440
-        parMap.put("pageSize",100);
441
-        parMap.put("opUserUuid",HKConstant.OP_USER_UUID);
442
-        parMap.put("deptName","住户");
443
-        String result = HKOpenApi.getDeptName(parMap);
444
-        System.out.println(result);
445 342
     }
446 343
 }

+ 4
- 7
CODE/smart-community/app-api/src/main/java/com/community/huiju/controller/FaceController.java View File

@@ -1,18 +1,14 @@
1 1
 package com.community.huiju.controller;
2
+
2 3
 import com.community.commom.constant.Constant;
3 4
 import com.community.commom.mode.ResponseBean;
4 5
 import com.community.commom.session.UserElement;
5
-import com.community.huiju.model.TaAgreement;
6
-import com.community.huiju.model.TaFace;
7
-import com.community.huiju.service.FaceServicel;
8
-import com.community.huiju.service.FaceServicel;
6
+import com.community.huiju.service.FaceServiceI;
9 7
 import io.swagger.annotations.*;
10
-import org.apache.commons.lang3.StringUtils;
11 8
 import org.springframework.beans.factory.annotation.Autowired;
12 9
 import org.springframework.cloud.context.config.annotation.RefreshScope;
13 10
 import org.springframework.web.bind.annotation.RequestMapping;
14 11
 import org.springframework.web.bind.annotation.RequestMethod;
15
-import org.springframework.web.bind.annotation.RequestParam;
16 12
 import org.springframework.web.bind.annotation.RestController;
17 13
 import org.springframework.web.multipart.MultipartFile;
18 14
 
@@ -24,12 +20,13 @@ import javax.servlet.http.HttpSession;
24 20
 @Api(value = "人脸相关API", description = "人脸相关API")
25 21
 public class FaceController {
26 22
     @Autowired
27
-    private FaceServicel faceServicel;
23
+    private FaceServiceI faceServicel;
28 24
 
29 25
     @ApiOperation(value = "添加人脸图片", notes = "添加人脸图片")
30 26
     @ApiImplicitParams({
31 27
             @ApiImplicitParam(paramType = "header",dataType = "String",name = "X-Auth-Token",value = "Token")
32 28
     })
29
+    
33 30
     @RequestMapping(value = "/addFace",method = RequestMethod.POST)
34 31
     public Object getTaFace(HttpSession session,
35 32
                             @ApiParam(value = "file" ,required = true) MultipartFile uploadFile){

CODE/smart-community/app-api/src/main/java/com/community/huiju/service/FaceServicel.java → CODE/smart-community/app-api/src/main/java/com/community/huiju/service/FaceServiceI.java View File

@@ -4,7 +4,7 @@ package com.community.huiju.service;
4 4
 import com.community.commom.mode.ResponseBean;
5 5
 import org.springframework.web.multipart.MultipartFile;
6 6
 
7
-public interface FaceServicel {
7
+public interface FaceServiceI {
8 8
     /**
9 9
      * 添加人脸
10 10
      * @param userId

+ 40
- 46
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/FaceServicelimpl.java View File

@@ -7,15 +7,14 @@ import com.community.commom.constant.Constant;
7 7
 import com.community.commom.mode.ResponseBean;
8 8
 import com.community.huiju.common.PicUtils;
9 9
 import com.community.huiju.common.hk.HKConstant;
10
-import com.community.huiju.common.hk.HKOpenApi;
11 10
 import com.community.huiju.dao.TaFaceMapper;
12 11
 import com.community.huiju.dao.TaSysRoleMapper;
13 12
 import com.community.huiju.dao.TaUserMapper;
14 13
 import com.community.huiju.model.TaFace;
15 14
 import com.community.huiju.model.TaSysRole;
16 15
 import com.community.huiju.model.TaUser;
16
+import com.community.huiju.service.FaceServiceI;
17 17
 import com.community.huiju.service.ImageServiceI;
18
-import com.community.huiju.service.FaceServicel;
19 18
 import com.hikvision.cms.api.common.util.Digests;
20 19
 import com.hikvision.cms.api.common.util.HttpClientSSLUtils;
21 20
 import org.springframework.beans.factory.annotation.Autowired;
@@ -28,8 +27,9 @@ import java.util.Date;
28 27
 import java.util.HashMap;
29 28
 import java.util.Map;
30 29
 
31
-@Service
32
-public class FaceServicelimpl implements FaceServicel {
30
+@Service("faceServicel")
31
+@Transactional
32
+public class FaceServicelimpl implements FaceServiceI {
33 33
 
34 34
 
35 35
     @Autowired
@@ -45,7 +45,6 @@ public class FaceServicelimpl implements FaceServicel {
45 45
     private ImageServiceI imageServiceI;
46 46
 
47 47
     @Override
48
-    @Transactional
49 48
     public ResponseBean addFace(Integer userid,MultipartFile uploadFile) {
50 49
         String faceImg = null;
51 50
         try {
@@ -85,7 +84,7 @@ public class FaceServicelimpl implements FaceServicel {
85 84
 
86 85
         //查询当前用户是否有人脸记录
87 86
         TaFace User = taFaceMapper.getByUserId(userid);
88
-        if (null == User) {   //为业主,已认证
87
+        if (null == User) {
89 88
             boolean isA=true;
90 89
             if (Constant.OWNER.equals(sysRole.getRoleName()) && "1".equals(taUser.getVerifyStatus())) {
91 90
                 ResponseBean responseBean = new ResponseBean();
@@ -117,24 +116,11 @@ public class FaceServicelimpl implements FaceServicel {
117 116
                 }
118 117
                 return responseBeans;
119 118
             }
120
-        } else {
121
-            //为业主,未认证情况下
122
-            if (Constant.OWNER.equals(sysRole.getRoleName()) && "1".equals(taUser.getVerifyStatus())) {
123
-                response.addError("8885", "您的信息已存在");
124
-                return response;
125
-            }
126
-            //家属或者租客,未认证情况下
127
-            if (Constant.RELATION.equals(sysRole.getRoleName()) || Constant.TENANT.equals(sysRole.getDescription()) && "1".equals(taUser.getVerifyStatus())) {
128
-                response.addError("8885", "您的信息已存在");
129
-                return response;
130
-            }
131 119
         }
132
-        response.addError("9995", "无法确认您的身份,请联系物业");
133 120
         return response;
134 121
     }
135 122
 
136 123
     @Override
137
-    @Transactional
138 124
     public ResponseBean upDateFace(Integer userId,MultipartFile uploadFile) {
139 125
         boolean isA=false;
140 126
         String faceImg = null;
@@ -162,14 +148,15 @@ public class FaceServicelimpl implements FaceServicel {
162 148
         }
163 149
         return responseBean;
164 150
     }
165
-
166
-    //人脸录入验证
167
-    @Transactional
151
+    
152
+    /**
153
+     * 人脸录入验证
154
+     */
168 155
     public Object checKout(String faceImg, TaFace taFace, boolean isA,Integer user,String name,MultipartFile uploadFile) {
169 156
         AESDecode aesd = new AESDecode();
170
-                String body = "{\"type\": \"0\", \"image_url\":\"" + faceImg + "\"}";
157
+        String body = "{\"type\": \"0\", \"image_url\":\"" + faceImg + "\"}";
171 158
         try {
172
-             ResponseBean responseBean = aesd.send(body);
159
+            ResponseBean responseBean = aesd.send(body);
173 160
             JSONObject jsonObject = JSONObject.parseObject(responseBean.getMessage());
174 161
             Integer type = (Integer) jsonObject.get("errno");
175 162
             Integer faceNum= (Integer) jsonObject.get("face_num");
@@ -198,7 +185,13 @@ public class FaceServicelimpl implements FaceServicel {
198 185
         }
199 186
         return false;
200 187
     }
201
-    //在图片验证通过的情况下,推送到海康
188
+    
189
+    /**
190
+     * 在图片验证通过的情况下,推送到海康
191
+     * @param name
192
+     * @param uploadFile
193
+     * @return
194
+     */
202 195
     public Object imgPush(String name,MultipartFile uploadFile){
203 196
         //把图片压缩成100K以下
204 197
         // 压缩后的图片字节数组
@@ -211,22 +204,22 @@ public class FaceServicelimpl implements FaceServicel {
211 204
         } catch (IOException e) {
212 205
             e.printStackTrace();
213 206
         }
214
-        // String imgs = hkOpenApi.getImgStr(uploadFile);
215
-        String imgs = HKOpenApi.getImgStr(picByte);
207
+        // 推送海康服务器
208
+        String imgs = PicUtils.getImgStr(picByte);
216 209
         String pgId= (String) HKpersonGroupId();
217 210
         JSONObject jsonObject = JSONObject.parseObject(pgId);
218 211
         Integer personGroupId = (Integer) jsonObject.get("personGroupId");
219 212
         System.out.println(personGroupId);
220 213
         String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.OP_IMG;
221 214
         Map<String, Object> map = new HashMap<String, Object>();
222
-        map.put("appkey", HKConstant.APPKEY);//设置APPKEY
223
-        map.put("time", System.currentTimeMillis());//设置时间参数
224
-        map.put("token", HKConstant.SECRET);//认证token
225
-        map.put("opUserUuid",HKConstant.OP_USER_UUID);//操作用户UUID
226
-        map.put("facePhotos", imgs); //bs64转码
227
-        map.put("personName",name);//名字
228
-        map.put("personGroupId",personGroupId);//分组用户ID
229
-        map.put("birthday",System.currentTimeMillis());//时间取毫秒
215
+        map.put("appkey", HKConstant.APPKEY);
216
+        map.put("time", System.currentTimeMillis());
217
+        map.put("token", HKConstant.SECRET);
218
+        map.put("opUserUuid",HKConstant.OP_USER_UUID);
219
+        map.put("facePhotos", imgs);
220
+        map.put("personName",name);
221
+        map.put("personGroupId",personGroupId);
222
+        map.put("birthday",System.currentTimeMillis());
230 223
         String params =  JSON.toJSONString(map);
231 224
         System.out.println(" ====== testGetDefaultUserUUID 请求参数:【" + params + "】");
232 225
         String data = null;
@@ -239,20 +232,21 @@ public class FaceServicelimpl implements FaceServicel {
239 232
         System.out.println(" ====== testGetDefaultUserUUID 请求返回结果:【{" + data + "}】");
240 233
         return data;
241 234
     }
242
-
243
-    //把图片推送海康,需要获得海康人员分组下的
244
-    // **personGroupId**
245
-    @Transactional
235
+    
236
+    /**
237
+     * 把图片推送海康,需要获得海康人员分组下的
238
+     * @return
239
+     */
246 240
     public Object HKpersonGroupId(){
247 241
         String url = HKConstant.OPENAPI_IP_PORT_HTTP + HKConstant.OP_PERSON_ID;
248 242
         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());//时间取毫秒
243
+        map.put("appkey", HKConstant.APPKEY);
244
+        map.put("time", System.currentTimeMillis());
245
+        map.put("token", HKConstant.SECRET);
246
+        map.put("opUserUuid",HKConstant.OP_USER_UUID);
247
+        map.put("pageNo",1);
248
+        map.put("pageSize",100);
249
+        map.put("birthday",System.currentTimeMillis());
256 250
         String params =  JSON.toJSONString(map);
257 251
         String data = null;
258 252
         try {

+ 1
- 0
CODE/smart-community/app-api/src/main/java/com/community/huiju/service/impl/MonitoringServiceImpl.java View File

@@ -2,6 +2,7 @@ package com.community.huiju.service.impl;
2 2
 import com.alibaba.fastjson.JSONObject;
3 3
 import com.community.commom.mode.ResponseBean;
4 4
 import com.community.huiju.common.hk.HKConstant;
5
+import com.community.huiju.common.hk.HKOpenApi;
5 6
 import com.community.huiju.service.IMonitoringService;
6 7
 import com.google.common.collect.Maps;
7 8
 import lombok.extern.slf4j.Slf4j;