Explorar el Código

Merge remote-tracking branch 'origin/master'

yang hace 3 años
padre
commit
bb3fb0e018

+ 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;

+ 4 - 0
huimv-farm-receiver/src/main/java/com/huimv/receiver/farm/controller/WeightController.java

@@ -1,6 +1,7 @@
 package com.huimv.receiver.farm.controller;
 
 import com.huimv.receiver.farm.service.IWeight;
+import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
@@ -14,6 +15,7 @@ import org.springframework.web.bind.annotation.*;
  **/
 @CrossOrigin
 @RestController
+@Slf4j
 @RequestMapping(value = "/receiver/farm/weight")
 public class WeightController {
     @Autowired
@@ -22,6 +24,7 @@ public class WeightController {
     //保存日总重
     @RequestMapping(value = "/putDayWeight",method = RequestMethod.POST)
     public void putDayWeight(@RequestParam(value = "data",required = true) String data){
+    log.info("接收每天总重>>"+data);
         //
         weight.saveDayWeight(data);
     }
@@ -29,6 +32,7 @@ public class WeightController {
     //保存批次总重
     @RequestMapping(value = "/putBatchWeight",method = RequestMethod.POST)
     public void putBatchWeight(@RequestParam(value = "data",required = true) String data){
+        log.info("接收批次总重>>"+data);
         //
         weight.saveBatchWeight(data);
     }

+ 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);
 }

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

@@ -6,11 +6,13 @@ 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 lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 
 import java.sql.Timestamp;
 import java.util.Date;
+import java.util.Optional;
 
 /**
  * @Project : huimv.shiwan
@@ -21,6 +23,7 @@ import java.util.Date;
  * @Create : 2020-12-25
  **/
 @Service
+@Slf4j
 public class WeightImpl implements IWeight {
     @Autowired
     private ProdDayWeightRepo dayWeightRepo;
@@ -39,17 +42,21 @@ public class WeightImpl implements IWeight {
      */
     @Override
     public void saveDayWeight(String data) {
+        log.info("saveDayWeight>>"+data);
         JSONObject dayWeightJo = JSONObject.parseObject(data);
         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()));
@@ -58,6 +65,7 @@ public class WeightImpl implements IWeight {
             newDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
             newDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
             dayWeightRepo.saveAndFlush(newDayWeightEntity);
+            log.info("新增每天总重>>"+newDayWeightEntity);
         }
 
     }
@@ -76,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"));
@@ -89,11 +98,14 @@ public class WeightImpl implements IWeight {
             newBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
             newBatchWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
             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"));
             batchWeightRepo.saveAndFlush(existBatchWeightEntity);
+            log.info("编辑批次称重数据>>"+existBatchWeightEntity);
         }
     }
 }