Commit fd892de1c67e7d69f9d5baa2dfbdc1859d31b50b
1 parent
53310256
Exists in
master
活体检测问题修复
Showing
6 changed files
with
63 additions
and
7 deletions
Show diff stats
cloud/dahua/src/main/java/com/example/dahua/MyTask.java
| @@ -15,6 +15,7 @@ import com.example.dahua.mqtt.MqttManager; | @@ -15,6 +15,7 @@ import com.example.dahua.mqtt.MqttManager; | ||
| 15 | import com.example.dahua.service.AttendanceService; | 15 | import com.example.dahua.service.AttendanceService; |
| 16 | import com.example.dahua.utils.DateUtils; | 16 | import com.example.dahua.utils.DateUtils; |
| 17 | import com.example.dahua.utils.FileUtils; | 17 | import com.example.dahua.utils.FileUtils; |
| 18 | +import com.example.dahua.utils.JsonUtils; | ||
| 18 | import com.example.dahua.xiananDao.SearchMapper; | 19 | import com.example.dahua.xiananDao.SearchMapper; |
| 19 | import com.example.dahua.xiananDao.SendRecordDao; | 20 | import com.example.dahua.xiananDao.SendRecordDao; |
| 20 | import com.sun.jna.Pointer; | 21 | import com.sun.jna.Pointer; |
| @@ -445,6 +446,7 @@ public class MyTask implements ApplicationRunner { | @@ -445,6 +446,7 @@ public class MyTask implements ApplicationRunner { | ||
| 445 | searchMapper.checkIn(checkIn); | 446 | searchMapper.checkIn(checkIn); |
| 446 | 447 | ||
| 447 | if (checkIn.getIsSuccess() == 1) { | 448 | if (checkIn.getIsSuccess() == 1) { |
| 449 | + log.info("考勤成功: checkIn: {}, 方向:{}",JsonUtils.nonDefaultMapper().toJson(checkIn),eventType == 1 ? "进门" : "出门"); | ||
| 448 | //考勤成功 | 450 | //考勤成功 |
| 449 | String content = "考勤成功!,设备:" + deviceId + "卡号:" + cardNo + "方向:" + (eventType == 1 ? "进门" : "出门") + "______" + eventTime; | 451 | String content = "考勤成功!,设备:" + deviceId + "卡号:" + cardNo + "方向:" + (eventType == 1 ? "进门" : "出门") + "______" + eventTime; |
| 450 | 452 | ||
| @@ -538,7 +540,7 @@ public class MyTask implements ApplicationRunner { | @@ -538,7 +540,7 @@ public class MyTask implements ApplicationRunner { | ||
| 538 | if (null != placeId) { | 540 | if (null != placeId) { |
| 539 | //关联的显示看板设备 | 541 | //关联的显示看板设备 |
| 540 | List<String> kanbanIds = userDao.getKanBanIdWithPlaceId(placeId); | 542 | List<String> kanbanIds = userDao.getKanBanIdWithPlaceId(placeId); |
| 541 | - | 543 | + log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(kanbanIds)); |
| 542 | for (int i = 0; i < kanbanIds.size(); i++) { | 544 | for (int i = 0; i < kanbanIds.size(); i++) { |
| 543 | String kanbanId = kanbanIds.get(i); | 545 | String kanbanId = kanbanIds.get(i); |
| 544 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; | 546 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + kanbanId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; |
| @@ -551,6 +553,7 @@ public class MyTask implements ApplicationRunner { | @@ -551,6 +553,7 @@ public class MyTask implements ApplicationRunner { | ||
| 551 | String schoolId = userDao.getSchoolIdWidthCardNum(cardNum); | 553 | String schoolId = userDao.getSchoolIdWidthCardNum(cardNum); |
| 552 | if(StringUtils.isEmpty(schoolId)||Integer.parseInt(schoolId) <=0)return; | 554 | if(StringUtils.isEmpty(schoolId)||Integer.parseInt(schoolId) <=0)return; |
| 553 | List<String> clintIds = userDao.getClintIds(schoolId); | 555 | List<String> clintIds = userDao.getClintIds(schoolId); |
| 556 | + log.info("设备ID集: "+ JsonUtils.nonDefaultMapper().toJson(clintIds)); | ||
| 554 | for (int i = 0; i < clintIds.size(); i++) { | 557 | for (int i = 0; i < clintIds.size(); i++) { |
| 555 | String clintId = clintIds.get(i); | 558 | String clintId = clintIds.get(i); |
| 556 | String data = "{\"cmd\":\"" + 34 + "\",\"clientId\":\"" + clintId + "\",\"data\":{\"cardNum\":\"" + cardNum + "\",\"inOrOut\":\"" + inOrOut + "\"}}"; | 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,7 +256,11 @@ public class UserControl { | ||
| 256 | public boolean checkFace(@RequestParam("url") String httpurl) { | 256 | public boolean checkFace(@RequestParam("url") String httpurl) { |
| 257 | 257 | ||
| 258 | boolean check = BaiduUtils.getBaiduUtils().checkImg(httpurl); | 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 | if (check) { | 264 | if (check) { |
| 261 | File file = new File(httpurl); | 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,5 +62,9 @@ public interface UserService { | ||
| 62 | */ | 62 | */ |
| 63 | String getUserId(String code,String schoolId); | 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,12 +8,15 @@ import com.example.dahua.enums.EnumDeviceType; | ||
| 8 | import com.example.dahua.lib.NetSDKLib; | 8 | import com.example.dahua.lib.NetSDKLib; |
| 9 | import com.example.dahua.module.GateModule; | 9 | import com.example.dahua.module.GateModule; |
| 10 | import com.example.dahua.service.UserService; | 10 | import com.example.dahua.service.UserService; |
| 11 | +import com.example.dahua.utils.BaiduUtils; | ||
| 12 | +import com.example.dahua.utils.FileUtils; | ||
| 11 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 12 | import org.apache.commons.lang.StringUtils; | 14 | import org.apache.commons.lang.StringUtils; |
| 13 | import org.springframework.beans.factory.annotation.Autowired; | 15 | import org.springframework.beans.factory.annotation.Autowired; |
| 14 | import org.springframework.stereotype.Repository; | 16 | import org.springframework.stereotype.Repository; |
| 15 | import org.springframework.stereotype.Service; | 17 | import org.springframework.stereotype.Service; |
| 16 | 18 | ||
| 19 | +import java.io.File; | ||
| 17 | import java.util.List; | 20 | import java.util.List; |
| 18 | 21 | ||
| 19 | @Repository | 22 | @Repository |
| @@ -154,5 +157,33 @@ public class UserServiceImp implements UserService { | @@ -154,5 +157,33 @@ public class UserServiceImp implements UserService { | ||
| 154 | return userId; | 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,6 +3,7 @@ package com.example.dahua.utils; | ||
| 3 | import com.alibaba.fastjson.JSON; | 3 | import com.alibaba.fastjson.JSON; |
| 4 | import com.example.dahua.async.ImageUtils; | 4 | import com.example.dahua.async.ImageUtils; |
| 5 | import com.example.dahua.lib.CompressPic; | 5 | import com.example.dahua.lib.CompressPic; |
| 6 | +import lombok.extern.slf4j.Slf4j; | ||
| 6 | import org.json.JSONArray; | 7 | import org.json.JSONArray; |
| 7 | import org.json.JSONObject; | 8 | import org.json.JSONObject; |
| 8 | 9 | ||
| @@ -12,6 +13,7 @@ import java.net.HttpURLConnection; | @@ -12,6 +13,7 @@ import java.net.HttpURLConnection; | ||
| 12 | import java.net.URL; | 13 | import java.net.URL; |
| 13 | import java.util.*; | 14 | import java.util.*; |
| 14 | 15 | ||
| 16 | +@Slf4j | ||
| 15 | public class BaiduUtils { | 17 | public class BaiduUtils { |
| 16 | 18 | ||
| 17 | private static BaiduUtils baiduUtils; | 19 | private static BaiduUtils baiduUtils; |
| @@ -53,8 +55,12 @@ public class BaiduUtils { | @@ -53,8 +55,12 @@ public class BaiduUtils { | ||
| 53 | String param = GsonUtils.toJson(list); | 55 | String param = GsonUtils.toJson(list); |
| 54 | // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 | 56 | // 注意这里仅为了简化编码每一次请求都去获取access_token,线上环境access_token有过期时间, 客户端可自行缓存,过期后重新获取。 |
| 55 | String accessToken = getAuth(); | 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 | JSONObject jsonObject = new JSONObject(result1); | 64 | JSONObject jsonObject = new JSONObject(result1); |
| 59 | String error_msg = jsonObject.optString("error_msg"); | 65 | String error_msg = jsonObject.optString("error_msg"); |
| 60 | JSONObject result = jsonObject.optJSONObject("result"); | 66 | JSONObject result = jsonObject.optJSONObject("result"); |
| @@ -227,7 +233,6 @@ public class BaiduUtils { | @@ -227,7 +233,6 @@ public class BaiduUtils { | ||
| 227 | 233 | ||
| 228 | String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add"; | 234 | String url = "https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add"; |
| 229 | 235 | ||
| 230 | - | ||
| 231 | try { | 236 | try { |
| 232 | Map<String, Object> map = new HashMap<>(); | 237 | Map<String, Object> map = new HashMap<>(); |
| 233 | map.put("image", Base64Util.encode(InputStream2ByteArray(img.getAbsolutePath()))); | 238 | map.put("image", Base64Util.encode(InputStream2ByteArray(img.getAbsolutePath()))); |
| @@ -260,6 +265,7 @@ public class BaiduUtils { | @@ -260,6 +265,7 @@ public class BaiduUtils { | ||
| 260 | // facerecordService.addFacerecord(facerecordBean); | 265 | // facerecordService.addFacerecord(facerecordBean); |
| 261 | return "注册成功"; | 266 | return "注册成功"; |
| 262 | } else { | 267 | } else { |
| 268 | + log.info("注册人脸失败,文件大小,size: "+ img.length()); | ||
| 263 | return error_msg; | 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,12 +13,15 @@ import com.example.dahua.dao.UserDao; | ||
| 13 | import com.example.dahua.mqtt.MqttManager; | 13 | import com.example.dahua.mqtt.MqttManager; |
| 14 | import com.example.dahua.service.PermissFaceService; | 14 | import com.example.dahua.service.PermissFaceService; |
| 15 | import com.example.dahua.service.UserService; | 15 | import com.example.dahua.service.UserService; |
| 16 | +import com.example.dahua.utils.BaiduUtils; | ||
| 16 | import com.example.dahua.utils.DateUtils; | 17 | import com.example.dahua.utils.DateUtils; |
| 18 | +import com.example.dahua.utils.HttpUtil; | ||
| 17 | import com.example.dahua.utils.JsonUtils; | 19 | import com.example.dahua.utils.JsonUtils; |
| 18 | import com.example.dahua.xiananDao.SearchMapper; | 20 | import com.example.dahua.xiananDao.SearchMapper; |
| 19 | import org.junit.Test; | 21 | import org.junit.Test; |
| 20 | import org.springframework.beans.factory.annotation.Autowired; | 22 | import org.springframework.beans.factory.annotation.Autowired; |
| 21 | 23 | ||
| 24 | +import java.io.File; | ||
| 22 | import java.util.Date; | 25 | import java.util.Date; |
| 23 | 26 | ||
| 24 | /** | 27 | /** |
| @@ -118,7 +121,12 @@ public class SearchMapperTest extends Tester { | @@ -118,7 +121,12 @@ public class SearchMapperTest extends Tester { | ||
| 118 | System.out.println("发送成功"); | 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 | } |