批次号
R 20230213 0001
一个批次号对应多个行号
grmsStockRecordItemTemp.setBatchNo(batchNo);
grmsStockRecordItemTemp.setItemNo(list.indexOf(grmsStockRecordItemTemp) + 1 + "");
代码
/**
* 生成入库头表批次号
*/
private String generateGrmsStockRecordBatchNo() {
// 入库规则:R + 年月日 + 4位 流水
String codePre = "R";
String now;
Integer code;
String batchNo;
String lastDate;
try {
redisLock.lock(codePre);
now = DateUtils.parseDateToStr("yyyyMMdd", DateUtils.getNowDate());
List<GrmsStockRecord> list = grmsStockRecordMapper.selectGrmsStockRecordLists();
if (CollectionUtils.isEmpty(list)){
return codePre + now + String.format("%04d", 1);
}
batchNo = list.get(0).getBatchNo();
code = Integer.parseInt(batchNo.substring(9).replaceAll("^(0+)",""));
lastDate = batchNo.substring(1,9);
return lastDate.equals(now) ? codePre + now + String.format("%04d", code+1) : codePre + now + String.format("%04d", 1);
}catch (Exception e){
log.error("物料编码生成异常", e);
throw new RuntimeException("物料编码生成异常", e);
}finally {
redisLock.unlock(codePre);
}
}