|
|
|
@ -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 |
|
|
|
* |
|
|
|
* <p><b>更新说明:</b></p> |
|
|
|
* <ul> |
|
|
|
* <li>2025-12-26: 改为调用存储过程方式,避免Druid WallFilter误判DELETE TOP语法为SQL注入</li> |
|
|
|
* </ul> |
|
|
|
*/ |
|
|
|
@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<String, Object> 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); |
|
|
|
// 调用存储过程执行归档 - rqrq |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("keepCount", keepCount); |
|
|
|
params.put("archivedCount", 0); |
|
|
|
|
|
|
|
if (thresholdId == null) { |
|
|
|
System.out.println("数据量不足" + keepCount + "条,无需归档 - rqrq"); |
|
|
|
return 0; |
|
|
|
} |
|
|
|
dataArchiveMapper.callArchiveWcsCallbackPalletScan(params); |
|
|
|
|
|
|
|
System.out.println("查询到阈值ID=" + thresholdId + ",将归档小于此ID的数据 - rqrq"); |
|
|
|
int archivedCount = (Integer) params.get("archivedCount"); |
|
|
|
|
|
|
|
// 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; |
|
|
|
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; |
|
|
|
} |
|
|
|
// 调用存储过程执行归档 - rqrq |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("keepCount", keepCount); |
|
|
|
params.put("archivedCount", 0); |
|
|
|
|
|
|
|
System.out.println("查询到阈值ID=" + thresholdId + ",将归档小于此ID的数据 - rqrq"); |
|
|
|
dataArchiveMapper.callArchiveWcsCallbackTask(params); |
|
|
|
|
|
|
|
// 2. 插入到历史表(不带id字段)- rqrq |
|
|
|
int insertCount = dataArchiveMapper.insertWcsCallbackTaskToHistory(thresholdId); |
|
|
|
System.out.println("已插入" + insertCount + "条数据到wcs_callback_task_history - rqrq"); |
|
|
|
int archivedCount = (Integer) params.get("archivedCount"); |
|
|
|
|
|
|
|
// 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; |
|
|
|
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"); |
|
|
|
// 调用存储过程执行归档 - rqrq |
|
|
|
Map<String, Object> params = new HashMap<>(); |
|
|
|
params.put("keepCount", keepCount); |
|
|
|
params.put("archivedTaskCount", 0); |
|
|
|
params.put("archivedDetailCount", 0); |
|
|
|
|
|
|
|
// 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"); |
|
|
|
dataArchiveMapper.callArchiveWmsTransportTask(params); |
|
|
|
|
|
|
|
// 3. 再归档主表 wms_transport_task - rqrq |
|
|
|
// 3.1 插入主表数据到历史表 - rqrq |
|
|
|
int taskInsertCount = dataArchiveMapper.insertWmsTransportTaskToHistory(thresholdId); |
|
|
|
System.out.println("已插入" + taskInsertCount + "条数据到wms_transport_task_history - rqrq"); |
|
|
|
int archivedTaskCount = (Integer) params.get("archivedTaskCount"); |
|
|
|
int archivedDetailCount = (Integer) params.get("archivedDetailCount"); |
|
|
|
|
|
|
|
// 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; |
|
|
|
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 { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|