guohongjin
2024-05-15 5b7639f0bd9e056738ec15100ed0532e965c6cd5
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
package cn.stylefeng.roses.kernel.rule.util;
 
import cn.hutool.core.util.StrUtil;
 
/**
 * Guns资源缓存前缀标识替换工具
 * <p>
 * Guns资源编码为固定的guns$开头,如果项目编码修改后,应将资源标识前缀进行修改
 *
 * @author fengshuonan
 * @date 2022/11/16 23:07
 */
public class GunsResourceCodeUtil {
 
    /**
     * Guns默认的资源前缀标识
     */
    public static final String GUNS_RES_PREFIX = "guns\\$";
 
    /**
     * 将参数的资源编码,改为携带新的应用编码的资源编码
     * <p>
     * 例如之前是:guns$sys_notice$add
     * <p>
     * 修改之后为:{newAppCode参数}$sys_notice$add
     *
     * @author fengshuonan
     * @date 2022/11/16 23:09
     */
    public static String replace(String resourceCode, String newAppCode) {
 
        // 前缀为空则直接返回空串
        if (StrUtil.isEmpty(resourceCode)) {
            return "";
        }
 
        // 计算出新的前缀
        String newPrefix = newAppCode + "\\$";
 
        // 如果资源编码已经是新的前缀则直接返回
        if (resourceCode.startsWith(newPrefix)) {
            return resourceCode;
        }
 
        return resourceCode.replaceFirst(GUNS_RES_PREFIX, newPrefix);
    }
 
}