From df228095b86fa06e0b9020ca81e4646d6650abc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B8=B8=E7=86=9F=E5=90=B4=E5=BD=A6=E7=A5=96?= Date: Fri, 26 Dec 2025 17:17:03 +0800 Subject: [PATCH] =?UTF-8?q?=E6=A0=87=E7=AD=BE=E6=A0=A1=E5=87=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/DataArchiveMapper.java | 51 +++++- .../service/impl/DataArchiveServiceImpl.java | 154 ++++++------------ .../automatedWarehouse/DataArchiveMapper.xml | 50 +++++- 3 files changed, 150 insertions(+), 105 deletions(-) diff --git a/src/main/java/com/gaotao/modules/automatedWarehouse/mapper/DataArchiveMapper.java b/src/main/java/com/gaotao/modules/automatedWarehouse/mapper/DataArchiveMapper.java index d62016a..193a5cd 100644 --- a/src/main/java/com/gaotao/modules/automatedWarehouse/mapper/DataArchiveMapper.java +++ b/src/main/java/com/gaotao/modules/automatedWarehouse/mapper/DataArchiveMapper.java @@ -3,14 +3,62 @@ package com.gaotao.modules.automatedWarehouse.mapper; import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Param; +import java.util.Map; + /** * @Description 数据归档Mapper接口 - rqrq * @Author rqrq * @Date 2025/11/11 + * + *

更新说明:

+ * */ @Mapper public interface DataArchiveMapper { + // ========== 存储过程调用方法(推荐使用)========== - rqrq + + /** + * @Description 调用存储过程归档interface_call_log数据 - rqrq + * @param params 参数Map,包含: + * - keepCount: 保留最新记录数量 + * - archivedCount: 输出参数,归档的记录数量 + * @author rqrq + */ + void callArchiveInterfaceCallLog(Map params); + + /** + * @Description 调用存储过程归档wcs_callback_pallet_scan数据 - rqrq + * @param params 参数Map,包含: + * - keepCount: 保留最新记录数量 + * - archivedCount: 输出参数,归档的记录数量 + * @author rqrq + */ + void callArchiveWcsCallbackPalletScan(Map params); + + /** + * @Description 调用存储过程归档wcs_callback_task数据 - rqrq + * @param params 参数Map,包含: + * - keepCount: 保留最新记录数量 + * - archivedCount: 输出参数,归档的记录数量 + * @author rqrq + */ + void callArchiveWcsCallbackTask(Map params); + + /** + * @Description 调用存储过程归档wms_transport_task数据(包含主表和明细表)- rqrq + * @param params 参数Map,包含: + * - keepCount: 保留最新记录数量 + * - archivedTaskCount: 输出参数,归档的主表记录数量 + * - archivedDetailCount: 输出参数,归档的明细表记录数量 + * @author rqrq + */ + void callArchiveWmsTransportTask(Map params); + + // ========== 以下为原有方法,保留备用 ========== - rqrq + /** * @Description 查询倒数第N条记录的ID(通用方法)- rqrq * @param tableName 表名 @@ -44,7 +92,9 @@ public interface DataArchiveMapper { * @param thresholdId 阈值ID * @return 本次删除的记录数 * @author rqrq + * @deprecated 此方法因Druid WallFilter不支持DELETE TOP语法已弃用,请使用存储过程 */ + @Deprecated int deleteInterfaceCallLogByThresholdIdBatch(@Param("thresholdId") Long thresholdId); // ========== wcs_callback_pallet_scan 归档相关方法 ========== - rqrq @@ -117,4 +167,3 @@ public interface DataArchiveMapper { */ int deleteWmsTransportTaskByThresholdId(@Param("thresholdId") Long thresholdId); } - diff --git a/src/main/java/com/gaotao/modules/automatedWarehouse/service/impl/DataArchiveServiceImpl.java b/src/main/java/com/gaotao/modules/automatedWarehouse/service/impl/DataArchiveServiceImpl.java index 9c5baee..0cb82b6 100644 --- a/src/main/java/com/gaotao/modules/automatedWarehouse/service/impl/DataArchiveServiceImpl.java +++ b/src/main/java/com/gaotao/modules/automatedWarehouse/service/impl/DataArchiveServiceImpl.java @@ -7,10 +7,18 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.HashMap; +import java.util.Map; + /** * @Description 数据归档服务实现类 - rqrq * @Author rqrq * @Date 2025/11/11 + * + *

更新说明:

+ *
    + *
  • 2025-12-26: 改为调用存储过程方式,避免Druid WallFilter误判DELETE TOP语法为SQL注入
  • + *
*/ @Slf4j @Service @@ -31,34 +39,17 @@ public class DataArchiveServiceImpl implements DataArchiveService { System.out.println("开始归档interface_call_log数据 - rqrq,保留最新" + keepCount + "条"); try { - // 1. 查询倒数第N条的ID - rqrq - Long thresholdId = dataArchiveMapper.getThresholdIdByKeepCount("interface_call_log", keepCount); - - if (thresholdId == null) { - System.out.println("数据量不足" + keepCount + "条,无需归档 - rqrq"); - return 0; - } - - System.out.println("查询到阈值ID=" + thresholdId + ",将归档小于此ID的数据 - rqrq"); - - // 2. 插入到历史表(不带id字段)- rqrq - int insertCount = dataArchiveMapper.insertInterfaceCallLogToHistory(thresholdId); - System.out.println("已插入" + insertCount + "条数据到interface_call_log_history - rqrq"); - - // 3. 批量删除原表数据(每次1000条,避免锁升级)- rqrq - int totalDeleted = 0; - int deleted; - do { - deleted = dataArchiveMapper.deleteInterfaceCallLogByThresholdIdBatch(thresholdId); - totalDeleted += deleted; - if (deleted > 0) { - System.out.println("本批次删除" + deleted + "条,累计删除" + totalDeleted + "条 - rqrq"); - } - } while (deleted > 0); - System.out.println("已删除" + totalDeleted + "条数据从interface_call_log - rqrq"); - - System.out.println("interface_call_log归档完成 - rqrq,归档数量=" + totalDeleted); - return totalDeleted; + // 调用存储过程执行归档 - rqrq + Map params = new HashMap<>(); + params.put("keepCount", keepCount); + params.put("archivedCount", 0); + + dataArchiveMapper.callArchiveInterfaceCallLog(params); + + int archivedCount = (Integer) params.get("archivedCount"); + + System.out.println("interface_call_log归档完成 - rqrq,归档数量=" + archivedCount); + return archivedCount; } catch (Exception e) { System.out.println("归档interface_call_log失败 - rqrq:" + e.getMessage()); @@ -78,26 +69,17 @@ public class DataArchiveServiceImpl implements DataArchiveService { System.out.println("开始归档wcs_callback_pallet_scan数据 - rqrq,保留最新" + keepCount + "条"); try { - // 1. 查询倒数第N条的ID - rqrq - Long thresholdId = dataArchiveMapper.getThresholdIdByKeepCount("wcs_callback_pallet_scan", keepCount); - - if (thresholdId == null) { - System.out.println("数据量不足" + keepCount + "条,无需归档 - rqrq"); - return 0; - } - - System.out.println("查询到阈值ID=" + thresholdId + ",将归档小于此ID的数据 - rqrq"); - - // 2. 插入到历史表(不带id字段)- rqrq - int insertCount = dataArchiveMapper.insertWcsCallbackPalletScanToHistory(thresholdId); - System.out.println("已插入" + insertCount + "条数据到wcs_callback_pallet_scan_history - rqrq"); - - // 3. 删除原表数据 - rqrq - int deleteCount = dataArchiveMapper.deleteWcsCallbackPalletScanByThresholdId(thresholdId); - System.out.println("已删除" + deleteCount + "条数据从wcs_callback_pallet_scan - rqrq"); - - System.out.println("wcs_callback_pallet_scan归档完成 - rqrq,归档数量=" + deleteCount); - return deleteCount; + // 调用存储过程执行归档 - rqrq + Map params = new HashMap<>(); + params.put("keepCount", keepCount); + params.put("archivedCount", 0); + + dataArchiveMapper.callArchiveWcsCallbackPalletScan(params); + + int archivedCount = (Integer) params.get("archivedCount"); + + System.out.println("wcs_callback_pallet_scan归档完成 - rqrq,归档数量=" + archivedCount); + return archivedCount; } catch (Exception e) { System.out.println("归档wcs_callback_pallet_scan失败 - rqrq:" + e.getMessage()); @@ -117,26 +99,17 @@ public class DataArchiveServiceImpl implements DataArchiveService { System.out.println("开始归档wcs_callback_task数据 - rqrq,保留最新" + keepCount + "条"); try { - // 1. 查询倒数第N条的ID - rqrq - Long thresholdId = dataArchiveMapper.getThresholdIdByKeepCount("wcs_callback_task", keepCount); - - if (thresholdId == null) { - System.out.println("数据量不足" + keepCount + "条,无需归档 - rqrq"); - return 0; - } - - System.out.println("查询到阈值ID=" + thresholdId + ",将归档小于此ID的数据 - rqrq"); - - // 2. 插入到历史表(不带id字段)- rqrq - int insertCount = dataArchiveMapper.insertWcsCallbackTaskToHistory(thresholdId); - System.out.println("已插入" + insertCount + "条数据到wcs_callback_task_history - rqrq"); - - // 3. 删除原表数据 - rqrq - int deleteCount = dataArchiveMapper.deleteWcsCallbackTaskByThresholdId(thresholdId); - System.out.println("已删除" + deleteCount + "条数据从wcs_callback_task - rqrq"); - - System.out.println("wcs_callback_task归档完成 - rqrq,归档数量=" + deleteCount); - return deleteCount; + // 调用存储过程执行归档 - rqrq + Map params = new HashMap<>(); + params.put("keepCount", keepCount); + params.put("archivedCount", 0); + + dataArchiveMapper.callArchiveWcsCallbackTask(params); + + int archivedCount = (Integer) params.get("archivedCount"); + + System.out.println("wcs_callback_task归档完成 - rqrq,归档数量=" + archivedCount); + return archivedCount; } catch (Exception e) { System.out.println("归档wcs_callback_task失败 - rqrq:" + e.getMessage()); @@ -156,37 +129,19 @@ public class DataArchiveServiceImpl implements DataArchiveService { System.out.println("开始归档wms_transport_task及明细数据 - rqrq,保留最新" + keepCount + "条"); try { - // 1. 查询倒数第N条的ID - rqrq - Long thresholdId = dataArchiveMapper.getThresholdIdByKeepCount("wms_transport_task", keepCount); - - if (thresholdId == null) { - System.out.println("数据量不足" + keepCount + "条,无需归档 - rqrq"); - return 0; - } - - System.out.println("查询到阈值ID=" + thresholdId + ",将归档小于此ID的数据 - rqrq"); - - // 2. 先归档明细表 wms_transport_task_detail - rqrq - // 2.1 插入明细数据到历史表(根据task_no关联)- rqrq - int detailInsertCount = dataArchiveMapper.insertWmsTransportTaskDetailToHistory(thresholdId); - System.out.println("已插入" + detailInsertCount + "条数据到wms_transport_task_detail_history - rqrq"); - - // 3. 再归档主表 wms_transport_task - rqrq - // 3.1 插入主表数据到历史表 - rqrq - int taskInsertCount = dataArchiveMapper.insertWmsTransportTaskToHistory(thresholdId); - System.out.println("已插入" + taskInsertCount + "条数据到wms_transport_task_history - rqrq"); - - // 4. 删除原表数据(先删明细,再删主表)- rqrq - // 4.1 删除明细表数据 - rqrq - int detailDeleteCount = dataArchiveMapper.deleteWmsTransportTaskDetailByThresholdId(thresholdId); - System.out.println("已删除" + detailDeleteCount + "条数据从wms_transport_task_detail - rqrq"); - - // 4.2 删除主表数据 - rqrq - int taskDeleteCount = dataArchiveMapper.deleteWmsTransportTaskByThresholdId(thresholdId); - System.out.println("已删除" + taskDeleteCount + "条数据从wms_transport_task - rqrq"); - - System.out.println("wms_transport_task及明细归档完成 - rqrq,归档任务数=" + taskDeleteCount + ",明细数=" + detailDeleteCount); - return taskDeleteCount; + // 调用存储过程执行归档 - rqrq + Map params = new HashMap<>(); + params.put("keepCount", keepCount); + params.put("archivedTaskCount", 0); + params.put("archivedDetailCount", 0); + + dataArchiveMapper.callArchiveWmsTransportTask(params); + + int archivedTaskCount = (Integer) params.get("archivedTaskCount"); + int archivedDetailCount = (Integer) params.get("archivedDetailCount"); + + System.out.println("wms_transport_task及明细归档完成 - rqrq,归档任务数=" + archivedTaskCount + ",明细数=" + archivedDetailCount); + return archivedTaskCount; } catch (Exception e) { System.out.println("归档wms_transport_task失败 - rqrq:" + e.getMessage()); @@ -194,4 +149,3 @@ public class DataArchiveServiceImpl implements DataArchiveService { } } } - diff --git a/src/main/resources/mapper/automatedWarehouse/DataArchiveMapper.xml b/src/main/resources/mapper/automatedWarehouse/DataArchiveMapper.xml index 9930300..3928936 100644 --- a/src/main/resources/mapper/automatedWarehouse/DataArchiveMapper.xml +++ b/src/main/resources/mapper/automatedWarehouse/DataArchiveMapper.xml @@ -2,6 +2,44 @@ + + + + + + + + + + + + + + + + +