diff --git a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java index 8eb0d1e3..92936032 100644 --- a/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java +++ b/ruoyi-admin/src/main/java/com/ruoyi/system/service/impl/SysSalesOrderServiceImpl.java @@ -183,6 +183,7 @@ public class SysSalesOrderServiceImpl implements ISysSalesOrderService String loginName = ShiroUtils.getLoginName(); sysSalesOrder.setCreateBy(loginName); sysSalesOrder.setCreateTime(DateUtils.getNowDate()); + sysSalesOrder.setSalesOrderCode(getId()); int result = sysSalesOrderMapper.insertSysSalesOrder(sysSalesOrder); sysSalesOrder.getSalesOrderId(); int s = sysSalesOrder.getSysSalesOrderChildList().size(); @@ -256,7 +257,7 @@ public class SysSalesOrderServiceImpl implements ISysSalesOrderService @Override public String getId() { - return redisCache.generateBillNo("XS"); + return redisCache.generateBillNoByYear("XS"); } @Override diff --git a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java index 65b49107..f38cc7c3 100644 --- a/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java +++ b/ruoyi-common/src/main/java/com/ruoyi/common/core/redis/RedisCache.java @@ -314,7 +314,29 @@ public class RedisCache String serialNum = String.format("%03d",no); return codeKey+serialNum; } - + /** + * 生成流水号(年为单位) + * @param prefix + * @return + */ + public String generateBillNoByYear(String prefix) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); + SimpleDateFormat year_format = new SimpleDateFormat("yyyy"); + String yearMonthDay = sdf.format(new Date()); + String yearPart = year_format.format(new Date()); + String codeKey = prefix+yearPart; + Long no = 0L; + //获取每日流水 + if (hasKey(codeKey)) { + no = Long.valueOf(get(codeKey).toString()); + } + no = incr(codeKey, 1); + if (no == null) { + throw new RuntimeException("Redis单据编号流水递增失败"); + } + String serialNum = String.format("%03d",no); + return prefix + yearMonthDay +serialNum; + } public String generateNo(String prefix) { String codeKey = prefix; Long no = 0L;