配置類: 調用: ...
配置類:
@Configuration public class FeignConfiguration { @Bean(name="remoteRestTemplate") public RestTemplate RestTemplate(){ SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); requestFactory.setConnectTimeout(5000); requestFactory.setReadTimeout(3500); RestTemplate restTemplate = new RestTemplate(requestFactory); return restTemplate; } }
調用:
@Service @Slf4j public class SlCustomerCreditSettingProductServiceImpl implements SlCustomerCreditSettingProductService { @Autowired private SlCustomerCreditSettingProductFeignClient slCustomerCreditSettingProductFeignClient; @Autowired @Qualifier(value = "remoteRestTemplate") private RestTemplate restTemplate; @Value("${crb_hub_url}") private String crbHubUrl; @Autowired private MQServerService mqServerService; @Override public List<SlCustomerCreditSettingProductRespVo> getCustomerCreditSettingProductRespVo(UserInfo userInfo) throws OpenHttpExection{ SlCustomerCreditSettingProductQueryVo slCustomerCreditSettingProductQueryVo = new SlCustomerCreditSettingProductQueryVo(); slCustomerCreditSettingProductQueryVo.setCorporationId(userInfo.getCorporationId()); slCustomerCreditSettingProductQueryVo.setCustomerId(userInfo.getCustomerId()); slCustomerCreditSettingProductQueryVo.setEffectiveEndDate(userInfo.getMakeDate()); slCustomerCreditSettingProductQueryVo.setMakeDate(userInfo.getMakeDate()); slCustomerCreditSettingProductQueryVo.setRegionCode(userInfo.getRegionCode()); List<SlCustomerCreditSettingProductRespVo> slCustomerCreditSettingProductRespVos = Lists.newArrayList(); ParameterizedTypeReference<List<CustomerCreditSettingProduct>> typeRef = new ParameterizedTypeReference<List<CustomerCreditSettingProduct>>() {}; ResponseEntity<List<CustomerCreditSettingProduct>> customerCreditSettingProductRespVos; //post調用外部介面 try { customerCreditSettingProductRespVos = restTemplate.exchange( crbHubUrl+"/customerCreditSettingProductApiController/findByCustomerIdAndCorporationId", HttpMethod.POST, new HttpEntity<>(slCustomerCreditSettingProductQueryVo), typeRef); }catch (Exception e){ throw new OpenHttpExection(e.getMessage()); } if(CollectionUtils.isNotEmpty(customerCreditSettingProductRespVos.getBody())) { for (CustomerCreditSettingProduct o : customerCreditSettingProductRespVos.getBody()) { SlCustomerCreditSettingProductRespVo slCustomerCreditSettingProductRespVo = new SlCustomerCreditSettingProductRespVo(); BeanUtils.copyProperties(o, slCustomerCreditSettingProductRespVo); slCustomerCreditSettingProductRespVos.add(slCustomerCreditSettingProductRespVo); } //mq發送數據 SynSlCustomerCreditSettingProduct synSlCustomerCreditSettingProduct = new SynSlCustomerCreditSettingProduct(); synSlCustomerCreditSettingProduct.setCustomerCreditSettingProducts(customerCreditSettingProductRespVos.getBody()); synSlCustomerCreditSettingProduct.setSlCustomerCreditSettingProductQueryVo(slCustomerCreditSettingProductQueryVo); try { mqServerService.sendLoopCedit(synSlCustomerCreditSettingProduct); }catch (Exception e){ e.printStackTrace(); log.error("同步客戶信用體系設定數據到本地資料庫失敗!"); } } return slCustomerCreditSettingProductRespVos; } }