feat: 实现设备管理员修改预约结束时间接口

This commit is contained in:
BenjaminNH 2025-07-21 21:24:04 +08:00
parent 1b2753c9a3
commit ec9a40be88
5 changed files with 22 additions and 3 deletions

View File

@ -2,11 +2,9 @@ package github.benjamin.equipreservebackend.controller;
import com.alibaba.excel.EasyExcel; import com.alibaba.excel.EasyExcel;
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.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.DeviceStatsVO;
import github.benjamin.equipreservebackend.vo.ReservationStatsVO; import github.benjamin.equipreservebackend.vo.ReservationStatsVO;
import github.benjamin.equipreservebackend.vo.ReservationVO; import github.benjamin.equipreservebackend.vo.ReservationVO;
import github.benjamin.equipreservebackend.vo.UserReservationVO; import github.benjamin.equipreservebackend.vo.UserReservationVO;
@ -22,6 +20,7 @@ import java.nio.charset.StandardCharsets;
import java.time.LocalDate; import java.time.LocalDate;
import java.time.format.DateTimeFormatter; import java.time.format.DateTimeFormatter;
import java.util.List; import java.util.List;
import java.util.Map;
@RestController @RestController
@RequestMapping("/reservation") @RequestMapping("/reservation")
@ -83,4 +82,12 @@ public class ReservationController {
.doWrite(data); .doWrite(data);
} }
@PreAuthorize("hasRole('DEVICE_ADMIN')")
@PostMapping("/endTime/{reservationId}")
public ResponseResult<?> updateEndTime(@PathVariable Long reservationId,
@RequestBody Map<String, String> body) {
LocalDate endTime = LocalDate.parse(body.get("endTime"));
reservationService.updateEndTime(reservationId, endTime);
return ResponseResult.success();
}
} }

View File

@ -22,4 +22,6 @@ public interface ReservationService {
List<ReservationStatsVO> getReservationStats(LocalDate start, LocalDate end); List<ReservationStatsVO> getReservationStats(LocalDate start, LocalDate end);
List<DeviceDetailStatsVO> getDeviceDetailStats(Long deviceId, LocalDate start, LocalDate end); List<DeviceDetailStatsVO> getDeviceDetailStats(Long deviceId, LocalDate start, LocalDate end);
void updateEndTime(Long reservationId, LocalDate endTime);
} }

View File

@ -1,6 +1,7 @@
package github.benjamin.equipreservebackend.service.impl; 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.core.conditions.update.LambdaUpdateWrapper;
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.Device;
@ -165,4 +166,11 @@ public class ReservationServiceImpl implements ReservationService {
.le(Reservation::getEndTime, end) .le(Reservation::getEndTime, end)
.orderByAsc(Reservation::getApplicantName, Reservation::getStartTime)).stream().map(DeviceDetailStatsVO::new).toList(); .orderByAsc(Reservation::getApplicantName, Reservation::getStartTime)).stream().map(DeviceDetailStatsVO::new).toList();
} }
@Override
public void updateEndTime(Long reservationId, LocalDate endTime) {
reservationMapper.update(new LambdaUpdateWrapper<Reservation>()
.eq(Reservation::getId, reservationId)
.set(Reservation::getEndTime, endTime));
}
} }

View File

@ -9,6 +9,8 @@ import java.time.LocalDate;
@Data @Data
public class LeaderApprovalVO { public class LeaderApprovalVO {
@JsonSerialize(using = ToStringSerializer.class)
private Long reservationId;
@JsonSerialize(using = ToStringSerializer.class) @JsonSerialize(using = ToStringSerializer.class)
private Long approvalId; private Long approvalId;
private String applicantName; private String applicantName;

View File

@ -5,7 +5,7 @@
<mapper namespace="github.benjamin.equipreservebackend.mapper.ApprovalMapper"> <mapper namespace="github.benjamin.equipreservebackend.mapper.ApprovalMapper">
<select id="getApproval" 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, r.status SELECT r.id as reservation_id, a.id as approval_id, 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