From 8a5eb3c0984c030615f9e847880724b092c1f1eb Mon Sep 17 00:00:00 2001 From: lulz1 Date: Tue, 9 Jul 2024 16:11:38 +0800 Subject: [PATCH] =?UTF-8?q?fix:=E4=BF=AE=E5=A4=8D=E9=80=9A=E8=BF=87?= =?UTF-8?q?=E4=B8=B4=E6=97=B6=E8=A7=84=E5=88=92=E5=8D=95=E5=92=8C=E7=B3=BB?= =?UTF-8?q?=E7=BB=9F=E7=BC=96=E5=8F=B7=E6=9F=A5=E8=AF=A2=E7=BB=93=E6=9E=9C?= =?UTF-8?q?=E4=B8=80=E7=9B=B4=E6=98=AF=E4=B8=B4=E6=97=B6=E5=8D=95=E5=8F=B7?= =?UTF-8?q?=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../application/out/OrderOutController.java | 5 +- .../cache/RouteCacheService.java | 52 +++++++++++-------- .../java/com/chint/RouteApplicationTests.java | 2 + 3 files changed, 35 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/chint/application/out/OrderOutController.java b/src/main/java/com/chint/application/out/OrderOutController.java index 5e2c6c7d..ac7d34c3 100644 --- a/src/main/java/com/chint/application/out/OrderOutController.java +++ b/src/main/java/com/chint/application/out/OrderOutController.java @@ -64,8 +64,9 @@ public class OrderOutController { String billcode = queryData.getBillcode(); String sysCode = queryData.getSysCode(); RouteOrder routeOrder = routeRepository.findTempRouteOrderBySysCodeAndBillCode(sysCode, billcode); - if (routeOrder == null) { - routeOrder = orderQuery.queryByBillCodeAndSysCode(billcode, sysCode); + RouteOrder routeOrderFromDB = orderQuery.queryByBillCodeAndSysCode(billcode, sysCode); + if (routeOrderFromDB != null) { + routeOrder = routeOrderFromDB; } return Result.Success(SUCCESS, orderQuery.queryRouteRes(routeOrder.reloadStatus())); } diff --git a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java index 457f28e9..8b4a4068 100644 --- a/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java +++ b/src/main/java/com/chint/infrastructure/cache/RouteCacheService.java @@ -58,8 +58,7 @@ public class RouteCacheService { } public RouteOrder reloadRouteOrderInCache(RouteOrder routeOrder) { - routeCacheManage.invalidateRouteCache(routeOrder.getRouteId()); - routeCacheManage.cacheRouteOrder(routeOrder); + updateRouteCache(routeOrder); return routeOrder; } @@ -110,37 +109,46 @@ public class RouteCacheService { } public RouteOrder getRouteByFakeOrderNoAndSysCode(String fakeOrderNo, String sysCode) { - Long routeId = routeCacheManage.cacheFakeOrderNoAndSysCodeMapRouteId(fakeOrderNo, sysCode, null); - if (routeId == null) { - routeCacheManage.invalidateFakeOrderNoAndSysCodeMapRouteId(fakeOrderNo, sysCode); - } - RouteOrder routeOrder = jdbcRouteRepository.findByApproveOrderNo_FakeOrderNoAndApproveOrderNo_SysCode(fakeOrderNo, sysCode); - if (routeOrder == null) { - routeCacheManage.invalidateFakeOrderNoAndSysCodeMapRouteId(fakeOrderNo, sysCode); - return null; - } else { - routeOrder.reloadStatus(); - routeCacheManage.cacheFakeOrderNoAndSysCodeMapRouteId(fakeOrderNo, sysCode, routeOrder); - return getFromCacheOrSaveToCache(routeOrder.getRouteId()); - } + return getRouteByOrderNoAndSysCode(fakeOrderNo, sysCode, true); } public RouteOrder getRouteByActualOrderNoAndSysCode(String actualOrderNo, String sysCode) { - Long routeId = routeCacheManage.cacheActualOrderNoAndSysCodeMapRouteId(actualOrderNo, sysCode, null); + return getRouteByOrderNoAndSysCode(actualOrderNo, sysCode, false); + } + + private RouteOrder getRouteByOrderNoAndSysCode(String orderNo, String sysCode, boolean isFake) { + Long routeId = isFake ? + routeCacheManage.cacheFakeOrderNoAndSysCodeMapRouteId(orderNo, sysCode, null) : + routeCacheManage.cacheActualOrderNoAndSysCodeMapRouteId(orderNo, sysCode, null); if (routeId == null) { - routeCacheManage.invalidateActualOrderNoAndSysCodeMapRouteId(actualOrderNo, sysCode); + if (isFake) { + routeCacheManage.invalidateFakeOrderNoAndSysCodeMapRouteId(orderNo, sysCode); + } else { + routeCacheManage.invalidateActualOrderNoAndSysCodeMapRouteId(orderNo, sysCode); + } } - RouteOrder routeOrder = jdbcRouteRepository.findByApproveOrderNo_ActualOrderNoAndApproveOrderNo_SysCode(actualOrderNo, sysCode); + RouteOrder routeOrder = isFake ? + jdbcRouteRepository.findByApproveOrderNo_FakeOrderNoAndApproveOrderNo_SysCode(orderNo, sysCode) : + jdbcRouteRepository.findByApproveOrderNo_ActualOrderNoAndApproveOrderNo_SysCode(orderNo, sysCode); if (routeOrder == null) { - routeCacheManage.invalidateActualOrderNoAndSysCodeMapRouteId(actualOrderNo, sysCode); - return null; + if (isFake) { + routeCacheManage.invalidateFakeOrderNoAndSysCodeMapRouteId(orderNo, sysCode); + } else { + routeCacheManage.invalidateActualOrderNoAndSysCodeMapRouteId(orderNo, sysCode); + } } else { routeOrder.reloadStatus(); - routeCacheManage.cacheActualOrderNoAndSysCodeMapRouteId(actualOrderNo, sysCode, routeOrder); - return getFromCacheOrSaveToCache(routeOrder.getRouteId()); + if (isFake) { + routeCacheManage.cacheFakeOrderNoAndSysCodeMapRouteId(orderNo, sysCode, routeOrder); + } else { + routeCacheManage.cacheActualOrderNoAndSysCodeMapRouteId(orderNo, sysCode, routeOrder); + } + updateRouteCache(routeOrder); } + return routeOrder; } + public RouteOrder getRouteByRouteOrderNo(String routeOrderNo) { Long routeId = routeCacheManage.cacheRouteOrderNoMapRouteId(routeOrderNo, null); if (routeId == null) { diff --git a/src/test/java/com/chint/RouteApplicationTests.java b/src/test/java/com/chint/RouteApplicationTests.java index 76eb4942..376757b0 100644 --- a/src/test/java/com/chint/RouteApplicationTests.java +++ b/src/test/java/com/chint/RouteApplicationTests.java @@ -335,6 +335,8 @@ class RouteApplicationTests { } + + @Test void testPushBatch() throws UnsupportedEncodingException { List billcodeList = List.of("CLS24062500065",