public class PrimarykeyUtil {
private static int ext=100;
public static synchronized String getPrimaryId(){
SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMddHHmmssSSS");
String orderid = sdf.format(new Date());
if(ext >999){
ext = 100;
} else {
ext++;
}
String rand ="";
for(int i=0;i<10;i++){
Random rm = new Random();
rand +=rm.nextInt(10);
}
return orderid + ext + rand;
}
public static synchronized String getPrimaryId(String prefix){
SimpleDateFormat sdf =new SimpleDateFormat("yyyyMMddHHmmssSSS");
String orderid = sdf.format(new Date());
if(ext >999){
ext = 100;
} else {
ext++;
}
String rand ="";
for(int i=0;i<10;i++){
Random rm = new Random();
rand +=rm.nextInt(10);
}
return prefix+"_"+orderid + ext + rand;
}
public static void main(String[] args) {
System.out.println(getPrimaryId("menu"));
}
public static synchronized String getFileDirectory(){
SimpleDateFormat formats =new SimpleDateFormat("yyyyMMddHHmmssSSS");
return formats.format(new Date());
}
/**
* 创建模板页面ID
* @param templatePageID
* @return
*/
public static String createTemplatePageID(String templatePageID)
{
String newPageId = null;
try {
if(templatePageID != null){
String []temp = templatePageID.split("-");
DecimalFormat decimalFormat = new DecimalFormat("00");
long number = (Long) decimalFormat.parse(temp[1]);
number++;
newPageId = decimalFormat.format(number);
}else{
newPageId = "01";
}
} catch (Exception e) {
throw new RuntimeException(e.getMessage());
}
return newPageId;
}
}
网友评论