Commit 9af10910 by 向延琳

修改null判断

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