InsAlltrustApiServiceImpl.java 99 KB

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