|
|
|
@ -266,6 +266,10 @@ public class CommonOpt { |
|
|
|
public List<LineData> getLineData(Long companyId, LineDataSearchParams lineDataSearchParams, int deviceType) { |
|
|
|
List<LineData> lineDataList = new ArrayList<>(); |
|
|
|
for (String attrCode : lineDataSearchParams.getAttrCodeList()){ |
|
|
|
DeviceInfo deviceInfo = getDeviceInfoByDeviceId(lineDataSearchParams.getDeviceId()); |
|
|
|
if (null == deviceInfo){ |
|
|
|
continue; |
|
|
|
} |
|
|
|
LineData lineData = new LineData(); |
|
|
|
lineData.setAttrCode(attrCode); |
|
|
|
try { |
|
|
|
@ -328,9 +332,9 @@ public class CommonOpt { |
|
|
|
try (ResultSet result = preparedStatement.executeQuery()) { |
|
|
|
if (result.next()) { |
|
|
|
if (deviceType == 2) { |
|
|
|
processResult(result, lineData, lastDayValue); |
|
|
|
processResult(result, lineData, deviceInfo, lastDayValue); |
|
|
|
} else if (deviceType == 3) { |
|
|
|
processResult(result, lineData); |
|
|
|
processResult(result, lineData, deviceInfo); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -349,6 +353,15 @@ public class CommonOpt { |
|
|
|
return lineDataList; |
|
|
|
} |
|
|
|
|
|
|
|
private DeviceInfo getDeviceInfoByDeviceId(String deviceId) { |
|
|
|
DeviceInfoExample example = new DeviceInfoExample(); |
|
|
|
example.createCriteria() |
|
|
|
.andDeviceIdEqualTo(deviceId) |
|
|
|
.andFlagEqualTo(0); |
|
|
|
List<DeviceInfo> list = deviceInfoMapperExt.selectByExample(example); |
|
|
|
return list.isEmpty() ? null : list.get(0); |
|
|
|
} |
|
|
|
|
|
|
|
private Double getLastDayValue(Connection conn, String date, String deviceId) { |
|
|
|
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy_MM_dd"); |
|
|
|
// 解析日期字符串为 LocalDate 对象
|
|
|
|
@ -386,7 +399,7 @@ public class CommonOpt { |
|
|
|
return null; |
|
|
|
} |
|
|
|
|
|
|
|
private void processResult(ResultSet result, LineData lineData) { |
|
|
|
private void processResult(ResultSet result, LineData lineData, DeviceInfo deviceInfo) { |
|
|
|
try { |
|
|
|
// 用于存储 xData 和 yData
|
|
|
|
List<Object> xDataList = new ArrayList<>(); |
|
|
|
@ -417,7 +430,7 @@ public class CommonOpt { |
|
|
|
|
|
|
|
// 将 rawData解析 添加到 yData
|
|
|
|
// String value = extractFirstValue(mapper, rawData);
|
|
|
|
yDataList.add(StringUtils.isBlank(value) ? "0" : value); |
|
|
|
yDataList.add(CommonUtil.formatDecimal(StringUtils.isBlank(value) ? "0" : value, deviceInfo.getDashboardDecimalPlaces())); |
|
|
|
|
|
|
|
} while (result.next()); |
|
|
|
|
|
|
|
@ -429,7 +442,7 @@ public class CommonOpt { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
private void processResult(ResultSet result, LineData lineData, Double lastDayValue) { |
|
|
|
private void processResult(ResultSet result, LineData lineData, DeviceInfo deviceInfo, Double lastDayValue) { |
|
|
|
try { |
|
|
|
// 用于存储 xData 和 yData
|
|
|
|
List<Object> xDataList = new ArrayList<>(); |
|
|
|
@ -477,7 +490,7 @@ public class CommonOpt { |
|
|
|
//只取每小时的最后一条数据
|
|
|
|
for (Map.Entry<String, Double> entry : lastHourData.entrySet()) { |
|
|
|
xDataList.add(entry.getKey()); // 添加每小时的时间
|
|
|
|
yDataList.add(entry.getValue()); // 添加每小时最后一条数据的值
|
|
|
|
yDataList.add(CommonUtil.formatDecimal(entry.getValue(), deviceInfo.getDashboardDecimalPlaces())); // 添加每小时最后一条数据的值
|
|
|
|
} |
|
|
|
|
|
|
|
// 将处理后的数据加入到 lineData 中
|
|
|
|
|