From e47d11017af9eff6581591d5d73c1e55676b0955 Mon Sep 17 00:00:00 2001 From: 啊鑫 <t2856754968@163.com> Date: 星期四, 05 六月 2025 09:16:24 +0800 Subject: [PATCH] 优化执行内存 --- src/main/java/com/gs/xky/service/XkyService.java | 44 +++++++++++++++++++++++++++++++++++++++----- 1 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/main/java/com/gs/xky/service/XkyService.java b/src/main/java/com/gs/xky/service/XkyService.java index 0ec06d5..f8e8321 100644 --- a/src/main/java/com/gs/xky/service/XkyService.java +++ b/src/main/java/com/gs/xky/service/XkyService.java @@ -42,7 +42,7 @@ public void GetSaveDetail() throws IOException { long currentTimeMillis = System.currentTimeMillis(); - long startDate = currentTimeMillis - (20 * 60 * 1000); // 璁$畻 20 鍒嗛挓鍓嶇殑鏃堕棿鎴� + long startDate = currentTimeMillis - (30 * 60 * 1000); // 璁$畻 120 鍒嗛挓鍓嶇殑鏃堕棿鎴� XkyCommonParam<BodyParam> param = XkyCommonParam.GetInit(); BodyParam bodyParam = new BodyParam(); @@ -66,24 +66,58 @@ return; } - deliveryNoList.forEach(deliveryNo -> { + log.info("銆怗etSaveDetail銆戣幏鍙栧埌{}鏉¢�佽揣鍗曟暟鎹�", deliveryNoList.size()); + + // 鍒嗘壒澶勭悊鏁版嵁锛屽噺灏戝唴瀛樺崰鐢� + int batchSize = 10; // 姣忔壒澶勭悊10鏉℃暟鎹� + int totalSize = deliveryNoList.size(); + int batchCount = (totalSize + batchSize - 1) / batchSize; // 鍚戜笂鍙栨暣璁$畻鎵规鏁� + + for (int i = 0; i < batchCount; i++) { + int fromIndex = i * batchSize; + int toIndex = Math.min((i + 1) * batchSize, totalSize); + + log.info("銆怗etSaveDetail銆戝鐞嗙{}鎵归�佽揣鍗曟暟鎹紝鑼冨洿锛歿}-{}", i + 1, fromIndex, toIndex); + + // 鑾峰彇褰撳墠鎵规鐨勬暟鎹� + List<XkyEntity> batchDeliveries = deliveryNoList.subList(fromIndex, toIndex); + + // 澶勭悊褰撳墠鎵规鐨勬暟鎹� + processBatchDeliveries(batchDeliveries); + } + + log.info("銆怗etSaveDetail銆戞墍鏈夐�佽揣鍗曞鐞嗗畬鎴�"); + } + + /** + * 鎵归噺澶勭悊閫佽揣鍗曟暟鎹� + * + * @param batchDeliveries 褰撳墠鎵规鐨勯�佽揣鍗曟暟鎹� + */ + private void processBatchDeliveries(List<XkyEntity> batchDeliveries) { + batchDeliveries.forEach(deliveryNo -> { try { if ("6".equals(deliveryNo.getStatus()) || "0".equals(deliveryNo.getLogisticsStatus())) { - log.info("銆怗etSaveDetail銆戠Щ闄ら�佽揣鍗�: {}", deliveryNo.getDeliveryNo()); + log.info("銆恜rocessBatchDeliveries銆戠Щ闄ら�佽揣鍗�: {}", deliveryNo.getDeliveryNo()); remove1(deliveryNo); } else if ("1".equals(deliveryNo.getStatus()) && ("2".equals(deliveryNo.getLogisticsStatus()) || "1".equals(deliveryNo.getLogisticsStatus()))) { + log.info("銆恜rocessBatchDeliveries銆戝鐞嗛�佽揣鍗�: {}, 鐗╂祦鐘舵��: {}", deliveryNo.getDeliveryNo(), deliveryNo.getLogisticsStatus()); XkyDetail detail = getDetail(deliveryNo.getDeliveryNo()); deliveryNoticeService.saveDeliveryNotice(detail); List<BarcodeDeliveryNo> barcodeDeliveryNos = GetBarcodeInformation(deliveryNo.getDeliveryNo()); barcodeInformationService.SaveBarcodeInformation(barcodeDeliveryNos, deliveryNo.getDeliveryNo()); //宸查�佽揪鐨勬墠鑷姩杞崲涓篗ES鍒拌揣鍗� if ("2".equals(deliveryNo.getLogisticsStatus())) { + log.info("銆恜rocessBatchDeliveries銆戦�佽揣鍗曞凡閫佽揪锛屾墽琛岀鏀�: {}", deliveryNo.getDeliveryNo()); deliveryNoticeService.callPdaReceiptBtn("閫佽揣鍗曠鏀禰BTNOK[PL017[" + deliveryNo.getDeliveryNo(), ""); } } } catch (IOException e) { - log.error("銆怗etSaveDetail 澶勭悊寮傚父銆戦�佽揣鍗�: {}, 寮傚父: {}", deliveryNo.getDeliveryNo(), e.getMessage(), e); - throw new RuntimeException(e); + log.error("銆恜rocessBatchDeliveries銆戝鐞嗛�佽揣鍗曞紓甯�: {}, 寮傚父: {}", deliveryNo.getDeliveryNo(), e.getMessage(), e); + // 涓嶆姏鍑哄紓甯革紝閬垮厤涓�涓�佽揣鍗曠殑寮傚父瀵艰嚧鏁翠釜鎵规澶辫触 + } catch (Exception e) { + log.error("銆恜rocessBatchDeliveries銆戝鐞嗛�佽揣鍗曟湭棰勬湡寮傚父: {}, 寮傚父: {}", deliveryNo.getDeliveryNo(), e.getMessage(), e); + // 涓嶆姏鍑哄紓甯革紝閬垮厤涓�涓�佽揣鍗曠殑寮傚父瀵艰嚧鏁翠釜鎵规澶辫触 } }); } -- Gitblit v1.9.3