Преглед изворни кода

添加从销售接口取数和数据入库功能;

zhuoning пре 3 година
родитељ
комит
e32fd5ad81

+ 176 - 0
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/entity/ProdSalesEntity.java

@@ -0,0 +1,176 @@
+package com.huimv.production.autoGetData.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.util.Date;
+
+@Entity
+@Table(name = "prod_sales")
+public class ProdSalesEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    @Column(name = "farm_name")
+    private String farmName;
+
+    @Column(name = "today_quantity")
+    private String todayQuantity;
+
+    @Column(name = "today_weight")
+    private String todayWeight;
+
+    @Column(name = "today_money")
+    private String todayMoney;
+
+    @Column(name = "week_quantity")
+    private String weekQuantity;
+
+    @Column(name = "week_weight")
+    private String weekWeight;
+
+    @Column(name = "week_money")
+    private String weekMoney;
+
+    @Column(name = "month_quantity")
+    private String monthQuantity;
+
+    @Column(name = "month_weight")
+    private String monthWeight;
+
+    @Column(name = "month_money")
+    private String monthMoney;
+
+    @Column(name = "add_date")
+    private Date addDate;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public void setFarmName(String farmName) {
+        this.farmName = farmName;
+    }
+
+    public String getFarmName() {
+        return farmName;
+    }
+
+    public void setTodayQuantity(String todayQuantity) {
+        this.todayQuantity = todayQuantity;
+    }
+
+    public String getTodayQuantity() {
+        return todayQuantity;
+    }
+
+    public void setTodayWeight(String todayWeight) {
+        this.todayWeight = todayWeight;
+    }
+
+    public String getTodayWeight() {
+        return todayWeight;
+    }
+
+    public void setTodayMoney(String todayMoney) {
+        this.todayMoney = todayMoney;
+    }
+
+    public String getTodayMoney() {
+        return todayMoney;
+    }
+
+    public void setWeekQuantity(String weekQuantity) {
+        this.weekQuantity = weekQuantity;
+    }
+
+    public String getWeekQuantity() {
+        return weekQuantity;
+    }
+
+    public void setWeekWeight(String weekWeight) {
+        this.weekWeight = weekWeight;
+    }
+
+    public String getWeekWeight() {
+        return weekWeight;
+    }
+
+    public void setWeekMoney(String weekMoney) {
+        this.weekMoney = weekMoney;
+    }
+
+    public String getWeekMoney() {
+        return weekMoney;
+    }
+
+    public void setMonthQuantity(String monthQuantity) {
+        this.monthQuantity = monthQuantity;
+    }
+
+    public String getMonthQuantity() {
+        return monthQuantity;
+    }
+
+    public void setMonthWeight(String monthWeight) {
+        this.monthWeight = monthWeight;
+    }
+
+    public String getMonthWeight() {
+        return monthWeight;
+    }
+
+    public void setMonthMoney(String monthMoney) {
+        this.monthMoney = monthMoney;
+    }
+
+    public String getMonthMoney() {
+        return monthMoney;
+    }
+
+    public void setAddDate(Date addDate) {
+        this.addDate = addDate;
+    }
+
+    public Date getAddDate() {
+        return addDate;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdSalesEntity{" +
+                "id=" + id + '\'' +
+                "farmId=" + farmId + '\'' +
+                "farmName=" + farmName + '\'' +
+                "todayQuantity=" + todayQuantity + '\'' +
+                "todayWeight=" + todayWeight + '\'' +
+                "todayMoney=" + todayMoney + '\'' +
+                "weekQuantity=" + weekQuantity + '\'' +
+                "weekWeight=" + weekWeight + '\'' +
+                "weekMoney=" + weekMoney + '\'' +
+                "monthQuantity=" + monthQuantity + '\'' +
+                "monthWeight=" + monthWeight + '\'' +
+                "monthMoney=" + monthMoney + '\'' +
+                "addDate=" + addDate + '\'' +
+                '}';
+    }
+}

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

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

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

