1
zhang
1 天以前 23182f2c951df5fa55e70e30ff70ddaf91199a2e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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"));
    }
}