Browse Source

新增电子称接收批次称重数据。

zhuoning 3 years ago
parent
commit
50f5c9e76f

+ 9 - 0
huimv-farm-v2/huimv-center-receiver/src/main/java/com/huimv/receiver/farm/controller/WeightController.java

@@ -19,9 +19,18 @@ public class WeightController {
     @Autowired
     private IWeight weight;
 
+    //保存日总重
     @RequestMapping(value = "/putDayWeight",method = RequestMethod.POST)
     public void putDayWeight(@RequestParam(value = "data",required = true) String data){
         //
         weight.saveDayWeight(data);
     }
+
+    //保存批次总重
+    @RequestMapping(value = "/putBatchWeight",method = RequestMethod.POST)
+    public void putBatchWeight(@RequestParam(value = "data",required = true) String data){
+        //
+        weight.saveBatchWeight(data);
+    }
+
 }

+ 128 - 0
huimv-farm-v2/huimv-center-receiver/src/main/java/com/huimv/receiver/farm/dao/entity/ProdBatchWeightEntity.java

@@ -0,0 +1,128 @@
+package com.huimv.receiver.farm.dao.entity;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "prod_batch_weight")
+public class ProdBatchWeightEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "batch_code")
+    private String batchCode;
+
+    @Column(name = "batch_sort")
+    private Integer batchSort;
+
+    @Column(name = "gross_weight")
+    private Float grossWeight;
+
+    @Column(name = "tare_weight")
+    private Float tareWeight;
+
+    @Column(name = "net_weight")
+    private Float netWeight;
+
+    @Column(name = "trade_id")
+    private Integer tradeId;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    @Column(name = "add_time")
+    private Timestamp addTime;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setBatchCode(String batchCode) {
+        this.batchCode = batchCode;
+    }
+
+    public String getBatchCode() {
+        return batchCode;
+    }
+
+    public void setBatchSort(Integer batchSort) {
+        this.batchSort = batchSort;
+    }
+
+    public Integer getBatchSort() {
+        return batchSort;
+    }
+
+    public void setGrossWeight(Float grossWeight) {
+        this.grossWeight = grossWeight;
+    }
+
+    public Float getGrossWeight() {
+        return grossWeight;
+    }
+
+    public void setTareWeight(Float tareWeight) {
+        this.tareWeight = tareWeight;
+    }
+
+    public Float getTareWeight() {
+        return tareWeight;
+    }
+
+    public void setNetWeight(Float netWeight) {
+        this.netWeight = netWeight;
+    }
+
+    public Float getNetWeight() {
+        return netWeight;
+    }
+
+    public void setTradeId(Integer tradeId) {
+        this.tradeId = tradeId;
+    }
+
+    public Integer getTradeId() {
+        return tradeId;
+    }
+
+    public void setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public void setAddTime(Timestamp addTime) {
+        this.addTime = addTime;
+    }
+
+    public Timestamp getAddTime() {
+        return addTime;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdBatchWeightEntity{" +
+                "id=" + id + '\'' +
+                "batchCode=" + batchCode + '\'' +
+                "batchSort=" + batchSort + '\'' +
+                "grossWeight=" + grossWeight + '\'' +
+                "tareWeight=" + tareWeight + '\'' +
+                "netWeight=" + netWeight + '\'' +
+                "tradeId=" + tradeId + '\'' +
+                "farmId=" + farmId + '\'' +
+                "addTime=" + addTime + '\'' +
+                '}';
+    }
+}

+ 12 - 0
huimv-farm-v2/huimv-center-receiver/src/main/java/com/huimv/receiver/farm/dao/repo/ProdBatchWeightRepo.java

@@ -0,0 +1,12 @@
+package com.huimv.receiver.farm.dao.repo;
+
+import com.huimv.receiver.farm.dao.entity.ProdBatchWeightEntity;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+public interface ProdBatchWeightRepo extends JpaRepository<ProdBatchWeightEntity, Integer>, JpaSpecificationExecutor<ProdBatchWeightEntity> {
+
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_batch_weight WHERE batch_code=?1")
+    ProdBatchWeightEntity findByBatchCode(String batchCode);
+}

