From 17b2f907652f04cd1dbe214ce104277e6fee431f Mon Sep 17 00:00:00 2001 From: BenjaminNH <1249376374@qq.com> Date: Fri, 4 Jul 2025 23:25:47 +0800 Subject: [PATCH] =?UTF-8?q?bugfix:=20=E4=BF=AE=E5=A4=8D=E6=9F=A5=E8=AF=A2?= =?UTF-8?q?=E9=A2=84=E7=BA=A6=E8=AE=BE=E5=A4=87=E7=AE=A1=E7=90=86=E5=91=98?= =?UTF-8?q?=E8=A2=AB=E5=88=A0=E9=99=A4=E6=97=B6=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/impl/ReservationServiceImpl.java | 4 ++-- .../equipreservebackend/vo/UserReservationVO.java | 15 +++++++++++---- 2 files changed, 13 insertions(+), 6 deletions(-) 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(); }