java110
2023-06-29 4e7907983a99e695f2acba4dec8bd73b7dbe6b2b
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;
@@ -280,8 +280,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,7 +294,9 @@
            count = lastCount++;
        } finally {
            LOCK.unlock();
            return getRandom() + String.format(idLength, count);
            String id = (hasRandom?getRandom():"") + String.format(idLength, count);
            id = id.replace("-","");
            return id;
        }
    }
@@ -340,8 +346,37 @@
     * @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);