| | |
| | | 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; |
| | |
| | | import com.java110.utils.util.DateUtil; |
| | | import org.springframework.web.client.RestTemplate; |
| | | |
| | | import java.math.BigInteger; |
| | | import java.rmi.NoSuchObjectException; |
| | | import java.util.HashMap; |
| | | import java.util.Map; |
| | |
| | | |
| | | 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"; |
| | |
| | | public static final String CODE_PREFIX_propertyUserId = "93"; |
| | | public static final String CODE_PREFIX_propertyFeeId = "94"; |
| | | public static final String CODE_PREFIX_houseId = "95"; |
| | | public static final String CODE_PREFIX_fadId = "96"; |
| | | public static final String CODE_PREFIX_pgId = "600"; |
| | | |
| | | public static final String CODE_PREFIX_floorId = "73"; |
| | |
| | | public static final String CODE_PREFIX_shId = "25"; |
| | | public static final String CODE_PREFIX_allocationStorehouseId = "26"; |
| | | public static final String CODE_PREFIX_usId = "27"; |
| | | public static final String CODE_PREFIX_rstId = "28"; |
| | | public static final String CODE_PREFIX_crId = "28"; |
| | | public static final String CODE_PREFIX_partyaId = "28"; |
| | | public static final String CODE_PREFIX_rsId = "29"; |
| | | public static final String CODE_PREFIX_ausId = "29"; |
| | | public static final String CODE_PREFIX_rsurId = "30"; |
| | | public static final String CODE_PREFIX_applyId = "29"; |
| | | public static final String CODE_PREFIX_prId = "30"; |
| | | public static final String CODE_PREFIX_acctId = "31"; |
| | | public static final String CODE_PREFIX_vipAcctId = "32"; |
| | | public static final String CODE_PREFIX_rssId = "33"; |
| | | public static final String CODE_PREFIX_pfId = "34"; |
| | | public static final String CODE_PREFIX_ARDRID = "35"; |
| | | public static final String CODE_PREFIX_csId = "36"; |
| | | public static final String CODE_PREFIX_bankId = "74"; |
| | | public static final String CODE_PREFIX_bondId = "76"; |
| | | public static final String CODE_PREFIX_bobjId = "77"; |
| | | public static final String CODE_PREFIX_smsId = "78"; |
| | | public static final String CODE_PREFIX_adsId = "78"; |
| | | public static final String CODE_PREFIX_userAnId = "88"; |
| | | public static final String CODE_PREFIX_anValueId = "68"; |
| | | |
| | | public static final String CODE_PREFIX_backId = "78"; |
| | | public static final String CODE_PREFIX_monthId = "79"; |
| | | public static final String CODE_PREFIX_xmlId = "79"; |
| | | public static final String CODE_PREFIX_formId = "80"; |
| | | 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时有用 |
| | |
| | | |
| | | 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) { |
| | |
| | | count = lastCount++; |
| | | } finally { |
| | | LOCK.unlock(); |
| | | return getRandom() + String.format(idLength, count); |
| | | String id = (hasRandom ? getRandom() : "") + String.format(idLength, count); |
| | | id = id.replace("-", ""); |
| | | return id; |
| | | } |
| | | } |
| | | |
| | |
| | | * @throws GenerateCodeException |
| | | */ |
| | | public static String getGeneratorId(String prefix) throws GenerateCodeException { |
| | | return getGeneratorId(prefix, false); |
| | | } |
| | | |
| | | public static Long getGeneratorIdToLong(String prefix) throws GenerateCodeException { |
| | | String generatorId = getGeneratorId(prefix, false); |
| | | if (generatorId.length() >= 10) { |
| | | return Long.parseLong(generatorId.substring(generatorId.length() - 10)); |
| | | } else { |
| | | // 可选:长度不足时补0(根据业务需求选择,也可直接抛异常) |
| | | return Long.parseLong(String.format("%012d", Long.parseLong(generatorId))); |
| | | // 若不想补0,直接抛异常: |
| | | // throw new IllegalArgumentException("生成的ID长度不足12位,无法截取"); |
| | | } |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 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_MILLI) + nextId("%06d"); |
| | | } else { |
| | | return prefix + DateUtil.getNow(DateUtil.DATE_FORMATE_STRING_MILLI) + 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); |
| | |
| | | return result; |
| | | } |
| | | |
| | | public static String getUUID() { |
| | | UUID uuid = UUID.randomUUID(); |
| | | 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); |
| | | } |
| | | } |