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

沒有留言:

張貼留言

量身訂做建議(37 歲,6 年 Java 後端工程師)from chatgpt

🎯 量身訂做建議(37 歲,6 年 Java 後端工程師) 1️⃣ 先看你的條件 年齡 37 屬於「中高年資」工程師,履歷上的 深度 / 系統設計能力 會比「語言多寡」更重要。 6 年 Java 後端 代表你在 Spring Boot、資料庫、API 設計...