feat: 修改团队负责人审核预约接口实现与设备管理员共用
This commit is contained in:
parent
caf903114e
commit
efb8295071
@ -18,8 +18,8 @@ public class ApprovalController {
|
|||||||
|
|
||||||
private final ApprovalService approvalService;
|
private final ApprovalService approvalService;
|
||||||
|
|
||||||
@PreAuthorize("hasRole('LEADER')")
|
@PreAuthorize("hasAnyRole('LEADER', 'DEVICE_ADMIN')")
|
||||||
@PostMapping("/leader")
|
@PostMapping
|
||||||
public ResponseResult<?> addApproval(@RequestBody LeaderApprovalDTO dto) {
|
public ResponseResult<?> addApproval(@RequestBody LeaderApprovalDTO dto) {
|
||||||
approvalService.addApproval(dto);
|
approvalService.addApproval(dto);
|
||||||
return ResponseResult.success();
|
return ResponseResult.success();
|
||||||
|
@ -34,9 +34,9 @@ public class ReservationController {
|
|||||||
return ResponseResult.success(res);
|
return ResponseResult.success(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreAuthorize("hasRole('LEADER')")
|
@PreAuthorize("hasAnyRole('LEADER', 'DEVICE_ADMIN')")
|
||||||
@GetMapping("/leader/{id}")
|
@GetMapping("/approval/{id}")
|
||||||
public ResponseResult<Page<ReservationVO>> getLeaderReservation(@PathVariable("id") Long id,
|
public ResponseResult<Page<ReservationVO>> getReservation(@PathVariable("id") Long id,
|
||||||
@RequestParam(defaultValue = "1") Integer page,
|
@RequestParam(defaultValue = "1") Integer page,
|
||||||
@RequestParam(defaultValue = "10") Integer size) {
|
@RequestParam(defaultValue = "10") Integer size) {
|
||||||
return ResponseResult.success(reservationService.getReservationVO(id, page, size));
|
return ResponseResult.success(reservationService.getReservationVO(id, page, size));
|
||||||
|
@ -5,8 +5,9 @@ import lombok.Data;
|
|||||||
@Data
|
@Data
|
||||||
public class LeaderApprovalDTO {
|
public class LeaderApprovalDTO {
|
||||||
|
|
||||||
private Long leaderId;
|
private Long userId;
|
||||||
private Long reservationId;
|
private Long reservationId;
|
||||||
private Boolean isApprove;
|
private Boolean isApprove;
|
||||||
|
private Boolean needAssist;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,13 +9,18 @@ import github.benjamin.equipreservebackend.constant.ReservationStatus;
|
|||||||
import github.benjamin.equipreservebackend.dto.LeaderApprovalDTO;
|
import github.benjamin.equipreservebackend.dto.LeaderApprovalDTO;
|
||||||
import github.benjamin.equipreservebackend.entity.Approval;
|
import github.benjamin.equipreservebackend.entity.Approval;
|
||||||
import github.benjamin.equipreservebackend.entity.Reservation;
|
import github.benjamin.equipreservebackend.entity.Reservation;
|
||||||
|
import github.benjamin.equipreservebackend.entity.Role;
|
||||||
|
import github.benjamin.equipreservebackend.exception.ApiException;
|
||||||
import github.benjamin.equipreservebackend.mapper.ApprovalMapper;
|
import github.benjamin.equipreservebackend.mapper.ApprovalMapper;
|
||||||
import github.benjamin.equipreservebackend.mapper.ReservationMapper;
|
import github.benjamin.equipreservebackend.mapper.ReservationMapper;
|
||||||
|
import github.benjamin.equipreservebackend.mapper.RoleMapper;
|
||||||
import github.benjamin.equipreservebackend.service.ApprovalService;
|
import github.benjamin.equipreservebackend.service.ApprovalService;
|
||||||
import github.benjamin.equipreservebackend.vo.LeaderApprovalVO;
|
import github.benjamin.equipreservebackend.vo.LeaderApprovalVO;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
public class ApprovalServiceImpl implements ApprovalService {
|
public class ApprovalServiceImpl implements ApprovalService {
|
||||||
@ -24,18 +29,36 @@ public class ApprovalServiceImpl implements ApprovalService {
|
|||||||
|
|
||||||
private final ReservationMapper reservationMapper;
|
private final ReservationMapper reservationMapper;
|
||||||
|
|
||||||
|
private final RoleMapper roleMapper;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addApproval(LeaderApprovalDTO dto) {
|
public void addApproval(LeaderApprovalDTO dto) {
|
||||||
|
List<Role> userRoles = roleMapper.selectRoleByUserId(dto.getUserId());
|
||||||
|
final ApprovalStep step;
|
||||||
|
final ReservationStatus status;
|
||||||
|
if (userRoles.stream().anyMatch(r -> r.getCode().equals("LEADER"))) {
|
||||||
|
step = ApprovalStep.LEADER;
|
||||||
|
status = dto.getIsApprove() ? ReservationStatus.APPROVED : ReservationStatus.REJECTED;
|
||||||
|
} else if (userRoles.stream().anyMatch(r -> r.getCode().equals("DEVICE_ADMIN"))){
|
||||||
|
step = ApprovalStep.DEVICE_ADMIN;
|
||||||
|
if (dto.getIsApprove()) {
|
||||||
|
status = dto.getNeedAssist() ? ReservationStatus.APPROVED_ASSIST : ReservationStatus.APPROVED;
|
||||||
|
} else {
|
||||||
|
status = ReservationStatus.REJECTED;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new ApiException("用户角色不匹配,请核对或联系开发人员");
|
||||||
|
}
|
||||||
Approval approval = Approval.builder()
|
Approval approval = Approval.builder()
|
||||||
.approverId(dto.getLeaderId())
|
.approverId(dto.getUserId())
|
||||||
.reservationId(dto.getReservationId())
|
.reservationId(dto.getReservationId())
|
||||||
.step(ApprovalStep.LEADER.getStep())
|
.step(step.getStep())
|
||||||
.decision(dto.getIsApprove() ? 1 : 0)
|
.decision(dto.getIsApprove() ? 1 : 0)
|
||||||
.build();
|
.build();
|
||||||
approvalMapper.insert(approval);
|
approvalMapper.insert(approval);
|
||||||
reservationMapper.update(new LambdaUpdateWrapper<Reservation>()
|
reservationMapper.update(new LambdaUpdateWrapper<Reservation>()
|
||||||
.eq(Reservation::getId, dto.getReservationId())
|
.eq(Reservation::getId, dto.getReservationId())
|
||||||
.set(Reservation::getStatus, dto.getIsApprove() ? ReservationStatus.PENDING_DEVICE_ADMIN : ReservationStatus.REJECTED));
|
.set(Reservation::getStatus, status));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -3,14 +3,9 @@ package github.benjamin.equipreservebackend.service.impl;
|
|||||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import github.benjamin.equipreservebackend.constant.ReservationStatus;
|
import github.benjamin.equipreservebackend.constant.ReservationStatus;
|
||||||
import github.benjamin.equipreservebackend.entity.Device;
|
import github.benjamin.equipreservebackend.entity.*;
|
||||||
import github.benjamin.equipreservebackend.entity.Reservation;
|
import github.benjamin.equipreservebackend.exception.ApiException;
|
||||||
import github.benjamin.equipreservebackend.entity.Team;
|
import github.benjamin.equipreservebackend.mapper.*;
|
||||||
import github.benjamin.equipreservebackend.entity.User;
|
|
||||||
import github.benjamin.equipreservebackend.mapper.DeviceMapper;
|
|
||||||
import github.benjamin.equipreservebackend.mapper.ReservationMapper;
|
|
||||||
import github.benjamin.equipreservebackend.mapper.TeamMapper;
|
|
||||||
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.ReservationVO;
|
||||||
@ -39,6 +34,8 @@ public class ReservationServiceImpl implements ReservationService {
|
|||||||
|
|
||||||
private final TeamMapper teamMapper;
|
private final TeamMapper teamMapper;
|
||||||
|
|
||||||
|
private final RoleMapper roleMapper;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 未来days天内有预约的设备显示为“有预约”
|
* 未来days天内有预约的设备显示为“有预约”
|
||||||
*/
|
*/
|
||||||
@ -128,11 +125,21 @@ public class ReservationServiceImpl implements ReservationService {
|
|||||||
List<Device> devices = deviceMapper.selectList(new LambdaQueryWrapper<Device>()
|
List<Device> devices = deviceMapper.selectList(new LambdaQueryWrapper<Device>()
|
||||||
.eq(Device::getTeamId, user.getTeamId())
|
.eq(Device::getTeamId, user.getTeamId())
|
||||||
.select());
|
.select());
|
||||||
|
List<Role> userRole = roleMapper.selectRoleByUserId(userId);
|
||||||
|
ReservationStatus status;
|
||||||
|
if (userRole.stream().anyMatch(r -> r.getCode().equals("LEADER"))) {
|
||||||
|
status = ReservationStatus.PENDING_LEADER;
|
||||||
|
} else if (userRole.stream().anyMatch(r -> r.getCode().equals("DEVICE_ADMIN"))) {
|
||||||
|
status = ReservationStatus.PENDING_DEVICE_ADMIN;
|
||||||
|
} else {
|
||||||
|
throw new ApiException("用户角色不正确,请检查或联系开发人员");
|
||||||
|
}
|
||||||
|
|
||||||
List<Long> deviceIds = devices.stream().map(Device::getId).toList();
|
List<Long> deviceIds = devices.stream().map(Device::getId).toList();
|
||||||
Map<Long, Device> deviceMap = devices.stream().collect(Collectors.toMap(Device::getId, Function.identity()));
|
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>()
|
Page<Reservation> reservationPage = reservationMapper.selectPage(new Page<>(page, size), new LambdaQueryWrapper<Reservation>()
|
||||||
.in(Reservation::getDeviceId, deviceIds)
|
.in(Reservation::getDeviceId, deviceIds)
|
||||||
.eq(Reservation::getStatus, ReservationStatus.PENDING_LEADER)
|
.eq(Reservation::getStatus, status)
|
||||||
.orderByDesc(Reservation::getCreatedTime));
|
.orderByDesc(Reservation::getCreatedTime));
|
||||||
Page<ReservationVO> res = PageUtil.copyPage(reservationPage);
|
Page<ReservationVO> res = PageUtil.copyPage(reservationPage);
|
||||||
res.setRecords(reservationPage.getRecords().stream()
|
res.setRecords(reservationPage.getRecords().stream()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user