|
@@ -2,20 +2,35 @@ package com.huimv.cattle.controller;
|
|
|
|
|
|
|
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import com.huimv.cattle.pojo.DataSource;
|
|
import com.huimv.cattle.pojo.FarmStockRank;
|
|
import com.huimv.cattle.pojo.FarmStockRank;
|
|
import com.huimv.cattle.pojo.SalesCattle;
|
|
import com.huimv.cattle.pojo.SalesCattle;
|
|
|
|
+import com.huimv.cattle.pojo.SysFarm;
|
|
import com.huimv.cattle.pojo.vo.FarmStockRankVo;
|
|
import com.huimv.cattle.pojo.vo.FarmStockRankVo;
|
|
|
|
+import com.huimv.cattle.service.DataSourceService;
|
|
import com.huimv.cattle.service.FarmStockRankService;
|
|
import com.huimv.cattle.service.FarmStockRankService;
|
|
|
|
+import com.huimv.cattle.service.SysFarmService;
|
|
import com.huimv.cattle.utils.FarmCodeUtils;
|
|
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.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.transaction.annotation.Transactional;
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
+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.ArrayList;
|
|
|
|
+import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@@ -34,6 +49,12 @@ public class FarmStockRankController {
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private FarmStockRankService farmStockRankService;
|
|
private FarmStockRankService farmStockRankService;
|
|
|
|
+ @Resource
|
|
|
|
+ private DataSourceService dataSourceService;
|
|
|
|
+ @Resource
|
|
|
|
+ private RestTemplate restTemplate;
|
|
|
|
+ @Autowired
|
|
|
|
+ private SysFarmService farmService;
|
|
|
|
|
|
@PostMapping("/saveFarmStockRank")
|
|
@PostMapping("/saveFarmStockRank")
|
|
@Transactional
|
|
@Transactional
|
|
@@ -41,8 +62,6 @@ public class FarmStockRankController {
|
|
String farmCode = FarmCodeUtils.getFarmCode(farmStockRankVo.getFarmCode(), request);
|
|
String farmCode = FarmCodeUtils.getFarmCode(farmStockRankVo.getFarmCode(), request);
|
|
List<FarmStockRank> farmStockRanks = farmStockRankVo.getFarmStockRanks();
|
|
List<FarmStockRank> farmStockRanks = farmStockRankVo.getFarmStockRanks();
|
|
farmStockRankService.remove(new QueryWrapper<FarmStockRank>().eq("farm_code",farmCode));
|
|
farmStockRankService.remove(new QueryWrapper<FarmStockRank>().eq("farm_code",farmCode));
|
|
- System.out.println(farmStockRankVo.getFarmCode());
|
|
|
|
- System.out.println(farmStockRanks.toString());
|
|
|
|
for (FarmStockRank farmStockRank : farmStockRanks) {
|
|
for (FarmStockRank farmStockRank : farmStockRanks) {
|
|
farmStockRank.setFarmCode(farmCode);
|
|
farmStockRank.setFarmCode(farmCode);
|
|
farmStockRankService.save(farmStockRank);
|
|
farmStockRankService.save(farmStockRank);
|
|
@@ -66,11 +85,67 @@ public class FarmStockRankController {
|
|
@PostMapping("/getFarmStockRank")
|
|
@PostMapping("/getFarmStockRank")
|
|
public Result list(@RequestBody FarmStockRank farmStockRank,HttpServletRequest request){
|
|
public Result list(@RequestBody FarmStockRank farmStockRank,HttpServletRequest request){
|
|
String farmCode = FarmCodeUtils.getFarmCode(farmStockRank.getFarmCode(), request);
|
|
String farmCode = FarmCodeUtils.getFarmCode(farmStockRank.getFarmCode(), request);
|
|
- List<FarmStockRank> list = farmStockRankService.list(new QueryWrapper<FarmStockRank>().eq("farm_code",farmCode).orderByDesc("stock"));
|
|
|
|
- if (ObjectUtil.isEmpty(list)){
|
|
|
|
- return new Result(ResultCode.SUCCESS,new ArrayList<>());
|
|
|
|
|
|
+ // //读取模式切换
|
|
|
|
+ DataSource dataSource = dataSourceService.getDataSourceStatus();
|
|
|
|
+ if (dataSource.getViewType() == 1) {
|
|
|
|
+ //view=1,显示县填写数据
|
|
|
|
+ return farmStockRankService.getFarmStockRank(farmCode);
|
|
|
|
+ } else {
|
|
|
|
+ //view=2,显示镇汇总数据
|
|
|
|
+ if (dataSource.getDsStatus() == 1) {
|
|
|
|
+ //status=1,显示镇汇总(手填)数据
|
|
|
|
+ return farmStockRankService.getFarmStockRank(farmCode);
|
|
|
|
+ } else {
|
|
|
|
+ //status=2,显示镇汇总(养殖云)数据
|
|
|
|
+ System.out.println("status=2,显示镇汇总(养殖云)数据");
|
|
|
|
+ JSONArray farmCodes = getFarmCodeByAdcode(farmCode);
|
|
|
|
+ if (ObjectUtil.isEmpty(farmCodes)){
|
|
|
|
+ return new Result(ResultCode.SUCCESS,new ArrayList<>());
|
|
|
|
+ }
|
|
|
|
+ return getStockRankByDivision(farmCodes);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private Result getStockRankByDivision(JSONArray farmCodes) {
|
|
|
|
+ HttpHeaders httpHeaders = new HttpHeaders();
|
|
|
|
+ MediaType type = MediaType.parseMediaType("application/json;charset=UTF-8");
|
|
|
|
+ httpHeaders.setContentType(type);
|
|
|
|
+ HashMap<String, Object> map = new HashMap<>();
|
|
|
|
+ //这里提交的是区县编码或乡镇编码
|
|
|
|
+ map.put("farmCodes", farmCodes);
|
|
|
|
+ HttpEntity<Map<String, Object>> objectHttpEntity = new HttpEntity<>(map, httpHeaders);
|
|
|
|
+ //读取真实数据
|
|
|
|
+ String remoteUrl = "http://123.60.134.84:10001/breed/api/v1.0.0/cattle/getStockRankByDivision";
|
|
|
|
+ ResponseEntity<String> entity = restTemplate.postForEntity(remoteUrl, objectHttpEntity, String.class);
|
|
|
|
+ if(entity.getStatusCode().toString().contains("200")){
|
|
|
|
+ String body = entity.getBody();
|
|
|
|
+ System.out.println(body);
|
|
|
|
+ JSONArray dataJo = JSON.parseObject(body).getJSONArray("data");
|
|
|
|
+ System.out.println("dataJo="+dataJo);
|
|
|
|
+ //, )
|
|
|
|
+ return new Result(ResultCode.SUCCESS,dataJo);
|
|
|
|
+ }else{
|
|
|
|
+ return new Result(ResultCode.FAIL,"调取远程数据出错.");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private JSONArray 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];
|
|
|
|
+ }
|
|
}
|
|
}
|
|
- return new Result(ResultCode.SUCCESS,list);
|
|
|
|
|
|
+ String remoteUrl = "http://123.60.134.84:10001/admin/v1.0.0/account/getFarmByAdcode";
|
|
|
|
+ Map map = new HashMap();
|
|
|
|
+ map.put("adcode",adcode);
|
|
|
|
+ ResponseEntity<String> stringResponseEntity = restTemplate.postForEntity(remoteUrl, map, String.class);
|
|
|
|
+ JSONArray jsonObject = JSON.parseArray(stringResponseEntity.getBody());
|
|
|
|
+ System.out.println(jsonObject);
|
|
|
|
+ return jsonObject;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|