|
@@ -1,13 +1,23 @@
|
|
|
package com.huimv.env.produce.controller;
|
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
import com.huimv.common.utils.Result;
|
|
|
+import com.huimv.common.utils.ResultCode;
|
|
|
+import com.huimv.env.produce.service.DataSourceService;
|
|
|
import com.huimv.env.produce.service.EliminateDetailService;
|
|
|
import com.huimv.env.produce.service.SalesDetailService;
|
|
|
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 java.text.ParseException;
|
|
|
+import java.util.HashMap;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -24,6 +34,68 @@ import java.util.Map;
|
|
|
public class SalesDetailController {
|
|
|
@Autowired
|
|
|
private com.huimv.env.produce.service.SalesDetailService salesDetailService;
|
|
|
+ @Autowired
|
|
|
+ private DataSourceService dataSourceService;
|
|
|
+ @Autowired
|
|
|
+ private RestTemplate restTemplate;
|
|
|
+
|
|
|
+ //查询
|
|
|
+ @PostMapping("/getSaleHistory")
|
|
|
+ public Result getSaleHistory(@RequestBody Map<String, String> paramsMap) throws ParseException {
|
|
|
+ Integer dsStatu = dataSourceService.getDataSourceStatus(paramsMap);
|
|
|
+ if (dsStatu == null) {
|
|
|
+ dsStatu = 0;
|
|
|
+ }
|
|
|
+ if (dsStatu == 1) {
|
|
|
+ //读取远程销售历史
|
|
|
+ return getRemoteSaleHistory(paramsMap);
|
|
|
+ } else {
|
|
|
+ //读取填报数据
|
|
|
+ return salesDetailService.getLocalSaleHistory(paramsMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private Result getRemoteSaleHistory(Map<String, String> paramsMap) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+ //查询
|
|
|
+ @PostMapping("/getAllSale")
|
|
|
+ public Result getAllSale(@RequestBody Map<String, String> paramsMap) throws ParseException {
|
|
|
+ Integer dsStatu = dataSourceService.getDataSourceStatus(paramsMap);
|
|
|
+ if (dsStatu == null) {
|
|
|
+ dsStatu = 0;
|
|
|
+ }
|
|
|
+ if (dsStatu == 1) {
|
|
|
+ //读取远程历史存栏
|
|
|
+ return getRemoteAllSale(paramsMap);
|
|
|
+ } else {
|
|
|
+ //读取填报数据
|
|
|
+ return salesDetailService.getLocalSales(paramsMap);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
+ private Result getRemoteAllSale(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/sales/getAllSale";
|
|
|
+ ResponseEntity<String> entity = restTemplate.postForEntity(remoteUrl, objectHttpEntity, String.class);
|
|
|
+ if(entity.getStatusCode().toString().contains("200")){
|
|
|
+ String body = entity.getBody();
|
|
|
+ System.out.println("body="+body);
|
|
|
+ //JSONArray.parseArray(JSON.parseObject(body).getString("data"))
|
|
|
+ return new Result(ResultCode.SUCCESS,JSON.parseObject(body).getJSONObject("data"));
|
|
|
+ }else{
|
|
|
+ return new Result(ResultCode.FAIL,"调取远程数据出错.");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
//查询
|
|
|
@PostMapping("/getSales")
|