Просмотр исходного кода

优化从生产接口取数和数据入库功能。

zhuoning 3 лет назад
Родитель
Сommit
b7db5ac5b1

+ 41 - 3
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/config/SaticScheduleTask.java

@@ -102,22 +102,60 @@ public class SaticScheduleTask  {
         return iAutoGetErpData.findAll();
     }
 
-//    @Scheduled(cron = "60 * * * * ? ")
+    //
+    @Scheduled(cron = "0 0/2 * * * ?")
     private void getManyFarmProduce() throws IOException {
         //获取多牧场生产数
         iAutoGetErpData.getManyFarmProduce();
     }
 
-    //    @Scheduled(cron = "60 * * * * ? ")
+    //ok
+//    @Scheduled(cron = "0 0/60 * * * ?")
     private void getManyFarmStock() throws IOException {
         //获取多牧场存栏
         iAutoGetErpData.getManyFarmStock();
     }
 
-    //    @Scheduled(cron = "60 * * * * ? ")
+    //ok
+//    @Scheduled(cron = "0 0/60 * * * ?")
     private void getCostWithManyFarm() throws IOException, ParseException {
         //获取多牧场生产成本
         iAutoGetErpData.getCostWithManyFarm();
     }
 
+    // ok
+//    @Scheduled(cron = "0 0/60 * * * ?")
+    private void getWarningMessage() throws IOException, ParseException {
+        //获取预警信息
+        iAutoGetErpData.getWarningMessage();
+    }
+
+    //ok
+//    @Scheduled(cron = "0 0/60 * * * ?")
+    private void getWorkPlan() throws IOException, ParseException {
+        //工作计划
+        iAutoGetErpData.getWorkPlan();
+    }
+
+    //ok
+//    @Scheduled(cron = "0 0/60 * * * ?")
+    private void getPrepareStatusQuantity() throws IOException, ParseException {
+        //获取各种准备状态数量
+        iAutoGetErpData.getPrepareStatusQuantity();
+    }
+
+    //ok
+//    @Scheduled(cron = "0 0/60 * * * ?")
+    private void getPayable() throws IOException, ParseException {
+        //应付排名
+        iAutoGetErpData.getPayable();
+    }
+
+    //ok
+//    @Scheduled(cron = "0 0/60 * * * ?")
+    private void getSales() throws IOException, ParseException {
+        System.out.println("");
+        //读取销售数据
+        iAutoGetErpData.getSales();
+    }
 }

+ 24 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/entity/ProdFarmNameEntity.java

