diff --git a/src/main/java/com/spring/modules/part/mapper/RoutingManagementMapper.java b/src/main/java/com/spring/modules/part/mapper/RoutingManagementMapper.java index 445e5568..62199786 100644 --- a/src/main/java/com/spring/modules/part/mapper/RoutingManagementMapper.java +++ b/src/main/java/com/spring/modules/part/mapper/RoutingManagementMapper.java @@ -215,4 +215,6 @@ public interface RoutingManagementMapper extends BaseMapper void syncSaveWorkCenterCost(List subList); void syncUpdateWorkCenterCost(List subList); + + void deleteWorkCenterCostAll(); } diff --git a/src/main/java/com/spring/modules/part/service/impl/RoutingManagementServiceImpl.java b/src/main/java/com/spring/modules/part/service/impl/RoutingManagementServiceImpl.java index e12b0e54..3595b3eb 100644 --- a/src/main/java/com/spring/modules/part/service/impl/RoutingManagementServiceImpl.java +++ b/src/main/java/com/spring/modules/part/service/impl/RoutingManagementServiceImpl.java @@ -1602,51 +1602,53 @@ public class RoutingManagementServiceImpl extends ServiceImpl plmWorkCenterCosts = routingManagementMapper.getPLMWorkCenterCosts(arr); - - // 转换列表为映射以便于比较 - Map mapListAll = ifsWorkCenterCosts.stream() - .collect(Collectors.toMap(WorkCenterCost::getIfsRowId, Function.identity())); - Map mapList1 = plmWorkCenterCosts.stream() - .collect(Collectors.toMap(WorkCenterCost::getIfsRowId, Function.identity())); - - // 找出需要新增的对象(IFS有而PLM没有的) - Set keysToAdd = new HashSet<>(mapListAll.keySet()); - keysToAdd.removeAll(mapList1.keySet()); - List toAdd = keysToAdd.stream() - .map(mapListAll::get) - .collect(Collectors.toList()); - - // 找出需要更新的对象(ifsRowVersion不同) - Set commonKeys = new HashSet<>(mapListAll.keySet()); - commonKeys.retainAll(mapList1.keySet()); - List toUpdate = commonKeys.stream() - .filter(key -> !mapListAll.get(key).getIfsRowVersion().equals(mapList1.get(key).getIfsRowVersion())) - .map(key -> mapListAll.get(key)) // 选择listAll中的版本进行更新 - .collect(Collectors.toList()); +// // 查询PLM数据 +// String[] arr = data.getSiteCon().replace("(", "").replace(")", "").replace("'", "").split(","); +// List plmWorkCenterCosts = routingManagementMapper.getPLMWorkCenterCosts(arr); +// +// // 转换列表为映射以便于比较 +// Map mapListAll = ifsWorkCenterCosts.stream() +// .collect(Collectors.toMap(WorkCenterCost::getIfsRowId, Function.identity())); +// Map mapList1 = plmWorkCenterCosts.stream() +// .collect(Collectors.toMap(WorkCenterCost::getIfsRowId, Function.identity())); + +// // 找出需要新增的对象(IFS有而PLM没有的) +// Set keysToAdd = new HashSet<>(mapListAll.keySet()); +// keysToAdd.removeAll(mapList1.keySet()); +// List toAdd = keysToAdd.stream() +// .map(mapListAll::get) +// .collect(Collectors.toList()); +// +// // 找出需要更新的对象(ifsRowVersion不同) +// Set commonKeys = new HashSet<>(mapListAll.keySet()); +// commonKeys.retainAll(mapList1.keySet()); +// List toUpdate = commonKeys.stream() +// .filter(key -> !mapListAll.get(key).getIfsRowVersion().equals(mapList1.get(key).getIfsRowVersion())) +// .map(key -> mapListAll.get(key)) // 选择listAll中的版本进行更新 +// .collect(Collectors.toList()); - // 新增 - if (!toAdd.isEmpty()) { + // 删除再新增 + if (!ifsWorkCenterCosts.isEmpty()) { + // 清空数据 + routingManagementMapper.deleteWorkCenterCostAll(); // 分批插入 int batchSize = 50; // 假设每批100条记录 - for (int i = 0; i < toAdd.size(); i += batchSize) { - int end = Math.min(i + batchSize, toAdd.size()); - List subList = toAdd.subList(i, end); + for (int i = 0; i < ifsWorkCenterCosts.size(); i += batchSize) { + int end = Math.min(i + batchSize, ifsWorkCenterCosts.size()); + List subList = ifsWorkCenterCosts.subList(i, end); routingManagementMapper.syncSaveWorkCenterCost(subList); } } - // 修改 - if (!toUpdate.isEmpty()) { - // 分批修改 - int batchSize = 50; // 假设每批100条记录 - for (int i = 0; i < toUpdate.size(); i += batchSize) { - int end = Math.min(i + batchSize, toUpdate.size()); - List subList = toUpdate.subList(i, end); - routingManagementMapper.syncUpdateWorkCenterCost(subList); - } - } +// // 修改 +// if (!toUpdate.isEmpty()) { +// // 分批修改 +// int batchSize = 50; // 假设每批100条记录 +// for (int i = 0; i < toUpdate.size(); i += batchSize) { +// int end = Math.min(i + batchSize, toUpdate.size()); +// List subList = toUpdate.subList(i, end); +// routingManagementMapper.syncUpdateWorkCenterCost(subList); +// } +// } } @Override diff --git a/src/main/resources/mapper/part/RoutingManagementMapper.xml b/src/main/resources/mapper/part/RoutingManagementMapper.xml index b8de15ee..7ab0cd64 100644 --- a/src/main/resources/mapper/part/RoutingManagementMapper.xml +++ b/src/main/resources/mapper/part/RoutingManagementMapper.xml @@ -1783,4 +1783,9 @@ + + + + TRUNCATE TABLE work_center_cost +