2021年12月1日 星期三

日期組成流水號

String no = repo.getLastIoNo();
String prefix = new SimpleDateFormat("yyyyMMdd").format(new Date());
prefix = prefix.substring(prefix.length() - 6);

        if(no != null && no.matches("^" + prefix + "\\d{3}$")) {
            no = String.valueOf(Integer.valueOf(no) + 1);
        } else if(no == null || !no.matches("^" + prefix + "\\d{3}$")) {
            no = String.format("%s%s", prefix, "001");
        } else {
            throw new Exception("Create StockIoMaster io_no fail");
        }

簡單的說, 這個組成的流水碼最後會變成yyMMdd001, 後面會隨數字變多yyMMdd002, 接續增加

而這組流水碼, 會從001開始, 如果資料庫有取出東西, 且同一prefix的情況, 會自動將序號轉成數字

加一, 這樣就產生一組新的序號在資料庫中

取資料的寫法如下


@Query("select max(m.ioNo) from stock_io_master as m")
String getLastIoNo();

沒有留言:

張貼留言

invalid packging for parent POM com.xxxxxx:1.0SNAPSHOT must be "pom" but is "jar"

 出現在專案上面冒紅線, 並有紅字invalid packing...... 在本專案的原因是, 這裡有母子專案 有在子專案pom檔中聲明parent <parent> <artifactId> heima-leadnews-test </a...