@@ -26,6 +26,12 @@ public class ProdFarmNameEntity implements Serializable {
     @Column(name = "erp_short_name")
     private String erpShortName;
 
+    @Column(name = "erp_farm_id")
+    private String erpFarmId;
+
+    @Column(name = "erp_warn_farm_name")
+    private String erpWarnFarmName;
+
     public void setId(Integer id) {
         this.id = id;
     }
@@ -66,6 +72,22 @@ public class ProdFarmNameEntity implements Serializable {
         return erpShortName;
     }
 
+    public void setErpFarmId(String erpFarmId) {
+        this.erpFarmId = erpFarmId;
+    }
+
+    public String getErpFarmId() {
+        return erpFarmId;
+    }
+
+    public void setErpWarnFarmName(String erpWarnFarmName) {
+        this.erpWarnFarmName = erpWarnFarmName;
+    }
+
+    public String getErpWarnFarmName() {
+        return erpWarnFarmName;
+    }
+
     @Override
     public String toString() {
         return "ProdFarmNameEntity{" +
@@ -74,6 +96,8 @@ public class ProdFarmNameEntity implements Serializable {
                 "farmId=" + farmId + '\'' +
                 "erpFarmName=" + erpFarmName + '\'' +
                 "erpShortName=" + erpShortName + '\'' +
+                "erpFarmId=" + erpFarmId + '\'' +
+                "erpWarnFarmName=" + erpWarnFarmName + '\'' +
                 '}';
     }
 }

+ 199 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/entity/ProdProduceEntity.java

@@ -0,0 +1,199 @@
+package com.huimv.production.autoGetData.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+
+@Entity
+@Table(name = "prod_produce")
+public class ProdProduceEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    /**
+     * 存栏类型
+     */
+    @Column(name = "stock_type")
+    private String stockType;
+
+    /**
+     * 存栏名称
+     */
+    @Column(name = "stock_name")
+    private String stockName;
+
+    /**
+     * 存栏数量
+     */
+    @Column(name = "stock_quantity")
+    private String stockQuantity;
+
+    /**
+     * 占比
+     */
+    @Column(name = "rate")
+    private Float rate;
+
+    /**
+     * 月份
+     */
+    @Column(name = "month")
+    private Integer month;
+
+    /**
+     * 年份
+     */
+    @Column(name = "year")
+    private Integer year;
+
+    /**
+     * 牧场id
+     */
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    /**
+     * 分区id
+     */
+    @Column(name = "subarea_id")
+    private Integer subareaId;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    /**
+     * 存栏类型
+     */
+    public void setStockType(String stockType) {
+        this.stockType = stockType;
+    }
+
+    /**
+     * 存栏类型
+     */
+    public String getStockType() {
+        return stockType;
+    }
+
+    /**
+     * 存栏名称
+     */
+    public void setStockName(String stockName) {
+        this.stockName = stockName;
+    }
+
+    /**
+     * 存栏名称
+     */
+    public String getStockName() {
+        return stockName;
+    }
+
+    /**
+     * 存栏数量
+     */
+    public void setStockQuantity(String stockQuantity) {
+        this.stockQuantity = stockQuantity;
+    }
+
+    /**
+     * 存栏数量
+     */
+    public String getStockQuantity() {
+        return stockQuantity;
+    }
+
+    /**
+     * 占比
+     */
+    public void setRate(Float rate) {
+        this.rate = rate;
+    }
+
+    /**
+     * 占比
+     */
+    public Float getRate() {
+        return rate;
+    }
+
+    /**
+     * 月份
+     */
+    public void setMonth(Integer month) {
+        this.month = month;
+    }
+
+    /**
+     * 月份
+     */
+    public Integer getMonth() {
+        return month;
+    }
+
+    /**
+     * 年份
+     */
+    public void setYear(Integer year) {
+        this.year = year;
+    }
+
+    /**
+     * 年份
+     */
+    public Integer getYear() {
+        return year;
+    }
+
+    /**
+     * 牧场id
+     */
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    /**
+     * 牧场id
+     */
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    /**
+     * 分区id
+     */
+    public void setSubareaId(Integer subareaId) {
+        this.subareaId = subareaId;
+    }
+
+    /**
+     * 分区id
+     */
+    public Integer getSubareaId() {
+        return subareaId;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdProduceEntity{" +
+                "id=" + id + '\'' +
+                "stockType=" + stockType + '\'' +
+                "stockName=" + stockName + '\'' +
+                "stockQuantity=" + stockQuantity + '\'' +
+                "rate=" + rate + '\'' +
+                "month=" + month + '\'' +
+                "year=" + year + '\'' +
+                "farmId=" + farmId + '\'' +
+                "subareaId=" + subareaId + '\'' +
+                '}';
+    }
+}

+ 9 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/repo/ProdProduceRepo.java

@@ -0,0 +1,9 @@
+package com.huimv.production.autoGetData.repo;
+
+import com.huimv.production.autoGetData.entity.ProdProduceEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+
+public interface ProdProduceRepo extends JpaRepository<ProdProduceEntity, Integer>, JpaSpecificationExecutor<ProdProduceEntity> {
+
+}

+ 162 - 160
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -91,6 +91,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         JSONObject jsonObject = template.getForObject(apiIp + apiPort + serviceName + "/getPsy?startDate=" + startDate + "&endDate=" + endDate + "&accessToken=" + token
                 , JSONObject.class);
         String data = jsonObject.getString("data");
+        System.out.println("data>>"+data);
         if (data == null) {
             return;
         }
@@ -420,6 +421,9 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         return list;
     }
 
