feat: 修复普通用户预约列表显示接口逻辑,优化设备管理员和团队负责人公共接口来逻辑
This commit is contained in:
parent
efb8295071
commit
a89d452074
@ -7,8 +7,8 @@ public enum ReservationStatus {
|
||||
PENDING_LEADER("团队负责人审批中"),
|
||||
PENDING_DEVICE_ADMIN("设备负责人审批中"),
|
||||
APPROVED("通过"),
|
||||
APPROVED_ASSIST("需要协助实验"),
|
||||
REJECTED("审批不通过");
|
||||
APPROVED_ASSIST("通过,需要协助实验"),
|
||||
REJECTED("不通过");
|
||||
|
||||
final String label;
|
||||
|
||||
|
@ -25,15 +25,15 @@ public class ApprovalController {
|
||||
return ResponseResult.success();
|
||||
}
|
||||
|
||||
@PreAuthorize("hasRole('LEADER')")
|
||||
@GetMapping("/leader/{id}")
|
||||
public ResponseResult<IPage<LeaderApprovalVO>> getLeaderApproval(@PathVariable("id") Long id,
|
||||
@PreAuthorize("hasAnyRole('LEADER', 'DEVICE_ADMIN')")
|
||||
@GetMapping("/{id}")
|
||||
public ResponseResult<IPage<LeaderApprovalVO>> getApproval(@PathVariable("id") Long id,
|
||||
@RequestParam(defaultValue = "1") Integer page,
|
||||
@RequestParam(defaultValue = "10") Integer size,
|
||||
@RequestParam(required = false) String applicantName,
|
||||
@RequestParam(required = false) String deviceName) {
|
||||
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));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,7 +11,7 @@ import org.springframework.stereotype.Repository;
|
||||
@Repository
|
||||
public interface ApprovalMapper extends BaseMapper<Approval> {
|
||||
|
||||
IPage<LeaderApprovalVO> getLeaderApproval(Page<?> page,
|
||||
IPage<LeaderApprovalVO> getApproval(Page<?> page,
|
||||
@Param("approverId") Long approverId,
|
||||
@Param("applicantName") String applicantName,
|
||||
@Param("deviceName") String deviceName);
|
||||
|
@ -9,5 +9,5 @@ import github.benjamin.equipreservebackend.vo.LeaderApprovalVO;
|
||||
public interface ApprovalService {
|
||||
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);
|
||||
}
|
||||
|
@ -38,7 +38,7 @@ public class ApprovalServiceImpl implements ApprovalService {
|
||||
final ReservationStatus status;
|
||||
if (userRoles.stream().anyMatch(r -> r.getCode().equals("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"))){
|
||||
step = ApprovalStep.DEVICE_ADMIN;
|
||||
if (dto.getIsApprove()) {
|
||||
@ -62,7 +62,7 @@ public class ApprovalServiceImpl implements ApprovalService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public IPage<LeaderApprovalVO> getLeaderApproval(Page<Approval> pageRequest, Long userId, String applicantName, String deviceName) {
|
||||
return approvalMapper.getLeaderApproval(pageRequest, userId, applicantName, deviceName);
|
||||
public IPage<LeaderApprovalVO> getApproval(Page<Approval> pageRequest, Long userId, String applicantName, String deviceName) {
|
||||
return approvalMapper.getApproval(pageRequest, userId, applicantName, deviceName);
|
||||
}
|
||||
}
|
||||
|
@ -90,19 +90,14 @@ public class ReservationServiceImpl implements ReservationService {
|
||||
|
||||
Page<UserReservationVO> res = PageUtil.copyPage(reservations);
|
||||
List<UserReservationVO> vos;
|
||||
if (deviceAdminIDs.isEmpty()) {
|
||||
vos = reservations.getRecords().stream()
|
||||
.map(reservation -> new UserReservationVO(reservation, deviceNameMap))
|
||||
.toList();
|
||||
} else {
|
||||
Map<Long, User> deviceAdminMap = userMapper.selectList(new LambdaQueryWrapper<User>()
|
||||
.in(User::getId, deviceAdminIDs))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(User::getId, Function.identity()));
|
||||
vos = reservations.getRecords().stream()
|
||||
.map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap))
|
||||
.toList();
|
||||
}
|
||||
Map<Long, User> deviceAdminMap = userMapper.selectList(new LambdaQueryWrapper<User>()
|
||||
.in(User::getId, deviceAdminIDs))
|
||||
.stream()
|
||||
.collect(Collectors.toMap(User::getId, Function.identity()));
|
||||
|
||||
vos = reservations.getRecords().stream()
|
||||
.map(reservation -> new UserReservationVO(reservation, deviceNameMap, deviceAdminMap))
|
||||
.toList();
|
||||
res.setRecords(vos);
|
||||
return res;
|
||||
}
|
||||
|
@ -18,5 +18,6 @@ public class LeaderApprovalVO {
|
||||
private LocalDate startTime;
|
||||
private LocalDate endTime;
|
||||
private Integer decision;
|
||||
private String status;
|
||||
|
||||
}
|
||||
|
@ -24,23 +24,17 @@ public class UserReservationVO {
|
||||
private String deviceAdminContact;
|
||||
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.deviceName = deviceNameMap.get(r.getDeviceId());
|
||||
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();
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -4,8 +4,8 @@
|
||||
|
||||
<mapper namespace="github.benjamin.equipreservebackend.mapper.ApprovalMapper">
|
||||
|
||||
<select id="getLeaderApproval" 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 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, r.status
|
||||
FROM approvals a
|
||||
LEFT JOIN reservations r ON a.reservation_id = r.id
|
||||
LEFT JOIN devices d ON r.device_id = d.id
|
||||
|
Loading…
x
Reference in New Issue
Block a user