|
|
|
|
@ -64,12 +64,12 @@ import org.springframework.validation.annotation.Validated;
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.time.LocalDate;
|
|
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
import java.time.LocalTime;
|
|
|
|
|
import java.time.format.DateTimeFormatter;
|
|
|
|
|
import java.util.*;
|
|
|
|
|
import java.util.concurrent.atomic.AtomicInteger;
|
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
|
|
@ -974,6 +974,85 @@ public class DeviceServiceImpl implements DeviceService {
|
|
|
|
|
return resultMap;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<Map<String, Object>> singleDeviceFrom(Long deviceId) {
|
|
|
|
|
Map<String, List<Map<String, Object>>> resultMap = new LinkedHashMap<>();
|
|
|
|
|
List<Map<String, Object>> resultList = new ArrayList<>();
|
|
|
|
|
List<DeviceContactModelDO> records = deviceContactModelMapper.selectList(Wrappers.<DeviceContactModelDO>lambdaQuery()
|
|
|
|
|
.eq(DeviceContactModelDO::getDeviceId,deviceId)
|
|
|
|
|
.orderByDesc(DeviceContactModelDO::getId));
|
|
|
|
|
|
|
|
|
|
if (records == null || records.isEmpty()) {
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
// 获取最新一行数据
|
|
|
|
|
Map<String, Object> latestRow = tdengineService.newSelectLatestRow(deviceId);
|
|
|
|
|
if (latestRow == null || latestRow.isEmpty()) {
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 属性类型映射
|
|
|
|
|
Map<Long, String> idToNameMap = deviceAttributeTypeMapper.selectList()
|
|
|
|
|
.stream()
|
|
|
|
|
.collect(Collectors.toMap(
|
|
|
|
|
DeviceAttributeTypeDO::getId,
|
|
|
|
|
DeviceAttributeTypeDO::getName
|
|
|
|
|
));
|
|
|
|
|
Map<Long, String> attributeTypeCache = new HashMap<>();
|
|
|
|
|
|
|
|
|
|
// 遍历 records 填充数据
|
|
|
|
|
for (DeviceContactModelDO record : records) {
|
|
|
|
|
|
|
|
|
|
String attributeCode = record.getAttributeCode();
|
|
|
|
|
if (attributeCode == null) continue;
|
|
|
|
|
|
|
|
|
|
Object rawValue = latestRow.get(attributeCode);
|
|
|
|
|
|
|
|
|
|
Object finalValue = DataTypeParseUtil.parse(rawValue, record.getDataType());
|
|
|
|
|
|
|
|
|
|
record.setAddressValue(finalValue);
|
|
|
|
|
|
|
|
|
|
// 属性类型名称
|
|
|
|
|
String attributeTypeName = "其他";
|
|
|
|
|
Object typeObj = record.getAttributeType();
|
|
|
|
|
if (typeObj != null) {
|
|
|
|
|
String typeStr = typeObj.toString();
|
|
|
|
|
try {
|
|
|
|
|
Long typeId = Long.parseLong(typeStr);
|
|
|
|
|
attributeTypeName = attributeTypeCache.computeIfAbsent(typeId,
|
|
|
|
|
k -> idToNameMap.getOrDefault(typeId, typeStr));
|
|
|
|
|
} catch (NumberFormatException e) {
|
|
|
|
|
attributeTypeName = typeStr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Map<String, Object> simplifiedData = new HashMap<>();
|
|
|
|
|
simplifiedData.put("value", record.getAddressValue());
|
|
|
|
|
simplifiedData.put("label", record.getAttributeName());
|
|
|
|
|
simplifiedData.put("prop", "parpmeter_" + record.getId());
|
|
|
|
|
resultMap.computeIfAbsent(attributeTypeName, k -> new ArrayList<>()).add(simplifiedData);
|
|
|
|
|
}
|
|
|
|
|
if (!resultMap.isEmpty()) {
|
|
|
|
|
AtomicInteger a= new AtomicInteger(0);
|
|
|
|
|
resultMap.forEach((key, value) -> {
|
|
|
|
|
HashMap<String, Object> objectObjectHashMap = new HashMap<>();
|
|
|
|
|
objectObjectHashMap.put("id", a.incrementAndGet());
|
|
|
|
|
objectObjectHashMap.put("title", key);
|
|
|
|
|
objectObjectHashMap.put("items", value);
|
|
|
|
|
resultList.add(objectObjectHashMap);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (Exception e) {
|
|
|
|
|
log.warn("处理设备 {} 最新数据时异常: {}", deviceId, e.getMessage());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return resultList;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public PageResult<Map<String, Object>> historyRecord(
|
|
|
|
|
@ -1746,6 +1825,7 @@ public class DeviceServiceImpl implements DeviceService {
|
|
|
|
|
return new PageResult<>(availableDeviceList, page.getTotal());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 按时间区间查询设备整体开机率、稼动率日趋势。
|
|
|
|
|
* 按天复用 deviceOperationPage 统计单设备数据后求平均。
|
|
|
|
|
|