package com.zy.acs.hex.utils;
|
|
import com.zy.acs.hex.constant.InfluxDBConstant;
|
|
import java.util.HashMap;
|
import java.util.Map;
|
|
public class StrUtils {
|
|
public static Map<String, String> getTagsByRoutingKey(String routingKey) {
|
|
// 正则表达式匹配 rcs.up. 开头,后面跟着两个版本号部分
|
String regex = "^rcs\\.up\\.(\\*|[a-zA-Z0-9]+)\\.(\\*|[a-zA-Z0-9]+)$";
|
if (routingKey.matches(regex)) {
|
// 分割字符串并返回版本号部分
|
String[] parts = routingKey.split("\\.");
|
if (parts.length == 4) {
|
Map<String, String> data = new HashMap<>();
|
data.put(InfluxDBConstant.DEVICE_MEASUREMENT_TAG_TYPE, parts[1]);
|
data.put(InfluxDBConstant.DEVICE_MEASUREMENT_TAG_DEVICEID, parts[2]);
|
data.put(InfluxDBConstant.DEVICE_MEASUREMENT_TAG_EVENT, parts[3]);
|
return data;
|
}
|
}
|
// 如果格式不符合,返回空数组
|
return null;
|
}
|
|
public static String getDeviceIdByRoutingKey(String routingKey) {
|
|
// 正则表达式匹配 rcs.up. 开头,后面跟着两个版本号部分
|
String regex = "^rcs\\.up\\.(\\*|[a-zA-Z0-9]+)\\.(\\*|[a-zA-Z0-9]+)$";
|
if (routingKey.matches(regex)) {
|
// 分割字符串并返回版本号部分
|
String[] parts = routingKey.split("\\.");
|
if (parts.length == 4) {
|
return parts[2];
|
}
|
}
|
// 如果格式不符合,返回空数组
|
return null;
|
}
|
|
public static String getEventByRoutingKey(String routingKey) {
|
|
// 正则表达式匹配 rcs.up. 开头,后面跟着两个版本号部分
|
String regex = "^rcs\\.up\\.(\\*|[a-zA-Z0-9]+)\\.(\\*|[a-zA-Z0-9]+)$";
|
if (routingKey.matches(regex)) {
|
// 分割字符串并返回版本号部分
|
String[] parts = routingKey.split("\\.");
|
if (parts.length == 4) {
|
return parts[2];
|
}
|
}
|
// 如果格式不符合,返回空数组
|
return null;
|
}
|
|
public static void main(String[] args) {
|
System.out.println(StrUtils.getDeviceIdByRoutingKey("rcs.up.ds1233.2aads"));
|
}
|
}
|