Bläddra i källkod

增加接口:司机身份验证

15810770710@163.com 3 år sedan
förälder
incheckning
3f38906236

+ 4 - 0
src/main/java/info/aspirecn/iov/yysj/check/info/CheckInfo.java

@@ -107,4 +107,8 @@ public class CheckInfo {
 	public VehicleTrajectoryFilter addVehicleTrajectoryFilter() {
 		return new VehicleTrajectoryFilter();
 	}
+	@Bean
+	public DriverInfoFilter addDriverInfoFilter() {
+		return new DriverInfoFilter();
+	}
 }

+ 17 - 0
src/main/java/info/aspirecn/iov/yysj/check/info/common/CommonUtil.java

@@ -92,6 +92,17 @@ public class CommonUtil {
         }
         return false;
     }
+
+    // 交易司机信息核验url
+    public static boolean checkDriverInfoCheckUrl(String url) {
+        Constants.DriverInfoCheckUrl[] requestUrls = Constants.DriverInfoCheckUrl.values();
+        for (Constants.DriverInfoCheckUrl requestUrl : requestUrls) {
+            if (requestUrl.getValue().equals(url)) {
+                return true;
+            }
+        }
+        return false;
+    }
     //获取所有请求url
     public static boolean checkAllUrl(String url){
         Constants.RequestUrl[] requestUrls = Constants.RequestUrl.values();
@@ -113,6 +124,12 @@ public class CommonUtil {
                 return true;
             }
         }
+        Constants.DriverInfoCheckUrl[] driverInfoCheckUrls = Constants.DriverInfoCheckUrl.values();
+        for (Constants.DriverInfoCheckUrl requestUrl : driverInfoCheckUrls) {
+            if(requestUrl.getValue().equals(url)){
+                return true;
+            }
+        }
         return false;
     }
 

+ 43 - 0
src/main/java/info/aspirecn/iov/yysj/check/info/common/TransferParam.java

