forked from kidgrow-microservices-platform

侯瑞军
2020-06-03 257af1d1b9812aea141348a583277bc26d9ce5c4
kidgrow-commons/kidgrow-db-spring-boot-starter/src/main/java/com/kidgrow/db/sharding/HashModTableSuffix.java
@@ -13,17 +13,21 @@
public class HashModTableSuffix implements TableSuffix {
    private String hash;
    private static final int MOD = 100;
    private Long tableSize = 64L;
    private String tableSuffix="-000";
    public HashModTableSuffix(String hash) {
    public HashModTableSuffix(String hash,long tableSize, String tableSuffix) {
        if (StringUtils.isEmpty(hash)) {
            throw new IllegalArgumentException("hash should not be null or empty");
        }
        this.hash = hash;
        this.tableSize=tableSize;
        this.tableSuffix=tableSuffix;
    }
    @Override
    public String getSuffix() {
        return String.format("_%d", hash.hashCode() / MOD);
        String format = "%0" + (tableSuffix.length() - 1) + "d";
        return "_"+String.format(format, Math.abs(hash.hashCode()) % tableSize);
    }
}