自动生成指定格式的编号
需求
WX [日期][5位的递增编号]
/** * 获取工单编号 */ public String getWorkflowSn() { String datetime = new SimpleDateFormat("yyyyMMdd").format(new Date()); //这个方法的功能是获取当天的工单数量,代码贴在下方,可供参考 long wfNumber = workflowManager.getWfNumberByDay(new SimpleDateFormat("yyyy-MM-dd").format(new Date())); return String.format("WX%s%05d", datetime, wfNumber + 1); }
public long getWfNumberByDay(String target) { String select = "select wf_sn \"wfSn\" from dev_repair_workflow where is_deleted = 0 and to_char(start_time,'yyyy-mm-dd') = ? order by start_time desc"; List<Map<String, Object>> wfList = dao.sqlQuery(select, target); return wfList.size(); }