|
@@ -2,20 +2,31 @@ package com.huimv.cattle.controller;
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
+import com.huimv.cattle.pojo.DataSource;
|
|
|
import com.huimv.cattle.pojo.PreventDetection;
|
|
|
import com.huimv.cattle.pojo.SalesCattle;
|
|
|
import com.huimv.cattle.pojo.vo.SalesCattleVo;
|
|
|
+import com.huimv.cattle.service.DataSourceService;
|
|
|
import com.huimv.cattle.service.SalesCattleService;
|
|
|
import com.huimv.cattle.utils.FarmCodeUtils;
|
|
|
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.transaction.annotation.Transactional;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
|
|
+import javax.annotation.Resource;
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
@@ -33,6 +44,10 @@ import java.util.Map;
|
|
|
public class SalesCattleController {
|
|
|
@Autowired
|
|
|
private SalesCattleService salesCattleService;
|
|
|
+ @Resource
|
|
|
+ private DataSourceService dataSourceService;
|
|
|
+ @Resource
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
|
|
@Transactional
|
|
|
@PostMapping("/saveSalesCattle")
|
|
@@ -62,13 +77,48 @@ public class SalesCattleController {
|
|
|
return new Result(10000,"删除成功",true);
|
|
|
}
|
|
|
@PostMapping("/getSalesCattle")
|
|
|
- public Result list(@RequestBody SalesCattle salesCattle,HttpServletRequest request){
|
|
|
- String farmCode = FarmCodeUtils.getFarmCode(salesCattle.getFarmCode(), request);
|
|
|
- List<SalesCattle> list = salesCattleService.list(new QueryWrapper<SalesCattle>().eq("farm_code",farmCode).orderByDesc("year").orderByDesc("quarter"));
|
|
|
- if (ObjectUtil.isEmpty(list)){
|
|
|
- return new Result(ResultCode.SUCCESS,new ArrayList<>());
|
|
|
+ public Result list(@RequestBody Map<String,String> paramsMap,HttpServletRequest request){
|
|
|
+ String farmCode = FarmCodeUtils.getFarmCode(paramsMap.get("farmCode"), request);
|
|
|
+ // //读取模式切换
|
|
|
+ DataSource dataSource = dataSourceService.getDataSourceStatus();
|
|
|
+ if (dataSource.getViewType() == 1) {
|
|
|
+ //view=1,显示县填写数据
|
|
|
+ return salesCattleService.getSalesCattle(farmCode);
|
|
|
+ } else {
|
|
|
+ //view=2,显示镇汇总数据
|
|
|
+ if (dataSource.getDsStatus() == 1) {
|
|
|
+ //status=1,显示镇汇总(手填)数据
|
|
|
+ return salesCattleService.getSalesCattle(farmCode);
|
|
|
+ } else {
|
|
|
+ //status=2,显示镇汇总(养殖云)数据
|
|
|
+ System.out.println("status=2,显示镇汇总(养殖云)数据");
|
|
|
+ return getSalesByDivision(farmCode);
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Result getSalesByDivision(String farmCode) {
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
|
|
|
+ httpHeaders.setContentType(type);
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
+ //这里提交的是区县编码或乡镇编码
|
|
|
+ map.put("farmCode", farmCode);
|
|
|
+ HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(map, httpHeaders);
|
|
|
+ //读取真实数据
|
|
|
+ String remoteUrl = "http://123.60.134.84:10001/breed/api/v1.0.0/cattle/getSalesByDivision";
|
|
|
+ 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,"调取远程数据出错.");
|
|
|
}
|
|
|
- return new Result(ResultCode.SUCCESS,list);
|
|
|
}
|
|
|
}
|
|
|
|