InsAlltrustApiServiceImpl.java 70 KB

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