fix: 设备即将过期,功能优化完善。
This commit is contained in:
@@ -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,46 +825,66 @@ 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)
|
||||
.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>()
|
||||
.eq(Device::getUserId, rootUserId)
|
||||
.gt(Device::getDeadTime, now)
|
||||
.le(Device::getDeadTime, oneMonthLater)
|
||||
.ge(Device::getWarnCode, 0)
|
||||
.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());
|
||||
|
||||
|
||||
// 转换已过期设备,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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user