Commit fd892de1c67e7d69f9d5baa2dfbdc1859d31b50b

Authored by 徐泉
1 parent 53310256
Exists in master

活体检测问题修复

cloud/dahua/src/main/java/com/example/dahua/MyTask.java
... ... @@ -15,6 +15,7 @@ import com.example.dahua.mqtt.MqttManager;
15 15 import com.example.dahua.service.AttendanceService;
16 16 import com.example.dahua.utils.DateUtils;
17 17 import com.example.dahua.utils.FileUtils;
  18 +import com.example.dahua.utils.JsonUtils;
18 19 import com.example.dahua.xiananDao.SearchMapper;
19 20 import com.example.dahua.xiananDao.SendRecordDao;
20 21 import com.sun.jna.Pointer;
... ... @@ -445,6 +446,7 @@ public class MyTask implements ApplicationRunner {
445 446 searchMapper.checkIn(checkIn);
446 447  
447 448 if (checkIn.getIsSuccess() == 1) {
  449 + log.info("考勤成功: checkIn: {}, 方向:{}",JsonUtils.nonDefaultMapper().toJson(checkIn),eventType == 1 ? "进门" : "出门");
448 450 //考勤成功
449 451 String content = "考勤成功!,设备:" + deviceId + "卡号:" + cardNo + "方向:" + (eventType == 1 ? "进门" : "出门") + "______" + eventTime;
450 452  
... ... @@ -538,7 +540,7 @@ public class MyTask implements ApplicationRunner {
538 540 if (null != placeId) {
539 541 //关联的显示看板设备
540 542 List<String> kanbanIds = userDao.getKanBanIdWithPlaceId(placeId);
541   -
  543 + log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds));
542 544 for (int i = 0; i < kanbanIds.size(); i++) {
543 545 String kanbanId = kanbanIds.get(i);
544 546 String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}";
... ... @@ -551,6 +553,7 @@ public class MyTask implements ApplicationRunner {
551 553 String schoolId = userDao.getSchoolIdWidthCardNum(cardNum);
552 554 if(StringUtils.isEmpty(schoolId)||Integer.parseInt(schoolId) <=0)return;
553 555 List<String> clintIds = userDao.getClintIds(schoolId);
  556 + log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(clintIds));
554 557 for (int i = 0; i < clintIds.size(); i++) {
555 558 String clintId = clintIds.get(i);
556 559 String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}";
... ...
cloud/dahua/src/main/java/com/example/dahua/control/UserControl.java
... ... @@ -256,7 +256,11 @@ public class UserControl {
256 256 public boolean checkFace(@RequestParam("url") String httpurl) {
257 257  
258 258 boolean check = BaiduUtils.getBaiduUtils().checkImg(httpurl);
259   -
  259 + //获取文件名
  260 + File file1 = new File(httpurl);
  261 + File target = new File("./huoti/");
  262 + //压缩后的文件
  263 + httpurl = target.getAbsolutePath() + "/"+ file1.getName();
260 264 if (check) {
261 265 File file = new File(httpurl);
262 266  
... ...
cloud/dahua/src/main/java/com/example/dahua/service/UserService.java
... ... @@ -62,5 +62,9 @@ public interface UserService {
62 62 */
63 63 String getUserId(String code,String schoolId);
64 64  
65   -
  65 + /**
  66 + * 测试用
  67 + * @param url
  68 + */
  69 + void test(String url);
66 70 }
... ...
cloud/dahua/src/main/java/com/example/dahua/service/imp/UserServiceImp.java
... ... @@ -8,12 +8,15 @@ import com.example.dahua.enums.EnumDeviceType;
8 8 import com.example.dahua.lib.NetSDKLib;
9 9 import com.example.dahua.module.GateModule;
10 10 import com.example.dahua.service.UserService;
  11 +import com.example.dahua.utils.BaiduUtils;
  12 +import com.example.dahua.utils.FileUtils;
11 13 import lombok.extern.slf4j.Slf4j;
12 14 import org.apache.commons.lang.StringUtils;
13 15 import org.springframework.beans.factory.annotation.Autowired;
14 16 import org.springframework.stereotype.Repository;
15 17 import org.springframework.stereotype.Service;
16 18  
  19 +import java.io.File;
17 20 import java.util.List;
18 21  
19 22 @Repository
... ... @@ -154,5 +157,33 @@ public class UserServiceImp implements UserService {
154 157 return userId;
155 158 }
156 159  
  160 + @Override
  161 + public void test(String httpurl) {
  162 + log.info("在线活体检测, 文件地址:"+httpurl);
  163 + boolean check = BaiduUtils.getBaiduUtils().checkImg(httpurl);
  164 + File file1 = new File(httpurl);
  165 +
  166 + File target = new File("./huoti/");
  167 + httpurl = target.getAbsolutePath() + "/"+ file1.getName();
  168 +
  169 + if (check) {
  170 + File file = new File(httpurl);
  171 +
  172 + String userCode = file.getName().split("\\.")[0];
  173 +
  174 + String schoolId = "864";
157 175  
  176 + if (httpurl.contains("Student") && !httpurl.startsWith("http")) {
  177 + schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Student"));
  178 + } else if (httpurl.contains("Teacher") && !httpurl.startsWith("http")) {
  179 + schoolId = httpurl.substring(httpurl.indexOf("School") + 6, httpurl.indexOf("\\Teacher"));
  180 + }
  181 + System.out.println("choolId:" + schoolId + "userCode:" + userCode);
  182 + if (!org.springframework.util.StringUtils.isEmpty(schoolId) && !org.springframework.util.StringUtils.isEmpty(userCode)) {
  183 + String userId = getUserId(userCode, schoolId);
  184 + BaiduUtils.getBaiduUtils().addFace(new File(httpurl), schoolId, userId, userId);
  185 + FileUtils.getInstance().writeLogs("人脸添加成功:" + userId, "人脸添加成功.txt");
  186 + }
  187 + }
  188 + }
158 189 }
... ...
cloud/dahua/src/main/java/com/example/dahua/utils/BaiduUtils.java
... ... @@ -3,6 +3,7 @@ package com.example.dahua.utils;
3 3 import com.alibaba.fastjson.JSON;
4 4 import com.example.dahua.async.ImageUtils;
5 5 import com.example.dahua.lib.CompressPic;
  6 +import lombok.extern.slf4j.Slf4j;
6 7 import org.json.JSONArray;
7 8 import org.json.JSONObject;
8 9  
... ... @@ -12,6 +13,7 @@ import java.net.HttpURLConnection;
12 13 import java.net.URL;
13 14 import java.util.*;
14 15  
  16 +@Slf4j
15 17 public class BaiduUtils {
16 18  
17 19 private static BaiduUtils baiduUtils;
... ... @@ -53,8 +55,12 @@ public class BaiduUtils {
53 55 String param = GsonUtils.toJson(list);
54 56 // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。
55 57 String accessToken = getAuth();
56   -
57   - String result1 = HttpUtil.post(url, accessToken, "application/json", param);
  58 + String result1 ="";
  59 + try{
  60 + result1 = HttpUtil.post(url, accessToken, "application/json", param);
  61 + }catch (IOException e){
  62 + log.error("活体检测异常,错误信息:{}",e);
  63 + }
58 64 JSONObject jsonObject = new JSONObject(result1);
59 65 String error_msg = jsonObject.optString("error_msg");
60 66 JSONObject result = jsonObject.optJSONObject("result");
... ... @@ -227,7 +233,6 @@ public class BaiduUtils {
227 233  
228 234 String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add";
229 235  
230   -
231 236 try {
232 237 Map<String, Object> map = new HashMap<>();
233 238 map.put("image", Base64Util.encode(InputStream2ByteArray(img.getAbsolutePath())));
... ... @@ -260,6 +265,7 @@ public class BaiduUtils {
260 265 // facerecordService.addFacerecord(facerecordBean);
261 266 return "注册成功";
262 267 } else {
  268 + log.info("注册人脸失败,文件大小,size: "+ img.length());
263 269 return error_msg;
264 270 }
265 271  
... ...
cloud/dahua/src/test/java/com/example/dahua/mapper/SearchMapperTest.java
... ... @@ -13,12 +13,15 @@ import com.example.dahua.dao.UserDao;
13 13 import com.example.dahua.mqtt.MqttManager;
14 14 import com.example.dahua.service.PermissFaceService;
15 15 import com.example.dahua.service.UserService;
  16 +import com.example.dahua.utils.BaiduUtils;
16 17 import com.example.dahua.utils.DateUtils;
  18 +import com.example.dahua.utils.HttpUtil;
17 19 import com.example.dahua.utils.JsonUtils;
18 20 import com.example.dahua.xiananDao.SearchMapper;
19 21 import org.junit.Test;
20 22 import org.springframework.beans.factory.annotation.Autowired;
21 23  
  24 +import java.io.File;
22 25 import java.util.Date;
23 26  
24 27 /**
... ... @@ -118,7 +121,12 @@ public class SearchMapperTest extends Tester {
118 121 System.out.println("发送成功");
119 122 }
120 123  
  124 + @Test
  125 + public void test6() {
  126 +// String path = "D://dahua-logs/sxzx2020889.png";
  127 + String path = "D://dahua-logs/sxzx2020002.png";
  128 + userService.test(path);
  129 + }
121 130  
122 131  
123   -// boolean uploadImgAndUserInfo(String file, String schoolId, String studentCode, String clint_type, int userType, String devid);
124 132 }
... ...