package com.ydtech.modules.ins.service.impl; 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.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.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.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.utils.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; 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.LocalDateTime; import java.util.*; import java.util.concurrent.atomic.AtomicInteger; @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; @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 方式 // /** * 1 车型查询接口 */ @Override public HttpResult modelsQueryApi(CarModel_Req carModelReq) { // if (org.springframework.util.StringUtils.isEmpty(carModelReq.getFrameNo()) || org.springframework.util.StringUtils.isEmpty(carModelReq.getEnrollDate()) || org.springframework.util.StringUtils.isEmpty(carModelReq.getModelName())) { // return HttpResult.error("frameNo, enrollDate, modelName 这些参数不能为空!"); // } // gainAuthorityDataXml(), apiComponents.gainAgent() // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(carModelReq.getAgreementId()); ModelsQueryXml m = buildModelsQueryParam(carModelReq, ycConfigureParameters); ObjectMapper xmlMapper = this.gainXmlMapper(); log.info("===永诚--车型查询接口请求开始==="); InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_MODEL); String responseData = apiLog.getResponseData(); log.info("===永诚--车型查询接口请求结束==="); try { String cleanStr = YcBuildData.cleanResponseStr(responseData); ModelsQueryResponse rd = xmlMapper.readValue(cleanStr, ModelsQueryResponse.class); if (rd.getReturnCode().equals("E0001")) { return HttpResult.ok(rd.getMsg()); } return HttpResult.ok(buildCarModel(rd)); } catch (IOException e) { throw new RuntimeException(e); } } @Override public List modelsQuery(CarModel_Req carModelReq) { // public List modelsQuery(CarModel_Req carModelReq) { // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(carModelReq.getAgreementId()); ModelsQueryXml m = buildModelsQueryParam(carModelReq, ycConfigureParameters); ObjectMapper xmlMapper = this.gainXmlMapper(); log.info("===永诚--车型查询接口请求开始==="); InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_MODEL); String responseData = apiLog.getResponseData(); log.info("===永诚--车型查询接口请求结束==="); try { String cleanStr = YcBuildData.cleanResponseStr(responseData); ModelsQueryResponse rd = xmlMapper.readValue(cleanStr, ModelsQueryResponse.class); return buildCarModel(rd); } catch (IOException e) { throw new RuntimeException(e); } } 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("-","")); ModelsQueryXml m = buildModelsQueryParam(carModelReq, ycConfigureParameters); ObjectMapper xmlMapper = this.gainXmlMapper(); log.info("===永诚--车型查询接口请求开始==="); InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_MODEL); String responseData = apiLog.getResponseData(); log.info("===永诚--车型查询接口请求结束==="); try { String cleanStr = YcBuildData.cleanResponseStr(responseData); ModelsQueryResponse rd = xmlMapper.readValue(cleanStr, ModelsQueryResponse.class); List vehicleInfoList = buildCarModel(rd); long count = vehicleInfoList.stream().filter(x -> x.getModelCode().equals(carInfo.getModelCode())).count(); if(count < 1 ){ //匹配车辆信息 vehicleInfoList.stream().forEach(a ->{ //购置价匹配 if(a.getVehiclePrice().equals(carInfo.getPurchasePrice())){ carInfo.setModelCode(a.getModelCode()); carInfo.setCiModelCode(a.getModelCode()); carInfo.setCiCarName(a.getVehicleName()); carInfo.setModelcname(a.getVehicleName()); } }); } } catch (IOException e) { throw new SystemException("车型查询接口异常,请联系管理。"); } } /** * 2 报价 */ @Override public HttpResult quoteApi(BaseQuoteVo quoteVo) { // 获取协议配置信息 YcConfigureParameters ycConfigureParameters = gainYcConfigParams(quoteVo.getAgreementId()); BaseQuoteInfoVo yaQuoteInfoVo = insOrdersComponents.getQuoteInfo(quoteVo.getOrderNo()); gainVehicleModel(ycConfigureParameters, yaQuoteInfoVo.getCarInfo()); 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); //请求转保处理 if (StringUtils.isNotEmpty(quoteVo.getRenewalCodeJq()) || StringUtils.isNotEmpty(quoteVo.getRenewalCodeSy())) { m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(quoteVo.getRenewalCodeJq()); m.getRequestLabel().getCondition().getVhl().setCCheckCodeSY(quoteVo.getRenewalCodeSy()); m.getRequestLabel().getCondition().getVhl().setCBusType("2"); m.getRequestLabel().getCondition().getVhl().setCQryCdeJQ(quoteVo.getCQryCdeJq()); m.getRequestLabel().getCondition().getVhl().setCQryCdeSY(quoteVo.getCQryCdeSy()); } RuoteResponse rr = requestApi(m, new RuoteResponse(), iac, YcBuildData.API_QUOTE, InsQuoteFlow.Q_S_0); if (null == rr) return HttpResult.error("远程请求报价失败"); if (rr.getHead().getErrorCode().equals("000000")) { String cCheckCodeJQ = rr.getVhl().getCCheckCodeJQ(); String cCheckCodeSY = rr.getVhl().getCCheckCodeSY(); boolean flagTransferInsJQ = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeJQ()) && StringUtils.isNotEmpty(rr.getVhl().getCQryCdeJQ()); boolean flagTransferInsSY = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeSY()) && StringUtils.isNotEmpty(rr.getVhl().getCQryCdeSY()); boolean flagTransferIns = StringUtils.isNotEmpty(rr.getVhl().getCBusType()) && (flagTransferInsJQ || flagTransferInsSY); //响应 转保单 if (flagTransferIns) { quoteVo.setRenewalCodeJq(cCheckCodeJQ); quoteVo.setRenewalCodeSy(cCheckCodeSY); quoteVo.setCQryCdeJq(rr.getVhl().getCQryCdeJQ()); quoteVo.setCQryCdeSy(rr.getVhl().getCQryCdeSY()); return HttpResult.error(101, quoteVo, "转保单"); } } else { return HttpResult.error(rr.getHead().getErrorMessage()); // throw new SystemException(rd.getHead().getErrorMessage()); } // RuoteResponse rr = null; // int flag = 0; // while (flag < 3) { // log.debug("永诚API方式 - 报价 - 请求 {} 次",flag); // rr = requestApi(m, new RuoteResponse(), iac, YcBuildData.API_QUOTE, InsQuoteFlow.Q_S_0); // if (null == rr) return HttpResult.error("远程请求报价失败"); // if (rr.getHead().getErrorCode().equals("000000")) { // // String cCheckCodeJQ = rr.getVhl().getCCheckCodeJQ(); // String cCheckCodeSY = rr.getVhl().getCCheckCodeSY(); // // boolean flagTransferInsJQ = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeJQ()) && // StringUtils.isNotEmpty(rr.getVhl().getCQryCdeJQ()); // boolean flagTransferInsSY = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeSY()) && // StringUtils.isNotEmpty(rr.getVhl().getCQryCdeSY()); // boolean flagTransferIns = StringUtils.isNotEmpty(rr.getVhl().getCBusType()) && (flagTransferInsJQ || flagTransferInsSY); // //转保单 // if (flagTransferIns) { // log.debug("永诚API方式 - 报价 - 转保单业务处理"); // String cBusType = rr.getVhl().getCBusType(); // m.getRequestLabel().getCondition().getVhl().setCBusType(cBusType); // if(flagTransferInsJQ){ // String imgStr = Tess4jOcr.ocrImageStr(cCheckCodeJQ); // //获取图片的验证码 // m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(imgStr); // } // if(flagTransferInsSY){ // String imgStr = Tess4jOcr.ocrImageStr(cCheckCodeJQ); // //获取图片的验证码 // m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(imgStr); // } // // }else{ // flag = 10; // } // // flag++; // // // // } else { // return HttpResult.error(rr.getHead().getErrorMessage()); //// throw new SystemException(rd.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()); return HttpResult.ok("报价成功", quoteRespVo); } /** * 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); //处理地区 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); 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; //组装参数 log.debug("=========永诚API方式 - xml请求 - 影像上传开始======"); //接口请求 ImageUp iUp = ImageUp.buildImageUpParam(order, ycConfigureParameters, a.getImage(), a.getImgtype()); log.debug("=========永诚API方式 - xml请求 - 影像上传结束!======"); ObjectMapper xmlMapper = gainXmlMapper(); //接口请求 apiLog = httpPost(xmlMapper, iUp, YcBuildData.API_UPLOAD); 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请求 - 获取缴费链接开始======"); 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) { 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(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(); //接口请求 log.debug("=========永诚API方式 - xml请求 - 补传回调开始======"); InsApiLog apiLog = httpPost(xmlMapper, o, YcBuildData.API_ORDER_QUERY); log.debug("=========永诚API方式 - xml请求 - 补传回调结束!======"); verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_5); String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); // CallbackAnOrderResponse callbackAnOrderResponse = xmlMapper.readValue(cleanStr, CallbackAnOrderResponse.class); if (StringUtils.isNotEmpty(cleanStr)) { 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("系统错误,请联系管理员"); } return httpResult; } /** * 6 电子保单 */ @Override public HttpResult getPolicyPrintApi(PolicyPrintVo policyPrintVo) { HttpResult httpResult = new HttpResult(); try { InsAreaCompany iac = insAreaCompanyService.getById(policyPrintVo.getCompanyId()); // InsOrder order = insOrderService.selectByPk(orderno); if (iac == null) { return HttpResult.error("报价订单不存在"); } // 获取协议配置信息 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请求 - 获取保单开始======"); 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(); if (policyPrintVo.getType().equals("1")) { m.put("jqFlagUrl", pResp.getPolicyBZUrl()); m.put("jqUrl", ""); m.put("syUrl", ""); } if (policyPrintVo.getType().equals("2")) { m.put("jqFlagUrl", pResp.getPolicyBZUrl()); m.put("jqUrl", pResp.getJqpolicyUrl()); m.put("syUrl", pResp.getSypolicyUrl()); } // 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请求 - 获取意健险方案及险种查询开始======"); 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请求 - 获取意健险方案及险种查询开始======"); 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()); 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; } /** * @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()); 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() > 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) { //车主 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) { // private Object aaa(T m,T ruoteResponse,InsAreaCompany iac){ //6 接口请求 log.debug("=========永诚API方式 - xml请求 - {}开始======", iqf.getDesc()); InsApiLog apiLog = httpPost(xmlMapper, m, reqUrl); log.debug("=========永诚API方式 - xml请求 - {}结束!======", iqf.getDesc()); verifyRequest(apiLog, iac, iqf); String responseData = apiLog.getResponseData(); String cleanStr = YcBuildData.cleanResponseStr(responseData); // Object rd = null; try { response = (T) xmlMapper.readValue(cleanStr, response.getClass()); return response; } catch (JsonProcessingException e) { log.debug("=========永诚API方式 - xml请求 - {}解析报错:{}", iqf.getDesc(), e.getMessage()); // throw new RuntimeException(e); 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; } }