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;
|
}
|
}
|