xml 代码
- //要得到的结果是比如今天是2007年1月1号
- //序列号为070101***其中***为001为开始每次+1依次类推~~~
- public String getNextSn() {
- /*
- * the order SN would be formated as 'YYMMDDxxx'
- * YY: first two digit of the current year
- * MM: current month
- * DD: current day
- * xxx: sequent increasing number
- */
- String sql = "select concat( DATE_FORMAT(current_date(),'%y%m%d'), IFNULL(max(substring(oi.sn,-3)+1),'001') ) "
- + " from OrderInfo oi "
- + "where substring(oi.sn,1,6) = DATE_FORMAT(current_date(),'%y%m%d')";
- //return tempList.get(0).toString();
- List tempList = getHibernateTemplate().find(sql);
- if (tempList != null && tempList.size()>0 ){
- String snlength = tempList.get(0).toString();
- String snFinal=(String) snlength.subSequence(0, 6);
- String snFinal2=(String) snlength.substring(6,snlength.length());
- if(snlength.length()==7)
- {
- snFinalsnFinal=snFinal+"0"+"0"+snFinal2;
- }
- if(snlength.length()==8)
- {
- snFinalsnFinal=snFinal+"0"+snFinal2;
- }
- if(snlength.length()==9)
- {
- snFinalsnFinal=snFinal+snFinal2;
- }
- //String snFinal2=(String) snlength.subSequence(7, snlength.length());
- return snFinal;
- }
- else {
- return null;
- }
- }