+ 3 - 0
huimv-farm-v2/huimv-center-receiver/src/main/java/com/huimv/receiver/farm/service/IWeight.java

@@ -3,4 +3,7 @@ package com.huimv.receiver.farm.service;
 public interface IWeight {
     //
     void saveDayWeight(String data);
+
+    //
+    void saveBatchWeight(String data);
 }

+ 49 - 1
huimv-farm-v2/huimv-center-receiver/src/main/java/com/huimv/receiver/farm/service/impl/WeightImpl.java

@@ -1,7 +1,9 @@
 package com.huimv.receiver.farm.service.impl;
 
 import com.alibaba.fastjson.JSONObject;
+import com.huimv.receiver.farm.dao.entity.ProdBatchWeightEntity;
 import com.huimv.receiver.farm.dao.entity.ProdDayWeightEntity;
+import com.huimv.receiver.farm.dao.repo.ProdBatchWeightRepo;
 import com.huimv.receiver.farm.dao.repo.ProdDayWeightRepo;
 import com.huimv.receiver.farm.service.IWeight;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -22,7 +24,19 @@ import java.util.Date;
 public class WeightImpl implements IWeight {
     @Autowired
     private ProdDayWeightRepo dayWeightRepo;
+    @Autowired
+    private ProdBatchWeightRepo batchWeightRepo;
 
+    /**
+     * @Method      : saveDayWeight
+     * @Description : 保存日总重数据
+     * @Params      : [data]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/7       
+     * @Time        : 19:48
+     */
     @Override
     public void saveDayWeight(String data) {
         JSONObject dayWeightJo = JSONObject.parseObject(data);
@@ -32,7 +46,6 @@ public class WeightImpl implements IWeight {
         ProdDayWeightEntity existDayWeightEntity = dayWeightRepo.findByDateAndFarmId(new Date(date),farmId);
         if(existDayWeightEntity != null){
             existDayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
-//            existDayWeightEntity.setFarmId(dayWeightJo.getInteger("farmId"));
             existDayWeightEntity.setGrossWeight(dayWeightJo.getFloat("grossWeight"));
             existDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
             existDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
@@ -48,4 +61,39 @@ public class WeightImpl implements IWeight {
         }
 
     }
+
+    /**
+     * @Method      : saveBatchWeight
+     * @Description : 保存批次重量数据
+     * @Params      : [data]
+     * @Return      : void
+     * 
+     * @Author      : ZhuoNing
+     * @Date        : 2021/12/7       
+     * @Time        : 19:49
+     */
+    @Override
+    public void saveBatchWeight(String data) {
+        JSONObject batchWeightJo = JSONObject.parseObject(data);
+        String batchCode = batchWeightJo.getString("batchCode");
+        System.out.println("batchCode<<"+batchCode);
+        //查找批次称重数据
+        ProdBatchWeightEntity existBatchWeightEntity = batchWeightRepo.findByBatchCode(batchCode);
+        if(existBatchWeightEntity == null){
+            ProdBatchWeightEntity newBatchWeightEntity = new ProdBatchWeightEntity();
+            newBatchWeightEntity.setBatchCode(batchWeightJo.getString("batchCode"));
+            newBatchWeightEntity.setBatchSort(batchWeightJo.getInteger("batchSort"));
+            newBatchWeightEntity.setFarmId(batchWeightJo.getInteger("farmId"));
+            newBatchWeightEntity.setGrossWeight(batchWeightJo.getFloat("grossWeight"));
+            newBatchWeightEntity.setTareWeight(batchWeightJo.getFloat("tareWeight"));
+            newBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
+            newBatchWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
+            batchWeightRepo.saveAndFlush(newBatchWeightEntity);
+        }else{
+            existBatchWeightEntity.setGrossWeight(batchWeightJo.getFloat("grossWeight"));
+            existBatchWeightEntity.setTareWeight(batchWeightJo.getFloat("tareWeight"));
+            existBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
+            batchWeightRepo.saveAndFlush(existBatchWeightEntity);
+        }
+    }
 }