|
@@ -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;
|
|
|
+ }
|
|
|
+}
|