fix: 设备即将过期,功能优化完善。

This commit is contained in:
tianyongbao
2026-05-30 19:33:00 +08:00
parent 00d7a64464
commit 4dcc9cd7d0
2 changed files with 49 additions and 22 deletions

View File

@@ -1,6 +1,7 @@
package com.intc.fishery.controller; package com.intc.fishery.controller;
import java.util.List; import java.util.List;
import java.util.ArrayList;
import com.intc.fishery.domain.bo.*; import com.intc.fishery.domain.bo.*;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
@@ -824,46 +825,66 @@ public class DeviceController extends BaseController {
} }
/** /**
* 查询即将到期设备列表 * 查询设备过期列表
* 返回当前时间到未来1个月内将要到期的设备 * 返回已过期和即将过期未最1个月内的设备
* *
* @param rootUserId 用户ID * @param rootUserId 用户ID
* @return 即将到期的设备列表 * @return 设备过期列表(包含已过期和即将过期)
*/ */
@GetMapping("/list_device_dead") @GetMapping("/list_device_dead")
public R<List<PublicDeviceDeadInfo>> queryListDeviceDead( public R<List<PublicDeviceDeadInfo>> queryListDeviceDead(
@RequestParam("rootUserId") Long rootUserId) { @RequestParam("rootUserId") Long rootUserId) {
// 计算时间范围:当前时间到未1个月 // 计算时间范围:当前时间到未1个月
Date now = new Date(); Date now = new Date();
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
calendar.setTime(now); calendar.setTime(now);
calendar.add(Calendar.MONTH, 1); calendar.add(Calendar.MONTH, 1);
Date oneMonthLater = calendar.getTime(); Date oneMonthLater = calendar.getTime();
// 查询即将到期的设备 List<PublicDeviceDeadInfo> list = new ArrayList<>();
List<Device> devices = deviceMapper.selectList(
// 查询已过期的设备deadTime <= 当前时间)
List<Device> expiredDevices = deviceMapper.selectList(
new LambdaQueryWrapper<Device>()
.eq(Device::getUserId, rootUserId)
.le(Device::getDeadTime, now)
.select(Device::getId, Device::getDeviceName, Device::getSerialNum, Device::getDeadTime)
.orderByAsc(Device::getDeadTime)
);
// 查询即将过期的设备(当前时间 < deadTime <= 未最1个月
List<Device> soonExpireDevices = deviceMapper.selectList(
new LambdaQueryWrapper<Device>() new LambdaQueryWrapper<Device>()
.eq(Device::getUserId, rootUserId) .eq(Device::getUserId, rootUserId)
.gt(Device::getDeadTime, now) .gt(Device::getDeadTime, now)
.le(Device::getDeadTime, oneMonthLater) .le(Device::getDeadTime, oneMonthLater)
.ge(Device::getWarnCode, 0)
.select(Device::getId, Device::getDeviceName, Device::getSerialNum, Device::getDeadTime) .select(Device::getId, Device::getDeviceName, Device::getSerialNum, Device::getDeadTime)
.orderByAsc(Device::getDeadTime) .orderByAsc(Device::getDeadTime)
); );
// 转换为VO列表 // 转换已过期设备status=1
List<PublicDeviceDeadInfo> list = devices.stream() for (Device device : expiredDevices) {
.map(device -> { PublicDeviceDeadInfo vo = new PublicDeviceDeadInfo();
PublicDeviceDeadInfo vo = new PublicDeviceDeadInfo(); vo.setId(device.getId());
vo.setId(device.getId()); vo.setDeviceName(device.getDeviceName());
vo.setDeviceName(device.getDeviceName()); vo.setSerialNum(device.getSerialNum());
vo.setSerialNum(device.getSerialNum()); vo.setDeadTime(device.getDeadTime());
vo.setDeadTime(device.getDeadTime()); vo.setStatus(1);
return vo; list.add(vo);
}) }
.collect(Collectors.toList());
// 转换即将过期设备status=2
for (Device device : soonExpireDevices) {
PublicDeviceDeadInfo vo = new PublicDeviceDeadInfo();
vo.setId(device.getId());
vo.setDeviceName(device.getDeviceName());
vo.setSerialNum(device.getSerialNum());
vo.setDeadTime(device.getDeadTime());
vo.setStatus(2);
list.add(vo);
}
return R.ok(list); return R.ok(list);
} }

View File

@@ -45,4 +45,10 @@ public class PublicDeviceDeadInfo implements Serializable {
@Schema(description = "服务到期时间") @Schema(description = "服务到期时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss") @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private Date deadTime; private Date deadTime;
/**
* 过期状态1-已过期2-即将过期
*/
@Schema(description = "过期状态1-已过期2-即将过期")
private Integer status;
} }