Commit 9af10910 by 向延琳

修改null判断

1 parent 64582d98
...@@ -56,12 +56,9 @@ public class BatteryService { ...@@ -56,12 +56,9 @@ public class BatteryService {
public void saveBatteryInfo(DevicePowerDTO devicePowerDTO) { public void saveBatteryInfo(DevicePowerDTO devicePowerDTO) {
//从车辆信息中获取创建人信息 //从车辆信息中获取创建人信息
Vehicle vehicle = vehicleMapper.getVehicleBySn(devicePowerDTO.getSn()); Vehicle vehicle = vehicleMapper.getVehicleBySn(devicePowerDTO.getSn());
Long createdBy = null; Long createdBy = Optional.ofNullable(vehicle).map(Vehicle::getCreatedBy).orElse(null);
Long updatedBy = null; Long updatedBy = Optional.ofNullable(vehicle).map(Vehicle::getUpdatedBy).orElse(null);
if(Objects.nonNull(vehicle)) { if(Objects.isNull(vehicle)) {
createdBy = vehicle.getCreatedBy();
updatedBy = vehicle.getUpdatedBy();
} else {
log.warn("该设备没有绑定车辆" + devicePowerDTO.getSn()); log.warn("该设备没有绑定车辆" + devicePowerDTO.getSn());
} }
//从关联表从获取关联id //从关联表从获取关联id
......
...@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional; ...@@ -18,6 +18,7 @@ import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.Date; import java.util.Date;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
/** /**
* 新e盾|里程服务实现类 * 新e盾|里程服务实现类
...@@ -58,12 +59,9 @@ public class JourneyService { ...@@ -58,12 +59,9 @@ public class JourneyService {
//从车辆信息中获取创建人信息 //从车辆信息中获取创建人信息
Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn()); Vehicle vehicle = getVehicleBySn(deviceJourneyDTO.getSn());
Long createdBy = null; Long createdBy = Optional.ofNullable(vehicle).map(Vehicle::getCreatedBy).orElse(null);
Long updatedBy = null; Long updatedBy = Optional.ofNullable(vehicle).map(Vehicle::getUpdatedBy).orElse(null);
if (Objects.nonNull(vehicle)) { if(Objects.isNull(vehicle)) {
createdBy = vehicle.getCreatedBy();
updatedBy = vehicle.getUpdatedBy();
} else {
log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn()); log.warn("该设备没有绑定车辆" + deviceJourneyDTO.getSn());
} }
//从关联表从获取关联id //从关联表从获取关联id
......
...@@ -19,6 +19,7 @@ import java.util.Collection; ...@@ -19,6 +19,7 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
...@@ -58,11 +59,9 @@ public class VehicleService { ...@@ -58,11 +59,9 @@ public class VehicleService {
public Long getVdId(String sn) { public Long getVdId(String sn) {
VehicleDevice vehicleDevice = vehicleDeviceMapper.selectVehicleDevcieBySn(sn); VehicleDevice vehicleDevice = vehicleDeviceMapper.selectVehicleDevcieBySn(sn);
Long vnId = null; return Optional.ofNullable(vehicleDevice)
if(Objects.nonNull(vehicleDevice)) { .map(VehicleDevice::getId)
vnId = vehicleDevice.getId(); .orElse(null);
}
return vnId;
} }
/** /**
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!