|
@@ -40,17 +40,52 @@ public class StockDetailController {
|
|
private RestTemplate restTemplate;
|
|
private RestTemplate restTemplate;
|
|
|
|
|
|
//查询
|
|
//查询
|
|
|
|
+ @PostMapping("/getStockHistory")
|
|
|
|
+ public Result getStockHistory(@RequestBody Map<String, String> paramsMap) throws ParseException {
|
|
|
|
+ Integer dsStatu = dataSourceService.getDataSourceStatus(paramsMap);
|
|
|
|
+ if (dsStatu == null) {
|
|
|
|
+ dsStatu = 0;
|
|
|
|
+ }
|
|
|
|
+ if (dsStatu == 1) {
|
|
|
|
+ //读取远程历史存栏
|
|
|
|
+ return getRemoteHistoryStock(paramsMap);
|
|
|
|
+ } else {
|
|
|
|
+ //读取填报数据
|
|
|
|
+ return stockDetailService.getLocalHistoryStock(paramsMap);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //
|
|
|
|
+ private Result getRemoteHistoryStock(Map<String, String> paramsMap) {
|
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
|
|
|
|
+ httpHeaders.setContentType(type);
|
|
|
|
+// MultiValueMap<String, Object> map=new LinkedMultiValueMap<>();
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ map.put("farmCode", paramsMap.get("farmCode"));
|
|
|
|
+ map.put("months", paramsMap.get("months"));
|
|
|
|
+ HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(map, httpHeaders);
|
|
|
|
+ //读取真实数据
|
|
|
|
+ String remoteUrl = "http://123.60.134.84:10001/breed/api/v1.0.0/stock/getStockHistory";
|
|
|
|
+ ResponseEntity<String> entity = restTemplate.postForEntity(remoteUrl, objectHttpEntity, String.class);
|
|
|
|
+ if(entity.getStatusCode().toString().contains("200")){
|
|
|
|
+ String body = entity.getBody();
|
|
|
|
+ return new Result(ResultCode.SUCCESS,JSONArray.parseArray(JSON.parseObject(body).getString("data")));
|
|
|
|
+ }else{
|
|
|
|
+ return new Result(ResultCode.FAIL,"调取远程数据出错.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //查询
|
|
@PostMapping("/getCurrentStock")
|
|
@PostMapping("/getCurrentStock")
|
|
public Result getCurrentStock(@RequestBody Map<String, String> paramsMap) throws ParseException {
|
|
public Result getCurrentStock(@RequestBody Map<String, String> paramsMap) throws ParseException {
|
|
Integer dsStatu = dataSourceService.getDataSourceStatus(paramsMap);
|
|
Integer dsStatu = dataSourceService.getDataSourceStatus(paramsMap);
|
|
- System.out.println("1 dsStatu="+dsStatu);
|
|
|
|
if (dsStatu == null) {
|
|
if (dsStatu == null) {
|
|
dsStatu = 0;
|
|
dsStatu = 0;
|
|
}
|
|
}
|
|
- System.out.println("2 dsStatu="+dsStatu);
|
|
|
|
if (dsStatu == 1) {
|
|
if (dsStatu == 1) {
|
|
//读取远程数据
|
|
//读取远程数据
|
|
- return getRemoteData();
|
|
|
|
|
|
+ return getRemoteStock();
|
|
} else {
|
|
} else {
|
|
//读取填报数据
|
|
//读取填报数据
|
|
return stockDetailService.getCurrentStock(paramsMap);
|
|
return stockDetailService.getCurrentStock(paramsMap);
|
|
@@ -58,7 +93,7 @@ public class StockDetailController {
|
|
}
|
|
}
|
|
|
|
|
|
//读取远程数据
|
|
//读取远程数据
|
|
- public Result getRemoteData(){
|
|
|
|
|
|
+ public Result getRemoteStock(){
|
|
HttpHeaders httpHeaders = new HttpHeaders();
|
|
HttpHeaders httpHeaders = new HttpHeaders();
|
|
MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
|
|
MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
|
|
httpHeaders.setContentType(type);
|
|
httpHeaders.setContentType(type);
|
|
@@ -69,11 +104,8 @@ public class StockDetailController {
|
|
//读取真实数据
|
|
//读取真实数据
|
|
String remoteUrl = "http://123.60.134.84:10001/breed/api/v1.0.0/stock/getCurrentStock";
|
|
String remoteUrl = "http://123.60.134.84:10001/breed/api/v1.0.0/stock/getCurrentStock";
|
|
ResponseEntity<String> entity = restTemplate.postForEntity(remoteUrl, objectHttpEntity, String.class);
|
|
ResponseEntity<String> entity = restTemplate.postForEntity(remoteUrl, objectHttpEntity, String.class);
|
|
-// System.out.println("状态码:"+entity.getStatusCode());
|
|
|
|
-// System.out.println("响应体:"+entity.getBody());
|
|
|
|
if(entity.getStatusCode().toString().contains("200")){
|
|
if(entity.getStatusCode().toString().contains("200")){
|
|
String body = entity.getBody();
|
|
String body = entity.getBody();
|
|
- System.out.println("body>>>>>>>>>>>>>"+body);
|
|
|
|
return new Result(ResultCode.SUCCESS,JSONArray.parseArray(JSON.parseObject(body).getString("data")));
|
|
return new Result(ResultCode.SUCCESS,JSONArray.parseArray(JSON.parseObject(body).getString("data")));
|
|
}else{
|
|
}else{
|
|
return new Result(ResultCode.FAIL,"调取远程数据出错.");
|
|
return new Result(ResultCode.FAIL,"调取远程数据出错.");
|