fix: 修复key重复导致的异常
This commit is contained in:
+27
-27
@@ -1,8 +1,8 @@
|
|||||||
package cn.odboy.constool;
|
package cn.odboy.constool;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.odboy.base.KitBaseUserTimeTb;
|
|
||||||
import cn.odboy.framework.exception.BadRequestException;
|
import cn.odboy.framework.exception.BadRequestException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -97,7 +97,7 @@ public class KitDiffSyncConstTool<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构建本地数据的键值映射
|
// 构建本地数据的键值映射
|
||||||
Map<K, T> localMap = localRecords.stream().collect(Collectors.toMap(keyMapper, i -> i));
|
Map<K, T> localMap = localRecords.stream().collect(Collectors.toMap(keyMapper, i -> i, (oldest, newest) -> oldest));
|
||||||
|
|
||||||
List<T> insertList = new ArrayList<>();
|
List<T> insertList = new ArrayList<>();
|
||||||
List<T> updateCompareList = new ArrayList<>();
|
List<T> updateCompareList = new ArrayList<>();
|
||||||
@@ -140,29 +140,29 @@ public class KitDiffSyncConstTool<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 使用示例
|
// * 使用示例
|
||||||
*/
|
// */
|
||||||
public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
List<KitBaseUserTimeTb> localList = new ArrayList<>();
|
// List<KitBaseUserTimeTb> localList = new ArrayList<>();
|
||||||
List<KitBaseUserTimeTb> onlineList = new ArrayList<>();
|
// List<KitBaseUserTimeTb> onlineList = new ArrayList<>();
|
||||||
|
//
|
||||||
KitDiffSyncConstTool<KitBaseUserTimeTb> diffSyncTool = new KitDiffSyncConstTool<>(localList, onlineList);
|
// KitDiffSyncConstTool<KitBaseUserTimeTb> diffSyncTool = new KitDiffSyncConstTool<>(localList, onlineList);
|
||||||
diffSyncTool.sync(KitBaseUserTimeTb::getCreateBy, new SyncCallback<>() {
|
// diffSyncTool.sync(KitBaseUserTimeTb::getCreateBy, new SyncCallback<>() {
|
||||||
@Override
|
// @Override
|
||||||
public void doSaveBatch(List<KitBaseUserTimeTb> records) {
|
// public void doSaveBatch(List<KitBaseUserTimeTb> records) {
|
||||||
// 全量保存
|
// // 全量保存
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void doUpdateBatch(List<KitBaseUserTimeTb> localList, List<KitBaseUserTimeTb> compareList) {
|
// public void doUpdateBatch(List<KitBaseUserTimeTb> localList, List<KitBaseUserTimeTb> compareList) {
|
||||||
// 将 compareList 中的数据,填充到对应的 localList 数据中,更新 localList 数据
|
// // 将 compareList 中的数据,填充到对应的 localList 数据中,更新 localList 数据
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void doDeleteBatch(List<KitBaseUserTimeTb> records) {
|
// public void doDeleteBatch(List<KitBaseUserTimeTb> records) {
|
||||||
// 条件删除
|
// // 条件删除
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-27
@@ -1,8 +1,8 @@
|
|||||||
package cn.odboy.constool;
|
package cn.odboy.constool;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.odboy.base.KitBaseUserTimeTb;
|
|
||||||
import cn.odboy.framework.exception.BadRequestException;
|
import cn.odboy.framework.exception.BadRequestException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -97,7 +97,7 @@ public class KitDiffSyncConstTool<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构建本地数据的键值映射
|
// 构建本地数据的键值映射
|
||||||
Map<K, T> localMap = localRecords.stream().collect(Collectors.toMap(keyMapper, i -> i));
|
Map<K, T> localMap = localRecords.stream().collect(Collectors.toMap(keyMapper, i -> i, (oldest, newest) -> oldest));
|
||||||
|
|
||||||
List<T> insertList = new ArrayList<>();
|
List<T> insertList = new ArrayList<>();
|
||||||
List<T> updateCompareList = new ArrayList<>();
|
List<T> updateCompareList = new ArrayList<>();
|
||||||
@@ -140,29 +140,29 @@ public class KitDiffSyncConstTool<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 使用示例
|
// * 使用示例
|
||||||
*/
|
// */
|
||||||
public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
List<KitBaseUserTimeTb> localList = new ArrayList<>();
|
// List<KitBaseUserTimeTb> localList = new ArrayList<>();
|
||||||
List<KitBaseUserTimeTb> onlineList = new ArrayList<>();
|
// List<KitBaseUserTimeTb> onlineList = new ArrayList<>();
|
||||||
|
//
|
||||||
KitDiffSyncConstTool<KitBaseUserTimeTb> diffSyncTool = new KitDiffSyncConstTool<>(localList, onlineList);
|
// KitDiffSyncConstTool<KitBaseUserTimeTb> diffSyncTool = new KitDiffSyncConstTool<>(localList, onlineList);
|
||||||
diffSyncTool.sync(KitBaseUserTimeTb::getCreateBy, new SyncCallback<>() {
|
// diffSyncTool.sync(KitBaseUserTimeTb::getCreateBy, new SyncCallback<>() {
|
||||||
@Override
|
// @Override
|
||||||
public void doSaveBatch(List<KitBaseUserTimeTb> records) {
|
// public void doSaveBatch(List<KitBaseUserTimeTb> records) {
|
||||||
// 全量保存
|
// // 全量保存
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void doUpdateBatch(List<KitBaseUserTimeTb> localList, List<KitBaseUserTimeTb> compareList) {
|
// public void doUpdateBatch(List<KitBaseUserTimeTb> localList, List<KitBaseUserTimeTb> compareList) {
|
||||||
// 将 compareList 中的数据,填充到对应的 localList 数据中,更新 localList 数据
|
// // 将 compareList 中的数据,填充到对应的 localList 数据中,更新 localList 数据
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void doDeleteBatch(List<KitBaseUserTimeTb> records) {
|
// public void doDeleteBatch(List<KitBaseUserTimeTb> records) {
|
||||||
// 条件删除
|
// // 条件删除
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
+27
-27
@@ -1,8 +1,8 @@
|
|||||||
package cn.odboy.constool;
|
package cn.odboy.constool;
|
||||||
|
|
||||||
import cn.hutool.core.collection.CollUtil;
|
import cn.hutool.core.collection.CollUtil;
|
||||||
import cn.odboy.base.KitBaseUserTimeTb;
|
|
||||||
import cn.odboy.framework.exception.BadRequestException;
|
import cn.odboy.framework.exception.BadRequestException;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@@ -97,7 +97,7 @@ public class KitDiffSyncConstTool<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 构建本地数据的键值映射
|
// 构建本地数据的键值映射
|
||||||
Map<K, T> localMap = localRecords.stream().collect(Collectors.toMap(keyMapper, i -> i));
|
Map<K, T> localMap = localRecords.stream().collect(Collectors.toMap(keyMapper, i -> i, (oldest, newest) -> oldest));
|
||||||
|
|
||||||
List<T> insertList = new ArrayList<>();
|
List<T> insertList = new ArrayList<>();
|
||||||
List<T> updateCompareList = new ArrayList<>();
|
List<T> updateCompareList = new ArrayList<>();
|
||||||
@@ -140,29 +140,29 @@ public class KitDiffSyncConstTool<T> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
// /**
|
||||||
* 使用示例
|
// * 使用示例
|
||||||
*/
|
// */
|
||||||
public static void main(String[] args) {
|
// public static void main(String[] args) {
|
||||||
List<KitBaseUserTimeTb> localList = new ArrayList<>();
|
// List<KitBaseUserTimeTb> localList = new ArrayList<>();
|
||||||
List<KitBaseUserTimeTb> onlineList = new ArrayList<>();
|
// List<KitBaseUserTimeTb> onlineList = new ArrayList<>();
|
||||||
|
//
|
||||||
KitDiffSyncConstTool<KitBaseUserTimeTb> diffSyncTool = new KitDiffSyncConstTool<>(localList, onlineList);
|
// KitDiffSyncConstTool<KitBaseUserTimeTb> diffSyncTool = new KitDiffSyncConstTool<>(localList, onlineList);
|
||||||
diffSyncTool.sync(KitBaseUserTimeTb::getCreateBy, new SyncCallback<>() {
|
// diffSyncTool.sync(KitBaseUserTimeTb::getCreateBy, new SyncCallback<>() {
|
||||||
@Override
|
// @Override
|
||||||
public void doSaveBatch(List<KitBaseUserTimeTb> records) {
|
// public void doSaveBatch(List<KitBaseUserTimeTb> records) {
|
||||||
// 全量保存
|
// // 全量保存
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void doUpdateBatch(List<KitBaseUserTimeTb> localList, List<KitBaseUserTimeTb> compareList) {
|
// public void doUpdateBatch(List<KitBaseUserTimeTb> localList, List<KitBaseUserTimeTb> compareList) {
|
||||||
// 将 compareList 中的数据,填充到对应的 localList 数据中,更新 localList 数据
|
// // 将 compareList 中的数据,填充到对应的 localList 数据中,更新 localList 数据
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public void doDeleteBatch(List<KitBaseUserTimeTb> records) {
|
// public void doDeleteBatch(List<KitBaseUserTimeTb> records) {
|
||||||
// 条件删除
|
// // 条件删除
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
}
|
// }
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user