+    @Autowired
+    private ProdProduceRepo produceRepo;
+
     @Override
     public void getManyFarmProduce() throws IOException {
         String startDate;
@@ -465,76 +469,75 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 
                     //删除旧数据
                     //删除产房成活率
-                    ProdStockEntity delStockEntity1 = new ProdStockEntity();
-                    delStockEntity1.setYear(Integer.parseInt(year));
-                    delStockEntity1.setMonth(Integer.parseInt(month));
-                    delStockEntity1.setStockType("grice_rate");
-                    Example<ProdStockEntity> example1 = Example.of(delStockEntity1);
-//                    prodStockRepo.delete(prodStockRepo.findOne(example10).get());
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example1));
+                    ProdProduceEntity delEntity1 = new ProdProduceEntity();
+                    delEntity1.setYear(Integer.parseInt(year));
+                    delEntity1.setMonth(Integer.parseInt(month));
+                    delEntity1.setStockType("grice_rate");
+                    Example<ProdProduceEntity> example1 = Example.of(delEntity1);
+                    produceRepo.deleteAll(produceRepo.findAll(example1));
                     //删除保育成活率
-                    ProdStockEntity delStockEntity2 = new ProdStockEntity();
-                    delStockEntity2.setYear(Integer.parseInt(year));
-                    delStockEntity2.setMonth(Integer.parseInt(month));
-                    delStockEntity2.setStockType("piglet_rate");
-                    Example<ProdStockEntity> example2 = Example.of(delStockEntity2);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example2));
+                    ProdProduceEntity delEntity2 = new ProdProduceEntity();
+                    delEntity2.setYear(Integer.parseInt(year));
+                    delEntity2.setMonth(Integer.parseInt(month));
+                    delEntity2.setStockType("piglet_rate");
+                    Example<ProdProduceEntity> example2 = Example.of(delEntity2);
+                    produceRepo.deleteAll(produceRepo.findAll(example2));
                     //删除育肥成活率
-                    ProdStockEntity delStockEntity3 = new ProdStockEntity();
-                    delStockEntity3.setYear(Integer.parseInt(year));
-                    delStockEntity3.setMonth(Integer.parseInt(month));
-                    delStockEntity3.setStockType("fatpig_rate");
-                    Example<ProdStockEntity> example3 = Example.of(delStockEntity3);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example3));
+                    ProdProduceEntity delEntity3 = new ProdProduceEntity();
+                    delEntity3.setYear(Integer.parseInt(year));
+                    delEntity3.setMonth(Integer.parseInt(month));
+                    delEntity3.setStockType("fatpig_rate");
+                    Example<ProdProduceEntity> example3 = Example.of(delEntity3);
+                    produceRepo.deleteAll(produceRepo.findAll(example3));
                     //删除7日内断配率
-                    ProdStockEntity delStockEntity4 = new ProdStockEntity();
-                    delStockEntity4.setYear(Integer.parseInt(year));
-                    delStockEntity4.setMonth(Integer.parseInt(month));
-                    delStockEntity4.setStockType("break_rate");
-                    Example<ProdStockEntity> example4 = Example.of(delStockEntity4);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example4));
+                    ProdProduceEntity delEntity4 = new ProdProduceEntity();
+                    delEntity4.setYear(Integer.parseInt(year));
+                    delEntity4.setMonth(Integer.parseInt(month));
+                    delEntity4.setStockType("break_rate");
+                    Example<ProdProduceEntity> example4 = Example.of(delEntity4);
+                    produceRepo.deleteAll(produceRepo.findAll(example4));
                     //删除平均窝产仔猪
-                    ProdStockEntity delStockEntity5 = new ProdStockEntity();
-                    delStockEntity5.setYear(Integer.parseInt(year));
-                    delStockEntity5.setMonth(Integer.parseInt(month));
-                    delStockEntity5.setStockType("avg_farrow_1");
-                    Example<ProdStockEntity> example5 = Example.of(delStockEntity5);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example5));
+                    ProdProduceEntity delEntity5 = new ProdProduceEntity();
+                    delEntity5.setYear(Integer.parseInt(year));
+                    delEntity5.setMonth(Integer.parseInt(month));
+                    delEntity5.setStockType("avg_farrow_1");
+                    Example<ProdProduceEntity> example5 = Example.of(delEntity5);
+                    produceRepo.deleteAll(produceRepo.findAll(example5));
                     //删除平均窝产活仔数
