|
@@ -1,13 +1,35 @@
|
|
package com.huimv.cattle.controller;
|
|
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.SysFarm;
|
|
|
|
+import com.huimv.cattle.service.DataSourceService;
|
|
import com.huimv.cattle.service.OverviewService;
|
|
import com.huimv.cattle.service.OverviewService;
|
|
|
|
+import com.huimv.cattle.service.SysFarmService;
|
|
|
|
+import com.huimv.cattle.utils.FarmCodeUtils;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.Result;
|
|
import com.huimv.common.utils.ResultCode;
|
|
import com.huimv.common.utils.ResultCode;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
-import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+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.PostMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.RestController;
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
+
|
|
|
|
+import javax.annotation.Resource;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.util.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -18,20 +40,88 @@ import java.util.Map;
|
|
* @author zn
|
|
* @author zn
|
|
* @since 2022-12-15
|
|
* @since 2022-12-15
|
|
*/
|
|
*/
|
|
-@CrossOrigin
|
|
|
|
@RestController
|
|
@RestController
|
|
@RequestMapping("/v1.0.0/overview")
|
|
@RequestMapping("/v1.0.0/overview")
|
|
public class OverviewController {
|
|
public class OverviewController {
|
|
@Autowired
|
|
@Autowired
|
|
private OverviewService overviewService;
|
|
private OverviewService overviewService;
|
|
|
|
+ @Resource
|
|
|
|
+ private DataSourceService dataSourceService;
|
|
|
|
+ @Resource
|
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysFarmService farmService;
|
|
|
|
|
|
@PostMapping("/getOverview")
|
|
@PostMapping("/getOverview")
|
|
public Result getOverView(HttpServletRequest httpServletRequest, @RequestBody Map<String,String> paramsMap) {
|
|
public Result getOverView(HttpServletRequest httpServletRequest, @RequestBody Map<String,String> paramsMap) {
|
|
- return overviewService.overList(httpServletRequest,paramsMap);
|
|
|
|
|
|
+ String farmCode = FarmCodeUtils.getFarmCode(paramsMap.get("farmCode"), httpServletRequest);
|
|
|
|
+ // //读取模式切换
|
|
|
|
+ DataSource dataSource = dataSourceService.getDataSourceStatus();
|
|
|
|
+ if (dataSource.getViewType() == 1) {
|
|
|
|
+ //view=1,显示县填写数据
|
|
|
|
+ return overviewService.overList(httpServletRequest,paramsMap);
|
|
|
|
+ } else {
|
|
|
|
+ //view=2,显示镇汇总数据
|
|
|
|
+ if (dataSource.getDsStatus() == 1) {
|
|
|
|
+ //status=1,显示镇汇总(手填)数据
|
|
|
|
+ return overviewService.getListOverview(httpServletRequest,paramsMap);
|
|
|
|
+ } else {
|
|
|
|
+ //status=2,显示镇汇总(养殖云)数据
|
|
|
|
+ System.out.println("status=2,显示镇汇总(养殖云)数据");
|
|
|
|
+ String farmCodes = getFarmCodeByAdcode(farmCode);
|
|
|
|
+ System.out.println(farmCodes);
|
|
|
|
+ if (StringUtils.isBlank(farmCodes)){
|
|
|
|
+ return new Result(ResultCode.SUCCESS,new ArrayList<>());
|
|
|
|
+ }
|
|
|
|
+ return getStockFromBreedCloud(farmCodes);
|
|
|
|
+ //++++++++++++++++++++++++++++++++++++++++++++++++++
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private String getFarmCodeByAdcode(String farmCode) {
|
|
|
|
+ String adcode = "620826";
|
|
|
|
+ if (!"0".equals(farmCode)){
|
|
|
|
+ SysFarm list = farmService.getOne(new QueryWrapper<SysFarm>().eq("farm_code", farmCode));
|
|
|
|
+ if (ObjectUtil.isNotEmpty(list)){
|
|
|
|
+ String[] split = list.getAdcode().split(",");
|
|
|
|
+ adcode = split[split.length-1];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ String remoteUrl = "http://123.60.134.84:10001/admin/v1.0.0/account/getFarmCodeByAdcode";
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
+ map.put("adcode",adcode);
|
|
|
|
+ ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(remoteUrl, map, String.class);
|
|
|
|
+ return stringResponseEntity.getBody();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //从养殖云获取数据
|
|
|
|
+ private Result getStockFromBreedCloud(String farmCodes) {
|
|
|
|
+ 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", farmCodes);
|
|
|
|
+ HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(map, httpHeaders);
|
|
|
|
+ //读取真实数据
|
|
|
|
+ String remoteUrl = "http://123.60.134.84:10001/breed/api/v1.0.0/cattle/getFarmCountByDivision";
|
|
|
|
+ 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("/saveOverview")
|
|
@PostMapping("/saveOverview")
|
|
- public Result saveOverView(HttpServletRequest httpServletRequest, @RequestBody Map<String,String> paramsMap) {
|
|
|
|
|
|
+ public Result saveOverView(HttpServletRequest httpServletRequest,@RequestBody Map<String,String> paramsMap) {
|
|
return overviewService.add(httpServletRequest,paramsMap);
|
|
return overviewService.add(httpServletRequest,paramsMap);
|
|
}
|
|
}
|
|
|
|
|