|
@@ -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.ProdBatchWeightRepo;
|
|
import com.huimv.receiver.farm.dao.repo.ProdDayWeightRepo;
|
|
import com.huimv.receiver.farm.dao.repo.ProdDayWeightRepo;
|
|
import com.huimv.receiver.farm.service.IWeight;
|
|
import com.huimv.receiver.farm.service.IWeight;
|
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
import java.sql.Timestamp;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
|
|
+import java.util.Optional;
|
|
|
|
|
|
/**
|
|
/**
|
|
* @Project : huimv.shiwan
|
|
* @Project : huimv.shiwan
|
|
@@ -21,6 +23,7 @@ import java.util.Date;
|
|
* @Create : 2020-12-25
|
|
* @Create : 2020-12-25
|
|
**/
|
|
**/
|
|
@Service
|
|
@Service
|
|
|
|
+@Slf4j
|
|
public class WeightImpl implements IWeight {
|
|
public class WeightImpl implements IWeight {
|
|
@Autowired
|
|
@Autowired
|
|
private ProdDayWeightRepo dayWeightRepo;
|
|
private ProdDayWeightRepo dayWeightRepo;
|
|
@@ -39,17 +42,21 @@ public class WeightImpl implements IWeight {
|
|
*/
|
|
*/
|
|
@Override
|
|
@Override
|
|
public void saveDayWeight(String data) {
|
|
public void saveDayWeight(String data) {
|
|
|
|
+ log.info("saveDayWeight>>"+data);
|
|
JSONObject dayWeightJo = JSONObject.parseObject(data);
|
|
JSONObject dayWeightJo = JSONObject.parseObject(data);
|
|
Long date = dayWeightJo.getLong("addTime");
|
|
Long date = dayWeightJo.getLong("addTime");
|
|
Integer farmId = dayWeightJo.getInteger("farmId");
|
|
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.setAddTime(new Timestamp(new Date().getTime()));
|
|
existDayWeightEntity.setGrossWeight(dayWeightJo.getFloat("grossWeight"));
|
|
existDayWeightEntity.setGrossWeight(dayWeightJo.getFloat("grossWeight"));
|
|
existDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
|
|
existDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
|
|
existDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
|
|
existDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
|
|
dayWeightRepo.saveAndFlush(existDayWeightEntity);
|
|
dayWeightRepo.saveAndFlush(existDayWeightEntity);
|
|
|
|
+ log.info("编辑每天总重>>"+existDayWeightEntity);
|
|
}else{
|
|
}else{
|
|
ProdDayWeightEntity newDayWeightEntity = new ProdDayWeightEntity();
|
|
ProdDayWeightEntity newDayWeightEntity = new ProdDayWeightEntity();
|
|
newDayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
|
|
newDayWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
|
|
@@ -58,6 +65,7 @@ public class WeightImpl implements IWeight {
|
|
newDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
|
|
newDayWeightEntity.setTareWeight(dayWeightJo.getFloat("tareWeight"));
|
|
newDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
|
|
newDayWeightEntity.setNetWeight(dayWeightJo.getFloat("netWeight"));
|
|
dayWeightRepo.saveAndFlush(newDayWeightEntity);
|
|
dayWeightRepo.saveAndFlush(newDayWeightEntity);
|
|
|
|
+ log.info("新增每天总重>>"+newDayWeightEntity);
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
@@ -76,10 +84,11 @@ public class WeightImpl implements IWeight {
|
|
public void saveBatchWeight(String data) {
|
|
public void saveBatchWeight(String data) {
|
|
JSONObject batchWeightJo = JSONObject.parseObject(data);
|
|
JSONObject batchWeightJo = JSONObject.parseObject(data);
|
|
String batchCode = batchWeightJo.getString("batchCode");
|
|
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();
|
|
ProdBatchWeightEntity newBatchWeightEntity = new ProdBatchWeightEntity();
|
|
newBatchWeightEntity.setBatchCode(batchWeightJo.getString("batchCode"));
|
|
newBatchWeightEntity.setBatchCode(batchWeightJo.getString("batchCode"));
|
|
newBatchWeightEntity.setBatchSort(batchWeightJo.getInteger("batchSort"));
|
|
newBatchWeightEntity.setBatchSort(batchWeightJo.getInteger("batchSort"));
|
|
@@ -89,11 +98,14 @@ public class WeightImpl implements IWeight {
|
|
newBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
|
|
newBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
|
|
newBatchWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
|
|
newBatchWeightEntity.setAddTime(new Timestamp(new Date().getTime()));
|
|
batchWeightRepo.saveAndFlush(newBatchWeightEntity);
|
|
batchWeightRepo.saveAndFlush(newBatchWeightEntity);
|
|
|
|
+ log.info("新增批次称重数据>>"+newBatchWeightEntity);
|
|
}else{
|
|
}else{
|
|
|
|
+ ProdBatchWeightEntity existBatchWeightEntity = optional.get();
|
|
existBatchWeightEntity.setGrossWeight(batchWeightJo.getFloat("grossWeight"));
|
|
existBatchWeightEntity.setGrossWeight(batchWeightJo.getFloat("grossWeight"));
|
|
existBatchWeightEntity.setTareWeight(batchWeightJo.getFloat("tareWeight"));
|
|
existBatchWeightEntity.setTareWeight(batchWeightJo.getFloat("tareWeight"));
|
|
existBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
|
|
existBatchWeightEntity.setNetWeight(batchWeightJo.getFloat("netWeight"));
|
|
batchWeightRepo.saveAndFlush(existBatchWeightEntity);
|
|
batchWeightRepo.saveAndFlush(existBatchWeightEntity);
|
|
|
|
+ log.info("编辑批次称重数据>>"+existBatchWeightEntity);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|