包装
This commit is contained in:
@@ -0,0 +1,683 @@
|
||||
/*
|
||||
* Copyright (c) 2019.
|
||||
* http://www.ulabcare.com
|
||||
*/
|
||||
|
||||
package com.cnbm.admin.utils;
|
||||
|
||||
/**
|
||||
* <p>
|
||||
* 编号生成帮助类
|
||||
* 以2+8+6形式生成(2位编号类型前缀+8位年月日+6位自增序列号 )
|
||||
* 2位编号类型前缀定义如下⤵
|
||||
* 1x:患者相关编号以 '1' 开头,(病例号:10 )
|
||||
* 2x:订单相关编号以 '2' 开头,如订单编号=20
|
||||
* 3x: 支付相关编号以 '3' 开头,如系统内部支付订单号=30
|
||||
* (未完待续...)
|
||||
* </P>
|
||||
*
|
||||
* @author FanYi
|
||||
* @date 2019-01-03
|
||||
* @since 1.0
|
||||
*/
|
||||
public class CodeGeneratorHelper {
|
||||
|
||||
/**
|
||||
* 订单编号
|
||||
*/
|
||||
public static final String ORDER_CODE = "ORDER_CODE";
|
||||
/**
|
||||
* 工艺编号
|
||||
*/
|
||||
public static final String PROCESS_FLOW_CODE = "PROCESS_FLOW_CODE";
|
||||
|
||||
/**
|
||||
* 工艺设备点编号
|
||||
*/
|
||||
public static final String PROCESS_FLOW_EQUIPMENT_CODE = "PROCESS_FLOW_EQUIPMENT_CODE";
|
||||
/**
|
||||
* BOM编号
|
||||
*/
|
||||
public static final String BOM_CODE = "BOM_CODE";
|
||||
/**
|
||||
* 基板编号
|
||||
*/
|
||||
public static final String SUBSTRATESU_CODE = "SUBSTRATESU_CODE";
|
||||
|
||||
/**
|
||||
* 报警等级编号
|
||||
*/
|
||||
public static final String ALARM_GRADE_CODE = "ALARM_GRADE_CODE";
|
||||
|
||||
/**
|
||||
* 物料信息编号
|
||||
*/
|
||||
public static final String MATERIAL_CODE = "MATERIAL_CODE";
|
||||
|
||||
/**
|
||||
* 物料信息编号
|
||||
*/
|
||||
public static final String EQUIPMENT_MATERIAL_BOM_CODE = "EQUIPMENT_MATERIAL_BOM_CODE";
|
||||
|
||||
/**
|
||||
* 区域编号
|
||||
*/
|
||||
public static final String AREA_CODE = "AREA_CODE";
|
||||
|
||||
/**
|
||||
* 缓存区编号
|
||||
*/
|
||||
public static final String CACHE_CODE = "CACHE_CODE";
|
||||
|
||||
/**
|
||||
* 设备报警编号
|
||||
*/
|
||||
public static final String EQUIPMENT_ALARM_CODE = "EQUIPMENT_ALARM_CODE";
|
||||
|
||||
/**
|
||||
* 设备保养计划单号
|
||||
*/
|
||||
public static final String EQUIPMENT_MAINTENANCE_PLAN_CODE = "EQUIPMENT_MAINTENANCE_PLAN_CODE";
|
||||
|
||||
/**
|
||||
* 设备保养记录单号
|
||||
*/
|
||||
public static final String EQUIPMENT_MAINTENANCE_LOG_CODE = "EQUIPMENT_MAINTENANCE_LOG_CODE";
|
||||
|
||||
|
||||
/**
|
||||
* 设备类型编号
|
||||
*/
|
||||
public static final String EQUIPMENT_TYPE_CODE = "EQUIPMENT_TYPE_CODE";
|
||||
|
||||
/**
|
||||
* 保养周期编号
|
||||
*/
|
||||
public static final String MAINTENANCE_PERIOD_CODE = "MAINTENANCE_PERIOD_CODE";
|
||||
|
||||
/**
|
||||
* 维修类型编号
|
||||
*/
|
||||
public static final String MAINTENANCE_TYPE_CODE = "MAINTENANCE_TYPE_CODE";
|
||||
|
||||
/**
|
||||
* 物料类型编号
|
||||
*/
|
||||
public static final String MATERIAL_TYPE_CODE = "MATERIAL_TYPE_CODE";
|
||||
|
||||
/**
|
||||
* 设备参数编号 编号
|
||||
*/
|
||||
public static final String EQUIPMENT_PARAMETER_CODE = "EQUIPMENT_PARAMETER_CODE";
|
||||
|
||||
/**
|
||||
* 设备编号
|
||||
*/
|
||||
public static final String EQUIPMENT_CODE = "EQUIPMENT_CODE";
|
||||
|
||||
/**
|
||||
* 库位编号
|
||||
*/
|
||||
public static final String STOCK_CODE = "STOCK_CODE";
|
||||
|
||||
/**
|
||||
* 库位位置编号
|
||||
*/
|
||||
public static final String STOCK_POSITION_CODE = "STOCK_POSITION_CODE";
|
||||
|
||||
/**
|
||||
* 货架编号
|
||||
*/
|
||||
public static final String SHELF_CODE = "SHELF_CODE";
|
||||
|
||||
/**
|
||||
* 废品报废编号
|
||||
*/
|
||||
public static final String SCRAP_CODE = "SCRAP_CODE";
|
||||
|
||||
/**
|
||||
* 连线设备编号
|
||||
*/
|
||||
public static final String CONNECTING_DEVICE_CODE = "CONNECTING_DEVICE_CODE";
|
||||
|
||||
/**
|
||||
* 报警类型编号
|
||||
*/
|
||||
public static final String ALARM_TYPE_CODE = "ALARM_TYPE_CODE";
|
||||
|
||||
/**
|
||||
* 报警信息编号
|
||||
*/
|
||||
public static final String ALARM_CODE = "ALARM_CODE";
|
||||
|
||||
/**
|
||||
* 物料批次编号
|
||||
*/
|
||||
public static final String MATERIAL_DATE_CODE = "MATERIAL_DATE_CODE";
|
||||
|
||||
/**
|
||||
* 储存箱编号
|
||||
*/
|
||||
public static final String STORAGE_BOX_CODE = "STORAGE_BOX_CODE";
|
||||
/**
|
||||
* 工序编号
|
||||
*/
|
||||
public static final String SEQUENCE_CODE = "SEQUENCE_CODE";
|
||||
|
||||
private static final String DETECT_EQUIPMENT_SYSTEM_CODE = "DETECT_EQUIPMENT_SYSTEM_CODE";
|
||||
|
||||
/**
|
||||
* 标签编码
|
||||
*/
|
||||
public static final String PRINT_MODEL_CODE = "PRINT_MODEL";
|
||||
|
||||
/**
|
||||
* 生成物料批次编号
|
||||
*
|
||||
* @return 物料批次编号
|
||||
*/
|
||||
public static String getMaterialDateCode() {
|
||||
return IDGenerator.gen("PC", "yyyyMMdd", 6, MATERIAL_DATE_CODE);
|
||||
}
|
||||
/**
|
||||
* 连线设备属性编号
|
||||
*/
|
||||
public static final String CONNECTING_DEVICE_ATTR_CODE = "CONNECTING_DEVICE_ATTR_CODE";
|
||||
|
||||
|
||||
/**
|
||||
* 工厂编号
|
||||
*/
|
||||
public static final String FACTORY_CODE = "FACTORY_CODE";
|
||||
|
||||
/**
|
||||
* 产线编号
|
||||
*/
|
||||
public static final String PRODUCTION_LINE_CODE = "PRODUCTION_LINE_CODE";
|
||||
|
||||
/**
|
||||
* 设备类型报警明细编号
|
||||
*/
|
||||
public static final String EQUIPMENT_TYPE_ALARM_CODE = "EQUIPMENT_TYPE_ALARM_CODE";
|
||||
|
||||
|
||||
/**
|
||||
* 工单编号
|
||||
*/
|
||||
public static final String WORK_ORDER_CODE = "WORK_ORDER_CODE";
|
||||
|
||||
/**
|
||||
* 报废类型编号
|
||||
*/
|
||||
public static final String SCRAP_TYPE_INFORMATION_CODE = "SCRAP_TYPE_INFORMATION_CODE";
|
||||
|
||||
/**
|
||||
* 报废原因编号
|
||||
*/
|
||||
public static final String SCRAP_INFORMATION_CODE = "SCRAP_INFORMATION_CODE";
|
||||
|
||||
/**
|
||||
* 报废原因编号
|
||||
*/
|
||||
public static final String SUBSTRATE_BATCH_INFO_CODE = "SUBSTRATE_BATCH_INFO_CODE";
|
||||
|
||||
/**
|
||||
* 检测下发区域编号
|
||||
*/
|
||||
public static final String DETECT_DISTRIBUTION_AREA_CODE = "DETECT_DISTRIBUTION_AREA_CODE";
|
||||
|
||||
/**
|
||||
* 离线检测参数编码
|
||||
*/
|
||||
public static final String OFFLINE_DETECT_PARAM_CODE = "OFFLINE_DETECT_PARAM_CODE";
|
||||
|
||||
/**
|
||||
* 设备配方CODE
|
||||
*/
|
||||
public static final String EQUIPMENT_RECIPE_CODE = "EQUIPMENT_RECIPE_CODE";
|
||||
|
||||
/**
|
||||
* 设备事件CODE
|
||||
*/
|
||||
public static final String EQUIPMENT_EVENT_CODE = "EQUIPMENT_EVENT_CODE";
|
||||
|
||||
/**
|
||||
* 设备分组CODE
|
||||
*/
|
||||
public static final String EQUIPMENT_GROUP_CODE = "EQUIPMENT_GROUP_CODE";
|
||||
|
||||
/**
|
||||
* power class CODE
|
||||
*/
|
||||
public static final String POWER_CLASSIFICATION_CODE = "POWER_CLASSIFICATION_CODE";
|
||||
|
||||
/**
|
||||
* power class CODE
|
||||
*/
|
||||
public static final String EQUIPMENT_REPAIR_CODE = "EQUIPMENT_REPAIR_CODE";
|
||||
|
||||
/**
|
||||
* 存储箱 CODE
|
||||
*/
|
||||
public static final String STORAGE_TANK_CODE = "STORAGE_TANK_CODE";
|
||||
|
||||
/**
|
||||
* 权限 CODE
|
||||
*/
|
||||
public static final String ROLE_CODE = "STORAGE_TANK_CODE";
|
||||
/**
|
||||
* 权限CODE
|
||||
*
|
||||
* @return 权限CODE
|
||||
*/
|
||||
public static String getRoleCode() {
|
||||
return IDGenerator.gen("ROLE", "yyyyMMdd", 6, ROLE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 存储箱CODE
|
||||
*
|
||||
* @return 存储箱CODE
|
||||
*/
|
||||
public static String getStorageTankCode() {
|
||||
return IDGenerator.gen("CCX", "yyyyMMdd", 6, STORAGE_TANK_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成工艺设备点CODE
|
||||
*
|
||||
* @return 工艺设备点CODE
|
||||
*/
|
||||
public static String getEquipmentRepairCode() {
|
||||
return IDGenerator.gen("SBWX", "yyyyMMdd", 6, EQUIPMENT_REPAIR_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成工艺设备点CODE
|
||||
*
|
||||
* @return 工艺设备点CODE
|
||||
*/
|
||||
public static String getProcessFlowEquipmentGroupCode() {
|
||||
return IDGenerator.gen("GYSBD", "yyyyMMdd", 6, PROCESS_FLOW_EQUIPMENT_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备分组CODE
|
||||
*
|
||||
* @return 设备分组CODE
|
||||
*/
|
||||
public static String getEquipmentGroupCode() {
|
||||
return IDGenerator.gen("SBFZ", "yyyyMMdd", 6, EQUIPMENT_GROUP_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备事件CODE
|
||||
*
|
||||
* @return 生成设备事件CODE
|
||||
*/
|
||||
public static String getEquipmentEventCode() {
|
||||
return IDGenerator.gen("SBSJ", "yyyyMMdd", 6, EQUIPMENT_EVENT_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备配方编码
|
||||
*
|
||||
* @return 生成设备配方编码
|
||||
*/
|
||||
public static String getEquipmentRecipeCode() {
|
||||
return IDGenerator.gen("SBPF", "yyyyMMdd", 6, EQUIPMENT_RECIPE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成离线检测参数编码
|
||||
*
|
||||
* @return 生成离线检测参数编码
|
||||
*/
|
||||
public static String getOfflineDetectParamCode() {
|
||||
return IDGenerator.gen("LXCS", "yyyyMMdd", 6, OFFLINE_DETECT_PARAM_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备类型报警明细编号
|
||||
*
|
||||
* @return 设备类型报警明细编号
|
||||
*/
|
||||
public static String getEquipmentTypeAlarmCode() {
|
||||
return IDGenerator.gen("20", "yyyyMMdd", 6, EQUIPMENT_TYPE_ALARM_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备类型报警明细编号
|
||||
*
|
||||
* @return 设备类型报警明细编号
|
||||
*/
|
||||
public static String getStorageBoxCode() {
|
||||
return IDGenerator.gen("CCX", "yyyyMMdd", 6, STORAGE_BOX_CODE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 生成订单编号
|
||||
*
|
||||
* @return 订单编号
|
||||
*/
|
||||
public static String getOrderCode() {
|
||||
return IDGenerator.gen("20", "yyyyMMdd", 6, ORDER_CODE);
|
||||
}
|
||||
/**
|
||||
* 生成工艺编号
|
||||
*
|
||||
* @return 工艺编号
|
||||
*/
|
||||
public static String getProcessFlowCode() {
|
||||
return IDGenerator.gen("GY", "yyyyMMdd", 6, PROCESS_FLOW_CODE);
|
||||
}
|
||||
/**
|
||||
* 生成基板编号
|
||||
*
|
||||
* @return 基板编号
|
||||
*/
|
||||
public static String getSubstrateCode() {
|
||||
return IDGenerator.gen("JB", "yyyyMMdd", 6, SUBSTRATESU_CODE);
|
||||
}
|
||||
/**
|
||||
* 生成BOM编号
|
||||
*
|
||||
* @return BOM编号
|
||||
*/
|
||||
public static String getBomCode() {
|
||||
return IDGenerator.gen("BOM", "yyyyMMdd", 6, BOM_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getCode(String code) {
|
||||
return IDGenerator.gen("20", "yyyyMMdd", 6, code);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成报警等级编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getAlarmGradeCode() {
|
||||
return IDGenerator.gen("BJDJ", "yyyyMMdd", 6, ALARM_GRADE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成物料信息编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getMaterialCode() {
|
||||
return IDGenerator.gen("WLXX", "yyyyMMdd", 6, MATERIAL_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备物料Bom 编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getEquipmentMaterialBomCode() {
|
||||
return IDGenerator.gen("SBWLBOM", "yyyyMMdd", 6, EQUIPMENT_MATERIAL_BOM_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备参数 编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getEquipmentParameterCode() {
|
||||
return IDGenerator.gen("SBCS", "yyyyMMdd", 6, EQUIPMENT_PARAMETER_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成区域编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getAreaCode() {
|
||||
return IDGenerator.gen("QY", "yyyyMMdd", 6, AREA_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成缓存区编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getCacheCode() {
|
||||
return IDGenerator.gen("HCQ", "yyyyMMdd", 6, CACHE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备报警编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getEquipmentAlarmCode() {
|
||||
return IDGenerator.gen("SBBJ", "yyyyMMdd", 6, EQUIPMENT_ALARM_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备保养计划编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getEquipmentMaintenancePlanCode() {
|
||||
return IDGenerator.gen("SBBYJH", "yyyyMMdd", 6, EQUIPMENT_MAINTENANCE_PLAN_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备保养记录编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getEquipmentMaintenanceLogCode() {
|
||||
return IDGenerator.gen("SBBYJL", "yyyyMMdd", 6, EQUIPMENT_MAINTENANCE_LOG_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备类型编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getEquipmentTypeCode() {
|
||||
return IDGenerator.gen("SBLX", "yyyyMMdd", 6, EQUIPMENT_TYPE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成保养周期编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getMaintenancePeriodCode() {
|
||||
return IDGenerator.gen("BYZQ", "yyyyMMdd", 6, MAINTENANCE_PERIOD_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成维修类型编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getMaintenanceTypeCode() {
|
||||
return IDGenerator.gen("WXLX", "yyyyMMdd", 6, MAINTENANCE_TYPE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成物料类型编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getMaterialTypeCode() {
|
||||
return IDGenerator.gen("WLLX", "yyyyMMdd", 6, MATERIAL_TYPE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成设备编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getEquipmentCode() {
|
||||
return IDGenerator.gen("SB", "yyyyMMdd", 6, EQUIPMENT_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成库位位置编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getStockPositionCode() {
|
||||
return IDGenerator.gen("KWWZ", "yyyyMMdd", 6, STOCK_POSITION_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成库位编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getStockCode() {
|
||||
return IDGenerator.gen("KW", "yyyyMMdd", 6, STOCK_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成货架编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getShelfCode() {
|
||||
return IDGenerator.gen("HJ", "yyyyMMdd", 6, SHELF_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成废品报废编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getScrapCode() {
|
||||
return IDGenerator.gen("FPBF", "yyyyMMdd", 6, SCRAP_CODE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成连线设备编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getConnectingDeviceCode() {
|
||||
return IDGenerator.gen("LXSB", "yyyyMMdd", 6, CONNECTING_DEVICE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成报警类型编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getAlarmTypeCode() {
|
||||
return IDGenerator.gen("BJLX", "yyyyMMdd", 6, ALARM_TYPE_CODE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成报警信息编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getAlarmCode() {
|
||||
return IDGenerator.gen("BJXX", "yyyyMMdd", 6, ALARM_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成连线设备属性编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getConnectingDeviceAttrCode() {
|
||||
return IDGenerator.gen("LXSBSX", "yyyyMMdd", 6, CONNECTING_DEVICE_ATTR_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成工厂编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getFactoryCode() {
|
||||
return IDGenerator.gen("GC", "yyyyMMdd", 6, FACTORY_CODE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成产线编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getProductionLineCode() {
|
||||
return IDGenerator.gen("CX", "yyyyMMdd", 6, PRODUCTION_LINE_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成工单编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getWorkOrderCode() {
|
||||
return IDGenerator.gen("ZGD", "yyyyMMdd", 6, WORK_ORDER_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成报废类型编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getScrapTypeInformationCode() {
|
||||
return IDGenerator.gen("BFLX", "yyyyMMdd", 6, SCRAP_TYPE_INFORMATION_CODE);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成报废原因编号
|
||||
*
|
||||
* @return 编号
|
||||
*/
|
||||
public static String getScrapInformationCode() {
|
||||
return IDGenerator.gen("BFYY", "yyyyMMdd", 6, SCRAP_INFORMATION_CODE);
|
||||
}
|
||||
|
||||
|
||||
public static String getSubstrateBatchInfoCode() {
|
||||
return IDGenerator.gen("PC", "yyyyMMdd", 6, SUBSTRATE_BATCH_INFO_CODE);
|
||||
}
|
||||
/**
|
||||
* 生成工序编号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getSequenceCode() {
|
||||
return IDGenerator.gen("20", "yyyyMMdd", 6, SEQUENCE_CODE);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 生成检测下发区域编号
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getDetectDistributionAreaCode() {
|
||||
return IDGenerator.gen("JCQY", "yyyyMMdd", 6, DETECT_DISTRIBUTION_AREA_CODE);
|
||||
}
|
||||
|
||||
|
||||
public static String getDetectEquipmentSystemCode() {
|
||||
return IDGenerator.gen("LX", "yyyyMMdd", 6, DETECT_EQUIPMENT_SYSTEM_CODE);
|
||||
}
|
||||
|
||||
public static String getPowerClassificationCode() {
|
||||
return IDGenerator.gen("PC", "yyyyMMdd", 6, POWER_CLASSIFICATION_CODE);
|
||||
}
|
||||
|
||||
public static String getPrintModelCode() {
|
||||
return IDGenerator.gen("PM", "yyyyMMdd", 6, PRINT_MODEL_CODE);
|
||||
}
|
||||
}
|
||||
213
ym-admin/src/main/java/com/cnbm/admin/utils/IDGenerator.java
Normal file
213
ym-admin/src/main/java/com/cnbm/admin/utils/IDGenerator.java
Normal file
@@ -0,0 +1,213 @@
|
||||
package com.cnbm.admin.utils;
|
||||
|
||||
import org.apache.commons.lang3.RandomStringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.redis.core.RedisTemplate;
|
||||
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
|
||||
import org.springframework.data.redis.serializer.RedisSerializer;
|
||||
import org.springframework.data.redis.serializer.StringRedisSerializer;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* id生成器,使用redis自增接口实现
|
||||
* TODO 待完善
|
||||
*
|
||||
* @author jiff
|
||||
* @date 2018-12-1
|
||||
* @since 1.0
|
||||
*/
|
||||
@Component
|
||||
public class IDGenerator {
|
||||
private RedisTemplate redisTemplate;
|
||||
private static IDGenerator idGenerator;
|
||||
|
||||
/**
|
||||
* 4位年格式
|
||||
*/
|
||||
public static final String PATTERN_YYYY = "yyyy";
|
||||
/**
|
||||
* 6位年月格式
|
||||
*/
|
||||
public static final String PATTERN_YYYYMM = "yyyyMM";
|
||||
/**
|
||||
* 8位年月日格式
|
||||
*/
|
||||
public static final String PATTERN_YYYYMMDD = "yyyyMMdd";
|
||||
/**
|
||||
* 10位年月日时格式
|
||||
*/
|
||||
public static final String PATTERN_YYYYMMDDHH = "yyyyMMddHH";
|
||||
/**
|
||||
* 12位年月日时分格式
|
||||
*/
|
||||
public static final String PATTERN_YYYYMMDDHHMM = "yyyyMMddHHmm";
|
||||
|
||||
|
||||
/**
|
||||
* 最大序列号长度
|
||||
*/
|
||||
private static final int MAX_SEQUENCE_LENGTH = 20;
|
||||
/**
|
||||
* 最大随机数长度
|
||||
*/
|
||||
private static final int MAX_RANDOM_LENGTH = 10;
|
||||
/**
|
||||
* 序列命名空间
|
||||
*/
|
||||
private static final String KEY_PREFIX_SEQUENCE = "SEQUENCE_";
|
||||
private static final Map<String, SimpleDateFormat> commonDateFormats = new HashMap<>();
|
||||
private static final List<DecimalFormat> sequenceFormats = new ArrayList<>();
|
||||
|
||||
static {
|
||||
commonDateFormats.put(PATTERN_YYYY, new SimpleDateFormat(PATTERN_YYYY));
|
||||
commonDateFormats.put(PATTERN_YYYYMM, new SimpleDateFormat(
|
||||
PATTERN_YYYYMM));
|
||||
commonDateFormats.put(PATTERN_YYYYMMDD, new SimpleDateFormat(
|
||||
PATTERN_YYYYMMDD));
|
||||
commonDateFormats.put(PATTERN_YYYYMMDDHH, new SimpleDateFormat(
|
||||
PATTERN_YYYYMMDDHH));
|
||||
commonDateFormats.put(PATTERN_YYYYMMDDHHMM, new SimpleDateFormat(
|
||||
PATTERN_YYYYMMDDHHMM));
|
||||
StringBuilder sequencePattern = new StringBuilder(MAX_SEQUENCE_LENGTH);
|
||||
for (int i = 0; i < MAX_SEQUENCE_LENGTH; i++) {
|
||||
sequencePattern.append("0");
|
||||
sequenceFormats.add(new DecimalFormat(sequencePattern.toString()));
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
public void setRedisTemplate(RedisTemplate redisTemplate) {
|
||||
RedisSerializer stringSerializer = new StringRedisSerializer();
|
||||
//设置序列化Key的实例化对象
|
||||
redisTemplate.setKeySerializer(stringSerializer);
|
||||
//设置序列化Value的实例化对象
|
||||
redisTemplate.setValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setHashKeySerializer(stringSerializer);
|
||||
redisTemplate.setHashValueSerializer(new GenericJackson2JsonRedisSerializer());
|
||||
redisTemplate.setStringSerializer(stringSerializer);
|
||||
redisTemplate.afterPropertiesSet();
|
||||
this.redisTemplate = redisTemplate;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
private void init() {
|
||||
idGenerator = this;
|
||||
idGenerator.redisTemplate = this.redisTemplate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成主键
|
||||
*
|
||||
* @param sequenceName 序列名
|
||||
* @return 主键
|
||||
*/
|
||||
public static long gen(String sequenceName) {
|
||||
return idGenerator.redisTemplate.opsForValue().increment(
|
||||
KEY_PREFIX_SEQUENCE + sequenceName, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成主键
|
||||
*
|
||||
* @param prefix 前缀,为空或null时则不使用前缀
|
||||
* @param pattern 时间戳格式,为空或null时不使用时间戳,已定义5种格式:{@link #PATTERN_YYYY}、{@link #PATTERN_YYYYMM}、{@link #PATTERN_YYYYMMDD}、{@link #PATTERN_YYYYMMDDHH}、{@link #PATTERN_YYYYMMDDHHMM}、
|
||||
* @param sequenceLength 序列长度,大于0时有效,否则使用序列原始值,最多{@value #MAX_SEQUENCE_LENGTH}位,超过{@value #MAX_SEQUENCE_LENGTH}默认为{@value #MAX_SEQUENCE_LENGTH}位
|
||||
* @param sequenceName 序列名,为空或null时则不生成序列值
|
||||
* @return prefix+timestamp+sequence
|
||||
*/
|
||||
public static String gen(String prefix, String pattern, int sequenceLength,
|
||||
String sequenceName) {
|
||||
return gen(prefix, pattern, sequenceLength, sequenceName, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成主键
|
||||
*
|
||||
* @param prefix 前缀,为空或null时则不使用前缀
|
||||
* @param pattern 时间戳格式,为空或null时不使用时间戳,已定义5种格式:{@link #PATTERN_YYYY}、{@link #PATTERN_YYYYMM}、{@link #PATTERN_YYYYMMDD}、{@link #PATTERN_YYYYMMDDHH}、{@link #PATTERN_YYYYMMDDHHMM}、
|
||||
* @param sequenceLength 序列长度,大于0时有效,否则使用序列原始值,最多{@value #MAX_SEQUENCE_LENGTH}位,超过{@value #MAX_SEQUENCE_LENGTH}默认为{@value #MAX_SEQUENCE_LENGTH}位
|
||||
* @param sequenceName 序列名,为空或null时则不生成序列值
|
||||
* @param randomLength 随机数长度,大于0时有效,最多{@value #MAX_RANDOM_LENGTH}位,超过{@value #MAX_RANDOM_LENGTH}默认为{@value #MAX_RANDOM_LENGTH}位
|
||||
* @return prefix+timestamp+sequence+random
|
||||
*/
|
||||
public static String gen(String prefix, String pattern, int sequenceLength,
|
||||
String sequenceName, int randomLength) {
|
||||
StringBuilder ids = new StringBuilder();
|
||||
if (!isEmpty(prefix)) {
|
||||
ids.append(prefix);
|
||||
}
|
||||
String timestamp = null;
|
||||
if (!isEmpty(pattern)) {
|
||||
timestamp = getFormattedDate(pattern);
|
||||
}
|
||||
if (timestamp != null) {
|
||||
ids.append(timestamp);
|
||||
}
|
||||
if (!isEmpty(sequenceName)) {
|
||||
long sequence = gen(sequenceName);
|
||||
if (sequenceLength > 0) {
|
||||
if (sequenceLength > MAX_SEQUENCE_LENGTH) {
|
||||
sequenceLength = MAX_SEQUENCE_LENGTH;
|
||||
}
|
||||
String formatSequence = sequenceFormats.get(sequenceLength - 1)
|
||||
.format(sequence);
|
||||
if (formatSequence.length() > sequenceLength) {
|
||||
formatSequence = formatSequence.substring(formatSequence
|
||||
.length() - sequenceLength);
|
||||
}
|
||||
ids.append(formatSequence);
|
||||
} else {
|
||||
ids.append(sequence);
|
||||
}
|
||||
}
|
||||
//随机数长度大于0时添加随机数
|
||||
if (randomLength > 0) {
|
||||
String random = RandomStringUtils.randomNumeric(randomLength);
|
||||
ids.append(random);
|
||||
}
|
||||
return ids.toString();
|
||||
}
|
||||
|
||||
private static String getFormattedDate(String pattern) {
|
||||
SimpleDateFormat sdf = commonDateFormats.get(pattern);
|
||||
if (sdf == null) {
|
||||
try {
|
||||
sdf = new SimpleDateFormat(pattern);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (sdf == null) {
|
||||
return null;
|
||||
}
|
||||
java.util.Date now = new java.util.Date();
|
||||
return sdf.format(now);
|
||||
}
|
||||
|
||||
private static boolean isEmpty(String str) {
|
||||
if (str == null || str.trim().isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
for (int i = 0; i < 100; i++) {
|
||||
System.out.println(RandomStringUtils.randomNumeric(1));
|
||||
System.out.println(RandomStringUtils.randomNumeric(2));
|
||||
System.out.println(RandomStringUtils.randomNumeric(4));
|
||||
}
|
||||
System.out.println(new DecimalFormat("00").format(103));
|
||||
System.out.println(new DecimalFormat("000").format(13));
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user