package org.jeecg.module.custom.ocr.utils.snow;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.SystemUtils;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * @author zhangyong
 * @title: DataCenterId
 * @projectName jyjz-parent
 * @description: TODO
 * @date 2021/11/13 11:13 AM
 */
public class DataCenterId {
    public final static Long generate() {

        String hostName = SystemUtils.getHostName();

        if(StringUtils.isBlank(hostName)){
            hostName = System.getenv("COMPUTERNAME");
        }
        if(StringUtils.isBlank(hostName)){
            try {
                hostName = (InetAddress.getLocalHost()).getHostName();
            } catch (UnknownHostException e) {
                e.printStackTrace();
            }
        }


        int[] ints = StringUtils.toCodePoints(hostName);
        int sums = 0;
        for (int i : ints) {
            sums += i;
        }
        return (long) (sums % 32);
    }
}