-                    ProdStockEntity delStockEntity6 = new ProdStockEntity();
-                    delStockEntity6.setYear(Integer.parseInt(year));
-                    delStockEntity6.setMonth(Integer.parseInt(month));
-                    delStockEntity6.setStockType("avg_farrow_2");
-                    Example<ProdStockEntity> example6 = Example.of(delStockEntity6);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example6));
+                    ProdProduceEntity delEntity6 = new ProdProduceEntity();
+                    delEntity6.setYear(Integer.parseInt(year));
+                    delEntity6.setMonth(Integer.parseInt(month));
+                    delEntity6.setStockType("avg_farrow_2");
+                    Example<ProdProduceEntity> example6 = Example.of(delEntity6);
+                    produceRepo.deleteAll(produceRepo.findAll(example6));
                     //删除平均窝产正常仔数
-                    ProdStockEntity delStockEntity7 = new ProdStockEntity();
-                    delStockEntity7.setYear(Integer.parseInt(year));
-                    delStockEntity7.setMonth(Integer.parseInt(month));
-                    delStockEntity7.setStockType("avg_farrow_3");
-                    Example<ProdStockEntity> example7 = Example.of(delStockEntity7);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example7));
+                    ProdProduceEntity delEntity7 = new ProdProduceEntity();
+                    delEntity7.setYear(Integer.parseInt(year));
+                    delEntity7.setMonth(Integer.parseInt(month));
+                    delEntity7.setStockType("avg_farrow_3");
+                    Example<ProdProduceEntity> example7 = Example.of(delEntity7);
+                    produceRepo.deleteAll(produceRepo.findAll(example7));
                     //删除窝断奶仔猪数
-                    ProdStockEntity delStockEntity8 = new ProdStockEntity();
-                    delStockEntity8.setYear(Integer.parseInt(year));
-                    delStockEntity8.setMonth(Integer.parseInt(month));
-                    delStockEntity8.setStockType("break_grice");
-                    Example<ProdStockEntity> example8 = Example.of(delStockEntity8);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example8));
+                    ProdProduceEntity delEntity8 = new ProdProduceEntity();
+                    delEntity8.setYear(Integer.parseInt(year));
+                    delEntity8.setMonth(Integer.parseInt(month));
+                    delEntity8.setStockType("break_grice");
+                    Example<ProdProduceEntity> example8 = Example.of(delEntity8);
+                    produceRepo.deleteAll(produceRepo.findAll(example8));
                     //删除平均窝断奶重
-                    ProdStockEntity delStockEntity9 = new ProdStockEntity();
-                    delStockEntity9.setYear(Integer.parseInt(year));
-                    delStockEntity9.setMonth(Integer.parseInt(month));
-                    delStockEntity9.setStockType("avg_weight");
-                    Example<ProdStockEntity> example9 = Example.of(delStockEntity9);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example9));
+                    ProdProduceEntity delEntity9 = new ProdProduceEntity();
+                    delEntity9.setYear(Integer.parseInt(year));
+                    delEntity9.setMonth(Integer.parseInt(month));
+                    delEntity9.setStockType("avg_weight");
+                    Example<ProdProduceEntity> example9 = Example.of(delEntity9);
+                    produceRepo.deleteAll(produceRepo.findAll(example9));
                     //删除产房成活率
