提交修改
This commit is contained in:
parent
fdccf1b8da
commit
62b43c8a4d
@ -2,21 +2,17 @@ package com.heyu.api.common;
|
||||
|
||||
import ch.qos.logback.classic.pattern.ClassicConverter;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
public class LogClassicConverter extends ClassicConverter {
|
||||
|
||||
|
||||
@Override
|
||||
public String convert(ILoggingEvent event) {
|
||||
if (LogAspect.threadLocalNo != null && LogAspect.threadLocalNo.get() != null) {
|
||||
String traceId = MDC.get("traceId");
|
||||
if (traceId != null) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append("[").append(LogAspect.threadLocalNo.get());
|
||||
Long start = LogAspect.threadLocalTime.get();
|
||||
Long end;
|
||||
if (start != null) {
|
||||
end = System.currentTimeMillis();
|
||||
sb.append(",").append(end - start);
|
||||
}
|
||||
sb.append("[").append(traceId);
|
||||
sb.append("]");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@ -1,6 +1,5 @@
|
||||
package com.heyu.api.data.service.impl.vv;
|
||||
|
||||
import com.heyu.api.common.LogAspect;
|
||||
import com.heyu.api.data.dao.vv.VvPackageDao;
|
||||
import com.heyu.api.data.dao.vv.VvTradeOrderLineStatusLogDao;
|
||||
import com.heyu.api.data.entity.vv.VvPackageEntity;
|
||||
@ -17,6 +16,7 @@ import com.heyu.api.data.utils.SanUtils;
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@ -114,7 +114,7 @@ public class VvTradeOrderConvertServiceImpl implements VvTradeOrderConvertServic
|
||||
entity.setFeatures(reason[1]);
|
||||
}
|
||||
}
|
||||
entity.setTraceId(LogAspect.threadLocalNo.get());
|
||||
entity.setTraceId(MDC.get("traceId"));
|
||||
vvTradeOrderLineStatusLogDao.insertVvTradeOrderLineStatusLog(entity);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@ -121,7 +121,7 @@ public class Base64Utils {
|
||||
|
||||
|
||||
public static void main(String[] args) {
|
||||
String imagePath = "/Users/quyixiao/Desktop/ocr/testxxx.jpg";
|
||||
String imagePath = "/Users/quyixiao/Desktop/Xnip2026-05-18_20-36-51.jpg";
|
||||
String base64Image = encodeImageToBase64(imagePath);
|
||||
System.out.println("Base64 Image String:");
|
||||
System.out.println(base64Image);
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
package com.heyu.api.data.utils;
|
||||
|
||||
|
||||
import com.heyu.api.common.LogAspect;
|
||||
import com.heyu.api.data.dto.RespCode;
|
||||
import org.slf4j.MDC;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
@ -40,8 +40,9 @@ public class R<T> {
|
||||
public R() {
|
||||
this.code = RespCode.SUCCESS.code;
|
||||
this.msg = RespCode.SUCCESS.msg;
|
||||
if (LogAspect.threadLocalNo != null) {
|
||||
this.traceId = LogAspect.threadLocalNo.get();
|
||||
this.traceId = MDC.get("traceId");
|
||||
if (this.traceId == null) {
|
||||
this.traceId = MDC.get("X-B3-TraceId");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -45,9 +45,7 @@ public class BVehicleLicenseHandle extends BaiduBaseHandle<BVehicleLicenseReques
|
||||
if (checkNotTrueFalse(bVehicleLicenseRequest.getQualityWarn())) {
|
||||
return "qualityWarn 必须为" + ApiConstants.trueOrFalse + ",false:不输出质量告警信息, true : 输出行驶证遮挡、不完整质量告警信息";
|
||||
}
|
||||
if (checkNotFrontBack(bVehicleLicenseRequest.getRiskWarn())) {
|
||||
return "riskWarn 必须为" + ApiConstants.trueOrFalse + ",false:不输出风险告警信息 , true:开启,输出行驶证复印、翻拍、PS等告警信息";
|
||||
}
|
||||
|
||||
return checkImageUri(bVehicleLicenseRequest);
|
||||
}
|
||||
|
||||
|
||||
@ -2,12 +2,12 @@ package com.heyu.api.aop;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.heyu.api.common.LogAspect;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.service.bussiness.RedisSettingService;
|
||||
import com.heyu.api.data.utils.*;
|
||||
import com.heyu.api.utils.OsUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@ -78,8 +78,6 @@ public class LogAop {
|
||||
if (StringUtils.isBlank(traceId)) {
|
||||
traceId = OrderUtil.getUserPoolOrder("on");
|
||||
}
|
||||
LogAspect.threadLocalNo.set(traceId);
|
||||
LogAspect.threadLocalTime.set(System.currentTimeMillis());
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
uri = attributes.getRequest().getRequestURI();
|
||||
|
||||
@ -127,7 +125,7 @@ public class LogAop {
|
||||
return point.proceed();
|
||||
}
|
||||
try {
|
||||
|
||||
MDC.put("traceId", traceId);
|
||||
|
||||
// 如果方法和类上都没有配置NotIntercept注解 ,则需要拦截 ,是linux才进行拦截
|
||||
if (intercept && OsUtil.isLinux()) {
|
||||
@ -154,8 +152,7 @@ public class LogAop {
|
||||
log.error("LogAop set error " + sb.toString(), e);
|
||||
} finally {
|
||||
printLog(result, args, ip, className, methodName, uri);
|
||||
LogAspect.threadLocalNo.remove();
|
||||
LogAspect.threadLocalTime.remove();
|
||||
MDC.remove("traceId");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -2,13 +2,13 @@ package com.heyu.api.aop;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.heyu.api.common.LogAspect;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.dto.BuyerDTO;
|
||||
import com.heyu.api.data.dto.VVRequestLogDTO;
|
||||
import com.heyu.api.data.dto.vv.VVAdminDTO;
|
||||
import com.heyu.api.data.utils.*;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.slf4j.MDC;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.Signature;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@ -88,8 +88,6 @@ public class ZhenZhenLogAop {
|
||||
}
|
||||
Long buyerId = null;
|
||||
Long startTime = System.currentTimeMillis();
|
||||
LogAspect.threadLocalNo.set(traceId);
|
||||
LogAspect.threadLocalTime.set(System.currentTimeMillis());
|
||||
HttpServletRequest request = attributes.getRequest();
|
||||
uri = attributes.getRequest().getRequestURI();
|
||||
|
||||
@ -103,6 +101,7 @@ public class ZhenZhenLogAop {
|
||||
|
||||
String token = "";
|
||||
try {
|
||||
MDC.put("traceId", traceId);
|
||||
args = recordRequestLog(point.getArgs(), uri);
|
||||
Signature sig = point.getSignature();
|
||||
|
||||
@ -204,8 +203,7 @@ public class ZhenZhenLogAop {
|
||||
log.error("LogAop set error " + sb.toString(), e);
|
||||
} finally {
|
||||
printLog(result, args, ip, className, methodName, uri, token, traceId, startTime, buyerId, describe);
|
||||
LogAspect.threadLocalNo.remove();
|
||||
LogAspect.threadLocalTime.remove();
|
||||
MDC.remove("traceId");
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -2,11 +2,31 @@ package com.heyu.api.controller;
|
||||
|
||||
import com.heyu.api.alibaba.request.ACommonTextRequest;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.constants.RedisConstans;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.RedisUtils;
|
||||
import com.heyu.api.data.utils.StringUtils;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
|
||||
@Slf4j
|
||||
@SuppressWarnings({"unchecked", "deprecation"})
|
||||
public class BaseController {
|
||||
|
||||
private static final String VEHICLE_LICENSE_URI = "/rest/2.0/ocr/v1/vehicle_license";
|
||||
private static final String BAIDU_API_KEY = "zs9oN4gSuoS3eK8dVJg6jyKh";
|
||||
private static final String BAIDU_SECRET_KEY = "uHIRXkj6rbW1eXy8eRVCeP1e3cRQKXay";
|
||||
private static final OkHttpClient HTTP_CLIENT = new OkHttpClient().newBuilder().build();
|
||||
|
||||
@Autowired
|
||||
private RedisUtils redisUtils;
|
||||
|
||||
|
||||
|
||||
@ -36,4 +56,70 @@ public class BaseController {
|
||||
return value == null || value.trim().length() == 0;
|
||||
}
|
||||
|
||||
protected Map<String, Object> requestBaidu(String content) {
|
||||
String result = null;
|
||||
try {
|
||||
if (StringUtils.isBlank(content)) {
|
||||
log.error("请求内容为空,未知异常");
|
||||
return null;
|
||||
}
|
||||
if (content.startsWith("&")) {
|
||||
content = content.substring(1);
|
||||
}
|
||||
|
||||
Request baiduRequest = createBaiduRequest(content);
|
||||
try (Response response = HTTP_CLIENT.newCall(baiduRequest).execute()) {
|
||||
result = response.body().string();
|
||||
return com.alibaba.fastjson.JSONObject.parseObject(result, Map.class);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
log.error("BaseController requestBaidu 异常", e);
|
||||
} finally {
|
||||
log.info("BaseController requestBaidu result :{}", result);
|
||||
}
|
||||
log.error("BaseController requestBaidu 没有返回值。");
|
||||
return null;
|
||||
}
|
||||
|
||||
private Request createBaiduRequest(String content) {
|
||||
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
||||
okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, content);
|
||||
return new Request.Builder()
|
||||
.url("https://aip.baidubce.com/" + VEHICLE_LICENSE_URI + "?access_token=" + getBaiduAccessToken())
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
.addHeader("Accept", "application/json")
|
||||
.build();
|
||||
}
|
||||
|
||||
private String getAccessToken(String apiKey, String secretKey) throws Exception {
|
||||
MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
|
||||
okhttp3.RequestBody body = okhttp3.RequestBody.create(mediaType, "grant_type=client_credentials&client_id=" + apiKey
|
||||
+ "&client_secret=" + secretKey);
|
||||
Request request = new Request.Builder()
|
||||
.url("https://aip.baidubce.com/oauth/2.0/token")
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/x-www-form-urlencoded")
|
||||
.build();
|
||||
try (Response response = HTTP_CLIENT.newCall(request).execute()) {
|
||||
return new org.json.JSONObject(response.body().string()).getString("access_token");
|
||||
}
|
||||
}
|
||||
|
||||
private String getBaiduAccessToken() {
|
||||
try {
|
||||
String accessTokenKey = BAIDU_API_KEY + ":" + BAIDU_SECRET_KEY + ":token";
|
||||
String accessToken = redisUtils.get(accessTokenKey);
|
||||
if (StringUtils.isBlank(accessToken)) {
|
||||
accessToken = getAccessToken(BAIDU_API_KEY, BAIDU_SECRET_KEY);
|
||||
redisUtils.set(accessTokenKey, accessToken, RedisConstans.SECOND_OF_ONE_7_DAY);
|
||||
}
|
||||
return accessToken;
|
||||
} catch (Exception e) {
|
||||
log.error("getBaiduToken error", e);
|
||||
}
|
||||
log.error("getBaiduToken error token is null ");
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -5,7 +5,7 @@ import com.aliyun.ocr20191230.models.RecognizeDriverLicenseResponseBody;
|
||||
import com.heyu.api.alibaba.handle.common.text.ARecognizeDriverLicenseHandle;
|
||||
import com.heyu.api.alibaba.request.common.text.ARecognizeDriverLicenseRequest;
|
||||
import com.heyu.api.controller.BaseController;
|
||||
import com.heyu.api.data.annotation.NotIntercept;
|
||||
import com.heyu.api.data.annotation.EbAuthentication;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.R;
|
||||
@ -14,6 +14,7 @@ import com.heyu.api.resp.car.RecognizeDriverLicenseFaceResp;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
@ -42,20 +43,18 @@ import org.springframework.web.bind.annotation.RestController;
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/driver/license")
|
||||
@NotIntercept
|
||||
public class RecognizeDriverLicenseController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ARecognizeDriverLicenseHandle aRecognizeDriverLicenseHandle;
|
||||
|
||||
// http://localhost:8888/driver/license/recognize?side=face&imageBase64=/9j/4AAQSkZJRgABA
|
||||
@EbAuthentication(tencent = ApiConstants.TENCENT_AUTH)
|
||||
@PostMapping("/recognize")
|
||||
public R recognize(ARecognizeDriverLicenseRequest request) {
|
||||
public R recognize(@RequestBody ARecognizeDriverLicenseRequest request) {
|
||||
if (!hasImage(request)) {
|
||||
return R.error("imageUrl和imageBase64不能同时为空");
|
||||
}
|
||||
if (!isFaceOrBack(request.getSide())) {
|
||||
return R.error("side只能为face或back");
|
||||
}
|
||||
|
||||
ApiR<RecognizeDriverLicenseResponse> aR = aRecognizeDriverLicenseHandle.handle(request);
|
||||
if (!isValidAliResponse(aR)) {
|
||||
|
||||
@ -1,103 +1,133 @@
|
||||
package com.heyu.api.controller.car;
|
||||
|
||||
import com.aliyun.ocr20191230.models.RecognizeDrivingLicenseResponse;
|
||||
import com.aliyun.ocr20191230.models.RecognizeDrivingLicenseResponseBody;
|
||||
import com.heyu.api.alibaba.handle.common.text.ARecognizeDrivingLicenseHandle;
|
||||
import com.heyu.api.alibaba.request.common.text.ARecognizeDrivingLicenseRequest;
|
||||
import com.heyu.api.baidu.handle.traffic.BVehicleLicenseHandle;
|
||||
import com.heyu.api.baidu.request.traffic.BVehicleLicenseRequest;
|
||||
import com.heyu.api.controller.BaseController;
|
||||
import com.heyu.api.data.annotation.NotIntercept;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.utils.ApiR;
|
||||
import com.heyu.api.data.utils.MapUtils;
|
||||
import com.heyu.api.data.utils.R;
|
||||
import com.heyu.api.data.utils.StringUtils;
|
||||
import com.heyu.api.request.car.VehicleLicenseRequest;
|
||||
import com.heyu.api.resp.car.RecognizeDrivingLicenseBackResp;
|
||||
import com.heyu.api.resp.car.RecognizeDrivingLicenseFaceResp;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
/***
|
||||
*
|
||||
* https://next.api.aliyun.com/api/ocr/2019-12-30/RecognizeDrivingLicense?tab=DEMO&lang=JAVA
|
||||
*行驶证识别
|
||||
*
|
||||
* RecognizeDrivingLicense
|
||||
* 行驶证识别能力可以识别行驶证首页和副页关键字段内容,输出品牌型号、车辆类型、车牌号码、检验记录、核定载质量、核定载人数等 21 个关键字段信息。
|
||||
*
|
||||
/**
|
||||
* 行驶证识别。
|
||||
* https://console.bce.baidu.com/support/?_=1740219852952×tamp=1740323990690#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E4%BA%A4%E9%80%9A%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fvehicle_license&method=post
|
||||
*
|
||||
*
|
||||
*/
|
||||
@Slf4j
|
||||
@RestController
|
||||
@RequestMapping("/driving/license")
|
||||
@NotIntercept
|
||||
@SuppressWarnings("unchecked")
|
||||
public class RecognizeDrivingLicenseController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
private ARecognizeDrivingLicenseHandle arRecognizeDrivingLicenseHandle;
|
||||
|
||||
@Autowired
|
||||
private BVehicleLicenseHandle bVehicleLicenseHandle;
|
||||
|
||||
// http://localhost:8888/driving/license/recognize
|
||||
@PostMapping("/recognize")
|
||||
public R recognize(ARecognizeDrivingLicenseRequest request) {
|
||||
if (!hasImage(request)) {
|
||||
return R.error("imageUrl和imageBase64不能同时为空");
|
||||
public R<Object> recognize(@RequestBody VehicleLicenseRequest request) {
|
||||
BVehicleLicenseRequest bVehicleLicenseRequest = toBaiduRequest(request);
|
||||
String checkMsg = checkRequest(bVehicleLicenseRequest);
|
||||
if (!isBlank(checkMsg)) {
|
||||
return R.error(checkMsg);
|
||||
}
|
||||
if (!isFaceOrBack(request.getSide())) {
|
||||
return R.error("side只能为face或back");
|
||||
Map<String, Object> data = requestBaidu(getContent(bVehicleLicenseRequest));
|
||||
if (data == null) {
|
||||
return R.error("识别失败");
|
||||
}
|
||||
|
||||
ApiR<Map> bR = bVehicleLicenseHandle.handle(toBaiduRequest(request));
|
||||
if (bR != null && bR.isSuccess() && bR.getData() != null) {
|
||||
if (ApiConstants.face.equals(request.getSide())) {
|
||||
return R.ok().setData(toFaceResp(bR.getData()));
|
||||
}
|
||||
return R.ok().setData(toBackResp(bR.getData()));
|
||||
}
|
||||
|
||||
ApiR<RecognizeDrivingLicenseResponse> aR = arRecognizeDrivingLicenseHandle.handle(request);
|
||||
if (!isValidAliResponse(aR)) {
|
||||
return R.error(!isBlank(thirdError(aR)) ? thirdError(aR) : thirdError(bR));
|
||||
}
|
||||
|
||||
RecognizeDrivingLicenseResponseBody.RecognizeDrivingLicenseResponseBodyData data =
|
||||
aR.getData().getBody().getData();
|
||||
if (ApiConstants.face.equals(request.getSide())) {
|
||||
if (data.getFaceResult() == null) {
|
||||
return R.error("未识别到行驶证正页信息");
|
||||
}
|
||||
return R.ok().setData(toFaceResp(data.getFaceResult()));
|
||||
}
|
||||
if (data.getBackResult() == null) {
|
||||
return R.error("未识别到行驶证副页信息");
|
||||
}
|
||||
return R.ok().setData(toBackResp(data.getBackResult()));
|
||||
R<Object> result = R.ok();
|
||||
return result.setData(toRecognizeResp(bVehicleLicenseRequest.getVehicleLicenseSide(), data));
|
||||
}
|
||||
|
||||
private BVehicleLicenseRequest toBaiduRequest(ARecognizeDrivingLicenseRequest request) {
|
||||
private BVehicleLicenseRequest toBaiduRequest(VehicleLicenseRequest request) {
|
||||
BVehicleLicenseRequest bVehicleLicenseRequest = new BVehicleLicenseRequest();
|
||||
bVehicleLicenseRequest.setVehicleLicenseSide(request.getSide());
|
||||
if (request == null) {
|
||||
return bVehicleLicenseRequest;
|
||||
}
|
||||
bVehicleLicenseRequest.setImageUrl(request.getImageUrl());
|
||||
bVehicleLicenseRequest.setImageBase64(request.getImageBase64());
|
||||
if (StringUtils.isNotBlank(request.getSide())) {
|
||||
bVehicleLicenseRequest.setVehicleLicenseSide(request.getSide());
|
||||
}
|
||||
return bVehicleLicenseRequest;
|
||||
}
|
||||
|
||||
private boolean isValidAliResponse(ApiR<RecognizeDrivingLicenseResponse> apiR) {
|
||||
return apiR != null
|
||||
&& apiR.isSuccess()
|
||||
&& apiR.getData() != null
|
||||
&& isSuccessStatusCode(apiR.getData().getStatusCode())
|
||||
&& apiR.getData().getBody() != null
|
||||
&& apiR.getData().getBody().getData() != null;
|
||||
private String checkRequest(BVehicleLicenseRequest request) {
|
||||
if (!hasImage(request)) {
|
||||
return "imageUrl和imageBase64不能同时为空";
|
||||
}
|
||||
if (checkNotTrueFalse(request.getDetectDirection())) {
|
||||
return "detectDirection 必须传 " + ApiConstants.trueOrFalse + ",false:不进行图像方向自动矫正, true: 开启图像方向自动矫正功能,可对旋转 90/180/270 度的图片进行自动矫正并识别";
|
||||
}
|
||||
if (checkNotFrontBack(request.getVehicleLicenseSide())) {
|
||||
return "vehicleLicenseSide 必须传 " + ApiConstants.frontOrback + ",front:正向, back反面";
|
||||
}
|
||||
if (checkNotTrueFalse(request.getUnified())) {
|
||||
return "unified必须为 " + ApiConstants.trueOrFalse + ", false 不进行归一化处理, rue:对输出字段进行归一化处理,将新/老版行驶证的“注册登记日期/注册日期”统一为”注册日期“进行输出";
|
||||
}
|
||||
if (checkNotTrueFalse(request.getQualityWarn())) {
|
||||
return "qualityWarn 必须为" + ApiConstants.trueOrFalse + ",false:不输出质量告警信息, true : 输出行驶证遮挡、不完整质量告警信息";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean hasImage(BVehicleLicenseRequest request) {
|
||||
return request != null && (!isBlank(request.getImageUrl()) || !isBlank(request.getImageBase64()));
|
||||
}
|
||||
|
||||
private String getContent(BVehicleLicenseRequest request) {
|
||||
StringBuffer sb = getImageContent(request);
|
||||
if (StringUtils.isNotBlank(request.getDetectDirection())) {
|
||||
sb.append("&detect_direction=").append(request.getDetectDirection());
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getVehicleLicenseSide())) {
|
||||
sb.append("&vehicle_license_side=").append(request.getVehicleLicenseSide());
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getUnified())) {
|
||||
sb.append("&unified=").append(request.getUnified());
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getQualityWarn())) {
|
||||
sb.append("&quality_warn=").append(request.getQualityWarn());
|
||||
}
|
||||
if (StringUtils.isNotBlank(request.getRiskWarn())) {
|
||||
sb.append("&risk_warn=").append(request.getRiskWarn());
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
private StringBuffer getImageContent(BVehicleLicenseRequest request) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
if (StringUtils.isNotBlank(request.getImageBase64())) {
|
||||
sb.append("&image=").append(request.getImageBase64());
|
||||
}
|
||||
|
||||
if (StringUtils.isNotBlank(request.getImageUrl())) {
|
||||
sb.append("&url=").append(request.getImageUrl());
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
|
||||
private boolean checkNotTrueFalse(String value) {
|
||||
return !ApiConstants.trueOrFalse.contains(value);
|
||||
}
|
||||
|
||||
private boolean checkNotFrontBack(String value) {
|
||||
return !ApiConstants.frontOrback.contains(value);
|
||||
}
|
||||
|
||||
private Object toRecognizeResp(String side, Map<String, Object> data) {
|
||||
if (ApiConstants.front.equals(side)) {
|
||||
return toFaceResp(data);
|
||||
}
|
||||
return toBackResp(data);
|
||||
}
|
||||
|
||||
private RecognizeDrivingLicenseFaceResp toFaceResp(Map<String, Object> data) {
|
||||
@ -130,35 +160,4 @@ public class RecognizeDrivingLicenseController extends BaseController {
|
||||
return backResp;
|
||||
}
|
||||
|
||||
private RecognizeDrivingLicenseFaceResp toFaceResp(
|
||||
RecognizeDrivingLicenseResponseBody.RecognizeDrivingLicenseResponseBodyDataFaceResult faceResult) {
|
||||
RecognizeDrivingLicenseFaceResp faceResp = new RecognizeDrivingLicenseFaceResp();
|
||||
faceResp.setIssueDate(faceResult.getIssueDate());
|
||||
faceResp.setModel(faceResult.getModel());
|
||||
faceResp.setVehicleType(faceResult.getVehicleType());
|
||||
faceResp.setOwner(faceResult.getOwner());
|
||||
faceResp.setEngineNumber(faceResult.getEngineNumber());
|
||||
faceResp.setPlateNumber(faceResult.getPlateNumber());
|
||||
faceResp.setAddress(faceResult.getAddress());
|
||||
faceResp.setUseCharacter(faceResult.getUseCharacter());
|
||||
faceResp.setVin(faceResult.getVin());
|
||||
faceResp.setRegisterDate(faceResult.getRegisterDate());
|
||||
return faceResp;
|
||||
}
|
||||
|
||||
private RecognizeDrivingLicenseBackResp toBackResp(
|
||||
RecognizeDrivingLicenseResponseBody.RecognizeDrivingLicenseResponseBodyDataBackResult backResult) {
|
||||
RecognizeDrivingLicenseBackResp backResp = new RecognizeDrivingLicenseBackResp();
|
||||
backResp.setOverallDimension(backResult.getOverallDimension());
|
||||
backResp.setInspectionRecord(backResult.getInspectionRecord());
|
||||
backResp.setUnladenMass(backResult.getUnladenMass());
|
||||
backResp.setFileNumber(backResult.getFileNumber());
|
||||
backResp.setTractionMass(backResult.getTractionMass());
|
||||
backResp.setGrossMass(backResult.getGrossMass());
|
||||
backResp.setPlateNumber(backResult.getPlateNumber());
|
||||
backResp.setApprovedPassengerCapacity(backResult.getApprovedPassengerCapacity());
|
||||
backResp.setEnergyType(backResult.getEnergyType());
|
||||
backResp.setApprovedLoad(backResult.getApprovedLoad());
|
||||
return backResp;
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,44 @@
|
||||
package com.heyu.api.request.car;
|
||||
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
*https://console.bce.baidu.com/support/?_=1740219852952×tamp=1740323990690#/api?product=AI&project=%E6%96%87%E5%AD%97%E8%AF%86%E5%88%AB&parent=%E4%BA%A4%E9%80%9A%E5%9C%BA%E6%99%AFOCR&api=rest%2F2.0%2Focr%2Fv1%2Fvehicle_license&method=post
|
||||
*
|
||||
* 行驶证识别
|
||||
*/
|
||||
@Data
|
||||
public class VehicleLicenseRequest {
|
||||
|
||||
/**
|
||||
* 是否必选: 和 url/pdf_file/ofd_file 四选一
|
||||
* 类型: string
|
||||
* 说明:
|
||||
* 图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过8M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
|
||||
* 优先级:image > url > pdf_file > ofd_file ,当image字段存在时,url、pdf_file、ofd_file 字段失效
|
||||
*/
|
||||
private String imageBase64;
|
||||
|
||||
|
||||
/**
|
||||
* 和 image/pdf_file/ofd_file 四选一
|
||||
* 说明 :
|
||||
* 图片完整url,url长度不超过1024字节,url对应的图片base64编码后大小不超过8M,最短边至少15px,最长边最大4096px,支持jpg/jpeg/png/bmp格式
|
||||
* 优先级:image > url > pdf_file > ofd_file,当image字段存在时,url字段失效
|
||||
* 请注意关闭URL防盗链
|
||||
*/
|
||||
private String imageUrl;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* - front:默认值,识别行驶证主页
|
||||
* - back:识别行驶证副页
|
||||
*/
|
||||
private String side;
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -17,7 +17,6 @@
|
||||
package com.heyu.api.schedule;
|
||||
|
||||
|
||||
import com.heyu.api.common.EBException;
|
||||
import com.heyu.api.data.constants.ApiConstants;
|
||||
import com.heyu.api.data.entity.calca.ScheduleJobEntity;
|
||||
import org.quartz.*;
|
||||
@ -65,7 +64,7 @@ public class ScheduleUtils {
|
||||
try {
|
||||
return (CronTrigger) scheduler.getTrigger(getTriggerKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new EBException("获取定时任务CronTrigger出现异常", e);
|
||||
throw new RuntimeException("获取定时任务CronTrigger出现异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +95,7 @@ public class ScheduleUtils {
|
||||
pauseJob(scheduler, scheduleJob.getJobId());
|
||||
}
|
||||
} catch (SchedulerException e) {
|
||||
throw new EBException("创建定时任务失败", e);
|
||||
throw new RuntimeException("创建定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -127,7 +126,7 @@ public class ScheduleUtils {
|
||||
}
|
||||
|
||||
} catch (SchedulerException e) {
|
||||
throw new EBException("更新定时任务失败", e);
|
||||
throw new RuntimeException("更新定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -141,7 +140,7 @@ public class ScheduleUtils {
|
||||
dataMap.put(ApiConstants.JOB_PARAM_KEY, scheduleJob);
|
||||
scheduler.triggerJob(getJobKey(scheduleJob.getJobId()), dataMap);
|
||||
} catch (SchedulerException e) {
|
||||
throw new EBException("立即执行定时任务失败", e);
|
||||
throw new RuntimeException("立即执行定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -152,7 +151,7 @@ public class ScheduleUtils {
|
||||
try {
|
||||
scheduler.pauseJob(getJobKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new EBException("暂停定时任务失败", e);
|
||||
throw new RuntimeException("暂停定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,7 +162,7 @@ public class ScheduleUtils {
|
||||
try {
|
||||
scheduler.resumeJob(getJobKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new EBException("暂停定时任务失败", e);
|
||||
throw new RuntimeException("暂停定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -174,7 +173,7 @@ public class ScheduleUtils {
|
||||
try {
|
||||
scheduler.deleteJob(getJobKey(jobId));
|
||||
} catch (SchedulerException e) {
|
||||
throw new EBException("删除定时任务失败", e);
|
||||
throw new RuntimeException("删除定时任务失败", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,15 +6,9 @@
|
||||
<!-- 定义log文件的目录 -->
|
||||
<property name="LOG_HOME" value="${user.home}/logs/api-interface"></property>
|
||||
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<conversionRule conversionWord="convertMessage"
|
||||
converterClass="com.heyu.api.common.LogClassicConverter"/>
|
||||
|
||||
|
||||
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="LOG_PATTERN"
|
||||
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread]%-5level %F:%L %convertMessage %msg%n"/>
|
||||
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread]%-5level %F:%L %msg%n"/>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!--日志文件输出格式-->
|
||||
|
||||
@ -6,15 +6,9 @@
|
||||
<!-- 定义log文件的目录 -->
|
||||
<property name="LOG_HOME" value="/home/heyu/logs/api-interface"></property>
|
||||
|
||||
<!-- 彩色日志依赖的渲染类 -->
|
||||
<conversionRule conversionWord="convertMessage"
|
||||
converterClass="com.heyu.api.common.LogClassicConverter"/>
|
||||
|
||||
|
||||
|
||||
<!-- 日志输出格式 -->
|
||||
<property name="LOG_PATTERN"
|
||||
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread]%-5level %F:%L %convertMessage %msg%n"/>
|
||||
value="%d{yyyy-MM-dd HH:mm:ss.SSS} [%X{X-B3-TraceId:-},%X{X-B3-SpanId:-}] [%thread]%-5level %F:%L %msg%n"/>
|
||||
|
||||
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
|
||||
<!--日志文件输出格式-->
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user