Przeglądaj źródła

新增电子秤查询

zhuoning 3 lat temu
rodzic
commit
25d22b192e

+ 36 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/controller/WeightController.java

@@ -0,0 +1,36 @@
+package com.huimv.produce.controller;
+
+import com.huimv.common.utils.Result;
+import com.huimv.produce.service.IWeight;
+import lombok.extern.slf4j.Slf4j;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.web.bind.annotation.CrossOrigin;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestParam;
+import org.springframework.web.bind.annotation.RestController;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+@CrossOrigin
+@RestController
+@RequestMapping(value = "/produce/weight")
+@Slf4j
+public class WeightController {
+    @Autowired
+    private IWeight weight;
+
+    @RequestMapping(value = "/getDayWeight")
+    public Result getDayWeight(@RequestParam(value = "farmId",required = true) Integer farmId,@RequestParam(value = "startDate",required = false) String startDate,@RequestParam(value = "endDate",required = false) String endDate){
+        log.info("farmId>>"+farmId);
+        log.info("startDate>>"+startDate);
+        log.info("endDate>>"+endDate);
+        //
+        return weight.getDayWeight(farmId,startDate,endDate);
+    }
+}

+ 96 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/repo/ProdDayWeightEntity.java

@@ -0,0 +1,96 @@
+package com.huimv.produce.repo;
+
+import javax.persistence.Entity;
+import javax.persistence.Column;
+import javax.persistence.GenerationType;
+import javax.persistence.Table;
+import javax.persistence.GeneratedValue;
+import java.sql.Timestamp;
+import java.io.Serializable;
+import javax.persistence.Id;
+ 
+@Entity
+@Table(name = "prod_day_weight")
+public class ProdDayWeightEntity 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 = "farm_id")
+private Integer farmId;
+
+@Column(name = "gross_weight")
+private Float grossWeight;
+
+@Column(name = "net_weight")
+private Float netWeight;
+
+@Column(name = "tare_weight")
+private Float tareWeight;
+
+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  setFarmId(Integer farmId) {
+this.farmId = farmId;
+}
+
+public Integer getFarmId() {
+return farmId;
+}
+
+public  void  setGrossWeight(Float grossWeight) {
+this.grossWeight = grossWeight;
+}
+
+public Float getGrossWeight() {
+return grossWeight;
+}
+
+public  void  setNetWeight(Float netWeight) {
+this.netWeight = netWeight;
+}
+
+public Float getNetWeight() {
+return netWeight;
+}
+
+public  void  setTareWeight(Float tareWeight) {
+this.tareWeight = tareWeight;
+}
+
+public Float getTareWeight() {
+return tareWeight;
+}
+
+@Override
+public String toString() {
+return "ProdDayWeightEntity{" +
+    "id=" + id + '\'' +
+    "addTime=" + addTime + '\'' +
+    "farmId=" + farmId + '\'' +
+    "grossWeight=" + grossWeight + '\'' +
+    "netWeight=" + netWeight + '\'' +
+    "tareWeight=" + tareWeight + '\'' +
+    '}';
+}
+}

+ 13 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/repo/ProdDayWeightRepo.java

@@ -0,0 +1,13 @@
+package com.huimv.produce.repo;
+
+import org.springframework.data.jpa.repository.JpaRepository;
+import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
+import org.springframework.data.jpa.repository.Query;
+
+import java.util.List;
+
+public interface ProdDayWeightRepo extends JpaRepository<ProdDayWeightEntity, Integer>, JpaSpecificationExecutor<ProdDayWeightEntity> {
+
+    @Query(nativeQuery = true,value = "SELECT * FROM prod_day_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')")
+    List<ProdDayWeightEntity> findByFarmIdAndStartAndEndDate(Integer farmId, String startDate, String endDate);
+}

+ 7 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/IWeight.java

@@ -0,0 +1,7 @@
+package com.huimv.produce.service;
+
+import com.huimv.common.utils.Result;
+
+public interface IWeight {
+    Result getDayWeight(Integer farmId, String startDate, String endDate);
+}

+ 34 - 0
huimv-farm-v2/huimv-produce-warning/src/main/java/com/huimv/produce/service/impl/WeightImpl.java

@@ -0,0 +1,34 @@
+package com.huimv.produce.service.impl;
+
+import com.huimv.common.utils.Result;
+import com.huimv.common.utils.ResultCode;
+import com.huimv.produce.repo.ProdDayWeightEntity;
+import com.huimv.produce.repo.ProdDayWeightRepo;
+import com.huimv.produce.service.IWeight;
+import org.springframework.beans.factory.annotation.Autowired;
+
+import java.util.List;
+
+/**
+ * @Project : huimv.shiwan
+ * @Package : com.huimv.biosafety.uface.controller
+ * @Description : TODO
+ * @Version : 1.0
+ * @Author : ZhuoNing
+ * @Create : 2020-12-25
+ **/
+public class WeightImpl implements IWeight {
+    @Autowired
+    private ProdDayWeightRepo dayWeightRepo;
+
+    @Override
+    public Result getDayWeight(Integer farmId, String startDate, String endDate){
+        //
+        List<ProdDayWeightEntity> dayWeightEntityList = dayWeightRepo.findByFarmIdAndStartAndEndDate(farmId,startDate,endDate);
+        if(dayWeightEntityList.size()>0){
+            return new Result(ResultCode.SUCCESS,dayWeightEntityList);
+        }else{
+            return new Result(10001,"暂无数据.",false);
+        }
+    }
+}