根据日期生成简单的单据号


//单据号生成
public static String getReceiptId(String type){
StringBuilder id = new StringBuilder();
id.append(type);
Date date = new Date();
Calendar cale = Calendar.getInstance();
cale.setTime(date);
String year = cale.get(Calendar.YEAR)+"";
id.append(year.substring(2,year.length()));
String month = (cale.get(Calendar.MONTH) < 9)?"0" + (cale.get(Calendar.MONTH)+1):"" + (cale.get(Calendar.MONTH)+1);
id.append(month);
String day = (cale.get(Calendar.DAY_OF_MONTH) < 10)?"0"+cale.get(Calendar.DAY_OF_MONTH):""+cale.get(Calendar.DAY_OF_MONTH);
id.append(day);
//查看数据库的单据
String sql = "select c_batchnoid from (select c_batchnoid from bas_batchno where C_BATCHNOTYPE = '"+type+"' order by D_CREATDATE DESC) where rownum = 1";
DbConnectionCache db = DbConnectionCache.getInstance();
Map mp = new HashMap();
String upid = DBUtil.SingleValue(db.getConnection(), sql, mp);
if(upid!=""){
if((upid.substring(1, 3)).equals(year.substring(2,year.length()))&&upid.substring(3, 5).equals(month)&&upid.substring(5, 7).equals(day)){
int seq = Integer.parseInt(upid.substring(upid.length() - 3,upid.length()))+1;
if(Integer.parseInt(upid.substring(upid.length() - 3,upid.length()))!=000){
seq = Integer.parseInt(upid.substring(upid.length() - 3,upid.length()))+1;
}else{
seq = Integer.parseInt(upid.substring(upid.length() - 4,upid.length()))+1;
}
if(seq<10){
id.append("00"+seq);
}else if(seq<100){
id.append("0"+seq);
}else{
id.append(seq);
}
}else{
id.append("001");
}
}else{
id.append("001");
}
return id.toString();
}

你可能感兴趣的:(java)