feat: 实现团队负责人查询待审批预约接口
This commit is contained in:
parent
71bd2bb31b
commit
7b7076858c
@ -4,6 +4,7 @@ import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|||||||
import github.benjamin.equipreservebackend.entity.Reservation;
|
import github.benjamin.equipreservebackend.entity.Reservation;
|
||||||
import github.benjamin.equipreservebackend.response.ResponseResult;
|
import github.benjamin.equipreservebackend.response.ResponseResult;
|
||||||
import github.benjamin.equipreservebackend.service.ReservationService;
|
import github.benjamin.equipreservebackend.service.ReservationService;
|
||||||
|
import github.benjamin.equipreservebackend.vo.ReservationVO;
|
||||||
import github.benjamin.equipreservebackend.vo.UserReservationVO;
|
import github.benjamin.equipreservebackend.vo.UserReservationVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
@ -26,11 +27,19 @@ public class ReservationController {
|
|||||||
@PreAuthorize("hasRole('USER')")
|
@PreAuthorize("hasRole('USER')")
|
||||||
@GetMapping("/{userId}")
|
@GetMapping("/{userId}")
|
||||||
public ResponseResult<Page<UserReservationVO>> getUserReservation(@PathVariable("userId") Long userId,
|
public ResponseResult<Page<UserReservationVO>> getUserReservation(@PathVariable("userId") Long userId,
|
||||||
@RequestParam(defaultValue = "10") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer size) {
|
@RequestParam(defaultValue = "10") Integer size) {
|
||||||
Page<Reservation> pageRequest = new Page<>(page, size);
|
Page<Reservation> pageRequest = new Page<>(page, size);
|
||||||
Page<UserReservationVO> res = reservationService.getUserReservationVO(userId, pageRequest);
|
Page<UserReservationVO> res = reservationService.getUserReservationVO(userId, pageRequest);
|
||||||
return ResponseResult.success(res);
|
return ResponseResult.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PreAuthorize("hasRole('LEADER')")
|
||||||
|
@GetMapping("/leader/{id}")
|
||||||
|
public ResponseResult<Page<ReservationVO>> getLeaderReservation(@PathVariable("id") Long id,
|
||||||
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
|
@RequestParam(defaultValue = "10") Integer size) {
|
||||||
|
return ResponseResult.success(reservationService.getReservationVO(id, page, size));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package github.benjamin.equipreservebackend.service;
|
|||||||
|
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import github.benjamin.equipreservebackend.entity.Reservation;
|
import github.benjamin.equipreservebackend.entity.Reservation;
|
||||||
|
import github.benjamin.equipreservebackend.vo.ReservationVO;
|
||||||
import github.benjamin.equipreservebackend.vo.TimeRangeVO;
|
import github.benjamin.equipreservebackend.vo.TimeRangeVO;
|
||||||
import github.benjamin.equipreservebackend.vo.UserReservationVO;
|
import github.benjamin.equipreservebackend.vo.UserReservationVO;
|
||||||
|
|
||||||
@ -16,4 +17,6 @@ public interface ReservationService {
|
|||||||
Page<UserReservationVO> getUserReservationVO(Long userId, Page<Reservation> pageRequest);
|
Page<UserReservationVO> getUserReservationVO(Long userId, Page<Reservation> pageRequest);
|
||||||
|
|
||||||
List<TimeRangeVO> getUnavailableTimes(Long id);
|
List<TimeRangeVO> getUnavailableTimes(Long id);
|
||||||
|
|
||||||
|
Page<ReservationVO> getReservationVO(Long userId, Integer page, Integer size);
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import github.benjamin.equipreservebackend.mapper.TeamMapper;
|
|||||||
import github.benjamin.equipreservebackend.mapper.UserMapper;
|
import github.benjamin.equipreservebackend.mapper.UserMapper;
|
||||||
import github.benjamin.equipreservebackend.service.ReservationService;
|
import github.benjamin.equipreservebackend.service.ReservationService;
|
||||||
import github.benjamin.equipreservebackend.utils.PageUtil;
|
import github.benjamin.equipreservebackend.utils.PageUtil;
|
||||||
|
import github.benjamin.equipreservebackend.vo.ReservationVO;
|
||||||
import github.benjamin.equipreservebackend.vo.TimeRangeVO;
|
import github.benjamin.equipreservebackend.vo.TimeRangeVO;
|
||||||
import github.benjamin.equipreservebackend.vo.UserReservationVO;
|
import github.benjamin.equipreservebackend.vo.UserReservationVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
@ -20,7 +21,6 @@ import org.springframework.beans.factory.annotation.Value;
|
|||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
@ -121,4 +121,23 @@ public class ReservationServiceImpl implements ReservationService {
|
|||||||
.map(r -> new TimeRangeVO(r.getStartTime(), r.getEndTime()))
|
.map(r -> new TimeRangeVO(r.getStartTime(), r.getEndTime()))
|
||||||
.toList();
|
.toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Page<ReservationVO> getReservationVO(Long userId, Integer page, Integer size) {
|
||||||
|
User user = userMapper.selectById(userId);
|
||||||
|
List<Device> devices = deviceMapper.selectList(new LambdaQueryWrapper<Device>()
|
||||||
|
.eq(Device::getTeamId, user.getTeamId())
|
||||||
|
.select());
|
||||||
|
List<Long> deviceIds = devices.stream().map(Device::getId).toList();
|
||||||
|
Map<Long, Device> deviceMap = devices.stream().collect(Collectors.toMap(Device::getId, Function.identity()));
|
||||||
|
Page<Reservation> reservationPage = reservationMapper.selectPage(new Page<>(page, size), new LambdaQueryWrapper<Reservation>()
|
||||||
|
.in(Reservation::getDeviceId, deviceIds)
|
||||||
|
.eq(Reservation::getStatus, ReservationStatus.PENDING_LEADER)
|
||||||
|
.orderByDesc(Reservation::getCreatedTime));
|
||||||
|
Page<ReservationVO> res = PageUtil.copyPage(reservationPage);
|
||||||
|
res.setRecords(reservationPage.getRecords().stream()
|
||||||
|
.map(r -> new ReservationVO(r, deviceMap.get(r.getDeviceId())))
|
||||||
|
.toList());
|
||||||
|
return res;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,42 @@
|
|||||||
|
package github.benjamin.equipreservebackend.vo;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StringSerializer;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
|
||||||
|
import github.benjamin.equipreservebackend.entity.Device;
|
||||||
|
import github.benjamin.equipreservebackend.entity.Reservation;
|
||||||
|
import github.benjamin.equipreservebackend.entity.User;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class ReservationVO {
|
||||||
|
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long reservationId;
|
||||||
|
private String applicantName;
|
||||||
|
private String applicantTeam;
|
||||||
|
private String applicantContact;
|
||||||
|
@JsonSerialize(using = ToStringSerializer.class)
|
||||||
|
private Long deviceId;
|
||||||
|
private String deviceName;
|
||||||
|
private LocalDate startTime;
|
||||||
|
private LocalDate endTime;
|
||||||
|
|
||||||
|
public ReservationVO(Reservation r, Device d) {
|
||||||
|
this.reservationId = r.getId();
|
||||||
|
this.applicantName = r.getApplicantName();
|
||||||
|
this.applicantTeam = r.getApplicantTeam();
|
||||||
|
this.applicantContact = r.getApplicantContact();
|
||||||
|
this.deviceId = d.getId();
|
||||||
|
this.deviceName = d.getName();
|
||||||
|
this.startTime = r.getStartTime();
|
||||||
|
this.endTime = r.getEndTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user