Explorar el Código

加入远程获取

523096025 hace 4 años
padre
commit
8d11c9ff8a

+ 1 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/HuimvHyAutoGetDataApplication.java

@@ -2,6 +2,7 @@ package com.huimv.production.autoGetData;
 
 import org.springframework.boot.SpringApplication;
 import org.springframework.boot.autoconfigure.SpringBootApplication;
+import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.context.annotation.Bean;
 import org.springframework.scheduling.annotation.EnableScheduling;
 import org.springframework.web.client.RestTemplate;

+ 13 - 8
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/config/SaticScheduleTask.java

@@ -38,22 +38,22 @@ public class SaticScheduleTask  {
 
 
 //    @Scheduled(cron = "0/5 * * * * ?")
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0/10 * * * ? ")
     private void getPsyTask(){
         System.err.println("执行 getPsyTask 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getPsy();
     }
 
+
 //    @Scheduled(cron = "* 0/5 * * * ?")
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0/10 * * * ? ")
     private void getReEstrusRate(){
         System.err.println("执行 getReEstrusRate 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getReEstrusRate();
-
     }
 
 //    @Scheduled(cron = "* 0/5 * * * ?")
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0/10 * * * ? ")
     private void getParturitionRate(){
         System.err.println("执行 getParturitionRate 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getParturitionRate();
@@ -67,25 +67,25 @@ public class SaticScheduleTask  {
     }
 
 
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0/10 * * * ? ")
     private void getPigletInfo(){
         System.err.println("执行 getPigletInfo 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getPigletInfo();
     }
 
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0/10 * * * ? ")
     private void getMateQuantity(){
         System.err.println("执行 getMateQuantity 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getMateQuantity();
     }
 
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0/10 * * * ? ")
     private void getConceptionRate(){
         System.err.println("执行 getConceptionRate 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getConceptionRate();
     }
 
-    @Scheduled(cron = "0 0/1 * * * ? ")
+    @Scheduled(cron = "0 0/10 * * * ? ")
     private void getAllStorage(){
         System.err.println("执行 getAllStorage 执行静态定时任务时间: " + LocalDateTime.now());
         iAutoGetErpData.getAllStorage();
@@ -93,5 +93,10 @@ public class SaticScheduleTask  {
     }
 
 
+    @RequestMapping("/findAll")
+    private List findAll(){
+
+        return iAutoGetErpData.findAll();
+    }
 
 }

+ 29 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/entity/ProductionGroup.java

@@ -0,0 +1,29 @@
+package com.huimv.production.autoGetData.entity;
+
+import lombok.Data;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name = "index_production_group")
+@Data
+public class ProductionGroup implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "variety")
+    private String variety;
+
+    @Column(name = "frequency")
+    private String frequency;
+
+    @Column(name = "production_type")
+    private String productionType;
+
+}

+ 12 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/repo/ProductionGroupRepo.java

@@ -0,0 +1,12 @@
+package com.huimv.production.autoGetData.repo;
+
+import com.huimv.production.autoGetData.entity.ProductionGroup;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+import java.util.List;
+
+public interface ProductionGroupRepo extends JpaRepository<ProductionGroup, Integer>, JpaSpecificationExecutor<ProductionGroup> {
+
+    List<ProductionGroup> findAllByVariety(String variety);
+}

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

@@ -18,4 +18,6 @@ public interface IAutoGetErpData {
     void getConceptionRate();
 
     void getAllStorage();
+
+    List findAll();
 }

+ 101 - 27
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -3,7 +3,9 @@ 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.entity.ProductionGroup;
 import com.huimv.production.autoGetData.repo.IndexParameterRepository;
+import com.huimv.production.autoGetData.repo.ProductionGroupRepo;
 import com.huimv.production.autoGetData.service.IAutoGetErpData;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -39,13 +41,15 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     private RestTemplate template;
     @Autowired
     private IndexParameterRepository parameterRepository;
+    @Autowired
+    private ProductionGroupRepo productionGroupRepo;
 
     //PSY
     @Override
     public void getPsy() {
         String token = getToken();
-        String servicePath = apiIp + apiPort + serviceName;
-        System.out.println("servicePath>>"+servicePath);
+//        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 );
         String data = jsonObject.getString("data");
@@ -75,21 +79,29 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         }
 
         String reestrus_rate ="0.00000";
+        String variety = "";
+        ProductionGroup productionGroup = new ProductionGroup();
+        int i =4;
         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");
+                    variety = stringStringMap.get("variety");
+                    productionGroup.setProductionType("reEstrus");
+                    productionGroup.setVariety(variety);
+                    productionGroup.setId(i);
+                    productionGroup.setFrequency(reestrus_rate);
+                    productionGroupRepo.save(productionGroup);
+                    i++;
                 }
             }
         }
-        IndexParameter indexParameter = parameterRepository.findById(9).get();
-        indexParameter.setData(reestrus_rate);
-        indexParameter.setUpdateTime(new Date());
+
 
         System.out.println("返情率------->"+data);
-        parameterRepository.save(indexParameter);
+
 
     }
 
@@ -104,25 +116,30 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
             return;
         }
 