@@ -27,6 +27,7 @@ public class TransferParam {
 	private static final String WEIGHT_000 = "([0-9]){0,}.[0-9]{3}";
 	private static final String ID_CODE_REGEX = "^([1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$|^[1-9]\\" +
 			"d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X|x))$";
+	private static final String NAME_REGEX = "^[\\u4E00-\\u9FA5\\uf900-\\ufa2d\\u3400-\\u4DB5\\u20000-\\u2A6D6·s]{1,30}$";
 	/*
 	 * {"vehicleNumber":"新A93293","licensePlateTypeCode":"2","vehicleTonnage":"0"}
 	 */
@@ -94,6 +95,9 @@ public class TransferParam {
 		}
 		if ("16".equals(productId)) {
 			customBody = waybillHistoryPosition(paramMap, emptyList, errorList);
+		}
+		if ("17".equals(productId)) {
+			customBody = driverInfoCheck(paramMap, emptyList, errorList);
 		} else if (Constants.OtherRquestUrl.IDLENTITYVERIFICATION.getValue().equals(productId)) {// 身份核验
 			String req_id = paramMap.get(Constants.req_id);
 			if (StringUtils.isEmpty(req_id)) {
@@ -1018,6 +1022,41 @@ public class TransferParam {
 		return null;
 	}
 
+	// 校验项 司机身份验证
+	public Map<String, Object> driverInfoCheck(Map<String, String> requestMap, Set<String> emptyList, Set<String> errorList){
+		log.info("requestMap:{}", requestMap);
+		// 身份证号
+		String drivingLicense = requestMap.get(Constants.DRIVER_DRIVING_LICENSE);
+		// 姓名
+		String driverName = requestMap.get(Constants.DRIVER_NAME);
+
+		if (drivingLicense == null || StringUtils.isEmpty(drivingLicense)) {
+			emptyList.add(Constants.DRIVER_DRIVING_LICENSE);
+		} else {
+			if (!checkIdCode(drivingLicense)) {
+				errorList.add(Constants.DRIVER_DRIVING_LICENSE);
+			}
+		}
+
+		if (driverName == null || StringUtils.isEmpty(driverName)) {
+			emptyList.add(Constants.DRIVER_NAME);
+		} else {
+			if (!checkName(driverName)) {
+				errorList.add(Constants.DRIVER_NAME);
+			}
+		}
+
+		Map<String, Object> resultMap = new HashMap<String, Object>();
+		if (emptyList.size() == 0 && errorList.size() == 0) {
+			resultMap.put(Constants.driver_name,driverName);
+			resultMap.put(Constants.driver_idCode,drivingLicense);
+			log.info("参数拼接");
+			return resultMap;
+		}
+		log.info("参数校验失败");
+		return null;
+	}
+
 	public static boolean checkPlateColor(String plateColor) {
 		String[] vehiclePlateColorCodeArr = {"1", "2", "3", "4", "5", "9", "91", "92", "93", "94"};
 		return ArrayUtils.contains(vehiclePlateColorCodeArr, plateColor);
@@ -1289,6 +1328,10 @@ public class TransferParam {
 		return idCodePattern.matcher(idCode).matches();
 	}
 
+	public boolean checkName(String name){
+		Pattern namePattern = Pattern.compile(NAME_REGEX);
+		return namePattern.matcher(name).matches();
+	}
 	public static void main(String[] args) {
 		String certificateNumberReg = "[0-9a-zA-Z]{1,20}";
 		Pattern certificateNumberPattern = Pattern.compile(certificateNumberReg);

+ 2 - 0
src/main/java/info/aspirecn/iov/yysj/check/info/common/ZuulHelper.java

@@ -386,6 +386,8 @@ public class ZuulHelper {
 				return 13;
 			}else if (Constants.RequestUrl.VEHICLE_POSITION_CONSISTENCY_CHECK.getValue().equals(url)) {
 				return 14;
+			}else if (Constants.DriverInfoCheckUrl.DRIVER_INFO_URL.getValue().equals(url)) {
+				return 15;
 			}
 
 		return 0;

+ 17 - 0
src/main/java/info/aspirecn/iov/yysj/check/info/entity/DriverInfoResponseData.java

@@ -0,0 +1,17 @@
+package info.aspirecn.iov.yysj.check.info.entity;
+
+import lombok.AllArgsConstructor;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Data
+@NoArgsConstructor
+@AllArgsConstructor
+public class DriverInfoResponseData {
+    private String result;
+    private String errorInfo;
+}

+ 166 - 0
src/main/java/info/aspirecn/iov/yysj/check/info/pre/DriverInfoFilter.java

@@ -0,0 +1,166 @@
+package info.aspirecn.iov.yysj.check.info.pre;
+
+import com.alibaba.fastjson.JSON;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.netflix.zuul.ZuulFilter;
+import com.netflix.zuul.context.RequestContext;
+import info.aspirecn.cloud.yysj.commons.lang.BillItemResult;
+import info.aspirecn.cloud.yysj.commons.lang.Constants;
+import info.aspirecn.cloud.yysj.commons.lang.ProductCheckRequest;
+import info.aspirecn.iov.yysj.check.info.common.*;
+import info.aspirecn.iov.yysj.check.info.entity.BillResultObject;
+import info.aspirecn.iov.yysj.check.info.entity.CheckDetailLogObject;
+import info.aspirecn.iov.yysj.check.info.entity.DriverInfoResponseData;
+import info.aspirecn.iov.yysj.check.info.entity.VehicleTrajectoryObject;
+import info.aspirecn.iov.yysj.paramtransfer.inter.YysjUserActionInterface;
+import info.aspirecn.iov.yysj.paramtransfer.inter.vo.YysjProduct;
+import lombok.extern.slf4j.Slf4j;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
+
+import javax.servlet.http.HttpServletRequest;
+import java.util.*;
+
+/**
+ * @author xusonglin
+ * @version V1.0
+ **/
+@Slf4j
+public class DriverInfoFilter extends ZuulFilter {
+    @Autowired
+    private ZuulHelper helper;
+    @Autowired
+    private YysjUserActionInterface yysjUserActionInterface;
+    @Autowired
+    private ChannelRibbonHandle channelRibbonHandle;
+    @Autowired
+    private TransferParam transferParam;
+    @Autowired
+    private ObjectMapper mapper;
+
+    @Override
+    public boolean shouldFilter() {
+        RequestContext requestContext = RequestContext.getCurrentContext();
+        String url = requestContext.getRequest().getRequestURI();
+        log.info("DriverInfoFilter-- shouldFilter:{}, url:{}", CommonUtil.checkDriverInfoCheckUrl(url), url);
+        return CommonUtil.checkDriverInfoCheckUrl(url);
+    }
+
+    @Override
+    public Object run() {
+        RequestContext requestContext = RequestContext.getCurrentContext();
+        HttpServletRequest request = requestContext.getRequest();
+
+        //获取流水号
+        String traceId = (String) requestContext.get(Constants.HEADER_TRACEID_KEY);
+
+        requestContext.set(Constants.Url, request.getRequestURI());
+
+        //获取userId
+        String userId = request.getHeader(Constants.HEADER_USER_ID);
+        //获取url
+        String url = requestContext.getRequest().getRequestURI();
+        //根据url获取订购项类型
+        int type = helper.getType(url);
+        log.info("DriverInfoFilter-run()-userId:{},traceId:{},url:{},type:{}", userId, traceId, url, type);
+        //响应对象
+        try {
+
+            BillResultObject billResultObject = new BillResultObject();
+            billResultObject.setTraceId((String) requestContext.get(Constants.HEADER_TRACEID_KEY));
+            DriverInfoResponseData responseData = new DriverInfoResponseData();
+            try {
+                String consistent = Constants.consistent_code;
+                List<YysjProduct> yysjProducts = yysjUserActionInterface.getYysjProductIdByUserId(userId, type);
+                if (yysjProducts == null || yysjProducts.size() == 0) {
+                    throw new ResultCodeException(Constants.ResultDesc.NO_PERMISSION.getCode(), "未订购核验项", "根据类型和用户没有获取到校验资格项");
+
+                }
+                YysjProduct yysjProduct = yysjProducts.get(0);
+                //开始组装请求参数
+                Map<String, String> map = (Map<String, String>) requestContext.get("bodyMap");
+
+                String token = (String) requestContext.get(Constants.HEADER_TOKEN_KEY);
+                Set<String> emptyList = new HashSet<>();
+                Set<String> errorList = new HashSet<>();
+
+                // todo 此处之前传的第二个参数是url
+                Map<String, Object> cutomerMap = transferParam.getCustomBody(map, yysjProduct.getYysjProductCode(), emptyList, errorList);
+                if (emptyList.size() != 0) {
+                    String emptyNode = StringUtils.joinWith(",", emptyList.toArray());
+                    throw new ResultCodeException(Constants.ResultDesc.PARAMNULL.getCode(), emptyNode + "必填项为空", "存在空值在必须校验的项上" + emptyNode);
+
+                }
+                if (errorList.size() != 0) {
+                    String emptyNode = StringUtils.joinWith(",", errorList.toArray());
+                    throw new ResultCodeException(Constants.ResultDesc.PARAMERROR.getCode(), emptyNode + "参数不符合规格", "存在错误的校验项上" + emptyNode);
+
+                }
+
+                ProductCheckRequest productCheckRequest = new ProductCheckRequest();
+                productCheckRequest.setYysjProductId(yysjProduct.getYysjProductId());
+                productCheckRequest.setProductCode(yysjProduct.getYysjProductCode());
+                List<String> list = yysjProduct.getSjjhProductId();
+                productCheckRequest.setSjjhProductId(list);
+                productCheckRequest.setCustomBody(cutomerMap);
+                String requestBody = mapper.writeValueAsString(productCheckRequest);
+
+                BillItemResult billItemResult = channelRibbonHandle.channelRibbonHandle(token, requestBody, userId, traceId, yysjProduct.getYysjProductId());
+                if ("1".equals(billItemResult.getResult())) {
+                    //上游返回一致
+                    responseData.setResult("0");
+                } else {
+                    responseData.setResult("1");
+                    consistent = Constants.inconsistent_code;
+                    BillItemResult.ErrorResponse errorResponse = billItemResult.getExceptionInformation();
+                    String errorInfo = "";
+                    if (errorResponse.getCode() == Constants.ErrorCode.Exception.getErrorCode()) {
+                        errorInfo = Constants.errorInfo;
+                    } else if (errorResponse.getCode() == Constants.ErrorCode.MONEYNOTENOUGH.getErrorCode()) {
+                        errorInfo = Constants.moneyNotEnough;
+                    } else {
+                        Set<String> resultList = errorResponse.getResultList();
+//                        Set<String> resultSet = transferParam.resultTransferParam(yysjProduct.getYysjProductCode(), resultList);
+                        if (errorResponse.getCode() == Constants.ErrorCode.NULL.getErrorCode()) {
+                            errorInfo = "数据源为空";
+                        } else {
+                            errorInfo = "数据源为不一致";
+                        }
+                    }
+                    responseData.setErrorInfo(errorInfo);
+                }
+                request.setAttribute("consistent", consistent);
+                billResultObject.setResultCode(Constants.ResultDesc.SUCCESS.getCode());
+                billResultObject.setResultMsg(Constants.ResultDesc.SUCCESS.getValue());
+                billResultObject.setData(responseData);
+            } catch (ResultCodeException ex) {
+                log.error("resultCodeException:{}", ex);
+                billResultObject.setResultCode(ex.getCode());
+                billResultObject.setResultMsg(ex.getMessage());
+
+            } catch (Exception ex) {
+                log.error("Exception:{}", ex);
+                billResultObject.setResultCode(Constants.ResultDesc.SERVERERROR.getCode());
+                billResultObject.setResultMsg(Constants.ResultDesc.SERVERERROR.getValue());
+
+            }
+            helper.responseHandle(billResultObject, requestContext, false);
+        } catch (JsonProcessingException e) {
+            log.error("解析对象出错,message:{}", e);
+        }
+        return null;
+
+    }
+
+    @Override
+    public String filterType() {
+        return FilterConstants.PRE_TYPE;
+    }
+
+    @Override
+    public int filterOrder() {
+        return FilterConstants.SERVLET_30_WRAPPER_FILTER_ORDER + 4;
+    }
+}