package com.cf.imes.framework.mybatis.core.generator;

import cn.hutool.core.lang.Snowflake;
import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.core.incrementer.IdentifierGenerator;

/**
 * @author there
 */
public class SnowFlakeGenerator implements IdentifierGenerator {

    private Snowflake snowflake;

    public SnowFlakeGenerator(Integer workerId,Integer datacenterId) {
        this.snowflake = IdUtil.getSnowflake(workerId, datacenterId);
    }

    @Override
    public Number nextId(Object entity) {
        return snowflake.nextId();
    }

}
