Prechádzať zdrojové kódy

修改更新每天总重和批次称重

zhuoning 3 rokov pred
rodič
commit
a9aa8853ae

+ 0 - 1
huimv-farm-receiver/src/main/java/com/huimv/receiver/eco/service/ISysMonthWaterService.java

@@ -1,7 +1,6 @@
 package com.huimv.receiver.eco.service;
 
 import com.baomidou.mybatisplus.extension.service.IService;
-import com.huimv.common.utils.Result;
 import com.huimv.receiver.eco.entity.SysMonthWater;
 
 /**

+ 0 - 1
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/controller/CenterDeviceController.java

@@ -1,7 +1,6 @@
 package com.huimv.receiver.farm.controller;
 
 import com.huimv.common.utils.Result;
-import com.huimv.common.utils.ResultCode;
 import com.huimv.receiver.farm.service.ICenterDevice;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;

+ 3 - 1
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/repo/ProdBatchWeightRepo.java

@@ -5,8 +5,10 @@ import org.springframework.data.jpa.repository.JpaRepository;
 import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
 
+import java.util.Optional;
+
 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);
+    Optional<ProdBatchWeightEntity> findByBatchCode(String batchCode);
 }

+ 2 - 1
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/dao/repo/ProdDayWeightRepo.java

@@ -6,9 +6,10 @@ import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
 import org.springframework.data.jpa.repository.Query;
 
 import java.util.Date;
+import java.util.Optional;
 
 public interface ProdDayWeightRepo extends JpaRepository<ProdDayWeightEntity, Integer>, JpaSpecificationExecutor<ProdDayWeightEntity> {
 
     @Query(nativeQuery = true,value = "SELECT * FROM prod_day_weight WHERE DATE_FORMAT(add_time,'%Y-%m-%d') = DATE_FORMAT(?1,'%Y-%m-%d') AND farm_id=?2")
-    ProdDayWeightEntity findByDateAndFarmId(Date date, Integer farmId);
+    Optional<ProdDayWeightEntity> findByDateAndFarmId(Date date, Integer farmId);
 }

+ 12 - 5
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/service/impl/WeightImpl.java

@@ -12,6 +12,7 @@ import org.springframework.stereotype.Service;
 
 import java.sql.Timestamp;
 import java.util.Date;
+import java.util.Optional;
 
 /**
  * @Project : huimv.shiwan
@@ -46,13 +47,16 @@ public class WeightImpl implements IWeight {
         Long date = dayWeightJo.getLong("addTime");
         Integer farmId = dayWeightJo.getInteger("farmId");
         //
-        ProdDayWeightEntity existDayWeightEntity = dayWeightRepo.findByDateAndFarmId(new Date(date),farmId);
-        if(existDayWeightEntity != null){
+        Optional<ProdDayWeightEntity> optional = dayWeightRepo.findByDateAndFarmId(new Date(date),farmId);
+        log.info("optional.isPresent>>"+optional.isPresent());
+        if(optional.isPresent()){
+            ProdDayWeightEntity existDayWeightEntity = optional.get();
             existDayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
             existDayWeightEntity.setGrossWeight(dayWeightJo.getFloat("grossWeight"));
             existDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
             existDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
             dayWeightRepo.saveAndFlush(existDayWeightEntity);
+            log.info("编辑每天总重>>"+existDayWeightEntity);
         }else{
             ProdDayWeightEntity newDayWeightEntity = new ProdDayWeightEntity();
             newDayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
@@ -61,6 +65,7 @@ public class WeightImpl implements IWeight {
             newDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
             newDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
             dayWeightRepo.saveAndFlush(newDayWeightEntity);
+            log.info("新增每天总重>>"+newDayWeightEntity);
         }
 
     }
@@ -79,10 +84,11 @@ public class WeightImpl implements IWeight {
     public void saveBatchWeight(String data) {
         JSONObject batchWeightJo = JSONObject.parseObject(data);
         String batchCode = batchWeightJo.getString("batchCode");
-        System.out.println("batchCode<<"+batchCode);
+        System.out.println("batchCode>>"+batchCode);
         //查找批次称重数据
-        ProdBatchWeightEntity existBatchWeightEntity = batchWeightRepo.findByBatchCode(batchCode);
-        if(existBatchWeightEntity == null){
+        Optional<ProdBatchWeightEntity> optional = batchWeightRepo.findByBatchCode(batchCode);
+        log.info("optional.isPresent>>"+optional.isPresent());
+        if(!optional.isPresent()){
             ProdBatchWeightEntity newBatchWeightEntity = new ProdBatchWeightEntity();
             newBatchWeightEntity.setBatchCode(batchWeightJo.getString("batchCode"));
             newBatchWeightEntity.setBatchSort(batchWeightJo.getInteger("batchSort"));
@@ -94,6 +100,7 @@ public class WeightImpl implements IWeight {
             batchWeightRepo.saveAndFlush(newBatchWeightEntity);
             log.info("新增批次称重数据>>"+newBatchWeightEntity);
         }else{
+            ProdBatchWeightEntity existBatchWeightEntity = optional.get();
             existBatchWeightEntity.setGrossWeight(batchWeightJo.getFloat("grossWeight"));
             existBatchWeightEntity.setTareWeight(batchWeightJo.getFloat("tareWeight"));
             existBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));