package com.sundot.airport.system.utils;

import com.sundot.airport.system.mapper.BaseCodeGeneratorMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @Description: 8位数字编码生成工具类
 * @Author: chenshudong
 * @Date: 2025/07/08
 */
@Component
public class CodeGeneratorUtil {

    // 8位数字编码格式
    private static final String CODE_FORMAT = "%08d";
    // 默认的stub
    private static final String DEFAULT_STUB = "default";

    @Autowired
    private BaseCodeGeneratorMapper baseCodeGeneratorMapper;

    /**
     * 生成8位数字编码
     *
     * @return 8位数字编码字符串
     */
    public String getNextCodeGenerator() {
        baseCodeGeneratorMapper.replaceIntoBaseCodeGenerator(DEFAULT_STUB);
        Long nextCodeGenerator = baseCodeGeneratorMapper.getNextCodeGenerator();
        return String.format(CODE_FORMAT, nextCodeGenerator);
    }

}
