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",