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();

沒有留言:

張貼留言

題目: 瞬間有100-200萬筆資料量進來, 如何最快安全的接收?

如果想到快, 可能直覺就是Redis, 但是... 問:瞬間有100-200萬筆資料量進來, 如果存到redis, 這樣操作有沒有可能壓垮redis? 答: 在瞬間大量資料(如100-200萬筆)快速進入Redis,確實有可能導致Redis的性能瓶頸甚至崩潰,特別是在以下情況下:...