| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600 |
- 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.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);
- }
- }
- /**
- * 2 报价
- */
- @Override
- public HttpResult quoteApi(BaseQuoteVo<AccidentalDrivingVo> quoteVo) {
- // 获取协议配置信息
- YcConfigureParameters ycConfigureParameters = gainYcConfigParams(quoteVo.getAgreementId());
- // public HttpResult quoteApi(BaseQuoteInfoVo yaQuoteInfoVo) {
- BaseQuoteInfoVo yaQuoteInfoVo = insOrdersComponents.getQuoteInfo(quoteVo.getOrderNo());
- 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<String, String> 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<InsTaskImage> 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<InsAreaCompany> 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<EsmInsAttachInsure> lqw = new LambdaQueryWrapper<EsmInsAttachInsure>();
- lqw.eq(EsmInsAttachInsure::getCompanyId, accidentalDrivingVo.getCompanyCode());
- lqw.eq(EsmInsAttachInsure::getSeating, accidentalDrivingVo.getSeatNum());
- esmInsAttachInsureMapper.delete(lqw);
- List<ResponseYwCvrg.CvrgList> cList = accidentResp.getResponseYwCvrg().getCvrgList();
- List<EsmInsAttachInsure> 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<EsmInsAttachInsure> eiaiList = new ArrayList<>();
- if (ar.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
- //清空旧的存入表
- LambdaQueryWrapper<EsmInsAttachInsure> lqw = new LambdaQueryWrapper<EsmInsAttachInsure>();
- lqw.eq(EsmInsAttachInsure::getCompanyId, accidentalDrivingVo.getCompanyCode());
- lqw.eq(EsmInsAttachInsure::getSeating, accidentalDrivingVo.getSeatNum());
- lqw.select(EsmInsAttachInsure::getId);
- List<EsmInsAttachInsure> eiaiList = esmInsAttachInsureMapper.selectList(lqw);
- //删除已经存在的数据
- if (null != eiaiList && eiaiList.size() > 0) {
- List<String> ids = new ArrayList<>();
- eiaiList.stream().forEach(i -> {
- ids.add(i.getId());
- });
- LambdaQueryWrapper<EsmInsAttachInsureDetails> lqwDetails = new LambdaQueryWrapper<>();
- lqwDetails.in(EsmInsAttachInsureDetails::getAttachInsureId, ids);
- //详情删除
- esmInsAttachInsureDetailsMapper.delete(lqwDetails);
- // esmInsAttachInsureMapper.delete(lqw);
- esmInsAttachInsureMapper.deleteBatchIds(ids);
- }
- List<ResponseYwCvrg.CvrgList> 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<ResponseYwCvrg.CvrgList> 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<EsmInsAttachInsure> lqw = new LambdaQueryWrapper<EsmInsAttachInsure>();
- // lqw.eq(EsmInsAttachInsure::getCompanyId,accidentalDrivingVo.getCompanyCode());
- // lqw.eq(EsmInsAttachInsure::getSeating,accidentalDrivingVo.getSeatNum());
- // esmInsAttachInsureMapper.delete(lqw);
- //
- // List<ResponseYwCvrg.CvrgList> cList = accidentResp.getResponseYwCvrg().getCvrgList();
- //
- // List<EsmInsAttachInsure> 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<InsAreaCompany> 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<CarModelDTO> buildCarModel(ModelsQueryResponse modelsQueryResponse) {
- List<ModelsQueryResponse.VehicleInfo> vList = modelsQueryResponse.getVehicleInfoList();
- List<CarModelDTO> carModelList = new ArrayList<>();
- vList.stream().forEach(a -> {
- CarModelDTO dto = new CarModelDTO();
- BeanUtils.copyProperties(a, dto);
- carModelList.add(dto);
- });
- return carModelList;
- }
- private <T> InsApiLog httpPost(ObjectMapper mapper, T requestData, String apiName) {
- String xmlString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"http://newWS.front.app.echannel.ebiz.alltrust.com/\">";
- xmlString += "<soapenv:Body>";
- try {
- mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
- xmlString += mapper.writeValueAsString(requestData);
- xmlString += "</soapenv:Body>\n" +
- "</soapenv:Envelope>";
- } 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<InsOrder> 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<RiskInfoVo> 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<KindInfoVo> kinds = record.getKindList();
- // String productId = "";
- // String productname = "";
- //
- // List<EsmAgreement> 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<EsmAgreementProd> 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<EsmRetail> list = esmRetailService.selectList(" where deptid = ? and status=?", new Object[]{deptid, "1"});
- // //2、根据userid查询三级推荐人
- // List<SysUser> 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<Double> rateList = new ArrayList<Double>();
- // 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<AccidentalDrivingVo> 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<String, String> gainRegionCode(String address) {
- log.debug("*********永诚API方式 - 身份证地址解析 参数:" + address);
- Map<String, String> 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<InsAlltrustRegion> areaList = new ArrayList<>();
- if (StringUtils.isNotEmpty(district)) {
- //查询地区
- LambdaQueryWrapper<InsAlltrustRegion> lqw = new LambdaQueryWrapper<>();
- lqw.eq(InsAlltrustRegion::getArea, district);
- areaList = insAlltrustRegionMapper.selectList(lqw);
- }
- //如果地区查不到 用城市当地区查
- if (null == areaList || areaList.size() < 1) {
- LambdaQueryWrapper<InsAlltrustRegion> 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<String, String> 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<String, String> 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<String, String> 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> 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;
- }
- }
|