系统设置:设备查询接口优化
This commit is contained in:
parent
7fc8b14781
commit
4599221606
@ -1026,24 +1026,12 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
if (CollectionUtils.isEmpty(list)) {
|
if (CollectionUtils.isEmpty(list)) {
|
||||||
return new ArrayList<>();
|
return new ArrayList<>();
|
||||||
}
|
}
|
||||||
List<String> serialNumberList;
|
Integer entrance = null == device ? null : device.getEntrance();
|
||||||
SysUser user = getLoginUser().getUser();
|
// 未处理告警数(alertCount)只有详情,根据产品查询设备详情 entrance=4
|
||||||
if (null != user.getDept()) {
|
if (Integer.valueOf(4).equals(entrance)) {
|
||||||
Long tenantId = user.getDept().getDeptUserId();
|
fillAlertCount(list);
|
||||||
serialNumberList = list.stream().filter(d -> tenantId.equals(d.getTenantId()))
|
|
||||||
.map(DeviceShortOutput::getSerialNumber).collect(Collectors.toList());
|
|
||||||
} else {
|
|
||||||
serialNumberList = list.stream().map(DeviceShortOutput::getSerialNumber).collect(Collectors.toList());
|
|
||||||
}
|
}
|
||||||
if (!CollectionUtils.isEmpty(serialNumberList)) {
|
fillShortListLatestReportTime(list, entrance);
|
||||||
List<DeviceAlertCount> alist = alertLogService.selectDeviceAlertCount(serialNumberList);
|
|
||||||
for (DeviceAlertCount item : alist) {
|
|
||||||
list.stream()
|
|
||||||
.filter(it -> Objects.equals(it.getSerialNumber(), item.getSerialNumber()))
|
|
||||||
.forEach(it -> it.setAlertCount(item));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
fillShortListLatestReportTime(list, device.getEntrance());
|
|
||||||
long took = System.currentTimeMillis() - startTime;
|
long took = System.currentTimeMillis() - startTime;
|
||||||
if (took > 1000L) {
|
if (took > 1000L) {
|
||||||
log.warn("selectDeviceShortList took: {}", took);
|
log.warn("selectDeviceShortList took: {}", took);
|
||||||
@ -1051,6 +1039,39 @@ public class DeviceServiceImpl implements IDeviceService {
|
|||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 回填设备未处理告警数(DeviceShortOutput#alertCount)。
|
||||||
|
* <p>
|
||||||
|
* 只统计当前登录用户自己租户的设备:存在部门时按 dept.deptUserId 过滤,
|
||||||
|
* 因此「查询下级机构」带出来的下级机构设备不会带告警徽标。
|
||||||
|
*/
|
||||||
|
private void fillAlertCount(List<DeviceShortOutput> list) {
|
||||||
|
SysUser user = getLoginUser().getUser();
|
||||||
|
Long deptUserId = null != user.getDept() ? user.getDept().getDeptUserId() : null;
|
||||||
|
List<String> serialNumberList = list.stream()
|
||||||
|
.filter(d -> null == deptUserId || deptUserId.equals(d.getTenantId()))
|
||||||
|
.map(DeviceShortOutput::getSerialNumber)
|
||||||
|
.collect(Collectors.toList());
|
||||||
|
if (CollectionUtils.isEmpty(serialNumberList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
List<DeviceAlertCount> alertCountList = alertLogService.selectDeviceAlertCount(serialNumberList);
|
||||||
|
if (CollectionUtils.isEmpty(alertCountList)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 先按 serialNumber 建索引再回填,避免原先的嵌套 stream 匹配(O(设备数 × 告警行数))
|
||||||
|
Map<String, DeviceAlertCount> alertCountMap = new HashMap<>(alertCountList.size());
|
||||||
|
for (DeviceAlertCount item : alertCountList) {
|
||||||
|
alertCountMap.put(item.getSerialNumber(), item);
|
||||||
|
}
|
||||||
|
for (DeviceShortOutput row : list) {
|
||||||
|
DeviceAlertCount alertCount = alertCountMap.get(row.getSerialNumber());
|
||||||
|
if (null != alertCount) {
|
||||||
|
row.setAlertCount(alertCount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询当前用户可见设备统计(与 shortList 相同范围)
|
* 查询当前用户可见设备统计(与 shortList 相同范围)
|
||||||
*/
|
*/
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user