生成 “R+年月日+4位” 流水号+ “行号” 生成随机流水号
批次号
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;
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?