|
@@ -16,14 +16,13 @@ import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import okhttp3.*;
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
|
+import org.apache.commons.lang3.ArrayUtils;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-import org.springframework.beans.factory.annotation.Qualifier;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
-import sun.rmi.runtime.Log;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import javax.validation.ConstraintViolation;
|
|
@@ -36,8 +35,8 @@ import java.security.MessageDigest;
|
|
|
import java.time.LocalDateTime;
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
import java.util.*;
|
|
|
-import java.util.concurrent.ThreadPoolExecutor;
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
+import java.util.regex.Pattern;
|
|
|
|
|
|
/**
|
|
|
* @description:
|
|
@@ -93,6 +92,12 @@ public class ChannelServiceImpl implements ChannelService {
|
|
|
@Value("${supplier.decodeAppSecret}")
|
|
|
private String decodeAppSecret;
|
|
|
|
|
|
+ @Value("${supplier.vehicleInfo.url}")
|
|
|
+ private String vehicleInfoUrl;
|
|
|
+
|
|
|
+ @Value("${supplier.vehicleInfo.encodeKey}")
|
|
|
+ private String vehicleInfoEncodeKey;
|
|
|
+
|
|
|
DateTimeFormatter yMdHms = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
|
|
|
|
|
private static final String MEDIA_TYPE = "application/json;charset=UTF-8";
|
|
@@ -204,6 +209,7 @@ public class ChannelServiceImpl implements ChannelService {
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
+
|
|
|
private boolean validateType(ChannelTypeHandleResponseObject ret, String returnType, IllegalInfoV2CustomBodyObject customBodyObject) {
|
|
|
if (StringUtils.isBlank(customBodyObject.getType()) || !customBodyObject.getType().equals("1")) {
|
|
|
if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
@@ -465,7 +471,7 @@ public class ChannelServiceImpl implements ChannelService {
|
|
|
log.info("supplier10000040.validateIllegalInfoV2接口-上游返回时间={}", System.currentTimeMillis() - startTime);
|
|
|
if (response.body() != null) {
|
|
|
responseContext = response.body().string();
|
|
|
- log.info("supplier10000040.validateIllegalInfoV2接口responseContext={}",responseContext);
|
|
|
+ log.info("supplier10000040.validateIllegalInfoV2接口responseContext={}", responseContext);
|
|
|
}
|
|
|
response.close();
|
|
|
} catch (SocketTimeoutException ste) {
|
|
@@ -504,7 +510,7 @@ public class ChannelServiceImpl implements ChannelService {
|
|
|
}
|
|
|
|
|
|
private ChannelTypeHandleResponseObject setIllegalInfoV2Response(IllegalInfoV2ResponseObject responseObject,
|
|
|
- String interfaceType, ChannelTypeHandleResponseObject ret) {
|
|
|
+ String interfaceType, ChannelTypeHandleResponseObject ret) {
|
|
|
if (!responseObject.getCode().equals("1")) {
|
|
|
ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
ret.setResultBody(Constant.OTHER_ERROR);
|
|
@@ -561,7 +567,7 @@ public class ChannelServiceImpl implements ChannelService {
|
|
|
return ret;
|
|
|
}
|
|
|
|
|
|
- private boolean checkIllegalInfoV2ErrorResult (String code, String isDrugs, String isEscape, String isPedigree, String interfaceType) {
|
|
|
+ private boolean checkIllegalInfoV2ErrorResult(String code, String isDrugs, String isEscape, String isPedigree, String interfaceType) {
|
|
|
if (StringUtils.isBlank(code) || StringUtils.isBlank(isDrugs) || StringUtils.isBlank(isEscape) || StringUtils.isBlank(isPedigree)) {
|
|
|
return false;
|
|
|
} else if (!code.equals("0")) {
|
|
@@ -891,4 +897,203 @@ public class ChannelServiceImpl implements ChannelService {
|
|
|
}
|
|
|
return result;
|
|
|
}
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public ChannelTypeHandleResponseObject validateVehicleInfo(HttpServletRequest request, String customBody, int outTime) {
|
|
|
+ ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
|
|
|
+ ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
|
|
|
+ String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
|
|
|
+ String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
|
|
|
+
|
|
|
+ if (StringUtils.isBlank(returnType)) {
|
|
|
+ returnType = Constant.CUSTOMER_RETURN_ZW;
|
|
|
+ }
|
|
|
+ if (outTime <= 0) {
|
|
|
+ outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
|
|
|
+ }
|
|
|
+ log.info("validateVehicleInfo---customBody={},outTime={}", customBody, outTime);
|
|
|
+ VehicleInfoCustomBodyObject customBodyObject = new VehicleInfoCustomBodyObject();
|
|
|
+ try {
|
|
|
+ customBodyObject = objectMapper.readValue(customBody, VehicleInfoCustomBodyObject.class);
|
|
|
+ } catch (IOException ioe) {
|
|
|
+ log.info("supplier10000040.validateVehicleInfo接口-IOException:", ioe);
|
|
|
+ ErrorUtils.captureException(ioe);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 参数校验
|
|
|
+ if (!validateParams(ret, returnType, customBodyObject)) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ String traceId = request.getHeader("x-b3-traceid");
|
|
|
+// String traceId = System.currentTimeMillis() + "";
|
|
|
+ String encodeParams = "";
|
|
|
+
|
|
|
+ JSONObject requestParam = new JSONObject();
|
|
|
+ requestParam.put("idCode", customBodyObject.getCardId());
|
|
|
+ requestParam.put("name", customBodyObject.getName());
|
|
|
+ requestParam.put("plateNumber", customBodyObject.getPlateNumber());
|
|
|
+ requestParam.put("plateColor", customBodyObject.getPlateType());
|
|
|
+ requestParam.put("traceId", traceId);
|
|
|
+ try {
|
|
|
+ encodeParams = AesUtil.encryAES(JSON.toJSONString(requestParam), vehicleInfoEncodeKey);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("supplier10000040.validateVehicleInfo接口Exception=", e);
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ JSONObject params = new JSONObject();
|
|
|
+ params.put("param", encodeParams);
|
|
|
+
|
|
|
+ MediaType mediaType = MediaType.parse(MEDIA_TYPE);
|
|
|
+ RequestBody requestBody = RequestBody.create(mediaType, JSON.toJSONString(params));
|
|
|
+
|
|
|
+ Request okRequest = new Request.Builder()
|
|
|
+ .post(requestBody)
|
|
|
+ .url(vehicleInfoUrl)
|
|
|
+ .build();
|
|
|
+ OkHttpClient client = okHttpClient.newBuilder()
|
|
|
+ .connectTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .readTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .writeTimeout(outTime, TimeUnit.MILLISECONDS)
|
|
|
+ .build();
|
|
|
+
|
|
|
+ String responseContext = "";
|
|
|
+ try {
|
|
|
+ Long startTime = System.currentTimeMillis();
|
|
|
+ Response response = client.newCall(okRequest).execute();
|
|
|
+ log.info("supplier10000040.validateVehicleInfo接口-上游返回时间={}", System.currentTimeMillis() - startTime);
|
|
|
+ if (response.body() != null) {
|
|
|
+ responseContext = response.body().string();
|
|
|
+ log.info("supplier10000040.validateVehicleInfo接口responseContext={}", responseContext);
|
|
|
+ }
|
|
|
+ response.close();
|
|
|
+ } catch (SocketTimeoutException ste) {
|
|
|
+ log.info("supplier10000040.validateVehicleInfo接口-SocketTimeoutException:", ste);
|
|
|
+ ErrorUtils.captureException(ste);
|
|
|
+ ret.setCode(Constant.REQUEST_TIMEOUT);
|
|
|
+ return ret;
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.info("supplier10000040.validateVehicleInfo接口Exception=", e);
|
|
|
+ ErrorUtils.captureException(e);
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+ JSONObject resultJsonObject = JSON.parseObject(responseContext);
|
|
|
+ if (resultJsonObject.get("code") != null && resultJsonObject.getString("code").equals("1")) {
|
|
|
+ VehicleInfoResponseObject responseObject = JSON.toJavaObject(resultJsonObject, VehicleInfoResponseObject.class);
|
|
|
+ if (responseObject != null) {
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ setVehicleInfoResponse(ret, responseObject);
|
|
|
+ } else {
|
|
|
+ ret.setCode(Constant.FAIL);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ ret.setCode(Constant.SUCCESS);
|
|
|
+ }
|
|
|
+ if (resultJsonObject.get("code") != null) {
|
|
|
+ upstreamCode = resultJsonObject.getString("code");
|
|
|
+ }
|
|
|
+
|
|
|
+ //上游返回码
|
|
|
+ request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
|
|
|
+ return ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ private void setVehicleInfoResponse(ChannelTypeHandleResponseObject ret, VehicleInfoResponseObject responseObject) {
|
|
|
+ if (responseObject.getCode().equals("1") && responseObject.getMessage().getCode().equals("0")) {
|
|
|
+ // 查询成功,返回结果
|
|
|
+ ret.setResultBody(responseObject.getMessage().getResult());
|
|
|
+ ret.setResultDesc(Constant.QUERY_SUCCESS);
|
|
|
+ ret.setResultCode(Constant.MATCH_CODE);
|
|
|
+ ret.setIsCharge(Constant.IS_CHARGE);
|
|
|
+ } else {
|
|
|
+ // 查询失败
|
|
|
+ ret.setResultCode(Constant.OTHER_ERROR_CODE);
|
|
|
+ ret.setResultBody(Constant.OTHER_ERROR);
|
|
|
+ ret.setIsCharge(Constant.IS_NOT_CHARGE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private boolean validateParams(ChannelTypeHandleResponseObject ret, String returnType, VehicleInfoCustomBodyObject customBodyObject) {
|
|
|
+ if (!validateParamNullValue(customBodyObject)) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+
|
|
|
+ boolean checkResult;
|
|
|
+ if (StringUtils.isBlank(customBodyObject.getCardId())) {
|
|
|
+ checkResult = false;
|
|
|
+ } else if (StringUtils.isBlank(customBodyObject.getCardType())
|
|
|
+ || !ArrayUtils.contains(ChannelConstant.CARD_TYPE_ARRAY, customBodyObject.getCardType())) {
|
|
|
+ checkResult = false;
|
|
|
+ } else if (StringUtils.isBlank(customBodyObject.getName())) {
|
|
|
+ checkResult = false;
|
|
|
+ } else if (StringUtils.isBlank(customBodyObject.getPlateNumber())
|
|
|
+ || !PatternTools.checkResult(Constant.PATTERN_CAR_NUMBER_REGEX, customBodyObject.getPlateNumber())) {
|
|
|
+ checkResult = false;
|
|
|
+ } else if (StringUtils.isBlank(customBodyObject.getPlateType())
|
|
|
+ || !ArrayUtils.contains(ChannelConstant.PLATE_TYPE_ARRAY, customBodyObject.getPlateType())) {
|
|
|
+ checkResult = false;
|
|
|
+ } else {
|
|
|
+ checkResult = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!checkResult) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
|
|
|
+ ret.setResultBody(Constant.INVALID_PARAMETER);
|
|
|
+ ret.setResultDesc(Constant.INVALID_PARAMETER);
|
|
|
+ }
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (customBodyObject.getCardType().equals("1")
|
|
|
+ && !PatternTools.checkResult(Constant.PATTERN_ID_NUMBER_REGEX, customBodyObject.getCardId())) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.IDCODE_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_IDCODE_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_IDCODE_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ checkResult = false;
|
|
|
+ } else if (customBodyObject.getCardType().equals("1")
|
|
|
+ && !PatternTools.checkResult(Constant.PATTERN_CN_NAME_REGEX, customBodyObject.getName())) {
|
|
|
+ if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
|
|
|
+ ret.setResultCode(Constant.NAME_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.NAME_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.NAME_FORMAT_ERROR);
|
|
|
+ } else {
|
|
|
+ ret.setResultCode(Constant.JK_NAME_FORMAT_ERROR_CODE);
|
|
|
+ ret.setResultDesc(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ ret.setResultBody(Constant.JK_NAME_FORMAT_ERROR);
|
|
|
+ }
|
|
|
+ checkResult = false;
|
|
|
+ } else {
|
|
|
+ checkResult = true;
|
|
|
+ }
|
|
|
+ return checkResult;
|
|
|
+ }
|
|
|
}
|