|
@@ -0,0 +1,179 @@
|
|
|
+package info.aspirecn.iov.yysj.check.info.pre;
|
|
|
+
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashSet;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.Set;
|
|
|
+
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+
|
|
|
+import info.aspirecn.iov.yysj.check.info.entity.BillResultObject;
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.cloud.netflix.zuul.filters.support.FilterConstants;
|
|
|
+
|
|
|
+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.ChannelRibbonHandle;
|
|
|
+import info.aspirecn.iov.yysj.check.info.common.CommonUtil;
|
|
|
+import info.aspirecn.iov.yysj.check.info.common.ResultCodeException;
|
|
|
+import info.aspirecn.iov.yysj.check.info.common.TransferParam;
|
|
|
+import info.aspirecn.iov.yysj.check.info.common.ZuulHelper;
|
|
|
+import info.aspirecn.iov.yysj.check.info.entity.CheckDetailLogObject;
|
|
|
+import info.aspirecn.iov.yysj.check.info.entity.RoadTransportObject;
|
|
|
+import info.aspirecn.iov.yysj.check.info.entity.RoadTransportObject.VerifyResultSet;
|
|
|
+import info.aspirecn.iov.yysj.check.info.entity.RoadTransportObject.VerifyResultSet.Errorresult;
|
|
|
+import info.aspirecn.iov.yysj.paramtransfer.inter.YysjUserActionInterface;
|
|
|
+import info.aspirecn.iov.yysj.paramtransfer.inter.vo.YysjProduct;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+@Slf4j
|
|
|
+public class RoadTransportFilter 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();
|
|
|
+ return CommonUtil.checkRoadTransUrl(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);
|
|
|
+
|
|
|
+ //响应对象
|
|
|
+
|
|
|
+
|
|
|
+ try{
|
|
|
+
|
|
|
+ BillResultObject billResultObject = new BillResultObject();
|
|
|
+ VerifyResultSet verifyResultSet =new VerifyResultSet();
|
|
|
+ RoadTransportObject roadTransportObject = new RoadTransportObject(verifyResultSet,null);
|
|
|
+ billResultObject.setTraceId((String)requestContext.get(Constants.HEADER_TRACEID_KEY));
|
|
|
+ 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);
|
|
|
+ List<CheckDetailLogObject> checkDetails = new ArrayList<CheckDetailLogObject>();
|
|
|
+ Set<String> emptyList = new HashSet<>();
|
|
|
+ Set<String> erroList = new HashSet<>();
|
|
|
+
|
|
|
+ Map<String,Object> cutomeMap= transferParam.getCustomBody(map,url,emptyList,erroList);
|
|
|
+ if(emptyList.size()!=0){
|
|
|
+ String emptyNode = StringUtils.joinWith(",",emptyList.toArray());
|
|
|
+ throw new ResultCodeException(Constants.ResultDesc.PARAMNULL.getCode(),emptyNode+"必填项为空","存在空值在必须校验的项上"+emptyNode);
|
|
|
+
|
|
|
+ }
|
|
|
+ if(erroList.size()!=0){
|
|
|
+ String emptyNode = StringUtils.joinWith(",",erroList.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(cutomeMap);
|
|
|
+ String requestBody = mapper.writeValueAsString(productCheckRequest);
|
|
|
+
|
|
|
+ BillItemResult billItemResult = channelRibbonHandle.channelRibbonHandle(token, requestBody, userId, traceId, yysjProduct.getYysjProductId());
|
|
|
+ if("1".equals(billItemResult.getResult())) {//上游返回一致
|
|
|
+ String detail = billItemResult.getDetail();
|
|
|
+ Object object = helper.transResponse(url, detail);
|
|
|
+ verifyResultSet.setCorrectResult(object);
|
|
|
+ }else {
|
|
|
+ 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="数据源" + StringUtils.join(resultSet.toArray(), ",") + "为空";
|
|
|
+ } else {
|
|
|
+ errorInfo="数据源" + StringUtils.join(resultSet.toArray(), ",") + "为不一致";
|
|
|
+ }
|
|
|
+ }
|
|
|
+ Errorresult errorresult = new Errorresult();
|
|
|
+ errorresult.setErrorInfo(errorInfo);
|
|
|
+ verifyResultSet.setErrorResult(errorresult);
|
|
|
+ }
|
|
|
+ request.setAttribute("consistent",consistent);
|
|
|
+ billResultObject.setResultCode(Constants.ResultDesc.SUCCESS.getCode());
|
|
|
+ billResultObject.setResultMsg(Constants.ResultDesc.SUCCESS.getValue());
|
|
|
+ billResultObject.setData(roadTransportObject);
|
|
|
+ } 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 + 6;
|
|
|
+ }
|
|
|
+}
|