feat: 修复普通用户预约列表显示接口逻辑,优化设备管理员和团队负责人公共接口来逻辑

This commit is contained in:
BenjaminNH 2025-06-30 17:20:26 +08:00
parent efb8295071
commit a89d452074
9 changed files with 27 additions and 37 deletions

View File

@ -7,8 +7,8 @@ public enum ReservationStatus {
PENDING_LEADER("团队负责人审批中"), PENDING_LEADER("团队负责人审批中"),
PENDING_DEVICE_ADMIN("设备负责人审批中"), PENDING_DEVICE_ADMIN("设备负责人审批中"),
APPROVED("通过"), APPROVED("通过"),
APPROVED_ASSIST("需要协助实验"), APPROVED_ASSIST("通过,需要协助实验"),
REJECTED("审批不通过"); REJECTED("不通过");
final String label; final String label;

View File

@ -25,15 +25,15 @@ public class ApprovalController {
return ResponseResult.success(); return ResponseResult.success();
} }
@PreAuthorize("hasRole('LEADER')") @PreAuthorize("hasAnyRole('LEADER', 'DEVICE_ADMIN')")
@GetMapping("/leader/{id}") @GetMapping("/{id}")
public ResponseResult<IPage<LeaderApprovalVO>> getLeaderApproval(@PathVariable("id") Long id, public ResponseResult<IPage<LeaderApprovalVO>> getApproval(@PathVariable("id") Long id,
@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size, @RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String applicantName, @RequestParam(required = false) String applicantName,
@RequestParam(required = false) String deviceName) { @RequestParam(required = false) String deviceName) {
Page<Approval> pageRequest = new Page<>(page, size); Page<Approval> pageRequest = new Page<>(page, size);
return ResponseResult.success(approvalService.getLeaderApproval(pageRequest, id, applicantName, deviceName)); return ResponseResult.success(approvalService.getApproval(pageRequest, id, applicantName, deviceName));
} }
} }

View File

@ -11,7 +11,7 @@ import org.springframework.stereotype.Repository;
@Repository @Repository
public interface ApprovalMapper extends BaseMapper<Approval> { public interface ApprovalMapper extends BaseMapper<Approval> {
IPage<LeaderApprovalVO> getLeaderApproval(Page<?> page, IPage<LeaderApprovalVO> getApproval(Page<?> page,
@Param("approverId") Long approverId, @Param("approverId") Long approverId,
@Param("applicantName") String applicantName, @Param("applicantName") String applicantName,
@Param("deviceName") String deviceName); @Param("deviceName") String deviceName);

View File

@ -9,5 +9,5 @@ import github.benjamin.equipreservebackend.vo.LeaderApprovalVO;
public interface ApprovalService { public interface ApprovalService {
void addApproval(LeaderApprovalDTO dto); void addApproval(LeaderApprovalDTO dto);
IPage<LeaderApprovalVO> getLeaderApproval(Page<Approval> pageRequest, Long userId, String applicantName, String deviceName); IPage<LeaderApprovalVO> getApproval(Page<Approval> pageRequest, Long userId, String applicantName, String deviceName);
} }

View File

@ -38,7 +38,7 @@ public class ApprovalServiceImpl implements ApprovalService {
final ReservationStatus status; final ReservationStatus status;
if (userRoles.stream().anyMatch(r -> r.getCode().equals("LEADER"))) { if (userRoles.stream().anyMatch(r -> r.getCode().equals("LEADER"))) {
step = ApprovalStep.LEADER; step = ApprovalStep.LEADER;
status = dto.getIsApprove() ? ReservationStatus.APPROVED : ReservationStatus.REJECTED; status = dto.getIsApprove() ? ReservationStatus.PENDING_DEVICE_ADMIN : ReservationStatus.REJECTED;
} else if (userRoles.stream().anyMatch(r -> r.getCode().equals("DEVICE_ADMIN"))){ } else if (userRoles.stream().anyMatch(r -> r.getCode().equals("DEVICE_ADMIN"))){
step = ApprovalStep.DEVICE_ADMIN; step = ApprovalStep.DEVICE_ADMIN;
if (dto.getIsApprove()) { if (dto.getIsApprove()) {
@ -62,7 +62,7 @@ public class ApprovalServiceImpl implements ApprovalService {
} }
@Override @Override
public IPage<LeaderApprovalVO> getLeaderApproval(Page<Approval> pageRequest, Long userId, String applicantName, String deviceName) { public IPage<LeaderApprovalVO> getApproval(Page<Approval> pageRequest, Long userId, String applicantName, String deviceName) {
return approvalMapper.getLeaderApproval(pageRequest, userId, applicantName, deviceName); return approvalMapper.getApproval(pageRequest, userId, applicantName, deviceName);
} }
} }

View File

@ -90,19 +90,14 @@ public class ReservationServiceImpl implements ReservationService {
Page<UserReservationVO> res = PageUtil.copyPage(reservations); Page<UserReservationVO> res = PageUtil.copyPage(reservations);
List<UserReservationVO> vos; List<UserReservationVO> vos;
if (deviceAdminIDs.isEmpty()) { Map<Long, User> deviceAdminMap = userMapper.selectList(new LambdaQueryWrapper<User>()
vos = reservations.getRecords().stream() .in(User::getId, deviceAdminIDs))
.map(reservation -> new UserReservationVO(reservation, deviceNameMap)) .stream()
.toList(); .collect(Collectors.toMap(User::getId, Function.identity()));
} else {
Map<Long, User> deviceAdminMap = userMapper.selectList(new LambdaQueryWrapper<User>() vos = reservations.getRecords().stream()
.in(User::getId, deviceAdminIDs)) .map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap))
.stream() .toList();
.collect(Collectors.toMap(User::getId, Function.identity()));
vos = reservations.getRecords().stream()
.map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap))
.toList();
}
res.setRecords(vos); res.setRecords(vos);
return res; return res;
} }

