删除最大值
This commit is contained in:
parent
e663491aa0
commit
a07a72854e
|
|
@ -163,6 +163,13 @@ public class SyncDataJob implements Job {
|
|||
Date currentEnd = addDays(currentStart, syncCount);
|
||||
if (currentEnd.after(dateRange.getMaxDate())) {
|
||||
currentEnd = dateRange.getMaxDate();
|
||||
StringBuilder whereClause = new StringBuilder();
|
||||
whereClause.append("TO_CHAR(")
|
||||
.append(stasSyncStrategy.getColumnName())
|
||||
.append(", 'YYYY-MM-DD HH24:MI:SS') = '")
|
||||
.append(sdf.format(currentEnd))
|
||||
.append("'");
|
||||
deleteByEquals(targetConn, stasSyncStrategy, sourceDbType, whereClause.toString());
|
||||
}
|
||||
|
||||
// 根据数据库类型构建不同的日期条件
|
||||
|
|
@ -210,6 +217,12 @@ public class SyncDataJob implements Job {
|
|||
long currentEnd = currentStart + syncCount;
|
||||
if (currentEnd > idRange.getMaxId()) {
|
||||
currentEnd = idRange.getMaxId();
|
||||
StringBuilder whereClause = new StringBuilder();
|
||||
whereClause.append(stasSyncStrategy.getColumnName())
|
||||
.append(" = '")
|
||||
.append(currentEnd)
|
||||
.append("'");
|
||||
deleteByEquals(targetConn, stasSyncStrategy, sourceDbType, whereClause.toString());
|
||||
}
|
||||
|
||||
String whereClause = stasSyncStrategy.getColumnName() + " BETWEEN " + currentStart + " AND " + currentEnd;
|
||||
|
|
@ -231,6 +244,25 @@ public class SyncDataJob implements Job {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据日期等于或ID等于删除数据(使用yyyy-MM-dd格式比较)
|
||||
*/
|
||||
public int deleteByEquals(Connection conn, StasSyncStrategy stasSyncStrategy, Integer dbType, String whereClause) throws SQLException {
|
||||
String sql;
|
||||
// 构建完整的SQL语句
|
||||
if (SourceDataTypeEnum.ORACLE.getKey().equals(dbType)) {
|
||||
sql = "DELETE FROM \"" + stasSyncStrategy.getSourceOwner().toUpperCase() + "\".\"" +
|
||||
stasSyncStrategy.getTableName() + "\" WHERE " + whereClause;
|
||||
} else {
|
||||
sql = "DELETE FROM \"" + stasSyncStrategy.getSourceOwner().toLowerCase() + "\".\"" +
|
||||
stasSyncStrategy.getTableName() + "\" WHERE " + whereClause;
|
||||
}
|
||||
|
||||
try (PreparedStatement pstmt = conn.prepareStatement(sql)) {
|
||||
return pstmt.executeUpdate();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取表的日期范围
|
||||
*/
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user