Jelajahi Sumber

数据中心新增保存每次称重

zhuoning 3 tahun lalu
induk
melakukan
a668aab70d

+ 4 - 3
huimv-farm-produce/src/main/java/com/huimv/produce/produce/repo/ProdBatchWeightRepo.java

@@ -9,8 +9,9 @@ import org.springframework.data.jpa.repository.Query;
 import java.util.Date;
 
 public interface ProdBatchWeightRepo extends JpaRepository<ProdBatchWeightEntity, Integer>, JpaSpecificationExecutor<ProdBatchWeightEntity> {
-
-    @Query(nativeQuery = true,value = "SELECT * FROM prod_batch_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d') ORDER BY id DESC",
-            countQuery = "SELECT COUNT(*) FROM prod_batch_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d')")
+    //
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d') ORDER BY id DESC",
+            countQuery = "SELECT COUNT(*) FROM prod_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d')")
     Page<ProdBatchWeightEntity> findByFarmIdAndStartDateAndEndDate(Integer farmId, Date startDate, Date endDate, Pageable pageable);
+
 }

+ 131 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/repo/ProdWeightEntity.java

@@ -0,0 +1,131 @@
+package com.huimv.produce.produce.repo;
+
+import javax.persistence.*;
+import java.io.Serializable;
+import java.sql.Timestamp;
+
+@Entity
+@Table(name = "prod_weight")
+public class ProdWeightEntity implements Serializable {
+
+    private static final long serialVersionUID = 1L;
+
+    @Id
+    @GeneratedValue(strategy = GenerationType.IDENTITY)
+    @Column(name = "id", nullable = false)
+    private Integer id;
+
+    @Column(name = "add_time")
+    private Timestamp addTime;
+
+    /**
+     * 毛重
+     */
+    @Column(name = "gross_weight")
+    private Float grossWeight;
+
+    /**
+     * 皮重
+     */
+    @Column(name = "tare_weight")
+    private Float tareWeight;
+
+    /**
+     * 净重
+     */
+    @Column(name = "net_weight")
+    private Float netWeight;
+
+    @Column(name = "farm_id")
+    private Integer farmId;
+
+    @Column(name = "batch_id")
+    private Integer batchId;
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
+    public Integer getId() {
+        return id;
+    }
+
+    public void setAddTime(Timestamp addTime) {
+        this.addTime = addTime;
+    }
+
+    public Timestamp getAddTime() {
+        return addTime;
+    }
+
+    /**
+     * 毛重
+     */
+    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 setFarmId(Integer farmId) {
+        this.farmId = farmId;
+    }
+
+    public Integer getFarmId() {
+        return farmId;
+    }
+
+    public void setBatchId(Integer batchId) {
+        this.batchId = batchId;
+    }
+
+    public Integer getBatchId() {
+        return batchId;
+    }
+
+    @Override
+    public String toString() {
+        return "ProdWeightEntity{" +
+                "id=" + id + '\'' +
+                "addTime=" + addTime + '\'' +
+                "grossWeight=" + grossWeight + '\'' +
+                "tareWeight=" + tareWeight + '\'' +
+                "netWeight=" + netWeight + '\'' +
+                "farmId=" + farmId + '\'' +
+                "batchId=" + batchId + '\'' +
+                '}';
+    }
+}

+ 17 - 0
huimv-farm-produce/src/main/java/com/huimv/produce/produce/repo/ProdWeightRepo.java

@@ -0,0 +1,17 @@
+package com.huimv.produce.produce.repo;
+
+import org.springframework.data.domain.Page;
+import org.springframework.data.domain.Pageable;
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.Date;
+
+public interface ProdWeightRepo extends JpaRepository<ProdWeightEntity, Integer>, JpaSpecificationExecutor<ProdWeightEntity> {
+    //
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_batch_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d') ORDER BY id DESC",
+            countQuery = "SELECT COUNT(*) FROM prod_batch_weight WHERE farm_id=?1 AND DATE_FORMAT(add_time,'%Y-%m-%d')>=DATE_FORMAT(?2,'%Y-%m-%d') AND DATE_FORMAT(add_time,'%Y-%m-%d')<=DATE_FORMAT(?3,'%Y-%m-%d')")
+    Page<ProdWeightEntity> findWeightByFarmIdAndStartDateAndEndDate(Integer farmId, Date startDate, Date endDate, Pageable pageable);
+
+}

+ 9 - 4
huimv-farm-produce/src/main/java/com/huimv/produce/produce/service/impl/WeightImpl.java

@@ -3,10 +3,7 @@ package com.huimv.produce.produce.service.impl;
 import com.alibaba.fastjson.JSONObject;
 import com.huimv.common.utils.Result;
 import com.huimv.common.utils.ResultCode;
-import com.huimv.produce.produce.repo.ProdBatchWeightEntity;
-import com.huimv.produce.produce.repo.ProdBatchWeightRepo;
-import com.huimv.produce.produce.repo.ProdDayWeightEntity;
-import com.huimv.produce.produce.repo.ProdDayWeightRepo;
+import com.huimv.produce.produce.repo.*;
 import com.huimv.produce.produce.service.IWeight;
 import com.huimv.produce.produce.utils.DateUtil;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -38,6 +35,8 @@ public class WeightImpl implements IWeight {
     @Autowired
     private ProdBatchWeightRepo batchWeightRepo;
     @Autowired
+    private ProdWeightRepo weightRepo;
+    @Autowired
     private DateUtil dateUtil;
 
     /**
@@ -226,6 +225,12 @@ public class WeightImpl implements IWeight {
         return new Result(ResultCode.SUCCESS, batchWeightRepo.findByFarmIdAndStartDateAndEndDate(farmId, startDate, endDate, pageable));
     }
 
+    public Result getEveryTimeWeightOnPage(Integer farmId, Date startDate, Date endDate, Integer pageNo, Integer pageSize) throws ParseException {
+        Pageable pageable = PageRequest.of(pageNo - 1, pageSize, Sort.Direction.DESC, "id");
+        //
+        return new Result(ResultCode.SUCCESS, weightRepo.findWeightByFarmIdAndStartDateAndEndDate(farmId, startDate, endDate, pageable));
+    }
+
     @PersistenceContext
     EntityManager entityManager;