|
|
|
@ -485,16 +485,19 @@ public class MongoUtil {
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* <pre>
|
|
|
|
* <pre>
|
|
|
|
* auto : Integer (increment),Long (increment),String(date_id)
|
|
|
|
* auto : Integer (increment),Long (snowflake),String(snowflake)
|
|
|
|
* increment : Integer,Long
|
|
|
|
* increment : Integer,Long
|
|
|
|
* date_id : Long,String(date_id)
|
|
|
|
* date_id : Long,String(date_id)
|
|
|
|
* uuid : String
|
|
|
|
* uuid : String
|
|
|
|
|
|
|
|
* snowflake: Long String
|
|
|
|
* </pre>
|
|
|
|
* </pre>
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static enum FillIdType {
|
|
|
|
public static enum FillIdType {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
auto, increment, date_id, uuid;
|
|
|
|
auto, increment, date_id, uuid, snowflake;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
@ -532,17 +535,21 @@ public class MongoUtil {
|
|
|
|
} else if (f.getType() == Long.class) {
|
|
|
|
} else if (f.getType() == Long.class) {
|
|
|
|
if (type == FillIdType.date_id) {
|
|
|
|
if (type == FillIdType.date_id) {
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateIdLong(entity.getClass(), 17));
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateIdLong(entity.getClass(), 17));
|
|
|
|
} else {
|
|
|
|
} else if(type == FillIdType.increment) {
|
|
|
|
if (!IdUtils.nextIdInit(entity.getClass())) {
|
|
|
|
if (!IdUtils.nextIdInit(entity.getClass())) {
|
|
|
|
IdUtils.nextIdInit(entity.getClass(), findMaxId(entity.getClass()));
|
|
|
|
IdUtils.nextIdInit(entity.getClass(), findMaxId(entity.getClass()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtils.nextId(entity.getClass()));
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtils.nextId(entity.getClass()));
|
|
|
|
|
|
|
|
}else {
|
|
|
|
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtil.getSnowflakeNextId());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (f.getType() == String.class) {
|
|
|
|
} else if (f.getType() == String.class) {
|
|
|
|
if (type == FillIdType.date_id) {
|
|
|
|
if (type == FillIdType.date_id) {
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateId(entity.getClass(), 17));
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtils.nextDateId(entity.getClass(), 17));
|
|
|
|
} else {
|
|
|
|
} else if(type == FillIdType.uuid) {
|
|
|
|
ReflectUtil.setFieldValue(entity, f, UUID.fastUUID().toString(true));
|
|
|
|
ReflectUtil.setFieldValue(entity, f, UUID.fastUUID().toString(true));
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
|
|
|
ReflectUtil.setFieldValue(entity, f, IdUtil.getSnowflakeNextIdStr());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return entity;
|
|
|
|
return entity;
|
|
|
|
|