java 使用流水单号 生成订单编号

有一个流水表,四个字段
自增主键
存单子的日期
单子号
guid 与订单关联的guid
select ROW_NUMBER() OVER (order by id) as rowid , releaseTime,guid from zx_serialNumber_table order by cast(releaseTime as DATETIME) DESC

ROW_NUMBER()自动生成顺序编号
通过forech遍历匹配guid,得到对应的rowid就是row_number生成的序号

List> serialNumberList = generalService.query4staff("select ROW_NUMBER() OVER (order by id) as rowid , releaseTime,guid from zx_serialNumber_table order by cast(releaseTime as DATETIME) DESC");
for (Map map : serialNumberList) {
	System.out.println(computerEquipmentProcurement.getGuid());
	System.out.println(String.valueOf(map.get("guid")));
	if (String.valueOf(map.get("guid")).equals(computerEquipmentProcurement.getGuid())) {
		applicationNumber = String.valueOf(map.get("releaseTime")).substring(0, 7).replaceAll("-", "")+ "0"+String.valueOf(map.get("rowid"));
	}
}


你可能感兴趣的:(JavaWeb,随笔,sql,server,java技巧)