|
|
|
@ -20,7 +20,7 @@ import org.dromara.rfid.service.IDashboardService;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDate;
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
import java.time.ZoneId;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.*;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
@ -284,4 +284,54 @@ public class DashboardServiceImpl implements IDashboardService {
|
|
|
|
dashboard.setAlarmStats(getAlarmStats(null));
|
|
|
|
dashboard.setAlarmStats(getAlarmStats(null));
|
|
|
|
return dashboard;
|
|
|
|
return dashboard;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取所有设备的最新读取记录
|
|
|
|
|
|
|
|
* <p>
|
|
|
|
|
|
|
|
* 查询近7天分表中每个设备的最新一条读取记录。
|
|
|
|
|
|
|
|
* 由于设备可能当天或最近几天没有数据,需要跨多表查询。
|
|
|
|
|
|
|
|
* </p>
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public List<DashboardVO.DeviceLatestRecordVO> getDeviceLatestRecords() {
|
|
|
|
|
|
|
|
// 计算近7天的日期范围
|
|
|
|
|
|
|
|
LocalDate today = LocalDate.now();
|
|
|
|
|
|
|
|
LocalDate startDate = today.minusDays(6);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取近7天内实际存在的分表列表(使用 DateUtil 转换避免 java.sql.Date 不支持 toInstant)
|
|
|
|
|
|
|
|
Date beginDate = DateUtil.date(startDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
|
|
|
Date endDate = DateUtil.date(today.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
|
|
|
|
|
|
|
List<String> existingTables = RfidReadRecordTableHelper.getExistingTableNames(beginDate, endDate);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (CollUtil.isEmpty(existingTables)) {
|
|
|
|
|
|
|
|
log.warn("近7天内没有可用的读取记录分表");
|
|
|
|
|
|
|
|
return Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log.debug("查询设备最新记录,涉及分表: {}", existingTables);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<RfidReadRecordVo> latestRecords;
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 多表查询所有设备的最新记录
|
|
|
|
|
|
|
|
latestRecords = readRecordMapper.selectLatestRecordByDeviceMultiTable(existingTables, null);
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
|
|
|
log.warn("查询设备最新读取记录失败: {}", e.getMessage());
|
|
|
|
|
|
|
|
latestRecords = Collections.emptyList();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return latestRecords.stream().map(record -> {
|
|
|
|
|
|
|
|
DashboardVO.DeviceLatestRecordVO vo = new DashboardVO.DeviceLatestRecordVO();
|
|
|
|
|
|
|
|
vo.setDeviceId(record.getDeviceId());
|
|
|
|
|
|
|
|
vo.setDeviceCode(record.getDeviceCode());
|
|
|
|
|
|
|
|
vo.setDeviceName(record.getDeviceName());
|
|
|
|
|
|
|
|
vo.setLatestBarcode(record.getBarcode());
|
|
|
|
|
|
|
|
vo.setLatestRecordTime(record.getRecordTime() != null
|
|
|
|
|
|
|
|
? DateUtil.format(record.getRecordTime(), "yyyy-MM-dd HH:mm:ss")
|
|
|
|
|
|
|
|
: null);
|
|
|
|
|
|
|
|
vo.setReadStatus(record.getReadStatus());
|
|
|
|
|
|
|
|
vo.setAlarmFlag(record.getAlarmFlag());
|
|
|
|
|
|
|
|
vo.setAlarmAction(record.getAlarmAction());
|
|
|
|
|
|
|
|
return vo;
|
|
|
|
|
|
|
|
}).collect(Collectors.toList());
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|