-        String parturition_rate ="0.00000";
+        String parturitionRate ="0.00000";
+        String variety = "";
+        ProductionGroup productionGroup = new ProductionGroup();
+        int i =1;
         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("海盐")){
-                    parturition_rate  = stringStringMap.get("parturition_rate");
+                    parturitionRate  = stringStringMap.get("parturition_rate");
+                    variety = stringStringMap.get("variety");
+                    productionGroup.setFrequency(parturitionRate);
+                    productionGroup.setId(i);
+                    productionGroup.setProductionType("parturition");
+                    productionGroup.setVariety(variety);
+                    productionGroupRepo.save(productionGroup);
+                    i++;
                 }
             }
         }
-        IndexParameter indexParameter = parameterRepository.findById(12).get();
-        indexParameter.setData(parturition_rate);
-        indexParameter.setUpdateTime(new Date());
-
 
-        System.out.println("分娩率------->"+data);
-        parameterRepository.save(indexParameter);
     }
 
+    //获取各种存栏
     @Override
     public List getStorage() {
         String token = getToken();
@@ -151,7 +168,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
     //获取均产仔数,仔猪存活率
     @Override
     public void getPigletInfo() {
-       /* String token = getToken();
+        String token = getToken();
         JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName +"/getPigletInfo?startDate="+startDate+"&endDate="+endDate+"&accessToken="+token
                 ,JSONObject.class );
         String data = jsonObject.getString("data");
@@ -159,20 +176,40 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
             return;
         }
         //TODO 未完成
-        String parturition_rate ="0.00000";
+        System.out.println("均产仔数,仔猪存活率--->"+data);
+        String birth_number ="0";
+        String total ="0";
+        String dead_quantity ="0";
         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("海盐")){
-                    parturition_rate  = stringStringMap.get("parturition_rate");
+                    birth_number  = stringStringMap.get("birth_number");
+                    total  = stringStringMap.get("total");
+                    dead_quantity  = stringStringMap.get("dead_quantity");
                 }
             }
         }
-        IndexParameter indexParameter = parameterRepository.findById(12).get();
-        indexParameter.setData(parturition_rate);
+
+        //分娩头数
+        IndexParameter indexParameter = parameterRepository.findById(19).get();
+        indexParameter.setData(birth_number);
         indexParameter.setUpdateTime(new Date());
-        parameterRepository.save(indexParameter);*/
+        parameterRepository.save(indexParameter);
+
+
+        //产仔总数
+        IndexParameter indexParameter2 = parameterRepository.findById(20).get();
+        indexParameter2.setData(total);
+        indexParameter2.setUpdateTime(new Date());
+        parameterRepository.save(indexParameter2);
+
+        //仔猪死淘数
+        IndexParameter indexParameter3 = parameterRepository.findById(21).get();
+        indexParameter3.setData(dead_quantity);
+        indexParameter3.setUpdateTime(new Date());
+        parameterRepository.save(indexParameter);
     }
 
     //配种数量
@@ -186,22 +223,29 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
             return;
         }
         String mate_quantity ="0";
+        String variety = "";
+        ProductionGroup productionGroup = new ProductionGroup();
+        int i = 7;
         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("海盐")){
                     mate_quantity  = stringStringMap.get("mate_quantity");
+                    variety = stringStringMap.get("variety");
+                    productionGroup.setId(i);
+                    productionGroup.setFrequency(mate_quantity);
+                    productionGroup.setVariety(variety);
+                    productionGroup.setProductionType("mateQuantity");
+                    productionGroupRepo.save(productionGroup);
+                    i++;
                 }
             }
         }
-        IndexParameter indexParameter = parameterRepository.findById(10).get();
-        indexParameter.setData(mate_quantity);
-        indexParameter.setUpdateTime(new Date());
 
         System.out.println("配种数------->"+data);
 
