package info.aspirecn.iov.sjjh.supplier10000034.service; import java.io.IOException; import java.net.SocketTimeoutException; import java.util.ArrayList; import java.util.List; import javax.servlet.http.HttpServletRequest; import org.apache.commons.lang.math.NumberUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException; import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject; import info.aspirecn.iov.sjjh.commons.lang.Constant; import info.aspirecn.iov.sjjh.commons.lang.PatternTools; import info.aspirecn.iov.sjjh.supplier10000034.SjjhConstants; import info.aspirecn.iov.sjjh.supplier10000034.gjwl.Response; import info.aspirecn.iov.sjjh.supplier10000034.gjwl.util.PostUtil; import info.aspirecn.iov.sjjh.supplier10000034.vo.EnterprisePermitRequestObject; import info.aspirecn.iov.sjjh.supplier10000034.vo.EnterprisePermitResponseObject; import info.aspirecn.iov.sjjh.supplier10000034.vo.PersonQualificationRequestObject; import info.aspirecn.iov.sjjh.supplier10000034.vo.PersonQualificationResponseObject; import info.aspirecn.iov.sjjh.supplier10000034.vo.PersonQualificationResponseObject.QualificationCertificateInfo; import info.aspirecn.iov.sjjh.supplier10000034.vo.ResultBody; import info.aspirecn.iov.sjjh.supplier10000034.vo.VehiclePermitSecondJsonResolveObject; import info.aspirecn.iov.sjjh.supplier10000034.vo.VehiclePermitSjxyRequstObject; import info.aspirecn.iov.sjjh.supplier10000034.vo.VehicleRoadTransportResponseObject; import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils; import lombok.extern.slf4j.Slf4j; /** * * @author bzh * */ @Slf4j @Service public class Supplier10000034SecondServiceImpl implements Supplier10000034SecondService { @Value("${custom.appKey}") private String appKey; @Value("${custom.appSecret}") private String appSecret; @Value("${custom.enterpriseUrl}") private String enterpriseUrl; @Value("${custom.personUrl}") private String personUrl; @Value("${custom.checkVehicleRoadTransportUrl}") private String checkVehicleRoadTransportUrl; @Value("${custom.urlCheckVehicleExist}") private String urlCheckVehicleExist; @Value("${custom.enterpriseV2Url}") private String enterpriseV2Url; @Value("${custom.personV2Url}") private String personV2Url; @Value("${custom.sleepTime}") private String sleepTime; @Autowired private ObjectMapper objectMapper; /** *企业道路运输经营许可证核查 */ @Override public ChannelTypeHandleResponseObject checkEnterprisePermit(HttpServletRequest request, String customBody, int outTime) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setCode(Constant.SUCCESS); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if(StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } try { if (outTime <= SjjhConstants.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } log.info("supplier10000034.checkEnterprisePermit---customBody={},outTime={}", customBody, outTime); ObjectMapper mapper = new ObjectMapper(); EnterprisePermitRequestObject jsonResolveObject = mapper.readValue(customBody, EnterprisePermitRequestObject.class); String entName = jsonResolveObject.getEntName(); String permitNumber = jsonResolveObject.getPermitNumber(); String provinceCode = jsonResolveObject.getProvinceCode(); //参数校验 log.info("supplier10000034.checkEnterprisePermit---requestObject={},请求url:{}", JSON.toJSON(jsonResolveObject),enterpriseV2Url); List paramErrorResultList = new ArrayList<>(); if (StringUtils.isBlank(permitNumber)) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER); } if (StringUtils.isBlank(provinceCode)&&provinceCode.length()!=6) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); } if (!paramErrorResultList.isEmpty()) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } else { ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } ret.setResultDesc(Constant.INVALID_PARAMETER); ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); resultBody.setResultList(paramErrorResultList); ret.setResultBody(resultBody); return ret; } JSONObject jsonObject = new JSONObject(); jsonObject.put(SjjhConstants.ERROR_RETURN_PERMITNUMBER, permitNumber); jsonObject.put(SjjhConstants.ERROR_RETURN_PROVINCECODE, provinceCode); String body = jsonObject.toJSONString(); Response responseContext = PostUtil.postString(enterpriseV2Url, body, appKey, appSecret,outTime); log.info("supplier10000034.checkEnterprisePermit接口responseContext={}", responseContext.getBody()); EnterprisePermitResponseObject responseObject = objectMapper.readValue( responseContext.getBody(), EnterprisePermitResponseObject.class); log.info("supplier10000034.checkEnterprisePermit接口responseObject={}", responseObject); ret = setCheckEnterprisePermit(ret, returnType, entName, permitNumber, responseObject); if(responseObject != null) { upstreamCode = responseObject.getResultCode(); } } catch (SocketTimeoutException ste) { ErrorUtils.captureException(ste); log.info("supplier10000034.checkEnterprisePermit接口SocketTimeoutException={}", ste); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (UnrecognizedPropertyException upe) { log.info("supplier10000034.checkEnterprisePermit-UnrecognizedPropertyException:{}", upe); ErrorUtils.captureException(upe); ret.setCode(Constant.SUCCESS); ret.setIsCharge(Constant.IS_NOT_CHARGE); /**参数错误*/ if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } else { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_ENTNAME); resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER); resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); return ret; } catch (Exception ioe) { log.info("supplier10000034.checkVehicleRoadTransport接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } /** * 填充企业道路运输经营许可证核查接口的返回对象 * @param ret * @param returnType * @param responseObject * @return */ public ChannelTypeHandleResponseObject setCheckEnterprisePermit(ChannelTypeHandleResponseObject ret, String returnType,String entName,String permitNumber,EnterprisePermitResponseObject responseObject) { String resultCode = responseObject.getResultCode(); if (SjjhConstants.RESULT_CODE_0.equals(resultCode)) { // 查询成功,返回结果 ret.setIsCharge(Constant.INTERFACE_QUERY_FEE); //1、源数据是否为空 List resultList = new ArrayList<>(); if(StringUtils.isBlank(responseObject.getData().getEnterpriseName())){ resultList.add(SjjhConstants.ERROR_RETURN_ENTNAME); } if(StringUtils.isBlank(responseObject.getData().getPermitNumber())){ resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER); } if(!resultList.isEmpty()){ //数据源为空响应 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH); } else { ret.setResultCode(Constant.UN_MATCH_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_ONE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else { //2、数据是否一致 if(StringUtils.isNotBlank(entName)&&!entName.equalsIgnoreCase(responseObject.getData().getEnterpriseName())){ resultList.add(SjjhConstants.ERROR_RETURN_ENTNAME); } else if(StringUtils.isNotBlank(permitNumber)&&!permitNumber.equalsIgnoreCase(responseObject.getData().getPermitNumber())){ resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER); } if(!resultList.isEmpty()){ //数据不一致响应 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH); } else { ret.setResultCode(Constant.UN_MATCH_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_TWO); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else { //数据一致响应 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_MATCH); } else { ret.setResultCode(Constant.MATCH_CODE); } ret.setResultBody(responseObject.getData()); } } } else if(SjjhConstants.INTERFACE_CODE_110000.equals(resultCode)) { if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){ ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO); } else { ret.setResultCode(Constant.UN_FIND_NUM_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER); resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); }else if(SjjhConstants.INTERFACE_CODE_140002.equals(resultCode)){ /**参数错误*/ if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } else { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER); resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); }else { // 其他错误 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR); } else { ret.setResultCode(Constant.OTHER_ERROR_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER); resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } return ret; } /** *人员从业资格证核查 */ @Override public ChannelTypeHandleResponseObject checkPersonQualification(HttpServletRequest request, String customBody, int outTime) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setCode(Constant.SUCCESS); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if(StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } try { if (outTime <= SjjhConstants.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } log.info("supplier10000034.checkPersonQualification---customBody={},outTime={}", customBody, outTime); ObjectMapper mapper = new ObjectMapper(); PersonQualificationRequestObject jsonResolveObject = mapper.readValue(customBody, PersonQualificationRequestObject.class); String name = jsonResolveObject.getNameOfPerson(); String idCode = jsonResolveObject.getIdentityDocumentNumber(); String qualificationCertificateNumber = jsonResolveObject.getQualificationCertificateNumber(); String provinceCode = jsonResolveObject.getProvinceCode(); //参数校验 log.info("supplier10000034.checkPersonQualification---requestObject={},请求url:{}", JSON.toJSON(jsonResolveObject),personV2Url); List paramErrorResultList = new ArrayList<>(); if (StringUtils.isBlank(name)&&!PatternTools.checkResult(Constant.PATTERN_CN_NAME_REGEX,name)) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON); } if (StringUtils.isBlank(provinceCode)&&provinceCode.length()!=6) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); } if (StringUtils.isBlank(idCode)&&StringUtils.isBlank(qualificationCertificateNumber)) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER); paramErrorResultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); } if(StringUtils.isNotEmpty(idCode) && !PatternTools.checkResult(Constant.PATTERN_ID_NUMBER_REGEX,idCode)){ paramErrorResultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); } if (!paramErrorResultList.isEmpty()) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } else { ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } ret.setResultDesc(Constant.INVALID_PARAMETER); ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); resultBody.setResultList(paramErrorResultList); ret.setResultBody(resultBody); return ret; } String body = objectMapper.writeValueAsString(jsonResolveObject); Response responseContext = PostUtil.postString(personV2Url, body, appKey, appSecret,outTime); log.info("supplier10000034.checkPersonQualification接口responseContext={}", responseContext.getBody()); PersonQualificationResponseObject responseObject = objectMapper.readValue( responseContext.getBody(), PersonQualificationResponseObject.class); log.info("supplier10000034.checkPersonQualification接口responseObject={}", responseObject); ret = setCheckPersonQualification(ret, returnType, name, idCode, provinceCode, qualificationCertificateNumber, responseObject); if(responseObject != null) { upstreamCode = responseObject.getResultCode(); } } catch (SocketTimeoutException ste) { ErrorUtils.captureException(ste); log.info("supplier10000034.checkPersonQualification接口SocketTimeoutException={}", ste); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (UnrecognizedPropertyException upe) { log.info("supplier10000034.checkPersonQualification-UnrecognizedPropertyException:{}", upe); ErrorUtils.captureException(upe); ret.setCode(Constant.SUCCESS); ret.setIsCharge(Constant.IS_NOT_CHARGE); /**参数错误*/ if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } else { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON); resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER); resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); return ret; } catch (Exception ioe) { log.info("supplier10000034.checkPersonQualification接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } /** * 填充人员从业资格证核查接口的返回对象 * @param ret * @param returnType * @param name * @param idCode * @return */ public ChannelTypeHandleResponseObject setCheckPersonQualification(ChannelTypeHandleResponseObject ret, String returnType,String name,String idCode,String provinceCode, String qualificationCertificateNumber,PersonQualificationResponseObject responseObject) { String resultCode = responseObject.getResultCode(); if (SjjhConstants.RESULT_CODE_0.equals(resultCode)) { // 查询成功,返回结果 ret.setIsCharge(Constant.INTERFACE_QUERY_FEE); //1、源数据是否为空 List resultList = new ArrayList<>(); if (StringUtils.isNotBlank(name) && StringUtils.isBlank(responseObject.getData().getNameOfPerson())) { resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON); } if (StringUtils.isNotBlank(idCode) && StringUtils.isBlank(responseObject.getData().getIdentityDocumentNumber())) { resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); } if (StringUtils.isNotBlank(qualificationCertificateNumber)) { for (QualificationCertificateInfo qualificationCertificateInfo : responseObject.getData().getQualificationCertificateInfo()) { if(StringUtils.isBlank(qualificationCertificateInfo.getQualificationCertificateNumber())){ resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER); } } } if(!resultList.isEmpty()){ //数据源为空响应 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH); } else { ret.setResultCode(Constant.UN_MATCH_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_ONE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else { //2、数据是否一致 if (StringUtils.isNotBlank(name) && !name.equalsIgnoreCase(responseObject.getData().getNameOfPerson())) { resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON); } if(StringUtils.isNotBlank(idCode) && !idCode.equalsIgnoreCase(responseObject.getData().getIdentityDocumentNumber())){ resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); } if(StringUtils.isNotBlank(provinceCode) && !provinceCode.equalsIgnoreCase(responseObject.getData().getProvinceCode())){ resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); } if (StringUtils.isNotBlank(qualificationCertificateNumber)) { for (QualificationCertificateInfo qualificationCertificateInfo : responseObject.getData().getQualificationCertificateInfo()) { if(StringUtils.isNotBlank(qualificationCertificateInfo.getQualificationCertificateNumber()) && !qualificationCertificateNumber.equalsIgnoreCase(qualificationCertificateInfo.getQualificationCertificateNumber())){ resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER); } } } if(!resultList.isEmpty()){ //数据不一致响应 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH); } else { ret.setResultCode(Constant.UN_MATCH_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_TWO); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else { //数据一致响应 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_MATCH); } else { ret.setResultCode(Constant.MATCH_CODE); } ret.setResultBody(responseObject.getData()); } } } else if(SjjhConstants.INTERFACE_CODE_110000.equals(resultCode)) { if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){ ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO); } else { ret.setResultCode(Constant.UN_FIND_NUM_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_ONE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON); if (StringUtils.isNotBlank(idCode)) { resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); } if (StringUtils.isNotBlank(qualificationCertificateNumber)) { resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER); } resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); } else if(SjjhConstants.INTERFACE_CODE_140002.equals(resultCode)){ /**参数错误*/ if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){ ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } else { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON); if (StringUtils.isNotBlank(idCode)) { resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); } if (StringUtils.isNotBlank(qualificationCertificateNumber)) { resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER); } resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); } else { // 其他错误 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR); } else { ret.setResultCode(Constant.OTHER_ERROR_CODE); } ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON); if (StringUtils.isNotBlank(idCode)) { resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER); } if (StringUtils.isNotBlank(qualificationCertificateNumber)) { resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER); } resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } return ret; } @Override public ChannelTypeHandleResponseObject checkVehicleRoadTransport(HttpServletRequest request, String customBody, int outTime) { ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject(); ret.setCode(Constant.SUCCESS); ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE); String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE; request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA); if(StringUtils.isBlank(returnType)) { returnType = Constant.CUSTOMER_RETURN_ZW; } try { if (outTime <= SjjhConstants.PARA_ZERO) { outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT; } log.info("supplier10000034.checkVehicleRoadTransport---customBody={},outTime={}", customBody, outTime); ObjectMapper mapper = new ObjectMapper(); VehiclePermitSecondJsonResolveObject jsonResolveObject = mapper.readValue(customBody, VehiclePermitSecondJsonResolveObject.class); String carNumber = jsonResolveObject.getVehicleNumber(); String colorType = jsonResolveObject.getVehiclePlateColorCode(); String vin = jsonResolveObject.getVin(); String roadNumber = jsonResolveObject.getRoadTransportCertificateNumber(); //参数校验 log.info("supplier10000034.checkVehicleRoadTransport---requestObject={}", jsonResolveObject); List paramErrorResultList = new ArrayList<>(); //车牌号校验 if (StringUtils.isBlank(carNumber) || !PatternTools.checkResult(SjjhConstants.PARA_THREE, carNumber)) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_VEHICLENUMBER); } //车颜色校验 if (StringUtils.isBlank(colorType) || (!SjjhConstants.PARA_COLOR_ONE.equals(colorType) && !SjjhConstants.PARA_COLOR_TWO.equals(colorType))) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_COLOR_CODE); } //VIN和道路运输证号非空校验 if (StringUtils.isBlank(vin) && StringUtils.isBlank(roadNumber)) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_VIN); paramErrorResultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER); } //道路运输证号不为空且全是数字 if (StringUtils.isNotBlank(roadNumber) && !NumberUtils.isNumber(roadNumber)) { paramErrorResultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER); } if (!paramErrorResultList.isEmpty()) { if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } else { ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } ret.setResultDesc(Constant.INVALID_PARAMETER); ResultBody resultBody = new ResultBody(); resultBody.setCode(SjjhConstants.PARA_THREE); resultBody.setResultList(paramErrorResultList); ret.setResultBody(resultBody); return ret; } //请求的body,json格式 VehiclePermitSjxyRequstObject requestObject = new VehiclePermitSjxyRequstObject(); requestObject.setLicensePlateTypeCode(colorType); requestObject.setVehicleNumber(carNumber); String body = objectMapper.writeValueAsString(requestObject); log.info("supplier10000034.checkVehicleRoadTransport接口body={},url={}", body, checkVehicleRoadTransportUrl); info.aspirecn.iov.sjjh.supplier10000034.gjwl.Response response = PostUtil.postString( checkVehicleRoadTransportUrl, body, appKey, appSecret, outTime); String responseContext = response.getBody(); log.info("supplier10000034.checkVehicleRoadTransport接口responseContext={}", responseContext); VehicleRoadTransportResponseObject responseObject = mapper.readValue( responseContext, VehicleRoadTransportResponseObject.class); String resultCode = ""; if(responseObject != null) { upstreamCode = responseObject.getResultCode(); resultCode = responseObject.getResultCode(); } ret = setCheckVehicleRoadTransport(ret, returnType, vin, roadNumber, resultCode, responseObject); } catch (SocketTimeoutException ste) { ErrorUtils.captureException(ste); log.info("supplier10000034.checkVehicleRoadTransport接口SocketTimeoutException={}", ste); ret.setCode(Constant.REQUEST_TIMEOUT); } catch (UnrecognizedPropertyException upe) { log.info("supplier10000034.checkVehicleRoadTransport-UnrecognizedPropertyException:{}", upe); ErrorUtils.captureException(upe); ret.setCode(Constant.SUCCESS); ret.setIsCharge(Constant.IS_NOT_CHARGE); /**参数错误*/ if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){ ret.setResultCode(Constant.JK_RETURN_CODE_9909); } else { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } ret.setResultBody(Constant.PARAMETER_NAME_ERROR); ret.setResultDesc(Constant.PARAMETER_NAME_ERROR); return ret; } catch (Exception ioe) { log.info("supplier10000034.checkVehicleRoadTransport接口-Exception:{}", ioe); ErrorUtils.captureException(ioe); ret.setCode(Constant.FAIL); } request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode); return ret; } /** * 填充核车辆道路运输许可证信息接口的返回对象 * @param ret * @param returnType * @param vin * @param roadNumber * @param responseObject * @return */ public ChannelTypeHandleResponseObject setCheckVehicleRoadTransport(ChannelTypeHandleResponseObject ret, String returnType,String vin,String roadNumber,String resultCode, VehicleRoadTransportResponseObject responseObject) { ResultBody resultBody = new ResultBody(); if (responseObject != null && responseObject.getData() != null && SjjhConstants.RESULT_CODE_0.equals(resultCode)) { // 查询成功,返回结果 ret.setIsCharge(Constant.INTERFACE_QUERY_FEE); //1、源数据是否为空 List resultList = new ArrayList<>(); if(StringUtils.isBlank(responseObject.getData().getVehicleNumber())){ resultList.add(SjjhConstants.ERROR_RETURN_VEHICLENUMBER); } if(StringUtils.isBlank(responseObject.getData().getLicensePlateTypeCode())){ resultList.add(SjjhConstants.ERROR_RETURN_COLOR_CODE); } if(StringUtils.isNotBlank(roadNumber) && StringUtils.isBlank(responseObject.getData().getRoadTransportCertificateNumber())){ resultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER); } if(StringUtils.isNotBlank(vin) && StringUtils.isBlank(responseObject.getData().getVinNo())){ resultList.add(SjjhConstants.ERROR_RETURN_VIN); } if(!resultList.isEmpty()){ //数据源为空响应 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH); } else { ret.setResultCode(Constant.UN_MATCH_CODE); } resultBody.setCode(SjjhConstants.PARA_ONE); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else { //2、数据是否一致 if(StringUtils.isNotBlank(roadNumber) && StringUtils.isBlank(vin)){ if(!roadNumber.equalsIgnoreCase(responseObject.getData().getRoadTransportCertificateNumber())) { resultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER); } } else if(StringUtils.isBlank(roadNumber) && StringUtils.isNotBlank(vin)){ if(!vin.equalsIgnoreCase(responseObject.getData().getVinNo())) { resultList.add(SjjhConstants.ERROR_RETURN_VIN); } } else if(!vin.equalsIgnoreCase(responseObject.getData().getVinNo())) { resultList.add(SjjhConstants.ERROR_RETURN_VIN); } if(!resultList.isEmpty()){ //数据不一致响应 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH); } else { ret.setResultCode(Constant.UN_MATCH_CODE); } resultBody.setCode(SjjhConstants.PARA_TWO); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else { //数据一致响应 if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_MATCH); } else { ret.setResultCode(Constant.MATCH_CODE); } ret.setResultBody(responseObject.getData()); } } } else if(SjjhConstants.INTERFACE_CODE_110000.equals(resultCode)) { // 查询结果为空 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO); } else { ret.setResultCode(Constant.UN_FIND_NUM_CODE); } resultBody.setCode(SjjhConstants.PARA_ONE); List resultList = getErrorParamList(); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else if(SjjhConstants.INTERFACE_CODE_140002.equals(resultCode)) { // 参数错误 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER); } else { ret.setResultCode(Constant.INVALID_PARAMETER_CODE); } resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = getErrorParamList(); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } else { // 其他错误 if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) { ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR); } else { ret.setResultCode(Constant.OTHER_ERROR_CODE); } resultBody.setCode(SjjhConstants.PARA_THREE); List resultList = getErrorParamList(); resultBody.setResultList(resultList); ret.setResultBody(resultBody); } return ret; } /** * 获取错误返回中相关参数LIST * @return */ private List getErrorParamList() { List resultList = new ArrayList<>(); resultList.add(SjjhConstants.ERROR_RETURN_VEHICLENUMBER); resultList.add(SjjhConstants.ERROR_RETURN_COLOR_CODE); resultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER); resultList.add(SjjhConstants.ERROR_RETURN_VIN); return resultList; } }