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

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

import java.net.Inet4Address;

/**
 * @author zhangyong
 * @title: WorkId
 * @projectName jyjz-parent
 * @description: TODO
 * @date 2021/11/13 11:13 AM
 */
public final class WorkId {
    public final static Long generate() {
        try {
            //获取本地ip地址
            String hostAddress = Inet4Address.getLocalHost().getHostAddress();
            int[] ints = StringUtils.toCodePoints(hostAddress);
            int sums = 0;
            for (int b : ints) {
                sums += b;
            }
            return (long) (sums % 32);
        } catch (Exception e) {
            // 如果获取失败，则使用随机数备用
            return RandomUtils.nextLong(0, 31);
        }
    }
}