-        parameterRepository.save(indexParameter);
+
     }
 
     //受胎率
@@ -224,14 +268,14 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                 }
             }
         }
-        IndexParameter indexParameter = parameterRepository.findById(11).get();
+        IndexParameter indexParameter = parameterRepository.findById(18).get();
         indexParameter.setData(conception_rate);
         indexParameter.setUpdateTime(new Date());
 
         System.out.println("受胎率------->"+data);
         parameterRepository.save(indexParameter);
     }
-
+    //总存栏,母猪存栏
     @Override
     public void getAllStorage() {
         String token = getToken();
@@ -262,12 +306,42 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         IndexParameter indexParameter1 = parameterRepository.findById(3).get();
         indexParameter1.setData(sow_quantity);
         indexParameter1.setUpdateTime(new Date());
+        System.out.println("总存栏,母猪存栏------->"+data);
+
         parameterRepository.save(indexParameter);
     }
 
+    @Override
+    public List findAll() {
+        List<ProductionGroup> delivery = productionGroupRepo.findAllByVariety("巴嘉");
+        List<ProductionGroup> reservice = productionGroupRepo.findAllByVariety("杜巴嘉");
+        List<ProductionGroup> breeding = productionGroupRepo.findAllByVariety("金华两头乌");
+        Map map1 = new HashMap();
+        Map map2 = new HashMap();
+        Map map3 = new HashMap();
+        map1.put("veriety","巴嘉");
+        map2.put("veriety","杜巴嘉");
+        map3.put("veriety","金华两头乌");
+        for (ProductionGroup productionGroup : delivery) {
+            map1.put(productionGroup.getProductionType(),productionGroup.getFrequency());
+        }
+        for (ProductionGroup productionGroup : reservice) {
+            map2.put(productionGroup.getProductionType(),productionGroup.getFrequency());
+        }
+        for (ProductionGroup productionGroup : breeding) {
+            map3.put(productionGroup.getProductionType(),productionGroup.getFrequency());
+        }
+
+        List list = new ArrayList();
+        list.add(map1);
+        list.add(map2);
+        list.add(map3);
+        return list;
+    }
+
 
     private String getToken(){
-        JSONObject token = template.getForObject("http://192.168.1.62:9100/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c",
+        JSONObject token = template.getForObject("http://127.0.0.1:9100/token/getToken?userId=20210501&timestamp=45546546454&random=1156&sign=7fa431325504e01e9fa87ed0e274c40c",
                 JSONObject.class);
         return token.getString("accessToken");
 

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

@@ -2,7 +2,7 @@ spring.profiles.active=dev
 
 erp.datasource.startDate=2020.1.1
 erp.datasource.endDate=2021.12.31
-erp.datasource.apiIp=http://192.168.1.62
+erp.datasource.apiIp=http://127.0.0.1
 erp.datasource.apiPort=:9100
 erp.datasource.serviceName=/erpData
 #erp.datasource.filterFarm=º£ÑÎ

+ 2 - 1
huimv-hy-production/huimv.hy.erp.datasource/src/main/java/com/huimv/production/datasource/service/impl/ErpDataServiceImpl.java

@@ -21,7 +21,8 @@ import java.util.List;
 @Service
 @Slf4j
 public class ErpDataServiceImpl implements IErpDataService {
-    private String testFarm = "油车港";
+//    private String testFarm = "油车港";
+    private String testFarm = "海盐";
     @Autowired
     private TDeliveryRepo tDeliveryRepo;
 

+ 1 - 1
huimv-hy-production/huimv.hy.erp.datasource/src/main/resources/application-dev.yml

@@ -5,7 +5,7 @@ spring:
     name: huimv-hy-erp-datasource
   datasource:
     driver-class-name: com.microsoft.sqlserver.jdbc.SQLServerDriver
-    url: jdbc:sqlserver://192.168.1.26:1433;DatabaseName=yz
+    url: jdbc:sqlserver://115.238.57.190:1433;DatabaseName=yz
     username: sa
     password: hm123456@
     maxActive: 20

+ 5 - 0
huimv-hy-production/pom.xml

@@ -79,6 +79,11 @@
     <build>
         <plugins>
             <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-resources-plugin</artifactId>
+                <version>3.1.0</version>
+            </plugin>
+            <plugin>
                 <groupId>org.springframework.boot</groupId>
                 <artifactId>spring-boot-maven-plugin</artifactId>
             </plugin>