InsAlltrustApiServiceImpl.java 74 KB

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