|
@@ -47,31 +47,36 @@ public class IdentifyServiceImpl implements IdentifyService {
|
|
|
public HttpResult<Map<String, Object>> idCard(MultipartFile image1, MultipartFile image2) throws IOException {
|
|
public HttpResult<Map<String, Object>> idCard(MultipartFile image1, MultipartFile image2) throws IOException {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
CustomerInfoVO customerInfoVO = new CustomerInfoVO();
|
|
CustomerInfoVO customerInfoVO = new CustomerInfoVO();
|
|
|
- String s1MD5 = DigestUtils.md5Hex(image1.getBytes());
|
|
|
|
|
- String s1 = byteToBase64(image1);
|
|
|
|
|
- String s1Key = IMAGE_IDENTIFY_KEY + "idCard:" + "front:" + s1MD5;
|
|
|
|
|
- if (StringUtils.isNotBlank(s1) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s1Key))) {
|
|
|
|
|
- //走缓存
|
|
|
|
|
- BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s1Key)), customerInfoVO);
|
|
|
|
|
- } else {
|
|
|
|
|
- //识别身份证正面
|
|
|
|
|
- Idcard.getIdCardFront(s1, customerInfoVO);
|
|
|
|
|
- AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
|
|
|
- //设置缓存
|
|
|
|
|
- redisTemplate.opsForValue().set(s1Key, customerInfoVO, 1, TimeUnit.DAYS);
|
|
|
|
|
|
|
+ if (image1 != null){
|
|
|
|
|
+ String s1MD5 = DigestUtils.md5Hex(image1.getBytes());
|
|
|
|
|
+ String s1 = byteToBase64(image1);
|
|
|
|
|
+ String s1Key = IMAGE_IDENTIFY_KEY + "idCard:" + "front:" + s1MD5;
|
|
|
|
|
+ if (StringUtils.isNotBlank(s1) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s1Key))) {
|
|
|
|
|
+ //走缓存
|
|
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s1Key)), customerInfoVO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //识别身份证正面
|
|
|
|
|
+ Idcard.getIdCardFront(s1, customerInfoVO);
|
|
|
|
|
+ AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
|
|
|
+ //设置缓存
|
|
|
|
|
+ redisTemplate.opsForValue().set(s1Key, customerInfoVO, 1, TimeUnit.DAYS);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
- String s2MD5 = DigestUtils.md5Hex(image2.getBytes());
|
|
|
|
|
- String s2 = byteToBase64(image2);
|
|
|
|
|
- String s2Key = IMAGE_IDENTIFY_KEY + "idCard:" + "back:" + s2MD5;
|
|
|
|
|
- if (StringUtils.isNotBlank(s2) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s2Key))) {
|
|
|
|
|
- //走缓存
|
|
|
|
|
- BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s2Key)), customerInfoVO);
|
|
|
|
|
- } else {
|
|
|
|
|
- //识别身份证背面
|
|
|
|
|
- Idcard.getIdCardBack(s2, customerInfoVO);
|
|
|
|
|
- AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
|
|
|
- //设置缓存
|
|
|
|
|
- redisTemplate.opsForValue().set(s2Key, customerInfoVO, 1, TimeUnit.DAYS);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if (image2 != null) {
|
|
|
|
|
+ String s2MD5 = DigestUtils.md5Hex(image2.getBytes());
|
|
|
|
|
+ String s2 = byteToBase64(image2);
|
|
|
|
|
+ String s2Key = IMAGE_IDENTIFY_KEY + "idCard:" + "back:" + s2MD5;
|
|
|
|
|
+ if (StringUtils.isNotBlank(s2) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s2Key))) {
|
|
|
|
|
+ //走缓存
|
|
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s2Key)), customerInfoVO);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //识别身份证背面
|
|
|
|
|
+ Idcard.getIdCardBack(s2, customerInfoVO);
|
|
|
|
|
+ AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
|
|
|
+ //设置缓存
|
|
|
|
|
+ redisTemplate.opsForValue().set(s2Key, customerInfoVO, 1, TimeUnit.DAYS);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
@@ -83,34 +88,37 @@ public class IdentifyServiceImpl implements IdentifyService {
|
|
|
public HttpResult<Map<String, Object>> drivingPermit(MultipartFile image1, MultipartFile image2) throws IOException {
|
|
public HttpResult<Map<String, Object>> drivingPermit(MultipartFile image1, MultipartFile image2) throws IOException {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
CardUserInfo cardUserInfo = new CardUserInfo();
|
|
CardUserInfo cardUserInfo = new CardUserInfo();
|
|
|
- String s1MD5 = DigestUtils.md5Hex(image1.getBytes());
|
|
|
|
|
- String s1 = byteToBase64(image1);
|
|
|
|
|
- String s1Key = IMAGE_IDENTIFY_KEY + "drivingPermit:" + "front:" + s1MD5;
|
|
|
|
|
- if (StringUtils.isNotBlank(s1) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s1Key))) {
|
|
|
|
|
- //走缓存
|
|
|
|
|
- BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s1Key)), cardUserInfo);
|
|
|
|
|
- } else {
|
|
|
|
|
- //行驶证正面识别
|
|
|
|
|
- MultiObjectDetect.drivingPermitFront(s1, cardUserInfo);
|
|
|
|
|
- AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
|
|
- //设置缓存
|
|
|
|
|
- redisTemplate.opsForValue().set(s1Key, cardUserInfo, 1, TimeUnit.DAYS);
|
|
|
|
|
|
|
+ if (image1 != null) {
|
|
|
|
|
+ String s1MD5 = DigestUtils.md5Hex(image1.getBytes());
|
|
|
|
|
+ String s1 = byteToBase64(image1);
|
|
|
|
|
+ String s1Key = IMAGE_IDENTIFY_KEY + "drivingPermit:" + "front:" + s1MD5;
|
|
|
|
|
+ if (StringUtils.isNotBlank(s1) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s1Key))) {
|
|
|
|
|
+ //走缓存
|
|
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s1Key)), cardUserInfo);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //行驶证正面识别
|
|
|
|
|
+ MultiObjectDetect.drivingPermitFront(s1, cardUserInfo);
|
|
|
|
|
+ AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
|
|
+ //设置缓存
|
|
|
|
|
+ redisTemplate.opsForValue().set(s1Key, cardUserInfo, 1, TimeUnit.DAYS);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- String s2MD5 = DigestUtils.md5Hex(image2.getBytes());
|
|
|
|
|
- String s2 = byteToBase64(image2);
|
|
|
|
|
- String s2Key = IMAGE_IDENTIFY_KEY + "drivingPermit:" + "back:" + s2MD5;
|
|
|
|
|
- if (StringUtils.isNotBlank(s2) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s2Key))) {
|
|
|
|
|
- //走缓存
|
|
|
|
|
- BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s2Key)), cardUserInfo);
|
|
|
|
|
- } else {
|
|
|
|
|
- //行驶证反面识别
|
|
|
|
|
- MultiObjectDetect.drivingPermitBack(s2, cardUserInfo);
|
|
|
|
|
- AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
|
|
- //设置缓存
|
|
|
|
|
- redisTemplate.opsForValue().set(s2Key, cardUserInfo, 1, TimeUnit.DAYS);
|
|
|
|
|
|
|
+ if (image2 != null) {
|
|
|
|
|
+ String s2MD5 = DigestUtils.md5Hex(image2.getBytes());
|
|
|
|
|
+ String s2 = byteToBase64(image2);
|
|
|
|
|
+ String s2Key = IMAGE_IDENTIFY_KEY + "drivingPermit:" + "back:" + s2MD5;
|
|
|
|
|
+ if (StringUtils.isNotBlank(s2) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(s2Key))) {
|
|
|
|
|
+ //走缓存
|
|
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(s2Key)), cardUserInfo);
|
|
|
|
|
+ } else {
|
|
|
|
|
+ //行驶证反面识别
|
|
|
|
|
+ MultiObjectDetect.drivingPermitBack(s2, cardUserInfo);
|
|
|
|
|
+ AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
|
|
+ //设置缓存
|
|
|
|
|
+ redisTemplate.opsForValue().set(s2Key, cardUserInfo, 1, TimeUnit.DAYS);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
-
|
|
|
|
|
AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
map.put("carInfo", cardUserInfo);
|
|
map.put("carInfo", cardUserInfo);
|
|
|
return HttpResult.ok("success", map);
|
|
return HttpResult.ok("success", map);
|