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

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

View File

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

View File

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