-                    ProdStockEntity delStockEntity10 = new ProdStockEntity();
-                    delStockEntity10.setYear(Integer.parseInt(year));
-                    delStockEntity10.setMonth(Integer.parseInt(month));
-                    delStockEntity10.setStockType("nest_times");
-                    Example<ProdStockEntity> example10 = Example.of(delStockEntity10);
-                    prodStockRepo.deleteAll(prodStockRepo.findAll(example10));
+                    ProdProduceEntity delEntity10 = new ProdProduceEntity();
+                    delEntity10.setYear(Integer.parseInt(year));
+                    delEntity10.setMonth(Integer.parseInt(month));
+                    delEntity10.setStockType("nest_times");
+                    Example<ProdProduceEntity> example10 = Example.of(delEntity10);
+                    produceRepo.deleteAll(produceRepo.findAll(example10));
                     // 添加入库
                     for (int a = 0; a < dataJa.size(); a++) {
                         JSONObject dataJo = dataJa.getJSONObject(a);
@@ -547,142 +550,141 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                         if (cfchl == null || cfchl.trim().length() == 0) {
                             cfchl = "0";
                         }
-                        ProdStockEntity stockEntity1 = new ProdStockEntity();
-                        stockEntity1.setFarmId(farmId);
-                        stockEntity1.setStockType("grice_rate");
-                        stockEntity1.setStockName("产房成活率");
-                        stockEntity1.setStockQuantity(mathUtil.countRate(Float.parseFloat(cfchl), 1));
-//                    stockEntity1.setRate();
-                        stockEntity1.setMonth(Integer.valueOf(month));
-                        stockEntity1.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity1);
+                        ProdProduceEntity addEntity1 = new ProdProduceEntity();
+                        addEntity1.setFarmId(farmId);
+                        addEntity1.setStockType("grice_rate");
+                        addEntity1.setStockName("产房成活率");
+                        addEntity1.setStockQuantity(mathUtil.countRate(Float.parseFloat(cfchl), 1));
+                        addEntity1.setMonth(Integer.valueOf(month));
+                        addEntity1.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity1);
 
                         //保育成活率
                         String bychl = dataJo.getString("bychl");
                         if (bychl == null || bychl.trim().length() == 0) {
                             bychl = "0";
                         }
-                        ProdStockEntity stockEntity2 = new ProdStockEntity();
-                        stockEntity2.setFarmId(farmId);
-                        stockEntity2.setStockType("piglet_rate");
-                        stockEntity2.setStockName("保育成活率");
-                        stockEntity2.setStockQuantity(mathUtil.countRate(Float.parseFloat(bychl), 1));
+                        ProdProduceEntity addEntity2 = new ProdProduceEntity();
+                        addEntity2.setFarmId(farmId);
+                        addEntity2.setStockType("piglet_rate");
+                        addEntity2.setStockName("保育成活率");
+                        addEntity2.setStockQuantity(mathUtil.countRate(Float.parseFloat(bychl), 1));
 //                    stockEntity2.setRate();
-                        stockEntity2.setMonth(Integer.valueOf(month));
-                        stockEntity2.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity2);
+                        addEntity2.setMonth(Integer.valueOf(month));
+                        addEntity2.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity2);
                         //肥猪成活率
                         String fzchl = dataJo.getString("fzchl");
                         if (fzchl == null || fzchl.trim().length() == 0) {
                             fzchl = "0";
                         }
-                        ProdStockEntity stockEntity3 = new ProdStockEntity();
-                        stockEntity3.setFarmId(farmId);
-                        stockEntity3.setStockType("fatpig_rate");
-                        stockEntity3.setStockName("肥猪成活率");
-                        stockEntity3.setStockQuantity(mathUtil.countRate(Float.parseFloat(fzchl), 1));
-//                    stockEntity3.setRate();
-                        stockEntity3.setMonth(Integer.valueOf(month));
-                        stockEntity3.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity3);
+                        ProdProduceEntity addEntity3 = new ProdProduceEntity();
+                        addEntity3.setFarmId(farmId);
+                        addEntity3.setStockType("fatpig_rate");
+                        addEntity3.setStockName("肥猪成活率");
+                        addEntity3.setStockQuantity(mathUtil.countRate(Float.parseFloat(fzchl), 1));
+//                    addEntity3.setRate();
+                        addEntity3.setMonth(Integer.valueOf(month));
+                        addEntity3.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity3);
                         //平均窝产仔猪
                         String pjwczz = dataJo.getString("pjwczz");
                         if (pjwczz == null || pjwczz.trim().length() == 0) {
                             pjwczz = "0";
                         }
-                        ProdStockEntity stockEntity4 = new ProdStockEntity();
-                        stockEntity4.setFarmId(farmId);
-                        stockEntity4.setStockType("avg_farrow_1");
-                        stockEntity4.setStockName("平均窝产仔猪");
-                        stockEntity4.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjwczz), 1));
-//                    stockEntity4.setRate();
-                        stockEntity4.setMonth(Integer.valueOf(month));
-                        stockEntity4.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity4);
+                        ProdProduceEntity addEntity4 = new ProdProduceEntity();
+                        addEntity4.setFarmId(farmId);
+                        addEntity4.setStockType("avg_farrow_1");
+                        addEntity4.setStockName("平均窝产仔猪");
+                        addEntity4.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjwczz), 1));
+//                    addEntity4.setRate();
+                        addEntity4.setMonth(Integer.valueOf(month));
+                        addEntity4.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity4);
                         //平均窝产活仔数
                         String pjwchzs = dataJo.getString("pjwchzs");
                         if (pjwchzs == null || pjwchzs.trim().length() == 0) {
                             pjwchzs = "0";
                         }
