diff --git a/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java b/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java index 5b87c79..5f8cb36 100644 --- a/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java +++ b/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java @@ -81,10 +81,10 @@ public class ReservationServiceImpl implements ReservationService { .map(Reservation::getDeviceId) .distinct() .toList(); - Map deviceNameMap = deviceMapper.selectList(new LambdaQueryWrapper() + Map deviceNameMap = deviceMapper.selectList(new LambdaQueryWrapper() .in(Device::getId, deviceIds)) .stream() - .collect(Collectors.toMap(Device::getId, Device::getName)); + .collect(Collectors.toMap(Device::getId, Function.identity())); // 获取设备管理员信息 List deviceAdminIDs = reservations.getRecords().stream() diff --git a/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java b/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java index 922a64d..58c3e35 100644 --- a/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java +++ b/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java @@ -1,6 +1,7 @@ package github.benjamin.equipreservebackend.vo; import github.benjamin.equipreservebackend.constant.ReservationStatus; +import github.benjamin.equipreservebackend.entity.Device; import github.benjamin.equipreservebackend.entity.Reservation; import github.benjamin.equipreservebackend.entity.User; import lombok.AllArgsConstructor; @@ -10,6 +11,7 @@ import lombok.NoArgsConstructor; import java.time.LocalDate; import java.time.LocalDateTime; import java.util.Map; +import java.util.Objects; @Data @NoArgsConstructor @@ -25,15 +27,20 @@ public class UserReservationVO { private LocalDateTime createdTime; - public UserReservationVO(Reservation r, Map deviceNameMap, Map deviceAdminMap) { + public UserReservationVO(Reservation r, Map deviceMap, Map deviceAdminMap) { this.reservationId = r.getId().toString(); - this.deviceName = deviceNameMap.get(r.getDeviceId()); + this.deviceName = deviceMap.get(r.getDeviceId()).getName(); this.startTime = r.getStartTime(); this.endTime = r.getEndTime(); this.statusLabel = ReservationStatus.valueOf(r.getStatus()).getLabel(); User deviceAdmin = deviceAdminMap.get(r.getDeviceAdminId()); - this.deviceAdminName = deviceAdmin.getName(); - this.deviceAdminContact = deviceAdmin.getPhone(); + if (Objects.nonNull(deviceAdmin)) { + this.deviceAdminName = deviceAdmin.getName(); + this.deviceAdminContact = deviceAdmin.getPhone(); + } else { + this.deviceAdminName = "该管理员不存在,请联系设备相关人员"; + this.deviceAdminContact = ""; + } this.createdTime = r.getCreatedTime(); }