|
@@ -1,13 +1,24 @@
|
|
|
package com.huimv.cattle.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import com.huimv.cattle.pojo.DataSource;
|
|
|
+import com.huimv.cattle.service.DataSourceService;
|
|
|
import com.huimv.cattle.service.StockService;
|
|
|
import com.huimv.common.utils.Result;
|
|
|
import com.huimv.common.utils.ResultCode;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.http.HttpEntity;
|
|
|
+import org.springframework.http.HttpHeaders;
|
|
|
+import org.springframework.http.MediaType;
|
|
|
+import org.springframework.http.ResponseEntity;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -24,10 +35,55 @@ import java.util.Map;
|
|
|
public class StockController {
|
|
|
@Autowired
|
|
|
private StockService stockService;
|
|
|
+ @Resource
|
|
|
+ private DataSourceService dataSourceService;
|
|
|
+ @Resource
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
|
|
@PostMapping("/getStock")
|
|
|
public Result list(HttpServletRequest httpServletRequest,@RequestBody Map<String,String> paramsMap) {
|
|
|
- return stockService.getStock(httpServletRequest,paramsMap);
|
|
|
+ // //读取模式切换
|
|
|
+ DataSource dataSource = dataSourceService.getDataSourceStatus();
|
|
|
+ if (dataSource.getViewType() == 1) {
|
|
|
+ //view=1,显示县填写数据
|
|
|
+ return stockService.getStock(httpServletRequest,paramsMap);
|
|
|
+ } else {
|
|
|
+ //view=2,显示镇汇总数据
|
|
|
+ if (dataSource.getDsStatus() == 1) {
|
|
|
+ //status=1,显示镇汇总(手填)数据
|
|
|
+ return stockService.getStock(httpServletRequest,paramsMap);
|
|
|
+ } else {
|
|
|
+ //status=2,显示镇汇总(养殖云)数据
|
|
|
+ System.out.println("status=2,显示镇汇总(养殖云)数据");
|
|
|
+ return getStockFromBreedCloud(paramsMap);
|
|
|
+ //++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //从养殖云获取数据
|
|
|
+ private Result getStockFromBreedCloud(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"));
|
|
|
+ HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(map, httpHeaders);
|
|
|
+ //读取真实数据
|
|
|
+ String remoteUrl = "http://123.60.134.84:10001/breed/api/v1.0.0/cattle/getStockByDivision";
|
|
|
+ ResponseEntity<String> entity = restTemplate.postForEntity(remoteUrl, objectHttpEntity, String.class);
|
|
|
+ if(entity.getStatusCode().toString().contains("200")){
|
|
|
+ String body = entity.getBody();
|
|
|
+ System.out.println(body);
|
|
|
+ JSONObject dataJo = JSON.parseObject(body).getJSONObject("data");
|
|
|
+ System.out.println("dataJo="+dataJo);
|
|
|
+ //, )
|
|
|
+ return new Result(ResultCode.SUCCESS,dataJo);
|
|
|
+ }else{
|
|
|
+ return new Result(ResultCode.FAIL,"调取远程数据出错.");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@PostMapping("/saveStock")
|