
package cn.freemud.utils;
import org.apache.commons.lang.StringUtils;

/**
 * key生成器
 *
 */
public class KeyGeneratorUtil {

    public static final int RESERVE_LENGTH = 3;
    public static final String RESERVE_STR = "000";

    public static final int USER_ID_LENGTH = 2;
    public static final String PAD_STR = "0";

    /**
     * 取模
     */
    public static final int mode = 6;

    /**
     * code转换成id
     *
     * @param code
     * @return
     */
    public static Long transCodeToId(String code) {
        if (StringUtils.isEmpty(code)) {
            return null;
        }
        int end = StringUtils.length(code) - RESERVE_LENGTH - USER_ID_LENGTH;
        return Long.valueOf(StringUtils.substring(code, 0, end));
    }
}
