From 739be8ca2dbcc37063746f9bfde2b527ce787081 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=8E=8B=E6=99=93=E8=BF=AA?= <2596750866@qq.com> Date: Fri, 9 Aug 2024 10:54:40 +0800 Subject: [PATCH] =?UTF-8?q?[feat]=20=E4=BF=AE=E6=94=B9RedisCache=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB=EF=BC=8C=E6=96=B0=E5=A2=9E=E6=AF=8F=E5=B9=B4?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8F=B7=E4=BB=8E001=E5=BC=80=E5=A7=8B?= =?UTF-8?q?=E9=80=92=E5=A2=9E=E7=94=9F=E6=88=90=E7=BC=96=E5=8F=B7=E6=96=B9?= =?UTF-8?q?=E6=B3=95=EF=BC=9B=20=E4=BF=AE=E6=94=B9=E9=94=80=E5=94=AE?= =?UTF-8?q?=E8=AE=A2=E5=8D=95service=E6=8E=A5=E5=8F=A3=EF=BC=8C=E6=9B=B4?= =?UTF-8?q?=E6=8D=A2=E7=BC=96=E5=8F=B7=E7=94=9F=E6=88=90=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E6=96=B9=E6=B3=95=EF=BC=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../impl/SysSalesOrderServiceImpl.java | 3 ++- .../ruoyi/common/core/redis/RedisCache.java | 24 ++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) 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;