|
@@ -1,8 +1,18 @@
|
|
package com.huimv.production.autoGetData.service.impl;
|
|
package com.huimv.production.autoGetData.service.impl;
|
|
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.huimv.production.autoGetData.entity.IndexParameter;
|
|
|
|
+import com.huimv.production.autoGetData.repo.IndexParameterRepository;
|
|
import com.huimv.production.autoGetData.service.IAutoGetErpData;
|
|
import com.huimv.production.autoGetData.service.IAutoGetErpData;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
+import org.springframework.web.client.RestTemplate;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.List;
|
|
|
|
+import java.util.Map;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Project : huimv.shiwan
|
|
* @Project : huimv.shiwan
|
|
@@ -21,10 +31,97 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
|
|
// 查询结束日期
|
|
// 查询结束日期
|
|
@Value("${erp.datasource.endDate}")
|
|
@Value("${erp.datasource.endDate}")
|
|
private String endDate;
|
|
private String endDate;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RestTemplate template;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private IndexParameterRepository parameterRepository;
|
|
|
|
|
|
|
|
+
|
|
|
|
+ //PSY
|
|
@Override
|
|
@Override
|
|
public void getPsy() {
|
|
public void getPsy() {
|
|
- System.out.println("startDate:"+startDate);
|
|
|
|
- System.out.println("endDate:"+endDate);
|
|
|
|
|
|
+ String token = getToken();
|
|
|
|
+ JSONObject jsonObject = template.getForObject("http://192.168.1.62:9100/erpData/getPsy?startDate="+startDate+"&endDate="+endDate+"&accessToken="+token
|
|
|
|
+ ,JSONObject.class );
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ if (data == null){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+ IndexParameter indexParameter = parameterRepository.findById(7).get();
|
|
|
|
+ indexParameter.setUpdateTime(new Date());
|
|
|
|
+ //TODO 将数据加入到数据库
|
|
|
|
+ indexParameter.setData(data);
|
|
|
|
+
|
|
|
|
+ parameterRepository.save(indexParameter);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //返情率
|
|
|
|
+ @Override
|
|
|
|
+ public void getReEstrusRate() {
|
|
|
|
+ String token = getToken();
|
|
|
|
+ JSONObject jsonObject = template.getForObject("http://192.168.1.62:9100/erpData/getReEstrusRate?startDate="+startDate+"&endDate="+endDate+"&accessToken="+token
|
|
|
|
+ ,JSONObject.class );
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ if (data == null){
|
|
|
|
+ return;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String reestrus_rate ="0.00000";
|
|
|
|
+ List<Map<String,String>> list = (List<Map<String,String>> ) JSON.parse(data);
|
|
|
|
+ for (Map<String, String> stringStringMap : list) {
|
|
|
|
+ for (String s : stringStringMap.keySet()) {
|
|
|
|
+ String farm = stringStringMap.get(s);
|
|
|
|
+ if (farm != null && farm.contains("海盐")){
|
|
|
|
+ reestrus_rate = stringStringMap.get("reestrus_rate");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ IndexParameter indexParameter = parameterRepository.findById(9).get();
|
|
|
|
+ indexParameter.setData(reestrus_rate);
|
|
|
|
+ indexParameter.setUpdateTime(new Date());
|
|
|
|
+ parameterRepository.save(indexParameter);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void getParturitionRate() {
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ private String getToken(){
|
|
|
|
+ JSONObject token = template.getForObject("http://192.168.1.62:9100/token/getToken?userId=20210501×tamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c",
|
|
|
|
+ JSONObject.class);
|
|
|
|
+ return token.getString("accessToken");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ public static void main(String[] args) {
|
|
|
|
+ RestTemplate restTemplate = new RestTemplate();
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ JSONObject token1 = restTemplate.getForObject("http://192.168.1.62:9100/token/getToken?userId=20210501×tamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c",
|
|
|
|
+ JSONObject.class);
|
|
|
|
+ String token = token1.getString("accessToken");
|
|
|
|
+ JSONObject jsonObject = restTemplate.getForObject("http://192.168.1.62:9100/erpData/getReEstrusRate?startDate=2020.1.1&endDate=2021.12.31&accessToken="+token
|
|
|
|
+ ,JSONObject.class );
|
|
|
|
+ String data = jsonObject.getString("data");
|
|
|
|
+ String reestrus_rate ="0.00000";
|
|
|
|
+ List<Map<String,String>> list = (List<Map<String,String>> ) JSON.parse(data);
|
|
|
|
+ for (Map<String, String> stringStringMap : list) {
|
|
|
|
+ for (String s : stringStringMap.keySet()) {
|
|
|
|
+ String farm = stringStringMap.get(s);
|
|
|
|
+ if (farm != null && farm.contains("海盐")){
|
|
|
|
+ reestrus_rate = stringStringMap.get("reestrus_rate");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
}
|
|
}
|
|
}
|
|
}
|