Browse Source

新建受胎率。

zhuoning 4 năm trước cách đây
mục cha
commit
ca440281b3

+ 36 - 37
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/config/SaticScheduleTask.java

@@ -31,53 +31,52 @@ public class SaticScheduleTask  {
 //        System.err.println("执行静态定时任务时间: " + LocalDateTime.now());
 //    }
 
-
-
     @Scheduled(cron = "0/5 * * * * ?")
     private void getPsyTask(){
         System.err.println("执行 getPsyTask 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getPsy();
     }
 
-    @Scheduled(cron = "* 0/5 * * * ?")
-    private void getReEstrusRate(){
-        System.err.println("执行 getReEstrusRate 执行静态定时任务时间: " + LocalDateTime.now());
-        iAutoGetErpData.getReEstrusRate();
-
-    }
-
-    @Scheduled(cron = "* 0/5 * * * ?")
-    private void getParturitionRate(){
-        System.err.println("执行 getParturitionRate 执行静态定时任务时间: " + LocalDateTime.now());
-        iAutoGetErpData.getParturitionRate();
-    }
-
-    @Scheduled(cron = "* 0/5 * * * ?")
-    private void getStorage(){
-        System.err.println("执行 getStorage 执行静态定时任务时间: " + LocalDateTime.now());
-    }
-
-    @Scheduled(cron = "* 0/5 * * * ?")
-    private void getPigletInfo(){
-        System.err.println("执行 getPigletInfo 执行静态定时任务时间: " + LocalDateTime.now());
-    }
-
-    @Scheduled(cron = "* 0/5 * * * ?")
-    private void getMateQuantity(){
-        System.err.println("执行 getMateQuantity 执行静态定时任务时间: " + LocalDateTime.now());
-    }
+//    @Scheduled(cron = "* 0/5 * * * ?")
+//    private void getReEstrusRate(){
+//        System.err.println("执行 getReEstrusRate 执行静态定时任务时间: " + LocalDateTime.now());
+//        iAutoGetErpData.getReEstrusRate();
+//
+//    }
+//
+//    @Scheduled(cron = "* 0/5 * * * ?")
+//    private void getParturitionRate(){
+//        System.err.println("执行 getParturitionRate 执行静态定时任务时间: " + LocalDateTime.now());
+//        iAutoGetErpData.getParturitionRate();
+//    }
+//
+//    @Scheduled(cron = "* 0/5 * * * ?")
+//    private void getStorage(){
+//        System.err.println("执行 getStorage 执行静态定时任务时间: " + LocalDateTime.now());
+//    }
+//
+//    @Scheduled(cron = "* 0/5 * * * ?")
+//    private void getPigletInfo(){
+//        System.err.println("执行 getPigletInfo 执行静态定时任务时间: " + LocalDateTime.now());
+//    }
+//
+//    @Scheduled(cron = "* 0/5 * * * ?")
+//    private void getMateQuantity(){
+//        System.err.println("执行 getMateQuantity 执行静态定时任务时间: " + LocalDateTime.now());
+//    }
 
-    @Scheduled(cron = "* 0/5 * * * ?")
+    @Scheduled(cron = "0/5 * * * * ?")
     private void getConceptionRate(){
-        System.err.println("执行 getConceptionRate 执行静态定时任务时间: " + LocalDateTime.now());
+        // 读取受胎率
+        iAutoGetErpData.getConceptionRate();
     }
 
-    @Scheduled(cron = "* 0/5 * * * ?")
-    private void getAllStorage(){
-        System.err.println("执行 getAllStorage 执行静态定时任务时间: " + LocalDateTime.now());
-
-
-    }
+//    @Scheduled(cron = "* 0/5 * * * ?")
+//    private void getAllStorage(){
+//        System.err.println("执行 getAllStorage 执行静态定时任务时间: " + LocalDateTime.now());
+//
+//
+//    }
 
 
 

+ 2 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/IAutoGetErpData.java

@@ -6,4 +6,6 @@ public interface IAutoGetErpData {
     void getReEstrusRate();
 
     void getParturitionRate();
+
+    void getConceptionRate();
 }

+ 80 - 23
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -5,14 +5,17 @@ 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 lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
+import org.springframework.data.domain.Example;
 import org.springframework.stereotype.Service;
 import org.springframework.web.client.RestTemplate;
 
 import java.util.Date;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 
 /**
  * @Project : huimv.shiwan
@@ -23,6 +26,7 @@ import java.util.Map;
  * @Create : 2020-12-25
  **/
 @Service
+@Slf4j
 public class AutoGetErpDataImpl implements IAutoGetErpData {
     // 查询开始日期
     @Value("${erp.datasource.startDate}")
@@ -36,6 +40,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     private String apiPort;
     @Value("${erp.datasource.serviceName}")
     private String serviceName;
+    private String filterFarm = "海盐";
 
     @Autowired
     private RestTemplate template;
@@ -47,11 +52,11 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     public void getPsy() {
         String token = getToken();
         String servicePath = apiIp + apiPort + serviceName;
-        System.out.println("servicePath>>"+servicePath);
-        JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName + "/getPsy?startDate="+startDate+"&endDate="+endDate+"&accessToken="+token
-                ,JSONObject.class );
+        System.out.println("servicePath>>" + servicePath);
+        JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName + "/getPsy?startDate=" + startDate + "&endDate=" + endDate + "&accessToken=" + token
+                , JSONObject.class);
         String data = jsonObject.getString("data");
-        if (data == null){
+        if (data == null) {
             return;
         }
         IndexParameter indexParameter = parameterRepository.findById(7).get();
@@ -60,28 +65,26 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         indexParameter.setData(data);
 
         parameterRepository.save(indexParameter);
-
-
     }
 
     //返情率
     @Override
     public void getReEstrusRate() {
         String token = getToken();
-        JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName + "/getReEstrusRate?startDate="+startDate+"&endDate="+endDate+"&accessToken="+token
-                ,JSONObject.class );
+        JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName + "/getReEstrusRate?startDate=" + startDate + "&endDate=" + endDate + "&accessToken=" + token
+                , JSONObject.class);
         String data = jsonObject.getString("data");
-        if (data == null){
+        if (data == null) {
             return;
         }
 
-        String reestrus_rate ="0.00000";
-        List<Map<String,String>> list =  (List<Map<String,String>> ) JSON.parse(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");
+                if (farm != null && farm.contains("海盐")) {
+                    reestrus_rate = stringStringMap.get("reestrus_rate");
                 }
             }
         }
@@ -97,37 +100,91 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 
     }
 
