Supplier10000034SecondServiceImpl.java 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799
  1. package info.aspirecn.iov.sjjh.supplier10000034.service;
  2. import java.io.IOException;
  3. import java.net.SocketTimeoutException;
  4. import java.util.ArrayList;
  5. import java.util.List;
  6. import javax.servlet.http.HttpServletRequest;
  7. import org.apache.commons.lang.math.NumberUtils;
  8. import org.apache.commons.lang3.StringUtils;
  9. import org.springframework.beans.factory.annotation.Autowired;
  10. import org.springframework.beans.factory.annotation.Value;
  11. import org.springframework.stereotype.Service;
  12. import com.alibaba.fastjson.JSON;
  13. import com.alibaba.fastjson.JSONObject;
  14. import com.fasterxml.jackson.databind.ObjectMapper;
  15. import com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException;
  16. import info.aspirecn.iov.sjjh.commons.lang.ChannelTypeHandleResponseObject;
  17. import info.aspirecn.iov.sjjh.commons.lang.Constant;
  18. import info.aspirecn.iov.sjjh.commons.lang.PatternTools;
  19. import info.aspirecn.iov.sjjh.supplier10000034.SjjhConstants;
  20. import info.aspirecn.iov.sjjh.supplier10000034.gjwl.Response;
  21. import info.aspirecn.iov.sjjh.supplier10000034.gjwl.util.PostUtil;
  22. import info.aspirecn.iov.sjjh.supplier10000034.vo.EnterprisePermitRequestObject;
  23. import info.aspirecn.iov.sjjh.supplier10000034.vo.EnterprisePermitResponseObject;
  24. import info.aspirecn.iov.sjjh.supplier10000034.vo.PersonQualificationRequestObject;
  25. import info.aspirecn.iov.sjjh.supplier10000034.vo.PersonQualificationResponseObject;
  26. import info.aspirecn.iov.sjjh.supplier10000034.vo.PersonQualificationResponseObject.QualificationCertificateInfo;
  27. import info.aspirecn.iov.sjjh.supplier10000034.vo.ResultBody;
  28. import info.aspirecn.iov.sjjh.supplier10000034.vo.VehiclePermitSecondJsonResolveObject;
  29. import info.aspirecn.iov.sjjh.supplier10000034.vo.VehiclePermitSjxyRequstObject;
  30. import info.aspirecn.iov.sjjh.supplier10000034.vo.VehicleRoadTransportResponseObject;
  31. import info.aspirecn.rdc.aspirecloud.node.except.utils.ErrorUtils;
  32. import lombok.extern.slf4j.Slf4j;
  33. /**
  34. *
  35. * @author bzh
  36. *
  37. */
  38. @Slf4j
  39. @Service
  40. public class Supplier10000034SecondServiceImpl implements Supplier10000034SecondService {
  41. @Value("${custom.appKey}")
  42. private String appKey;
  43. @Value("${custom.appSecret}")
  44. private String appSecret;
  45. @Value("${custom.enterpriseUrl}")
  46. private String enterpriseUrl;
  47. @Value("${custom.personUrl}")
  48. private String personUrl;
  49. @Value("${custom.checkVehicleRoadTransportUrl}")
  50. private String checkVehicleRoadTransportUrl;
  51. @Value("${custom.urlCheckVehicleExist}")
  52. private String urlCheckVehicleExist;
  53. @Value("${custom.enterpriseV2Url}")
  54. private String enterpriseV2Url;
  55. @Value("${custom.personV2Url}")
  56. private String personV2Url;
  57. @Value("${custom.sleepTime}")
  58. private String sleepTime;
  59. @Autowired
  60. private ObjectMapper objectMapper;
  61. /**
  62. *企业道路运输经营许可证核查
  63. */
  64. @Override
  65. public ChannelTypeHandleResponseObject checkEnterprisePermit(HttpServletRequest request, String customBody,
  66. int outTime) {
  67. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  68. ret.setCode(Constant.SUCCESS);
  69. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  70. String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  71. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  72. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  73. if(StringUtils.isBlank(returnType)) {
  74. returnType = Constant.CUSTOMER_RETURN_ZW;
  75. }
  76. try {
  77. if (outTime <= SjjhConstants.PARA_ZERO) {
  78. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  79. }
  80. log.info("supplier10000034.checkEnterprisePermit---customBody={},outTime={}", customBody, outTime);
  81. ObjectMapper mapper = new ObjectMapper();
  82. EnterprisePermitRequestObject jsonResolveObject = mapper.readValue(customBody,
  83. EnterprisePermitRequestObject.class);
  84. String entName = jsonResolveObject.getEntName();
  85. String permitNumber = jsonResolveObject.getPermitNumber();
  86. String provinceCode = jsonResolveObject.getProvinceCode();
  87. //参数校验
  88. log.info("supplier10000034.checkEnterprisePermit---requestObject={},请求url:{}", JSON.toJSON(jsonResolveObject),enterpriseV2Url);
  89. List<String> paramErrorResultList = new ArrayList<>();
  90. if (StringUtils.isBlank(permitNumber)) {
  91. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER);
  92. }
  93. if (StringUtils.isBlank(provinceCode)&&provinceCode.length()!=6) {
  94. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  95. }
  96. if (!paramErrorResultList.isEmpty()) {
  97. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  98. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  99. } else {
  100. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  101. }
  102. ret.setResultDesc(Constant.INVALID_PARAMETER);
  103. ResultBody resultBody = new ResultBody();
  104. resultBody.setCode(SjjhConstants.PARA_THREE);
  105. resultBody.setResultList(paramErrorResultList);
  106. ret.setResultBody(resultBody);
  107. return ret;
  108. }
  109. JSONObject jsonObject = new JSONObject();
  110. jsonObject.put(SjjhConstants.ERROR_RETURN_PERMITNUMBER, permitNumber);
  111. jsonObject.put(SjjhConstants.ERROR_RETURN_PROVINCECODE, provinceCode);
  112. String body = jsonObject.toJSONString();
  113. Response responseContext = PostUtil.postString(enterpriseV2Url, body, appKey, appSecret,outTime);
  114. log.info("supplier10000034.checkEnterprisePermit接口responseContext={}", responseContext.getBody());
  115. EnterprisePermitResponseObject responseObject = objectMapper.readValue(
  116. responseContext.getBody(), EnterprisePermitResponseObject.class);
  117. log.info("supplier10000034.checkEnterprisePermit接口responseObject={}", responseObject);
  118. ret = setCheckEnterprisePermit(ret, returnType, entName, permitNumber, responseObject);
  119. if(responseObject != null) {
  120. upstreamCode = responseObject.getResultCode();
  121. }
  122. } catch (SocketTimeoutException ste) {
  123. ErrorUtils.captureException(ste);
  124. log.info("supplier10000034.checkEnterprisePermit接口SocketTimeoutException={}", ste);
  125. ret.setCode(Constant.REQUEST_TIMEOUT);
  126. } catch (UnrecognizedPropertyException upe) {
  127. log.info("supplier10000034.checkEnterprisePermit-UnrecognizedPropertyException:{}", upe);
  128. ErrorUtils.captureException(upe);
  129. ret.setCode(Constant.SUCCESS);
  130. ret.setIsCharge(Constant.IS_NOT_CHARGE);
  131. /**参数错误*/
  132. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
  133. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  134. } else {
  135. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  136. }
  137. ResultBody resultBody = new ResultBody();
  138. resultBody.setCode(SjjhConstants.PARA_THREE);
  139. List<String> resultList = new ArrayList<>();
  140. resultList.add(SjjhConstants.ERROR_RETURN_ENTNAME);
  141. resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER);
  142. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  143. resultBody.setResultList(resultList);
  144. ret.setResultBody(resultBody);
  145. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  146. return ret;
  147. } catch (Exception ioe) {
  148. log.info("supplier10000034.checkVehicleRoadTransport接口-Exception:{}", ioe);
  149. ErrorUtils.captureException(ioe);
  150. ret.setCode(Constant.FAIL);
  151. }
  152. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  153. return ret;
  154. }
  155. /**
  156. * 填充企业道路运输经营许可证核查接口的返回对象
  157. * @param ret
  158. * @param returnType
  159. * @param responseObject
  160. * @return
  161. */
  162. public ChannelTypeHandleResponseObject setCheckEnterprisePermit(ChannelTypeHandleResponseObject ret,
  163. String returnType,String entName,String permitNumber,EnterprisePermitResponseObject responseObject) {
  164. String resultCode = responseObject.getResultCode();
  165. if (SjjhConstants.RESULT_CODE_0.equals(resultCode)) {
  166. // 查询成功,返回结果
  167. ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
  168. //1、源数据是否为空
  169. List<String> resultList = new ArrayList<>();
  170. if(StringUtils.isBlank(responseObject.getData().getEnterpriseName())){
  171. resultList.add(SjjhConstants.ERROR_RETURN_ENTNAME);
  172. }
  173. if(StringUtils.isBlank(responseObject.getData().getPermitNumber())){
  174. resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER);
  175. }
  176. if(!resultList.isEmpty()){
  177. //数据源为空响应
  178. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  179. ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
  180. } else {
  181. ret.setResultCode(Constant.UN_MATCH_CODE);
  182. }
  183. ResultBody resultBody = new ResultBody();
  184. resultBody.setCode(SjjhConstants.PARA_ONE);
  185. resultBody.setResultList(resultList);
  186. ret.setResultBody(resultBody);
  187. } else {
  188. //2、数据是否一致
  189. if(StringUtils.isNotBlank(entName)&&!entName.equalsIgnoreCase(responseObject.getData().getEnterpriseName())){
  190. resultList.add(SjjhConstants.ERROR_RETURN_ENTNAME);
  191. } else if(StringUtils.isNotBlank(permitNumber)&&!permitNumber.equalsIgnoreCase(responseObject.getData().getPermitNumber())){
  192. resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER);
  193. }
  194. if(!resultList.isEmpty()){
  195. //数据不一致响应
  196. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  197. ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
  198. } else {
  199. ret.setResultCode(Constant.UN_MATCH_CODE);
  200. }
  201. ResultBody resultBody = new ResultBody();
  202. resultBody.setCode(SjjhConstants.PARA_TWO);
  203. resultBody.setResultList(resultList);
  204. ret.setResultBody(resultBody);
  205. } else {
  206. //数据一致响应
  207. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  208. ret.setResultCode(Constant.JK_RETURN_CODE_MATCH);
  209. } else {
  210. ret.setResultCode(Constant.MATCH_CODE);
  211. }
  212. ret.setResultBody(responseObject.getData());
  213. }
  214. }
  215. } else if(SjjhConstants.INTERFACE_CODE_110000.equals(resultCode)) {
  216. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
  217. ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
  218. } else {
  219. ret.setResultCode(Constant.UN_FIND_NUM_CODE);
  220. }
  221. ResultBody resultBody = new ResultBody();
  222. resultBody.setCode(SjjhConstants.PARA_THREE);
  223. List<String> resultList = new ArrayList<>();
  224. resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER);
  225. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  226. resultBody.setResultList(resultList);
  227. ret.setResultBody(resultBody);
  228. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  229. }else if(SjjhConstants.INTERFACE_CODE_140002.equals(resultCode)){
  230. /**参数错误*/
  231. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
  232. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  233. } else {
  234. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  235. }
  236. ResultBody resultBody = new ResultBody();
  237. resultBody.setCode(SjjhConstants.PARA_THREE);
  238. List<String> resultList = new ArrayList<>();
  239. resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER);
  240. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  241. resultBody.setResultList(resultList);
  242. ret.setResultBody(resultBody);
  243. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  244. }else {
  245. // 其他错误
  246. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  247. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  248. } else {
  249. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  250. }
  251. ResultBody resultBody = new ResultBody();
  252. resultBody.setCode(SjjhConstants.PARA_THREE);
  253. List<String> resultList = new ArrayList<>();
  254. resultList.add(SjjhConstants.ERROR_RETURN_PERMITNUMBER);
  255. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  256. resultBody.setResultList(resultList);
  257. ret.setResultBody(resultBody);
  258. }
  259. return ret;
  260. }
  261. /**
  262. *人员从业资格证核查
  263. */
  264. @Override
  265. public ChannelTypeHandleResponseObject checkPersonQualification(HttpServletRequest request, String customBody,
  266. int outTime) {
  267. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  268. ret.setCode(Constant.SUCCESS);
  269. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  270. String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  271. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  272. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  273. if(StringUtils.isBlank(returnType)) {
  274. returnType = Constant.CUSTOMER_RETURN_ZW;
  275. }
  276. try {
  277. if (outTime <= SjjhConstants.PARA_ZERO) {
  278. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  279. }
  280. log.info("supplier10000034.checkPersonQualification---customBody={},outTime={}", customBody, outTime);
  281. ObjectMapper mapper = new ObjectMapper();
  282. PersonQualificationRequestObject jsonResolveObject = mapper.readValue(customBody,
  283. PersonQualificationRequestObject.class);
  284. String name = jsonResolveObject.getNameOfPerson();
  285. String idCode = jsonResolveObject.getIdentityDocumentNumber();
  286. String qualificationCertificateNumber = jsonResolveObject.getQualificationCertificateNumber();
  287. String provinceCode = jsonResolveObject.getProvinceCode();
  288. //参数校验
  289. log.info("supplier10000034.checkPersonQualification---requestObject={},请求url:{}", JSON.toJSON(jsonResolveObject),personV2Url);
  290. List<String> paramErrorResultList = new ArrayList<>();
  291. if (StringUtils.isBlank(name)&&!PatternTools.checkResult(Constant.PATTERN_CN_NAME_REGEX,name)) {
  292. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON);
  293. }
  294. if (StringUtils.isBlank(provinceCode)&&provinceCode.length()!=6) {
  295. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  296. }
  297. if (StringUtils.isBlank(idCode)&&StringUtils.isBlank(qualificationCertificateNumber)) {
  298. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER);
  299. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  300. }
  301. if(StringUtils.isNotEmpty(idCode) && !PatternTools.checkResult(Constant.PATTERN_ID_NUMBER_REGEX,idCode)){
  302. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  303. }
  304. if (!paramErrorResultList.isEmpty()) {
  305. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  306. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  307. } else {
  308. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  309. }
  310. ret.setResultDesc(Constant.INVALID_PARAMETER);
  311. ResultBody resultBody = new ResultBody();
  312. resultBody.setCode(SjjhConstants.PARA_THREE);
  313. resultBody.setResultList(paramErrorResultList);
  314. ret.setResultBody(resultBody);
  315. return ret;
  316. }
  317. String body = objectMapper.writeValueAsString(jsonResolveObject);
  318. Response responseContext = PostUtil.postString(personV2Url, body, appKey, appSecret,outTime);
  319. log.info("supplier10000034.checkPersonQualification接口responseContext={}", responseContext.getBody());
  320. PersonQualificationResponseObject responseObject = objectMapper.readValue(
  321. responseContext.getBody(), PersonQualificationResponseObject.class);
  322. log.info("supplier10000034.checkPersonQualification接口responseObject={}", responseObject);
  323. ret = setCheckPersonQualification(ret, returnType, name, idCode, provinceCode,
  324. qualificationCertificateNumber, responseObject);
  325. if(responseObject != null) {
  326. upstreamCode = responseObject.getResultCode();
  327. }
  328. } catch (SocketTimeoutException ste) {
  329. ErrorUtils.captureException(ste);
  330. log.info("supplier10000034.checkPersonQualification接口SocketTimeoutException={}", ste);
  331. ret.setCode(Constant.REQUEST_TIMEOUT);
  332. } catch (UnrecognizedPropertyException upe) {
  333. log.info("supplier10000034.checkPersonQualification-UnrecognizedPropertyException:{}", upe);
  334. ErrorUtils.captureException(upe);
  335. ret.setCode(Constant.SUCCESS);
  336. ret.setIsCharge(Constant.IS_NOT_CHARGE);
  337. /**参数错误*/
  338. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
  339. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  340. } else {
  341. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  342. }
  343. ResultBody resultBody = new ResultBody();
  344. resultBody.setCode(SjjhConstants.PARA_THREE);
  345. List<String> resultList = new ArrayList<>();
  346. resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON);
  347. resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  348. resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER);
  349. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  350. resultBody.setResultList(resultList);
  351. ret.setResultBody(resultBody);
  352. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  353. return ret;
  354. } catch (Exception ioe) {
  355. log.info("supplier10000034.checkPersonQualification接口-Exception:{}", ioe);
  356. ErrorUtils.captureException(ioe);
  357. ret.setCode(Constant.FAIL);
  358. }
  359. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  360. return ret;
  361. }
  362. /**
  363. * 填充人员从业资格证核查接口的返回对象
  364. * @param ret
  365. * @param returnType
  366. * @param name
  367. * @param idCode
  368. * @return
  369. */
  370. public ChannelTypeHandleResponseObject setCheckPersonQualification(ChannelTypeHandleResponseObject ret,
  371. String returnType,String name,String idCode,String provinceCode,
  372. String qualificationCertificateNumber,PersonQualificationResponseObject responseObject) {
  373. String resultCode = responseObject.getResultCode();
  374. if (SjjhConstants.RESULT_CODE_0.equals(resultCode)) {
  375. // 查询成功,返回结果
  376. ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
  377. //1、源数据是否为空
  378. List<String> resultList = new ArrayList<>();
  379. if (StringUtils.isNotBlank(name) && StringUtils.isBlank(responseObject.getData().getNameOfPerson())) {
  380. resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON);
  381. }
  382. if (StringUtils.isNotBlank(idCode) && StringUtils.isBlank(responseObject.getData().getIdentityDocumentNumber())) {
  383. resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  384. }
  385. if (StringUtils.isNotBlank(qualificationCertificateNumber)) {
  386. for (QualificationCertificateInfo qualificationCertificateInfo : responseObject.getData().getQualificationCertificateInfo()) {
  387. if(StringUtils.isBlank(qualificationCertificateInfo.getQualificationCertificateNumber())){
  388. resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER);
  389. }
  390. }
  391. }
  392. if(!resultList.isEmpty()){
  393. //数据源为空响应
  394. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  395. ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
  396. } else {
  397. ret.setResultCode(Constant.UN_MATCH_CODE);
  398. }
  399. ResultBody resultBody = new ResultBody();
  400. resultBody.setCode(SjjhConstants.PARA_ONE);
  401. resultBody.setResultList(resultList);
  402. ret.setResultBody(resultBody);
  403. } else {
  404. //2、数据是否一致
  405. if (StringUtils.isNotBlank(name)
  406. && !name.equalsIgnoreCase(responseObject.getData().getNameOfPerson())) {
  407. resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON);
  408. }
  409. if(StringUtils.isNotBlank(idCode)
  410. && !idCode.equalsIgnoreCase(responseObject.getData().getIdentityDocumentNumber())){
  411. resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  412. }
  413. if(StringUtils.isNotBlank(provinceCode)
  414. && !provinceCode.equalsIgnoreCase(responseObject.getData().getProvinceCode())){
  415. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  416. }
  417. if (StringUtils.isNotBlank(qualificationCertificateNumber)) {
  418. for (QualificationCertificateInfo qualificationCertificateInfo : responseObject.getData().getQualificationCertificateInfo()) {
  419. if(StringUtils.isNotBlank(qualificationCertificateInfo.getQualificationCertificateNumber())
  420. && !qualificationCertificateNumber.equalsIgnoreCase(qualificationCertificateInfo.getQualificationCertificateNumber())){
  421. resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER);
  422. }
  423. }
  424. }
  425. if(!resultList.isEmpty()){
  426. //数据不一致响应
  427. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  428. ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
  429. } else {
  430. ret.setResultCode(Constant.UN_MATCH_CODE);
  431. }
  432. ResultBody resultBody = new ResultBody();
  433. resultBody.setCode(SjjhConstants.PARA_TWO);
  434. resultBody.setResultList(resultList);
  435. ret.setResultBody(resultBody);
  436. } else {
  437. //数据一致响应
  438. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  439. ret.setResultCode(Constant.JK_RETURN_CODE_MATCH);
  440. } else {
  441. ret.setResultCode(Constant.MATCH_CODE);
  442. }
  443. ret.setResultBody(responseObject.getData());
  444. }
  445. }
  446. } else if(SjjhConstants.INTERFACE_CODE_110000.equals(resultCode)) {
  447. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
  448. ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
  449. } else {
  450. ret.setResultCode(Constant.UN_FIND_NUM_CODE);
  451. }
  452. ResultBody resultBody = new ResultBody();
  453. resultBody.setCode(SjjhConstants.PARA_ONE);
  454. List<String> resultList = new ArrayList<>();
  455. resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON);
  456. if (StringUtils.isNotBlank(idCode)) {
  457. resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  458. }
  459. if (StringUtils.isNotBlank(qualificationCertificateNumber)) {
  460. resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER);
  461. }
  462. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  463. resultBody.setResultList(resultList);
  464. ret.setResultBody(resultBody);
  465. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  466. } else if(SjjhConstants.INTERFACE_CODE_140002.equals(resultCode)){
  467. /**参数错误*/
  468. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
  469. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  470. } else {
  471. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  472. }
  473. ResultBody resultBody = new ResultBody();
  474. resultBody.setCode(SjjhConstants.PARA_THREE);
  475. List<String> resultList = new ArrayList<>();
  476. resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON);
  477. if (StringUtils.isNotBlank(idCode)) {
  478. resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  479. }
  480. if (StringUtils.isNotBlank(qualificationCertificateNumber)) {
  481. resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER);
  482. }
  483. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  484. resultBody.setResultList(resultList);
  485. ret.setResultBody(resultBody);
  486. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  487. } else {
  488. // 其他错误
  489. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  490. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  491. } else {
  492. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  493. }
  494. ResultBody resultBody = new ResultBody();
  495. resultBody.setCode(SjjhConstants.PARA_THREE);
  496. List<String> resultList = new ArrayList<>();
  497. resultList.add(SjjhConstants.ERROR_RETURN_NAMEOFPERSON);
  498. if (StringUtils.isNotBlank(idCode)) {
  499. resultList.add(SjjhConstants.ERROR_RETURN_IDENTITYDOCUMENTNUMBER);
  500. }
  501. if (StringUtils.isNotBlank(qualificationCertificateNumber)) {
  502. resultList.add(SjjhConstants.ERROR_RETURN_QUALIFICATIONCERTIFICATENUMBER);
  503. }
  504. resultList.add(SjjhConstants.ERROR_RETURN_PROVINCECODE);
  505. resultBody.setResultList(resultList);
  506. ret.setResultBody(resultBody);
  507. }
  508. return ret;
  509. }
  510. @Override
  511. public ChannelTypeHandleResponseObject checkVehicleRoadTransport(HttpServletRequest request, String customBody, int outTime) {
  512. ChannelTypeHandleResponseObject ret = new ChannelTypeHandleResponseObject();
  513. ret.setCode(Constant.SUCCESS);
  514. ret.setIsCharge(Constant.INTERFACE_QUERY_NO_FEE);
  515. String upstreamCode = Constant.LOG_UPSTREAM_DEFAULT_RESPONSE_CODE;
  516. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  517. String returnType = request.getHeader(Constant.CUSTOMER_RETURN_TYPE_PARA);
  518. if(StringUtils.isBlank(returnType)) {
  519. returnType = Constant.CUSTOMER_RETURN_ZW;
  520. }
  521. try {
  522. if (outTime <= SjjhConstants.PARA_ZERO) {
  523. outTime = Constant.HTTPCLIENT_CONNECTTIMEOUT;
  524. }
  525. log.info("supplier10000034.checkVehicleRoadTransport---customBody={},outTime={}", customBody, outTime);
  526. ObjectMapper mapper = new ObjectMapper();
  527. VehiclePermitSecondJsonResolveObject jsonResolveObject = mapper.readValue(customBody,
  528. VehiclePermitSecondJsonResolveObject.class);
  529. String carNumber = jsonResolveObject.getVehicleNumber();
  530. String colorType = jsonResolveObject.getVehiclePlateColorCode();
  531. String vin = jsonResolveObject.getVin();
  532. String roadNumber = jsonResolveObject.getRoadTransportCertificateNumber();
  533. //参数校验
  534. log.info("supplier10000034.checkVehicleRoadTransport---requestObject={}", jsonResolveObject);
  535. List<String> paramErrorResultList = new ArrayList<>();
  536. //车牌号校验
  537. if (StringUtils.isBlank(carNumber) || !PatternTools.checkResult(SjjhConstants.PARA_THREE, carNumber)) {
  538. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_VEHICLENUMBER);
  539. }
  540. //车颜色校验
  541. if (StringUtils.isBlank(colorType) || (!SjjhConstants.PARA_COLOR_ONE.equals(colorType)
  542. && !SjjhConstants.PARA_COLOR_TWO.equals(colorType))) {
  543. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_COLOR_CODE);
  544. }
  545. //VIN和道路运输证号非空校验
  546. if (StringUtils.isBlank(vin) && StringUtils.isBlank(roadNumber)) {
  547. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_VIN);
  548. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER);
  549. }
  550. //道路运输证号不为空且全是数字
  551. if (StringUtils.isNotBlank(roadNumber)
  552. && !NumberUtils.isNumber(roadNumber)) {
  553. paramErrorResultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER);
  554. }
  555. if (!paramErrorResultList.isEmpty()) {
  556. if (Constant.CUSTOMER_RETURN_ZW.equals(returnType)) {
  557. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  558. } else {
  559. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  560. }
  561. ret.setResultDesc(Constant.INVALID_PARAMETER);
  562. ResultBody resultBody = new ResultBody();
  563. resultBody.setCode(SjjhConstants.PARA_THREE);
  564. resultBody.setResultList(paramErrorResultList);
  565. ret.setResultBody(resultBody);
  566. return ret;
  567. }
  568. //请求的body,json格式
  569. VehiclePermitSjxyRequstObject requestObject = new VehiclePermitSjxyRequstObject();
  570. requestObject.setLicensePlateTypeCode(colorType);
  571. requestObject.setVehicleNumber(carNumber);
  572. String body = objectMapper.writeValueAsString(requestObject);
  573. log.info("supplier10000034.checkVehicleRoadTransport接口body={},url={}", body, checkVehicleRoadTransportUrl);
  574. info.aspirecn.iov.sjjh.supplier10000034.gjwl.Response response = PostUtil.postString(
  575. checkVehicleRoadTransportUrl, body, appKey, appSecret, outTime);
  576. String responseContext = response.getBody();
  577. log.info("supplier10000034.checkVehicleRoadTransport接口responseContext={}", responseContext);
  578. VehicleRoadTransportResponseObject responseObject = mapper.readValue(
  579. responseContext, VehicleRoadTransportResponseObject.class);
  580. String resultCode = "";
  581. if(responseObject != null) {
  582. upstreamCode = responseObject.getResultCode();
  583. resultCode = responseObject.getResultCode();
  584. }
  585. ret = setCheckVehicleRoadTransport(ret, returnType, vin, roadNumber, resultCode, responseObject);
  586. } catch (SocketTimeoutException ste) {
  587. ErrorUtils.captureException(ste);
  588. log.info("supplier10000034.checkVehicleRoadTransport接口SocketTimeoutException={}", ste);
  589. ret.setCode(Constant.REQUEST_TIMEOUT);
  590. } catch (UnrecognizedPropertyException upe) {
  591. log.info("supplier10000034.checkVehicleRoadTransport-UnrecognizedPropertyException:{}", upe);
  592. ErrorUtils.captureException(upe);
  593. ret.setCode(Constant.SUCCESS);
  594. ret.setIsCharge(Constant.IS_NOT_CHARGE);
  595. /**参数错误*/
  596. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)){
  597. ret.setResultCode(Constant.JK_RETURN_CODE_9909);
  598. } else {
  599. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  600. }
  601. ret.setResultBody(Constant.PARAMETER_NAME_ERROR);
  602. ret.setResultDesc(Constant.PARAMETER_NAME_ERROR);
  603. return ret;
  604. } catch (Exception ioe) {
  605. log.info("supplier10000034.checkVehicleRoadTransport接口-Exception:{}", ioe);
  606. ErrorUtils.captureException(ioe);
  607. ret.setCode(Constant.FAIL);
  608. }
  609. request.setAttribute(Constant.LOG_UPSTREAM_RESPONSE_CODE, upstreamCode);
  610. return ret;
  611. }
  612. /**
  613. * 填充核车辆道路运输许可证信息接口的返回对象
  614. * @param ret
  615. * @param returnType
  616. * @param vin
  617. * @param roadNumber
  618. * @param responseObject
  619. * @return
  620. */
  621. public ChannelTypeHandleResponseObject setCheckVehicleRoadTransport(ChannelTypeHandleResponseObject ret,
  622. String returnType,String vin,String roadNumber,String resultCode,
  623. VehicleRoadTransportResponseObject responseObject) {
  624. ResultBody resultBody = new ResultBody();
  625. if (responseObject != null && responseObject.getData() != null
  626. && SjjhConstants.RESULT_CODE_0.equals(resultCode)) {
  627. // 查询成功,返回结果
  628. ret.setIsCharge(Constant.INTERFACE_QUERY_FEE);
  629. //1、源数据是否为空
  630. List<String> resultList = new ArrayList<>();
  631. if(StringUtils.isBlank(responseObject.getData().getVehicleNumber())){
  632. resultList.add(SjjhConstants.ERROR_RETURN_VEHICLENUMBER);
  633. }
  634. if(StringUtils.isBlank(responseObject.getData().getLicensePlateTypeCode())){
  635. resultList.add(SjjhConstants.ERROR_RETURN_COLOR_CODE);
  636. }
  637. if(StringUtils.isNotBlank(roadNumber) && StringUtils.isBlank(responseObject.getData().getRoadTransportCertificateNumber())){
  638. resultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER);
  639. }
  640. if(StringUtils.isNotBlank(vin) && StringUtils.isBlank(responseObject.getData().getVinNo())){
  641. resultList.add(SjjhConstants.ERROR_RETURN_VIN);
  642. }
  643. if(!resultList.isEmpty()){
  644. //数据源为空响应
  645. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  646. ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
  647. } else {
  648. ret.setResultCode(Constant.UN_MATCH_CODE);
  649. }
  650. resultBody.setCode(SjjhConstants.PARA_ONE);
  651. resultBody.setResultList(resultList);
  652. ret.setResultBody(resultBody);
  653. } else {
  654. //2、数据是否一致
  655. if(StringUtils.isNotBlank(roadNumber) && StringUtils.isBlank(vin)){
  656. if(!roadNumber.equalsIgnoreCase(responseObject.getData().getRoadTransportCertificateNumber())) {
  657. resultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER);
  658. }
  659. } else if(StringUtils.isBlank(roadNumber) && StringUtils.isNotBlank(vin)){
  660. if(!vin.equalsIgnoreCase(responseObject.getData().getVinNo())) {
  661. resultList.add(SjjhConstants.ERROR_RETURN_VIN);
  662. }
  663. } else if(!vin.equalsIgnoreCase(responseObject.getData().getVinNo())) {
  664. resultList.add(SjjhConstants.ERROR_RETURN_VIN);
  665. }
  666. if(!resultList.isEmpty()){
  667. //数据不一致响应
  668. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  669. ret.setResultCode(Constant.JK_RETURN_CODE_NO_MATCH);
  670. } else {
  671. ret.setResultCode(Constant.UN_MATCH_CODE);
  672. }
  673. resultBody.setCode(SjjhConstants.PARA_TWO);
  674. resultBody.setResultList(resultList);
  675. ret.setResultBody(resultBody);
  676. } else {
  677. //数据一致响应
  678. if (Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  679. ret.setResultCode(Constant.JK_RETURN_CODE_MATCH);
  680. } else {
  681. ret.setResultCode(Constant.MATCH_CODE);
  682. }
  683. ret.setResultBody(responseObject.getData());
  684. }
  685. }
  686. } else if(SjjhConstants.INTERFACE_CODE_110000.equals(resultCode)) {
  687. // 查询结果为空
  688. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  689. ret.setResultCode(Constant.JK_RETURN_CODE_NO_INFO);
  690. } else {
  691. ret.setResultCode(Constant.UN_FIND_NUM_CODE);
  692. }
  693. resultBody.setCode(SjjhConstants.PARA_ONE);
  694. List<String> resultList = getErrorParamList();
  695. resultBody.setResultList(resultList);
  696. ret.setResultBody(resultBody);
  697. } else if(SjjhConstants.INTERFACE_CODE_140002.equals(resultCode)) {
  698. // 参数错误
  699. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  700. ret.setResultCode(Constant.JK_RETURN_CODE_INVALID_PARAMETER);
  701. } else {
  702. ret.setResultCode(Constant.INVALID_PARAMETER_CODE);
  703. }
  704. resultBody.setCode(SjjhConstants.PARA_THREE);
  705. List<String> resultList = getErrorParamList();
  706. resultBody.setResultList(resultList);
  707. ret.setResultBody(resultBody);
  708. } else {
  709. // 其他错误
  710. if(Constant.CUSTOMER_RETURN_JK.equals(returnType)) {
  711. ret.setResultCode(Constant.JK_RETURN_CODE_OTHER_ERROR);
  712. } else {
  713. ret.setResultCode(Constant.OTHER_ERROR_CODE);
  714. }
  715. resultBody.setCode(SjjhConstants.PARA_THREE);
  716. List<String> resultList = getErrorParamList();
  717. resultBody.setResultList(resultList);
  718. ret.setResultBody(resultBody);
  719. }
  720. return ret;
  721. }
  722. /**
  723. * 获取错误返回中相关参数LIST
  724. * @return
  725. */
  726. private List<String> getErrorParamList() {
  727. List<String> resultList = new ArrayList<>();
  728. resultList.add(SjjhConstants.ERROR_RETURN_VEHICLENUMBER);
  729. resultList.add(SjjhConstants.ERROR_RETURN_COLOR_CODE);
  730. resultList.add(SjjhConstants.ERROR_RETURN_ROADNUMBER);
  731. resultList.add(SjjhConstants.ERROR_RETURN_VIN);
  732. return resultList;
  733. }
  734. }