forked from kidgrow-microservices-platform

kidgrow-commons/kidgrow-db-spring-boot-starter/src/main/java/com/kidgrow/db/sharding/HashModTableSuffix.java
@@ -13,21 +13,28 @@
public class HashModTableSuffix implements TableSuffix {
    private String hash;
    private Long tableSize = 64L;
    private String tableSuffix="-000";
    private Long tableSize = 128L;
    private String tableSuffix="_000";
    public HashModTableSuffix(String hash,long tableSize, String tableSuffix) {
        if (StringUtils.isEmpty(hash)) {
            throw new IllegalArgumentException("hash should not be null or empty");
        } else {
            this.hash = hash;
        }
        this.hash = hash;
        this.tableSize=tableSize;
        this.tableSuffix=tableSuffix;
        if (tableSize != 0) {
            this.tableSize = tableSize;
        }
        if (!StringUtils.isEmpty(tableSuffix)) {
            this.tableSuffix=tableSuffix;
        }
    }
    @Override
    public String getSuffix() {
        String format = "%0" + (tableSuffix.length() - 1) + "d";
        return "_"+String.format(format, Math.abs(hash.hashCode()) % tableSize);
        return tableSuffix.substring(0,1)+String.format(format, Math.abs(hash.hashCode()) % tableSize);
    }
}