bugfix: 修复查询预约设备管理员被删除时报错

This commit is contained in:
BenjaminNH 2025-07-04 23:25:47 +08:00
parent 674f320424
commit 17b2f90765
2 changed files with 13 additions and 6 deletions

View File

@ -81,10 +81,10 @@ public class ReservationServiceImpl implements ReservationService {
.map(Reservation::getDeviceId) .map(Reservation::getDeviceId)
.distinct() .distinct()
.toList(); .toList();
Map<Long, String> deviceNameMap = deviceMapper.selectList(new LambdaQueryWrapper<Device>() Map<Long, Device> deviceNameMap = deviceMapper.selectList(new LambdaQueryWrapper<Device>()
.in(Device::getId, deviceIds)) .in(Device::getId, deviceIds))
.stream() .stream()
.collect(Collectors.toMap(Device::getId, Device::getName)); .collect(Collectors.toMap(Device::getId, Function.identity()));
// 获取设备管理员信息 // 获取设备管理员信息
List<Long> deviceAdminIDs = reservations.getRecords().stream() List<Long> deviceAdminIDs = reservations.getRecords().stream()

View File

@ -1,6 +1,7 @@
package github.benjamin.equipreservebackend.vo; package github.benjamin.equipreservebackend.vo;
import github.benjamin.equipreservebackend.constant.ReservationStatus; import github.benjamin.equipreservebackend.constant.ReservationStatus;
import github.benjamin.equipreservebackend.entity.Device;
import github.benjamin.equipreservebackend.entity.Reservation; import github.benjamin.equipreservebackend.entity.Reservation;
import github.benjamin.equipreservebackend.entity.User; import github.benjamin.equipreservebackend.entity.User;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
@ -10,6 +11,7 @@ import lombok.NoArgsConstructor;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import java.util.Map; import java.util.Map;
import java.util.Objects;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@ -25,15 +27,20 @@ public class UserReservationVO {
private LocalDateTime createdTime; private LocalDateTime createdTime;
public UserReservationVO(Reservation r, Map<Long, String> deviceNameMap, Map<Long, User> deviceAdminMap) { public UserReservationVO(Reservation r, Map<Long, Device> deviceMap, Map<Long, User> deviceAdminMap) {
this.reservationId = r.getId().toString(); this.reservationId = r.getId().toString();
this.deviceName = deviceNameMap.get(r.getDeviceId()); this.deviceName = deviceMap.get(r.getDeviceId()).getName();
this.startTime = r.getStartTime(); this.startTime = r.getStartTime();
this.endTime = r.getEndTime(); this.endTime = r.getEndTime();
this.statusLabel = ReservationStatus.valueOf(r.getStatus()).getLabel(); this.statusLabel = ReservationStatus.valueOf(r.getStatus()).getLabel();
User deviceAdmin = deviceAdminMap.get(r.getDeviceAdminId()); User deviceAdmin = deviceAdminMap.get(r.getDeviceAdminId());
if (Objects.nonNull(deviceAdmin)) {
this.deviceAdminName = deviceAdmin.getName(); this.deviceAdminName = deviceAdmin.getName();
this.deviceAdminContact = deviceAdmin.getPhone(); this.deviceAdminContact = deviceAdmin.getPhone();
} else {
this.deviceAdminName = "该管理员不存在,请联系设备相关人员";
this.deviceAdminContact = "";
}
this.createdTime = r.getCreatedTime(); this.createdTime = r.getCreatedTime();
} }