InsAlltrustApiServiceImpl.java 85 KB

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