-                        ProdStockEntity stockEntity5 = new ProdStockEntity();
-                        stockEntity5.setFarmId(farmId);
-                        stockEntity5.setStockType("avg_farrow_2");
-                        stockEntity5.setStockName("平均窝产活仔数");
-                        stockEntity5.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjwchzs), 1));
-//                    stockEntity5.setRate();
-                        stockEntity5.setMonth(Integer.valueOf(month));
-                        stockEntity5.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity5);
+                        ProdProduceEntity addEntity5 = new ProdProduceEntity();
+                        addEntity5.setFarmId(farmId);
+                        addEntity5.setStockType("avg_farrow_2");
+                        addEntity5.setStockName("平均窝产活仔数");
+                        addEntity5.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjwchzs), 1));
+//                    addEntity5.setRate();
+                        addEntity5.setMonth(Integer.valueOf(month));
+                        addEntity5.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity5);
                         //平均窝产正常仔数
                         String pjwczczs = dataJo.getString("pjwczczs");
                         if (pjwczczs == null || pjwczczs.trim().length() == 0) {
                             pjwczczs = "0";
                         }
-                        ProdStockEntity stockEntity6 = new ProdStockEntity();
-                        stockEntity6.setFarmId(farmId);
-                        stockEntity6.setStockType("avg_farrow_3");
-                        stockEntity6.setStockName("平均窝产正常仔数");
-                        stockEntity6.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjwczczs), 1));
-//                    stockEntity6.setRate();
-                        stockEntity6.setMonth(Integer.valueOf(month));
-                        stockEntity6.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity6);
+                        ProdProduceEntity addEntity6 = new ProdProduceEntity();
+                        addEntity6.setFarmId(farmId);
+                        addEntity6.setStockType("avg_farrow_3");
+                        addEntity6.setStockName("平均窝产正常仔数");
+                        addEntity6.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjwczczs), 1));
+//                    addEntity6.setRate();
+                        addEntity6.setMonth(Integer.valueOf(month));
+                        addEntity6.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity6);
                         //窝断奶仔猪数
                         String wdnzzs = dataJo.getString("wdnzzs");
                         if (wdnzzs == null || wdnzzs.trim().length() == 0) {
                             wdnzzs = "0";
                         }
-                        ProdStockEntity stockEntity7 = new ProdStockEntity();
-                        stockEntity7.setFarmId(farmId);
-                        stockEntity7.setStockType("break_grice");
-                        stockEntity7.setStockName("窝断奶仔猪数");
-                        stockEntity7.setStockQuantity(mathUtil.countRate(Float.parseFloat(wdnzzs), 1));
-//                    stockEntity7.setRate();
-                        stockEntity7.setMonth(Integer.valueOf(month));
-                        stockEntity7.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity7);
+                        ProdProduceEntity addEntity7 = new ProdProduceEntity();
+                        addEntity7.setFarmId(farmId);
+                        addEntity7.setStockType("break_grice");
+                        addEntity7.setStockName("窝断奶仔猪数");
+                        addEntity7.setStockQuantity(mathUtil.countRate(Float.parseFloat(wdnzzs), 1));
+//                    addEntity7.setRate();
+                        addEntity7.setMonth(Integer.valueOf(month));
+                        addEntity7.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity7);
                         //平均断奶窝重
                         String pjdnwz = dataJo.getString("pjdnwz");
                         if (pjdnwz == null || pjdnwz.trim().length() == 0) {
                             pjdnwz = "0";
                         }
