InsAlltrustApiServiceImpl.java 67 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600
  1. package com.ydtech.modules.ins.service.impl;
  2. import com.alibaba.fastjson.JSONObject;
  3. import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
  4. import com.fasterxml.jackson.annotation.JsonInclude;
  5. import com.fasterxml.jackson.core.JsonProcessingException;
  6. import com.fasterxml.jackson.databind.*;
  7. import com.fasterxml.jackson.dataformat.xml.XmlMapper;
  8. import com.ydtech.components.InsAlltrustRequestApiComponents;
  9. import com.ydtech.constants.InsTaskHistoryEnum;
  10. import com.ydtech.constants.enums.InsOrderStatus;
  11. import com.ydtech.constants.enums.InsQuoteFlow;
  12. import com.ydtech.constants.enums.dict.AttachInsureEnum;
  13. import com.ydtech.constants.enums.dict.WhetherEnum;
  14. import com.ydtech.core.page.HttpResult;
  15. import com.ydtech.exception.SystemException;
  16. import com.ydtech.modules.admin.service.SysDeptService;
  17. import com.ydtech.modules.admin.service.SysUserService;
  18. import com.ydtech.modules.esm.dao.EsmInsAttachInsureDetailsMapper;
  19. import com.ydtech.modules.esm.dao.EsmInsAttachInsureMapper;
  20. import com.ydtech.modules.esm.model.*;
  21. import com.ydtech.modules.esm.service.*;
  22. import com.ydtech.modules.ins.dao.InsAlltrustRegionMapper;
  23. import com.ydtech.modules.ins.model.InsApiLog;
  24. import com.ydtech.modules.ins.model.vo.CustomerInfoVo;
  25. import com.ydtech.modules.ins.model.vo.QuoteRespVo;
  26. import com.ydtech.modules.ins.model.vo.RiskInfoVo;
  27. import com.ydtech.modules.ins.model.ya.CarModelDTO;
  28. import com.ydtech.modules.ins.model.ya.CarModel_Req;
  29. import com.ydtech.modules.ins.model.ya.YaQuoteInfoVo;
  30. import com.ydtech.modules.ins.model.yc.*;
  31. import com.ydtech.modules.ins.model.yc.accident.response.ResponseYwCvrg;
  32. import com.ydtech.modules.ins.model.yc.audit.Audit;
  33. import com.ydtech.modules.ins.model.yc.audit.response.AuditResponse;
  34. import com.ydtech.modules.ins.model.yc.callbackAnOrder.CallbackAnOrder;
  35. import com.ydtech.modules.ins.model.yc.imageUp.ImageUp;
  36. import com.ydtech.modules.ins.model.yc.imageUp.response.ImageUpResponse;
  37. import com.ydtech.modules.ins.model.yc.modelsQuery.ModelsQueryResponse;
  38. import com.ydtech.modules.ins.model.yc.modelsQuery.ModelsQueryXml;
  39. import com.ydtech.modules.ins.model.yc.accident.Accident;
  40. import com.ydtech.modules.ins.model.yc.pay.Pay;
  41. import com.ydtech.modules.ins.model.yc.pay.response.AccidentResponse;
  42. import com.ydtech.modules.ins.model.yc.pay.response.PayResponse;
  43. import com.ydtech.modules.ins.model.yc.policy.Policy;
  44. import com.ydtech.modules.ins.model.yc.policy.response.PolicyResponse;
  45. import com.ydtech.modules.ins.model.yc.ruote.*;
  46. import com.ydtech.modules.ins.model.yc.ruote.response.RuoteResponse;
  47. import com.ydtech.modules.ins.service.*;
  48. import com.ydtech.modules.order.components.ConfigureParametersComponents;
  49. import com.ydtech.modules.order.components.InsOrdersComponents;
  50. import com.ydtech.modules.order.entity.InsAreaCompany;
  51. import com.ydtech.modules.order.entity.InsOrders;
  52. import com.ydtech.modules.order.entity.vo.*;
  53. import com.ydtech.modules.order.service.InsAreaCompanyService;
  54. import com.ydtech.modules.order.service.InsOrdersService;
  55. import com.ydtech.utils.*;
  56. import org.slf4j.Logger;
  57. import org.slf4j.LoggerFactory;
  58. import org.springframework.beans.BeanUtils;
  59. import org.springframework.beans.factory.annotation.Autowired;
  60. import org.springframework.stereotype.Service;
  61. import org.springframework.transaction.annotation.Transactional;
  62. import java.io.IOException;
  63. import java.math.BigDecimal;
  64. import java.text.SimpleDateFormat;
  65. import java.time.LocalDateTime;
  66. import java.util.*;
  67. import java.util.concurrent.atomic.AtomicInteger;
  68. @Service
  69. public class InsAlltrustApiServiceImpl implements InsAlltrustApiService {
  70. private static final Logger log = LoggerFactory.getLogger("alltrust");
  71. @Autowired
  72. private InsAlltrustRequestApiComponents apiComponents;
  73. @Autowired
  74. private InsAlltrustRegionMapper insAlltrustRegionMapper;
  75. @Autowired
  76. private InsOrdersComponents insOrdersComponents;
  77. private AuthorityDataXml authorityDataXml = null;
  78. private ObjectMapper xmlMapper = null;
  79. @Autowired
  80. private YcBuildData ycBuildData;
  81. @Autowired
  82. private SysUserService sysUserService;
  83. @Autowired
  84. private SysDeptService sysDeptService;
  85. @Autowired
  86. private EsmRetailService esmRetailService;
  87. @Autowired
  88. private EsmAgreementService esmAgreementService;
  89. @Autowired
  90. private EsmAgreementProdService esmAgreementProdService;
  91. // @Autowired
  92. // private EsmUserInternalService esmUserInternalService;
  93. @Autowired
  94. private InsTaskHistoryService insTaskHistoryService;
  95. @Autowired
  96. private InsAreaCompanyService insAreaCompanyService;
  97. @Autowired
  98. private InsOrdersService insOrdersService;
  99. @Autowired
  100. private InsTaskImageService insTaskImageService;
  101. @Autowired
  102. private EsmInsAttachInsureMapper esmInsAttachInsureMapper;
  103. @Autowired
  104. private EsmInsAttachInsureDetailsMapper esmInsAttachInsureDetailsMapper;
  105. @Autowired
  106. private EsmInsCompanyService esmInsCompanyService;
  107. @Autowired
  108. InsApiLogService insApiLogService;
  109. @Autowired
  110. ConfigureParametersComponents configureParametersComponents;
  111. // /**
  112. // * @description: 获取验证数据
  113. // * @author: lig
  114. // * @date: 2023年02月07日 0007
  115. // */
  116. // private AuthorityDataXml gainAuthorityDataXml() {
  117. // if (null == authorityDataXml) {
  118. // authorityDataXml = new AuthorityDataXml();
  119. // authorityDataXml.setUserName(apiComponents.getUserName());
  120. // authorityDataXml.setPassword(apiComponents.getPassword());
  121. // }
  122. // return authorityDataXml;
  123. // }
  124. // /**
  125. // * 获取渠道
  126. // */
  127. // public Agent gainAgent() {
  128. // return apiComponents.gainAgent();
  129. //// if (null == agent) {
  130. //// agent = new Agent();
  131. //// agent.setAgentCode(agentCode);
  132. //// agent.setConferCode(agentType);
  133. //// agent.setAgentType(agentType);
  134. //// agent.setAgentNme(agentNme);
  135. //// agent.setQlftNo(qlftNo);
  136. //// agent.setCustNature(custNature);
  137. //// agent.setAgentProfId(agentCode);
  138. //// agent.setSubCoNo(agentType);
  139. //// }
  140. //// return agent;
  141. // }
  142. private ObjectMapper gainXmlMapper() {
  143. if (null == xmlMapper) {
  144. xmlMapper = new XmlMapper();
  145. xmlMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
  146. xmlMapper.configure(SerializationFeature.WRAP_ROOT_VALUE, false);
  147. xmlMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  148. xmlMapper.setPropertyNamingStrategy(PropertyNamingStrategy.UPPER_CAMEL_CASE);
  149. xmlMapper.enable(MapperFeature.USE_STD_BEAN_NAMING);
  150. xmlMapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
  151. }
  152. return xmlMapper;
  153. }
  154. //
  155. //==============================API 方式
  156. //
  157. /**
  158. * 1 车型查询接口
  159. */
  160. @Override
  161. public HttpResult modelsQueryApi(CarModel_Req carModelReq) {
  162. // if (org.springframework.util.StringUtils.isEmpty(carModelReq.getFrameNo()) || org.springframework.util.StringUtils.isEmpty(carModelReq.getEnrollDate()) || org.springframework.util.StringUtils.isEmpty(carModelReq.getModelName())) {
  163. // return HttpResult.error("frameNo, enrollDate, modelName 这些参数不能为空!");
  164. // }
  165. // gainAuthorityDataXml(), apiComponents.gainAgent()
  166. // 获取协议配置信息
  167. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(carModelReq.getAgreementId());
  168. ModelsQueryXml m = buildModelsQueryParam(carModelReq, ycConfigureParameters);
  169. ObjectMapper xmlMapper = this.gainXmlMapper();
  170. log.info("===永诚--车型查询接口请求开始===");
  171. InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_MODEL);
  172. String responseData = apiLog.getResponseData();
  173. log.info("===永诚--车型查询接口请求结束===");
  174. try {
  175. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  176. ModelsQueryResponse rd = xmlMapper.readValue(cleanStr, ModelsQueryResponse.class);
  177. if (rd.getReturnCode().equals("E0001")) {
  178. return HttpResult.ok(rd.getMsg());
  179. }
  180. return HttpResult.ok(buildCarModel(rd));
  181. } catch (IOException e) {
  182. throw new RuntimeException(e);
  183. }
  184. }
  185. /**
  186. * 2 报价
  187. */
  188. @Override
  189. public HttpResult quoteApi(BaseQuoteVo<AccidentalDrivingVo> quoteVo) {
  190. // 获取协议配置信息
  191. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(quoteVo.getAgreementId());
  192. // public HttpResult quoteApi(BaseQuoteInfoVo yaQuoteInfoVo) {
  193. BaseQuoteInfoVo yaQuoteInfoVo = insOrdersComponents.getQuoteInfo(quoteVo.getOrderNo());
  194. HttpResult httpResult = new HttpResult();
  195. ObjectMapper xmlMapper = this.gainXmlMapper();
  196. InsAreaCompany iac = null;
  197. InsOrders order = insOrdersService.getById(yaQuoteInfoVo.getOrderNo());
  198. AccidentalDrivingVo adVo = quoteVo.getAccidentalDrivingVo();
  199. //1.1必填校验
  200. checkEmpty(yaQuoteInfoVo);
  201. //组装参数
  202. Ruote m = Ruote.buildQuoteParam(yaQuoteInfoVo, ycConfigureParameters, apiComponents, adVo);
  203. //构造地区
  204. buildRegion(m);
  205. //请求转保处理
  206. if (StringUtils.isNotEmpty(quoteVo.getRenewalCodeJq()) || StringUtils.isNotEmpty(quoteVo.getRenewalCodeSy())) {
  207. m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(quoteVo.getRenewalCodeJq());
  208. m.getRequestLabel().getCondition().getVhl().setCCheckCodeSY(quoteVo.getRenewalCodeSy());
  209. m.getRequestLabel().getCondition().getVhl().setCBusType("2");
  210. m.getRequestLabel().getCondition().getVhl().setCQryCdeJQ(quoteVo.getCQryCdeJq());
  211. m.getRequestLabel().getCondition().getVhl().setCQryCdeSY(quoteVo.getCQryCdeSy());
  212. }
  213. RuoteResponse rr = requestApi(m, new RuoteResponse(), iac, YcBuildData.API_QUOTE, InsQuoteFlow.Q_S_0);
  214. if (null == rr) return HttpResult.error("远程请求报价失败");
  215. if (rr.getHead().getErrorCode().equals("000000")) {
  216. String cCheckCodeJQ = rr.getVhl().getCCheckCodeJQ();
  217. String cCheckCodeSY = rr.getVhl().getCCheckCodeSY();
  218. boolean flagTransferInsJQ = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeJQ()) &&
  219. StringUtils.isNotEmpty(rr.getVhl().getCQryCdeJQ());
  220. boolean flagTransferInsSY = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeSY()) &&
  221. StringUtils.isNotEmpty(rr.getVhl().getCQryCdeSY());
  222. boolean flagTransferIns = StringUtils.isNotEmpty(rr.getVhl().getCBusType()) && (flagTransferInsJQ || flagTransferInsSY);
  223. //响应 转保单
  224. if (flagTransferIns) {
  225. quoteVo.setRenewalCodeJq(cCheckCodeJQ);
  226. quoteVo.setRenewalCodeSy(cCheckCodeSY);
  227. quoteVo.setCQryCdeJq(rr.getVhl().getCQryCdeJQ());
  228. quoteVo.setCQryCdeSy(rr.getVhl().getCQryCdeSY());
  229. return HttpResult.error(101, quoteVo, "转保单");
  230. }
  231. } else {
  232. return HttpResult.error(rr.getHead().getErrorMessage());
  233. // throw new SystemException(rd.getHead().getErrorMessage());
  234. }
  235. // RuoteResponse rr = null;
  236. // int flag = 0;
  237. // while (flag < 3) {
  238. // log.debug("永诚API方式 - 报价 - 请求 {} 次",flag);
  239. // rr = requestApi(m, new RuoteResponse(), iac, YcBuildData.API_QUOTE, InsQuoteFlow.Q_S_0);
  240. // if (null == rr) return HttpResult.error("远程请求报价失败");
  241. // if (rr.getHead().getErrorCode().equals("000000")) {
  242. //
  243. // String cCheckCodeJQ = rr.getVhl().getCCheckCodeJQ();
  244. // String cCheckCodeSY = rr.getVhl().getCCheckCodeSY();
  245. //
  246. // boolean flagTransferInsJQ = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeJQ()) &&
  247. // StringUtils.isNotEmpty(rr.getVhl().getCQryCdeJQ());
  248. // boolean flagTransferInsSY = StringUtils.isNotEmpty(rr.getVhl().getCCheckCodeSY()) &&
  249. // StringUtils.isNotEmpty(rr.getVhl().getCQryCdeSY());
  250. // boolean flagTransferIns = StringUtils.isNotEmpty(rr.getVhl().getCBusType()) && (flagTransferInsJQ || flagTransferInsSY);
  251. // //转保单
  252. // if (flagTransferIns) {
  253. // log.debug("永诚API方式 - 报价 - 转保单业务处理");
  254. // String cBusType = rr.getVhl().getCBusType();
  255. // m.getRequestLabel().getCondition().getVhl().setCBusType(cBusType);
  256. // if(flagTransferInsJQ){
  257. // String imgStr = Tess4jOcr.ocrImageStr(cCheckCodeJQ);
  258. // //获取图片的验证码
  259. // m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(imgStr);
  260. // }
  261. // if(flagTransferInsSY){
  262. // String imgStr = Tess4jOcr.ocrImageStr(cCheckCodeJQ);
  263. // //获取图片的验证码
  264. // m.getRequestLabel().getCondition().getVhl().setCCheckCodeJQ(imgStr);
  265. // }
  266. //
  267. // }else{
  268. // flag = 10;
  269. // }
  270. //
  271. // flag++;
  272. //
  273. //
  274. //
  275. // } else {
  276. // return HttpResult.error(rr.getHead().getErrorMessage());
  277. //// throw new SystemException(rd.getHead().getErrorMessage());
  278. // }
  279. //
  280. // }
  281. QuoteRespVo quoteRespVo = YcBuildData.buildQuoteRespVo(order, rr, yaQuoteInfoVo);
  282. //8 生成订单
  283. iac = response_order(order, quoteRespVo, m, rr, quoteVo);
  284. // updateApiLog(apiLog, iac);
  285. quoteRespVo.setCompanyId(iac.getId());
  286. return HttpResult.ok("报价成功", quoteRespVo);
  287. }
  288. /**
  289. * 3 核保
  290. *
  291. * @param quoteOrderNo
  292. */
  293. @Override
  294. @Transactional
  295. public HttpResult auditApi(String quoteOrderNo) {
  296. ObjectMapper xmlMapper = this.gainXmlMapper();
  297. String msg = "提交成功";
  298. HttpResult h = HttpResult.ok(msg);
  299. try {
  300. //子订单
  301. InsAreaCompany iac = insAreaCompanyService.getById(quoteOrderNo);
  302. if (iac == null) {
  303. return HttpResult.error("订单不存在");
  304. }
  305. InsOrders order = insOrdersService.getById(iac.getOrderno());
  306. // 获取协议配置信息
  307. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId());
  308. // if (InsOrderStatus.S_5.getCode().equals(iac.getOrderstatus()) || InsOrderStatus.S_4.getCode().equals(iac.getOrderstatus())) {
  309. // return HttpResult.ok(InsOrderStatus.matchKey(iac.getOrderstatus()).getDesc());
  310. // }
  311. //车主
  312. CustomerInfoVo ownerInfo = JSONObject.parseObject(order.getOwnerinfo().toJSONString(), CustomerInfoVo.class);
  313. //被保人
  314. CustomerInfoVo insureInfo = JSONObject.parseObject(order.getInsureinfo().toJSONString(), CustomerInfoVo.class);
  315. //投保人
  316. CustomerInfoVo applyInfo = JSONObject.parseObject(order.getApplyinfo().toJSONString(), CustomerInfoVo.class);
  317. //组装参数
  318. Audit m = Audit.buildAuditParam(ownerInfo, insureInfo, applyInfo, ycConfigureParameters, iac);
  319. //处理地区
  320. Map<String, String> insureMap = gainRegionCode(insureInfo.getAddr());
  321. if (null != insureMap && insureMap.size() > 0) {
  322. m.getRequestLabel().getCondition().getCustomer().setCProvince(insureMap.get("provinceCode"));
  323. m.getRequestLabel().getCondition().getCustomer().setCCity(insureMap.get("cityCode"));
  324. m.getRequestLabel().getCondition().getCustomer().setCCounty(insureMap.get("areaCode"));
  325. } else {
  326. throw new SystemException("永诚 - 被保人地区获取失败,请联系管理员");
  327. }
  328. log.debug("=========永诚API方式 - xml请求 - 核保开始======");
  329. //接口请求
  330. InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_AUDIT);
  331. log.debug("=========永诚API方式 - xml请求 - 核保结束!======");
  332. verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_1);
  333. String responseData = apiLog.getResponseData();
  334. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  335. AuditResponse rd = xmlMapper.readValue(cleanStr, AuditResponse.class);
  336. if (rd.getResponseHead().getReturnCode().equals("0000")) {
  337. // if (rd.getResponseHead().getReturnCode().equals("E0000")) {
  338. String statusJq = StringUtils.toString(rd.getStatusJq(), "");
  339. String statusSy = StringUtils.toString(rd.getStatusSY(), "");
  340. if (statusJq.equals("0") || statusSy.equals("0")) {
  341. iac.setOrderstatus(InsOrderStatus.S_1.getCode());
  342. } else if (statusJq.equals("3") || statusSy.equals("3")) {
  343. iac.setOrderstatus(InsOrderStatus.S_4.getCode());
  344. } else {
  345. iac.setOrderstatus(InsOrderStatus.S_2.getCode());
  346. }
  347. if (StringUtils.toInt(order.getOrderstatus()) < StringUtils.toInt(iac.getOrderstatus())) {
  348. order.setOrderstatus(iac.getOrderstatus());
  349. }
  350. } else {
  351. msg = rd.getResponseHead().getReturnMessage();
  352. return HttpResult.error("核保失败" + msg);
  353. }
  354. iac.setAuditid(order.getUserid());
  355. iac.setInsOrderNo(rd.getOrderCode());
  356. SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  357. iac.setAudittime(LocalDateTime.now());
  358. iac.setJqapplyno(StringUtils.toString(rd.getPolicyAppNoJQ(), ""));
  359. iac.setSyapplyno(StringUtils.toString(rd.getPolicyAppNoSY(), ""));
  360. iac.setJqappoint(""); //交强特别约定
  361. iac.setSyappoint(""); //商业特别约定
  362. if (InsOrderStatus.S_2.getCode().equals(InsOrderStatus.matchKey(iac.getOrderstatus()).getCode())) {
  363. //获取缴费地址
  364. getPayUrlApi(iac);
  365. } else {
  366. h = HttpResult.error(msg + "状态:" + InsOrderStatus.matchKey(iac.getOrderstatus()).getDesc());
  367. }
  368. insAreaCompanyService.updateById(iac);
  369. insOrdersService.updateByOrderStatus(order.getOrderno(), order.getOrderstatus());
  370. // if (InsOrderStatus.S_2.getCode().equals(InsOrderStatus.matchKey(iac.getOrderstatus()).getCode())) {
  371. // return HttpResult.ok(msg);
  372. // } else {
  373. // return HttpResult.error(msg + "状态:" + InsOrderStatus.matchKey(iac.getOrderstatus()).getDesc());
  374. // }
  375. // //插入轨迹表
  376. // insTaskHistoryService.insertByOrderStatus(order);
  377. } catch (SystemException e) {
  378. return HttpResult.error(e.getMessage());
  379. } catch (Exception e) {
  380. // e.printStackTrace();
  381. log.error("===永诚API方式--核保报错(订单号-{}):{}", quoteOrderNo, e.getMessage());
  382. return HttpResult.error("系统错误,请联系管理员");
  383. }
  384. return h;
  385. }
  386. /**
  387. * 4 影像上传
  388. */
  389. @Override
  390. public HttpResult UploadImageApi(String quoteOrderNo) {
  391. HttpResult resutl = HttpResult.ok();
  392. InsAreaCompany iac = insAreaCompanyService.getByIdIsExist(quoteOrderNo);
  393. InsOrders order = insOrdersService.getById(iac.getOrderno());
  394. List<InsTaskImage> insTaskImages = insTaskImageService.selectByTaskId(order.getQuoteno());
  395. //获取协议配置信息
  396. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId());
  397. insTaskImages.stream().forEach(a -> {
  398. InsApiLog apiLog = null;
  399. //组装参数
  400. log.debug("=========永诚API方式 - xml请求 - 影像上传开始======");
  401. //接口请求
  402. ImageUp iUp = ImageUp.buildImageUpParam(order, ycConfigureParameters, a.getImage(), a.getImgtype());
  403. log.debug("=========永诚API方式 - xml请求 - 影像上传结束!======");
  404. ObjectMapper xmlMapper = gainXmlMapper();
  405. //接口请求
  406. apiLog = httpPost(xmlMapper, iUp, YcBuildData.API_UPLOAD);
  407. verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_2);
  408. try {
  409. String responseData = apiLog.getResponseData();
  410. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  411. log.error("===永诚API方式--上传影像清洗返回参数:" + cleanStr);
  412. ImageUpResponse iur = xmlMapper.readValue(cleanStr, ImageUpResponse.class);
  413. } catch (IOException e) {
  414. e.printStackTrace();
  415. log.error("===永诚API方式--上传影像报错:" + e.getMessage());
  416. throw new SystemException("系统错误,请联系管理员");
  417. }
  418. });
  419. return HttpResult.ok();
  420. }
  421. /**
  422. * 5 支付
  423. */
  424. @Override
  425. public InsAreaCompany getPayUrlApi(InsAreaCompany iac) {
  426. try {
  427. // 获取协议配置信息
  428. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId());
  429. //组装参数
  430. Pay pay = Pay.buildPayParam(iac, ycConfigureParameters.gainAuthorityDataXml(), apiComponents.getPayCallBack());
  431. ObjectMapper xmlMapper = gainXmlMapper();
  432. //接口请求
  433. log.debug("=========永诚API方式 - xml请求 - 获取缴费链接开始======");
  434. InsApiLog apiLog = httpPost(xmlMapper, pay, YcBuildData.API_PAY);
  435. log.debug("=========永诚API方式 - xml请求 - 获取缴费链接结束!======");
  436. verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_3);
  437. String responseData = apiLog.getResponseData();
  438. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  439. PayResponse payResp = xmlMapper.readValue(cleanStr, PayResponse.class);
  440. if (payResp.getReturnCode().equals("E0000")) {
  441. iac.setPaymentLink(payResp.getPayTransUrl());
  442. // insAreaCompanyService.updateById(iac);
  443. } else {
  444. log.error("永诚API方式 - 获取支付连接失败:" + payResp.getReturnMessage());
  445. }
  446. } catch (Exception e) {
  447. e.printStackTrace();
  448. throw new SystemException("获取支付连接失败");
  449. }
  450. return iac;
  451. }
  452. /**
  453. * 补传回调
  454. */
  455. @Override
  456. public HttpResult callbackAnOrder(String quoteOrderNo) {
  457. HttpResult httpResult = new HttpResult();
  458. try {
  459. InsAreaCompany iac = insAreaCompanyService.getById(quoteOrderNo);
  460. InsOrders order = insOrdersService.getById(iac.getOrderno());
  461. if (iac == null) {
  462. return HttpResult.error("报价订单不存在");
  463. }
  464. // 获取协议配置信息
  465. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId());
  466. //0 支付回调 1核保回调 5直接返回字符串信息
  467. // String type = "0";
  468. String type = "5";
  469. // if(iac.getOrderstatus().equals(InsOrderStatus.S_1.getCode())) type = "1";
  470. //组装参数
  471. CallbackAnOrder o = CallbackAnOrder.buildCallbackAnOrderParam(iac, ycConfigureParameters.gainAuthorityDataXml(), type);
  472. ObjectMapper xmlMapper = gainXmlMapper();
  473. //接口请求
  474. log.debug("=========永诚API方式 - xml请求 - 补传回调开始======");
  475. InsApiLog apiLog = httpPost(xmlMapper, o, YcBuildData.API_ORDER_QUERY);
  476. log.debug("=========永诚API方式 - xml请求 - 补传回调结束!======");
  477. verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_5);
  478. String responseData = apiLog.getResponseData();
  479. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  480. // CallbackAnOrderResponse callbackAnOrderResponse = xmlMapper.readValue(cleanStr, CallbackAnOrderResponse.class);
  481. if (StringUtils.isNotEmpty(cleanStr)) {
  482. log.info("永诚API方式 - 补传回调 - 参数:" + cleanStr);
  483. CallBackRequest param = CallBackRequest.buildCallBackParam(cleanStr);
  484. //成功
  485. if (param.getResult().equals("0")) {
  486. // LambdaQueryWrapper<InsAreaCompany> lqw = new LambdaQueryWrapper();
  487. // //交强投保单号查询
  488. // lqw.eq(StringUtils.isNotEmpty(param.getCiPolicyAppNo()), InsAreaCompany::getJqapplyno, param.getCiPolicyAppNo());
  489. // //商业投保单号查询
  490. // lqw.eq(StringUtils.isNotEmpty(param.getBizPolicyAppNo()), InsAreaCompany::getSyapplyno, param.getBizPolicyAppNo());
  491. // InsAreaCompany iac = insAreaCompanyService.getOne(lqw);
  492. if (StringUtils.isNotEmpty(param.getBizPolicyNo())) iac.setSypolicyno(param.getBizPolicyNo());
  493. if (StringUtils.isNotEmpty(param.getCiPolicyNo())) iac.setJqpolicyno(param.getCiPolicyNo());
  494. iac = buildCallBack(iac, param);
  495. if (StringUtils.toInt(order.getOrderstatus()) < StringUtils.toInt(iac.getOrderstatus())) {
  496. order.setOrderstatus(iac.getOrderstatus());
  497. }
  498. insAreaCompanyService.updateById(iac);
  499. insOrdersService.updateByOrderStatus(order.getOrderno(), order.getOrderstatus());
  500. } else {
  501. //失败原因
  502. httpResult = HttpResult.error(param.getMessage());
  503. log.info(String.format("永诚API方式 - 补传回调 - 失败,交强保单号:{} ,商业保单号:{},类型:{}", param.getCiPolicyNo(), param.getBizPolicyNo(), param.getType()));
  504. }
  505. return HttpResult.ok(param);
  506. }
  507. // if (cleanStr.equals("0000")) {
  508. // httpResult.setMsg("操作成功");
  509. // } else {
  510. // httpResult.setMsg(cleanStr);
  511. // }
  512. } catch (SystemException e) {
  513. return HttpResult.error(e.getMessage());
  514. } catch (Exception e) {
  515. e.printStackTrace();
  516. return HttpResult.error("系统错误,请联系管理员");
  517. }
  518. return httpResult;
  519. }
  520. /**
  521. * 6 电子保单
  522. */
  523. @Override
  524. public HttpResult getPolicyPrintApi(PolicyPrintVo policyPrintVo) {
  525. HttpResult httpResult = new HttpResult();
  526. try {
  527. InsAreaCompany iac = insAreaCompanyService.getById(policyPrintVo.getCompanyId());
  528. // InsOrder order = insOrderService.selectByPk(orderno);
  529. if (iac == null) {
  530. return HttpResult.error("报价订单不存在");
  531. }
  532. // 获取协议配置信息
  533. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(iac.getAgreementId());
  534. String policyNo = policyPrintVo.getRiskCode().equals("0507") ? iac.getJqpolicyno() : iac.getSypolicyno();
  535. //组装参数
  536. Policy p = Policy.buildPolicyParam(policyNo, ycConfigureParameters.gainAuthorityDataXml());
  537. ObjectMapper xmlMapper = gainXmlMapper();
  538. //接口请求
  539. log.debug("=========永诚API方式 - xml请求 - 获取保单开始======");
  540. InsApiLog apiLog = httpPost(xmlMapper, p, YcBuildData.API_GUARANTEE_SLIP);
  541. log.debug("=========永诚API方式 - xml请求 - 获取保单结束!======");
  542. verifyRequest(apiLog, iac, InsQuoteFlow.Q_S_4);
  543. String responseData = apiLog.getResponseData();
  544. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  545. PolicyResponse pResp = xmlMapper.readValue(cleanStr, PolicyResponse.class);
  546. if (pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
  547. Map m = new HashMap();
  548. if (policyPrintVo.getType().equals("1")) {
  549. m.put("jqFlagUrl", pResp.getPolicyBZUrl());
  550. m.put("jqUrl", "");
  551. m.put("syUrl", "");
  552. }
  553. if (policyPrintVo.getType().equals("2")) {
  554. m.put("jqFlagUrl", pResp.getPolicyBZUrl());
  555. m.put("jqUrl", pResp.getJqpolicyUrl());
  556. m.put("syUrl", pResp.getSypolicyUrl());
  557. }
  558. // httpResult.setData(m);
  559. // httpResult.setMsg(pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription());
  560. return HttpResult.ok(pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription(), m);
  561. } else {
  562. return HttpResult.error(pResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription());
  563. }
  564. } catch (Exception e) {
  565. e.printStackTrace();
  566. return HttpResult.error("系统错误,请联系管理员");
  567. }
  568. }
  569. /**
  570. * 驾意外险
  571. */
  572. @Override
  573. public HttpResult gainAccidentList(AccidentalDrivingQueryVo accidentalDrivingVo) {
  574. HttpResult httpResult = new HttpResult();
  575. try {
  576. // InsAreaCompany iac = insAreaCompanyService.getById(quoteOrderNo);
  577. // InsOrders order = insOrdersService.getById(iac.getOrderno());
  578. // if (iac == null) {
  579. // return HttpResult.error("报价订单不存在");
  580. // }
  581. // 获取协议配置信息
  582. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(accidentalDrivingVo.getAgreementId());
  583. //组装参数
  584. Accident accident = Accident.buildPayParam(accidentalDrivingVo, ycConfigureParameters, null);
  585. ObjectMapper xmlMapper = gainXmlMapper();
  586. //接口请求
  587. log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询开始======");
  588. InsApiLog apiLog = httpPost(xmlMapper, accident, YcBuildData.API_ACCIDENT);
  589. log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询结束!======");
  590. // verifyRequest(apiLog, iac,InsQuoteFlow.);
  591. String responseData = apiLog.getResponseData();
  592. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  593. AccidentResponse accidentResp = xmlMapper.readValue(cleanStr, AccidentResponse.class);
  594. if (accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
  595. //清空旧的存入表
  596. LambdaQueryWrapper<EsmInsAttachInsure> lqw = new LambdaQueryWrapper<EsmInsAttachInsure>();
  597. lqw.eq(EsmInsAttachInsure::getCompanyId, accidentalDrivingVo.getCompanyCode());
  598. lqw.eq(EsmInsAttachInsure::getSeating, accidentalDrivingVo.getSeatNum());
  599. esmInsAttachInsureMapper.delete(lqw);
  600. List<ResponseYwCvrg.CvrgList> cList = accidentResp.getResponseYwCvrg().getCvrgList();
  601. List<EsmInsAttachInsure> eiaiList = new ArrayList<>();
  602. cList.stream().forEach(a -> {
  603. EsmInsAttachInsure ati = new EsmInsAttachInsure();
  604. ati.setCode(a.getCInsuranceTypeCode());
  605. ati.setName(a.getCInsuranceType());
  606. ati.setSeating(accidentalDrivingVo.getSeatNum() + "");
  607. ati.setCompanyId(accidentalDrivingVo.getCompanyCode());
  608. ati.setType(AttachInsureEnum.AI001.getCode());
  609. ati.setEnable(WhetherEnum.YES.getCode());
  610. ati.setRestrictNum(StringUtils.toInt(a.getNPurchaseLimitsNum()));
  611. esmInsAttachInsureMapper.insert(ati);
  612. eiaiList.add(ati);
  613. });
  614. httpResult.setData(eiaiList);
  615. // httpResult.setData(accidentResp.getResponseYwCvrg().getCvrgList());
  616. httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription());
  617. } else {
  618. httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription());
  619. }
  620. } catch (SystemException e) {
  621. return HttpResult.error(e.getMessage());
  622. } catch (Exception e) {
  623. e.printStackTrace();
  624. return HttpResult.error("系统错误,请联系管理员");
  625. }
  626. return httpResult;
  627. }
  628. /**
  629. * 驾意外险 同步
  630. */
  631. @Override
  632. public HttpResult syncAccidentInsure(AccidentalDrivingQueryVo accidentalDrivingVo) {
  633. AccidentResponse ar = gainAccidentInsure(accidentalDrivingVo, null);
  634. // List<EsmInsAttachInsure> eiaiList = new ArrayList<>();
  635. if (ar.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
  636. //清空旧的存入表
  637. LambdaQueryWrapper<EsmInsAttachInsure> lqw = new LambdaQueryWrapper<EsmInsAttachInsure>();
  638. lqw.eq(EsmInsAttachInsure::getCompanyId, accidentalDrivingVo.getCompanyCode());
  639. lqw.eq(EsmInsAttachInsure::getSeating, accidentalDrivingVo.getSeatNum());
  640. lqw.select(EsmInsAttachInsure::getId);
  641. List<EsmInsAttachInsure> eiaiList = esmInsAttachInsureMapper.selectList(lqw);
  642. //删除已经存在的数据
  643. if (null != eiaiList && eiaiList.size() > 0) {
  644. List<String> ids = new ArrayList<>();
  645. eiaiList.stream().forEach(i -> {
  646. ids.add(i.getId());
  647. });
  648. LambdaQueryWrapper<EsmInsAttachInsureDetails> lqwDetails = new LambdaQueryWrapper<>();
  649. lqwDetails.in(EsmInsAttachInsureDetails::getAttachInsureId, ids);
  650. //详情删除
  651. esmInsAttachInsureDetailsMapper.delete(lqwDetails);
  652. // esmInsAttachInsureMapper.delete(lqw);
  653. esmInsAttachInsureMapper.deleteBatchIds(ids);
  654. }
  655. List<ResponseYwCvrg.CvrgList> cList = ar.getResponseYwCvrg().getCvrgList();
  656. cList.stream().forEach(a -> {
  657. EsmInsAttachInsure ati = new EsmInsAttachInsure();
  658. ati.setCode(a.getCInsuranceTypeCode());
  659. ati.setName(a.getCInsuranceType());
  660. ati.setSeating(accidentalDrivingVo.getSeatNum() + "");
  661. ati.setCompanyId(accidentalDrivingVo.getCompanyCode());
  662. ati.setType(AttachInsureEnum.AI001.getCode());
  663. ati.setEnable(WhetherEnum.YES.getCode());
  664. ati.setRestrictNum(StringUtils.toInt(a.getNPurchaseLimitsNum()));
  665. esmInsAttachInsureMapper.insert(ati);
  666. //具体方案信息
  667. AccidentResponse arCode = gainAccidentInsure(accidentalDrivingVo, a.getCInsuranceTypeCode());
  668. if (arCode.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
  669. AtomicInteger total = new AtomicInteger(0);
  670. List<ResponseYwCvrg.CvrgList> cListDetails = arCode.getResponseYwCvrg().getCvrgList();
  671. cListDetails.stream().forEach(d -> {
  672. EsmInsAttachInsureDetails atiDetails = new EsmInsAttachInsureDetails();
  673. atiDetails.setAttachInsureId(ati.getId());
  674. atiDetails.setName(d.getCInsuranceLiability());
  675. atiDetails.setCarSum(d.getNInsuranceAmountCar());
  676. atiDetails.setSeatSum(d.getNInsuranceAmountSeat());
  677. atiDetails.setPremium(d.getNLiabilityPremium());
  678. total.addAndGet(StringUtils.toInt(d.getNLiabilityPremium()));
  679. esmInsAttachInsureDetailsMapper.insert(atiDetails);
  680. });
  681. ati.setPremium(total.get() + "");
  682. esmInsAttachInsureMapper.updateById(ati);
  683. }
  684. // eiaiList.add(ati);
  685. });
  686. }
  687. return HttpResult.ok("同步成功");
  688. }
  689. /**
  690. * 驾意外险
  691. */
  692. @Override
  693. public AccidentResponse gainAccidentInsure(AccidentalDrivingQueryVo accidentalDrivingVo, String schemeNo) {
  694. HttpResult httpResult = new HttpResult();
  695. // 获取协议配置信息
  696. YcConfigureParameters ycConfigureParameters = gainYcConfigParams(accidentalDrivingVo.getAgreementId());
  697. //组装参数
  698. Accident accident = Accident.buildPayParam(accidentalDrivingVo, ycConfigureParameters, schemeNo);
  699. ObjectMapper xmlMapper = gainXmlMapper();
  700. //接口请求
  701. log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询开始======");
  702. InsApiLog apiLog = httpPost(xmlMapper, accident, YcBuildData.API_ACCIDENT);
  703. log.debug("=========永诚API方式 - xml请求 - 获取意健险方案及险种查询结束!======");
  704. // verifyRequest(apiLog, iac,InsQuoteFlow.);
  705. String responseData = apiLog.getResponseData();
  706. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  707. AccidentResponse accidentResp = null;
  708. try {
  709. accidentResp = xmlMapper.readValue(cleanStr, AccidentResponse.class);
  710. } catch (JsonProcessingException e) {
  711. log.error("转换错误 方法:gainAccidentInsure 类:AccidentResponse");
  712. throw new RuntimeException(e);
  713. }
  714. return accidentResp;
  715. // if (accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusCode().equals("E0000")) {
  716. // //清空旧的存入表
  717. // LambdaQueryWrapper<EsmInsAttachInsure> lqw = new LambdaQueryWrapper<EsmInsAttachInsure>();
  718. // lqw.eq(EsmInsAttachInsure::getCompanyId,accidentalDrivingVo.getCompanyCode());
  719. // lqw.eq(EsmInsAttachInsure::getSeating,accidentalDrivingVo.getSeatNum());
  720. // esmInsAttachInsureMapper.delete(lqw);
  721. //
  722. // List<ResponseYwCvrg.CvrgList> cList = accidentResp.getResponseYwCvrg().getCvrgList();
  723. //
  724. // List<EsmInsAttachInsure> eiaiList = new ArrayList<>();
  725. // cList.stream().forEach(a ->{
  726. // EsmInsAttachInsure ati = new EsmInsAttachInsure();
  727. // ati.setCode(a.getCInsuranceTypeCode());
  728. // ati.setName(a.getCInsuranceType());
  729. // ati.setSeating(accidentalDrivingVo.getSeatNum() + "");
  730. // ati.setCompanyId(accidentalDrivingVo.getCompanyCode());
  731. // ati.setType(AttachInsureEnum.AI001.getCode());
  732. // ati.setEnable(WhetherEnum.YES.getCode());
  733. // ati.setRestrictNum(StringUtils.toInt(a.getNPurchaseLimitsNum()));
  734. //
  735. // esmInsAttachInsureMapper.insert(ati);
  736. // eiaiList.add(ati);
  737. // });
  738. //
  739. //
  740. //
  741. //
  742. // httpResult.setData(eiaiList);
  743. //// httpResult.setData(accidentResp.getResponseYwCvrg().getCvrgList());
  744. // httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription());
  745. // } else {
  746. // httpResult.setMsg(accidentResp.getHead().getResponseCompleteMessageStatus().getMessageStatusDescription());
  747. // }
  748. }
  749. @Override
  750. @Transactional
  751. public HttpResult callBackApi(CallBackRequest param) {
  752. // if (StringUtils.isNotEmpty(param.getType())) return HttpResult.error("字段:type(回调类型) 参数为空");
  753. //成功
  754. if (param.getResult().equals("0")) {
  755. LambdaQueryWrapper<InsAreaCompany> lqw = new LambdaQueryWrapper();
  756. //交强投保单号查询
  757. lqw.eq(StringUtils.isNotEmpty(param.getCiPolicyAppNo()), InsAreaCompany::getJqapplyno, param.getCiPolicyAppNo());
  758. //商业投保单号查询
  759. lqw.eq(StringUtils.isNotEmpty(param.getBizPolicyAppNo()), InsAreaCompany::getSyapplyno, param.getBizPolicyAppNo());
  760. InsAreaCompany iac = insAreaCompanyService.getOne(lqw);
  761. if (null != iac) {
  762. if (StringUtils.isNotEmpty(param.getBizPolicyNo())) iac.setSypolicyno(param.getBizPolicyNo());
  763. if (StringUtils.isNotEmpty(param.getCiPolicyNo())) iac.setJqpolicyno(param.getCiPolicyNo());
  764. iac = buildCallBack(iac, param);
  765. InsOrders order = insOrdersService.getById(iac.getOrderno());
  766. if (StringUtils.toInt(order.getOrderstatus()) < StringUtils.toInt(iac.getOrderstatus())) {
  767. order.setOrderstatus(iac.getOrderstatus());
  768. }
  769. insAreaCompanyService.updateById(iac);
  770. insOrdersService.updateByOrderStatus(order.getOrderno(), order.getOrderstatus());
  771. //支付后 手工确认意外险
  772. } else {
  773. log.info(String.format("永诚API方式 - 回调 - 信息,订单不存在,交强保单号:{} ,商业保单号:{}", param.getCiPolicyNo(), param.getBizPolicyNo()));
  774. }
  775. } else {
  776. //失败原因
  777. param.getMessage();
  778. log.info(String.format("永诚API方式 - 回调 - 失败,交强保单号:{} ,商业保单号:{},类型:{}", param.getCiPolicyNo(), param.getBizPolicyNo(), param.getType()));
  779. }
  780. return HttpResult.ok(param);
  781. }
  782. /**
  783. * @description:构造车型查询参数
  784. * @author: lig
  785. * @date: 2023年02月08日 0008
  786. */
  787. private ModelsQueryXml buildModelsQueryParam(CarModel_Req carModelReq, YcConfigureParameters ycConfigureParameters) {
  788. ModelsQueryXml m = new ModelsQueryXml();
  789. ModelsQueryXml.RequestLabel requestLabel = new ModelsQueryXml.RequestLabel();
  790. requestLabel.setSearchKeyword(carModelReq.getFrameNo().substring(0, 8));
  791. requestLabel.setVid(carModelReq.getFrameNo());
  792. requestLabel.setEngineNo(carModelReq.getEngineNo());
  793. requestLabel.setDptCde(ycConfigureParameters.getDptCde());
  794. requestLabel.setProno("0326");
  795. requestLabel.setMotorTypeCode("11");
  796. requestLabel.setCFstRegYm(carModelReq.getEnrollDate());
  797. requestLabel.setAuthorityData(ycConfigureParameters.gainAuthorityDataXml());
  798. m.setRequestLabel(requestLabel);
  799. return m;
  800. }
  801. /**
  802. * @description: 构造返回内容,参考永安
  803. * @author: lig
  804. * @date: 2023年02月07日 0007
  805. */
  806. private List<CarModelDTO> buildCarModel(ModelsQueryResponse modelsQueryResponse) {
  807. List<ModelsQueryResponse.VehicleInfo> vList = modelsQueryResponse.getVehicleInfoList();
  808. List<CarModelDTO> carModelList = new ArrayList<>();
  809. vList.stream().forEach(a -> {
  810. CarModelDTO dto = new CarModelDTO();
  811. BeanUtils.copyProperties(a, dto);
  812. carModelList.add(dto);
  813. });
  814. return carModelList;
  815. }
  816. private <T> InsApiLog httpPost(ObjectMapper mapper, T requestData, String apiName) {
  817. String xmlString = "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tns=\"http://newWS.front.app.echannel.ebiz.alltrust.com/\">";
  818. xmlString += "<soapenv:Body>";
  819. try {
  820. mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
  821. xmlString += mapper.writeValueAsString(requestData);
  822. xmlString += "</soapenv:Body>\n" +
  823. "</soapenv:Envelope>";
  824. } catch (JsonProcessingException e) {
  825. throw new RuntimeException("永诚API方式-xml转换失败");
  826. }
  827. InsApiLog iplog = HttpXmlUtil.sendXmlPost(apiComponents.getUrl() + apiName, xmlString);
  828. log.info("永诚API方式 - xml请求 - 参数:" + iplog.getRequestData());
  829. log.info("永诚API方式 - xml请求 ------------分割线----------------");
  830. log.info("永诚API方式 - xml请求 - 响应:" + iplog.getResponseData());
  831. return iplog;
  832. }
  833. /**
  834. * @description: 拷贝永安方法,可以封装
  835. * @author: lig
  836. * @date: 2023年02月08日 0008
  837. */
  838. private void checkEmpty(YaQuoteInfoVo yaQuoteInfoVo) {
  839. if (yaQuoteInfoVo.getCarInfo() == null) {
  840. throw new SystemException("carInfo不能为空!");
  841. }
  842. if (yaQuoteInfoVo.getPolicyHolderInfo() == null || yaQuoteInfoVo.getInsuredPersonInfo() == null) {
  843. throw new SystemException("policyHolderInfo/insuredPersonInfo 不能为空!");
  844. }
  845. if (yaQuoteInfoVo.getRiskList() == null || yaQuoteInfoVo.getRiskList().size() == 0) {
  846. throw new SystemException("riskList 不能为空!");
  847. } else {
  848. for (RiskInfoVo riskInfoVo : yaQuoteInfoVo.getRiskList()) {
  849. if (riskInfoVo.getStartDate() == null || riskInfoVo.getEndDate() == null) {
  850. throw new SystemException("riskList.startDate / riskList.endDate不能为空!");
  851. }
  852. }
  853. }
  854. }
  855. // /**
  856. // * 生成订单 拷贝永安
  857. // *
  858. // * @author: lig
  859. // * @date: 2023年02月16日 0016
  860. // */
  861. // protected InsOrders gene_order(YaQuoteInfoVo record) {
  862. // InsOrders insOrder = new InsOrders();
  863. // String orderno = IdGenerate.nextId();
  864. // insOrder.setOrderno(orderno);
  865. // insOrder.setQuoteno(String.valueOf(record.getQuoteno()));
  866. // insOrder.setOrderstatus("0"); //0报价 1待核保 2已核保待缴费 3核保退回 4核保不通过
  867. // insOrder.setFrameno(record.getCarInfo().getFrameNo());
  868. // insOrder.setLicenseno(record.getCarInfo().getLicenseNo());
  869. //
  870. // insOrder.setCarinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getCarInfo())));
  871. // SysUser user = sysUserService.selectByPk(record.getUserId());
  872. // if (user == null) {
  873. // throw new SystemException("userId不存在");
  874. // }
  875. // if (org.springframework.util.StringUtils.isEmpty(record.getCarInfo().getFrameNo())) {
  876. // throw new SystemException("车架号不能为空");
  877. // }
  878. // // 关闭订单 不含当前报价号
  879. // InsOrders orderObj = insOrderService.queryQuoteno(new Object[]{record.getUserId(), record.getCarInfo().getFrameNo(), record.getQuoteno()});
  880. // if (orderObj != null) {
  881. // List<InsOrder> listo = insOrderService.selectList(" where quoteno=?", new Object[]{orderObj.getQuoteno()});
  882. // String status = "0";
  883. // for (InsOrder order : listo) {
  884. // if (!"0".equals(order.getOrderstatus())) {
  885. // status = order.getOrderstatus();
  886. // }
  887. // }
  888. // //0报价中 1待核保 2已核保 3核保退回 4核保不通过 5已核保待缴费 6已缴费 7已承保 99已关闭
  889. // if ("0".equals(status)) {//关闭订单
  890. // insOrderService.closeOrder(orderObj.getOrderno(), "99");
  891. // } else if (!"99".equals(status)) {
  892. // throw new SystemException("此车辆已提交核保,重新报价请先关闭订单,任务号:" + orderObj.getQuoteno());
  893. // }
  894. // }
  895. // insOrder.setUserid(user.getId());
  896. // insOrder.setUsername(user.getName());
  897. // insOrder.setDeptid(user.getDeptId());
  898. // SysDept dept = sysDeptService.selectByPk(user.getDeptId());
  899. // insOrder.setDeptname(dept == null ? "" : dept.getName());
  900. //
  901. // double retailRate = countRetail(user.getDeptId(), user.getId());
  902. //
  903. // insOrder.setOwnerinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getOwnerInfo())));
  904. // insOrder.setApplyinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getPolicyHolderInfo())));
  905. // insOrder.setInsureinfo(JSONObject.parseObject(JSONObject.toJSONString(record.getInsuredPersonInfo())));
  906. //
  907. // insOrder.setInsuredname(record.getPolicyHolderInfo().getName());
  908. //
  909. //
  910. // List<RiskInfoVo> risks = record.getRiskList();
  911. // for (RiskInfoVo risk : risks) {
  912. // if ("0507".equals(risk.getRiskCode())) {//交强
  913. // insOrder.setJqstartdate(risk.getStartDate());
  914. // insOrder.setJqenddate(risk.getEndDate());
  915. // }
  916. // if ("0510".equals(risk.getRiskCode())) {//商业
  917. // insOrder.setSystartdate(risk.getStartDate());
  918. // insOrder.setSyenddate(risk.getEndDate());
  919. // }
  920. // }
  921. //
  922. // List<KindInfoVo> kinds = record.getKindList();
  923. // String productId = "";
  924. // String productname = "";
  925. //
  926. // 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() + "%"});
  927. // if (agreements.size() == 0) {
  928. // throw new SystemException("不存在有效协议或机构" + user.getDeptId() + "未授权");
  929. // }
  930. // String agreeid = agreements.get(0).getId();
  931. // insOrder.setAgreeid(agreeid);
  932. // //匹配协议,获取费用
  933. // StringBuffer whereStr = new StringBuffer();
  934. // List params = new ArrayList();// where t.agreeid=? and t.productid in ()
  935. // whereStr.append("where t.agreeid=? ");
  936. // params.add(agreeid);
  937. // if (risks.size() == 1 && "0507".equals(risks.get(0).getRiskCode())) {
  938. // productId = "ZG01001";
  939. // productname = "单交强";
  940. // whereStr.append(" and t.productid=?");
  941. // params.add(productId);
  942. // } else if (risks.size() == 1 && kinds.size() == 1 && "B".equals(kinds.get(0).getKindCode())) {
  943. // productId = "ZG01002";
  944. // productname = "单三者";
  945. // whereStr.append(" and t.productid=?");
  946. // params.add(productId);
  947. // } else if (risks.size() == 1) {
  948. // productId = "ZG01003";
  949. // productname = "单商业";
  950. // whereStr.append(" and t.productid=?");
  951. // params.add(productId);
  952. // } else if (risks.size() == 2 && kinds.size() == 1 && "B".equals(kinds.get(0).getKindCode())) {
  953. // productId = "ZG01004";
  954. // productname = "交强+三者";
  955. // whereStr.append(" and t.productid in (?,?)");
  956. // params.add("ZG01004");
  957. // params.add("ZG01005");
  958. // } else {
  959. // productId = "ZG01006";
  960. // productname = "交强+商业";
  961. // whereStr.append(" and t.productid in (?,?)");
  962. // params.add("ZG01006");
  963. // params.add("ZG01007");
  964. // }
  965. //
  966. // insOrder.setProductid(productId);
  967. // insOrder.setProduct(productname);
  968. // List<EsmAgreementProd> agreementProds = esmAgreementProdService.selectList(whereStr.toString(), params.toArray());
  969. // for (EsmAgreementProd prod : agreementProds) {
  970. // if ("ZG01001".equals(prod.getProductid()) || "ZG01004".equals(prod.getProductid()) || "ZG01006".equals(prod.getProductid())) {
  971. //
  972. // insOrder.setFeerate(prod.getProductrate()); //交强手续费比例
  973. // insOrder.setJqdiscountrate(prod.getFeerate() - retailRate); //交强优惠比例=业务员绩效-分销费用
  974. // } else {
  975. // insOrder.setDisrate(prod.getProductrate()); //商业手续费比例
  976. // insOrder.setSydiscountrate(prod.getFeerate() - retailRate); //商业优惠比例=业务员绩效-分销费用
  977. //
  978. // }
  979. // insOrder.setProductid(prod.getId());
  980. // }
  981. //
  982. // insOrder.setRiskinfo(JSONObject.parseArray(JSONObject.toJSONString(record.getRiskList())));
  983. // insOrder.setKindinfo(JSONObject.parseArray(JSONObject.toJSONString(record.getKindList())));
  984. // SimpleDateFormat sdfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  985. //
  986. // insOrder.setInscompany("永安财险");
  987. // insOrder.setCreatetime(sdfm.format(new Date()));
  988. //
  989. // return insOrder;
  990. //
  991. // }
  992. // /**
  993. // * 分销费用统计 拷贝永安
  994. // *
  995. // * @param deptid
  996. // * @param userid
  997. // * @return
  998. // */
  999. // public double countRetail(String deptid, String userid) {
  1000. // double retailRate = 0;
  1001. //
  1002. // //1、根据机构匹配分销规则,获取分销比例
  1003. // List<EsmRetail> list = esmRetailService.selectList(" where deptid = ? and status=?", new Object[]{deptid, "1"});
  1004. // //2、根据userid查询三级推荐人
  1005. // List<SysUser> users = esmUserInternalService.getSuperior(userid);
  1006. //
  1007. // if (list != null && list.size() > 0 && users.size() > 0 && !"0".equals(list.get(0).getRetailtype())) {
  1008. // EsmRetail retail = list.get(0);
  1009. // List<Double> rateList = new ArrayList<Double>();
  1010. // rateList.add(retail.getDisrate1());
  1011. // rateList.add(retail.getDisrate2());
  1012. // rateList.add(retail.getDisrate3());
  1013. //
  1014. // if ("1".equals(retail.getRetailtype())) {//一级分销
  1015. // retailRate += rateList.get(0);
  1016. // } else if ("2".equals(retail.getRetailtype())) {//二级分销
  1017. // int num = users.size() > 2 ? 2 : users.size();
  1018. // for (int i = 0; i < num; i++) {
  1019. // retailRate += rateList.get(i);
  1020. // }
  1021. //
  1022. // } else {//三级分销
  1023. // int num = users.size() > 2 ? 3 : users.size();
  1024. // for (int i = 0; i < num; i++) {
  1025. // retailRate += rateList.get(i);
  1026. // }
  1027. //
  1028. // }
  1029. //
  1030. // }
  1031. //
  1032. // return retailRate;
  1033. // }
  1034. /**
  1035. * 新订单 - 子订单
  1036. *
  1037. * @author: lig
  1038. * @date: 2023年02月16日 0016
  1039. */
  1040. private InsAreaCompany response_order(InsOrders insOrder, QuoteRespVo quoteRespVo, Ruote requestData, RuoteResponse responseData, BaseQuoteVo<AccidentalDrivingVo> quoteVo) {
  1041. //交强保费 含税
  1042. double jqPremium = StringUtils.toDouble(responseData.getBase().getNBefTaxPrmJQ()) + StringUtils.toDouble(responseData.getBase().getNAppTaxAmtJQ());
  1043. //商业保费 含税
  1044. double syPremium = StringUtils.toDouble(responseData.getBase().getNBefTaxPrmSY()) + StringUtils.toDouble(responseData.getBase().getNAppTaxAmtSY());
  1045. //保险公司订单号
  1046. String insOrderNo = responseData.getBase().getCresvTxt6();
  1047. //查询码交强
  1048. String queryCodeJq = responseData.getVhl().getCQryCdeJQ();
  1049. //查询码商业
  1050. String queryCodeSy = responseData.getVhl().getCQryCdeSY();
  1051. EsmInsCompany eic = esmInsCompanyService.getById(quoteVo.getCompanyId());
  1052. boolean jq_falg = jqPremium > 0 ? true : false;
  1053. //保存订单信息
  1054. InsAreaCompany insAreaCompany = new InsAreaCompany();
  1055. insAreaCompany.setOrderno(insOrder.getOrderno());
  1056. insAreaCompany.setReptxt(JSONObject.parseObject(JSONObject.toJSONString(responseData)));
  1057. insAreaCompany.setJqpremium(BigDecimal.valueOf(jq_falg ? jqPremium : 0));
  1058. insAreaCompany.setSypremium(BigDecimal.valueOf(syPremium));
  1059. insAreaCompany.setTaxamount(BigDecimal.valueOf(jq_falg ? quoteRespVo.getTaxAmount() : 0));
  1060. insAreaCompany.setSumpremium(BigDecimal.valueOf(quoteRespVo.getSumPermium()));
  1061. // insAreaCompany.setSumpremium(BigDecimal.valueOf(add(quoteRespVo.getSumPermium(), insOrder.getTaxamount())));
  1062. insAreaCompany.setOrderstatus(InsTaskHistoryEnum.WAITING_NUCLEAR_INSURANCE.getState() + "");
  1063. insAreaCompany.setRiskinfo(JSONObject.parseArray(JSONObject.toJSONString(quoteRespVo.getRiskList())));
  1064. insAreaCompany.setKindinfo(JSONObject.parseArray(JSONObject.toJSONString(quoteRespVo.getKindList())));
  1065. insAreaCompany.setCreatetime(LocalDateTime.now());
  1066. insAreaCompany.setInsOrderNo(insOrderNo);
  1067. insAreaCompany.setJqapplyno(queryCodeJq);
  1068. insAreaCompany.setSyapplyno(queryCodeSy);
  1069. insAreaCompany.setCompanyId(eic.getId());
  1070. insAreaCompany.setInscompany(eic.getNamesimple());
  1071. insAreaCompany.setAgreementId(quoteVo.getAgreementId());
  1072. insAreaCompanyService.save(insAreaCompany);
  1073. return insAreaCompany;
  1074. // //插入轨迹表
  1075. // InsTaskHistory history = new InsTaskHistory();
  1076. // history.setId(String.valueOf(new Date().getTime()));
  1077. // history.setCompany(insOrder.getInscompany());
  1078. // history.setTaskid(insOrder.getOrderno());
  1079. // history.setOperatorid(insOrder.getUserid());
  1080. // history.setOperator(insOrder.getUsername());
  1081. // SimpleDateFormat sdfm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1082. // history.setCreatetime(sdfm.format(new Date()));
  1083. // history.setOperator(insOrder.getUsername());
  1084. // history.setStatus("0");
  1085. // history.setRemark("报价中");
  1086. // insTaskHistoryService.insert(history);
  1087. }
  1088. public static double add(double v1, double v2) {
  1089. BigDecimal b1 = new BigDecimal(Double.toString(v1));
  1090. BigDecimal b2 = new BigDecimal(Double.toString(v2));
  1091. return b1.add(b2).doubleValue();
  1092. }
  1093. public static String getUserName() {
  1094. return "";
  1095. // String userName = null;
  1096. // Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
  1097. //
  1098. // if (principal instanceof UserDetails) {
  1099. // userName = ((UserDetails) principal).getUsername();
  1100. // } else {
  1101. // userName = principal.toString();
  1102. // }
  1103. // return userName;
  1104. }
  1105. /**
  1106. * 验证远程请求
  1107. *
  1108. * @author: lig
  1109. * @date: 2023年02月22日 0022
  1110. */
  1111. private void verifyRequest(InsApiLog apiLog, InsAreaCompany insAreaCompany, InsQuoteFlow iqf) {
  1112. //增加api日志
  1113. insApiLogService.insertAsync(new InsApiLog(insAreaCompany, apiLog, iqf));
  1114. if (StringUtils.isNotEmpty(apiLog.getExceptionMsg())) {
  1115. throw new SystemException("远程接口调用异常");
  1116. // throw new RuntimeException("远程接口调用异常");
  1117. }
  1118. }
  1119. // /**
  1120. // * 验证远程请求
  1121. // *
  1122. // * @author: lig
  1123. // * @date: 2023年02月22日 0022
  1124. // */
  1125. // private void verifyRequest(InsApiLog apiLog, InsAreaCompany insAreaCompany) {
  1126. // //增加api日志
  1127. // insApiLogService.insertAsync(new InsApiLog(insAreaCompany, apiLog));
  1128. // if (StringUtils.isNotEmpty(apiLog.getExceptionMsg())) {
  1129. // throw new RuntimeException("远程接口调用异常");
  1130. // }
  1131. //
  1132. // }
  1133. /**
  1134. * 更新api log
  1135. *
  1136. * @author: lig
  1137. * @date: 2023-03-21
  1138. */
  1139. private void updateApiLog(InsApiLog apiLog, InsAreaCompany iac) {
  1140. if (null != apiLog && null != iac) {
  1141. apiLog.setOrderNo(StringUtils.toString(iac.getId()));
  1142. // apiLog.setOrderStatus(iac.getOrderstatus());
  1143. insApiLogService.UpdateAsync(apiLog);
  1144. }
  1145. }
  1146. @Override
  1147. public Map<String, String> gainRegionCode(String address) {
  1148. log.debug("*********永诚API方式 - 身份证地址解析 参数:" + address);
  1149. Map<String, String> m = IDCardUtils.addressResolution(address);
  1150. if (null == m) return null;
  1151. String city = m.get("city");
  1152. String district = m.get("district");
  1153. // if(StringUtils.isNullOrEmpty(district)){
  1154. // //第二级赋值到第三级
  1155. // district = city;
  1156. // }
  1157. List<InsAlltrustRegion> areaList = new ArrayList<>();
  1158. if (StringUtils.isNotEmpty(district)) {
  1159. //查询地区
  1160. LambdaQueryWrapper<InsAlltrustRegion> lqw = new LambdaQueryWrapper<>();
  1161. lqw.eq(InsAlltrustRegion::getArea, district);
  1162. areaList = insAlltrustRegionMapper.selectList(lqw);
  1163. }
  1164. //如果地区查不到 用城市当地区查
  1165. if (null == areaList || areaList.size() < 1) {
  1166. LambdaQueryWrapper<InsAlltrustRegion> cityLqw = new LambdaQueryWrapper<>();
  1167. cityLqw.eq(InsAlltrustRegion::getArea, city);
  1168. areaList = insAlltrustRegionMapper.selectList(cityLqw);
  1169. }
  1170. if (null != areaList && areaList.size() > 0) {
  1171. Map rMap = new HashMap();
  1172. rMap.put("provinceCode", areaList.get(0).getProvinceCode());
  1173. rMap.put("cityCode", areaList.get(0).getCityCode());
  1174. rMap.put("areaCode", areaList.get(0).getAreaCode());
  1175. return rMap;
  1176. }
  1177. return null;
  1178. }
  1179. private void buildRegion(Ruote m) {
  1180. //车主
  1181. Vhlowner owner = m.getRequestLabel().getCondition().getVhlowner();
  1182. //被保人
  1183. Insured i = m.getRequestLabel().getCondition().getInsured();
  1184. //投保人
  1185. Applicant a = m.getRequestLabel().getCondition().getApplicant();
  1186. String provinceCode = "provinceCode";
  1187. String cityCode = "cityCode";
  1188. String areaCode = "areaCode";
  1189. // owner.getCAreaCde()
  1190. Map<String, String> ownerMap = gainRegionCode(owner.getCWaddress());
  1191. if (null != ownerMap && ownerMap.size() > 0) {
  1192. owner.setCProvince(ownerMap.get(provinceCode));
  1193. owner.setCCity(ownerMap.get(cityCode));
  1194. owner.setCCounty(ownerMap.get(areaCode));
  1195. //清空格式化 自建数据
  1196. owner.setCWaddress(null);
  1197. } else {
  1198. throw new SystemException("永诚 - 车主地区获取失败,请联系管理员");
  1199. }
  1200. Map<String, String> iMap = gainRegionCode(i.getCClntAddr());
  1201. if (null != iMap && iMap.size() > 0) {
  1202. i.setCProvince(iMap.get(provinceCode));
  1203. i.setCCity(iMap.get(cityCode));
  1204. i.setCCounty(iMap.get(areaCode));
  1205. } else {
  1206. throw new SystemException("永诚 - 被保人地区获取失败,请联系管理员");
  1207. }
  1208. Map<String, String> aMap = gainRegionCode(a.getCClntAddr());
  1209. if (null != aMap && aMap.size() > 0) {
  1210. a.setCProvince(aMap.get(provinceCode));
  1211. a.setCCity(aMap.get(cityCode));
  1212. a.setCCounty(aMap.get(areaCode));
  1213. } else {
  1214. throw new SystemException("永诚 - 投保人地区获取失败,请联系管理员");
  1215. }
  1216. }
  1217. /**
  1218. * 构造回调
  1219. * 依赖 buildCallBack
  1220. *
  1221. * @author: lig
  1222. * @date: 2023-05-06
  1223. */
  1224. private InsAreaCompany buildCallBack(InsAreaCompany iac, CallBackRequest param) {
  1225. //正常回调 与 补传回调
  1226. if (StringUtils.isNotEmpty(param.getStatus())) {
  1227. iac = buildCallBackStatus(iac, param.getStatus());
  1228. } else {
  1229. if (StringUtils.isNotEmpty(param.getJqstatus())) {
  1230. iac = buildCallBackStatus(iac, param.getJqstatus());
  1231. }
  1232. if (StringUtils.isNotEmpty(param.getSystatus())) {
  1233. iac = buildCallBackStatus(iac, param.getSystatus());
  1234. }
  1235. }
  1236. return iac;
  1237. }
  1238. /**
  1239. * 构造回调状态
  1240. *
  1241. * @author: lig
  1242. * @date: 2023-05-06
  1243. */
  1244. private InsAreaCompany buildCallBackStatus(InsAreaCompany iac, String status) {
  1245. if (status.equals("9")) {
  1246. iac.setOrderstatus(InsOrderStatus.S_2.getCode());
  1247. //更新支付连接
  1248. log.debug("准备进入获取支付连接######################");
  1249. iac = getPayUrlApi(iac);
  1250. log.debug("结束 - 准备进入获取支付连接######################");
  1251. }
  1252. if (status.equals("3")) {
  1253. iac.setOrderstatus(InsOrderStatus.S_4.getCode());
  1254. }
  1255. if (status.equals("1")) {
  1256. iac.setOrderstatus(InsOrderStatus.S_3.getCode());
  1257. }
  1258. return iac;
  1259. }
  1260. // /**
  1261. // * 通过修改参数后 报价
  1262. // *
  1263. // * @author: lig
  1264. // * @date: 2023年05月17日 0017
  1265. // */
  1266. // private RuoteResponse quoteApiByEdit(Ruote m) {
  1267. //
  1268. // RuoteResponse rd = null;
  1269. //
  1270. // log.debug("=========永诚API方式 - xml请求 - (修改参数后)报价开始======");
  1271. // InsApiLog apiLog = httpPost(xmlMapper, m, YcBuildData.API_QUOTE);
  1272. // log.debug("=========永诚API方式 - xml请求 - (修改参数后)报价结束!======");
  1273. // verifyRequest(apiLog, null, InsQuoteFlow.Q_S_0);
  1274. //
  1275. // String responseData = apiLog.getResponseData();
  1276. //
  1277. // try {
  1278. // String cleanStr = YcBuildData.cleanResponseStr(responseData);
  1279. // rd = xmlMapper.readValue(cleanStr, RuoteResponse.class);
  1280. //
  1281. //
  1282. // } catch (IOException e) {
  1283. // log.error("=========永诚API方式 - xml请求 - (修改参数后)报价 错误:" + e.getMessage());
  1284. // throw new RuntimeException(e);
  1285. // }
  1286. // return rd;
  1287. //
  1288. // }
  1289. /**
  1290. * 请求API接口,返回对象
  1291. *
  1292. * @author: lig
  1293. * @date: 2023年05月18日 0018
  1294. */
  1295. private <T> T requestApi(Object m, T response, InsAreaCompany iac, String reqUrl, InsQuoteFlow iqf) {
  1296. // private Object aaa(T m,T ruoteResponse,InsAreaCompany iac){
  1297. //6 接口请求
  1298. log.debug("=========永诚API方式 - xml请求 - {}开始======", iqf.getDesc());
  1299. InsApiLog apiLog = httpPost(xmlMapper, m, reqUrl);
  1300. log.debug("=========永诚API方式 - xml请求 - {}结束!======", iqf.getDesc());
  1301. verifyRequest(apiLog, iac, iqf);
  1302. String responseData = apiLog.getResponseData();
  1303. String cleanStr = YcBuildData.cleanResponseStr(responseData);
  1304. // Object rd = null;
  1305. try {
  1306. response = (T) xmlMapper.readValue(cleanStr, response.getClass());
  1307. return response;
  1308. } catch (JsonProcessingException e) {
  1309. log.debug("=========永诚API方式 - xml请求 - {}解析报错:{}", iqf.getDesc(), e.getMessage());
  1310. // throw new RuntimeException(e);
  1311. throw new SystemException("请求接口失败,对象转换错误,请联系管理员。");
  1312. }
  1313. }
  1314. // private boolean gainResultFlag(RuoteResponse rd,Ruote m){
  1315. // boolean flag = false;
  1316. // if (null == rd) {
  1317. // throw new SystemException("远程请求报价失败");
  1318. // }
  1319. //
  1320. // if (rd.getHead().getErrorCode().equals("000000")) {
  1321. // //获取失败
  1322. // boolean fail = !(StringUtils.isNotEmpty(rd.getVhl().getCQryCdeJQ()) || StringUtils.isNotEmpty(rd.getVhl().getCQryCdeSY()));
  1323. // if (fail) {
  1324. // //如果类型错误,修改类型后,继续报价
  1325. // if (StringUtils.isNotEmpty(rd.getVhl().getCBusType())) {
  1326. // //修改类型继续报价
  1327. // m.getRequestLabel().getCondition().getVhl().setCBusType(rd.getVhl().getCBusType());
  1328. // rd = requestApi(m, new RuoteResponse(), iac, YcBuildData.API_QUOTE, InsQuoteFlow.Q_S_0);
  1329. // if (null == rd) return HttpResult.error("远程请求报价失败");
  1330. // if (fail) {
  1331. // throw new SystemException(rd.getHead().getErrorMessage());
  1332. // }
  1333. // }
  1334. // throw new SystemException(rd.getHead().getErrorMessage());
  1335. // }
  1336. // } else {
  1337. // throw new SystemException(rd.getHead().getErrorMessage());
  1338. // }
  1339. //
  1340. // }
  1341. private YcConfigureParameters gainYcConfigParams(String agreementId) {
  1342. YcConfigureParameters ycConfigureParameters = new YcConfigureParameters();
  1343. configureParametersComponents.toEntity(ycConfigureParameters, agreementId);
  1344. return ycConfigureParameters;
  1345. }
  1346. }