生成 “R+年月日+4位” 流水号+ “行号” 生成随机流水号

发布时间 2023-05-20 10:00:00作者: binbinx

批次号

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

随机流水号

WFI99884958

生成流程实例随机流水号

workflowInstance.setWorkflowInstanceId("WFI" + SNNoTools.getIntUUID().toString());

 

工具类

package com.tn.mdm.workflow.tools;

/**
* 生成编号
*
* @author admin
* @date 2022-04-25
*/
public class SNNoTools {

public static synchronized Integer getIntUUID() {
Integer data = 0;
while (data <= 0) {
Integer numOne = Math.abs((int) Math.round((Math.random() * 10) * 10000000));
Integer numTwo = Math.abs((int) Math.round((Math.random() * 10)));
data = numOne * numTwo;
}
return data;
}

}