-                        ProdStockEntity stockEntity8 = new ProdStockEntity();
-                        stockEntity8.setFarmId(farmId);
-                        stockEntity8.setStockType("avg_weight");
-                        stockEntity8.setStockName("平均断奶窝重");
-                        stockEntity8.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjdnwz), 1));
-//                    stockEntity8.setRate();
-                        stockEntity8.setMonth(Integer.valueOf(month));
-                        stockEntity8.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity8);
+                        ProdProduceEntity addEntity8 = new ProdProduceEntity();
+                        addEntity8.setFarmId(farmId);
+                        addEntity8.setStockType("avg_weight");
+                        addEntity8.setStockName("平均断奶窝重");
+                        addEntity8.setStockQuantity(mathUtil.countRate(Float.parseFloat(pjdnwz), 1));
+//                    addEntity8.setRate();
+                        addEntity8.setMonth(Integer.valueOf(month));
+                        addEntity8.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity8);
                         //7日断配率
                         String dpl7r = dataJo.getString("7rdpl");
                         if (dpl7r == null || dpl7r.trim().length() == 0) {
                             dpl7r = "0";
                         }
-                        ProdStockEntity stockEntity9 = new ProdStockEntity();
-                        stockEntity9.setFarmId(farmId);
-                        stockEntity9.setStockType("break_rate");
-                        stockEntity9.setStockName("7日断配率");
-                        stockEntity9.setStockQuantity(mathUtil.countRate(Float.parseFloat(dpl7r), 1));
-//                    stockEntity9.setRate();
-                        stockEntity9.setMonth(Integer.valueOf(month));
-                        stockEntity9.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity9);
+                        ProdProduceEntity addEntity9 = new ProdProduceEntity();
+                        addEntity9.setFarmId(farmId);
+                        addEntity9.setStockType("break_rate");
+                        addEntity9.setStockName("7日断配率");
+                        addEntity9.setStockQuantity(mathUtil.countRate(Float.parseFloat(dpl7r), 1));
+//                    addEntity9.setRate();
+                        addEntity9.setMonth(Integer.valueOf(month));
+                        addEntity9.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity9);
                         //年产窝数
                         String ncws = dataJo.getString("ncws");
                         if (ncws == null || ncws.length() == 0) {
                             ncws = "0";
                         }
