feat: 实现按设备名称查询

This commit is contained in:
BenjaminNH 2025-06-23 23:37:44 +08:00
parent d443a493d2
commit 44df4b564d
4 changed files with 12 additions and 7 deletions

View File

@ -5,7 +5,7 @@ import lombok.Getter;
@Getter
public enum DeviceReservationState {
FREE("可预约"),
FREE("空闲"),
RESERVED("有预约");
private final String label;

View File

@ -22,9 +22,10 @@ public class DeviceController {
@PreAuthorize("hasRole('USER')")
@GetMapping
public ResponseResult<Page<DeviceUserVO>> getDevices(@RequestParam(defaultValue = "1") Integer page,
@RequestParam(defaultValue = "10") Integer size) {
@RequestParam(defaultValue = "10") Integer size,
@RequestParam(required = false) String name) {
Page<Device> pageRequest = new Page<>(page, size);
Page<DeviceUserVO> res = deviceService.getDeviceVO(pageRequest);
Page<DeviceUserVO> res = deviceService.getDeviceVO(pageRequest, name);
return ResponseResult.success(res);
}

View File

@ -8,7 +8,7 @@ import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
public interface DeviceService {
Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest);
Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest, String name);
void addDevice(Device device);

View File

@ -38,10 +38,14 @@ public class DeviceServiceImpl implements DeviceService {
private final ReservationService reservationService;
@Override
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest) {
Page<Device> devices = deviceMapper.selectPage(pageRequest, new LambdaQueryWrapper<Device>()
public Page<DeviceUserVO> getDeviceVO(Page<Device> pageRequest, String name) {
LambdaQueryWrapper<Device> queryWrapper = new LambdaQueryWrapper<Device>()
.eq(Device::getStatus, DeviceStatus.AVAILABLE)
.orderByAsc(Device::getName));
.orderByAsc(Device::getName);
if (StringUtils.hasText(name)) {
queryWrapper.like(Device::getName, name);
}
Page<Device> devices = deviceMapper.selectPage(pageRequest,queryWrapper);
List<Long> deviceIds = devices.getRecords().stream()
.map(Device::getId)
.toList();