@@ -44,7 +44,7 @@ public interface IAutoGetErpData {
     void getPayable();
 
     //销售接口取数
-    void getSales();
+    void getSales() throws IOException, ParseException;
 
 
 

+ 57 - 1
huimv-hy-production/huimv.hy.autoGetData/src/main/java/com/huimv/production/autoGetData/service/impl/AutoGetErpDataImpl.java

@@ -1247,9 +1247,65 @@ public class AutoGetErpDataImpl implements IAutoGetErpData {
 
     }
 
+    @Autowired
+    private ProdSalesRepo salesRepo;
+
     @Override
-    public void getSales() {
+    public void getSales() throws IOException, ParseException {
+        //
+        Map timeoutMap = httpClientUtil.setTimeout(connectTimeout, requestTimeout, socketTimeout);
+        //
+        String token = getRemoteToken();
+        //
+        Map<String, String> paramsMap = new HashMap<String, String>();
+        paramsMap.put("accessToken", token);
 
+        String url = apiIp + apiPort + serviceName + "/getSales";
+        log.info("销售数据接口访问地址=" + url);
+        log.info("业务请求参数=" + paramsMap.toString());
+        log.info("开始取数=" + new Date(System.currentTimeMillis()));
+        //
+        JSONObject outJo = httpClientUtil.doGet(url, paramsMap);
+        log.info("返回结果=" + outJo);
+        log.info("结束取数=" + new Date(System.currentTimeMillis()));
+        if (outJo.getBoolean("status")) {
+            JSONObject contentJo = outJo.getJSONObject("content");
+            if (contentJo.getBoolean("success")) {
+                JSONArray dataJa = contentJo.getJSONArray("data");
+                if (dataJa.size() == 0) {
+                    log.info("未取到数据 。");
+                } else {
+                    //删除旧数据
+                    ProdSalesEntity delSalesEntity = new ProdSalesEntity();
+                    delSalesEntity.setAddDate(dateUtil.getTodayDate());
+                    Example<ProdSalesEntity> example = Example.of(delSalesEntity);
+                    salesRepo.deleteAll(salesRepo.findAll(example));
+
+                    //获取牧场所有名称数据
+                    List<ProdFarmNameEntity> farmNameEntityList = prodFarmNameRepo.findAll();
+                    //获取牧场所有名称数据
+                    for (int a = 0; a < dataJa.size(); a++) {
+                        JSONObject dataJo = dataJa.getJSONObject(a);
+                        ProdSalesEntity addSalesEntity = new ProdSalesEntity();
+                        addSalesEntity.setFarmName(dataJo.getString("mcmc"));
+                        //
+                        addSalesEntity.setFarmId(_getFarmIdByShortName(dataJo.getString("mcmc"), farmNameEntityList));
+                        addSalesEntity.setTodayMoney(dataJo.getString("today_money"));
+                        addSalesEntity.setTodayQuantity(dataJo.getString("today_quantity"));
+                        addSalesEntity.setTodayWeight(dataJo.getString("today_weight"));
+                        addSalesEntity.setWeekMoney(dataJo.getString("week_money"));
+                        addSalesEntity.setWeekQuantity(dataJo.getString("week_quantity"));
+                        addSalesEntity.setWeekWeight(dataJo.getString("week_weight"));
+                        addSalesEntity.setMonthMoney(dataJo.getString("month_money"));
+                        addSalesEntity.setMonthQuantity(dataJo.getString("month_quantity"));
+                        addSalesEntity.setMonthWeight(dataJo.getString("month_weight"));
+                        addSalesEntity.setAddDate(new Timestamp(new Date().getTime()));
+                        salesRepo.save(addSalesEntity);
+                    }
+
+                }
+            }
+        }
     }
 
    /* public static void main(String[] args) {

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

@@ -6,4 +6,8 @@ erp.datasource.endDate=2021.12.31
 erp.datasource.apiIp=http://121.40.221.149
 erp.datasource.apiPort=:9100
 erp.datasource.serviceName=/erpData
-#erp.datasource.filterFarm=º£ÑÎ
+#erp.datasource.filterFarm=º£ÑÎ
+
+timeout.connectTimeout=120000
+timeout.requestTimeout=120000
+timeout.socketTimeout=120000

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

@@ -57,5 +57,32 @@ public class AutoGetDataTEst {
         System.out.println(name.indexOf(name2));
     }
 
+    //测试从ERP工作计划接口取数
+    @Test
+    public void testGetWorkPlan() throws IOException, ParseException {
+        //
+        autoGetErpData.getWorkPlan();
+    }
+
+    //测试从待分娩、待配种、待断奶接口取数
+    @Test
+    public void testGetPrepareStatusQuantity() throws IOException, ParseException {
+        //
+        autoGetErpData.getPrepareStatusQuantity();
+    }
+
+    //测试从应付接口取数(无数据)
+    @Test
+    public void testGetPayable() throws IOException, ParseException {
+        //
+        autoGetErpData.getPayable();
+    }
+
+    //测试从销售接口取数
+    @Test
+    public void testGetSales() throws IOException, ParseException {
+        //
+        autoGetErpData.getSales();
+    }
 
 }