forked from kidgrow-microservices-platform

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
package com.kidgrow.db.utils;
 
import com.kidgrow.common.utils.StringUtils;
import com.kidgrow.db.sharding.TableSuffix;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
 
/**
 * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020<br>
 *
 * @Description: 获取分表后缀工具类<br>
 * @Project: <br>
 * @CreateDate: Created in 2020/2/4 16:05 <br>
 * @Author: <a href="4345453@kidgrow.com">liuke</a>
 */
@Component
@Slf4j
public class TableSuffixUtil {
 
    /**
     * 环境参数
     */
    private static String envName;
 
    /**
     * 获取参数哈希码的分表后缀
     * @param hashString 参数
     * @return java.lang.String 分表后缀
     */
    public static String getHashTableSuffx(String hashString) {
        String tableTag = "";
        if ((! StringUtils.isEmpty(envName)) && (! envName.toLowerCase().equals("pri"))) {
            tableTag = TableSuffix.ofHash(hashString, 0, null).getSuffix();
        }
        log.info("【{}】环境下【{}】的哈希表后缀为【{}】", envName,hashString, tableTag);
 
        return tableTag;
    }
 
    /**
     * 注解获取环境参数
     * @param activeEnvName 环境参数
     * @return void
     */
    @Value("${spring.profiles.active}")
    private void setEnvName(String activeEnvName){
        envName = activeEnvName;
    }
}