+    /**
+     * @Method : getConceptionRate
+     * @Description : 读取受胎率
+     * @Params : []
+     * @Return : void
+     * @Author : ZhuoNing
+     * @Date : 2021/5/17
+     * @Time : 17:38
+     */
+    @Override
+    public void getConceptionRate() {
+        String token = getToken();
+        JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName + "/getConceptionRate?startDate=" + startDate + "&endDate=" + endDate + "&accessToken=" + token
+                , JSONObject.class);
+        String data = jsonObject.getString("data");
+        if (data == null) {
+            return;
+        }
+        log.info("filterFarm: " + filterFarm);
+        // 过滤海盐数据
+        String conceptionRate = "0.00";
+        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(filterFarm)) {
+                    conceptionRate = stringStringMap.get("conception_rate");
+                }
+            }
+        }
+        log.info("返回结果 conceptionRate: " + conceptionRate);
+        IndexParameter queryIndexParameter = new IndexParameter();
+        queryIndexParameter.setName("受胎率");
+        Example<IndexParameter> example = Example.of(queryIndexParameter);
+        Optional<IndexParameter> indexParameterOptional = parameterRepository.findOne(example);
+        log.info("isPresent=" + indexParameterOptional.isPresent());
+        if (indexParameterOptional.isPresent()) {
+          // 更新数据
+            IndexParameter indexParameterData = indexParameterOptional.get();
+            IndexParameter indexParameter = new IndexParameter();
+            indexParameter.setId(indexParameterData.getId());
+            indexParameter.setName("受胎率");
+            indexParameter.setData(conceptionRate);
+            indexParameter.setCreateTime(indexParameterData.getCreateTime());
+            indexParameter.setUpdateTime(indexParameterData.getUpdateTime());
+            indexParameter.setCheckParameter(indexParameterData.getCheckParameter());
+            parameterRepository.save(indexParameter);
+        } else {
+            // 新建新数据
+            IndexParameter indexParameter = new IndexParameter();
+            indexParameter.setName("受胎率");
+            indexParameter.setData(conceptionRate);
+            indexParameter.setCheckParameter(false);
+            parameterRepository.save(indexParameter);
+        }
+    }
 
-    private String getToken(){
+    private String getToken() {
         JSONObject token = template.getForObject("http://192.168.1.62:9100/token/getToken?userId=20210501&timestamp=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&timestamp=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 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);
+        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");
+                if (farm != null && farm.contains("海盐")) {
+                    reestrus_rate = stringStringMap.get("reestrus_rate");
                 }
             }
         }
 
 
-
     }
 }

+ 2 - 1
huimv-hy-production/huimv.hy.autoGetData/src/main/resources/application.properties

@@ -4,4 +4,5 @@ erp.datasource.startDate=2020.1.1
 erp.datasource.endDate=2021.12.31
 erp.datasource.apiIp=http://192.168.1.62
 erp.datasource.apiPort=:9100
-erp.datasource.serviceName=/erpData
+erp.datasource.serviceName=/erpData
+#erp.datasource.filterFarm=º£ÑÎ