-                        ProdStockEntity stockEntity10 = new ProdStockEntity();
-                        stockEntity10.setFarmId(farmId);
-                        stockEntity10.setStockType("nest_times");
-                        stockEntity10.setStockName("年产窝数");
-                        stockEntity10.setStockQuantity(mathUtil.countRate(Float.parseFloat(ncws), 1));
-//                    stockEntity10.setRate();
-                        stockEntity10.setMonth(Integer.valueOf(month));
-                        stockEntity10.setYear(Integer.parseInt(year));
-                        prodStockRepo.saveAndFlush(stockEntity10);
+                        ProdProduceEntity addEntity10 = new ProdProduceEntity();
+                        addEntity10.setFarmId(farmId);
+                        addEntity10.setStockType("nest_times");
+                        addEntity10.setStockName("年产窝数");
+                        addEntity10.setStockQuantity(mathUtil.countRate(Float.parseFloat(ncws), 1));
+//                    addEntity10.setRate();
+                        addEntity10.setMonth(Integer.valueOf(month));
+                        addEntity10.setYear(Integer.parseInt(year));
+                        produceRepo.saveAndFlush(addEntity10);
                     }
                 }
             } else {
@@ -857,7 +859,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                     // 添加入库
                     for (int a = 0; a < dataJa.size(); a++) {
                         JSONObject dataJo = dataJa.getJSONObject(a);
-                        System.out.println((a + 1) + " " + dataJo);
+                        //
                         int farmId = _getFarmIdByShortName(dataJo.getString("mcmc"), farmNameEntityList);
                         int mz = dataJo.getInteger("mz");
                         int gz = dataJo.getInteger("gz");
@@ -865,7 +867,6 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                         int by = dataJo.getInteger("by");
                         int yf = dataJo.getInteger("yf");
                         int total = mz + gz + zz + by + yf;
-                        System.out.println("farmId=" + farmId + ",total=" + total);
                         //母猪存栏
                         ProdStockEntity stockEntity1 = new ProdStockEntity();
                         stockEntity1.setFarmId(farmId);
@@ -944,7 +945,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                         stockEntity8.setMonth(Integer.valueOf(month));
                         stockEntity8.setYear(Integer.parseInt(year));
                         prodStockRepo.saveAndFlush(stockEntity8);
-                        //空怀
+                        //空怀(包含返情)
                         ProdStockEntity stockEntity9 = new ProdStockEntity();
                         stockEntity9.setFarmId(farmId);
                         stockEntity9.setStockType("sow_stock_3");
@@ -953,8 +954,6 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                         stockEntity9.setMonth(Integer.valueOf(month));
                         stockEntity9.setYear(Integer.parseInt(year));
                         prodStockRepo.saveAndFlush(stockEntity9);
-                        //返情
-
                         //后备
                         ProdStockEntity stockEntity10 = new ProdStockEntity();
                         stockEntity10.setFarmId(farmId);
@@ -1129,6 +1128,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                     newWarningMsgEntity.setTipTime(dateUtil.formatDateTime(dataJo.getString("tsrq")));
                     newWarningMsgEntity.setFarmName(pigfarm);
                     newWarningMsgEntity.setWarningContent(message);
+                    //
                     newWarningMsgEntity.setFarmId(_getFarmId(pigfarm, farmNameEntityList));
                     newWarningMsgEntity.setAddTime(new Timestamp(new Date().getTime()));
                     newWarningMsgEntity.setHandleState(0);
@@ -1144,12 +1144,11 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 
     //读取ERP数据中对应的名称
     private int _getFarmId(String pigfarm, List<ProdFarmNameEntity> farmNameEntityList) {
-        System.out.println("pigfarm=" + pigfarm);
         //
         int farmId = 0;
         boolean isExist = false;
         for (ProdFarmNameEntity prodFarmNameEntity : farmNameEntityList) {
-            if (prodFarmNameEntity.getErpShortName() != null && prodFarmNameEntity.getErpShortName().indexOf(pigfarm) != -1) {
+            if (prodFarmNameEntity.getErpShortName() != null && (prodFarmNameEntity.getErpShortName().indexOf(pigfarm) != -1 || pigfarm.equalsIgnoreCase(prodFarmNameEntity.getErpWarnFarmName()))) {
                 farmId = prodFarmNameEntity.getFarmId();
                 isExist = true;
                 break;
@@ -1161,6 +1160,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         return farmId;
     }
 
+
     @Override
     public void getWorkPlan() throws IOException, ParseException {
         //
@@ -1230,7 +1230,7 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
         paramsMap.put("accessToken", token);
 
         String url = apiIp + apiPort + serviceName + "/getPrepareStatusQuantity";
-        log.info("获取工作计划数据访问地址=" + url);
+        log.info("获取母猪和仔猪各种状态数据访问地址=" + url);
         log.info("业务请求参数=" + paramsMap.toString());
         log.info("开始取数=" + new Date(System.currentTimeMillis()));
         //
@@ -1362,10 +1362,12 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
                     //获取牧场所有名称数据
                     for (int a = 0; a < dataJa.size(); a++) {
                         JSONObject dataJo = dataJa.getJSONObject(a);
+                        System.out.println("dataJ>>"+dataJo);
                         ProdSalesEntity addSalesEntity = new ProdSalesEntity();
-                        addSalesEntity.setFarmName(dataJo.getString("mcmc"));
+                        String farmName = dataJo.getString("farm_name");
+                        addSalesEntity.setFarmName(farmName);
                         //
-                        addSalesEntity.setFarmId(_getFarmIdByShortName(dataJo.getString("mcmc"), farmNameEntityList));
+                        addSalesEntity.setFarmId(_getFarmIdByShortName(farmName, farmNameEntityList));
                         addSalesEntity.setTodayMoney(dataJo.getString("today_money"));
                         addSalesEntity.setTodayQuantity(dataJo.getString("today_quantity"));
                         addSalesEntity.setTodayWeight(dataJo.getString("today_weight"));

+ 6 - 0
huimv-hy-production/huimv.hy.autoGetData/src/test/java/com/huimv/production/autoGetData/utils/AutoGetDataTEst.java

@@ -85,4 +85,10 @@ public class AutoGetDataTEst {
         autoGetErpData.getSales();
     }
 
+    @Test
+    public void testPsy(){
+        //
+        autoGetErpData.getPsy();
+    }
+
 }