chengf
2025-12-10 ee89a5cfa50980f1f2f2fa84bb69741b161670b5
java110-core/src/main/java/com/java110/core/factory/GenerateCodeFactory.java
@@ -1,7 +1,7 @@
package com.java110.core.factory;
import com.alibaba.fastjson.JSONObject;
import com.java110.dto.idSeq.IdSeqDto;
import com.java110.dto.system.IdSeqDto;
import com.java110.intf.code.ICodeApi;
import com.java110.intf.order.IIdSeqInnerServiceSMO;
import com.java110.utils.cache.MappingCache;
@@ -27,6 +27,9 @@
    private static final long ONE_STEP = 1000000;
    private static final Lock LOCK = new ReentrantLock();
    public static final String CODE_PREFIX_maintenanceId = "9222";
    public static String CODE_PREFIX_paymentRecordId = "9223";
    public static String CODE_PREFIX_fifthPaymentId = "9224";
    private static short lastCount = 1;
    private static int count = 0;
    private static final String first = "10";
@@ -224,6 +227,7 @@
    public static final String CODE_PREFIX_dataId = "81";
    public static final String CODE_PREFIX_tranId = "82";
    public static final String CODE_PREFIX_collId = "83";
    /**
     * 只有在不调用服务生成ID时有用
@@ -280,8 +284,12 @@
    private static String PLATFORM_CODE = "0001";
    @SuppressWarnings("finally")
    public static String nextId(String idLength) {
        return nextId(idLength, true);
    }
    @SuppressWarnings("finally")
    public static String nextId(String idLength, boolean hasRandom) {
        LOCK.lock();
        try {
            if (lastCount == ONE_STEP) {
@@ -290,8 +298,8 @@
            count = lastCount++;
        } finally {
            LOCK.unlock();
            String id = getRandom() + String.format(idLength, count);
            id = id.replace("-","");
            String id = (hasRandom ? getRandom() : "") + String.format(idLength, count);
            id = id.replace("-", "");
            return id;
        }
    }
@@ -342,8 +350,38 @@
     * @throws GenerateCodeException
     */
    public static String getGeneratorId(String prefix) throws GenerateCodeException {
        return getGeneratorId(prefix, false);
    }
    /**
     * pgId生成
     *
     * @return
     * @throws GenerateCodeException
     */
    public static String getGeneratorId(String prefix, boolean longId) throws GenerateCodeException {
        if (!MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_NEED_INVOKE_GENERATE_ID))) {
            return prefix + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H) + nextId("%04d");
            //2+14+4+6
            //7920230518235714886
            if (longId) {
                return prefix + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_DEFAULT) + nextId("%06d");
            } else {
                return prefix + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H) + nextId("%04d");
            }
        }
        //调用服务
        return getCode(prefix);
    }
    /**
     * pgId生成
     *
     * @return
     * @throws GenerateCodeException
     */
    public static String getDetailId(String prefix) throws GenerateCodeException {
        if (!MappingConstant.VALUE_ON.equals(MappingCache.getValue(MappingConstant.KEY_NEED_INVOKE_GENERATE_ID))) {
            return prefix + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_O) + nextId("%06d", false);
        }
        //调用服务
        return getCode(prefix);
@@ -988,4 +1026,9 @@
        return uuid.toString().replaceAll("-", "");
    }
    public static String getLink() {
        String time = DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_H);
        time = time.substring(2);
        return time + nextId("%04d",false);
    }
}