修复由于resttemplate返回的list元素为linkedhashmap导致的获取基础数据失败的问题。

This commit is contained in:
zhouxiunai
2019-02-19 14:23:28 +08:00
parent e8348be5ab
commit e345f2854d
5 changed files with 65 additions and 3 deletions
@@ -1,5 +1,7 @@
package com.gzzn.omms.msgexchangeapi.basicdata.service;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
@@ -8,6 +10,8 @@ import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.gzzn.omms.msgexchangeapi.basicdata.entity.OrmsStand;
import com.gzzn.omms.msgexchangeapi.dto.ResponseDto;
@@ -29,7 +33,12 @@ public class OrmsStandServiceImpl implements IOrmsStandService{
ResponseDto responseDto = responseEntity.getBody();
if (responseDto.getIs_success()) {
List<OrmsStand> rt = (List<OrmsStand>)responseDto.getBody();
List<LinkedHashMap> lsLinked = (List<LinkedHashMap>)responseDto.getBody();
//
ObjectMapper mapper = new ObjectMapper();
List<OrmsStand> rt = mapper.convertValue(lsLinked, new TypeReference<List<OrmsStand>>() { });
return rt;
}
else {
@@ -54,7 +54,7 @@ public class PSDTHandler extends FlopBaseHandler {
fltr.getPSDT().add(standata);
//如果是近机位
//获取机位
OrmsStand ormsStand = OrmsStandManager
.getInstance()
.getOrmsStandByStandCode(standata.getPSST());
@@ -64,6 +64,7 @@ public class PSDTHandler extends FlopBaseHandler {
continue;
}
//获取机位对应的登机桥
if("near".equalsIgnoreCase(ormsStand.getStandType()))
{
String abdg = fltr.getAbdg() + "," + standata.getPSST();//登机桥
@@ -0,0 +1,25 @@
package com.gzzn.omms.msgexchangeapi.basicdata;
import static org.assertj.core.api.Assertions.assertThat;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import com.gzzn.omms.msgexchangeapi.basicdata.entity.OrmsStand;
import com.gzzn.omms.msgexchangeapi.basicdata.manager.OrmsStandManager;
import com.gzzn.omms.msgexchangeapi.config.TestRestTemplateConfig;
@RunWith(SpringRunner.class)
@SpringBootTest(classes=TestRestTemplateConfig.class)
public class OrmsStandManagerTest {
@Test
public void testFindAll()
{
OrmsStand ormsStand = OrmsStandManager.getInstance().getOrmsStandByStandCode("140");
assertThat(ormsStand).isNotNull();
}
}
@@ -12,9 +12,10 @@ import org.springframework.test.context.junit4.SpringRunner;
import com.gzzn.omms.msgexchangeapi.basicdata.entity.OrmsStand;
import com.gzzn.omms.msgexchangeapi.basicdata.service.IOrmsStandService;
import com.gzzn.omms.msgexchangeapi.config.TestRestTemplateConfig;
@RunWith(SpringRunner.class)
@SpringBootTest
@SpringBootTest(classes=TestRestTemplateConfig.class)
public class OrmsStandServiceImplTest {
@Autowired
@@ -26,4 +27,7 @@ public class OrmsStandServiceImplTest {
List<OrmsStand> lsOrmsStands = ormsStandService.findAll();
assertThat(lsOrmsStands).isNotEmpty();
}
}
@@ -0,0 +1,23 @@
package com.gzzn.omms.msgexchangeapi.config;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
@TestConfiguration
public class TestRestTemplateConfig {
@Bean
public RestTemplate restTemplate(ClientHttpRequestFactory factory){
return new RestTemplate(factory);
}
@Bean
public ClientHttpRequestFactory simpleClientHttpRequestFactory(){
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setReadTimeout(5000);//单位为ms
factory.setConnectTimeout(5000);//单位为ms
return factory;
}
}