diff --git a/src/main/java/github/benjamin/equipreservebackend/mapper/UserMapper.java b/src/main/java/github/benjamin/equipreservebackend/mapper/UserMapper.java index 7358f94..e5105a2 100644 --- a/src/main/java/github/benjamin/equipreservebackend/mapper/UserMapper.java +++ b/src/main/java/github/benjamin/equipreservebackend/mapper/UserMapper.java @@ -2,8 +2,16 @@ package github.benjamin.equipreservebackend.mapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper; import github.benjamin.equipreservebackend.entity.User; +import org.apache.ibatis.annotations.MapKey; import org.springframework.stereotype.Repository; +import java.util.List; +import java.util.Map; + @Repository public interface UserMapper extends BaseMapper { + + @MapKey("teamId") + Map selectLeaderByTeamIds(List teamIds); + } 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 bae7cef..b4d0eba 100644 --- a/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java +++ b/src/main/java/github/benjamin/equipreservebackend/service/impl/ReservationServiceImpl.java @@ -86,6 +86,10 @@ public class ReservationServiceImpl implements ReservationService { .stream() .collect(Collectors.toMap(Device::getId, Function.identity())); + List teamIds = deviceNameMap.values().stream().map(Device::getTeamId).toList(); + + Map teamLeaderMap = userMapper.selectLeaderByTeamIds(teamIds); + // 获取设备管理员信息 List deviceAdminIDs = reservations.getRecords().stream() .map(Reservation::getDeviceAdminId) @@ -93,7 +97,6 @@ public class ReservationServiceImpl implements ReservationService { .distinct() .toList(); - List vos; Map deviceAdminMap = userMapper.selectList(new LambdaQueryWrapper() .in(User::getId, deviceAdminIDs)) @@ -101,7 +104,7 @@ public class ReservationServiceImpl implements ReservationService { .collect(Collectors.toMap(User::getId, Function.identity())); vos = reservations.getRecords().stream() - .map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap)) + .map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap, teamLeaderMap)) .toList(); res.setRecords(vos); return res; diff --git a/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java b/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java index 58c3e35..9fa38f7 100644 --- a/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java +++ b/src/main/java/github/benjamin/equipreservebackend/vo/UserReservationVO.java @@ -22,12 +22,13 @@ public class UserReservationVO { private LocalDate startTime; private LocalDate endTime; private String statusLabel; + private String deviceLeaderName; + private String deviceLeaderContact; private String deviceAdminName; private String deviceAdminContact; private LocalDateTime createdTime; - - public UserReservationVO(Reservation r, Map deviceMap, Map deviceAdminMap) { + public UserReservationVO(Reservation r, Map deviceMap, Map deviceAdminMap, Map teamLeaderMap) { this.reservationId = r.getId().toString(); this.deviceName = deviceMap.get(r.getDeviceId()).getName(); this.startTime = r.getStartTime(); @@ -41,6 +42,14 @@ public class UserReservationVO { this.deviceAdminName = "该管理员不存在,请联系设备相关人员"; this.deviceAdminContact = ""; } + User teamLeader = teamLeaderMap.get(deviceMap.get(r.getDeviceId()).getTeamId()); + if (Objects.nonNull(teamLeader)) { + this.deviceLeaderName = teamLeader.getName(); + this.deviceLeaderContact = teamLeader.getPhone(); + } else { + this.deviceLeaderName = "该负责人不存在,请联系设备相关人员"; + this.deviceLeaderContact = ""; + } this.createdTime = r.getCreatedTime(); } diff --git a/src/main/resources/mapper/UserMapper.xml b/src/main/resources/mapper/UserMapper.xml new file mode 100644 index 0000000..1d29276 --- /dev/null +++ b/src/main/resources/mapper/UserMapper.xml @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file