|
|
@ -421,55 +421,29 @@ public class CommonServiceImpl implements CommonService { |
|
|
List<ApiDeviceInfoVO> deviceInfos = deviceInfoMapperExt.getInfo4QueryAssetInfo(DeviceParamMap); |
|
|
List<ApiDeviceInfoVO> deviceInfos = deviceInfoMapperExt.getInfo4QueryAssetInfo(DeviceParamMap); |
|
|
|
|
|
|
|
|
// Query latest data and time if Aurora URL exists and devices are found
|
|
|
// Query latest data and time if Aurora URL exists and devices are found
|
|
|
if (StringUtils.isNotBlank(apikeyInfo.getAuroraUrl()) && CollectionUtils.isNotEmpty(deviceInfos)) { |
|
|
for (ApiDeviceInfoVO apiDeviceInfoVO : deviceInfos) { |
|
|
|
|
|
String deviceId = apiDeviceInfoVO.getDeviceId(); |
|
|
Class.forName("com.mysql.cj.jdbc.Driver"); |
|
|
// 计算分片
|
|
|
|
|
|
int partitionIndex = Math.abs(deviceId.hashCode()) % Constants.REDIS_PARTITION_NUM; |
|
|
String regex = "(jdbc:mysql://)([^/]+)(/data_center_aeon_admin.*)"; |
|
|
String redisKey = Constants.REDIS_RAW_DATA_REALTIME + partitionIndex; |
|
|
Pattern pattern = Pattern.compile(regex); |
|
|
|
|
|
Matcher matcher = pattern.matcher(dbUrl); |
|
|
// 从 Redis Hash 获取 JSON
|
|
|
String newJdbcUrl = ""; |
|
|
Object redisData = redisUtil.HGet(redisKey, deviceId); |
|
|
if (matcher.find()) { |
|
|
if (redisData != null) { |
|
|
newJdbcUrl = matcher.replaceAll("$1" + apikeyInfo.getAuroraUrl() + "$3"); |
|
|
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(redisData), Feature.OrderedField); |
|
|
} |
|
|
Long receiveTs = jsonObject.getLong("receive_ts"); |
|
|
|
|
|
String rawData = jsonObject.getString("rawData"); |
|
|
try (Connection conn = DriverManager.getConnection( |
|
|
|
|
|
newJdbcUrl.replace("data_center_aeon_admin", "aeon") + "&allowPublicKeyRetrieval=true", |
|
|
apiDeviceInfoVO.setLatestRawData(rawData); |
|
|
DESUtil.decrypt(apikeyInfo.getAuroraUsername(), Constants.DES_SALT), |
|
|
apiDeviceInfoVO.setLatestDataTime(receiveTs); |
|
|
DESUtil.decrypt(apikeyInfo.getAuroraPassword(), Constants.DES_SALT))) { |
|
|
|
|
|
|
|
|
// 遍历所有键值对
|
|
|
for (ApiDeviceInfoVO apiDeviceInfoVO : deviceInfos) { |
|
|
JSONObject rawDataObj = JSON.parseObject(rawData, Feature.OrderedField); |
|
|
String sql = "select rawData, receive_ts from rawData_realtime where deviceId = ? limit 1"; |
|
|
List<Object> valueList = new ArrayList<>(); |
|
|
logger.info("queryAssetInfo aurora sql:" + sql); |
|
|
for (String key : rawDataObj.keySet()) { |
|
|
|
|
|
valueList.add(rawDataObj.get(key)); |
|
|
try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) { |
|
|
|
|
|
preparedStatement.setString(1, apiDeviceInfoVO.getDeviceId()); |
|
|
|
|
|
|
|
|
|
|
|
ResultSet retult = preparedStatement.executeQuery(); |
|
|
|
|
|
|
|
|
|
|
|
while (retult.next()) { |
|
|
|
|
|
String rawData = retult.getString("rawData"); |
|
|
|
|
|
Long receiveTs = retult.getLong("receive_ts"); |
|
|
|
|
|
apiDeviceInfoVO.setLatestDataTime(receiveTs); |
|
|
|
|
|
apiDeviceInfoVO.setLatestRawData(rawData); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(rawData, Feature.OrderedField); |
|
|
|
|
|
// 遍历所有键值对
|
|
|
|
|
|
List<Object> valueList = new ArrayList<>(); |
|
|
|
|
|
for (String key : jsonObject.keySet()) { |
|
|
|
|
|
valueList.add(jsonObject.get(key)); |
|
|
|
|
|
} |
|
|
|
|
|
apiDeviceInfoVO.setDataValue(StringUtils.join(valueList, ",")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.close(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
apiDeviceInfoVO.setDataValue(StringUtils.join(valueList, ",")); |
|
|
conn.close(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("queryAssetInfo aurora query error", e); |
|
|
|
|
|
return SimpleDataResponse.fail(ResponseCode.SERVER_ERROR, ResponseCode.SERVER_ERROR_MSG); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -1495,46 +1469,31 @@ public class CommonServiceImpl implements CommonService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//Query latest data from Aurora if configured and devices are found
|
|
|
//Query latest data from Aurora if configured and devices are found
|
|
|
if (StringUtils.isNotBlank(apikeyInfo.getAuroraUrl()) && CollectionUtils.isNotEmpty(dpfDeviceInfoVOs)) { |
|
|
if (CollectionUtils.isNotEmpty(dpfDeviceInfoVOs)) { |
|
|
Class.forName("com.mysql.cj.jdbc.Driver"); |
|
|
for (ApiRiliDeviceInfoVO apiRiliDeviceInfoVO : dpfDeviceInfoVOs) { |
|
|
|
|
|
String deviceId = apiRiliDeviceInfoVO.getDeviceId(); |
|
|
String regex = "(jdbc:mysql://)([^/]+)(/data_center_aeon_admin.*)"; |
|
|
// 计算分片
|
|
|
Pattern pattern = Pattern.compile(regex); |
|
|
int partitionIndex = Math.abs(deviceId.hashCode()) % Constants.REDIS_PARTITION_NUM; |
|
|
Matcher matcher = pattern.matcher(dbUrl); |
|
|
String redisKey = Constants.REDIS_RAW_DATA_REALTIME + partitionIndex; |
|
|
String newJdbcUrl = ""; |
|
|
|
|
|
if (matcher.find()) { |
|
|
// 从 Redis Hash 获取 JSON
|
|
|
newJdbcUrl = matcher.replaceAll("$1" + apikeyInfo.getAuroraUrl() + "$3"); |
|
|
Object redisData = redisUtil.HGet(redisKey, deviceId); |
|
|
} |
|
|
if (redisData != null) { |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(redisData), Feature.OrderedField); |
|
|
try (Connection conn = DriverManager.getConnection( |
|
|
Long receiveTs = jsonObject.getLong("receive_ts"); |
|
|
newJdbcUrl.replace("data_center_aeon_admin", "aeon") + "&allowPublicKeyRetrieval=true", |
|
|
String rawData = jsonObject.getString("rawData"); |
|
|
DESUtil.decrypt(apikeyInfo.getAuroraUsername(), Constants.DES_SALT), |
|
|
|
|
|
DESUtil.decrypt(apikeyInfo.getAuroraPassword(), Constants.DES_SALT))) { |
|
|
apiRiliDeviceInfoVO.setLatestRawData(rawData); |
|
|
|
|
|
apiRiliDeviceInfoVO.setLatestDataTime(receiveTs); |
|
|
for (ApiRiliDeviceInfoVO apiRiliDeviceInfoVO : dpfDeviceInfoVOs) { |
|
|
|
|
|
|
|
|
// 遍历所有键值对
|
|
|
Map<String, Object> categoryIdSearchMap = new HashMap<>(); |
|
|
JSONObject rawDataObj = JSON.parseObject(rawData, Feature.OrderedField); |
|
|
categoryIdSearchMap.put("deviceId", apiRiliDeviceInfoVO.getDeviceId()); |
|
|
List<Object> valueList = new ArrayList<>(); |
|
|
Long deviceCategoryId = deviceInfoMapperExt.getDeviceCategoryId(categoryIdSearchMap); |
|
|
for (String key : rawDataObj.keySet()) { |
|
|
|
|
|
valueList.add(rawDataObj.get(key)); |
|
|
String baseSql = "SELECT rawData, receive_ts FROM rawData_realtime WHERE deviceId = ? LIMIT 1"; |
|
|
} |
|
|
// String sql = String.format(baseSql, formatRawDataWithDate(LocalDate.now(), deviceCategoryId));
|
|
|
apiRiliDeviceInfoVO.setDataValue(StringUtils.join(valueList, ",")); |
|
|
String sql = baseSql; |
|
|
} |
|
|
logger.info("queryDeviceInfo aurora sql: {}", sql); |
|
|
|
|
|
|
|
|
|
|
|
try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) { |
|
|
|
|
|
preparedStatement.setString(1, apiRiliDeviceInfoVO.getDeviceId()); |
|
|
|
|
|
try (ResultSet result = preparedStatement.executeQuery()) { |
|
|
|
|
|
|
|
|
|
|
|
if (result.next()) { |
|
|
|
|
|
processResult(result, apiRiliDeviceInfoVO); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("queryDeviceInfo processing aurora error", e); |
|
|
|
|
|
return SimpleDataResponse.fail(ResponseCode.SERVER_ERROR, ResponseCode.SERVER_ERROR_MSG, new ArrayList<>()); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
@ -2059,68 +2018,37 @@ public class CommonServiceImpl implements CommonService { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//Query latest data from Aurora if configured and devices are found
|
|
|
//Query latest data from Aurora if configured and devices are found
|
|
|
if (StringUtils.isNotBlank(apikeyInfo.getAuroraUrl()) && CollectionUtils.isNotEmpty(deviceInfoVOs)) { |
|
|
if (CollectionUtils.isNotEmpty(deviceInfoVOs)) { |
|
|
Class.forName("com.mysql.cj.jdbc.Driver"); |
|
|
for (ApiCancelAlarmDeviceInfoVO apiCancelAlarmDeviceInfoVO : deviceInfoVOs) { |
|
|
|
|
|
String deviceId = apiCancelAlarmDeviceInfoVO.getDeviceId(); |
|
|
String regex = "(jdbc:mysql://)([^/]+)(/data_center_aeon_admin.*)"; |
|
|
// 计算分片
|
|
|
Pattern pattern = Pattern.compile(regex); |
|
|
int partitionIndex = Math.abs(deviceId.hashCode()) % Constants.REDIS_PARTITION_NUM; |
|
|
Matcher matcher = pattern.matcher(dbUrl); |
|
|
String realtimeRedisKey = Constants.REDIS_RAW_DATA_REALTIME + partitionIndex; |
|
|
String newJdbcUrl = ""; |
|
|
|
|
|
if (matcher.find()) { |
|
|
// 从 Redis Hash 获取 JSON
|
|
|
newJdbcUrl = matcher.replaceAll("$1" + apikeyInfo.getAuroraUrl() + "$3"); |
|
|
Object redisData = redisUtil.HGet(realtimeRedisKey, deviceId); |
|
|
} |
|
|
if (redisData != null) { |
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(redisData), Feature.OrderedField); |
|
|
try (Connection conn = DriverManager.getConnection( |
|
|
Long receiveTs = jsonObject.getLong("receive_ts"); |
|
|
newJdbcUrl.replace("data_center_aeon_admin", "aeon") + "&allowPublicKeyRetrieval=true", |
|
|
String rawData = jsonObject.getString("rawData"); |
|
|
DESUtil.decrypt(apikeyInfo.getAuroraUsername(), Constants.DES_SALT), |
|
|
String alertLevel = jsonObject.getString("alertLevel"); |
|
|
DESUtil.decrypt(apikeyInfo.getAuroraPassword(), Constants.DES_SALT))) { |
|
|
String alertLevelName = jsonObject.getString("alertLevelName"); |
|
|
|
|
|
String alertCancelTitle = jsonObject.getString("alertCancelTitle"); |
|
|
for (ApiCancelAlarmDeviceInfoVO apiCancelAlarmDeviceInfoVO : deviceInfoVOs) { |
|
|
String alertTypeName = jsonObject.getString("alertTypeName"); |
|
|
// String sql = " select rawData, receive_ts, alertTitle, alertLevel,alertLevelName,alertTypeName from "+formatRawDataWithDate()+" where deviceId = '" + apiAlarmDeviceInfoVO.getDeviceId() + "' order by receive_ts desc limit 1" ;
|
|
|
apiCancelAlarmDeviceInfoVO.setLatestDataTime(receiveTs); |
|
|
// String sql = " select rawData, receive_ts, alertTitle, alertLevel, alertTypeName from "+formatRawDataWithDate()+" where deviceId = '" + apiAlarmDeviceInfoVO.getDeviceId() + "' order by receive_ts desc limit 1" ;
|
|
|
apiCancelAlarmDeviceInfoVO.setLatestRawData(rawData); |
|
|
String sql = "select rawData, receive_ts, alertCancelTitle, alertLevel, alertLevelName, alertTypeName from rawData_realtime where deviceId = ? limit 1"; |
|
|
apiCancelAlarmDeviceInfoVO.setAlertLevel(alertLevel); |
|
|
logger.info("queryAlarmDevice aurora sql: " + sql); |
|
|
apiCancelAlarmDeviceInfoVO.setAlertCancelTitle(alertCancelTitle); |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setAlertTypeName(alertTypeName); |
|
|
try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) { |
|
|
apiCancelAlarmDeviceInfoVO.setAlertLevelName(alertLevelName); |
|
|
preparedStatement.setString(1, apiCancelAlarmDeviceInfoVO.getDeviceId()); |
|
|
|
|
|
|
|
|
// 遍历所有键值对
|
|
|
ResultSet retult = preparedStatement.executeQuery(); |
|
|
JSONObject rawDataObj = JSON.parseObject(rawData, Feature.OrderedField); |
|
|
|
|
|
List<Object> valueList = new ArrayList<>(); |
|
|
while (retult.next()) { |
|
|
for (String key : rawDataObj.keySet()) { |
|
|
String rawData = retult.getString("rawData"); |
|
|
valueList.add(rawDataObj.get(key)); |
|
|
Long receiveTs = retult.getLong("receive_ts"); |
|
|
} |
|
|
String alertLevel = retult.getString("alertLevel"); |
|
|
apiCancelAlarmDeviceInfoVO.setDataValue(StringUtils.join(valueList, ",")); |
|
|
String alertLevelName = retult.getString("alertLevelName"); |
|
|
|
|
|
String alertCancelTitle = retult.getString("alertCancelTitle"); |
|
|
|
|
|
String alertTypeName = retult.getString("alertTypeName"); |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setLatestDataTime(receiveTs); |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setLatestRawData(rawData); |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setAlertLevel(alertLevel); |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setAlertCancelTitle(alertCancelTitle); |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setAlertTypeName(alertTypeName); |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setAlertLevelName(alertLevelName); |
|
|
|
|
|
|
|
|
|
|
|
JSONObject jsonObject = JSON.parseObject(rawData,Feature.OrderedField); |
|
|
|
|
|
// 遍历所有键值对
|
|
|
|
|
|
List<Object> valueList = new ArrayList<>(); |
|
|
|
|
|
for (String key : jsonObject.keySet()) { |
|
|
|
|
|
valueList.add(jsonObject.get(key)); |
|
|
|
|
|
} |
|
|
|
|
|
apiCancelAlarmDeviceInfoVO.setDataValue(StringUtils.join(valueList, ",")); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
preparedStatement.close(); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
conn.close(); |
|
|
|
|
|
} catch (Exception e) { |
|
|
|
|
|
logger.error("queryAlarmDevice processing aurora error", e); |
|
|
|
|
|
return SimpleDataResponse.fail(ResponseCode.SERVER_ERROR, ResponseCode.SERVER_ERROR_MSG); |
|
|
|
|
|
} finally { |
|
|
|
|
|
DataSourceContextHolder.clearCurrentDataSourceKey(); |
|
|
|
|
|
if (jedis != null) { |
|
|
|
|
|
// Close Jedis connection
|
|
|
|
|
|
jedis.close(); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|