|
|
@@ -8,17 +8,26 @@ import com.ydtech.modules.order.entity.BusinessLicense;
|
|
|
import com.ydtech.modules.order.service.IdentifyService;
|
|
|
import com.ydtech.modules.protocol.utils.AssertionUtils;
|
|
|
import com.ydtech.utils.ImageCompressionUtils;
|
|
|
+import com.ydtech.utils.ObjectUtil;
|
|
|
+import com.ydtech.utils.StringUtils;
|
|
|
import com.ydtech.utils.baidu.BusinessLicenseRecognition;
|
|
|
import com.ydtech.utils.baidu.Idcard;
|
|
|
import com.ydtech.utils.baidu.MultiObjectDetect;
|
|
|
+import org.springframework.beans.BeanUtils;
|
|
|
+import org.springframework.data.redis.core.RedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.util.ObjectUtils;
|
|
|
import org.springframework.web.multipart.MultipartFile;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import java.io.IOException;
|
|
|
import java.util.Base64;
|
|
|
import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
+import java.util.Objects;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+import static com.ydtech.modules.order.constants.OrderCacheConstant.IMAGE_IDENTIFY_KEY;
|
|
|
|
|
|
/**
|
|
|
* @author wenks
|
|
|
@@ -29,16 +38,39 @@ import java.util.Map;
|
|
|
@Service
|
|
|
public class IdentifyServiceImpl implements IdentifyService {
|
|
|
|
|
|
+
|
|
|
+ @Resource
|
|
|
+ private RedisTemplate<String, Object> redisTemplate;
|
|
|
+
|
|
|
@Override
|
|
|
public HttpResult<Map<String, Object>> idCard(MultipartFile image1, MultipartFile image2) {
|
|
|
Map<String, Object> map = new HashMap<>();
|
|
|
CustomerInfoVO customerInfoVO = new CustomerInfoVO();
|
|
|
|
|
|
String s1 = byteToBase64(image1);
|
|
|
- Idcard.getIdCardFront(s1, customerInfoVO);
|
|
|
+
|
|
|
+ if (StringUtils.isNotBlank(s1) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s1))) {
|
|
|
+ //走缓存
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s1)), customerInfoVO);
|
|
|
+ } else {
|
|
|
+ //识别身份证正面
|
|
|
+ Idcard.getIdCardFront(s1, customerInfoVO);
|
|
|
+ AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
|
+ //设置缓存
|
|
|
+ redisTemplate.opsForValue().set(IMAGE_IDENTIFY_KEY + s1, customerInfoVO, 1, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
|
|
|
String s2 = byteToBase64(image2);
|
|
|
- Idcard.getIdCardBack(s2, customerInfoVO);
|
|
|
+ if (StringUtils.isNotBlank(s2) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s2))) {
|
|
|
+ //走缓存
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s2)),customerInfoVO);
|
|
|
+ }else {
|
|
|
+ //识别身份证背面
|
|
|
+ Idcard.getIdCardBack(s2, customerInfoVO);
|
|
|
+ AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
|
+ //设置缓存
|
|
|
+ redisTemplate.opsForValue().set(IMAGE_IDENTIFY_KEY + s2, customerInfoVO, 1, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
|
|
|
AssertionUtils.isEmpty(customerInfoVO, "身份证识别失败");
|
|
|
map.put("customerInfo", customerInfoVO);
|
|
|
@@ -51,12 +83,30 @@ public class IdentifyServiceImpl implements IdentifyService {
|
|
|
CardUserInfo cardUserInfo = new CardUserInfo();
|
|
|
|
|
|
String s1 = byteToBase64(image1);
|
|
|
- MultiObjectDetect.drivingPermitFront(s1, cardUserInfo);
|
|
|
+ if (StringUtils.isNotBlank(s1) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s1))) {
|
|
|
+ //走缓存
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s1)),cardUserInfo);
|
|
|
+ } else {
|
|
|
+ //行驶证正面识别
|
|
|
+ MultiObjectDetect.drivingPermitFront(s1, cardUserInfo);
|
|
|
+ AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
+ //设置缓存
|
|
|
+ redisTemplate.opsForValue().set(IMAGE_IDENTIFY_KEY + s1, cardUserInfo, 1, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
|
|
|
String s2 = byteToBase64(image2);
|
|
|
- MultiObjectDetect.drivingPermitBack(s2, cardUserInfo);
|
|
|
+ if (StringUtils.isNotBlank(s2) && !ObjectUtil.isAllFieldNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s2))) {
|
|
|
+ //走缓存
|
|
|
+ BeanUtils.copyProperties(Objects.requireNonNull(redisTemplate.opsForValue().get(IMAGE_IDENTIFY_KEY + s2)),cardUserInfo);
|
|
|
+ }else {
|
|
|
+ //行驶证反面识别
|
|
|
+ MultiObjectDetect.drivingPermitBack(s2, cardUserInfo);
|
|
|
+ AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
+ //设置缓存
|
|
|
+ redisTemplate.opsForValue().set(IMAGE_IDENTIFY_KEY + s2, cardUserInfo, 1, TimeUnit.DAYS);
|
|
|
+ }
|
|
|
|
|
|
- AssertionUtils.isEmpty(cardUserInfo, "身份证识别失败");
|
|
|
+ AssertionUtils.isEmpty(cardUserInfo, "行驶证正面识别失败");
|
|
|
map.put("carInfo", cardUserInfo);
|
|
|
return HttpResult.ok("success", map);
|
|
|
}
|
|
|
@@ -85,4 +135,6 @@ public class IdentifyServiceImpl implements IdentifyService {
|
|
|
}
|
|
|
|
|
|
|
|
|
+
|
|
|
+
|
|
|
}
|