View File

@ -18,5 +18,6 @@ public class LeaderApprovalVO {
private LocalDate startTime; private LocalDate startTime;
private LocalDate endTime; private LocalDate endTime;
private Integer decision; private Integer decision;
private String status;
} }

View File

@ -24,23 +24,17 @@ public class UserReservationVO {
private String deviceAdminContact; private String deviceAdminContact;
private LocalDateTime createdTime; private LocalDateTime createdTime;
public UserReservationVO(Reservation r, Map<Long, String> deviceNameMap) {
public UserReservationVO(Reservation r, Map<Long, String> deviceNameMap, Map<Long, User> deviceAdminMap) {
this.reservationId = r.getId().toString(); this.reservationId = r.getId().toString();
this.deviceName = deviceNameMap.get(r.getDeviceId()); this.deviceName = deviceNameMap.get(r.getDeviceId());
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());
this.deviceAdminName = deviceAdmin.getName();
this.deviceAdminContact = deviceAdmin.getPhone();
this.createdTime = r.getCreatedTime(); this.createdTime = r.getCreatedTime();
}
public UserReservationVO(Reservation r, Map<Long, String> deviceNameMap, Map<Long, User> deviceAdminMap) {
this(r, deviceNameMap);
ReservationStatus status = ReservationStatus.valueOf(r.getStatus());
if (status == ReservationStatus.APPROVED_ASSIST) {
User deviceAdmin = deviceAdminMap.get(r.getDeviceAdminId());
this.deviceAdminName = deviceAdmin.getName();
this.deviceAdminContact = deviceAdmin.getPhone();
}
} }
} }

View File

@ -4,8 +4,8 @@
<mapper namespace="github.benjamin.equipreservebackend.mapper.ApprovalMapper"> <mapper namespace="github.benjamin.equipreservebackend.mapper.ApprovalMapper">
<select id="getLeaderApproval" resultType="github.benjamin.equipreservebackend.vo.LeaderApprovalVO"> <select id="getApproval" resultType="github.benjamin.equipreservebackend.vo.LeaderApprovalVO">
SELECT a.id as approvalId, r.applicant_name, r.applicant_team, r.applicant_contact, d.name as deviceName, r.start_time, r.end_time, a.decision SELECT a.id as approvalId, r.applicant_name, r.applicant_team, r.applicant_contact, d.name as deviceName, r.start_time, r.end_time, a.decision, r.status
FROM approvals a FROM approvals a
LEFT JOIN reservations r ON a.reservation_id = r.id LEFT JOIN reservations r ON a.reservation_id = r.id
LEFT JOIN devices d ON r.device_id = d.id LEFT JOIN devices d ON r.device_id = d.id