package com.ydtech.modules.ins.service.impl; import cn.hutool.core.collection.CollUtil; import com.alibaba.fastjson.JSONObject; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.*; import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.ydtech.components.InsAlltrustRequestApiComponents; import com.ydtech.constants.InsTaskHistoryEnum; import com.ydtech.constants.SysConstants; import com.ydtech.constants.enums.InsOrderStatus; import com.ydtech.constants.enums.InsQuoteFlow; import com.ydtech.constants.enums.dict.AttachInsureEnum; import com.ydtech.constants.enums.dict.WhetherEnum; import com.ydtech.core.page.HttpResult; import com.ydtech.exception.SystemException; import com.ydtech.modules.admin.service.SysDeptService; import com.ydtech.modules.admin.service.SysUserService; import com.ydtech.modules.esm.dao.EsmInsAttachInsureDetailsMapper; import com.ydtech.modules.esm.dao.EsmInsAttachInsureMapper; import com.ydtech.modules.esm.model.*; import com.ydtech.modules.esm.service.*; import com.ydtech.modules.ins.dao.InsAlltrustRegionMapper; import com.ydtech.modules.ins.model.InsApiLog; import com.ydtech.modules.ins.model.InsOrder; import com.ydtech.modules.ins.model.vo.CarInfoVo; import com.ydtech.modules.ins.model.vo.CustomerInfoVo; import com.ydtech.modules.ins.model.vo.QuoteRespVo; import com.ydtech.modules.ins.model.vo.RiskInfoVo; import com.ydtech.modules.ins.model.ya.CarModelDTO; import com.ydtech.modules.ins.model.ya.CarModel_Req; import com.ydtech.modules.ins.model.ya.YaQuoteInfoVo; import com.ydtech.modules.ins.model.yc.*; import com.ydtech.modules.ins.model.yc.accident.response.ResponseYwCvrg; import com.ydtech.modules.ins.model.yc.audit.Audit; import com.ydtech.modules.ins.model.yc.audit.response.AuditResponse; import com.ydtech.modules.ins.model.yc.callbackAnOrder.CallbackAnOrder; import com.ydtech.modules.ins.model.yc.imageUp.ImageUp; import com.ydtech.modules.ins.model.yc.imageUp.response.ImageUpResponse; import com.ydtech.modules.ins.model.yc.modelsQuery.ModelsQueryResponse; import com.ydtech.modules.ins.model.yc.modelsQuery.ModelsQueryXml; import com.ydtech.modules.ins.model.yc.accident.Accident; import com.ydtech.modules.ins.model.yc.pay.Pay; import com.ydtech.modules.ins.model.yc.pay.response.AccidentResponse; import com.ydtech.modules.ins.model.yc.pay.response.PayResponse; import com.ydtech.modules.ins.model.yc.policy.Policy; import com.ydtech.modules.ins.model.yc.policy.response.PolicyResponse; import com.ydtech.modules.ins.model.yc.ruote.*; import com.ydtech.modules.ins.model.yc.ruote.response.RuoteResponse; import com.ydtech.modules.ins.model.yc.ruote.response.TfiWarnListResponse; import com.ydtech.modules.ins.service.*; import com.ydtech.modules.order.components.ConfigureParametersComponents; import com.ydtech.modules.order.components.InsOrdersComponents; import com.ydtech.modules.order.entity.InsAreaCompany; import com.ydtech.modules.order.entity.InsOrders; import com.ydtech.modules.order.entity.vo.*; import com.ydtech.modules.order.service.InsAreaCompanyService; import com.ydtech.modules.order.service.InsOrdersService; import com.ydtech.modules.protocol.utils.AssertionUtils; import com.ydtech.utils.*; import com.ydtech.utils.baidu.FileUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.io.IOException; import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Collectors; @Service public class InsAlltrustApiServiceImpl implements InsAlltrustApiService { private static final Logger log = LoggerFactory.getLogger("alltrust"); @Autowired private InsAlltrustRequestApiComponents apiComponents; @Autowired private InsAlltrustRegionMapper insAlltrustRegionMapper; @Autowired private InsOrdersComponents insOrdersComponents; private AuthorityDataXml authorityDataXml = null; private ObjectMapper xmlMapper = null; //请求信息列表 List requestInfoList = new ArrayList<>(); @Value("${upload.file.path}") private String uploadFilePath; @Value("${upload.file.url}") private String showFileUrl; @Value("${api.url}") private String apiUrl; @Autowired private YcBuildData ycBuildData; @Autowired private SysUserService sysUserService; @Autowired private SysDeptService sysDeptService; @Autowired private EsmRetailService esmRetailService; @Autowired private EsmAgreementService esmAgreementService; @Autowired private EsmAgreementProdService esmAgreementProdService; // @Autowired // private EsmUserInternalService esmUserInternalService; @Autowired private InsTaskHistoryService insTaskHistoryService; @Autowired private InsAreaCompanyService insAreaCompanyService; @Autowired private InsOrdersService insOrdersService; @Autowired private InsTaskImageService insTaskImageService; @Autowired private EsmInsAttachInsureMapper esmInsAttachInsureMapper; @Autowired private EsmInsAttachInsureDetailsMapper esmInsAttachInsureDetailsMapper; @Autowired private EsmInsCompanyService esmInsCompanyService; @Autowired InsApiLogService insApiLogService; @Autowired ConfigureParametersComponents configureParametersComponents; // /** // * @description: 获取验证数据 // * @author: lig // * @date: 2023年02月07日 0007 // */ // private AuthorityDataXml gainAuthorityDataXml() { // if (null == authorityDataXml) { // authorityDataXml = new AuthorityDataXml(); // authorityDataXml.setUserName(apiComponents.getUserName()); // authorityDataXml.setPassword(apiComponents.getPassword()); // } // return authorityDataXml; // } // /** // * 获取渠道 // */ // public Agent gainAgent() { // return apiComponents.gainAgent(); //// if (null == agent) { //// agent = new Agent(); //// agent.setAgentCode(agentCode); //// agent.setConferCode(agentType); //// agent.setAgentType(agentType); //// agent.setAgentNme(agentNme); //// agent.setQlftNo(qlftNo); //// agent.setCustNature(custNature); //// agent.setAgentProfId(agentCode); //// agent.setSubCoNo(agentType); //// } //// return agent; // } private ObjectMapper gainXmlMapper() { if (null == xmlMapper) { xmlMapper = new XmlMapper(); xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); xmlMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false); xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE); xmlMapper.enable(MapperFeature.USE_STD_BEAN_NAMING); xmlMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); } return xmlMapper; } // //==============================API 方式 // public void gainVehicleModel(YcConfigureParameters ycConfigureParameters, CarInfoVo carInfo) { CarModel_Req carModelReq = new CarModel_Req(); carModelReq.setFrameNo(carInfo.getFrameNo()); carModelReq.setEngineNo(carInfo.getEngineNo()); carModelReq.setEnrollDate(carInfo.getRegisterDate().replaceAll("-", "")); log.info("===永诚--车型查询接口请求 =====参数确认:--" + ycConfigureParameters.getDptCde() + "==="); ModelsQueryXml m = buildModelsQueryParam(carModelReq, ycConfigureParameters); ObjectMapper xmlMapper = this.gainXmlMapper(); log.info("===永诚--车型查询接口请求开始--" + carInfo.getLicenseNo() + "==="); // InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_MODEL); String responseData = httpPostResultLog(xmlMapper, m, YcBuildData.API_MODEL, "永诚API方式 - 车型查询 - "); // String responseData = apiLog.getResponseData(); log.info("===永诚--车型查询接口请求结束--" + carInfo.getLicenseNo() + "==="); ModelsQueryResponse rd = null; try { String cleanStr = YcBuildData.cleanResponseStr(responseData); rd = xmlMapper.readValue(cleanStr, ModelsQueryResponse.class); // List vehicleInfoList = buildCarModel(rd); } catch (IOException e) { throw new SystemException("车型查询接口异常,请联系管理。"); } if (CollUtil.isEmpty(rd.getVehicleInfoList())) throw new SystemException("永诚车型库查找失败"); //获取上市年份大于等于注册日期的车辆信息 List vehicleInfoList = rd.getVehicleInfoList().stream().filter(a -> DateTimeUtil.dateIsAfter(carInfo.getRegisterDate(), a.getVehicleYear())).collect(Collectors.toList()); //匹配的车辆信息数据 为空 if (CollUtil.isEmpty(vehicleInfoList)) { carInfo.setModelCode(rd.getVehicleInfoList().get(0).getVehicleId()); // carInfo.setCiModelCode(a.getModelCode()); carInfo.setCiCarName(rd.getVehicleInfoList().get(0).getVehicleName()); carInfo.setModelcname(rd.getVehicleInfoList().get(0).getVehicleName()); return; } //匹配的车辆信息数据 ModelsQueryResponse.VehicleInfo matchVehicleInfo = vehicleInfoList.stream().filter(a -> a.getVehiclePrice().equals(carInfo.getPurchasePrice())).findFirst().orElse(null); if (null != matchVehicleInfo) { carInfo.setModelCode(matchVehicleInfo.getVehicleId()); carInfo.setCiCarName(matchVehicleInfo.getVehicleName()); carInfo.setModelcname(matchVehicleInfo.getVehicleName()); return; } //匹配的车辆信息数据里 未匹配成功 默认选择第一条 carInfo.setModelCode(vehicleInfoList.get(0).getVehicleId()); // carInfo.setCiModelCode(a.getModelCode()); carInfo.setCiCarName(vehicleInfoList.get(0).getVehicleName()); carInfo.setModelcname(vehicleInfoList.get(0).getVehicleName()); } /** * 2 报价 */ @Override public HttpResult quoteApi(BaseQuoteVo quoteVo) { requestInfoList = new ArrayList<>(); // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(quoteVo.getAgreementId()); BaseQuoteInfoVo yaQuoteInfoVo = insOrdersComponents.getQuoteInfo(quoteVo.getOrderNo()); CarInfoVo carInfo = yaQuoteInfoVo.getCarInfo(); //构造车辆信息 gainVehicleModel(ycConfigureParameters, carInfo); HttpResult httpResult = new HttpResult(); ObjectMapper xmlMapper = this.gainXmlMapper(); InsAreaCompany iac = null; InsOrders order = insOrdersService.getById(yaQuoteInfoVo.getOrderNo()); AccidentalDrivingVo adVo = quoteVo.getAccidentalDrivingVo(); //1.1必填校验 checkEmpty(yaQuoteInfoVo); //组装参数 Ruote m = Ruote.buildQuoteParam(yaQuoteInfoVo, ycConfigureParameters, apiComponents, adVo); //构造地区 buildRegion(m, yaQuoteInfoVo); RuoteResponse rr = null; boolean boo = false; boolean isRenewal = true; boolean isBiRepeat = true; String textHead = "==========永诚API方式 - 车架号:" + carInfo.getVinNo() + " - 报价 "; while (!boo) { rr = requestApi(m, new RuoteResponse(), iac, YcBuildData.API_QUOTE, InsQuoteFlow.Q_S_0, textHead); //处理返回信息 //1、交强险重复投保处理 boo = ciRepetitionInsure(rr, m); if (!boo) { textHead += " - 交强险重复投保处理 "; continue; } //2、转保处理 boo = reinsurance(rr, m); if (!boo) { textHead += " - 转保处理 "; continue; } if (isBiRepeat) { //3、商业险日期处理 boo = biRepetitionInsure(rr, m); if (!boo) { isBiRepeat = false; textHead += " - 商业险日期处理 "; continue; } } int codeErrorNum = 0; if (codeErrorNum > 3) boo = true; //转保验证码错误 boo = reinsuranceCodeError(rr, m); if (!boo) { codeErrorNum++; continue; } } if (null == rr) return HttpResult.error("远程请求报价失败"); if (!rr.getHead().getErrorCode().equals("000000")) return HttpResult.error(rr.getHead().getErrorMessage()); QuoteRespVo quoteRespVo = YcBuildData.buildQuoteRespVo(order, rr, yaQuoteInfoVo); //8 生成订单 iac = response_order(order, quoteRespVo, m, rr, quoteVo); // updateApiLog(apiLog, iac); quoteRespVo.setCompanyId(iac.getId()); if (CollUtil.isNotEmpty(requestInfoList)) { // requestInfoList.stream().forEach(c -> { // System.err.println("========请求流程信息==========:" + c); // }); quoteRespVo.getWarnMessageList().addAll(requestInfoList); } return HttpResult.ok("报价成功", quoteRespVo); } /** * 报价 交强险 重复 投保业务处理 */ public boolean ciRepetitionInsure(RuoteResponse rr, Ruote m) { String errorMsg = rr.getHead().getErrorMessage(); if (rr.getHead().getErrorCode().equals("009999") && errorMsg.contains("重复投保") && errorMsg.contains("终保日期") && errorMsg.contains("终保日期")) { requestInfoList.add(errorMsg); log.info("永诚API方式 - xml请求 ------------报价 -> 交强重复投保----------------"); //截取0 到 机动车交通事故强制险 String ciMsg = errorMsg; //终保日期 String coverageEndDate = ciMsg.substring(ciMsg.indexOf("终保日期") + 5, ciMsg.indexOf("终保日期") + 5 + 16); LocalDateTime start = DateTimeUtil.parseLocalDateTime(coverageEndDate, DateTimeUtil.DATETIME_PATTERN_EXT1); LocalDateTime end = start.plusYears(1L).minusDays(1L); String newStartDate = DateTimeUtil.getStartTimeOfDayStr(start, DateTimeUtil.DATETIME_PATTERN); if (start.getHour() > 0) { end = start.plusYears(1L); newStartDate = DateTimeUtil.format(start, DateTimeUtil.DATETIME_PATTERN); } String newEndDate = DateTimeUtil.getEndTimeOfDayStr(end, DateTimeUtil.DATETIME_PATTERN); System.err.println("新起:" + newStartDate); System.err.println("新止:" + newEndDate); m.getRequestLabel().getCondition().getBase().setTInsrncBgnTmJQ(newStartDate); m.getRequestLabel().getCondition().getBase().setTInsrncEndTmJQ(newEndDate); return false; } return true; } /** * 报价 商业险 重复 投保业务处理 */ public boolean biRepetitionInsure(RuoteResponse rr, Ruote m) { if (rr.getHead().getErrorCode().equals("000000") && null != rr.getTfiWarnList() && CollUtil.isNotEmpty(rr.getTfiWarnList().getTfiWarnData())) { // List tfiWarnData = rr.getTfiWarnList().getTfiWarnData().stream().filter(item -> null != item).filter(item -> StringUtils.isNotEmpty(item.getWarnMessage())).collect(Collectors.toList()); TfiWarnListResponse.TfiWarnData tfiWarnData = rr.getTfiWarnList().getTfiWarnData().stream().filter(item -> null != item).filter(item -> StringUtils.isNotEmpty(item.getWarnMessage())).filter(item -> item.getWarnMessage().contains("终保日期")).findFirst().orElse(null); if (null == tfiWarnData) return true; //截取0 到 机动车交通事故强制险 String ciMsg = tfiWarnData.getWarnMessage(); requestInfoList.add(ciMsg); if(ciMsg.contains("终保日期: 以上为所有结果信息"))return true; //终保日期 String coverageEndDate = ciMsg.substring(ciMsg.indexOf("终保日期") + 5, ciMsg.indexOf("终保日期") + 5 + 12); LocalDateTime start = DateTimeUtil.parseLocalDateTime(coverageEndDate, DateTimeUtil.UNSIGNED_DATETIME_PATTERN_EXT1); LocalDateTime end = start.plusYears(1L).minusDays(1L); String newStartDate = DateTimeUtil.getStartTimeOfDayStr(start, DateTimeUtil.DATETIME_PATTERN); String newEndDate = DateTimeUtil.getEndTimeOfDayStr(end, DateTimeUtil.DATETIME_PATTERN); System.err.println("商业新起:" + newStartDate); System.err.println("商业新止:" + newEndDate); m.getRequestLabel().getCondition().getBase().setTInsrncBgnTmSY(newStartDate); m.getRequestLabel().getCondition().getBase().setTInsrncEndTmSY(newEndDate); //转保信息清空 重新报价 // rr.getVhl().setCQryCdeJQ(null); // rr.getVhl().setCQryCdeSY(null); // rr.getVhl().setCBusType("0"); m.getRequestLabel().getCondition().getVhl().setCQryCdeJQ(null); m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(null); m.getRequestLabel().getCondition().getVhl().setCCheckCodeSY(null); m.getRequestLabel().getCondition().getVhl().setCQryCdeSY(null); m.getRequestLabel().getCondition().getVhl().setCBusType("0"); return false; } return true; } /** * 报价 转保校验码有误 */ public boolean reinsuranceCodeError(RuoteResponse rr, Ruote m) { if (rr.getHead().getErrorCode().equals("009999") && rr.getHead().getErrorMessage().contains("录入的校验码有误")) { requestInfoList.add(rr.getHead().getErrorMessage()); //转保信息清空 重新报价 m.getRequestLabel().getCondition().getVhl().setCBusType("0"); m.getRequestLabel().getCondition().getVhl().setCQryCdeJQ(""); m.getRequestLabel().getCondition().getVhl().setCQryCdeSY(""); m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(""); m.getRequestLabel().getCondition().getVhl().setCCheckCodeSY(""); return false; } return true; } /** * 报价 转保业务处理 */ public boolean reinsurance(RuoteResponse rr, Ruote m) { if (rr.getHead().getErrorCode().equals("000000")) { String cCheckCodeJQ = rr.getVhl().getCCheckCodeJQ(); String cQryCdeJQ = rr.getVhl().getCQryCdeJQ(); String cCheckCodeSY = rr.getVhl().getCCheckCodeSY(); //转保调用自动识别转保码 if (StringUtils.isNotEmpty(cCheckCodeJQ) || StringUtils.isNotEmpty(cCheckCodeSY)) { log.info(String.format("永诚API方式 - xml请求 报价,车牌号《%s》 -> 转保业务处理----------------", m.getRequestLabel().getCondition().getVhl().getCPlateNo())); // //丢失交强校验码图串 // if (StringUtils.isEmpty(cCheckCodeJQ) && StringUtils.isNotEmpty(cQryCdeJQ)) { // TfiWarnListResponse.TfiWarnData tfiWarnData = rr.getTfiWarnList().getTfiWarnData().stream().filter(item -> null != item).filter(item -> StringUtils.isNotEmpty(item.getWarnMessage())).filter(item -> item.getWarnMessage().contains(cQryCdeJQ)).findFirst().orElse(null); // if (null != tfiWarnData) { // String msg = tfiWarnData.getWarnMessage().substring(tfiWarnData.getWarnMessage().indexOf("flatCheckCode--") + 15); // cCheckCodeJQ = msg; // } // } requestInfoList.add(rr.getHead().getErrorMessage()); //调用python ocr String sendBody = ""; Map bodyMap = new HashMap(); bodyMap.put("jqImage", StringUtils.isNotEmpty(cCheckCodeJQ) ? cCheckCodeJQ : ""); bodyMap.put("syImage", StringUtils.isNotEmpty(cCheckCodeSY) ? cCheckCodeSY : ""); sendBody = JsonUtils.toJson(bodyMap); String ocrStr = HttpUtil.sendPost("http://47.92.254.66:8088/getres", sendBody); Map ocrMap = JsonUtils.toObject(ocrStr, Map.class); m.getRequestLabel().getCondition().getVhl().setCBusType("2"); //交强 m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(ocrMap.get("jqImageCode").toString()); // m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(ocrMap.get("jqImageCode").toString()); m.getRequestLabel().getCondition().getVhl().setCQryCdeJQ(StringUtils.isEmpty(ocrMap.get("jqImageCode").toString()) ? "" : rr.getVhl().getCQryCdeJQ()); //商业 m.getRequestLabel().getCondition().getVhl().setCCheckCodeSY(ocrMap.get("syImageCode").toString()); m.getRequestLabel().getCondition().getVhl().setCQryCdeSY(rr.getVhl().getCQryCdeSY()); return false; } } return true; } /** * 3 核保 * * @param quoteOrderNo */ @Override @Transactional public HttpResult auditApi(String quoteOrderNo) { ObjectMapper xmlMapper = this.gainXmlMapper(); String msg = "提交成功"; HttpResult h = HttpResult.ok(msg); try { //子订单 InsAreaCompany iac = insAreaCompanyService.getById(quoteOrderNo); if (iac == null) { return HttpResult.error("订单不存在"); } InsOrders order = insOrdersService.getById(iac.getOrderno()); // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId()); // if (InsOrderStatus.S_5.getCode().equals(iac.getOrderstatus()) || InsOrderStatus.S_4.getCode().equals(iac.getOrderstatus())) { // return HttpResult.ok(InsOrderStatus.matchKey(iac.getOrderstatus()).getDesc()); // } //车主 CustomerInfoVo ownerInfo = JSONObject.parseObject(order.getOwnerinfo().toJSONString(), CustomerInfoVo.class); //被保人 CustomerInfoVo insureInfo = JSONObject.parseObject(order.getInsureinfo().toJSONString(), CustomerInfoVo.class); //投保人 CustomerInfoVo applyInfo = JSONObject.parseObject(order.getApplyinfo().toJSONString(), CustomerInfoVo.class); //组装参数 Audit m = Audit.buildAuditParam(ownerInfo, insureInfo, applyInfo, ycConfigureParameters, iac); //构造被保人地区 InsAlltrustRegion insureInfoRegion = findRegion(insureInfo); if(null != insureInfoRegion){ m.getRequestLabel().getCondition().getCustomer().setCProvince(insureInfoRegion.getProvinceCode()); m.getRequestLabel().getCondition().getCustomer().setCCity(insureInfoRegion.getCityCode()); m.getRequestLabel().getCondition().getCustomer().setCCounty(insureInfoRegion.getArea()); }else{ throw new SystemException("永诚 - 被保人地区获取失败,请确认页面是否填写"); } // //处理地区 // Map insureMap = gainRegionCode(insureInfo.getAddr()); // if (null != insureMap && insureMap.size() > 0) { // m.getRequestLabel().getCondition().getCustomer().setCProvince(insureMap.get("provinceCode")); // m.getRequestLabel().getCondition().getCustomer().setCCity(insureMap.get("cityCode")); // m.getRequestLabel().getCondition().getCustomer().setCCounty(insureMap.get("areaCode")); // } else { // throw new SystemException("永诚 - 被保人地区获取失败,请联系管理员"); // } log.debug("=========永诚API方式 - xml请求 - 核保开始======"); //接口请求 // InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_AUDIT); String responseData = httpPostResultLog(xmlMapper, m, YcBuildData.API_AUDIT, "永诚API方式 - 核保 - "); log.debug("=========永诚API方式 - xml请求 - 核保结束!======"); // verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_1); // String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); AuditResponse rd = xmlMapper.readValue(cleanStr, AuditResponse.class); if (rd.getResponseHead().getReturnCode().equals("0000")) { // if (rd.getResponseHead().getReturnCode().equals("E0000")) { String statusJq = StringUtils.toString(rd.getStatusJq(), ""); String statusSy = StringUtils.toString(rd.getStatusSY(), ""); if (statusJq.equals("0") || statusSy.equals("0")) { iac.setOrderstatus(InsOrderStatus.S_1.getCode()); } else if (statusJq.equals("3") || statusSy.equals("3")) { iac.setOrderstatus(InsOrderStatus.S_4.getCode()); } else { iac.setOrderstatus(InsOrderStatus.S_2.getCode()); } if (StringUtils.toInt(order.getOrderstatus()) < StringUtils.toInt(iac.getOrderstatus())) { order.setOrderstatus(iac.getOrderstatus()); } } else { msg = rd.getResponseHead().getReturnMessage(); return HttpResult.error("核保失败" + msg); } iac.setAuditid(order.getUserid()); iac.setInsOrderNo(rd.getOrderCode()); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); iac.setAudittime(LocalDateTime.now()); iac.setJqapplyno(StringUtils.toString(rd.getPolicyAppNoJQ(), "")); iac.setSyapplyno(StringUtils.toString(rd.getPolicyAppNoSY(), "")); iac.setJqappoint(""); //交强特别约定 iac.setSyappoint(""); //商业特别约定 if (InsOrderStatus.S_2.getCode().equals(InsOrderStatus.matchKey(iac.getOrderstatus()).getCode())) { //获取缴费地址 getPayUrlApi(iac); } else { h = HttpResult.error(msg + "状态:" + InsOrderStatus.matchKey(iac.getOrderstatus()).getDesc()); } insAreaCompanyService.updateById(iac); insOrdersService.updateByOrderStatus(order.getOrderno(), order.getOrderstatus()); // if (InsOrderStatus.S_2.getCode().equals(InsOrderStatus.matchKey(iac.getOrderstatus()).getCode())) { // return HttpResult.ok(msg); // } else { // return HttpResult.error(msg + "状态:" + InsOrderStatus.matchKey(iac.getOrderstatus()).getDesc()); // } // //插入轨迹表 // insTaskHistoryService.insertByOrderStatus(order); } catch (SystemException e) { return HttpResult.error(e.getMessage()); } catch (Exception e) { // e.printStackTrace(); log.error("===永诚API方式--核保报错(订单号-{}):{}", quoteOrderNo, e.getMessage()); return HttpResult.error("系统错误,请联系管理员"); } return h; } /** * 4 影像上传 */ @Override public HttpResult UploadImageApi(String quoteOrderNo) { HttpResult resutl = HttpResult.ok(); InsAreaCompany iac = insAreaCompanyService.getByIdIsExist(quoteOrderNo); InsOrders order = insOrdersService.getById(iac.getOrderno()); List insTaskImages = insTaskImageService.selectByTaskId(order.getQuoteno()); //获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId()); insTaskImages.stream().forEach(a -> { InsApiLog apiLog = null; //组装参数 //接口请求 ImageUp iUp = ImageUp.buildImageUpParam(order, ycConfigureParameters, a.getImage(), a.getImgtype()); ObjectMapper xmlMapper = gainXmlMapper(); //接口请求 // apiLog = httpPost(xmlMapper, iUp, YcBuildData.API_UPLOAD); String responseData = httpPostResultLog(xmlMapper, iUp, YcBuildData.API_UPLOAD, "永诚API方式 - 影像上传 - "); verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_2); try { // String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); log.error("===永诚API方式--上传影像清洗返回参数:" + cleanStr); ImageUpResponse iur = xmlMapper.readValue(cleanStr, ImageUpResponse.class); } catch (IOException e) { e.printStackTrace(); log.error("===永诚API方式--上传影像报错:" + e.getMessage()); throw new SystemException("系统错误,请联系管理员"); } }); return HttpResult.ok(); } /** * 5 支付 */ @Override public InsAreaCompany getPayUrlApi(InsAreaCompany iac) { try { // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId()); //组装参数 Pay pay = Pay.buildPayParam(iac, ycConfigureParameters.gainAuthorityDataXml(), apiComponents.getPayCallBack()); ObjectMapper xmlMapper = gainXmlMapper(); //接口请求 log.debug("=========永诚API方式 - xml请求 - 获取缴费链接开始======"); String responseData = httpPostResultLog(xmlMapper, pay, YcBuildData.API_PAY, "永诚API方式 - 获取缴费链接 - "); // InsApiLog apiLog = httpPost(xmlMapper, pay, YcBuildData.API_PAY); log.debug("=========永诚API方式 - xml请求 - 获取缴费链接结束!======"); // verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_3); // String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); PayResponse payResp = xmlMapper.readValue(cleanStr, PayResponse.class); if (payResp.getReturnCode().equals("E0000")) { iac.setPaymentLink(payResp.getPayTransUrl()); // insAreaCompanyService.updateById(iac); } else { log.error("永诚API方式 - 获取支付连接失败:" + payResp.getReturnMessage()); } } catch (Exception e) { e.printStackTrace(); throw new SystemException("获取支付连接失败"); } return iac; } /** * 补传回调 */ @Override public HttpResult callbackAnOrder(String quoteOrderNo) { // log.debug("=========永诚API方式 - xml请求 - 补传回调开始======"); HttpResult httpResult = new HttpResult(); try { InsAreaCompany iac = insAreaCompanyService.getById(quoteOrderNo); InsOrders order = insOrdersService.getById(iac.getOrderno()); if (iac == null) { return HttpResult.error("报价订单不存在"); } if (StringUtils.isEmpty(iac.getAgreementId())) return HttpResult.error("协议号空"); // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId()); //0 支付回调 1核保回调 5直接返回字符串信息 // String type = "0"; String type = "5"; // if(iac.getOrderstatus().equals(InsOrderStatus.S_1.getCode())) type = "1"; //组装参数 CallbackAnOrder o = CallbackAnOrder.buildCallbackAnOrderParam(iac, ycConfigureParameters.gainAuthorityDataXml(), type); ObjectMapper xmlMapper = gainXmlMapper(); //接口请求 // InsApiLog apiLog = httpPostResultLog(xmlMapper, o, YcBuildData.API_ORDER_QUERY); String respData = httpPostResultLog(xmlMapper, o, YcBuildData.API_ORDER_QUERY, "永诚API方式 - 补传回调 - "); // log.info("永诚API方式 - xml请求 - 参数:" + apiLog.getRequestData()); // log.info("永诚API方式 - xml请求 ------------分割线----------------"); // log.info("永诚API方式 - xml请求 - 响应:" + apiLog.getResponseData()); // verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_5); // String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(respData); // CallbackAnOrderResponse callbackAnOrderResponse = xmlMapper.readValue(cleanStr, CallbackAnOrderResponse.class); if (StringUtils.isNotEmpty(cleanStr)) { if (cleanStr.equals("账户不存在或没有权限")) return HttpResult.ok("账户不存在或没有权限"); log.info("永诚API方式 - 补传回调 - 参数:" + cleanStr); CallBackRequest param = CallBackRequest.buildCallBackParam(cleanStr); //成功 if (param.getResult().equals("0")) { // LambdaQueryWrapper lqw = new LambdaQueryWrapper(); // //交强投保单号查询 // lqw.eq(StringUtils.isNotEmpty(param.getCiPolicyAppNo()), InsAreaCompany::getJqapplyno, param.getCiPolicyAppNo()); // //商业投保单号查询 // lqw.eq(StringUtils.isNotEmpty(param.getBizPolicyAppNo()), InsAreaCompany::getSyapplyno, param.getBizPolicyAppNo()); // InsAreaCompany iac = insAreaCompanyService.getOne(lqw); if (StringUtils.isNotEmpty(param.getBizPolicyNo())) iac.setSypolicyno(param.getBizPolicyNo()); if (StringUtils.isNotEmpty(param.getCiPolicyNo())) iac.setJqpolicyno(param.getCiPolicyNo()); iac = buildCallBack(iac, param); if (StringUtils.toInt(order.getOrderstatus()) < StringUtils.toInt(iac.getOrderstatus())) { order.setOrderstatus(iac.getOrderstatus()); } insAreaCompanyService.updateById(iac); insOrdersService.updateByOrderStatus(order.getOrderno(), order.getOrderstatus()); } else { //失败原因 httpResult = HttpResult.error(param.getMessage()); log.info(String.format("永诚API方式 - 补传回调 - 失败,交强保单号:{} ,商业保单号:{},类型:{}", param.getCiPolicyNo(), param.getBizPolicyNo(), param.getType())); } return HttpResult.ok(param); } // if (cleanStr.equals("0000")) { // httpResult.setMsg("操作成功"); // } else { // httpResult.setMsg(cleanStr); // } } catch (SystemException e) { return HttpResult.error(e.getMessage()); } catch (Exception e) { e.printStackTrace(); return HttpResult.error("系统错误,请联系管理员"); } // log.debug("=========永诚API方式 - xml请求 - 补传回调结束!======"); return httpResult; } /** * 补传回调 */ @Override public void callbackAnOrder() { LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(InsAreaCompany::getOrderstatus, InsOrderStatus.S_2.getCode()); lqw.gt(InsAreaCompany::getAudittime, LocalDate.now().minusDays(1)); List list = insAreaCompanyService.list(lqw); if (null != list && list.size() > 0) { list.stream().forEach(a -> { callbackAnOrder(a.getId()); }); } } /** * 6 电子保单 */ @Override public HttpResult getPolicyPrintApi(PolicyPrintVo policyPrintVo) { HttpResult httpResult = new HttpResult(); try { InsAreaCompany iac = insAreaCompanyService.getById(policyPrintVo.getCompanyId()); AssertionUtils.isEmpty(iac, "报价订单不存在"); InsOrders order = insOrdersService.getById(iac.getOrderno()); String licensePlate = order.getLicenseno(); //如果保单已经生成了就直接返回 if (policyPrintVo.getType().equals("2")) { Map m = new HashMap(); String jqFlagUrl = gainExistCarInsPolicy(licensePlate + "-交强险标志.pdf", licensePlate); String jqUrl = gainExistCarInsPolicy(licensePlate + "-交强险保单.pdf", licensePlate); String syUrl = gainExistCarInsPolicy(licensePlate + "-商业险保单.pdf", licensePlate); if (null != jqFlagUrl || null != jqUrl || null != syUrl) { m.put("jqFlagUrl", jqFlagUrl); m.put("jqUrl", jqUrl); m.put("syUrl", syUrl); return HttpResult.ok(m); } } // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId()); String policyNo = policyPrintVo.getRiskCode().equals("0507") ? iac.getJqpolicyno() : iac.getSypolicyno(); //组装参数 Policy p = Policy.buildPolicyParam(policyNo, ycConfigureParameters.gainAuthorityDataXml()); ObjectMapper xmlMapper = gainXmlMapper(); //接口请求 log.debug("=========永诚API方式 - xml请求 - 获取保单开始======"); String responseData = httpPostResultLog(xmlMapper, p, YcBuildData.API_GUARANTEE_SLIP, "永诚API方式 - 获取保单 - "); // InsApiLog apiLog = httpPost(xmlMapper, p, YcBuildData.API_GUARANTEE_SLIP); log.debug("=========永诚API方式 - xml请求 - 获取保单结束!======"); // verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_4); // String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); PolicyResponse pResp = xmlMapper.readValue(cleanStr, PolicyResponse.class); if (pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) { Map m = new HashMap(); String bzInsUrl = StringUtils.isNotEmpty(pResp.getPolicyBZUrl()) ? pResp.getPolicyBZUrl().replaceAll(";pkid", "&pkid") : ""; String jqFlagUrl = gainCarInsPolicy(bzInsUrl, licensePlate + "-交强险标志.pdf", licensePlate); if (policyPrintVo.getType().equals("1")) { m.put("jqFlagUrl", jqFlagUrl); m.put("jqUrl", ""); m.put("syUrl", ""); } if (policyPrintVo.getType().equals("2")) { String jqInsUrl = StringUtils.isNotEmpty(pResp.getJqpolicyUrl()) ? pResp.getJqpolicyUrl().replaceAll(";pkid", "&pkid") : ""; String syInsUrl = StringUtils.isNotEmpty(pResp.getSypolicyUrl()) ? pResp.getSypolicyUrl().replaceAll(";pkid", "&pkid") : ""; String jqUrl = gainCarInsPolicy(jqInsUrl, licensePlate + "-交强险保单.pdf", licensePlate); String syUrl = gainCarInsPolicy(syInsUrl, licensePlate + "-商业险保单.pdf", licensePlate); m.put("jqFlagUrl", jqFlagUrl); m.put("jqUrl", jqUrl); m.put("syUrl", syUrl); } // httpResult.setData(m); // httpResult.setMsg(pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription()); return HttpResult.ok(pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription(), m); } else { return HttpResult.error(pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription()); } } catch (Exception e) { e.printStackTrace(); return HttpResult.error("系统错误,请联系管理员"); } } /** * 驾意外险 */ @Override public HttpResult gainAccidentList(AccidentalDrivingQueryVo accidentalDrivingVo) { HttpResult httpResult = new HttpResult(); try { // InsAreaCompany iac = insAreaCompanyService.getById(quoteOrderNo); // InsOrders order = insOrdersService.getById(iac.getOrderno()); // if (iac == null) { // return HttpResult.error("报价订单不存在"); // } // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(accidentalDrivingVo.getAgreementId()); //组装参数 Accident accident = Accident.buildPayParam(accidentalDrivingVo, ycConfigureParameters, null); ObjectMapper xmlMapper = gainXmlMapper(); //接口请求 log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询开始======"); String responseData = httpPostResultLog(xmlMapper, accident, YcBuildData.API_ACCIDENT, "永诚API方式 - 获取意健险方案及险种 - "); // InsApiLog apiLog = httpPost(xmlMapper, accident, YcBuildData.API_ACCIDENT); log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询结束!======"); // verifyRequest(apiLog, iac,InsQuoteFlow.); // String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); AccidentResponse accidentResp = xmlMapper.readValue(cleanStr, AccidentResponse.class); if (accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) { //清空旧的存入表 LambdaQueryWrapper lqw = new LambdaQueryWrapper(); lqw.eq(EsmInsAttachInsure::getCompanyId, accidentalDrivingVo.getCompanyCode()); lqw.eq(EsmInsAttachInsure::getSeating, accidentalDrivingVo.getSeatNum()); esmInsAttachInsureMapper.delete(lqw); List cList = accidentResp.getResponseYwCvrg().getCvrgList(); List eiaiList = new ArrayList<>(); cList.stream().forEach(a -> { EsmInsAttachInsure ati = new EsmInsAttachInsure(); ati.setCode(a.getCInsuranceTypeCode()); ati.setName(a.getCInsuranceType()); ati.setSeating(accidentalDrivingVo.getSeatNum() + ""); ati.setCompanyId(accidentalDrivingVo.getCompanyCode()); ati.setType(AttachInsureEnum.AI001.getCode()); ati.setEnable(WhetherEnum.YES.getCode()); ati.setRestrictNum(StringUtils.toInt(a.getNPurchaseLimitsNum())); esmInsAttachInsureMapper.insert(ati); eiaiList.add(ati); }); httpResult.setData(eiaiList); // httpResult.setData(accidentResp.getResponseYwCvrg().getCvrgList()); httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription()); } else { httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription()); } } catch (SystemException e) { return HttpResult.error(e.getMessage()); } catch (Exception e) { e.printStackTrace(); return HttpResult.error("系统错误,请联系管理员"); } return httpResult; } /** * 驾意外险 同步 */ @Override public HttpResult syncAccidentInsure(AccidentalDrivingQueryVo accidentalDrivingVo) { AccidentResponse ar = gainAccidentInsure(accidentalDrivingVo, null); // List eiaiList = new ArrayList<>(); if (ar.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) { //清空旧的存入表 LambdaQueryWrapper lqw = new LambdaQueryWrapper(); lqw.eq(EsmInsAttachInsure::getCompanyId, accidentalDrivingVo.getCompanyCode()); lqw.eq(EsmInsAttachInsure::getSeating, accidentalDrivingVo.getSeatNum()); lqw.select(EsmInsAttachInsure::getId); List eiaiList = esmInsAttachInsureMapper.selectList(lqw); //删除已经存在的数据 if (null != eiaiList && eiaiList.size() > 0) { List ids = new ArrayList<>(); eiaiList.stream().forEach(i -> { ids.add(i.getId()); }); LambdaQueryWrapper lqwDetails = new LambdaQueryWrapper<>(); lqwDetails.in(EsmInsAttachInsureDetails::getAttachInsureId, ids); //详情删除 esmInsAttachInsureDetailsMapper.delete(lqwDetails); // esmInsAttachInsureMapper.delete(lqw); esmInsAttachInsureMapper.deleteBatchIds(ids); } List cList = ar.getResponseYwCvrg().getCvrgList(); cList.stream().forEach(a -> { EsmInsAttachInsure ati = new EsmInsAttachInsure(); ati.setCode(a.getCInsuranceTypeCode()); ati.setName(a.getCInsuranceType()); ati.setSeating(accidentalDrivingVo.getSeatNum() + ""); ati.setCompanyId(accidentalDrivingVo.getCompanyCode()); ati.setType(AttachInsureEnum.AI001.getCode()); ati.setEnable(WhetherEnum.YES.getCode()); ati.setRestrictNum(StringUtils.toInt(a.getNPurchaseLimitsNum())); esmInsAttachInsureMapper.insert(ati); //具体方案信息 AccidentResponse arCode = gainAccidentInsure(accidentalDrivingVo, a.getCInsuranceTypeCode()); if (arCode.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) { AtomicInteger total = new AtomicInteger(0); List cListDetails = arCode.getResponseYwCvrg().getCvrgList(); cListDetails.stream().forEach(d -> { EsmInsAttachInsureDetails atiDetails = new EsmInsAttachInsureDetails(); atiDetails.setAttachInsureId(ati.getId()); atiDetails.setName(d.getCInsuranceLiability()); atiDetails.setCarSum(d.getNInsuranceAmountCar()); atiDetails.setSeatSum(d.getNInsuranceAmountSeat()); atiDetails.setPremium(d.getNLiabilityPremium()); total.addAndGet(StringUtils.toInt(d.getNLiabilityPremium())); esmInsAttachInsureDetailsMapper.insert(atiDetails); }); ati.setPremium(total.get() + ""); esmInsAttachInsureMapper.updateById(ati); } // eiaiList.add(ati); }); } return HttpResult.ok("同步成功"); } /** * 驾意外险 */ @Override public AccidentResponse gainAccidentInsure(AccidentalDrivingQueryVo accidentalDrivingVo, String schemeNo) { HttpResult httpResult = new HttpResult(); // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(accidentalDrivingVo.getAgreementId()); //组装参数 Accident accident = Accident.buildPayParam(accidentalDrivingVo, ycConfigureParameters, schemeNo); ObjectMapper xmlMapper = gainXmlMapper(); //接口请求 log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询开始======"); String responseData = httpPostResultLog(xmlMapper, accident, YcBuildData.API_ACCIDENT, "永诚API方式 - 获取意健险方案及险种 - "); // InsApiLog apiLog = httpPost(xmlMapper, accident, YcBuildData.API_ACCIDENT); log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询结束!======"); // verifyRequest(apiLog, iac,InsQuoteFlow.); // String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); AccidentResponse accidentResp = null; try { accidentResp = xmlMapper.readValue(cleanStr, AccidentResponse.class); } catch (JsonProcessingException e) { log.error("转换错误 方法:gainAccidentInsure 类:AccidentResponse"); throw new RuntimeException(e); } return accidentResp; // if (accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) { // //清空旧的存入表 // LambdaQueryWrapper lqw = new LambdaQueryWrapper(); // lqw.eq(EsmInsAttachInsure::getCompanyId,accidentalDrivingVo.getCompanyCode()); // lqw.eq(EsmInsAttachInsure::getSeating,accidentalDrivingVo.getSeatNum()); // esmInsAttachInsureMapper.delete(lqw); // // List cList = accidentResp.getResponseYwCvrg().getCvrgList(); // // List eiaiList = new ArrayList<>(); // cList.stream().forEach(a ->{ // EsmInsAttachInsure ati = new EsmInsAttachInsure(); // ati.setCode(a.getCInsuranceTypeCode()); // ati.setName(a.getCInsuranceType()); // ati.setSeating(accidentalDrivingVo.getSeatNum() + ""); // ati.setCompanyId(accidentalDrivingVo.getCompanyCode()); // ati.setType(AttachInsureEnum.AI001.getCode()); // ati.setEnable(WhetherEnum.YES.getCode()); // ati.setRestrictNum(StringUtils.toInt(a.getNPurchaseLimitsNum())); // // esmInsAttachInsureMapper.insert(ati); // eiaiList.add(ati); // }); // // // // // httpResult.setData(eiaiList); //// httpResult.setData(accidentResp.getResponseYwCvrg().getCvrgList()); // httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription()); // } else { // httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription()); // } } @Override @Transactional public HttpResult callBackApi(CallBackRequest param) { // if (StringUtils.isNotEmpty(param.getType())) return HttpResult.error("字段:type(回调类型) 参数为空"); //成功 if (param.getResult().equals("0")) { LambdaQueryWrapper lqw = new LambdaQueryWrapper(); //交强投保单号查询 lqw.eq(StringUtils.isNotEmpty(param.getCiPolicyAppNo()), InsAreaCompany::getJqapplyno, param.getCiPolicyAppNo()); //商业投保单号查询 lqw.eq(StringUtils.isNotEmpty(param.getBizPolicyAppNo()), InsAreaCompany::getSyapplyno, param.getBizPolicyAppNo()); InsAreaCompany iac = insAreaCompanyService.getOne(lqw); if (null != iac) { if (StringUtils.isNotEmpty(param.getBizPolicyNo())) iac.setSypolicyno(param.getBizPolicyNo()); if (StringUtils.isNotEmpty(param.getCiPolicyNo())) iac.setJqpolicyno(param.getCiPolicyNo()); iac = buildCallBack(iac, param); InsOrders order = insOrdersService.getById(iac.getOrderno()); if (StringUtils.toInt(order.getOrderstatus()) < StringUtils.toInt(iac.getOrderstatus())) { order.setOrderstatus(iac.getOrderstatus()); } insAreaCompanyService.updateById(iac); insOrdersService.updateByOrderStatus(order.getOrderno(), order.getOrderstatus()); //支付后 手工确认意外险 } else { log.info(String.format("永诚API方式 - 回调 - 信息,订单不存在,交强保单号:{} ,商业保单号:{}", param.getCiPolicyNo(), param.getBizPolicyNo())); } } else { //失败原因 param.getMessage(); log.info(String.format("永诚API方式 - 回调 - 失败,交强保单号:{} ,商业保单号:{},类型:{}", param.getCiPolicyNo(), param.getBizPolicyNo(), param.getType())); } return HttpResult.ok(param); } /** * @description:构造车型查询参数 * @author: lig * @date: 2023年02月08日 0008 */ private ModelsQueryXml buildModelsQueryParam(CarModel_Req carModelReq, YcConfigureParameters ycConfigureParameters) { ModelsQueryXml m = new ModelsQueryXml(); ModelsQueryXml.RequestLabel requestLabel = new ModelsQueryXml.RequestLabel(); requestLabel.setSearchKeyword(carModelReq.getFrameNo().substring(0, 8)); requestLabel.setVid(carModelReq.getFrameNo()); requestLabel.setEngineNo(carModelReq.getEngineNo()); requestLabel.setDptCde(ycConfigureParameters.getDptCde()); requestLabel.setProno("0326"); requestLabel.setMotorTypeCode("11"); requestLabel.setCFstRegYm(carModelReq.getEnrollDate()); requestLabel.setAuthorityData(ycConfigureParameters.gainAuthorityDataXml(ycConfigureParameters)); m.setRequestLabel(requestLabel); return m; } /** * @description: 构造返回内容,参考永安 * @author: lig * @date: 2023年02月07日 0007 */ private List buildCarModel(ModelsQueryResponse modelsQueryResponse) { // private List buildCarModel(ModelsQueryResponse modelsQueryResponse) { List vList = modelsQueryResponse.getVehicleInfoList(); return vList; // List carModelList = new ArrayList<>(); // // vList.stream().forEach(a -> { // CarModelDTO dto = new CarModelDTO(); // BeanUtils.copyProperties(a, dto); // carModelList.add(dto); // }); // return carModelList; } // private InsApiLog httpPost(ObjectMapper mapper, T requestData, String apiName) { // // String xmlString = ""; // xmlString += ""; // try { // mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // xmlString += mapper.writeValueAsString(requestData); // // xmlString += "\n" + // ""; // // } catch (JsonProcessingException e) { // throw new RuntimeException("永诚API方式-xml转换失败"); // } // InsApiLog iplog = HttpXmlUtil.sendXmlPost(apiComponents.getUrl() + apiName, xmlString); //// log.info("永诚API方式 - xml请求 - 参数:" + iplog.getRequestData()); //// log.info("永诚API方式 - xml请求 ------------分割线----------------"); //// log.info("永诚API方式 - xml请求 - 响应:" + iplog.getResponseData()); // return iplog; // } /** * 日志返回处理 * * @author: lig * @date: 2023年09月02日 0002 */ private String httpPostResultLog(ObjectMapper mapper, T requestData, String apiName, String textHead) { String xmlString = ""; xmlString += ""; try { mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); xmlString += mapper.writeValueAsString(requestData); xmlString += "\n" + ""; } catch (JsonProcessingException e) { throw new RuntimeException("永诚API方式-xml转换失败"); } // InsApiLog iplog = HttpXmlUtil.sendXmlPost(apiComponents.getUrl() + apiName, xmlString); return HttpXmlUtil.sendXmlPostReq(apiComponents.getUrl() + apiName, xmlString, log, textHead); } // /** // * 日志返回处理 // * // * @author: lig // * @date: 2023年09月02日 0002 // */ // private InsApiLog httpPostResultLog(ObjectMapper mapper, T requestData, String apiName) { // // String xmlString = ""; // xmlString += ""; // try { // mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); // xmlString += mapper.writeValueAsString(requestData); // // xmlString += "\n" + // ""; // // } catch (JsonProcessingException e) { // throw new RuntimeException("永诚API方式-xml转换失败"); // } // InsApiLog iplog = HttpXmlUtil.sendXmlPost(apiComponents.getUrl() + apiName, xmlString); // // return iplog; // } /** * @description: 拷贝永安方法,可以封装 * @author: lig * @date: 2023年02月08日 0008 */ private void checkEmpty(YaQuoteInfoVo yaQuoteInfoVo) { if (yaQuoteInfoVo.getCarInfo() == null) { throw new SystemException("carInfo不能为空!"); } if (yaQuoteInfoVo.getPolicyHolderInfo() == null || yaQuoteInfoVo.getInsuredPersonInfo() == null) { throw new SystemException("policyHolderInfo/insuredPersonInfo 不能为空!"); } if (yaQuoteInfoVo.getRiskList() == null || yaQuoteInfoVo.getRiskList().size() == 0) { throw new SystemException("riskList 不能为空!"); } else { for (RiskInfoVo riskInfoVo : yaQuoteInfoVo.getRiskList()) { if (riskInfoVo.getStartDate() == null || riskInfoVo.getEndDate() == null) { throw new SystemException("riskList.startDate / riskList.endDate不能为空!"); } } } } // /** // * 生成订单 拷贝永安 // * // * @author: lig // * @date: 2023年02月16日 0016 // */ // protected InsOrders gene_order(YaQuoteInfoVo record) { // InsOrders insOrder = new InsOrders(); // String orderno = IdGenerate.nextId(); // insOrder.setOrderno(orderno); // insOrder.setQuoteno(String.valueOf(record.getQuoteno())); // insOrder.setOrderstatus("0"); //0报价 1待核保 2已核保待缴费 3核保退回 4核保不通过 // insOrder.setFrameno(record.getCarInfo().getFrameNo()); // insOrder.setLicenseno(record.getCarInfo().getLicenseNo()); // // insOrder.setCarinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getCarInfo()))); // SysUser user = sysUserService.selectByPk(record.getUserId()); // if (user == null) { // throw new SystemException("userId不存在"); // } // if (org.springframework.util.StringUtils.isEmpty(record.getCarInfo().getFrameNo())) { // throw new SystemException("车架号不能为空"); // } // // 关闭订单 不含当前报价号 // InsOrders orderObj = insOrderService.queryQuoteno(new Object[]{record.getUserId(), record.getCarInfo().getFrameNo(), record.getQuoteno()}); // if (orderObj != null) { // List listo = insOrderService.selectList(" where quoteno=?", new Object[]{orderObj.getQuoteno()}); // String status = "0"; // for (InsOrder order : listo) { // if (!"0".equals(order.getOrderstatus())) { // status = order.getOrderstatus(); // } // } // //0报价中 1待核保 2已核保 3核保退回 4核保不通过 5已核保待缴费 6已缴费 7已承保 99已关闭 // if ("0".equals(status)) {//关闭订单 // insOrderService.closeOrder(orderObj.getOrderno(), "99"); // } else if (!"99".equals(status)) { // throw new SystemException("此车辆已提交核保,重新报价请先关闭订单,任务号:" + orderObj.getQuoteno()); // } // } // insOrder.setUserid(user.getId()); // insOrder.setUsername(user.getName()); // insOrder.setDeptid(user.getDeptId()); // SysDept dept = sysDeptService.selectByPk(user.getDeptId()); // insOrder.setDeptname(dept == null ? "" : dept.getName()); // // double retailRate = countRetail(user.getDeptId(), user.getId()); // // insOrder.setOwnerinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getOwnerInfo()))); // insOrder.setApplyinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getPolicyHolderInfo()))); // insOrder.setInsureinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getInsuredPersonInfo()))); // // insOrder.setInsuredname(record.getPolicyHolderInfo().getName()); // // // List risks = record.getRiskList(); // for (RiskInfoVo risk : risks) { // if ("0507".equals(risk.getRiskCode())) {//交强 // insOrder.setJqstartdate(risk.getStartDate()); // insOrder.setJqenddate(risk.getEndDate()); // } // if ("0510".equals(risk.getRiskCode())) {//商业 // insOrder.setSystartdate(risk.getStartDate()); // insOrder.setSyenddate(risk.getEndDate()); // } // } // // List kinds = record.getKindList(); // String productId = ""; // String productname = ""; // // List agreements = esmAgreementService.selectList(" where t.agreestatus='1' and t.insure1 like ? " + "and exists (select 1 from esm_agreement_prod t2 where t.id=t2.agreeid and t2.authcomcode like ?)", new Object[]{"000006140400%", "%" + user.getDeptId() + "%"}); // if (agreements.size() == 0) { // throw new SystemException("不存在有效协议或机构" + user.getDeptId() + "未授权"); // } // String agreeid = agreements.get(0).getId(); // insOrder.setAgreeid(agreeid); // //匹配协议,获取费用 // StringBuffer whereStr = new StringBuffer(); // List params = new ArrayList();// where t.agreeid=? and t.productid in () // whereStr.append("where t.agreeid=? "); // params.add(agreeid); // if (risks.size() == 1 && "0507".equals(risks.get(0).getRiskCode())) { // productId = "ZG01001"; // productname = "单交强"; // whereStr.append(" and t.productid=?"); // params.add(productId); // } else if (risks.size() == 1 && kinds.size() == 1 && "B".equals(kinds.get(0).getKindCode())) { // productId = "ZG01002"; // productname = "单三者"; // whereStr.append(" and t.productid=?"); // params.add(productId); // } else if (risks.size() == 1) { // productId = "ZG01003"; // productname = "单商业"; // whereStr.append(" and t.productid=?"); // params.add(productId); // } else if (risks.size() == 2 && kinds.size() == 1 && "B".equals(kinds.get(0).getKindCode())) { // productId = "ZG01004"; // productname = "交强+三者"; // whereStr.append(" and t.productid in (?,?)"); // params.add("ZG01004"); // params.add("ZG01005"); // } else { // productId = "ZG01006"; // productname = "交强+商业"; // whereStr.append(" and t.productid in (?,?)"); // params.add("ZG01006"); // params.add("ZG01007"); // } // // insOrder.setProductid(productId); // insOrder.setProduct(productname); // List agreementProds = esmAgreementProdService.selectList(whereStr.toString(), params.toArray()); // for (EsmAgreementProd prod : agreementProds) { // if ("ZG01001".equals(prod.getProductid()) || "ZG01004".equals(prod.getProductid()) || "ZG01006".equals(prod.getProductid())) { // // insOrder.setFeerate(prod.getProductrate()); //交强手续费比例 // insOrder.setJqdiscountrate(prod.getFeerate() - retailRate); //交强优惠比例=业务员绩效-分销费用 // } else { // insOrder.setDisrate(prod.getProductrate()); //商业手续费比例 // insOrder.setSydiscountrate(prod.getFeerate() - retailRate); //商业优惠比例=业务员绩效-分销费用 // // } // insOrder.setProductid(prod.getId()); // } // // insOrder.setRiskinfo(JSONObject.parseArray(JSONObject.toJSONString(record.getRiskList()))); // insOrder.setKindinfo(JSONObject.parseArray(JSONObject.toJSONString(record.getKindList()))); // SimpleDateFormat sdfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // // insOrder.setInscompany("永安财险"); // insOrder.setCreatetime(sdfm.format(new Date())); // // return insOrder; // // } // /** // * 分销费用统计 拷贝永安 // * // * @param deptid // * @param userid // * @return // */ // public double countRetail(String deptid, String userid) { // double retailRate = 0; // // //1、根据机构匹配分销规则,获取分销比例 // List list = esmRetailService.selectList(" where deptid = ? and status=?", new Object[]{deptid, "1"}); // //2、根据userid查询三级推荐人 // List users = esmUserInternalService.getSuperior(userid); // // if (list != null && list.size() > 0 && users.size() > 0 && !"0".equals(list.get(0).getRetailtype())) { // EsmRetail retail = list.get(0); // List rateList = new ArrayList(); // rateList.add(retail.getDisrate1()); // rateList.add(retail.getDisrate2()); // rateList.add(retail.getDisrate3()); // // if ("1".equals(retail.getRetailtype())) {//一级分销 // retailRate += rateList.get(0); // } else if ("2".equals(retail.getRetailtype())) {//二级分销 // int num = users.size() > 2 ? 2 : users.size(); // for (int i = 0; i < num; i++) { // retailRate += rateList.get(i); // } // // } else {//三级分销 // int num = users.size() > 2 ? 3 : users.size(); // for (int i = 0; i < num; i++) { // retailRate += rateList.get(i); // } // // } // // } // // return retailRate; // } /** * 新订单 - 子订单 * * @author: lig * @date: 2023年02月16日 0016 */ private InsAreaCompany response_order(InsOrders insOrder, QuoteRespVo quoteRespVo, Ruote requestData, RuoteResponse responseData, BaseQuoteVo quoteVo) { //交强保费 含税 double jqPremium = StringUtils.toDouble(responseData.getBase().getNBefTaxPrmJQ()) + StringUtils.toDouble(responseData.getBase().getNAppTaxAmtJQ()); //商业保费 含税 double syPremium = StringUtils.toDouble(responseData.getBase().getNBefTaxPrmSY()) + StringUtils.toDouble(responseData.getBase().getNAppTaxAmtSY()); //保险公司订单号 String insOrderNo = responseData.getBase().getCresvTxt6(); //查询码交强 String queryCodeJq = responseData.getVhl().getCQryCdeJQ(); //查询码商业 String queryCodeSy = responseData.getVhl().getCQryCdeSY(); EsmInsCompany eic = esmInsCompanyService.getById(quoteVo.getCompanyId()); boolean jq_falg = jqPremium > 0 ? true : false; //保存订单信息 InsAreaCompany insAreaCompany = new InsAreaCompany(); insAreaCompany.setOrderno(insOrder.getOrderno()); insAreaCompany.setReptxt(JSONObject.parseObject(JSONObject.toJSONString(responseData))); insAreaCompany.setJqpremium(BigDecimal.valueOf(jq_falg ? jqPremium : 0)); insAreaCompany.setSypremium(BigDecimal.valueOf(syPremium)); insAreaCompany.setTaxamount(BigDecimal.valueOf(jq_falg ? quoteRespVo.getTaxAmount() : 0)); insAreaCompany.setSumpremium(BigDecimal.valueOf(quoteRespVo.getSumPermium())); // insAreaCompany.setSumpremium(BigDecimal.valueOf(add(quoteRespVo.getSumPermium(), insOrder.getTaxamount()))); insAreaCompany.setOrderstatus(InsTaskHistoryEnum.WAITING_NUCLEAR_INSURANCE.getState() + ""); insAreaCompany.setRiskinfo(JSONObject.parseArray(JSONObject.toJSONString(quoteRespVo.getRiskList()))); insAreaCompany.setKindinfo(JSONObject.parseArray(JSONObject.toJSONString(quoteRespVo.getKindList()))); insAreaCompany.setCreatetime(LocalDateTime.now()); insAreaCompany.setInsOrderNo(insOrderNo); insAreaCompany.setJqapplyno(queryCodeJq); insAreaCompany.setSyapplyno(queryCodeSy); insAreaCompany.setCompanyId(eic.getId()); insAreaCompany.setInscompany(eic.getNamesimple()); insAreaCompany.setAgreementId(quoteVo.getAgreementId()); insAreaCompany.setJqStartDate(responseData.getBase().getTInsrncBgnTmJQ()); insAreaCompany.setJqEndDate(responseData.getBase().getTInsrncEndTmJQ()); insAreaCompany.setSyStartDate(responseData.getBase().getTInsrncBgnTmSY()); insAreaCompany.setSyEndDate(responseData.getBase().getTInsrncEndTmSY()); insAreaCompanyService.save(insAreaCompany); return insAreaCompany; // //插入轨迹表 // InsTaskHistory history = new InsTaskHistory(); // history.setId(String.valueOf(new Date().getTime())); // history.setCompany(insOrder.getInscompany()); // history.setTaskid(insOrder.getOrderno()); // history.setOperatorid(insOrder.getUserid()); // history.setOperator(insOrder.getUsername()); // SimpleDateFormat sdfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // history.setCreatetime(sdfm.format(new Date())); // history.setOperator(insOrder.getUsername()); // history.setStatus("0"); // history.setRemark("报价中"); // insTaskHistoryService.insert(history); } public static double add(double v1, double v2) { BigDecimal b1 = new BigDecimal(Double.toString(v1)); BigDecimal b2 = new BigDecimal(Double.toString(v2)); return b1.add(b2).doubleValue(); } public static String getUserName() { return ""; // String userName = null; // Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); // // if (principal instanceof UserDetails) { // userName = ((UserDetails) principal).getUsername(); // } else { // userName = principal.toString(); // } // return userName; } /** * 验证远程请求 * * @author: lig * @date: 2023年02月22日 0022 */ private void verifyRequest(InsApiLog apiLog, InsAreaCompany insAreaCompany, InsQuoteFlow iqf) { //增加api日志 insApiLogService.insertAsync(new InsApiLog(insAreaCompany, apiLog, iqf)); if (StringUtils.isNotEmpty(apiLog.getExceptionMsg())) { throw new SystemException("远程接口调用异常"); // throw new RuntimeException("远程接口调用异常"); } } // /** // * 验证远程请求 // * // * @author: lig // * @date: 2023年02月22日 0022 // */ // private void verifyRequest(InsApiLog apiLog, InsAreaCompany insAreaCompany) { // //增加api日志 // insApiLogService.insertAsync(new InsApiLog(insAreaCompany, apiLog)); // if (StringUtils.isNotEmpty(apiLog.getExceptionMsg())) { // throw new RuntimeException("远程接口调用异常"); // } // // } /** * 更新api log * * @author: lig * @date: 2023-03-21 */ private void updateApiLog(InsApiLog apiLog, InsAreaCompany iac) { if (null != apiLog && null != iac) { apiLog.setOrderNo(StringUtils.toString(iac.getId())); // apiLog.setOrderStatus(iac.getOrderstatus()); insApiLogService.UpdateAsync(apiLog); } } // @Override // public Map gainRegionCode(String address) { // // log.debug("*********永诚API方式 - 身份证地址解析 参数:" + address); // Map m = IDCardUtils.addressResolution(address); // if (null == m) return null; // String city = m.get("city"); // String district = m.get("district"); //// if(StringUtils.isNullOrEmpty(district)){ //// //第二级赋值到第三级 //// district = city; //// } // // List areaList = new ArrayList<>(); // if (StringUtils.isNotEmpty(district)) { // //查询地区 // LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); // lqw.eq(InsAlltrustRegion::getArea, district); // areaList = insAlltrustRegionMapper.selectList(lqw); // } // // // //如果地区查不到 用城市当地区查 // if (null == areaList || areaList.size() < 1) { // LambdaQueryWrapper cityLqw = new LambdaQueryWrapper<>(); // cityLqw.eq(InsAlltrustRegion::getArea, city); // areaList = insAlltrustRegionMapper.selectList(cityLqw); // } // //如果地区查不到 用城市当地区查 // if (null == areaList || areaList.size() < 1) { // LambdaQueryWrapper cityLqw = new LambdaQueryWrapper<>(); // cityLqw.eq(InsAlltrustRegion::getArea, city); // areaList = insAlltrustRegionMapper.selectList(cityLqw); // } // // // if (null != areaList && areaList.size() > 0) { // Map rMap = new HashMap(); // rMap.put("provinceCode", areaList.get(0).getProvinceCode()); // rMap.put("cityCode", areaList.get(0).getCityCode()); // rMap.put("areaCode", areaList.get(0).getAreaCode()); // return rMap; // } // return null; // } private void buildRegion(Ruote m, BaseQuoteInfoVo yaQuoteInfoVo) { //车主 CustomerInfoVo owner = yaQuoteInfoVo.getOwnerInfo(); //被保人 CustomerInfoVo insured = yaQuoteInfoVo.getInsuredPersonInfo(); //投保人 CustomerInfoVo applicant = yaQuoteInfoVo.getPolicyHolderInfo(); String province = ""; String city = ""; String area = ""; if (null != owner) { InsAlltrustRegion ownerRegion = findRegion(owner); if (null != ownerRegion) { m.getRequestLabel().getCondition().getVhlowner().setCProvince(ownerRegion.getProvinceCode()); m.getRequestLabel().getCondition().getVhlowner().setCCity(ownerRegion.getCityCode()); m.getRequestLabel().getCondition().getVhlowner().setCCounty(ownerRegion.getAreaCode()); } } if (null != insured) { InsAlltrustRegion insuredRegion = findRegion(insured); if (null != insuredRegion) { m.getRequestLabel().getCondition().getInsured().setCProvince(insuredRegion.getProvinceCode()); m.getRequestLabel().getCondition().getInsured().setCCity(insuredRegion.getCityCode()); m.getRequestLabel().getCondition().getInsured().setCCounty(insuredRegion.getAreaCode()); } } if (null != applicant) { InsAlltrustRegion applicantRegion = findRegion(applicant); if (null != applicantRegion) { m.getRequestLabel().getCondition().getApplicant().setCProvince(applicantRegion.getProvinceCode()); m.getRequestLabel().getCondition().getApplicant().setCCity(applicantRegion.getCityCode()); m.getRequestLabel().getCondition().getApplicant().setCCounty(applicantRegion.getAreaCode()); } } } private InsAlltrustRegion findRegion(CustomerInfoVo info) { String province = info.getProvince(); String city = info.getCity(); String area = info.getCounty(); //lig 2023-09-21 临时解决 页面解决后可删除。 if (StringUtils.isEmpty(province) && StringUtils.isEmpty(city) && StringUtils.isEmpty(area)) { throw new SystemException("永诚报价需要录入省市县"); } LambdaQueryWrapper lqw = new LambdaQueryWrapper<>(); lqw.eq(StringUtils.isNotEmpty(province), InsAlltrustRegion::getProvince, province); lqw.eq(StringUtils.isNotEmpty(city), InsAlltrustRegion::getCity, city); lqw.eq(StringUtils.isNotEmpty(area), InsAlltrustRegion::getArea, area); try { return insAlltrustRegionMapper.selectOne(lqw); } catch (Exception e) { throw new SystemException("永诚 - 省市县校验失败," + province + city + area); } } // private void buildRegion(Ruote m) { // //车主 // Vhlowner owner = m.getRequestLabel().getCondition().getVhlowner(); // //被保人 // Insured i = m.getRequestLabel().getCondition().getInsured(); // //投保人 // Applicant a = m.getRequestLabel().getCondition().getApplicant(); // // // String provinceCode = "provinceCode"; // String cityCode = "cityCode"; // String areaCode = "areaCode"; //// owner.getCAreaCde() // // Map ownerMap = gainRegionCode(owner.getCWaddress()); // if (null != ownerMap && ownerMap.size() > 0) { // owner.setCProvince(ownerMap.get(provinceCode)); // owner.setCCity(ownerMap.get(cityCode)); // owner.setCCounty(ownerMap.get(areaCode)); // //清空格式化 自建数据 // owner.setCWaddress(null); // } else { // throw new SystemException("永诚 - 车主地区获取失败,请联系管理员"); // } // // Map iMap = gainRegionCode(i.getCClntAddr()); // if (null != iMap && iMap.size() > 0) { // i.setCProvince(iMap.get(provinceCode)); // i.setCCity(iMap.get(cityCode)); // i.setCCounty(iMap.get(areaCode)); // } else { // throw new SystemException("永诚 - 被保人地区获取失败,请联系管理员"); // } // // Map aMap = gainRegionCode(a.getCClntAddr()); // if (null != aMap && aMap.size() > 0) { // a.setCProvince(aMap.get(provinceCode)); // a.setCCity(aMap.get(cityCode)); // a.setCCounty(aMap.get(areaCode)); // } else { // throw new SystemException("永诚 - 投保人地区获取失败,请联系管理员"); // } // } /** * 构造回调 * 依赖 buildCallBack * * @author: lig * @date: 2023-05-06 */ private InsAreaCompany buildCallBack(InsAreaCompany iac, CallBackRequest param) { //正常回调 与 补传回调 if (StringUtils.isNotEmpty(param.getStatus())) { iac = buildCallBackStatus(iac, param.getStatus()); } else { if (StringUtils.isNotEmpty(param.getJqstatus())) { iac = buildCallBackStatus(iac, param.getJqstatus()); } if (StringUtils.isNotEmpty(param.getSystatus())) { iac = buildCallBackStatus(iac, param.getSystatus()); } } return iac; } /** * 构造回调状态 * * @author: lig * @date: 2023-05-06 */ private InsAreaCompany buildCallBackStatus(InsAreaCompany iac, String status) { if (status.equals("9")) { iac.setOrderstatus(InsOrderStatus.S_2.getCode()); //更新支付连接 log.debug("准备进入获取支付连接######################"); iac = getPayUrlApi(iac); log.debug("结束 - 准备进入获取支付连接######################"); } if (status.equals("3")) { iac.setOrderstatus(InsOrderStatus.S_4.getCode()); } if (status.equals("1")) { iac.setOrderstatus(InsOrderStatus.S_3.getCode()); } return iac; } // /** // * 通过修改参数后 报价 // * // * @author: lig // * @date: 2023年05月17日 0017 // */ // private RuoteResponse quoteApiByEdit(Ruote m) { // // RuoteResponse rd = null; // // log.debug("=========永诚API方式 - xml请求 - (修改参数后)报价开始======"); // InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_QUOTE); // log.debug("=========永诚API方式 - xml请求 - (修改参数后)报价结束!======"); // verifyRequest(apiLog, null, InsQuoteFlow.Q_S_0); // // String responseData = apiLog.getResponseData(); // // try { // String cleanStr = YcBuildData.cleanResponseStr(responseData); // rd = xmlMapper.readValue(cleanStr, RuoteResponse.class); // // // } catch (IOException e) { // log.error("=========永诚API方式 - xml请求 - (修改参数后)报价 错误:" + e.getMessage()); // throw new RuntimeException(e); // } // return rd; // // } /** * 请求API接口,返回对象 * * @author: lig * @date: 2023年05月18日 0018 */ private T requestApi(Object m, T response, InsAreaCompany iac, String reqUrl, InsQuoteFlow iqf, String textHead) { String responseData = httpPostResultLog(xmlMapper, m, reqUrl, textHead); if (responseData.contains("报价返回信息异常")) { throw new SystemException("永诚报价请求负荷,请稍后重试。"); } String cleanStr = YcBuildData.cleanResponseStr(responseData); try { response = (T) xmlMapper.readValue(cleanStr, response.getClass()); return response; } catch (JsonProcessingException e) { log.debug("=========永诚API方式 - xml请求 - {}解析报错:{}", iqf.getDesc(), e.getMessage()); throw new SystemException("请求接口失败,对象转换错误,请联系管理员。"); } } // private boolean gainResultFlag(RuoteResponse rd,Ruote m){ // boolean flag = false; // if (null == rd) { // throw new SystemException("远程请求报价失败"); // } // // if (rd.getHead().getErrorCode().equals("000000")) { // //获取失败 // boolean fail = !(StringUtils.isNotEmpty(rd.getVhl().getCQryCdeJQ()) || StringUtils.isNotEmpty(rd.getVhl().getCQryCdeSY())); // if (fail) { // //如果类型错误,修改类型后,继续报价 // if (StringUtils.isNotEmpty(rd.getVhl().getCBusType())) { // //修改类型继续报价 // m.getRequestLabel().getCondition().getVhl().setCBusType(rd.getVhl().getCBusType()); // rd = requestApi(m, new RuoteResponse(), iac, YcBuildData.API_QUOTE, InsQuoteFlow.Q_S_0); // if (null == rd) return HttpResult.error("远程请求报价失败"); // if (fail) { // throw new SystemException(rd.getHead().getErrorMessage()); // } // } // throw new SystemException(rd.getHead().getErrorMessage()); // } // } else { // throw new SystemException(rd.getHead().getErrorMessage()); // } // // } private YcConfigureParameters gainYcConfigParams(String agreementId) { YcConfigureParameters ycConfigureParameters = new YcConfigureParameters(); configureParametersComponents.toEntity(ycConfigureParameters, agreementId); return ycConfigureParameters; } /** * 获取车险保单 * * @author: lig * @date: 2023年09月21日 0021 */ public String gainCarInsPolicy(String url, String fileName, String licensePlate) { String dir = "carInsPolicy/" + licensePlate + "/"; return FileUtil.netUrlToFile(url, dir, fileName, uploadFilePath, apiUrl + showFileUrl); } /** * 获取《存在》的保单地址 * * @author: lig * @date: 2023年09月21日 0021 */ public String gainExistCarInsPolicy(String fileName, String licensePlate) { String dir = SysConstants.CAR_INS_POLICY + "/" + licensePlate + "/"; return FileUtil.fileExist(dir, fileName, uploadFilePath, apiUrl + showFileUrl); } }